Example #1
0
 public function __invoke(Request $request, \Page $page)
 {
     $app = $this->app;
     $pageRevision = $page->getPageRevision();
     // @todo: these are currently unused :S
     $vars = array();
     $options = array();
     // Find language
     $language = $page->getInheritedProperty('Language');
     $fallbackLanguage = $app['fallbackLanguage'];
     if (!$language && $fallbackLanguage) {
         $app->logger->debug('Using fallback language');
         $language = $fallbackLanguage;
     }
     // Set language
     if ($language) {
         $locale = \Curry_Language::setLanguage($language);
         $language = \Curry_Language::getLanguage();
         if ($language) {
             $app->logger->debug('Current language is now ' . $language->getName() . ' (with locale ' . $locale . ')');
         }
     } else {
         $app->logger->debug('Language not set for page');
     }
     // Attempt to render page
     $app->logger->debug('Showing page ' . $page->getName() . ' (PageRevisionId: ' . $pageRevision->getPageRevisionId() . ')');
     $generator = AbstractGenerator::create($app, $pageRevision);
     return $generator->render($vars, $options);
 }
Example #2
0
 /**
  * Sets the currently active language.
  * 
  * This also attempts to change the locale to langcode.UTF-8
  * 
  * @param string|Language $language Specifies the language, either langcode using a string or a Language instance.
  * @param bool $setlocale If true, an attempt to set the locale using setlocale() is done.
  * @return null|string	Returns the system locale.
  */
 public static function setLanguage($language, $setlocale = true)
 {
     $locale = null;
     if (is_string($language)) {
         self::$currentLanguage = LanguageQuery::create()->findPk($language);
     } else {
         self::$currentLanguage = $language;
     }
     if ($setlocale && self::$currentLanguage) {
         $locale = setlocale(LC_ALL, self::getLangCode() . '.UTF-8', self::getLangCode() . '.UTF8');
     }
     return $locale;
 }
Example #3
0
 /** {@inheritdoc} */
 public function toTwig()
 {
     $r = $this->getRequest();
     $luceneIndex = Curry_Core::getSearchIndex();
     $vars = array();
     $vars['Total'] = $luceneIndex->numDocs();
     if (isset($r->get['query'])) {
         $query = trim($r->get['query']);
         $hits = $luceneIndex->find($query);
         if ($this->alwaysWildcard && count($hits) === 0) {
             $hits = $luceneIndex->find($query . '*');
         }
         $tmp = array();
         if ($this->onlyThisLanguage) {
             foreach ($hits as $hit) {
                 try {
                     if ($hit->locale == Curry_Language::getLangCode()) {
                         $tmp[] = $hit;
                     }
                 } catch (Zend_Search_Lucene_Exception $e) {
                     $tmp[] = $hit;
                 }
             }
             $hits = $tmp;
         }
         $vars['Query'] = $query;
         $vars['NumHits'] = count($hits);
         $vars['hits'] = new Curry_Twig_CollectionWrapper($hits, array($this, 'getHitProperties'));
     }
     return $vars;
 }
Example #4
0
 /**
  * Global helper function for getting language variables. Alias for Curry_Language::get().
  *
  * @param string $variableName
  * @param string|Language|null $language
  * @return string|null
  */
 function L($variableName, $language = null)
 {
     return \Curry_Language::get($variableName, $language);
 }
 /**
  * Get an array of Curry\Module\PageModuleWrapper objects for all modules on the PageRevision we are rendering.
  *
  * @return \Curry\Module\PageModuleWrapper[]
  */
 protected function getPageModuleWrappers()
 {
     $langcode = (string) \Curry_Language::getLangCode();
     $cacheName = md5(__CLASS__ . '_ModuleWrappers_' . $this->pageRevision->getPageRevisionId() . '_' . $langcode);
     if (($moduleWrappers = $this->app->cache->load($cacheName)) === false) {
         $moduleWrappers = $this->pageRevision->getPageModuleWrappers($langcode);
         $this->app->cache->save($moduleWrappers, $cacheName);
     }
     return $moduleWrappers;
 }
