Exemple #1
0
 /**
  * Insert module and return generated content.
  *
  * @param Curry_PageModuleWrapper $pageModuleWrapper
  * @return string
  */
 protected function insertModule(Curry_PageModuleWrapper $pageModuleWrapper)
 {
     Curry_Core::log(($pageModuleWrapper->getEnabled() ? 'Inserting' : 'Skipping') . ' module "' . $pageModuleWrapper->getName() . '" of type "' . $pageModuleWrapper->getClassName() . '" with target "' . $pageModuleWrapper->getTarget() . '"');
     if (!$pageModuleWrapper->getEnabled()) {
         return "";
     }
     $cached = false;
     $devMode = Curry_Core::$config->curry->developmentMode;
     if ($devMode) {
         $time = microtime(true);
         $sqlQueries = Curry_Propel::getQueryCount();
         $userTime = Curry_Util::getCpuTime('u');
         $systemTime = Curry_Util::getCpuTime('s');
         $memoryUsage = memory_get_usage(true);
     }
     $this->moduleCache = array();
     $module = $pageModuleWrapper->createObject();
     $module->setPageGenerator($this);
     $cp = $module->getCacheProperties();
     $cacheName = $this->getModuleCacheName($pageModuleWrapper, $module);
     // try to use cached content
     if ($cp !== null && ($cache = Curry_Core::$cache->load($cacheName)) !== false) {
         $cached = true;
         $this->insertCachedModule($cache);
         $content = $cache['content'];
     } else {
         $template = null;
         if ($pageModuleWrapper->getTemplate()) {
             $template = Curry_Twig_Template::loadTemplate($pageModuleWrapper->getTemplate());
         } else {
             if ($module->getDefaultTemplate()) {
                 $template = Curry_Twig_Template::loadTemplateString($module->getDefaultTemplate());
             }
         }
         if ($template && $template->getEnvironment()) {
             $twig = $template->getEnvironment();
             $twig->addGlobal('module', array('Id' => $pageModuleWrapper->getPageModuleId(), 'ClassName' => $pageModuleWrapper->getClassName(), 'Name' => $pageModuleWrapper->getName(), 'ModuleDataId' => $pageModuleWrapper->getModuleDataId(), 'Target' => $pageModuleWrapper->getTarget()));
         }
         $content = (string) $module->showFront($template);
         if ($cp !== null) {
             $this->moduleCache['content'] = $content;
             $this->saveModuleCache($cacheName, $cp->getLifetime());
         }
     }
     if ($devMode) {
         $time = microtime(true) - $time;
         $userTime = Curry_Util::getCpuTime('u') - $userTime;
         $systemTime = Curry_Util::getCpuTime('s') - $systemTime;
         $memoryUsage = memory_get_usage(true) - $memoryUsage;
         $sqlQueries = $sqlQueries !== null ? Curry_Propel::getQueryCount() - $sqlQueries : null;
         $cpuLimit = Curry_Core::$config->curry->debug->moduleCpuLimit;
         $timeLimit = Curry_Core::$config->curry->debug->moduleTimeLimit;
         $memoryLimit = Curry_Core::$config->curry->debug->moduleMemoryLimit;
         $sqlLimit = Curry_Core::$config->curry->debug->moduleSqlLimit;
         if ($userTime + $systemTime > $cpuLimit || $time > $timeLimit) {
             trace_warning('Module generation time exceeded limit');
         }
         if ($memoryUsage > $memoryLimit) {
             trace_warning('Module memory usage exceeded limit');
         }
         if ($sqlQueries > $sqlLimit) {
             trace_warning('Module sql query count exceeded limit');
         }
         // add module debug info
         $this->moduleDebugInfo[] = array($pageModuleWrapper->getName(), $pageModuleWrapper->getClassName(), $pageModuleWrapper->getTemplate(), $pageModuleWrapper->getTarget(), $cached, round($time * 1000.0), round(($userTime + $systemTime) * 1000.0), Curry_Util::humanReadableBytes($memoryUsage), Curry_Util::humanReadableBytes(memory_get_peak_usage(true)), $sqlQueries !== null ? $sqlQueries : 'n/a');
     }
     return $content;
 }
Exemple #2
0
 /**
  * Get "copy code" for module.
  *
  * @param Curry_PageModuleWrapper $module
  * @return array
  */
 public static function getModuleCode(Curry_PageModuleWrapper $module)
 {
     $datas = array();
     $moduleDatas = ModuleDataQuery::create()->filterByPageModule($module->getPageModule())->filterByPageRevision($module->getPageRevision())->orderByLangcode()->find();
     foreach ($moduleDatas as $moduleData) {
         $datas[] = self::getModuleDataCode($moduleData);
     }
     return array("is_inherited" => $module->isInherited(), "uid" => $module->getPageModule()->getUid(), "name" => $module->getName(), "module_class" => $module->getClassName(), "inherit" => true, "target" => $module->getTarget(), "content_visibility" => $module->getPageModule()->getContentVisibility(), "search_visibility" => $module->getPageModule()->getSearchVisibility(), "datas" => $datas);
 }
Exemple #3
0
 /**
  * Edit module form.
  *
  * @param Curry_PageModuleWrapper $wrapper
  * @return Curry_Form|null
  */
 protected function getModuleForm(Curry_PageModuleWrapper $wrapper)
 {
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('pid_editmodule' => array('hidden'))));
     if ($wrapper->hasData()) {
         $subform = $wrapper->createObject()->showBack();
         if ($subform == null) {
             return null;
         }
         if (!$subform instanceof Curry_Form_SubForm) {
             throw new Exception($wrapper->getClassName() . '::showBack() did not return an instance of Curry_Form_SubForm.');
         }
         if (!$subform->getLegend()) {
             $subform->setLegend($wrapper->getName() . ' (' . $wrapper->getClassName() . ')');
         }
         if (!$subform instanceof Curry_Form_MultiForm) {
             $subform->setDecorators(array('FormElements'));
         }
         $form->addSubForm($subform, 'module' . $wrapper->getPageModuleId());
         $buttons = array('save');
         $form->addElement('submit', 'save', array('label' => 'Save'));
         if ($wrapper->isDeletable()) {
             $form->addElement('submit', 'delete', array('label' => 'Remove content'));
             $buttons[] = 'delete';
         }
         $form->addDisplayGroup($buttons, 'dg1', array('class' => 'horizontal-group'));
     } else {
         $form->addElement('submit', 'create', array('label' => $wrapper->isInherited() ? 'Override content' : 'Create content'));
     }
     return $form;
 }