예제 #1
0
 /**
  * For 2.3 upgrade:  Add initial plugin data to versions table
  * @return boolean
  */
 function addPluginVersions()
 {
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     import('site.VersionCheck');
     $categories = PluginRegistry::getCategories();
     foreach ($categories as $category) {
         PluginRegistry::loadCategory($category, true);
         $plugins = PluginRegistry::getPlugins($category);
         foreach ($plugins as $plugin) {
             $versionFile = $plugin->getPluginPath() . '/version.xml';
             if (FileManager::fileExists($versionFile)) {
                 $versionInfo =& VersionCheck::parseVersionXML($versionFile);
                 $pluginVersion = $versionInfo['version'];
                 $pluginVersion->setCurrent(1);
                 $versionDao->insertVersion($pluginVersion);
             } else {
                 $pluginVersion = new Version();
                 $pluginVersion->setMajor(1);
                 $pluginVersion->setMinor(0);
                 $pluginVersion->setRevision(0);
                 $pluginVersion->setBuild(0);
                 $pluginVersion->setDateInstalled(Core::getCurrentDate());
                 $pluginVersion->setCurrent(1);
                 $pluginVersion->setProductType('plugins.' . $category);
                 $pluginVersion->setProduct(basename($plugin->getPluginPath()));
                 $versionDao->insertVersion($pluginVersion);
             }
         }
     }
 }
예제 #2
0
 /**
  * Provide an endpoint for the PLN staging server to retrieve a deposit
  * @param array $args
  * @param Request $request
  */
 function deposits($args, &$request)
 {
     $journal =& $request->getJournal();
     $depositDao =& DAORegistry::getDAO('DepositDAO');
     $fileManager = new FileManager();
     $dispatcher = $request->getDispatcher();
     $depositUuid = !isset($args[0]) || empty($args[0]) ? null : $args[0];
     // sanitize the input
     if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/', $depositUuid)) {
         error_log(__("plugins.generic.pln.error.handler.uuid.invalid"));
         $dispatcher->handle404();
         return FALSE;
     }
     $deposit =& $depositDao->getDepositByUUID($journal->getId(), $depositUuid);
     if (!$deposit) {
         error_log(__("plugins.generic.pln.error.handler.uuid.notfound"));
         $dispatcher->handle404();
         return FALSE;
     }
     $depositPackage = new DepositPackage($deposit, null);
     $depositBag = $depositPackage->getPackageFilePath();
     if (!$fileManager->fileExists($depositBag)) {
         error_log("plugins.generic.pln.error.handler.file.notfound");
         $dispatcher->handle404();
         return FALSE;
     }
     return $fileManager->downloadFile($depositBag, mime_content_type($depositBag), TRUE);
 }
예제 #3
0
 function addCustomLocale($hookName, $args)
 {
     $locale =& $args[0];
     $localeFilename =& $args[1];
     $journal = Request::getJournal();
     $journalId = $journal->getId();
     $publicFilesDir = Config::getVar('files', 'public_files_dir');
     $customLocalePath = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
     import('file.FileManager');
     if (FileManager::fileExists($customLocalePath)) {
         Locale::registerLocaleFile($locale, $customLocalePath, true);
     }
     return true;
 }
예제 #4
0
 /**
  * Hook callback to add a custom locale file.
  * @param $hookName string
  * @param $args array
  * @return boolean
  */
 function addCustomLocale($hookName, $args)
 {
     $locale =& $args[0];
     $localeFilename =& $args[1];
     $request =& $this->getRequest();
     $journal = $request->getJournal();
     $journalId = $journal->getId();
     $publicFilesDir = Config::getVar('files', 'public_files_dir');
     $customLocalePath = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     if ($fileManager->fileExists($customLocalePath)) {
         AppLocale::registerLocaleFile($locale, $customLocalePath, true);
     }
     return true;
 }
예제 #5
0
 /**
  * Provide an endpoint for the PLN staging server to retrieve a deposit
  * @param array $args
  * @param Request $request
  */
 function deposits($args, &$request)
 {
     $journal =& $request->getJournal();
     $plnPlugin =& PluginRegistry::getPlugin('generic', PLN_PLUGIN_NAME);
     $depositDao =& DAORegistry::getDAO('DepositDAO');
     $fileManager = new FileManager();
     $depositUuid = !isset($args[0]) || empty($args[0]) ? null : $args[0];
     // sanitize the input
     if (!preg_match('/^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/', $depositUuid)) {
         return FALSE;
     }
     $deposit =& $depositDao->getDepositByUUID($journal->getId(), $depositUuid);
     if (!$deposit) {
         return FALSE;
     }
     $depositPackage = new DepositPackage($deposit);
     $depositBag = $depositPackage->getPackageFilePath();
     if (!$fileManager->fileExists($depositBag)) {
         return FALSE;
     }
     //TODO: Additional check here for journal UUID in HTTP header from staging server
     return $fileManager->downloadFile($depositBag, mime_content_type($depositBag), TRUE);
 }
예제 #6
0
 function register($category, $path)
 {
     if (parent::register($category, $path)) {
         if ($this->getEnabled()) {
             import('lib.pkp.classes.file.FileManager');
             $press = Request::getPress();
             $pressId = $press->getId();
             $locale = Locale::getLocale();
             $localeFiles = Locale::getLocaleFiles($locale);
             $publicFilesDir = Config::getVar('files', 'public_files_dir');
             $customLocaleDir = $publicFilesDir . DIRECTORY_SEPARATOR . 'presses' . DIRECTORY_SEPARATOR . $pressId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR;
             foreach ($localeFiles as $localeFile) {
                 $localeFilename = $localeFile->getFilename();
                 $customLocalePath = $customLocaleDir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
                 if (FileManager::fileExists($customLocalePath)) {
                     Locale::registerLocaleFile($locale, $customLocalePath, true);
                 }
             }
         }
         return true;
     }
     return false;
 }
예제 #7
0
 /**
  * Delete a file.
  * @param $filePath string the location of the file to be deleted
  * @return boolean returns true if successful
  */
 function deleteFile($filePath)
 {
     if (FileManager::fileExists($filePath)) {
         return unlink($filePath);
     } else {
         return false;
     }
 }
