00001 <?php
00002
00019
00020
00021
00022 class Plugin {
00024 var $pluginPath;
00025
00027 var $pluginCategory;
00028
00032 function Plugin() {
00033 }
00034
00039 function getPluginPath() {
00040 return $this->pluginPath;
00041 }
00042
00047 function getCategory() {
00048 return $this->pluginCategory;
00049 }
00050
00056 function getSeq() {
00057 return 0;
00058 }
00059
00068 function register($category, $path) {
00069 $this->pluginPath = $path;
00070 $this->pluginCategory = $category;
00071 if ($this->getInstallSchemaFile()) {
00072 HookRegistry::register ('Installer::postInstall', array(&$this, 'updateSchema'));
00073 }
00074 if ($this->getInstallSitePluginSettingsFile()) {
00075 HookRegistry::register ('Installer::postInstall', array(&$this, 'installSiteSettings'));
00076 }
00077 if ($this->getNewJournalPluginSettingsFile()) {
00078 HookRegistry::register ('JournalSiteSettingsForm::execute', array(&$this, 'installJournalSettings'));
00079 }
00080 if ($this->getInstallDataFile()) {
00081 HookRegistry::register ('Installer::postInstall', array(&$this, 'installData'));
00082 }
00083 return true;
00084 }
00085
00091 function addLocaleData($locale = null) {
00092 if ($locale == '') $locale = Locale::getLocale();
00093 $localeFilename = $this->getLocaleFilename($locale);
00094 if ($localeFilename) {
00095 Locale::registerLocaleFile($locale, $this->getLocaleFilename($locale));
00096 return true;
00097 }
00098 return false;
00099 }
00100
00106 function getLocaleFilename($locale) {
00107 return $this->getPluginPath() . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'locale.xml';
00108 }
00109
00115 function addHelpData($locale = null) {
00116 if ($locale == '') $locale = Locale::getLocale();
00117 $help =& Help::getHelp();
00118 import('help.PluginHelpMappingFile');
00119 $pluginHelpMapping =& new PluginHelpMappingFile($this);
00120 $help->addMappingFile($pluginHelpMapping);
00121 return true;
00122 }
00123
00129 function getHelpMappingFilename() {
00130 return $this->getPluginPath() . DIRECTORY_SEPARATOR . 'help.xml';
00131 }
00132
00139 function getName() {
00140 return 'Plugin';
00141 }
00142
00147 function getDisplayName() {
00148 return $this->getName();
00149 }
00150
00154 function getDescription() {
00155 return 'This is the base plugin class. It contains no concrete implementation. Its functions must be overridden by subclasses to provide actual functionality.';
00156 }
00157
00158 function getTemplatePath() {
00159 $basePath = dirname(dirname(dirname(__FILE__)));
00160 return "file:$basePath/" . $this->getPluginPath() . '/';
00161 }
00162
00167 function import($class) {
00168 require_once($this->getPluginPath() . '/' . str_replace('.', '/', $class) . '.inc.php');
00169 }
00170
00171 function getSetting($journalId, $name) {
00172 if (!Config::getVar('general', 'installed')) return null;
00173 if (defined('RUNNING_UPGRADE')) {
00174
00175
00176 $versionDao =& DAORegistry::getDAO('VersionDAO');
00177 $version =& $versionDao->getCurrentVersion();
00178 if ($version->compare('2.1.0') < 0) return null;
00179 }
00180 $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
00181 return $pluginSettingsDao->getSetting($journalId, $this->getName(), $name);
00182 }
00183
00191 function updateSetting($journalId, $name, $value, $type = null) {
00192 $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
00193 $pluginSettingsDao->updateSetting($journalId, $this->getName(), $name, $value, $type);
00194 }
00195
00199 function isSitePlugin() {
00200 return false;
00201 }
00202
00208 function getManagementVerbs() {
00209 return null;
00210 }
00211
00215 function manage($verb, $args) {
00216 return false;
00217 }
00218
00222 function smartyPluginUrl($params, &$smarty) {
00223 $path = array($this->getCategory(), $this->getName());
00224 if (is_array($params['path'])) {
00225 $params['path'] = array_merge($path, $params['path']);
00226 } elseif (!empty($params['path'])) {
00227 $params['path'] = array_merge($path, array($params['path']));
00228 } else {
00229 $params['path'] = $path;
00230 }
00231 return $smarty->smartyUrl($params, $smarty);
00232 }
00233
00239 function getInstallSchemaFile() {
00240 return null;
00241 }
00242
00250 function updateSchema($hookName, $args) {
00251 $installer =& $args[0];
00252 $result =& $args[1];
00253
00254 $schemaXMLParser = &new adoSchema($installer->dbconn, $installer->dbconn->charSet);
00255 $sql = $schemaXMLParser->parseSchema($this->getInstallSchemaFile());
00256 if ($sql) {
00257 $result = $installer->executeSQL($sql);
00258 } else {
00259 $installer->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $this->getInstallSchemaFile(), Locale::translate('installer.installParseDBFileError')));
00260 $result = false;
00261 }
00262 return false;
00263 }
00264
00271 function getNewJournalPluginSettingsFile() {
00272 return null;
00273 }
00274
00281 function installJournalSettings($hookName, $args) {
00282 $journal =& $args[1];
00283 $isNewJournal = $args[3];
00284
00285 if (!$isNewJournal) return false;
00286
00287 $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
00288 $pluginSettingsDao->installSettings($journal->getJournalId(), $this->getName(), $this->getNewJournalPluginSettingsFile());
00289
00290 return false;
00291 }
00292
00293
00294
00301 function getInstallSitePluginSettingsFile() {
00302 return null;
00303 }
00304
00311 function installSiteSettings($hookName, $args) {
00312 $installer =& $args[0];
00313 $result =& $args[1];
00314
00315
00316 if (!$installer->getParam('manualInstall')) {
00317 $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
00318 $pluginSettingsDao->installSettings(0, $this->getName(), $this->getInstallSitePluginSettingsFile());
00319 }
00320
00321 return false;
00322 }
00323
00329 function getInstallDataFile() {
00330 return null;
00331 }
00332
00339 function installData($hookName, $args) {
00340 $installer =& $args[0];
00341 $result =& $args[1];
00342
00343 $sql = $installer->dataXMLParser->parseData($this->getInstallDataFile());
00344 if ($sql) {
00345 $result = $installer->executeSQL($sql);
00346 } else {
00347 $installer->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $this->getInstallDataFile(), Locale::translate('installer.installParseDBFileError')));
00348 $result = false;
00349 }
00350 return false;
00351 }
00352 }
00353 ?>