/** * 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; }
/** * 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); }
/** * Module properties form. * * @param Curry_PageModuleWrapper $pageModuleWrapper * @return Curry_Form */ public static function getModulePropertiesForm(Curry_PageModuleWrapper $pageModuleWrapper) { $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('pid_moduleproperties' => array('hidden'), 'name' => array('text', array('label' => 'Name', 'required' => true, 'value' => $pageModuleWrapper->getPageModule()->getName(), 'description' => 'The name of this module. If you have many modules of the same type on the same page this will help you to seperate them from each other.')), 'target' => array('text', array('label' => 'Target', 'description' => 'Specifies what variable in the page-template to attach this module to.', 'required' => true, 'value' => $pageModuleWrapper->getTarget())), 'content_visibility' => array('select', array('label' => 'Content Visibility', 'description' => 'Set the visibility of this module in the Content backend module.', 'multiOptions' => PageModulePeer::$contentVisiblityOptions, 'value' => $pageModuleWrapper->getPageModule()->getContentVisibility(), 'required' => true)), 'search_visibility' => array('checkbox', array('label' => 'Search Visibility', 'description' => 'If this module should be rendered when indexing pages.', 'value' => $pageModuleWrapper->getPageModule()->getSearchVisibility(), 'required' => true))))); $showSelect = array("true" => "Yes", "false" => "No"); $defaultTemplate = $pageModuleWrapper->isInherited() ? "[ Inherit ]" : "[ None ]"; $template = $pageModuleWrapper->getModuleData()->getTemplate(); $templatesSelect = Curry_Backend_Template::getTemplateSelect(); if ($template && !array_key_exists($template, $templatesSelect)) { $templatesSelect[$template] = $template . ' <MISSING!>'; } $form->addSubForm(new Curry_Form_SubForm(array('legend' => $pageModuleWrapper->isInherited() ? 'Override inherited settings' : 'Inherited settings', 'elements' => array('template' => $pageModuleWrapper->hasTemplate() ? array('select', array('label' => 'Template', 'multiOptions' => array(null => $defaultTemplate) + $templatesSelect, 'value' => $template)) : array('select', array('label' => 'Template', 'multiOptions' => array("None"), 'disabled' => 'disabled')), 'show' => array('select', array('label' => 'Show', 'multiOptions' => $pageModuleWrapper->isInherited() ? array('' => "[ Inherit ]") + $showSelect : $showSelect, 'value' => self::bool2str($pageModuleWrapper->getModuleData()->getEnabled())))))), 'local'); $form->addElement('submit', 'save', array('label' => 'Save')); return $form; }