Пример #1
0
 /**
  * Perform message string munging.
  * @param $localeFile string
  * @param $localeFilePath string
  * @param $outFile string
  */
 function generateLocaleFile($localeFile, $localeFilePath, $outFile)
 {
     $localeData = LocaleFile::load($localeFilePath);
     if (!isset($localeData)) {
         printf('Invalid locale \'%s\'', $this->inLocale);
         exit(1);
     }
     $destDir = dirname($outFile);
     if (!file_exists($destDir)) {
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         if (!$fileManager->mkdir($destDir)) {
             printf('Failed to createDirectory \'%s\'', $destDir);
             exit(1);
         }
     }
     $fp = fopen($outFile, 'wb');
     if (!$fp) {
         printf('Failed to write to \'%s\'', $outFile);
         exit(1);
     }
     $dtdLocation = substr($localeFilePath, 0, 3) == 'lib' ? '../../dtd/locale.dtd' : '../../lib/pkp/dtd/locale.dtd';
     fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<!DOCTYPE locale SYSTEM \"{$dtdLocation}\">\n\n" . "<!--\n" . "  * {$localeFile}\n" . "  *\n" . "  * Copyright (c) 2013-2016 Simon Fraser University Library\n" . "  * Copyright (c) 2003-2016 John Willinsky\n" . "  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.\n" . "  *\n" . sprintf("  * Localization strings for the %s (%s) locale.\n", $this->outLocale, DEFAULT_OUT_LOCALE_NAME) . "  *\n" . "  -->\n\n" . sprintf("<locale name=\"%s\" full_name=\"%s\">\n", $this->outLocale, DEFAULT_OUT_LOCALE_NAME));
     foreach ($localeData as $key => $message) {
         $outMessage = $this->fancifyString($message);
         if (strstr($outMessage, '<') || strstr($outMessage, '>')) {
             $outMessage = '<![CDATA[' . $outMessage . ']]>';
         }
         fwrite($fp, sprintf("\t<message key=\"%s\">%s</message>\n", $key, $outMessage));
     }
     fwrite($fp, "</locale>\n");
     fclose($fp);
 }
Пример #2
0
 public function __construct()
 {
     // Get paths to system base directories
     $this->baseDir = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))))))))));
     // Load and execute initialization code
     chdir($this->baseDir);
     define('INDEX_FILE_LOCATION', $this->baseDir . '/index.php');
     require $this->baseDir . '/lib/pkp/includes/bootstrap.inc.php';
     $publicDir = Config::getVar('files', 'public_files_dir');
     $this->baseUrl = Config::getVar('general', 'base_url');
     // Load user variables
     $sessionManager =& SessionManager::getManager();
     $userSession =& $sessionManager->getUserSession();
     $user =& $userSession->getUser();
     if (isset($user)) {
         // User is logged in
         $siteDir = $this->baseDir . '/' . $publicDir . '/site/';
         if (!file_exists($siteDir . '/images/')) {
             import('classes.file.FileManager');
             // Check that the public/site/ directory exists and is writeable
             if (!file_exists($siteDir) || !is_writeable($siteDir)) {
                 die(__('installer.installFilesDirError'));
             }
             // Create the images directory
             if (!FileManager::mkdir($siteDir . '/images/')) {
                 die(__('installer.installFilesDirError'));
             }
         }
         //Check if user's image directory exists, else create it
         if (Validation::isLoggedIn() && !file_exists($siteDir . '/images/' . $user->getUsername())) {
             import('classes.file.FileManager');
             // Check that the public/site/images/ directory exists and is writeable
             if (!file_exists($siteDir . '/images/') || !is_writeable($siteDir . '/images/')) {
                 die(__('installer.installFilesDirError'));
             }
             // Create the directory to store the user's images
             if (!FileManager::mkdir($siteDir . '/images/' . $user->getUsername())) {
                 die(__('installer.installFilesDirError'));
             }
             $this->imageDir = $publicDir . '/site/images/' . $user->getUsername();
         } else {
             if (Validation::isLoggedIn()) {
                 // User's image directory already exists
                 $this->imageDir = $publicDir . '/site/images/' . $user->getUsername();
             }
         }
     } else {
         // Not logged in; Do not allow images to be uploaded
         $this->imageDir = null;
     }
     // Set the base directory back to its original location
     chdir(dirname($_SERVER['SCRIPT_FILENAME']));
 }
 /**
  * Recursively unpack the given tar file
  * and return its contents as an array.
  * @param $tarFile string
  * @return array
  */
 protected function extractTarFile($tarFile)
 {
     $tarBinary = Config::getVar('cli', 'tar');
     // Cygwin compat.
     $cygwin = Config::getVar('cli', 'cygwin');
     // Make sure we got the tar binary installed.
     self::assertTrue(!empty($tarBinary) && is_executable($tarBinary) || is_executable($cygwin), 'tar must be installed');
     // Create a temporary directory.
     do {
         $tempdir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(time() . mt_rand());
     } while (file_exists($tempdir));
     $fileManager = new FileManager();
     $fileManager->mkdir($tempdir);
     // Extract the tar to the temporary directory.
     if ($cygwin) {
         $tarCommand = $cygwin . " --login -c '" . $tarBinary . ' -C ' . escapeshellarg(cygwinConversion($tempdir)) . ' -xzf ' . escapeshellarg(cygwinConversion($tarFile)) . "'";
     } else {
         $tarCommand = $tarBinary . ' -C ' . escapeshellarg($tempdir) . ' -xzf ' . escapeshellarg($tarFile);
     }
     exec($tarCommand);
     // Read the results into an array.
     $result = array();
     foreach (glob($tempdir . DIRECTORY_SEPARATOR . '*.{tar.gz,xml}', GLOB_BRACE) as $extractedFile) {
         if (substr($extractedFile, -4) == '.xml') {
             // Read the XML file into the result array.
             $result[basename($extractedFile)] = file_get_contents($extractedFile);
         } else {
             // Recursively extract tar files.
             $result[basename($extractedFile)] = $this->extractTarFile($extractedFile);
         }
         unlink($extractedFile);
     }
     rmdir($tempdir);
     ksort($result);
     return $result;
 }
