示例#1
0
 /**
  * Create the Curry_Module instance from the serialized data.
  *
  * @param bool $inherited
  * @return Curry_Module
  */
 public function createObject($inherited = true)
 {
     // Make sure the module class exists
     $className = $this->getClassName();
     if (!class_exists($className)) {
         throw new Exception("Module class '{$className}' not found.");
     }
     // Get the module data
     $moduleDataId = null;
     if (!$inherited) {
         $moduleData = $this->getModuleData();
         $data = $moduleData->getData();
         $moduleDataId = $moduleData->getModuleDataId();
     } else {
         $data = $this->data;
         $moduleDataId = $this->dataSourceId;
     }
     // Create instance
     $obj = null;
     if ($data !== null) {
         try {
             $obj = unserialize($data);
             if ($obj && !$obj instanceof $className) {
                 trace_warning('Module class mismatch ' . $className);
                 $obj = null;
             }
         } catch (Exception $e) {
             trace_warning('Failed to unserialize module of class ' . $className);
         }
     }
     if (!$obj) {
         $obj = new $className();
     }
     $obj->setModuleDataId($moduleDataId);
     return $obj;
 }
示例#2
0
 protected static function getReleases()
 {
     try {
         // Override user agent
         $opts = array('http' => array('header' => "User-Agent: CurryCMS/" . Curry_Core::VERSION . " (http://currycms.com)\r\n"));
         $context = stream_context_create($opts);
         $tags = file_get_contents('https://api.github.com/repos/bombayworks/currycms/tags', null, $context);
         $tags = json_decode($tags);
         $versions = array();
         foreach ($tags as $tag) {
             if (preg_match('/^v?([\\d\\.]+.*)$/', strtolower($tag->name), $m)) {
                 $tag->version = $m[1];
                 $versions[$m[1]] = $tag;
             }
         }
         uksort($versions, 'version_compare');
         return $versions;
     } catch (Exception $e) {
         trace_warning('Failed to fetch release list: ' . $e->getMessage());
         return null;
     }
 }
示例#3
0
 /**
  * Return content to browser.
  *
  * @param string $content
  */
 protected function sendContent($content)
 {
     $internalEncoding = Curry_Core::$config->curry->internalEncoding;
     $outputEncoding = $this->getOutputEncoding();
     if ($outputEncoding && $internalEncoding != $outputEncoding) {
         trace_warning('Converting output from internal coding');
         $content = iconv($internalEncoding, $outputEncoding . "//TRANSLIT", $content);
     }
     echo $content;
 }