Example #6
0
 /**
  * Render the specified page revision.
  *
  * @param PageRevision $pageRevision
  * @param Curry_Request $request
  * @param array $vars
  * @param array $options
  */
 protected function render(PageRevision $pageRevision, Curry_Request $request, array $vars, array $options)
 {
     Curry_Core::log('Showing page ' . $pageRevision->getPage()->getName() . ' (PageRevisionId: ' . $pageRevision->getPageRevisionId() . ')', Zend_Log::NOTICE);
     $time = microtime(true);
     $queries = Curry_Propel::getQueryCount();
     $cacheName = __CLASS__ . '_Page_' . md5($request->getUri());
     $cacheLifetime = $pageRevision->getPage()->getCacheLifetime();
     $doCache = $request->getMethod() === 'GET' && $cacheLifetime !== 0;
     if ($doCache) {
         ob_start();
     }
     $generator = self::createPageGenerator($pageRevision, $request);
     $generator->display($vars, $options);
     if ($doCache) {
         $cache = array('page_id' => $pageRevision->getPageId(), 'page_revision_id' => $pageRevision->getPageRevisionId(), 'headers' => headers_list(), 'content' => ob_get_flush());
         Curry_Core::$cache->save($cache, $cacheName, array(), $cacheLifetime < 0 ? false : $cacheLifetime);
     }
     if (Curry_Core::$config->curry->updateTranslationStrings) {
         Curry_Language::updateLanguageStrings();
     }
     $time = microtime(true) - $time;
     $queries = $queries !== null ? Curry_Propel::getQueryCount() - $queries : null;
     Curry_Core::triggerHook('Curry_Application::render', $pageRevision->getPageId(), $pageRevision->getPageRevisionId(), $time, $queries);
 }
