/**
  * @copydoc Plugin::register
  */
 function register($category, $path)
 {
     $this->pluginPath = $path;
     $result = parent::register($category, $path);
     $request = $this->getRequest();
     if ($result && $this->getEnabled() && !defined('SESSION_DISABLE_INIT')) {
         $templateManager = TemplateManager::getManager($request);
         HookRegistry::register('PageHandler::displayCss', array($this, '_displayCssCallback'));
         // Add the stylesheet.
         $dispatcher = $request->getDispatcher();
         $templateManager->addStyleSheet($dispatcher->url($request, ROUTE_COMPONENT, null, 'page.PageHandler', 'css', null, array('name' => $this->getName())), STYLE_SEQUENCE_LATE);
         // If this theme uses templates, ensure they're given priority.
         array_unshift($templateManager->template_dir, $path = Core::getBaseDir() . DIRECTORY_SEPARATOR . $this->getPluginPath() . '/templates');
     }
     return $result;
 }
 /**
  * Constructor.
  * Initialize template engine and assign basic template variables.
  * @param $request PKPRequest
  */
 function __construct($request)
 {
     assert(is_a($request, 'PKPRequest'));
     $this->_request = $request;
     parent::__construct();
     // Set up Smarty configuration
     $baseDir = Core::getBaseDir();
     $cachePath = CacheManager::getFileCachePath();
     // Set the default template dir (app's template dir)
     $this->app_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'templates';
     // Set fallback template dir (core's template dir)
     $this->core_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'templates';
     $this->template_dir = array($this->app_template_dir, $this->core_template_dir);
     $this->compile_dir = $cachePath . DIRECTORY_SEPARATOR . 't_compile';
     $this->config_dir = $cachePath . DIRECTORY_SEPARATOR . 't_config';
     $this->cache_dir = $cachePath . DIRECTORY_SEPARATOR . 't_cache';
     $this->_cacheability = CACHEABILITY_NO_STORE;
     // Safe default
 }
    /**
     * Activate the theme.
     */
    function activate(&$templateMgr)
    {
        // Resets the template directory to the files in this directory -- Credit to https://github.com/cu-library/OJS-Modern-Theme for the fix/redirection
        $templateMgr->template_dir[0] = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'ojs-bootstrapped' . DIRECTORY_SEPARATOR . 'templates';
        $templateMgr->compile_id = 'bootstrapped';
        // Add viewport
        $viewport = ' <meta name="viewport" content="width=device-width, initial-scale=1">';
        // Add Font Awesome
        $fontAwesome = ' <link rel="stylesheet" id="font-awesome-css" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" type="text/css" media="screen">';
        // Add in jQuery
        $jQuery = '	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>';
        // Selctivizr for IE Pseudo classes
        $selctivizr = '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.5.1/mootools-yui-compressed.js"></script>
						<!--[if (gte IE 6)&(lte IE 8)]>
  							<script type="text/javascript" src="assets/js/selectivizr-min.js"></script>
						<![endif]-->';
        $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
        $templateMgr->assign('additionalHeadData', $additionalHeadData . "\n" . $jQuery . "\n" . $viewport . "\n" . $fontAwesome . "\n" . $selctivizr);
        // Add Scroll2Top JS
        $templateMgr->addJavaScript($this->getPluginPath() . '/assets/js/scroll2top.js');
        // Add Modernizr JS
        $templateMgr->addJavaScript($this->getPluginPath() . '/assets/js/modernizr.js');
        // Add in Bootstrap JS
        $templateMgr->addJavaScript($this->getPluginPath() . '/components/bootstrap-sass/assets/javascripts/bootstrap.min.js');
        // Add Custom JS
        $templateMgr->addJavaScript($this->getPluginPath() . '/assets/js/custom.js');
        if (($stylesheetFilename = $this->getStylesheetFilename()) != null) {
            $path = Request::getBaseUrl() . '/' . $this->getPluginPath() . '/assets/stylesheets/' . $stylesheetFilename;
            $templateMgr->addStyleSheet($path);
        }
        // borrows logic from user block plugin to handle user dropdown
        if (!defined('SESSION_DISABLE_INIT')) {
            $session =& Request::getSession();
            $templateMgr->assign_by_ref('userSession', $session);
            $templateMgr->assign('loggedInUsername', $session->getSessionVar('username'));
        }
        $requestedPage = PKPRequest::getRequestedPage();
        if ($requestedPage == 'article') {
            $path = Request::getBaseUrl() . '/' . $this->getPluginPath() . '/assets/stylesheets/style_article.css';
            $templateMgr->addStyleSheet($path);
            $templateMgr->addJavaScript($this->getPluginPath() . '/js/article.js');
        }
    }
 /**
  * Constructor.
  * Initialize template engine and assign basic template variables.
  * @param $request PKPRequest
  */
 function PKPTemplateManager($request)
 {
     assert(is_a($request, 'PKPRequest'));
     $this->_request = $request;
     parent::Smarty();
     // Set up Smarty configuration
     $baseDir = Core::getBaseDir();
     $cachePath = CacheManager::getFileCachePath();
     // Set the default template dir (app's template dir)
     $this->app_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'templates';
     // Set fallback template dir (core's template dir)
     $this->core_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'templates';
     $this->template_dir = array($this->app_template_dir, $this->core_template_dir);
     $this->compile_dir = $cachePath . DIRECTORY_SEPARATOR . 't_compile';
     $this->config_dir = $cachePath . DIRECTORY_SEPARATOR . 't_config';
     $this->cache_dir = $cachePath . DIRECTORY_SEPARATOR . 't_cache';
     $this->_cacheability = CACHEABILITY_NO_STORE;
     // Safe default
     // Are we using implicit authentication?
     $this->assign('implicitAuth', Config::getVar('security', 'implicit_auth'));
 }
 /**
  * @copydoc Plugin::register
  */
 function register($category, $path)
 {
     if (!parent::register($category, $path)) {
         return false;
     }
     $request = $this->getRequest();
     if ($this->getEnabled() && !defined('SESSION_DISABLE_INIT')) {
         $templateManager = TemplateManager::getManager($request);
         HookRegistry::register('PageHandler::displayCss', array($this, '_displayCssCallback'));
         $context = $request->getContext();
         $site = $request->getSite();
         $contextOrSite = $context ? $context : $site;
         // Add the stylesheet.
         if ($contextOrSite->getSetting('themePluginPath') == basename($path)) {
             $dispatcher = $request->getDispatcher();
             $templateManager->addStyleSheet($dispatcher->url($request, ROUTE_COMPONENT, null, 'page.PageHandler', 'css', null, array('name' => $this->getName())), STYLE_SEQUENCE_LATE);
             // If this theme uses templates, ensure they're given priority.
             array_unshift($templateManager->template_dir, $path = Core::getBaseDir() . DIRECTORY_SEPARATOR . $this->getPluginPath() . '/templates');
         }
     }
     return true;
 }