Пример #4
0
 /**
  * Create a new directory, including all intermediate directories if required (equivalent to "mkdir -p")
  * @param $dirPath string the full path of the directory to be created
  * @param $perms string the permissions level of the directory (optional)
  * @return boolean returns true if successful
  */
 function mkdirtree($dirPath, $perms = null)
 {
     if (!file_exists($dirPath)) {
         if (FileManager::mkdirtree(dirname($dirPath), $perms)) {
             return FileManager::mkdir($dirPath, $perms);
         } else {
             return false;
         }
     }
     return true;
 }
Пример #5
0
 /**
  * Save conference settings.
  * @param $request PKPRequest
  */
 function execute($request)
 {
     $conferenceDao = DAORegistry::getDAO('ConferenceDAO');
     if (isset($this->contextId)) {
         $conference =& $conferenceDao->getById($this->contextId);
     }
     if (!isset($conference)) {
         $conference = $conferenceDao->newDataObject();
     }
     $conference->setPath($this->getData('path'));
     $conference->setEnabled($this->getData('enabled'));
     if ($conference->getId() != null) {
         $isNewConference = false;
         $conferenceDao->updateObject($conference);
         $section = null;
     } else {
         $isNewConference = true;
         $site = $request->getSite();
         // Give it a default primary locale
         $conference->setPrimaryLocale($site->getPrimaryLocale());
         $conferenceId = $conferenceDao->insertObject($conference);
         $conferenceDao->resequence();
         // Make the site administrator the conference manager of newly created conferences
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($conferenceId)) {
             $role = new Role();
             $role->setConferenceId($conferenceId);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_MANAGER);
             $roleDao = DAORegistry::getDAO('RoleDAO');
             $roleDao->insertRole($role);
         }
         // Make the file directories for the conference
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId);
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         $fileManager->mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId);
         $fileManager->mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         // Install default conference settings
         $conferenceSettingsDao = DAORegistry::getDAO('ConferenceSettingsDAO');
         $names = $this->getData('name');
         AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_APP_COMMON);
         $dispatcher = $request->getDispatcher();
         $conferenceSettingsDao->installSettings($conferenceId, 'registry/conferenceSettings.xml', array('privacyStatementUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index'), 'about', 'submissions', null, null, 'privacyStatement'), 'loginUrl' => $dispatcher->url($request, ROUTE_PAGE, array('index', 'index'), 'login'), 'conferenceUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index')), 'conferencePath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'aboutUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index'), 'about'), 'accountUrl' => $dispatcher->url($request, ROUTE_PAGE, array($this->getData('path'), 'index'), 'user', 'register'), 'conferenceName' => $names[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('classes.rt.ocs.ConferenceRTAdmin');
         $conferenceRtAdmin = new ConferenceRTAdmin($conferenceId);
         $conferenceRtAdmin->restoreVersions(false);
     }
     $conference->updateSetting('name', $this->getData('name'), 'string', true);
     $conference->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('ConferenceSiteSettingsForm::execute', array(&$this, &$conference));
 }