Example #7
0
 /**
  * Shows the backend. This is the main method of this class.
  */
 public function show()
 {
     $twig = $this->getTwig();
     $templateFile = 'main.html';
     $backendList = null;
     // Set content-type with charset (some webservers may otherwise override the charset)
     $encoding = Curry_Core::$config->curry->outputEncoding;
     header("Content-type: text/html; charset=" . $encoding);
     $htmlHead = $this->getHtmlHead();
     $htmlHead->addStylesheet('shared/css/icons.css');
     $htmlHead->addScript('shared/libs/jquery-ui-1.8.17/js/jquery-1.7.1.min.js');
     $htmlHead->addScript('shared/backend/common/js/core.js');
     $htmlHead->addScript('shared/backend/common/js/plugins.js');
     $htmlHead->addScript('shared/backend/common/js/main.js');
     $htmlHead->addScript('shared/backend/common/js/finder.js');
     $htmlHead->addScript('shared/js/URI.js');
     // Project backend css/js
     if (file_exists(Curry_Core::$config->curry->wwwPath . '/css/backend.css')) {
         $htmlHead->addStylesheet('css/backend.css');
     }
     if (file_exists(Curry_Core::$config->curry->wwwPath . '/js/backend.js')) {
         $htmlHead->addScript('js/backend.js');
     }
     // Set language
     if (Curry_Core::$config->curry->fallbackLanguage) {
         Curry_Language::setLanguage(Curry_Core::$config->curry->fallbackLanguage);
     }
     // Globals
     $twig->addGlobal('ProjectName', Curry_Core::$config->curry->name);
     $twig->addGlobal('Encoding', $encoding);
     $twig->addGlobal('Version', Curry_Core::VERSION);
     // Logotype
     if (Curry_Core::$config->curry->backend->logotype) {
         $twig->addGlobal('Logotype', Curry_Core::$config->curry->backend->logotype);
     }
     // Current module
     $currentModule = 'Curry_Backend_Page';
     if (isset($_GET['module'])) {
         $currentModule = $_GET['module'];
     }
     if (Curry_Core::$config->curry->setup) {
         if ($currentModule !== 'Curry_Backend_Setup') {
             url('', array('module' => 'Curry_Backend_Setup'))->redirect();
         }
         if (!class_exists('User')) {
             eval("class User { public static function getUser(){ return new self; } public function hasAccess() { return true; } public function getName() { return 'Dummy'; } }");
         } else {
             User::dummyAuth();
         }
         $backendList = array('Curry_Backend_Setup' => 'Setup');
     } else {
         if (Curry_Core::$config->curry->backend->noauth) {
             User::dummyAuth();
         }
     }
     $user = User::getUser();
     if (!$user) {
         $loginRedirect = '';
         if (isset($_POST['login_redirect'])) {
             $loginRedirect = $_POST['login_redirect'];
         } else {
             if (!isset($_GET['logout']) && count($_GET)) {
                 $loginRedirect = (string) url('', $_GET);
             }
         }
         $twig->addGlobal('LoginRedirect', $loginRedirect);
         $this->addBodyClass('tpl-login');
         $templateFile = 'login.html';
     } else {
         $twig->addGlobal('user', array('Name' => $user->getName()));
         // Current module
         if ($backendList === null) {
             $backendList = Curry_Backend::getBackendList();
         }
         if ($currentModule != 'Curry_Backend_Setup') {
             unset($backendList['Curry_Backend_Setup']);
         }
         if (!array_key_exists($currentModule, $backendList)) {
             throw new Exception('Backend module "' . $currentModule . '" not found');
         }
         // Do we need to upgrade?
         $systemModules = array('Curry_Backend_System', 'Curry_Backend_Database', 'Curry_Backend_Setup');
         if (Curry_Core::requireMigration() && !in_array($currentModule, $systemModules)) {
             url('', array('module' => 'Curry_Backend_System', 'view' => 'Upgrade'))->redirect();
         }
         // Modules
         $backendGroups = array('Content' => array(), 'Appearance' => array(), 'Accounts' => array(), 'System' => array());
         foreach ($backendList as $module => $moduleName) {
             if (!$user->hasAccess($module)) {
                 continue;
             }
             $group = "Other";
             if (method_exists($module, 'getGroup')) {
                 $group = call_user_func(array($module, 'getGroup'));
             }
             $name = $moduleName;
             if (method_exists($module, 'getName')) {
                 $n = call_user_func(array($module, 'getName'));
                 if ($n) {
                     $name = $n;
                 }
             }
             $message = '';
             if (method_exists($module, 'getMessage')) {
                 $message = call_user_func(array($module, 'getMessage'));
             }
             $notifications = '';
             if (method_exists($module, 'getNotifications')) {
                 try {
                     $notifications = call_user_func(array($module, 'getNotifications'));
                     if (!isset($backendGroups[$group]['Notifications'])) {
                         $backendGroups[$group]['Notifications'] = 0;
                     }
                     $backendGroups[$group]['Notifications'] += (int) $notifications;
                 } catch (Exception $e) {
                 }
             }
             $moduleProperties = array('Module' => $module, 'Active' => $module === $currentModule, 'Url' => url('', array("module" => $module)), 'Name' => $name, 'Title' => $message, 'Notifications' => $notifications);
             if ($group) {
                 if (!isset($backendGroups[$group])) {
                     $backendGroups[$group] = array();
                 }
                 if (!isset($backendGroups[$group]['modules'])) {
                     $backendGroups[$group]['modules'] = array();
                 }
                 $backendGroups[$group]['modules'][$module] = $moduleProperties;
                 $backendGroups[$group]['Name'] = $group;
                 $backendGroups[$group]['Active'] = $module == $currentModule;
             }
             if ($module == $currentModule) {
                 $twig->addGlobal('module', $moduleProperties);
             }
         }
         $twig->addGlobal('moduleGroups', $backendGroups);
         if ($currentModule && class_exists($currentModule)) {
             if ($user->hasAccess($currentModule)) {
                 $this->backend = new $currentModule($this);
                 if ($this->backend) {
                     if (!in_array($currentModule, $systemModules)) {
                         if (self::isPropelBuildInvalid()) {
                             $this->backend->addMessage('Propel has been upgraded and you need to rebuild your database, use <a href="' . url('', array('module' => 'Curry_Backend_Database', 'view' => 'Propel')) . '">auto rebuild</a>.', Curry_Backend::MSG_WARNING, false);
                         }
                         if (Curry_Core::$config->curry->backend->noauth) {
                             $this->backend->addMessage('Authorization has been disabled for backend. You can re-enable it if you go to <a href="' . url('', array('module' => 'Curry_Backend_System')) . '">System Settings</a>.', Curry_Backend::MSG_WARNING, false);
                         }
                         if (Curry_Core::$config->curry->maintenance->enabled) {
                             $this->backend->addMessage('Site has been disabled for maintenance. You can re-enable it in <a href="' . url('', array('module' => 'Curry_Backend_System')) . '">System Settings</a>.', Curry_Backend::MSG_WARNING, false);
                         }
                         $this->doAutoBackup();
                     }
                     $twig->addGlobal('content', $this->backend->show());
                 }
             } else {
                 header('HTTP/1.1 403 Forbidden');
                 header('Status: 403 Forbidden');
                 $twig->addGlobal('content', 'Access denied');
             }
         }
     }
     // Finalize HtmlHead and add global
     $htmlHead->addInlineScript('$.registerLibrary(' . Zend_Json::encode($this->libraries, false, array('enableJsonExprFinder' => true)) . ');');
     $twig->addGlobal('HtmlHead', $htmlHead->getContent());
     $twig->addGlobal('BodyClass', $this->getBodyClass());
     // Render template
     $template = $twig->loadTemplate($templateFile);
     $template->display(array());
 }