Exemple #6
0
 /**
  * @copydoc PHPUnit_Framework_TestCase::setUp()
  */
 protected function setUp()
 {
     $this->setBackupGlobals(true);
     // Rather than using "include_once()", ADOdb uses
     // a global variable to maintain the information
     // whether its library has been included before (wtf!).
     // This causes problems with PHPUnit as PHPUnit will
     // delete all global state between two consecutive
     // tests to isolate tests from each other.
     if (function_exists('_array_change_key_case')) {
         global $ADODB_INCLUDED_LIB;
         $ADODB_INCLUDED_LIB = 1;
     }
     Config::setConfigFileName(Core::getBaseDir() . DIRECTORY_SEPARATOR . 'config.inc.php');
     // Backup DAOs.
     foreach ($this->getMockedDAOs() as $mockedDao) {
         $this->daoBackup[$mockedDao] = DAORegistry::getDAO($mockedDao);
     }
     // Backup registry keys.
     foreach ($this->getMockedRegistryKeys() as $mockedRegistryKey) {
         $this->registryBackup[$mockedRegistryKey] = Registry::get($mockedRegistryKey);
     }
 }
 function FBVTemplateManager()
 {
     parent::TemplateManager();
     $this->caching = 0;
     // look for templates in the test directory
     $baseDir = Core::getBaseDir();
     $test_template_dir = $baseDir . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'ui' . DIRECTORY_SEPARATOR . 'fbv';
     $this->template_dir[] = $test_template_dir;
     // $baseUrl has to be reset to properly reference the javascript files and stylesheets
     $baseUrl = '';
     $uriComponents = explode('/', $_SERVER['REQUEST_URI']);
     for ($i = 0, $count = count($uriComponents); $i < $count; $i++) {
         if ($uriComponents[$i] == 'tools' && $uriComponents[$i + 1] == 'fbvVisualResults.php') {
             break;
         } else {
             if (empty($uriComponents[$i])) {
                 continue;
             } else {
                 $baseUrl .= '/' . $uriComponents[$i];
             }
         }
     }
     $this->assign('baseUrl', $baseUrl);
 }