示例#4
0
 /**
  * Handle the specified request.
  *
  * @param Curry_Request $request
  */
 public function handle(Curry_Request $request)
 {
     trace_notice('Starting request at ' . $request->getUri());
     if (Curry_Core::$config->curry->autoPublish) {
         $this->autoPublish();
     }
     $page = null;
     $vars = array('curry' => array());
     $options = array();
     $forceShow = false;
     $showWorking = false;
     if (Curry_Core::$config->curry->setup) {
         die('Site is not yet configured, go to admin.php and configure your site.');
     }
     // check if we have a valid backend-user logged in
     $validUser = !!User::getUser();
     if ($validUser) {
         // check for inline-admin
         $adminNamespace = new Zend_Session_Namespace('Curry_Admin');
         if (Curry_Core::$config->curry->liveEdit && !$request->getParam('curry_force_show')) {
             if ($request->hasParam('curry_inline_admin')) {
                 $adminNamespace->inlineAdmin = $request->getParam('curry_inline_admin') ? true : false;
             }
             if ($adminNamespace->inlineAdmin) {
                 $options['inlineAdmin'] = true;
                 $forceShow = true;
                 $showWorking = true;
                 Curry_InlineAdmin::$active = true;
             }
         }
         // show working revision? (default is published)
         if ($request->getParam('curry_show_working')) {
             $forceShow = true;
             $showWorking = true;
         }
         // show inactive pages?
         if ($request->getParam('curry_force_show')) {
             $forceShow = true;
         }
         if ($showWorking) {
             Page::setRevisionType(Page::WORKING_REVISION);
         }
     }
     // Maintenance enabled?
     if (Curry_Core::$config->curry->maintenance->enabled && !$forceShow) {
         Curry_Core::log("Maintenance enabled");
         header('HTTP/1.1 503 Service Temporarily Unavailable');
         header('Status: 503 Service Temporarily Unavailable');
         header('Retry-After: 3600');
         $message = 'Page is down for maintenance, please check back later.';
         if (Curry_Core::$config->curry->maintenance->message) {
             $message = Curry_Core::$config->curry->maintenance->message;
         }
         $page = Curry_Core::$config->curry->maintenance->page;
         if ($page !== null) {
             $page = PageQuery::create()->findPk((int) $page);
         }
         if (!$page) {
             die($message);
         }
         $vars['curry']['MaintenanceMessage'] = $message;
     }
     // Check force domain?
     if (Curry_Core::$config->curry->forceDomain && !$forceShow) {
         $uri = $request->getUri();
         $url = parse_url(Curry_Core::$config->curry->baseUrl);
         if (strcasecmp($_SERVER['HTTP_HOST'], $url['host']) !== 0) {
             $location = substr(Curry_Core::$config->curry->baseUrl, 0, -1) . $uri;
             header("Location: " . $location, true, 301);
             exit;
         }
     }
     // Parameters to show a single module
     if ($request->getParam('curry_show_page_module_id')) {
         $options['pageModuleId'] = $request->getParam('curry_show_page_module_id');
     }
     if (isAjax() && $request->getParam('curry_ajax_page_module_id')) {
         $options['pageModuleId'] = $request->getParam('curry_ajax_page_module_id');
     }
     // Attempt to find cached page
     if ($request->getMethod() === 'GET') {
         $time = microtime(true);
         $cacheName = __CLASS__ . '_Page_' . md5($request->getUri());
         if (($cache = Curry_Core::$cache->load($cacheName)) !== false) {
             trace_notice('Using cached page content');
             foreach ($cache['headers'] as $header) {
                 header($header);
             }
             echo $cache['content'];
             Curry_Core::triggerHook('Curry_Application::render', $cache['page_id'], $cache['page_revision_id'], microtime(true) - $time, 0);
             return;
         }
     }
     // attempt to find the requested page
     if (!$page) {
         try {
             $page = $this->findPage($request);
             $page = $this->redirectPage($page, $request);
         } catch (Exception $e) {
             Curry_Core::log('Error when trying to find page: ' . $e->getMessage(), Zend_Log::ERR);
             $page = null;
         }
         // make sure page is enabled
         if ($page instanceof Page && !$forceShow && !$page->getEnabled()) {
             Curry_Core::log('Page is not accessible', Zend_Log::ERR);
             $page = null;
         }
     }
     // Page was not found, attempt to find 404 page
     if (!$page) {
         header("HTTP/1.1 404 Not Found");
         if (Curry_Core::$config->curry->errorPage->notFound) {
             $page = PageQuery::create()->findPk(Curry_Core::$config->curry->errorPage->notFound);
             if (!$page || !$page->getEnabled()) {
                 throw new Exception('Page not found, additionally the page-not-found page could not be found.');
             }
         } else {
             die('Page not found');
         }
     }
     // Set language
     $language = $page->getInheritedProperty('Language');
     $fallbackLanguage = Curry_Core::$config->curry->fallbackLanguage;
     if ($language) {
         $this->setLanguage($language);
     } else {
         if ($fallbackLanguage) {
             trace_warning('Using fallback language');
             $this->setLanguage($fallbackLanguage);
         } else {
             trace_warning('Language not set for page');
         }
     }
     // Attempt to render page
     try {
         $this->render($page->getPageRevision(), $request, $vars, $options);
     } catch (Curry_Exception_Unauthorized $e) {
         Curry_Core::log($e->getMessage(), Zend_Log::ERR);
         if (!headers_sent()) {
             header("HTTP/1.1 " . $e->getStatusCode() . " " . $e->getMessage());
         }
         if (Curry_Core::$config->curry->errorPage->unauthorized) {
             Curry_Core::log('Showing unauthorized page', Zend_Log::NOTICE);
             $page = PageQuery::create()->findPk(Curry_Core::$config->curry->errorPage->unauthorized);
             if (!$page) {
                 throw new Exception('Unauthorized page not found');
             }
             try {
                 $vars = array('curry' => array('error' => array('Message' => $e->getMessage(), 'Trace' => $e->getTraceAsString())));
                 $options = array();
                 $this->render($page->getPageRevision(), $request, $vars, $options);
             } catch (Exception $e2) {
                 Curry_Core::log('An error occured while trying to generate the unauthorized page: ' . $e2->getMessage(), Zend_Log::ERR);
                 throw $e;
             }
         } else {
             throw $e;
         }
     } catch (Curry_Exception_HttpError $e) {
         Curry_Core::log($e->getMessage(), Zend_Log::ERR);
         if (!headers_sent()) {
             header("HTTP/1.1 " . $e->getStatusCode() . " " . $e->getMessage());
         }
     } catch (Exception $e) {
         Curry_Core::log($e->getMessage(), Zend_Log::ERR);
         if (!headers_sent()) {
             header("HTTP/1.1 500 Internal server error");
         }
         if (Curry_Core::$config->curry->errorNotification) {
             Curry_Core::sendErrorNotification($e);
         }
         if (Curry_Core::$config->curry->errorPage->error) {
             Curry_Core::log('Trying to show error page', Zend_Log::NOTICE);
             $page = PageQuery::create()->findPk(Curry_Core::$config->curry->errorPage->error);
             if (!$page) {
                 throw new Exception('Error page not found');
             }
             try {
                 $vars = array('curry' => array('error' => array('Message' => $e->getMessage(), 'Trace' => $e->getTraceAsString())));
                 $options = array();
                 $this->render($page->getPageRevision(), $request, $vars, $options);
             } catch (Exception $e2) {
                 Curry_Core::log('An error occured, additionally an error occured while trying to generate the error page: ' . $e2->getMessage(), Zend_Log::ERR);
                 throw $e;
             }
         } else {
             throw $e;
         }
     }
 }