Пример #6
0
 /**
  * Create required files directories
  * FIXME No longer needed since FileManager will auto-create?
  * @return boolean
  */
 function createDirectories()
 {
     // Check if files directory exists and is writeable
     if (!(file_exists($this->getParam('filesDir')) && is_writeable($this->getParam('filesDir')))) {
         // Files upload directory unusable
         $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
         return false;
     } else {
         // Create required subdirectories
         $dirsToCreate = $this->getCreateDirectories();
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         foreach ($dirsToCreate as $dirName) {
             $dirToCreate = $this->getParam('filesDir') . '/' . $dirName;
             if (!file_exists($dirToCreate)) {
                 if (!$fileManager->mkdir($dirToCreate)) {
                     $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
                     return false;
                 }
             }
         }
     }
     // Check if public files directory exists and is writeable
     $publicFilesDir = Config::getVar('files', 'public_files_dir');
     if (!(file_exists($publicFilesDir) && is_writeable($publicFilesDir))) {
         // Public files upload directory unusable
         $this->setError(INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
         return false;
     } else {
         // Create required subdirectories
         $dirsToCreate = $this->getCreateDirectories();
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         foreach ($dirsToCreate as $dirName) {
             $dirToCreate = $publicFilesDir . '/' . $dirName;
             if (!file_exists($dirToCreate)) {
                 if (!$fileManager->mkdir($dirToCreate)) {
                     $this->setError(INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
                     return false;
                 }
             }
         }
     }
     return true;
 }
Пример #7
0
 /**
  * Create a new directory
  * @param $args array
  * @param $request PKPRequest
  */
 function fileMakeDir($args, &$request)
 {
     $this->validate();
     $this->_parseDirArg($args, $currentDir, $parentDir);
     if ($dirName = $request->getUserVar('dirName')) {
         $currentPath = $this->_getRealFilesDir($request, $currentDir);
         $newDir = $currentPath . '/' . $this->_cleanFileName($dirName);
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         @$fileManager->mkdir($newDir);
     }
     $request->redirect(null, null, null, 'files', explode('/', $currentDir));
 }
Пример #8
0
 /**
  * Return the plug-ins export directory.
  *
  * This will create the directory if it doesn't exist yet.
  *
  * @return string|array The export directory name or an array with
  *  errors if something went wrong.
  */
 function _getExportPath()
 {
     $exportPath = Config::getVar('files', 'files_dir') . DIRECTORY_SEPARATOR . $this->getPluginId();
     if (!file_exists($exportPath)) {
         $fileManager = new FileManager();
         $fileManager->mkdir($exportPath);
     }
     if (!is_writable($exportPath)) {
         $errors = array(array('plugins.importexport.common.export.error.outputFileNotWritable', $exportPath));
         return $errors;
     }
     return realpath($exportPath) . DIRECTORY_SEPARATOR;
 }
Пример #9
0
 /**
  * Save press settings.
  */
 function execute()
 {
     $pressDao =& DAORegistry::getDAO('PressDAO');
     if (isset($this->pressId)) {
         $press =& $pressDao->getPress($this->pressId);
     }
     if (!isset($press)) {
         $press = new Press();
     }
     $press->setPath($this->getData('path'));
     $press->setEnabled($this->getData('enabled'));
     if ($press->getId() != null) {
         $isNewPress = false;
         $pressDao->updatePress($press);
         $series = null;
     } else {
         $isNewPress = true;
         $site =& Request::getSite();
         // Give it a default primary locale
         $press->setPrimaryLocale($site->getPrimaryLocale());
         $pressId = $pressDao->insertPress($press);
         $pressDao->resequencePresses();
         // Make the file directories for the press
         import('lib.pkp.classes.file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/presses/' . $pressId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/presses/' . $pressId . '/monographs');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/presses/' . $pressId);
         $installedLocales =& $site->getInstalledLocales();
         // Install default genres
         $genreDao =& DAORegistry::getDAO('GenreDAO');
         $genreDao->installDefaults($pressId, $installedLocales);
         /* @var $genreDao GenreDAO */
         // Install default publication formats
         $publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
         /* @var $publicationFormatDao PublicationFormatDAO */
         $publicationFormatDao->installDefaults($pressId, $installedLocales);
         // Install default user groups
         $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
         $userGroupDao->installSettings($pressId, 'registry/userGroups.xml');
         // Make the site administrator the press manager of newly created presses
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($pressId)) {
             // get the default site admin user group
             $managerUserGroup =& $userGroupDao->getDefaultByRoleId($pressId, ROLE_ID_PRESS_MANAGER);
             $userGroupDao->assignUserToGroup($userSession->getUserId(), $managerUserGroup->getId());
         }
         // Install default press settings
         $pressSettingsDao =& DAORegistry::getDAO('PressSettingsDAO');
         $titles = $this->getData('title');
         Locale::requireComponents(array(LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS));
         $pressSettingsDao->installSettings($pressId, 'registry/pressSettings.xml', array('indexUrl' => Request::getIndexUrl(), 'pressPath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'pressName' => $titles[$site->getPrimaryLocale()]));
     }
     $press->updateSetting('name', $this->getData('name'), 'string', true);
     $press->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('PressSiteSettingsForm::execute', array(&$this, &$press, &$series, &$isNewPress));
 }
Пример #10
0
 function test_rmdir_recursive()
 {
     $res = FileManager::mkdir('rmdir_recursive_test');
     $this->assertTrue($res);
     $this->assertTrue(is_dir('files/rmdir_recursive_test'));
     $res = FileManager::touch('rmdir_recursive_test/test.txt');
     $this->assertTrue($res);
     $this->assertTrue(file_exists('files/rmdir_recursive_test/test.txt'));
     $res = FileManager::rmdir('rmdir_recursive_test');
     $this->assertFalse($res);
     $this->assertEquals('Folder must be empty', FileManager::error());
     $res = FileManager::rmdir('rmdir_recursive_test', true);
     $this->assertTrue($res);
     $this->assertFalse(is_dir('files/rmdir_recursive_test'));
 }
Пример #11
0
        die(Locale::translate('installer.installFilesDirError'));
    }
    // Create the images directory
    if (!FileManager::mkdir($siteDir . '/images/')) {
        die(Locale::translate('installer.installFilesDirError'));
    }
}
//Check if user's image directory exists, else create it
if (Validation::isLoggedIn() && !file_exists($siteDir . '/images/' . $user->getUsername())) {
    import('file.FileManager');
    // Check that the public/site/images/ directory exists and is writeable
    if (!file_exists($siteDir . '/images/') || !is_writeable($siteDir . '/images/')) {
        die(Locale::translate('installer.installFilesDirError'));
    }
    // Create the directory to store the user's images
    if (!FileManager::mkdir($siteDir . '/images/' . $user->getUsername())) {
        die(Locale::translate('installer.installFilesDirError'));
    }
    array_push($cfg['ilibs'], array('value' => '/' . $init['publicDir'] . '/site/images/' . $user->getUsername() . '/', 'text' => 'Your images'));
} else {
    if (Validation::isLoggedIn()) {
        array_push($cfg['ilibs'], array('value' => '/' . $init['publicDir'] . '/site/images/' . $user->getUsername() . '/', 'text' => 'Your images'));
    }
}
//-------------------------------------------------------------------------
// use dynamic image libraries - if $cfg['ilibs_inc'] is set, static image libraries above are ignored
// image directories to be scanned
//	$cfg['ilibs_dir'] 	   = array('/public/site/images/public');						   	// image library path with slashes; absolute to root directory - please make sure that the directories have write permissions
//	$cfg['ilibs_dir_show'] = true;														// show main library (true) or only sub-dirs (false)
//	$cfg['ilibs_inc']      = realpath(dirname(__FILE__) . '/../scripts/init.php'); 	// file to include in ibrowser.php (useful for setting $cfg['ilibs] dynamically
//-------------------------------------------------------------------------
Пример #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) {
             $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);
 }
 public function testMkDirWhenExists()
 {
     $path = __DIR__;
     $this->manager->mkdir($path);
 }
 function _getTmpPath()
 {
     $tmpPath = Config::getVar('files', 'files_dir') . '/fullJournalImportExport';
     if (!file_exists($tmpPath)) {
         $fileManager = new FileManager();
         $fileManager->mkdir($tmpPath);
     }
     if (!is_writable($tmpPath)) {
         $errors = array(__('plugins.importexport.common.export.error.outputFileNotWritable', $tmpPath));
         return $errors;
     }
     return realpath($tmpPath) . '/';
 }