Exemple #8
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;
     }
 }
 function activate(&$templateMgr)
 {
     $templateMgr->template_dir[0] = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'modern' . DIRECTORY_SEPARATOR . 'templates';
     $templateMgr->compile_id = 'modernTheme';
 }
 function editLocaleFile($args, $request)
 {
     $this->validate();
     $plugin =& $this->plugin;
     $this->setupTemplate($request);
     $locale = array_shift($args);
     if (!AppLocale::isLocaleValid($locale)) {
         $request->redirect(null, null, 'index');
     }
     $filename = urldecode(urldecode(array_shift($args)));
     if (!TranslatorAction::isLocaleFile($locale, $filename)) {
         $request->redirect(null, null, 'edit', $locale);
     }
     $templateMgr = TemplateManager::getManager($request);
     if (!is_writeable(Core::getBaseDir() . DIRECTORY_SEPARATOR . $filename)) {
         $templateMgr->assign('error', true);
     }
     import('lib.pkp.classes.file.EditableLocaleFile');
     $localeContentsRangeInfo = $this->getRangeInfo($request, 'localeContents');
     $localeContents = EditableLocaleFile::load($filename);
     // Handle a search, if one was executed.
     $searchKey = $request->getUserVar('searchKey');
     $found = false;
     $index = 0;
     $pageIndex = 0;
     if (!empty($searchKey)) {
         foreach ($localeContents as $key => $value) {
             if ($index % $localeContentsRangeInfo->getCount() == 0) {
                 $pageIndex++;
             }
             if ($key == $searchKey) {
                 $found = true;
                 break;
             }
             $index++;
         }
     }
     if ($found) {
         $localeContentsRangeInfo->setPage($pageIndex);
         $templateMgr->assign('searchKey', $searchKey);
     }
     $templateMgr->assign('filename', $filename);
     $templateMgr->assign('locale', $locale);
     import('lib.pkp.classes.core.ArrayItemIterator');
     $templateMgr->assign('localeContents', new ArrayItemIterator($localeContents, $localeContentsRangeInfo->getPage(), $localeContentsRangeInfo->getCount()));
     $templateMgr->assign('referenceLocaleContents', EditableLocaleFile::load(TranslatorAction::determineReferenceFilename($locale, $filename)));
     $templateMgr->display($plugin->getTemplatePath() . 'localeFile.tpl');
 }
 /**
  * Get the path in which file caches will be stored.
  * @return string The full path to the file cache directory
  */
 static function getFileCachePath()
 {
     return Core::getBaseDir() . DIRECTORY_SEPARATOR . 'cache';
 }
 /**
  * Delete a plugin from the system
  * @param plugin string
  */
 function deletePlugin($plugin)
 {
     $templateMgr =& TemplateManager::getManager();
     $this->setupTemplate(true);
     $templateMgr->assign('path', 'delete');
     $templateMgr->assign('deleted', false);
     $templateMgr->assign('error', false);
     $templateMgr->assign('pageHierarchy', PluginManagementHandler::setBreadcrumbs(true));
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $installedPlugin = $versionDao->getCurrentVersion($plugin);
     $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');
 }
Exemple #13
0
 * @defgroup config
 */
/**
 * @file classes/config/Config.inc.php
 *
 * Copyright (c) 2000-2011 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class Config
 * @ingroup config
 *
 * @brief Config class for accessing configuration parameters.
 */