예제 #8
0
 /**
  * Checks whether the given version file exists and whether it
  * contains valid data. Returns a Version object if everything
  * is ok, otherwise null. If $returnErroMsg is true, returns the
  * error message.
  *
  * @param $versionFile string
  * @param $returnErrorMesg boolean
  * @return Version or null/string if invalid or missing version file
  */
 function &getValidPluginVersionInfo($versionFile, $returnErrorMsg = false)
 {
     $nullVar = null;
     $errorMsg = null;
     $fileManager = new FileManager();
     if ($fileManager->fileExists($versionFile)) {
         $versionInfo =& VersionCheck::parseVersionXML($versionFile);
     } else {
         $errorMsg = 'manager.plugins.versionFileNotFound';
     }
     // Validate plugin name and type to avoid abuse
     if (is_null($errorMsg)) {
         $productType = explode(".", $versionInfo['type']);
         if (count($productType) != 2 || $productType[0] != 'plugins') {
             $errorMsg = 'manager.plugins.versionFileInvalid';
         }
     }
     if (is_null($errorMsg)) {
         $pluginVersion =& $versionInfo['version'];
         $namesToValidate = array($pluginVersion->getProduct(), $productType[1]);
         foreach ($namesToValidate as $nameToValidate) {
             if (!String::regexp_match('/[a-z][a-zA-Z0-9]+/', $nameToValidate)) {
                 $errorMsg = 'manager.plugins.versionFileInvalid';
                 break;
             }
         }
     }
     if ($errorMsg) {
         if ($returnErrorMsg) {
             return $errorMsg;
         } else {
             $templateMgr =& TemplateManager::getManager();
             $templateMgr->assign('message', $errorMsg);
             return $nullVar;
         }
     } else {
         return $pluginVersion;
     }
 }
예제 #9
0
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     if ($this->getParam('manualInstall')) {
         // Add insert statements for default data
         // FIXME use ADODB data dictionary?
         $this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales)));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'title', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactName', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactEmail', 'string', addslashes($this->getParam('adminEmail')), $this->getParam('locale')));
         $this->executeSQL(sprintf('INSERT INTO users (username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
         $this->executeSQL(sprintf('INSERT INTO roles (conference_id, user_id, role_id) VALUES (%d, (SELECT user_id FROM users WHERE username = \'%s\'), %d)', 0, $this->getParam('adminUsername'), ROLE_ID_SITE_ADMIN));
         // Install email template list and data for each locale
         $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
         foreach ($emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), true) as $sql) {
             $this->executeSQL($sql);
         }
         foreach ($this->installedLocales as $locale) {
             foreach ($emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale), true) as $sql) {
                 $this->executeSQL($sql);
             }
         }
     } else {
         // Add initial site data
         $locale = $this->getParam('locale');
         $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
         $site = new Site();
         $site->setRedirect(0);
         $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
         $site->setPrimaryLocale($locale);
         $site->setInstalledLocales($this->installedLocales);
         $site->setSupportedLocales($this->installedLocales);
         if (!$siteDao->insertSite($site)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
         $siteSettingsDao->updateSetting('title', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactName', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
         $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
         // Add initial site administrator user
         $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
         $user = new User();
         $user->setUsername($this->getParam('adminUsername'));
         $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
         $user->setFirstName($user->getUsername());
         $user->setLastName('');
         $user->setEmail($this->getParam('adminEmail'));
         if (!$userDao->insertUser($user)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         $roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
         $role = new Role();
         $role->setConferenceId(0);
         $role->setUserId($user->getId());
         $role->setRoleId(ROLE_ID_SITE_ADMIN);
         if (!$roleDao->insertRole($role)) {
             $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
             return false;
         }
         // Install email template list and data for each locale
         $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
         $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
         foreach ($this->installedLocales as $locale) {
             $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
         }
         // Add initial plugin data to versions table
         $versionDao =& DAORegistry::getDAO('VersionDAO');
         import('site.VersionCheck');
         $categories = PluginRegistry::getCategories();
         foreach ($categories as $category) {
             PluginRegistry::loadCategory($category, true);
             $plugins = PluginRegistry::getPlugins($category);
             foreach ($plugins as $plugin) {
                 $versionFile = $plugin->getPluginPath() . '/version.xml';
                 if (FileManager::fileExists($versionFile)) {
                     $versionInfo =& VersionCheck::parseVersionXML($versionFile);
                     $pluginVersion = $versionInfo['version'];
                     $pluginVersion->setCurrent(1);
                     $versionDao->insertVersion($pluginVersion);
                 } else {
                     $pluginVersion = new Version();
                     $pluginVersion->setMajor(1);
                     $pluginVersion->setMinor(0);
                     $pluginVersion->setRevision(0);
                     $pluginVersion->setBuild(0);
                     $pluginVersion->setDateInstalled(Core::getCurrentDate());
                     $pluginVersion->setCurrent(1);
                     $pluginVersion->setProductType('plugins.' . $category);
                     $pluginVersion->setProduct(basename($plugin->getPluginPath()));
                     $versionDao->insertVersion($pluginVersion);
                 }
             }
         }
     }
     return true;
 }
예제 #10
0
 /**
  * PRIVATE routine to write a minutes file and add it to the database.
  * @param $fileName original filename of the file
  * @param $contents string contents of the file to write
  * @param $mimeType string the mime type of the file
  * @param $type string identifying type
  * @param $fileId int ID of an existing file to update
  * @return int the file ID (false if upload failed)
  */
 function handleWrite(&$pdf, $type, $fileId = null)
 {
     if (HookRegistry::call('MinutesFileManager::handleWrite', array(&$contents, &$fileId, &$result))) {
         return $result;
     }
     $minutesFileDao =& DAORegistry::getDAO('MinutesFileDAO');
     $typePath = $this->typeToPath($type);
     $dir = $this->filesDir . $typePath . '/';
     if (!$fileId) {
         $minutesFile =& $minutesFileDao->getGeneratedMinutesFile($this->meeting->getId(), $typePath);
         if (!$minutesFile) {
             $minutesFile =& $this->generateDummyFile($this->meeting);
         }
         $dummyFile = true;
     } else {
         $dummyFile = false;
         $minutesFile = new MinutesFile();
         $minutesFile->setMeetingId($this->meetingId);
         $minutesFile->setFileId($fileId);
     }
     $minutesFile->setFileType('application/pdf');
     $minutesFile->setOriginalFileName(null);
     $minutesFile->setType($typePath);
     $minutesFile->setDateCreated(Core::getCurrentDate());
     $newFileName = $this->generateFilename($minutesFile, $typePath, '.pdf');
     if (!FileManager::fileExists($dir, 'dir')) {
         FileManager::mkdirtree($dir);
     }
     if ($pdf->Output($dir . $newFileName, "F") != '') {
         $minutesFileDao->deleteMinutesFileById($minutesFile->getFileId());
         return false;
     } else {
         $minutesFile->setFileSize(filesize($dir . $newFileName));
     }
     if ($dummyFile) {
         $minutesFileDao->updateMinutesFile($minutesFile);
     } else {
         $minutesFileDao->insertMinutesFile($minutesFile);
     }
     return $minutesFile->getFileId();
 }
 /**
  * Delete a plugin from the system
  * @param plugin string
  */
 function deletePlugin($plugin)
 {
     $this->validate();
     $templateMgr =& TemplateManager::getManager();
     $this->setupTemplate(true);
     $templateMgr->assign('path', 'delete');
     $templateMgr->assign('deleted', false);
     $templateMgr->assign('error', false);
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $installedPlugin = $versionDao->getCurrentVersion($plugin, true);
     $category = $this->getPluginCategory($plugin);
     if ($installedPlugin) {
         $pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $plugin;
         //make sure plugin type is valid and then delete the files
         if (in_array($category, PluginRegistry::getCategories())) {
             FileManager::rmtree($pluginDest);
         }
         if (FileManager::fileExists($pluginDest, 'dir')) {
             $templateMgr->assign('error', true);
             $templateMgr->assign('message', 'manager.plugins.deleteError');
         } else {
             $versionDao->disableVersion($plugin);
             $templateMgr->assign('deleted', true);
         }
     } else {
         $templateMgr->assign('error', true);
         $templateMgr->assign('message', 'manager.plugins.doesNotExist');
     }
     $templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true, $category));
     $templateMgr->display('manager/plugins/managePlugins.tpl');
 }