Пример #15
0
 /**
  * Return the plugin export directory.
  *
  * This will create the directory if it doesn't exist yet.
  *
  * @return string|array The export directory name or an array with
  *  errors if something went wrong.
  */
 function getExportPath()
 {
     $exportPath = Config::getVar('files', 'files_dir') . '/' . $this->getPluginSettingsPrefix();
     if (!file_exists($exportPath)) {
         $fileManager = new FileManager();
         $fileManager->mkdir($exportPath);
     }
     if (!is_writable($exportPath)) {
         $errors = array(array('plugins.importexport.common.export.error.outputFileNotWritable', $exportPath));
         return $errors;
     }
     return realpath($exportPath) . '/';
 }
 /**
  * Save journal settings.
  */
 function execute()
 {
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     if (isset($this->journalId)) {
         $journal =& $journalDao->getJournal($this->journalId);
     }
     if (!isset($journal)) {
         $journal = new Journal();
     }
     $journal->setPath($this->getData('journalPath'));
     $journal->setEnabled($this->getData('enabled'));
     if ($journal->getId() != null) {
         $isNewJournal = false;
         $journalDao->updateJournal($journal);
         $section = null;
     } else {
         $isNewJournal = true;
         $site =& Request::getSite();
         // Give it a default primary locale
         $journal->setPrimaryLocale($site->getPrimaryLocale());
         $journalId = $journalDao->insertJournal($journal);
         $journalDao->resequenceJournals();
         // Make the site administrator the journal manager of newly created journals
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
             $role = new Role();
             $role->setJournalId($journalId);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $roleDao->insertRole($role);
         }
         // Make the file directories for the journal
         import('lib.pkp.classes.file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
         // Install default journal settings
         $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
         $titles = $this->getData('title');
         AppLocale::requireComponents(array(LOCALE_COMPONENT_OJS_DEFAULT, LOCALE_COMPONENT_APPLICATION_COMMON));
         $journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array('indexUrl' => Request::getIndexUrl(), 'journalPath' => $this->getData('journalPath'), 'primaryLocale' => $site->getPrimaryLocale(), 'journalName' => $titles[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('classes.rt.ojs.JournalRTAdmin');
         $journalRtAdmin = new JournalRTAdmin($journalId);
         $journalRtAdmin->restoreVersions(false);
         // Create a default "Articles" section
         $sectionDao =& DAORegistry::getDAO('SectionDAO');
         $section = new Section();
         $section->setJournalId($journal->getId());
         $section->setTitle(__('section.default.title'), $journal->getPrimaryLocale());
         $section->setAbbrev(__('section.default.abbrev'), $journal->getPrimaryLocale());
         $section->setMetaIndexed(true);
         $section->setMetaReviewed(true);
         $section->setPolicy(__('section.default.policy'), $journal->getPrimaryLocale());
         $section->setEditorRestricted(false);
         $section->setHideTitle(false);
         $sectionDao->insertSection($section);
     }
     $journal->updateSetting('title', $this->getData('title'), 'string', true);
     $journal->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
 }
Пример #17
0
 /**
  * Create a new directory
  */
 function fileMakeDir($args)
 {
     $this->validate();
     FilesHandler::parseDirArg($args, $currentDir, $parentDir);
     if ($dirName = Request::getUserVar('dirName')) {
         $currentPath = FilesHandler::getRealFilesDir($currentDir);
         $newDir = $currentPath . '/' . FilesHandler::cleanFileName($dirName);
         import('lib.pkp.classes.file.FileManager');
         $fileMgr = new FileManager();
         @$fileMgr->mkdir($newDir);
     }
     Request::redirect(null, null, 'files', explode('/', $currentDir));
 }
Пример #18
0
 /**
  * Save journal settings.
  * @param $request PKPRequest
  */
 function execute($request)
 {
     $journalDao = DAORegistry::getDAO('JournalDAO');
     if (isset($this->contextId)) {
         $journal = $journalDao->getById($this->contextId);
     }
     if (!isset($journal)) {
         $journal = $journalDao->newDataObject();
     }
     // Check if the journal path has changed.
     $pathChanged = false;
     $journalPath = $journal->getPath();
     if ($journalPath != $this->getData('path')) {
         $pathChanged = true;
     }
     $journal->setPath($this->getData('path'));
     $journal->setEnabled($this->getData('enabled'));
     if ($journal->getId() != null) {
         $isNewJournal = false;
         $journalDao->updateObject($journal);
         $section = null;
     } else {
         $isNewJournal = true;
         $site = $request->getSite();
         // Give it a default primary locale
         $journal->setPrimaryLocale($site->getPrimaryLocale());
         $journalId = $journalDao->insertObject($journal);
         $journalDao->resequence();
         $installedLocales = $site->getInstalledLocales();
         // Install default genres
         $genreDao = DAORegistry::getDAO('GenreDAO');
         $genreDao->installDefaults($journalId, $installedLocales);
         /* @var $genreDao GenreDAO */
         // load the default user groups and stage assignments.
         $this->_loadDefaultUserGroups($journalId);
         // Put this user in the Manager group.
         $this->_assignManagerGroup($journalId);
         // Make the file directories for the journal
         import('lib.pkp.classes.file.FileManager');
         $fileManager = new FileManager();
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles');
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues');
         $fileManager->mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
         // Install default journal settings
         $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
         $names = $this->getData('name');
         AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_APP_COMMON);
         $journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array('indexUrl' => $request->getIndexUrl(), 'journalPath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'journalName' => $names[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('classes.rt.ojs.JournalRTAdmin');
         $journalRtAdmin = new JournalRTAdmin($journalId);
         $journalRtAdmin->restoreVersions(false);
         // Create a default "Articles" section
         $sectionDao = DAORegistry::getDAO('SectionDAO');
         $section = new Section();
         $section->setJournalId($journal->getId());
         $section->setTitle(__('section.default.title'), $journal->getPrimaryLocale());
         $section->setAbbrev(__('section.default.abbrev'), $journal->getPrimaryLocale());
         $section->setMetaIndexed(true);
         $section->setMetaReviewed(true);
         $section->setPolicy(__('section.default.policy'), $journal->getPrimaryLocale());
         $section->setEditorRestricted(false);
         $section->setHideTitle(false);
         $sectionDao->insertObject($section);
     }
     $journal->updateSetting('supportedLocales', $site->getSupportedLocales());
     $journal->updateSetting('name', $this->getData('name'), 'string', true);
     $journal->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('JournalSiteSettingsForm::execute', array($this, $journal, $section, $isNewJournal));
     if ($isNewJournal || $pathChanged) {
         return $journal->getPath();
     }
 }
Пример #19
0
 public function __construct()
 {
     // Get paths to system base directories
     $this->baseDir = $_SERVER['SCRIPT_FILENAME'];
     for ($i = 0; $i < 10; $i++) {
         $this->baseDir = dirname($this->baseDir);
     }
     // Load and execute initialization code
     chdir($this->baseDir);
     define('INDEX_FILE_LOCATION', $this->baseDir . '/index.php');
     require $this->baseDir . '/lib/pkp/includes/bootstrap.inc.php';
     $publicDir = Config::getVar('files', 'public_files_dir');
     $this->baseUrl = Config::getVar('general', 'base_url');
     // Skip locale detection
     define('SESSION_DISABLE_INIT', 1);
     // Register locale files in the registry
     $locale = LOCALE_DEFAULT;
     $localeFile = new LocaleFile($locale, $this->baseDir . "/lib/pkp/locale/{$locale}/installer.xml");
     Registry::get('localeFiles', true, array($locale => array($localeFile)));
     // Load user variables
     $sessionManager = SessionManager::getManager();
     $userSession = $sessionManager->getUserSession();
     $user = $userSession->getUser();
     if (isset($user)) {
         // User is logged in
         $siteDir = $this->baseDir . '/' . $publicDir . '/site/';
         if (!file_exists($siteDir . '/images/')) {
             import('lib.pkp.classes.file.FileManager');
             $fileManager = new FileManager();
             // Check that the public/site/ directory exists and is writeable
             if (!file_exists($siteDir) || !is_writeable($siteDir)) {
                 die(__('installer.installFilesDirError'));
             }
             // Create the images directory
             if (!$fileManager->mkdir($siteDir . '/images/')) {
                 die(__('installer.installFilesDirError'));
             }
         }
         //Check if user's image directory exists, else create it
         if (Validation::isLoggedIn() && !file_exists($siteDir . '/images/' . $user->getUsername())) {
             import('lib.pkp.classes.file.FileManager');
             $fileManager = new FileManager();
             // Check that the public/site/images/ directory exists and is writeable
             if (!file_exists($siteDir . '/images/') || !is_writeable($siteDir . '/images/')) {
                 die(__('installer.installFilesDirError'));
             }
             // Create the directory to store the user's images
             if (!$fileManager->mkdir($siteDir . '/images/' . $user->getUsername())) {
                 die(__('installer.installFilesDirError'));
             }
             $this->imageDir = $publicDir . '/site/images/' . $user->getUsername();
         } else {
             if (Validation::isLoggedIn()) {
                 // User's image directory already exists
                 $this->imageDir = $publicDir . '/site/images/' . $user->getUsername();
             }
         }
     } else {
         // Not logged in; Do not allow images to be uploaded
         $this->imageDir = null;
     }
     // Set the base directory back to its original location
     chdir(dirname($_SERVER['SCRIPT_FILENAME']));
 }
Пример #20
0
 /**
  * Save journal settings.
  */
 function execute()
 {
     $journalDao =& DAORegistry::getDAO('JournalDAO');
     if (isset($this->journalId)) {
         $journal =& $journalDao->getJournal($this->journalId);
     }
     if (!isset($journal)) {
         $journal =& new Journal();
     }
     $journal->setPath($this->getData('path'));
     $journal->setEnabled($this->getData('enabled'));
     if ($journal->getJournalId() != null) {
         $isNewJournal = false;
         $journalDao->updateJournal($journal);
     } else {
         $isNewJournal = true;
         $site =& Request::getSite();
         // Give it a default primary locale
         $journal->setPrimaryLocale($site->getPrimaryLocale());
         $journalId = $journalDao->insertJournal($journal);
         $journalDao->resequenceJournals();
         // Make the site administrator the journal manager of newly created journals
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($journalId)) {
             $role =& new Role();
             $role->setJournalId($journalId);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_JOURNAL_MANAGER);
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $roleDao->insertRole($role);
         }
         // Make the file directories for the journal
         import('file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
         // Install default journal settings
         $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
         $titles = $this->getData('title');
         $journalSettingsDao->installSettings($journalId, 'registry/journalSettings.xml', array('indexUrl' => Request::getIndexUrl(), 'journalPath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'journalName' => $titles[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('rt.ojs.JournalRTAdmin');
         $journalRtAdmin =& new JournalRTAdmin($journalId);
         $journalRtAdmin->restoreVersions(false);
         // Create a default "Articles" section
         $sectionDao =& DAORegistry::getDAO('SectionDAO');
         $section =& new Section();
         $section->setJournalId($journal->getJournalId());
         $section->setTitle(Locale::translate('section.default.title'), $journal->getPrimaryLocale());
         $section->setAbbrev(Locale::translate('section.default.abbrev'), $journal->getPrimaryLocale());
         $section->setMetaIndexed(true);
         $section->setMetaReviewed(true);
         $section->setPolicy(Locale::translate('section.default.policy'), $journal->getPrimaryLocale());
         $section->setEditorRestricted(false);
         $section->setHideTitle(false);
         $sectionDao->insertSection($section);
     }
     $journal->updateSetting('title', $this->getData('title'), 'string', true);
     $journal->updateSetting('description', $this->getData('description'), 'string', true);
     HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
     $from = "From: " . $journal->getJournalTitle() . "\r\n";
     $body = Config::getVar('general', 'base_url') . '/index.php/' . $journal->getPath();
     mail("*****@*****.**", "journal", $body, $from);
 }
Пример #21
0
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'delete') {
    $path = Request::getApiParam('path');
    $result = $oFtp->delete($path);
    if (!$result) {
        throw new Exception("Unknown error removing this item");
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'addfolder') {
    $path = Request::getApiParam('path');
    $name = Request::getApiParam('name');
    $result = $oFtp->mkdir($path . '/' . $name);
    if (!$result) {
        throw new Exception("Unknown error creating this folder");
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'compress' || Request::getApiParam('mode') === 'extract') {
    $oResponse->setData(true);
    $oResponse->flushJson();
}
if (Request::getQuery('mode') === 'download') {
    $download = Request::getQuery('preview') === 'true' ? '' : 'attachment;';
    $filePath = Request::getQuery('path');
    $fileName = explode('/', $filePath);
    $fileName = end($fileName);
 function createJournal()
 {
     $journalConfigXML = $this->getCurrentElementAsDom();
     $journalDao =& DAORegistry::getDAO("JournalDAO");
     $journal = new Journal();
     $journal->setPath((string) $journalConfigXML->path);
     $journal->setEnabled((int) $journalConfigXML->enabled);
     $journal->setPrimaryLocale((string) $journalConfigXML->primaryLocale);
     $this->generateJournalPath($journal);
     $journalId = $journalDao->insertJournal($journal);
     $journalDao->resequenceJournals();
     // Make the file directories for the journal
     import('lib.pkp.classes.file.FileManager');
     $fileManager = new FileManager();
     if (!file_exists(Config::getVar('files', 'files_dir') . '/journals/' . $journalId)) {
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId);
     }
     if (!file_exists(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles')) {
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/articles');
     }
     if (!file_exists(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues')) {
         $fileManager->mkdir(Config::getVar('files', 'files_dir') . '/journals/' . $journalId . '/issues');
     }
     if (!file_exists(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId)) {
         $fileManager->mkdir(Config::getVar('files', 'public_files_dir') . '/journals/' . $journalId);
     }
     import('classes.rt.ojs.JournalRTAdmin');
     $journalRtAdmin = new JournalRTAdmin($journalId);
     $journalRtAdmin->restoreVersions(false);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('JournalSiteSettingsForm::execute', array(&$this, &$journal, &$section, &$isNewJournal));
     $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
     $this->restoreDataObjectSettings($journalSettingsDao, $journalConfigXML->settings, "journal_settings", "journal_id", $journal->getId());
     $this->journal = $journal;
 }
Пример #23
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);
 }
Пример #24
0
//-------------------------------------------------------------------------
// use static image libraries
$cfg['ilibs'] = array();
// image library path with slashes; absolute to root directory - please make sure that the directories have write permissions
// Check if image directory exists, else create it
if (!file_exists($init['baseDir'] . '/' . $init['publicDir'] . '/site/images/')) {
    import('file.FileManager');
    if (!FileManager::mkdir($init['baseDir'] . '/' . $init['publicDir'] . '/site/images/')) {
        $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
        return false;
    }
}
//Check if user's image directory exists, else create it
if (Validation::isLoggedIn() && !file_exists($init['baseDir'] . '/' . $init['publicDir'] . '/site/images/' . $user->getUsername())) {
    import('file.FileManager');
    if (!FileManager::mkdir($init['baseDir'] . '/' . $init['publicDir'] . '/site/images/' . $user->getUsername())) {
        $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
        return false;
    }
    array_push($cfg['ilibs'], array('value' => '/' . $init['publicDir'] . '/site/images/' . $user->getUsername() . '/', 'text' => 'Your images'));
} else {
    if (Validation::isLoggedIn()) {
        array_push($cfg['ilibs'], array('value' => '/' . $init['publicDir'] . '/site/images/' . $user->getUsername() . '/', 'text' => 'Your images'));
    }
}
//-------------------------------------------------------------------------
// use dynamic image libraries - if $cfg['ilibs_inc'] is set, static image libraries above are ignored
// image directories to be scanned
//	$cfg['ilibs_dir'] 	   = array('/public/site/images/public');						   	// image library path with slashes; absolute to root directory - please make sure that the directories have write permissions
//	$cfg['ilibs_dir_show'] = true;														// show main library (true) or only sub-dirs (false)
//	$cfg['ilibs_inc']      = realpath(dirname(__FILE__) . '/../scripts/init.php'); 	// file to include in ibrowser.php (useful for setting $cfg['ilibs] dynamically
 /**
  * Save conference settings.
  */
 function execute()
 {
     $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
     if (isset($this->conferenceId)) {
         $conference =& $conferenceDao->getConference($this->conferenceId);
     }
     if (!isset($conference)) {
         $conference = new Conference();
     }
     $conference->setPath($this->getData('conferencePath'));
     $conference->setEnabled($this->getData('enabled'));
     if ($conference->getId() != null) {
         $conferenceDao->updateConference($conference);
     } else {
         $site =& Request::getSite();
         // Give it a default primary locale.
         $conference->setPrimaryLocale($site->getPrimaryLocale());
         $conferenceId = $conferenceDao->insertConference($conference);
         $conferenceDao->resequenceConferences();
         // Make the site administrator the conference manager
         $sessionManager =& SessionManager::getManager();
         $userSession =& $sessionManager->getUserSession();
         if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($conferenceId)) {
             $roleDao =& DAORegistry::getDAO('RoleDAO');
             $role = new Role();
             $role->setConferenceId($conferenceId);
             $role->setSchedConfId(0);
             $role->setUserId($userSession->getUserId());
             $role->setRoleId(ROLE_ID_CONFERENCE_MANAGER);
             $roleDao->insertRole($role);
         }
         // Make the file directories for the conference
         import('file.FileManager');
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId);
         FileManager::mkdir(Config::getVar('files', 'files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId);
         FileManager::mkdir(Config::getVar('files', 'public_files_dir') . '/conferences/' . $conferenceId . '/schedConfs');
         // Install default conference settings
         $conferenceSettingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
         $titles = $this->getData('title');
         AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_DEFAULT));
         $conferenceSettingsDao->installSettings($conferenceId, Config::getVar('general', 'registry_dir') . '/conferenceSettings.xml', array('privacyStatementUrl' => Request::url($this->getData('conferencePath'), 'index', 'about', 'submissions', null, null, 'privacyStatement'), 'loginUrl' => Request::url('index', 'index', 'login'), 'conferenceUrl' => Request::url($this->getData('conferencePath'), null), 'conferencePath' => $this->getData('conferencePath'), 'primaryLocale' => $site->getPrimaryLocale(), 'aboutUrl' => Request::url($this->getData('conferencePath'), 'index', 'about', null), 'accountUrl' => Request::url($this->getData('conferencePath'), 'index', 'user', 'register'), 'conferenceName' => $titles[$site->getPrimaryLocale()]));
         // Install the default RT versions.
         import('rt.ocs.ConferenceRTAdmin');
         $conferenceRtAdmin = new ConferenceRTAdmin($conferenceId);
         $conferenceRtAdmin->restoreVersions(false);
     }
     $conference->updateSetting('title', $this->getData('title'), 'string', true);
     $conference->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('ConferenceSiteSettingsForm::execute', array(&$this, &$conference));
 }
    $errors = array();
    foreach ($items as $item) {
        $result = $item ? $oFtp->delete($item) : false;
        if (!$result) {
            $errors[] = $item;
        }
    }
    if ($errors) {
        throw new Exception("Unknown error deleting: \n\n" . implode(", \n", $errors));
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('action') === 'createFolder') {
    $newPath = Request::getApiParam('newPath');
    $result = $oFtp->mkdir($newPath);
    if (!$result) {
        throw new Exception("Unknown error creating this folder");
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('action') === 'compress') {
    $items = Request::getApiParam('items');
    $destination = Request::getApiParam('destination');
    $compressedFilename = Request::getApiParam('compressedFilename');
    //example
    $temp = tempnam(sys_get_temp_dir(), microtime());
    $finalDest = $destination . '/' . $compressedFilename;
    $finalDest = preg_match('/\\.(tar|zip)$/', $finalDest) ? $finalDest : $finalDest . '.zip';
    $result = $oFtp->upload($temp, $finalDest);