// $Id$
/** The path to the default configuration file */
define('CONFIG_FILE', Core::getBaseDir() . DIRECTORY_SEPARATOR . 'config.inc.php');
import('lib.pkp.classes.config.ConfigParser');
class Config
{
    /**
     * Retrieve a specified configuration variable.
     * @param $section string
     * @param $key string
     * @return string
     */
    function getVar($section, $key)
    {
        $configData =& Config::getData();
        return isset($configData[$section][$key]) ? $configData[$section][$key] : null;
    }
    /**
Exemple #14
0
 /**
  * @covers PKPPageRouter::getCacheFilename
  */
 public function testGetCacheFilenameWithoutPathinfo()
 {
     $mockApplication = $this->_setUpMockEnvironment(self::PATHINFO_DISABLED);
     $_GET = array('firstContext' => 'something', 'secondContext' => 'something', 'page' => 'index');
     $expectedId = 'something-something-index---en_US';
     self::assertEquals(Core::getBaseDir() . '/cache/wc-' . md5($expectedId) . '.html', $this->router->getCacheFilename($this->request));
 }
 /**
  * Delete a plugin from the system
  * @param $category string
  * @param $plugin string
  */
 function deletePlugin($category, $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');
     /* @var $versionDao VersionDAO */
     $installedPlugin = $versionDao->getCurrentVersion('plugins.' . $category, $plugin, true);
     if ($installedPlugin) {
         $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;
         //make sure plugin type is valid and then delete the files
         if (in_array($category, PluginRegistry::getCategories())) {
             // Delete the plugin from the file system.
             FileManager::rmtree($pluginDest);
             FileManager::rmtree($pluginLibDest);
         }
         if (is_dir($pluginDest) || is_dir($pluginLibDest)) {
             $templateMgr->assign('error', true);
             $templateMgr->assign('message', 'manager.plugins.deleteError');
         } else {
             $versionDao->disableVersion('plugins.' . $category, $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');
 }
 /**
  * Fetch the actual RSS feed
  */
 function notificationFeed($args)
 {
     if (isset($args[0]) && isset($args[1])) {
         $type = $args[0];
         $token = $args[1];
     } else {
         return false;
     }
     $this->setupTemplate(true);
     $application = PKPApplication::getApplication();
     $appName = $application->getNameKey();
     $site =& Request::getSite();
     $siteTitle = $site->getLocalizedTitle();
     $notificationDao =& DAORegistry::getDAO('NotificationDAO');
     $notificationSettingsDao =& DAORegistry::getDAO('NotificationSettingsDAO');
     $userId = $notificationSettingsDao->getUserIdByRSSToken($token);
     $notifications = $notificationDao->getByUserId($userId);
     // Make sure the feed type is specified and valid
     $typeMap = array('rss' => 'rss.tpl', 'rss2' => 'rss2.tpl', 'atom' => 'atom.tpl');
     $mimeTypeMap = array('rss' => 'application/rdf+xml', 'rss2' => 'application/rss+xml', 'atom' => 'application/atom+xml');
     if (!isset($typeMap[$type])) {
         return false;
     }
     $versionDao =& DAORegistry::getDAO('VersionDAO');
     $version = $versionDao->getCurrentVersion();
     $templateMgr =& TemplateManager::getManager();
     $templateMgr->assign('version', $version->getVersionString());
     $templateMgr->assign('selfUrl', Request::getCompleteUrl());
     $templateMgr->assign('locale', AppLocale::getPrimaryLocale());
     $templateMgr->assign('appName', $appName);
     $templateMgr->assign('siteTitle', $siteTitle);
     $templateMgr->assign_by_ref('notifications', $notifications->toArray());
     $templateMgr->display(Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'notification' . DIRECTORY_SEPARATOR . $typeMap[$type], $mimeTypeMap[$type]);
     return true;
 }
 * Core web application concerns such as routing, dispatching, etc.
 */
/**
 * @file classes/core/Core.inc.php
 *
 * Copyright (c) 2014-2016 Simon Fraser University Library
 * Copyright (c) 2000-2016 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class Core
 * @ingroup core
 *
 * @brief Class containing system-wide functions.
 */
define('PKP_LIB_PATH', 'lib' . DIRECTORY_SEPARATOR . 'pkp');
define('USER_AGENTS_FILE', Core::getBaseDir() . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . 'registry' . DIRECTORY_SEPARATOR . 'botAgents.txt');
class Core
{
    /** @var array The regular expressions that will find a bot user agent */
    static $botRegexps = array();
    /**
     * Get the path to the base installation directory.
     * @return string
     */
    static function getBaseDir()
    {
        static $baseDir;
        if (!isset($baseDir)) {
            // Need to change if the index file moves
            $baseDir = dirname(INDEX_FILE_LOCATION);
        }
Exemple #18
0
 /**
  * Return the canonical template path of this plug-in
  * @param $inCore Return the core template path if true.
  * @return string
  */
 function getTemplatePath($inCore = false)
 {
     $basePath = Core::getBaseDir();
     if ($inCore) {
         $basePath = $basePath . DIRECTORY_SEPARATOR . PKP_LIB_PATH;
     }
     return "file:{$basePath}" . DIRECTORY_SEPARATOR . $this->getPluginPath() . DIRECTORY_SEPARATOR;
 }
 /**
  * Delete plugin.
  * @param $args array
  * @param $request PKPRequest
  * @return JSONMessage JSON object
  */
 function deletePlugin($args, $request)
 {
     $plugin = $this->getAuthorizedContextObject(ASSOC_TYPE_PLUGIN);
     $category = $plugin->getCategory();
     $productName = basename($plugin->getPluginPath());
     $versionDao = DAORegistry::getDAO('VersionDAO');
     /* @var $versionDao VersionDAO */
     $installedPlugin = $versionDao->getCurrentVersion('plugins.' . $category, $productName, true);
     $notificationMgr = new NotificationManager();
     $user = $request->getUser();
     if ($installedPlugin) {
         $pluginDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $productName;
         $pluginLibDest = Core::getBaseDir() . DIRECTORY_SEPARATOR . PKP_LIB_PATH . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $category . DIRECTORY_SEPARATOR . $productName;
         // make sure plugin type is valid and then delete the files
         if (in_array($category, PluginRegistry::getCategories())) {
             // Delete the plugin from the file system.
             $fileManager = new FileManager();
             $fileManager->rmtree($pluginDest);
             $fileManager->rmtree($pluginLibDest);
         }
         if (is_dir($pluginDest) || is_dir($pluginLibDest)) {
             $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('manager.plugins.deleteError', array('pluginName' => $plugin->getDisplayName()))));
         } else {
             $versionDao->disableVersion('plugins.' . $category, $productName);
             $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('manager.plugins.deleteSuccess', array('pluginName' => $plugin->getDisplayName()))));
         }
     } else {
         $notificationMgr->createTrivialNotification($user->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('manager.plugins.doesNotExist', array('pluginName' => $plugin->getDisplayName()))));
     }
     return DAO::getDataChangedEvent($plugin->getName());
 }
Exemple #20
0
 /**
  * Add scripts contained in scripts/ subdirectory to a string to be returned to callback func.
  * @param baseUrl string
  * @param scripts array All enabled scripts for this page
  * @return string
  */
 function addScripts($baseUrl, $scripts)
 {
     $scriptOpen = '	<script language="javascript" type="text/javascript" src="';
     $scriptClose = '"></script>';
     $returner = '';
     foreach ($scripts as $script) {
         if (file_exists(Core::getBaseDir() . DIRECTORY_SEPARATOR . $script)) {
             $returner .= $scriptOpen . $baseUrl . '/' . $script . $scriptClose . "\n";
         }
     }
     return $returner;
 }
Exemple #21
0
$sessionManager =& SessionManager::getManager();
$userSession =& $sessionManager->getUserSession();
$user =& $userSession->getUser();
// Insert system variables into associative array to be used by iBrowser
$init['publicDir'] = Config::getVar('files', 'public_files_dir');
if (isset($user)) {
    // User is logged in
    $init['user'] = $user->getUsername();
    //$init['lang'] = String::substr(Locale::getLocale(), 0, 2);
    $init['lang'] = 'en';
    $init['baseUrl'] = Config::getVar('general', 'base_url');
    $init['baseDir'] = $baseDir;
    $application = PKPApplication::getApplication();
    $contextDepth = $application->getContextDepth();
    $params = array();
    for ($i = 0; $i < $contextDepth; $i++) {
        array_push($params, 'index');
    }
    array_push($params, 'user');
    array_push($params, 'viewCaptcha');
    $url = call_user_func_array(array('Request', 'url'), $params);
    $init['captchaPath'] = str_replace('/lib/pkp/lib/tinymce/jscripts/tiny_mce/plugins/ibrowser', '', $url);
} else {
    // User is not logged in; they may only enter a URL for image upload
    // Insert into array to be used by the config script
    $init['user'] = null;
    $init['lang'] = 'en';
    $init['baseUrl'] = Config::getVar('general', 'base_url');
    $init['baseDir'] = Core::getBaseDir();
    $init['captchaPath'] = null;
}
 /**
  * Return list of stopwords.
  * FIXME Should this be locale-specific?
  * @return array with stopwords as keys
  */
 function &loadStopwords()
 {
     static $searchStopwords;
     if (!isset($searchStopwords)) {
         // Load stopwords only once per request (FIXME Cache?)
         $searchStopwords = array_count_values(array_filter(file(Core::getBaseDir() . '/lib/pkp/registry/stopwords.txt'), create_function('&$a', 'return ($a = trim($a)) && !empty($a) && $a[0] != \'#\';')));
         $searchStopwords[''] = 1;
     }
     return $searchStopwords;
 }
Exemple #23
0
 /**
  * Get the base path to be used for file references
  *
  * @param $path string An optional path to append to the base
  * @return string
  */
 public function _getBaseDir($path = '')
 {
     $path = empty($path) ? '' : DIRECTORY_SEPARATOR . $path;
     return Core::getBaseDir() . DIRECTORY_SEPARATOR . $this->getPluginPath() . $path;
 }
<?php

/**
 * @file classes/file/PKPFileDAO.inc.php
 *
 * Copyright (c) 2003-2011 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class PKPFileDAO
 * @ingroup file
 * @see PKPFile
 *
 * @brief Abstract base class for retrieving and modifying PKPFile
 * objects and their decendents
 */
define('INLINEABLE_TYPES_FILE', Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'registry' . DIRECTORY_SEPARATOR . 'inlineTypes.txt');
class PKPFileDAO extends DAO
{
    /**
     * @var array a private list of MIME types that can be shown inline
     *  in the browser
     */
    var $_inlineableTypes;
    /**
     * Constructor
     */
    function PKPFileDAO()
    {
        return parent::DAO();
    }
    //
Exemple #25
0
 /**
  * @covers Config::getConfigFileName
  */
 public function testGetDefaultConfigFileName()
 {
     $expectedResult = Core::getBaseDir() . DIRECTORY_SEPARATOR . 'config.inc.php';
     self::assertEquals($expectedResult, Config::getConfigFileName());
 }
Exemple #26
0
 /**
  * Check whether a file may be displayed inline.
  * @param $paperFile object
  * @return boolean
  */
 function isInlineable(&$paperFile)
 {
     if (!isset($this->inlineableTypes)) {
         $this->inlineableTypes = array_filter(file(Core::getBaseDir() . '/lib/pkp/registry/inlineTypes.txt'), create_function('&$a', 'return ($a = trim($a)) && !empty($a) && $a[0] != \'#\';'));
     }
     return in_array($paperFile->getFileType(), $this->inlineableTypes);
 }
Exemple #27
0
 /**
  * @copydoc PKPRouter::getCacheFilename()
  */
 function getCacheFilename($request)
 {
     if (!isset($this->_cacheFilename)) {
         if ($request->isPathInfoEnabled()) {
             $id = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : 'index';
             $id .= '-' . AppLocale::getLocale();
         } else {
             $id = '';
             $application = $this->getApplication();
             foreach ($application->getContextList() as $contextName) {
                 $id .= $request->getUserVar($contextName) . '-';
             }
             $id .= $request->getUserVar('page') . '-' . $request->getUserVar('op') . '-' . $request->getUserVar('path') . '-' . AppLocale::getLocale();
         }
         $path = Core::getBaseDir();
         $this->_cacheFilename = $path . '/cache/wc-' . md5($id) . '.html';
     }
     return $this->_cacheFilename;
 }
 /**
  * SCENARIO: execution environment check
  *   GIVEN I am in an environment that does not allow
  *         script execution
  *    WHEN I open up the lucene plugin settings page
  *    THEN I'll see an explanatory text that lists all
  *         measures users may take to enable server
  *         administration from the web interface.
  */
 public function testExecutionEnvironmentCheck()
 {
     // Assemble a command line script name.
     $scriptName = Core::getBaseDir() . '/plugins/generic/lucene/embedded/bin/start.sh';
     if (Core::isWindows()) {
         $scriptName = str_replace(array('/', '.sh'), array(DIRECTORY_SEPARATOR, '.bat'), $scriptName);
     }
     // Change the execution flags of the script.
     if (Core::isWindows()) {
         $targetName = $scriptName . '.bak';
         rename($scriptName, $targetName);
         self::assertFalse(is_readable($scriptName));
     } else {
         chmod($scriptName, 0664);
         self::assertFalse(is_executable($scriptName));
     }
     // Open the lucene plugin settings page.
     $this->logIn();
     $this->verifyAndOpen($this->_pluginSettings . '#indexAdmin');
     // Check that the explanatory text is shown.
     $this->waitForElementPresent('serverNotAvailable');
     // Change the execution flag back/rename back. (We should
     // probably do this in tearDown() but let's try
     // to limit the exposure of such a statement to
     // as little code as possible. We can still change
     // this if it turns out to produce errors in
     // practice.)
     if (Core::isWindows()) {
         rename($targetName, $scriptName);
     } else {
         chmod($scriptName, 0775);
     }
 }
 /**
  * Constructor.
  * Initialize template engine and assign basic template variables.
  * @param $request PKPRequest FIXME: is optional for backwards compatibility only - make mandatory
  */
 function PKPTemplateManager($request = null)
 {
     // FIXME: for backwards compatibility only - remove
     if (!isset($request)) {
         if (Config::getVar('debug', 'deprecation_warnings')) {
             trigger_error('Deprecated function call.');
         }
         $request =& Registry::get('request');
     }
     assert(is_a($request, 'PKPRequest'));
     // Retrieve the router
     $router =& $request->getRouter();
     assert(is_a($router, 'PKPRouter'));
     parent::Smarty();
     // Set up Smarty configuration
     $baseDir = Core::getBaseDir();
     $cachePath = CacheManager::getFileCachePath();
     // Set the default template dir (app's template dir)
     $this->app_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'templates';
     // Set fallback template dir (core's template dir)
     $this->core_template_dir = $baseDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'templates';
     $this->template_dir = array($this->app_template_dir, $this->core_template_dir);
     $this->compile_dir = $cachePath . DIRECTORY_SEPARATOR . 't_compile';
     $this->config_dir = $cachePath . DIRECTORY_SEPARATOR . 't_config';
     $this->cache_dir = $cachePath . DIRECTORY_SEPARATOR . 't_cache';
     // Assign common variables
     $this->styleSheets = array();
     $this->assign_by_ref('stylesheets', $this->styleSheets);
     $this->javaScripts = array();
     $this->cacheability = CACHEABILITY_NO_STORE;
     // Safe default
     $this->assign('defaultCharset', Config::getVar('i18n', 'client_charset'));
     $this->assign('basePath', $request->getBasePath());
     $this->assign('baseUrl', $request->getBaseUrl());
     $this->assign('requiresFormRequest', $request->isPost());
     if (is_a($router, 'PKPPageRouter')) {
         $this->assign('requestedPage', $router->getRequestedPage($request));
     }
     $this->assign('currentUrl', $request->getCompleteUrl());
     $this->assign('dateFormatTrunc', Config::getVar('general', 'date_format_trunc'));
     $this->assign('dateFormatShort', Config::getVar('general', 'date_format_short'));
     $this->assign('dateFormatLong', Config::getVar('general', 'date_format_long'));
     $this->assign('datetimeFormatShort', Config::getVar('general', 'datetime_format_short'));
     $this->assign('datetimeFormatLong', Config::getVar('general', 'datetime_format_long'));
     $this->assign('timeFormat', Config::getVar('general', 'time_format'));
     $this->assign('allowCDN', Config::getVar('general', 'enable_cdn'));
     $this->assign('useMinifiedJavaScript', Config::getVar('general', 'enable_minified'));
     $locale = Locale::getLocale();
     $this->assign('currentLocale', $locale);
     // If there's a locale-specific stylesheet, add it.
     if (($localeStyleSheet = Locale::getLocaleStyleSheet($locale)) != null) {
         $this->addStyleSheet($request->getBaseUrl() . '/' . $localeStyleSheet);
     }
     $application =& PKPApplication::getApplication();
     $this->assign('pageTitle', $application->getNameKey());
     // Register custom functions
     $this->register_modifier('translate', array('Locale', 'translate'));
     $this->register_modifier('get_value', array(&$this, 'smartyGetValue'));
     $this->register_modifier('strip_unsafe_html', array('String', 'stripUnsafeHtml'));
     $this->register_modifier('String_substr', array('String', 'substr'));
     $this->register_modifier('to_array', array(&$this, 'smartyToArray'));
     $this->register_modifier('concat', array(&$this, 'smartyConcat'));
     $this->register_modifier('escape', array(&$this, 'smartyEscape'));
     $this->register_modifier('strtotime', array(&$this, 'smartyStrtotime'));
     $this->register_modifier('explode', array(&$this, 'smartyExplode'));
     $this->register_modifier('assign', array(&$this, 'smartyAssign'));
     $this->register_function('translate', array(&$this, 'smartyTranslate'));
     $this->register_function('flush', array(&$this, 'smartyFlush'));
     $this->register_function('call_hook', array(&$this, 'smartyCallHook'));
     $this->register_function('html_options_translate', array(&$this, 'smartyHtmlOptionsTranslate'));
     $this->register_block('iterate', array(&$this, 'smartyIterate'));
     $this->register_function('call_progress_function', array(&$this, 'smartyCallProgressFunction'));
     $this->register_function('page_links', array(&$this, 'smartyPageLinks'));
     $this->register_function('page_info', array(&$this, 'smartyPageInfo'));
     $this->register_function('get_help_id', array(&$this, 'smartyGetHelpId'));
     $this->register_function('icon', array(&$this, 'smartyIcon'));
     $this->register_function('help_topic', array(&$this, 'smartyHelpTopic'));
     $this->register_function('sort_heading', array(&$this, 'smartySortHeading'));
     $this->register_function('sort_search', array(&$this, 'smartySortSearch'));
     $this->register_function('get_debug_info', array(&$this, 'smartyGetDebugInfo'));
     $this->register_function('assign_mailto', array(&$this, 'smartyAssignMailto'));
     $this->register_function('display_template', array(&$this, 'smartyDisplayTemplate'));
     $this->register_modifier('truncate', array(&$this, 'smartyTruncate'));
     // JS UI components
     $this->register_function('modal', array(&$this, 'smartyModal'));
     $this->register_function('confirm', array(&$this, 'smartyConfirm'));
     $this->register_function('confirm_submit', array(&$this, 'smartyConfirmSubmit'));
     $this->register_function('init_tabs', array(&$this, 'smartyInitTabs'));
     $this->register_function('modal_title', array(&$this, 'smartyModalTitle'));
     // register the resource name "core"
     $this->register_resource("core", array(array(&$this, 'smartyResourceCoreGetTemplate'), array(&$this, 'smartyResourceCoreGetTimestamp'), array(&$this, 'smartyResourceCoreGetSecure'), array(&$this, 'smartyResourceCoreGetTrusted')));
     $this->register_function('url', array(&$this, 'smartyUrl'));
     // ajax load into a div
     $this->register_function('load_url_in_div', array(&$this, 'smartyLoadUrlInDiv'));
     if (!defined('SESSION_DISABLE_INIT')) {
         /**
          * Kludge to make sure no code that tries to connect to
          * the database is executed (e.g., when loading
          * installer pages).
          */
         $this->assign('isUserLoggedIn', Validation::isLoggedIn());
         $application =& PKPApplication::getApplication();
         $currentVersion =& $application->getCurrentVersion();
         $this->assign('currentVersionString', $currentVersion->getVersionString());
         $this->assign('itemsPerPage', Config::getVar('interface', 'items_per_page'));
         $this->assign('numPageLinks', Config::getVar('interface', 'page_links'));
         $user =& $request->getUser();
         if ($user) {
             $notificationDao =& DAORegistry::getDAO('NotificationDAO');
             $notifications =& $notificationDao->getNotificationsByUserId($user->getId(), NOTIFICATION_LEVEL_TRIVIAL);
             $notificationsArray =& $notifications->toArray();
             unset($notifications);
             foreach ($notificationsArray as $notification) {
                 $notificationDao->deleteNotificationById($notification->getId());
             }
             $this->assign('systemNotifications', $notificationsArray);
         }
     }
     $this->initialized = false;
 }
Exemple #30
0
/**
 * @defgroup core
 */
/**
 * @file classes/core/Core.inc.php
 *
 * Copyright (c) 2013-2015 Simon Fraser University Library
 * Copyright (c) 2000-2015 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class Core
 * @ingroup core
 *
 * @brief Class containing system-wide functions.
 */
define('USER_AGENTS_FILE', Core::getBaseDir() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pkp' . DIRECTORY_SEPARATOR . 'registry' . DIRECTORY_SEPARATOR . 'botAgents.txt');
class Core
{
    /** @var array The regular expressions that will find a bot user agent */
    static $botRegexps = array();
    /**
     * Get the path to the base installation directory.
     * @return string
     */
    function getBaseDir()
    {
        static $baseDir;
        if (!isset($baseDir)) {
            // Need to change if the index file moves
            $baseDir = dirname(INDEX_FILE_LOCATION);
        }