예제 #12
0
 /**
  * Process apache log files, copying and filtering them
  * to the usage stats stage directory. Can work with both
  * a specific file or a directory.
  */
 function execute()
 {
     $fileMgr = new FileManager();
     $filesDir = Config::getVar('files', 'files_dir');
     $filePath = current($this->argv);
     $usageStatsDir = $this->_usageStatsDir;
     $tmpDir = $this->_tmpDir;
     if ($fileMgr->fileExists($tmpDir, 'dir')) {
         $fileMgr->rmtree($tmpDir);
     }
     if (!$fileMgr->mkdir($tmpDir)) {
         printf(__('admin.copyAccessLogFileTool.error.creatingFolder', array('tmpDir' => $tmpDir)) . "\n");
         exit(1);
     }
     if ($fileMgr->fileExists($filePath, 'dir')) {
         // Directory.
         $filesToCopy = glob($filePath . DIRECTORY_SEPARATOR . '*.*');
         foreach ($filesToCopy as $file) {
             // If a base filename is given as a parameter, check it.
             if (count($this->argv) == 2) {
                 $baseFilename = $this->argv[1];
                 if (strpos(pathinfo($file, PATHINFO_BASENAME), $baseFilename) !== 0) {
                     continue;
                 }
             }
             $this->_copyFile($file);
         }
     } else {
         if ($fileMgr->fileExists($filePath)) {
             // File.
             $this->_copyFile($filePath);
         } else {
             // Can't access.
             printf(__('admin.copyAccessLogFileTool.error.acessingFile', array('filePath' => $filePath)) . "\n");
         }
     }
     $fileMgr->rmtree($tmpDir);
 }
예제 #13
0
 /**
  * Apply an XSLT transform to a given XML and XSL. Both parameters
  * can be either strings, files or DOM objects.
  * @param $xml mixed
  * @param $xmlType integer
  * @param $xsl mixed
  * @param $xslType integer
  * @param $resultType integer
  * @return mixed return type depends on the $returnType parameter and can be
  *  DOMDocument or string. The method returns a boolean value of false if the
  *  transformation fails for some reason.
  */
 function &transform(&$xml, $xmlType, &$xsl, $xslType, $resultType)
 {
     // If either XML or XSL file don't exist, then fail without trying to process XSLT
     if ($xmlType == XSL_TRANSFORMER_DOCTYPE_FILE) {
         if (!FileManager::fileExists($xml)) {
             return false;
         }
     }
     if ($xslType == XSL_TRANSFORMER_DOCTYPE_FILE) {
         if (!FileManager::fileExists($xsl)) {
             return false;
         }
     }
     // The result type can only be string or DOM
     assert($resultType != XSL_TRANSFORMER_DOCTYPE_FILE);
     switch ($this->processor) {
         case 'External':
             return $this->_transformExternal(&$xml, $xmlType, &$xsl, $xslType, $resultType);
         case 'PHP4':
             return $this->_transformPHP4(&$xml, $xmlType, &$xsl, $xslType, $resultType);
         case 'PHP5':
             return $this->_transformPHP5(&$xml, $xmlType, &$xsl, $xslType, $resultType);
         default:
             // No XSLT processor available
             $falseVar = false;
             return $falseVar;
     }
 }