示例#5
0
 /**
  * Send error notification email.
  *
  * @param Exception $e
  */
 public static function sendErrorNotification(Exception $e)
 {
     try {
         // Create form to recreate error
         $method = strtoupper($_SERVER['REQUEST_METHOD']);
         $hidden = Curry_Html::createHiddenFields($method == 'POST' ? $_POST : $_GET);
         $action = url(Curry_URL::getRequestUri())->getAbsolute();
         $form = '<form action="' . $action . '" method="' . $method . '">' . $hidden . '<button type="submit">Execute</button></form>';
         // Create mail
         $mail = new Curry_Mail();
         $mail->addTo(Curry_Core::$config->curry->adminEmail);
         $mail->setSubject('Error on ' . Curry_Core::$config->curry->name);
         $mail->setBodyHtml('<html><body>' . '<h1>' . get_class($e) . '</h1>' . '<h2>' . htmlspecialchars($e->getMessage()) . '</h2>' . '<p><strong>Method:</strong> ' . $method . '<br/>' . '<strong>URL:</strong> ' . $action . '<br/>' . '<strong>File:</strong> ' . htmlspecialchars($e->getFile()) . '(' . $e->getLine() . ')</p>' . '<h2>Recreate</h2>' . $form . '<h2>Trace</h2>' . '<pre>' . htmlspecialchars($e->getTraceAsString()) . '</pre>' . '<h2>Variables</h2>' . '<h3>$_GET</h3>' . '<pre>' . htmlspecialchars(print_r($_GET, true)) . '</pre>' . '<h3>$_POST</h3>' . '<pre>' . htmlspecialchars(print_r($_POST, true)) . '</pre>' . '<h3>$_SERVER</h3>' . '<pre>' . htmlspecialchars(print_r($_SERVER, true)) . '</pre>' . '</body></html>');
         $mail->send();
         trace_notice('Sent error notification');
     } catch (Exception $e) {
         trace_warning('Failed to send error notification');
     }
 }
