/**
  * Uploads a press image.
  * @param $settingName string setting key associated with the file
  * @param $locale string
  */
 function uploadImage($settingName, $locale)
 {
     $press =& Request::getPress();
     $settingsDao =& DAORegistry::getDAO('PressSettingsDAO');
     import('classes.file.PublicFileManager');
     $fileManager = new PublicFileManager();
     if ($fileManager->uploadedFileExists($settingName)) {
         $type = $fileManager->getUploadedFileType($settingName);
         $extension = $fileManager->getImageExtension($type);
         if (!$extension) {
             return false;
         }
         $uploadName = $settingName . '_' . $locale . $extension;
         if ($fileManager->uploadPressFile($press->getId(), $settingName, $uploadName)) {
             // Get image dimensions
             $filePath = $fileManager->getPressFilesPath($press->getId());
             list($width, $height) = getimagesize($filePath . '/' . $uploadName);
             $value = $press->getSetting($settingName);
             $value[$locale] = array('name' => $fileManager->getUploadedFileName($settingName, $locale), 'uploadName' => $uploadName, 'width' => $width, 'height' => $height, 'dateUploaded' => Core::getCurrentDate());
             $settingsDao->updateSetting($press->getId(), $settingName, $value, 'object', true);
             return true;
         }
     }
     return false;
 }
 /**
  * Constructor.
  * Initialize template engine and assign basic template variables.
  * @param $request PKPRequest FIXME: is optional for backwards compatibility only - make mandatory
  */
 function TemplateManager($request = null)
 {
     // FIXME: for backwards compatibility only - remove
     if (!isset($request)) {
         // FIXME: Trigger a deprecation warning when enough instances of this
         // call have been fixed to not clutter the error log.
         $request =& Registry::get('request');
     }
     assert(is_a($request, 'PKPRequest'));
     parent::PKPTemplateManager($request);
     // Retrieve the router
     $router =& $request->getRouter();
     assert(is_a($router, 'PKPRouter'));
     // Are we using implicit authentication?
     $this->assign('implicitAuth', Config::getVar('security', 'implicit_auth'));
     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).
          */
         $press =& $router->getContext($request);
         $site =& $request->getSite();
         $siteFilesDir = $request->getBaseUrl() . '/' . PublicFileManager::getSiteFilesPath();
         $this->assign('sitePublicFilesDir', $siteFilesDir);
         $this->assign('publicFilesDir', $siteFilesDir);
         // May be overridden by press
         $siteStyleFilename = PublicFileManager::getSiteFilesPath() . '/' . $site->getSiteStyleFilename();
         if (file_exists($siteStyleFilename)) {
             $this->addStyleSheet($request->getBaseUrl() . '/' . $siteStyleFilename);
         }
         $this->assign('homeContext', array());
         if (isset($press)) {
             $this->assign_by_ref('currentPress', $press);
             $pressTitle = $press->getLocalizedName();
             $this->assign('siteTitle', $pressTitle);
             $this->assign('publicFilesDir', $request->getBaseUrl() . '/' . PublicFileManager::getPressFilesPath($press->getId()));
             $this->assign('primaryLocale', $press->getPrimaryLocale());
             $this->assign('alternateLocales', $press->getSetting('alternateLocales'));
             // Assign additional navigation bar items
             $navMenuItems =& $press->getLocalizedSetting('navItems');
             $this->assign_by_ref('navMenuItems', $navMenuItems);
             // Assign press page header
             $this->assign('displayPageHeaderTitle', $press->getPressPageHeaderTitle());
             $this->assign('displayPageHeaderLogo', $press->getPressPageHeaderLogo());
             $this->assign('alternatePageHeader', $press->getLocalizedSetting('pressPageHeader'));
             $this->assign('metaSearchDescription', $press->getLocalizedSetting('searchDescription'));
             $this->assign('metaSearchKeywords', $press->getLocalizedSetting('searchKeywords'));
             $this->assign('metaCustomHeaders', $press->getLocalizedSetting('customHeaders'));
             $this->assign('numPageLinks', $press->getSetting('numPageLinks'));
             $this->assign('itemsPerPage', $press->getSetting('itemsPerPage'));
             $this->assign('enableAnnouncements', $press->getSetting('enableAnnouncements'));
             // Load and apply theme plugin, if chosen
             $themePluginPath = $press->getSetting('pressTheme');
             if (!empty($themePluginPath)) {
                 // Load and activate the theme
                 $themePlugin =& PluginRegistry::loadPlugin('themes', $themePluginPath);
                 if ($themePlugin) {
                     $themePlugin->activate($this);
                 }
             }
             // Assign stylesheets and footer
             $pressStyleSheet = $press->getSetting('pressStyleSheet');
             if ($pressStyleSheet) {
                 $this->addStyleSheet($request->getBaseUrl() . '/' . PublicFileManager::getPressFilesPath($press->getId()) . '/' . $pressStyleSheet['uploadName']);
             }
             $this->assign('pageFooter', $press->getLocalizedSetting('pressPageFooter'));
         } else {
             // Add the site-wide logo, if set for this locale or the primary locale
             $displayPageHeaderTitle = $site->getLocalizedPageHeaderTitle();
             $this->assign('displayPageHeaderTitle', $displayPageHeaderTitle);
             if (isset($displayPageHeaderTitle['altText'])) {
                 $this->assign('displayPageHeaderTitleAltText', $displayPageHeaderTitle['altText']);
             }
             $this->assign('siteTitle', $site->getLocalizedTitle());
         }
         if (!$site->getRedirect()) {
             $this->assign('hasOtherPresses', true);
         }
     }
 }
 /**
  * Delete a press.
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function deleteContext($args, $request)
 {
     // Identify the current context.
     $context = $request->getContext();
     // Identify the press Id.
     $pressId = $request->getUserVar('rowId');
     $pressDao = DAORegistry::getDAO('PressDAO');
     $press = $pressDao->getById($pressId);
     if ($pressId) {
         $pressDao->deleteById($pressId);
         // Add publication formats tombstones for all press published monographs.
         import('classes.publicationFormat.PublicationFormatTombstoneManager');
         $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
         $publicationFormatTombstoneMgr->insertTombstonesByPress($press);
         // Delete press file tree
         // FIXME move this somewhere better.
         import('lib.pkp.classes.file.ContextFileManager');
         $pressFileManager = new ContextFileManager($pressId);
         $pressFileManager->rmtree($pressFileManager->getBasePath());
         import('classes.file.PublicFileManager');
         $publicFileManager = new PublicFileManager();
         $publicFileManager->rmtree($publicFileManager->getPressFilesPath($pressId));
         // If user is deleting the same press where he is...
         if ($context && $context->getId() == $pressId) {
             // return a redirect js event to index handler.
             $dispatcher = $request->getDispatcher();
             $url = $dispatcher->url($request, ROUTE_PAGE, null, 'index');
             return $request->redirectUrlJson($url);
         }
         return DAO::getDataChangedEvent($pressId);
     }
     return new JSONMessage();
 }
 /**
  * Delete a press.
  * @param $args array first parameter is the ID of the press to delete
  */
 function deletePress($args)
 {
     $this->validate();
     $pressDao =& DAORegistry::getDAO('PressDAO');
     if (isset($args) && !empty($args) && !empty($args[0])) {
         $pressId = $args[0];
         if ($pressDao->deletePressById($pressId)) {
             // Delete press file tree
             // FIXME move this somewhere better.
             import('lib.pkp.classes.file.FileManager');
             $fileManager = new FileManager();
             $pressPath = Config::getVar('files', 'files_dir') . '/presses/' . $pressId;
             $fileManager->rmtree($pressPath);
             import('classes.file.PublicFileManager');
             $publicFileManager = new PublicFileManager();
             $publicFileManager->rmtree($publicFileManager->getPressFilesPath($pressId));
         }
     }
     Request::redirect(null, null, 'presses');
 }
 function _handleOmpUrl($matchArray)
 {
     $request = Application::getRequest();
     $url = $matchArray[2];
     $anchor = null;
     if (($i = strpos($url, '#')) !== false) {
         $anchor = substr($url, $i + 1);
         $url = substr($url, 0, $i);
     }
     $urlParts = explode('/', $url);
     if (isset($urlParts[0])) {
         switch (strtolower_codesafe($urlParts[0])) {
             case 'press':
                 $url = $request->url(isset($urlParts[1]) ? $urlParts[1] : $request->getRequestedPressPath(), null, null, null, null, $anchor);
                 break;
             case 'monograph':
                 if (isset($urlParts[1])) {
                     $url = $request->url(null, 'catalog', 'book', $urlParts[1], null, $anchor);
                 }
                 break;
             case 'sitepublic':
                 array_shift($urlParts);
                 import('classes.file.PublicFileManager');
                 $publicFileManager = new PublicFileManager();
                 $url = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath() . '/' . implode('/', $urlParts) . ($anchor ? '#' . $anchor : '');
                 break;
             case 'public':
                 array_shift($urlParts);
                 $press = $request->getPress();
                 import('classes.file.PublicFileManager');
                 $publicFileManager = new PublicFileManager();
                 $url = $request->getBaseUrl() . '/' . $publicFileManager->getPressFilesPath($press->getId()) . '/' . implode('/', $urlParts) . ($anchor ? '#' . $anchor : '');
                 break;
         }
     }
     return $matchArray[1] . $url . $matchArray[3];
 }