예제 #14
0
파일: Install.inc.php 프로젝트: sedici/ocs
 /**
  * Create initial required data.
  * @return boolean
  */
 function createData()
 {
     // Add initial site data
     $locale = $this->getParam('locale');
     $siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
     $site = new Site();
     $site->setRedirect(0);
     $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
     $site->setPrimaryLocale($locale);
     $site->setInstalledLocales($this->installedLocales);
     $site->setSupportedLocales($this->installedLocales);
     if (!$siteDao->insertSite($site)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
     $siteSettingsDao->updateSetting('title', array($locale => __(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
     $siteSettingsDao->updateSetting('contactName', array($locale => __(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
     $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
     // Add initial site administrator user
     $userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
     $user = new User();
     $user->setUsername($this->getParam('adminUsername'));
     $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
     $user->setFirstName($user->getUsername());
     $user->setLastName('');
     $user->setEmail($this->getParam('adminEmail'));
     if (!$userDao->insertUser($user)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     $roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
     $role = new Role();
     $role->setConferenceId(0);
     $role->setUserId($user->getId());
     $role->setRoleId(ROLE_ID_SITE_ADMIN);
     if (!$roleDao->insertRole($role)) {
         $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
         return false;
     }
     // Install email template list and data for each locale
     $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
     $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
     foreach ($this->installedLocales as $locale) {
         $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
     }
     // Add initial plugin data to versions table
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     import('site.VersionCheck');
     $categories = PluginRegistry::getCategories();
     foreach ($categories as $category) {
         PluginRegistry::loadCategory($category, true);
         $plugins = PluginRegistry::getPlugins($category);
         foreach ($plugins as $plugin) {
             $versionFile = $plugin->getPluginPath() . '/version.xml';
             if (FileManager::fileExists($versionFile)) {
                 $versionInfo =& VersionCheck::parseVersionXML($versionFile);
                 $pluginVersion = $versionInfo['version'];
                 $pluginVersion->setCurrent(1);
                 $versionDao->insertVersion($pluginVersion);
             } else {
                 $pluginVersion = new Version();
                 $pluginVersion->setMajor(1);
                 $pluginVersion->setMinor(0);
                 $pluginVersion->setRevision(0);
                 $pluginVersion->setBuild(0);
                 $pluginVersion->setDateInstalled(Core::getCurrentDate());
                 $pluginVersion->setCurrent(1);
                 $pluginVersion->setProductType('plugins.' . $category);
                 $pluginVersion->setProduct(basename($plugin->getPluginPath()));
                 $versionDao->insertVersion($pluginVersion);
             }
         }
     }
     return true;
 }
예제 #15
0
 /**
  * @copydoc CategoryGridHandler::loadCategoryData()
  */
 function loadCategoryData($request, $categoryDataElement, $filter)
 {
     $plugins =& PluginRegistry::loadCategory($categoryDataElement);
     $versionDao = DAORegistry::getDAO('VersionDAO');
     import('lib.pkp.classes.site.VersionCheck');
     $fileManager = new FileManager();
     $notHiddenPlugins = array();
     foreach ((array) $plugins as $plugin) {
         if (!$plugin->getHideManagement()) {
             $notHiddenPlugins[$plugin->getName()] = $plugin;
         }
         $version = $plugin->getCurrentVersion();
         if ($version == null) {
             // this plugin is on the file system, but not installed.
             $versionFile = $plugin->getPluginPath() . '/version.xml';
             if ($fileManager->fileExists($versionFile)) {
                 $versionInfo = VersionCheck::parseVersionXML($versionFile);
                 $pluginVersion = $versionInfo['version'];
             } else {
                 $pluginVersion = new Version(1, 0, 0, 0, Core::getCurrentDate(), 1, 'plugins.' . $plugin->getCategory(), basename($plugin->getPluginPath()), '', 0, $plugin->isSitePlugin());
             }
             $versionDao->insertVersion($pluginVersion, true);
         }
     }
     if (!is_null($filter) && isset($filter['pluginName']) && $filter['pluginName'] != "") {
         // Find all plugins that have the filter name string in their display names.
         $filteredPlugins = array();
         foreach ($notHiddenPlugins as $plugin) {
             /* @var $plugin Plugin */
             $pluginName = $plugin->getDisplayName();
             if (stristr($pluginName, $filter['pluginName']) !== false) {
                 $filteredPlugins[$plugin->getName()] = $plugin;
             }
         }
         return $filteredPlugins;
     }
     return $notHiddenPlugins;
 }
예제 #16
0
 /**
  * Internal function to return the cover for publishing a research
  * @param $sectionEditorSubmission SectionEditorSubmission
  * @return string path to cover created
  */
 function &_generateCover($sectionEditorSubmission)
 {
     $journal =& Request::getJournal();
     import('classes.lib.tcpdf.pdf');
     import('classes.lib.tcpdf.tcpdf');
     Locale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON, LOCALE_COMPONENT_OJS_EDITOR, LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_PKP_USER));
     $pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // No header and footer for this document
     $pdf->SetPrintHeader(false);
     $pdf->SetPrintFooter(false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor($journal->getJournalTitle());
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, 20, PDF_MARGIN_RIGHT);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // Right now this cover page is only in english, but the english translation keys are ready
     $pdf->AddPage();
     $pdf->SetFont('dejavusans', 'B', 14);
     $pdf->MultiCell(0, 6, 'Final Technical Report', 0, 'C');
     // Locale::translate('editor.finalReport')
     $pdf->ln();
     $pdf->ln();
     $pdf->MultiCell(0, 6, 'for', 0, 'C');
     // Locale::translate('editor.finalReport.for')
     $pdf->ln();
     $pdf->ln();
     $pdf->MultiCell(0, 6, 'Research Project', 0, 'C');
     // Locale::translate('editor.finalReport.researchProject')
     $pdf->ln();
     $pdf->ln();
     $pdf->ln();
     $pdf->ln();
     $abstract = $sectionEditorSubmission->getAbstractByLocale('en_US');
     // Right now, considering only the english language
     $pdf->SetFont('dejavusans', 'B', 16);
     $pdf->MultiCell(0, 6, $abstract->getScientificTitle(), 0, 'C');
     $pdf->ln();
     $authors = $sectionEditorSubmission->getAuthors();
     $coInvestigatorsString = (string) '';
     $pInvestigatorsString = (string) '';
     foreach ($authors as $author) {
         if (!$author->getPrimaryContact()) {
             if ($coInvestigatorsString == '') {
                 $coInvestigatorsString = $author->getFullName() . ' (' . $author->getAffiliation() . ')';
             } else {
                 $coInvestigatorsString = $coInvestigatorsString . ', ' . $author->getFullName() . ' (' . $author->getAffiliation() . ')';
             }
         } else {
             $pInvestigatorsString = $author->getFullName() . ' (' . $author->getAffiliation() . ')';
         }
     }
     $pdf->SetFont('dejavusans', '', 16);
     $pdf->MultiCell(0, 6, 'Principal Investigator: ' . $pInvestigatorsString, 0, 'C');
     // Locale::translate('user.role.primaryInvestigator')
     if ($coInvestigatorsString != '') {
         $pdf->MultiCell(0, 6, 'Co-Investigator(s): ' . $coInvestigatorsString, 0, 'C');
         // Locale::translate('user.role.coinvestigator')
     }
     $pdf->ln();
     $pdf->ln();
     $pdf->ln();
     $pdf->ln();
     $pdf->SetFont('dejavusans', 'B', 16);
     $pdf->MultiCell(0, 6, $sectionEditorSubmission->getProposalId(), 0, 'C');
     $pdf->ln();
     $pdf->ln();
     $decision = $sectionEditorSubmission->getLastSectionDecision();
     $pdf->MultiCell(0, 0, date("F Y", strtotime($decision->getDateDecided())), 0, 'L', 0, 1, '', 250, true);
     $pdf->Image("public/site/images/mainlogo.png", 'C', 230, 40, '', '', false, 'C', false, 300, 'R', false, false, 0, false, false, false);
     $pdf->AddPage();
     $pdf->SetFont('dejavusans', 'B', 14);
     $pdf->MultiCell(0, 6, 'Final Technical Report', 0, 'C');
     // Locale::translate('editor.finalReport')
     $pdf->ln();
     $pdf->ln();
     $pdf->SetFont('dejavusans', 'B', 12);
     $pdf->MultiCell(0, 6, 'Disclaimer', 0, 'C');
     // Locale::translate('editor.finalReport.disclaimer')
     $pdf->ln();
     $pdf->ln();
     $pdf->SetFont('dejavusans', '', 11);
     $pdf->writeHTMLCell(0, 6, '', '', $journal->getSetting('reportDisclaimer'), 0, 0, false, true, 'J');
     $filePath = Config::getVar('files', 'files_dir') . '/articles/' . $sectionEditorSubmission->getArticleId() . '/public/';
     if (!FileManager::fileExists($filePath, 'dir')) {
         FileManager::mkdirtree($filePath);
     }
     $pdf->Output($filePath . 'tempCover.pdf', 'F');
     return $filePath;
 }
예제 #17
0
 /**
  * Auto stage usage stats log files, also moving files that
  * might be in processing folder to stage folder.
  */
 function autoStage()
 {
     $plugin = $this->_plugin;
     // Copy all log files to stage directory, except the current day one.
     $fileMgr = new FileManager();
     $logFiles = array();
     $logsDirFiles = glob($plugin->getUsageEventLogsPath() . DIRECTORY_SEPARATOR . '*');
     // It's possible that the processing directory has files that
     // were being processed but the php process was stopped before
     // finishing the processing. Just copy them to the stage directory too.
     $processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*');
     if (is_array($logsDirFiles)) {
         $logFiles = array_merge($logFiles, $logsDirFiles);
     }
     if (is_array($processingDirFiles)) {
         $logFiles = array_merge($logFiles, $processingDirFiles);
     }
     foreach ($logFiles as $filePath) {
         // Make sure it's a file.
         if ($fileMgr->fileExists($filePath)) {
             // Avoid current day file.
             $filename = pathinfo($filePath, PATHINFO_BASENAME);
             $currentDayFilename = $plugin->getUsageEventCurrentDayLogName();
             if ($filename == $currentDayFilename) {
                 continue;
             }
             $this->moveFile(pathinfo($filePath, PATHINFO_DIRNAME), $this->getStagePath(), $filename);
         }
     }
 }
예제 #18
0
 /**
  * Apply an XSLT transform to a given XML and XSL. Both parameters
  * can be either strings, files or DOM objects.
  * @param $xml mixed
  * @param $xmlType integer
  * @param $xsl mixed
  * @param $xslType integer
  * @param $resultType integer XSL_TRANSFORMER_DOCTYPE_...
  * @return mixed return type depends on the $resultType parameter and can be
  *  DOMDocument or string. The method returns a boolean value of false if the
  *  transformation fails for some reason.
  */
 function transform($xml, $xmlType, $xsl, $xslType, $resultType)
 {
     // If either XML or XSL file don't exist, then fail without trying to process XSLT
     $fileManager = new FileManager();
     if ($xmlType == XSL_TRANSFORMER_DOCTYPE_FILE) {
         if (!$fileManager->fileExists($xml)) {
             return false;
         }
     }
     if ($xslType == XSL_TRANSFORMER_DOCTYPE_FILE) {
         if (!$fileManager->fileExists($xsl)) {
             return false;
         }
     }
     // The result type can only be string or DOM
     assert($resultType != XSL_TRANSFORMER_DOCTYPE_FILE);
     switch (self::$processor) {
         case 'External':
             return $this->_transformExternal($xml, $xmlType, $xsl, $xslType, $resultType);
         case 'PHP':
             return $this->_transformPHP($xml, $xmlType, $xsl, $xslType, $resultType);
         default:
             // No XSLT processor available
             return false;
     }
 }
 /**
  * Constructor.
  * @param $argv array task arguments
  */
 function PKPUsageStatsLoader($args)
 {
     $plugin = PluginRegistry::getPlugin('generic', 'usagestatsplugin');
     /* @var $plugin UsageStatsPlugin */
     $this->_plugin = $plugin;
     $arg = current($args);
     switch ($arg) {
         case 'autoStage':
             if ($plugin->getSetting(0, 'createLogFiles')) {
                 $this->_autoStage = true;
             }
             break;
         case 'externalLogFiles':
             $this->_externalLogFiles = true;
             break;
     }
     // Define the base filesystem path.
     $args[0] = $plugin->getFilesPath();
     parent::FileLoader($args);
     if ($plugin->getEnabled()) {
         // Load the metric type constant.
         PluginRegistry::loadCategory('reports');
         import('classes.statistics.StatisticsHelper');
         $statsHelper = new StatisticsHelper();
         $geoLocationTool = $statsHelper->getGeoLocationTool();
         $this->_geoLocationTool = $geoLocationTool;
         $plugin->import('UsageStatsTemporaryRecordDAO');
         $statsDao = new UsageStatsTemporaryRecordDAO();
         DAORegistry::registerDAO('UsageStatsTemporaryRecordDAO', $statsDao);
         $this->_counterRobotsListFile = $this->_getCounterRobotListFile();
         $contextDao = Application::getContextDAO();
         /* @var $contextDao ContextDAO */
         $contextFactory = $contextDao->getAll();
         /* @var $contextFactory DAOResultFactory */
         $contextsByPath = array();
         while ($context = $contextFactory->next()) {
             /* @var $context Context */
             $contextsByPath[$context->getPath()] = $context;
         }
         $this->_contextsByPath = $contextsByPath;
         $this->checkFolderStructure(true);
         if ($this->_autoStage) {
             // Copy all log files to stage directory, except the current day one.
             $fileMgr = new FileManager();
             $logFiles = array();
             $logsDirFiles = glob($plugin->getUsageEventLogsPath() . DIRECTORY_SEPARATOR . '*');
             // It's possible that the processing directory have files that
             // were being processed but the php process was stopped before
             // finishing the processing. Just copy them to the stage directory too.
             $processingDirFiles = glob($this->getProcessingPath() . DIRECTORY_SEPARATOR . '*');
             if (is_array($logsDirFiles)) {
                 $logFiles = array_merge($logFiles, $logsDirFiles);
             }
             if (is_array($processingDirFiles)) {
                 $logFiles = array_merge($logFiles, $processingDirFiles);
             }
             foreach ($logFiles as $filePath) {
                 // Make sure it's a file.
                 if ($fileMgr->fileExists($filePath)) {
                     // Avoid current day file.
                     $filename = pathinfo($filePath, PATHINFO_BASENAME);
                     $currentDayFilename = $plugin->getUsageEventCurrentDayLogName();
                     if ($filename == $currentDayFilename) {
                         continue;
                     }
                     $this->moveFile(pathinfo($filePath, PATHINFO_DIRNAME), $this->getStagePath(), $filename);
                 }
             }
         }
     }
 }
예제 #20
0
 /**
  * Upgrade a plugin to a newer version from the user's filesystem
  * @param $category string
  * @param $plugin string
  * @param $path string path to plugin Directory
  * @param $category string
  * @param $plugin string
  * @return Version|null The upgraded version, on success; null on fail
  */
 function upgradePlugin($category, $plugin, $path, &$errorMsg)
 {
     $versionFile = $path . '/' . PLUGIN_VERSION_FILE;
     $pluginVersion = VersionCheck::getValidPluginVersionInfo($versionFile, $errorMsg);
     if (!$pluginVersion) {
         return null;
     }
     // Check whether the uploaded plug-in fits the original plug-in.
     if ('plugins.' . $category != $pluginVersion->getProductType()) {
         $errorMsg = __('manager.plugins.wrongCategory');
         return null;
     }
     if ($plugin != $pluginVersion->getProduct()) {
         $errorMsg = __('manager.plugins.wrongName');
         return null;
     }
     $versionDao = DAORegistry::getDAO('VersionDAO');
     $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
     if (!$installedPlugin) {
         $errorMsg = __('manager.plugins.pleaseInstall');
         return null;
     }
     if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
         $errorMsg = __('manager.plugins.installedVersionNewer');
         return null;
     } else {
         $pluginDest = Core::getBaseDir() . '/plugins/' . $category . '/' . $plugin;
         $pluginLibDest = Core::getBaseDir() . '/' . PKP_LIB_PATH . '/plugins/' . $category . '/' . $plugin;
         // Delete existing files.
         $fileManager = new FileManager();
         if (is_dir($pluginDest)) {
             $fileManager->rmtree($pluginDest);
         }
         if (is_dir($pluginLibDest)) {
             $fileManager->rmtree($pluginLibDest);
         }
         // Check whether deleting has worked.
         if (is_dir($pluginDest) || is_dir($pluginLibDest)) {
             $errorMsg = __('message', 'manager.plugins.deleteError');
             return null;
         }
         // Copy the plug-in from the temporary folder to the
         // target folder.
         // Start with the library part (if any).
         $libPath = $path . '/lib';
         if (is_dir($libPath)) {
             if (!$fileManager->copyDir($libPath, $pluginLibDest)) {
                 $errorMsg = __('manager.plugins.copyError');
                 return null;
             }
             // Remove the library part of the temporary folder.
             $fileManager->rmtree($libPath);
         }
         // Continue with the application-specific part (mandatory).
         if (!$fileManager->copyDir($path, $pluginDest)) {
             $errorMsg = __('manager.plugins.copyError');
             return null;
         }
         // Remove the temporary folder.
         $fileManager->rmtree(dirname($path));
         $upgradeFile = $pluginDest . '/' . PLUGIN_UPGRADE_FILE;
         if ($fileManager->fileExists($upgradeFile)) {
             $params = $this->_getConnectionParams();
             $installer = new Upgrade($params, $upgradeFile, true);
             if (!$installer->execute()) {
                 $errorMsg = __('manager.plugins.upgradeFailed', array('errorString' => $installer->getErrorString()));
                 return null;
             }
         }
         $installedPlugin->setCurrent(0);
         $pluginVersion->setCurrent(1);
         $versionDao->insertVersion($pluginVersion, true);
         return $pluginVersion;
     }
 }
예제 #21
0
 /**
  * Checks whether the given version file exists and whether it
  * contains valid data. Returns a Version object if everything
  * is ok, otherwise null.
  *
  * @param $versionFile string
  * @param $templateMgr TemplateManager
  * @return Version or null if invalid or missing version file
  */
 function &getValidPluginVersionInfo($versionFile, &$templateMgr)
 {
     $nullVar = null;
     if (FileManager::fileExists($versionFile)) {
         $versionInfo =& VersionCheck::parseVersionXML($versionFile);
     } else {
         $templateMgr->assign('message', 'manager.plugins.versionFileNotFound');
         return $nullVar;
     }
     $pluginVersion =& $versionInfo['version'];
     // Validate plugin name and type to avoid abuse
     $productType = explode(".", $versionInfo['type']);
     if (count($productType) != 2 || $productType[0] != 'plugins') {
         return $nullVar;
         $templateMgr->assign('message', 'manager.plugins.versionFileInvalid');
     }
     $namesToValidate = array($pluginVersion->getProduct(), $productType[1]);
     foreach ($namesToValidate as $nameToValidate) {
         if (!String::regexp_match('/[a-z][a-zA-Z0-9]+/', $nameToValidate)) {
             return $nullVar;
             $templateMgr->assign('message', 'manager.plugins.versionFileInvalid');
         }
     }
     return $pluginVersion;
 }
예제 #22
0
 function saveLocaleFile($args)
 {
     $this->validate();
     $plugin =& PluginRegistry::getPlugin('generic', 'CustomLocalePlugin');
     $this->setupTemplate($plugin, true);
     $locale = array_shift($args);
     if (!Locale::isLocaleValid($locale)) {
         $path = array($plugin->getCategory(), $plugin->getName(), 'index');
         Request::redirect(null, null, null, $path);
     }
     $filename = urldecode(urldecode(array_shift($args)));
     if (!CustomLocaleAction::isLocaleFile($locale, $filename)) {
         $path = array($plugin->getCategory(), $plugin->getName(), 'edit', $locale);
         Request::redirect(null, null, null, $path);
     }
     $journal =& Request::getJournal();
     $journalId = $journal->getId();
     $changes = Request::getUserVar('changes');
     $customFilesDir = Config::getVar('files', 'public_files_dir') . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale;
     $customFilePath = $customFilesDir . DIRECTORY_SEPARATOR . $filename;
     // Create empty custom locale file if it doesn't exist
     import('file.FileManager');
     import('file.EditableLocaleFile');
     if (!FileManager::fileExists($customFilePath)) {
         $numParentDirs = substr_count($customFilePath, DIRECTORY_SEPARATOR);
         $parentDirs = '';
         for ($i = 0; $i < $numParentDirs; $i++) {
             $parentDirs .= '..' . DIRECTORY_SEPARATOR;
         }
         $newFileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
         $newFileContents .= '<!DOCTYPE locale SYSTEM "' . $parentDirs . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'dtd' . DIRECTORY_SEPARATOR . 'locale.dtd' . '">' . "\n";
         $newFileContents .= '<locale name="' . $locale . '">' . "\n";
         $newFileContents .= '</locale>';
         FileManager::writeFile($customFilePath, $newFileContents);
     }
     $file = new EditableLocaleFile($locale, $customFilePath);
     while (!empty($changes)) {
         $key = array_shift($changes);
         $value = $this->correctCr(array_shift($changes));
         if (!empty($value)) {
             if (!$file->update($key, $value)) {
                 $file->insert($key, $value);
             }
         } else {
             $file->delete($key);
         }
     }
     $file->write();
     Request::redirectUrl(Request::getUserVar('redirectUrl'));
 }
예제 #23
0
 /**
  * Return string containing the transformed XML output.
  * This function applies an XSLT transform to a given XML source.
  * @param $xmlFile pathname to the XML source file (absolute)
  * @param $xslFile pathname to the XSL stylesheet (absolute)
  * @param (optional) $xsltType type of XSLT renderer to use (PHP4, PHP5, or XSLT shell command)
  * @param (optional) $arguments array of param-value pairs to pass to the XSLT  
  * @return string
  */
 function transformXSLT($xmlFile, $xslFile, $xsltType = "", $arguments = null)
 {
     // if either XML or XSL file don't exist, then fail without trying to process XSLT
     $fileManager = new FileManager();
     if (!$fileManager->fileExists($xmlFile) || !$fileManager->fileExists($xslFile)) {
         return false;
     }
     // Determine the appropriate XSLT processor for the system
     if (version_compare(PHP_VERSION, '5', '>=') && extension_loaded('xsl') && extension_loaded('dom')) {
         // PHP5.x with XSL/DOM modules present
         if ($xsltType == "PHP5" || $xsltType == "") {
             // load the XML file as a domdocument
             $xmlDom = new DOMDocument("1.0", "UTF-8");
             // these are required for external entity resolution (eg. &nbsp;)
             // it slows loading substantially (20-100x), often up to 60s
             // this can be solved by use of local catalogs to speed resolution
             //
             // http://www.whump.com/moreLikeThis/link/03815
             // http://www.suite75.net/blog/mt/tim/archives/2004_07.php
             //putenv("XML_CATALOG_FILES=/Users/mj/Sites/ojs2/plugins/generic/xmlGalley/transform/Publishing-2_2-dtd-June/catalog.ent");
             $xmlDom->substituteEntities = true;
             $xmlDom->resolveExternals = true;
             $xmlDom->load($xmlFile);
             // create the processor and import the stylesheet
             $xslDom = new DOMDocument("1.0", "UTF-8");
             $xslDom->load($xslFile);
             $proc = new XsltProcessor();
             $proc->importStylesheet($xslDom);
             // set XSL parameters
             foreach ((array) $arguments as $param => $value) {
                 $proc->setParameter(null, $param, $value);
             }
             // transform the XML document to an XHTML fragment
             $contents = $proc->transformToXML($xmlDom);
             return $contents;
         }
     }
     if (version_compare(PHP_VERSION, '5', '<') && extension_loaded('xslt')) {
         // PHP4.x with XSLT module present
         if ($xsltType == "PHP4" || $xsltType == "") {
             // create the processor
             $proc = xslt_create();
             // transform the XML document to an XHTML fragment
             $contents = xslt_process($proc, $xmlFile, $xslFile, null, null, $arguments);
             return $contents;
         }
     }
     if ($xsltType != "") {
         // external command-line renderer
         // parse the external command to check for %xsl and %xml parameter substitution
         if (strpos($xsltType, '%xsl') === false) {
             return false;
         }
         // perform %xsl and %xml replacements for fully-qualified shell command
         $xsltCommand = str_replace(array('%xsl', '%xml'), array($xslFile, $xmlFile), $xsltType);
         // check for safe mode and escape the shell command
         if (!ini_get('safe_mode')) {
             $xsltCommand = escapeshellcmd($xsltCommand);
         }
         // run the shell command and get the results
         exec($xsltCommand . ' 2>&1', $contents, $status);
         // if there is an error, spit out the shell results to aid debugging
         if ($status != false) {
             if ($contents != '') {
                 echo implode("\n", $contents);
                 return true;
             } else {
                 return false;
             }
         }
         return implode("\n", $contents);
     } else {
         // No XSLT processor available
         return false;
     }
 }
예제 #24
0
 /**
  * Insert or update plugin data in versions
  * and plugin_settings tables.
  * @return boolean
  */
 function addPluginVersions()
 {
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     import('lib.pkp.classes.site.VersionCheck');
     $fileManager = new FileManager();
     $categories = PluginRegistry::getCategories();
     foreach ($categories as $category) {
         PluginRegistry::loadCategory($category);
         $plugins = PluginRegistry::getPlugins($category);
         if (is_array($plugins)) {
             foreach ($plugins as $plugin) {
                 $versionFile = $plugin->getPluginPath() . '/version.xml';
                 if ($fileManager->fileExists($versionFile)) {
                     $versionInfo =& VersionCheck::parseVersionXML($versionFile);
                     $pluginVersion = $versionInfo['version'];
                 } else {
                     $pluginVersion = new Version(1, 0, 0, 0, Core::getCurrentDate(), 1, 'plugins.' . $category, basename($plugin->getPluginPath()), '', 0, $plugin->isSitePlugin());
                 }
                 $versionDao->insertVersion($pluginVersion, true);
             }
         }
     }
     return true;
 }
예제 #25
0
 /**
  * Process apache log files, copying and filtering them
  * to the usage stats stage directory. Can work with both
  * a specific file or a directory.
  */
 function execute()
 {
     $fileMgr = new FileManager();
     $filesDir = Config::getVar('files', 'files_dir');
     $filePath = current($this->argv);
     $usageStatsDir = $this->_usageStatsDir;
     $tmpDir = $this->_tmpDir;
     if ($fileMgr->fileExists($tmpDir, 'dir')) {
         $fileMgr->rmtree($tmpDir);
     }
     if (!$fileMgr->mkdir($tmpDir)) {
         printf(__('admin.copyAccessLogFileTool.error.creatingFolder', array('tmpDir' => $tmpDir)) . "\n");
         exit(1);
     }
     if ($fileMgr->fileExists($filePath, 'dir')) {
         // Directory.
         $filesToCopy = glob($filePath . DIRECTORY_SEPARATOR . '*');
         foreach ($filesToCopy as $file) {
             $this->_copyFile($file);
         }
     } else {
         if ($fileMgr->fileExists($filePath)) {
             // File.
             $this->_copyFile($filePath);
         } else {
             // Can't access.
             printf(__('admin.copyAccessLogFileTool.error.acessingFile', array('filePath' => $filePath)) . "\n");
         }
     }
     $fileMgr->rmtree($tmpDir);
 }
 /**
  * Upgrade a plugin to a newer version from the user's filesystem
  * @param $path string path to plugin Directory
  * @param $templateMgr reference to template manager
  * @param $category string
  * @param $plugin string
  * @return boolean
  */
 function upgradePlugin($path, &$templateMgr, $category, $plugin)
 {
     $this->validate();
     $versionFile = $path . VERSION_FILE;
     $templateMgr->assign('error', true);
     $templateMgr->assign('pageHierarchy', $this->setBreadcrumbs(true, $category));
     $pluginVersion =& VersionCheck::getValidPluginVersionInfo($versionFile, $templateMgr);
     if (is_null($pluginVersion)) {
         return false;
     }
     assert(is_a($pluginVersion, 'Version'));
     // Check whether the uploaded plug-in fits the original plug-in.
     if ('plugins.' . $category != $pluginVersion->getProductType()) {
         $templateMgr->assign('message', 'manager.plugins.wrongCategory');
         return false;
     }
     if ($plugin != $pluginVersion->getProduct()) {
         $templateMgr->assign('message', 'manager.plugins.wrongName');
         return false;
     }
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $installedPlugin = $versionDao->getCurrentVersion($pluginVersion->getProductType(), $pluginVersion->getProduct(), true);
     if (!$installedPlugin) {
         $templateMgr->assign('message', 'manager.plugins.pleaseInstall');
         return false;
     }
     if ($this->_checkIfNewer($pluginVersion->getProductType(), $pluginVersion->getProduct(), $pluginVersion)) {
         $templateMgr->assign('message', 'manager.plugins.installedVersionNewer');
         return false;
     } else {
         $pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $plugin;
         $pluginLibDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $plugin;
         // Delete existing files.
         if (is_dir($pluginDest)) {
             FileManager::rmtree($pluginDest);
         }
         if (is_dir($pluginLibDest)) {
             FileManager::rmtree($pluginLibDest);
         }
         // Check whether deleting has worked.
         if (is_dir($pluginDest) || is_dir($pluginLibDest)) {
             $templateMgr->assign('message', 'manager.plugins.deleteError');
             return false;
         }
         // Copy the plug-in from the temporary folder to the
         // target folder.
         // Start with the library part (if any).
         $libPath = $path . DIRECTORY_SEPARATOR . 'lib';
         if (is_dir($libPath)) {
             if (!FileManager::copyDir($libPath, $pluginLibDest)) {
                 $templateMgr->assign('message', 'manager.plugins.copyError');
                 return false;
             }
             // Remove the library part of the temporary folder.
             FileManager::rmtree($libPath);
         }
         // Continue with the application-specific part (mandatory).
         if (!FileManager::copyDir($path, $pluginDest)) {
             $templateMgr->assign('message', 'manager.plugins.copyError');
             return false;
         }
         // Remove the temporary folder.
         FileManager::rmtree(dirname($path));
         $upgradeFile = $pluginDest . UPGRADE_FILE;
         if (FileManager::fileExists($upgradeFile)) {
             $params = $this->_setConnectionParams();
             $installer = new Upgrade($params, $upgradeFile, true);
             if (!$installer->execute()) {
                 $templateMgr->assign('message', array('manager.plugins.upgradeFailed', $installer->getErrorString()));
                 return false;
             }
         }
         $installedPlugin->setCurrent(0);
         $pluginVersion->setCurrent(1);
         $versionDao->insertVersion($pluginVersion, true);
         $templateMgr->assign('category', $category);
         $templateMgr->assign('plugin', $plugin);
         $templateMgr->assign('message', array('manager.plugins.upgradeSuccessful', $pluginVersion->getVersionString()));
         $templateMgr->assign('uploaded', true);
         $templateMgr->assign('error', false);
         return true;
     }
 }
예제 #27
0
 function saveLocaleFile($args, &$request)
 {
     $this->validate();
     $plugin =& $this->plugin;
     $this->setupTemplate($request, $plugin, true);
     $locale = array_shift($args);
     if (!AppLocale::isLocaleValid($locale)) {
         $path = array($plugin->getCategory(), $plugin->getName(), 'index');
         $request->redirect(null, null, null, null, $path);
     }
     $filename = urldecode(urldecode(array_shift($args)));
     if (!CustomLocaleAction::isLocaleFile($locale, $filename)) {
         $path = array($plugin->getCategory(), $plugin->getName(), 'edit', $locale);
         $request->redirect(null, null, null, null, $path);
     }
     $conference =& $request->getConference();
     $conferenceId = $conference->getId();
     $changes = $request->getUserVar('changes');
     $customFilesDir = Config::getVar('files', 'public_files_dir') . DIRECTORY_SEPARATOR . 'conferences' . DIRECTORY_SEPARATOR . $conferenceId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale;
     $customFilePath = $customFilesDir . DIRECTORY_SEPARATOR . $filename;
     // Create empty custom locale file if it doesn't exist
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     import('classes.i18n.EditableLocaleFile');
     if (!$fileManager->fileExists($customFilePath)) {
         $numParentDirs = substr_count($customFilePath, DIRECTORY_SEPARATOR);
         $parentDirs = '';
         for ($i = 0; $i < $numParentDirs; $i++) {
             $parentDirs .= '..' . DIRECTORY_SEPARATOR;
         }
         $newFileContents = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
         $newFileContents .= '<!DOCTYPE locale SYSTEM "' . $parentDirs . 'locale' . DIRECTORY_SEPARATOR . 'locale.dtd' . '">' . "\n";
         $newFileContents .= '<locale name="' . $locale . '">' . "\n";
         $newFileContents .= '</locale>';
         $fileManager->writeFile($customFilePath, $newFileContents);
     }
     $file = new EditableLocaleFile($locale, $customFilePath);
     while (!empty($changes)) {
         $key = array_shift($changes);
         $value = $this->correctCr(array_shift($changes));
         if (!empty($value)) {
             if (!$file->update($key, $value)) {
                 $file->insert($key, $value);
             }
         } else {
             $file->delete($key);
         }
     }
     $file->write();
     $request->redirectUrl($request->getUserVar('redirectUrl'));
 }