示例#6
0
 /**
  * Create new module form.
  *
  * @param PageRevision $pageRevision
  * @param string $moduleClass
  * @return Curry_Form
  */
 public static function getNewModuleForm($pageRevision, $moduleClass, $target)
 {
     $valid = array();
     $modules = array();
     foreach (ModuleQuery::create()->orderByTitle()->find() as $module) {
         $inTargets = in_array($target, $module->getTargets());
         if (!$target || ($module->getTargetsExclude() ? !$inTargets : $inTargets)) {
             $modules[$module->getModuleId()] = $module->getTitle();
             $valid[] = $module->getModuleId();
         }
     }
     $user = User::getUser();
     $modulePermission = $user->hasPagePermission($pageRevision->getPage(), PageAccessPeer::PERM_MODULES);
     if ($modulePermission) {
         $modules = array('Predefined' => $modules);
         foreach (Curry_Module::getModuleList() as $className) {
             $parts = explode("_", str_replace("_Module_", "_", $className));
             $package = array_shift($parts);
             $modules[$package][$className] = join(" / ", $parts);
             $valid[] = $className;
         }
     }
     if (!$moduleClass || !in_array($moduleClass, $valid)) {
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('module_class' => array('select', array('label' => 'Type', 'multiOptions' => $modules, 'required' => true)), 'next' => array('submit', array('label' => 'Next')))));
         return $form;
     } else {
         // Fetch template targets
         $targets = array();
         try {
             $template = $pageRevision->getInheritedProperty('Template');
             if ($template) {
                 $template = Curry_Twig_Template::loadTemplate($template);
             }
             while ($template) {
                 $targets = array_merge($targets, $template->getPlaceholders());
                 $template = $template->getParent(array());
             }
         } catch (Exception $e) {
             trace_warning('Error in template: ' . $e->getMessage());
         }
         if (count($targets)) {
             $targets = array_combine(array_values($targets), array_values($targets));
         }
         // Check for predefined module creation
         if (ctype_digit($moduleClass)) {
             $module = ModuleQuery::create()->findPk($moduleClass);
             $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden', array('value' => 1)), 'module_class' => array('hidden', array('value' => $moduleClass)), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $module->getName())))));
             if (!$target) {
                 // Show only acceptable targets...
                 $form->addElement('select', 'target', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'multiOptions' => $targets));
             } else {
                 $form->addElement('hidden', 'target', array('value' => $target));
                 $form->setCsrfCheck(false);
                 $_POST = $form->getValues();
             }
             $form->addElement('submit', 'add', array('label' => 'Add module'));
             return $form;
         }
         if (!class_exists($moduleClass)) {
             throw new Exception('Class \'' . $moduleClass . '\' could not be loaded, please check the path and classname.');
         }
         $defaultName = substr($moduleClass, strrpos($moduleClass, '_') + 1);
         $targets[''] = '[ Custom ]';
         asort($targets);
         $templates = array('' => "[ None ]", 'new' => "[ Create new ]") + Curry_Backend_Template::getTemplateSelect();
         $defaultTemplateName = 'Modules/' . $defaultName . '.html';
         $defaultTemplate = '';
         if ($moduleClass !== 'Curry_Module_Article' && call_user_func(array($moduleClass, 'hasTemplate'))) {
             $defaultTemplate = array_key_exists($defaultTemplateName, $templates) ? $defaultTemplateName : 'new';
         }
         $predefinedTemplates = call_user_func(array($moduleClass, 'getPredefinedTemplates'));
         $predefinedTemplates = count($predefinedTemplates) ? array_combine(array_keys($predefinedTemplates), array_keys($predefinedTemplates)) : array();
         $predefinedTemplates = array('' => '[ Empty ]') + $predefinedTemplates;
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden'), 'module_class' => array('hidden', array('value' => $moduleClass)), 'module_class_display' => array('rawHtml', array('label' => 'Type', 'value' => '<input type="text" value="' . $moduleClass . '" disabled="disabled" />')), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $defaultName)), 'target' => array('select', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'value' => isset($_GET['target']) ? $_GET['target'] : null, 'multiOptions' => $targets, 'class' => 'trigger-change', 'onchange' => "\$('#target_name-label, #target_name-element').toggle(\$(this).val() == '');")), 'target_name' => array('text', array('label' => 'Target Name')), 'template' => array('select', array('class' => 'trigger-change', 'label' => 'Template', 'multiOptions' => $templates, 'value' => $defaultTemplate, 'onchange' => "\$('#template_name-label, #template_name-element, #predefined_template-label, #predefined_template-element').toggle(\$(this).val() == 'new');")), 'template_name' => array('text', array('label' => 'Name', 'value' => $defaultTemplateName)), 'predefined_template' => array('select', array('label' => 'Predefined template', 'multiOptions' => $predefinedTemplates)), 'content_visibility' => array('select', array('label' => 'Content Visibility', 'description' => 'Set the visibility of this module in the Content backend module.', 'multiOptions' => PageModulePeer::$contentVisiblityOptions, 'value' => PageModulePeer::CONTENT_VISIBILITY_ALWAYS, 'required' => true)), 'search_visibility' => array('checkbox', array('label' => 'Search Visibility', 'description' => 'If this module should be rendered when indexing pages.', 'value' => true, 'required' => true)))));
         $form->addDisplayGroup(array('position', 'content_visibility', 'search_visibility'), 'advanced', array('class' => 'advanced', 'legend' => 'Advanced'));
         $form->addElement('submit', 'add', array('label' => 'Add module'));
     }
     return $form;
 }
示例#7
0
 /**
  * Return partial a file to browser and exit. Will set appropriate headers and return the content.
  * 
  * @deprecated Please use Curry_Application::returnPartial() instead.
  *
  * @param string $file
  * @param string $contentType
  * @param string $filename
  */
 public function returnFile($file, $contentType, $filename)
 {
     trace_warning('DEPRECATED: ' . __CLASS__ . '::' . __METHOD__ . '(), please use Curry_Application::' . __METHOD__ . '() instead.');
     Curry_Application::returnFile($file, $contentType, $filename);
 }