public function __construct() { try { $this->oRootPage = PagePeer::getRootPage(); } catch (Exception $e) { $this->oRootPage = self::initializeRootPage(); } $this->oTreeWidget = new TreeWidgetModule(); $this->oTreeWidget->setDelegate($this); $this->oTreeWidget->setSetting('init_dnd', true); $oInitialPage = null; if (Manager::hasNextPathItem()) { $oInitialPage = PageQuery::create()->findPk(Manager::usePath()); if ($oInitialPage !== null) { Session::getSession()->setAttribute('persistent_page_id', $oInitialPage->getId()); } } else { if (Session::getSession()->hasAttribute('persistent_page_id')) { $oInitialPage = PageQuery::create()->findPk(Session::getSession()->getAttribute('persistent_page_id')); } } if ($oInitialPage === null) { $oInitialPage = $this->oRootPage; } $this->addResourceParameter(ResourceIncluder::RESOURCE_TYPE_JS, 'tree_session', $this->oTreeWidget->getSessionKey()); $this->addResourceParameter(ResourceIncluder::RESOURCE_TYPE_JS, 'initial_page_id', $oInitialPage->getId()); $this->addResourceParameter(ResourceIncluder::RESOURCE_TYPE_JS, 'initial_page_tree_left', $oInitialPage->getTreeLeft()); $oResourceIncluder = ResourceIncluder::defaultIncluder(); $oResourceIncluder->addResource('admin/template.css', null, null, array(), ResourceIncluder::PRIORITY_NORMAL, null, true); }
public function getJsForFrontend() { if (Settings::getSetting("frontend", "protect_email_addresses", false)) { ResourceIncluder::defaultIncluder()->addResource('e-mail-defuscate.js'); } return null; }
public static function includeAvailableResources($mModule, $bEndDependenciesOnJS = false, $oResourceIncluder = null, $aParameters = null) { if ($aParameters === null) { $aParameters = array_fill_keys(self::$RESOURCE_TYPES, array()); } $sModuleName = null; $sModuleType = null; if ($mModule instanceof Module) { $sModuleName = $mModule->getModuleName(); $sModuleType = $mModule->getType(); } else { $sModuleName = $mModule::getNameByClassName($mModule); $sModuleType = $mModule::getType(); } if ($oResourceIncluder === null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } foreach (self::$RESOURCE_TYPES as $sResourceType) { $sResourceLink = self::getAvailableResource($sModuleName, $sModuleType, $sResourceType, @$aParameters[$sResourceType]); if ($sResourceLink !== null) { if ($sResourceType === ResourceIncluder::RESOURCE_TYPE_JS && $bEndDependenciesOnJS) { $oResourceIncluder->addResourceEndingDependency($sResourceLink, $sResourceType); } else { $oResourceIncluder->addResource($sResourceLink, $sResourceType); } } } }
public static function includeResources($oResourceIncluder = null) { if ($oResourceIncluder == null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } $oResourceIncluder->addResource('widget/html5-formdata/formdata.js'); self::includeWidgetResources(false, $oResourceIncluder); }
public static function includeResources($oResourceIncluder = null) { if ($oResourceIncluder == null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } $oResourceIncluder->addResource('widget/jsTree/jquery.jstree.js'); $oResourceIncluder->addResource('widget/jsTree/jquery.jstree.tree_widget_plugin.js'); self::includeWidgetResources(false, $oResourceIncluder); }
public static function includeResources($oResourceIncluder = null) { if ($oResourceIncluder === null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } $oResourceIncluder->startDependencies(); ImagePickerWidgetModule::includeResources($oResourceIncluder); self::includeWidgetResources(true, $oResourceIncluder); }
public static function includeResources($oResourceIncluder = null) { if ($oResourceIncluder === null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } $oResourceIncluder->addResource('widget/popover/jquery.popover.js'); $oResourceIncluder->addResource(array(DIRNAME_WEB, 'js', 'widget', 'popover', 'jquery.popover.css')); self::includeWidgetResources(false, $oResourceIncluder); }
public static function includeResources($oResourceIncluder = null) { if ($oResourceIncluder === null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } $oResourceIncluder->startDependencies(); self::includeWidgetResources(true, $oResourceIncluder); $oCkEditor = ResourceFinder::findResourceObject(array('web', 'js', 'widget', 'ckeditor')); $oResourceIncluder->addCustomJs('CKEDITOR_BASEPATH = "' . $oCkEditor->getFrontendPath() . '/";'); $oResourceIncluder->addResource('widget/ckeditor/ckeditor.js'); }
public static function getRecaptchaCode($sId = '') { $oTemplate = self::constructTemplateForModuleAndType(self::$MODULE_TYPE, 'form', 'recaptcha'); $oTemplate->replaceIdentifier('key', Settings::getSetting('frontend', 're_captcha_public_key', '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI')); $sAPI = 'https://www.google.com/recaptcha/api.js?'; $oOutput = new XHTMLOutput(); if ($oOutput->getContentType() === 'application/xhtml+xml') { // Use fallback version because users don’t want to wait for timeout when document.write isn’t working. $sAPI .= '&fallback=true'; } ResourceIncluder::defaultIncluder()->addResource($sAPI, ResourceIncluder::RESOURCE_TYPE_JS); return $oTemplate; }
public function __construct() { parent::__construct(); SanityCheck::basicCheck(); $this->sModuleName = Manager::usePath(); $this->oResourceIncluder = ResourceIncluder::defaultIncluder(); if (isset($_REQUEST[self::CONTENT_LANGUAGE_SESSION_KEY])) { self::setContentLanguage($_REQUEST[self::CONTENT_LANGUAGE_SESSION_KEY]); } if (Session::getSession()->isAuthenticated() && Session::getSession()->getUser()->getIsBackendLoginEnabled()) { $oUser = Session::getSession()->getUser(); Session::getSession()->setLanguage(Session::getSession()->getUser()->getLanguageId()); if (isset($_REQUEST['preview']) || !$oUser->getIsAdminLoginEnabled()) { LinkUtil::redirect(LinkUtil::link(@$_REQUEST['preview'], 'PreviewManager')); } } }
public function writeResourceIncludes($oTemplateIdentifier) { $oResourceIncluder = null; if ($oTemplateIdentifier->getValue() !== null) { $oResourceIncluder = ResourceIncluder::namedIncluder($oTemplateIdentifier->getValue()); } else { if ($oTemplateIdentifier->hasParameter('name')) { // Fall back to 'name' param for backwards compatiblity $oResourceIncluder = ResourceIncluder::namedIncluder($oTemplateIdentifier->getParameter('name')); } else { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } } $bConsolidate = null; if ($oTemplateIdentifier->hasParameter('consolidate')) { $bConsolidate = $oTemplateIdentifier->getParameter('consolidate'); if ($bConsolidate === 'false') { $bConsolidate = false; } else { if ($bConsolidate !== 'internal') { $bConsolidate = true; } } } return $oResourceIncluder->getIncludes(!$oTemplateIdentifier->hasParameter('noNewlines'), $bConsolidate); }
public function fillAutofill() { $bIsPreview = $this->isPreview(); $this->oTemplate->replaceIdentifierCallback("autofill", function ($oTemplateIdentifier, $iFlags) use($bIsPreview) { $oModule = FrontendModule::getModuleInstance($oTemplateIdentifier->getValue(), $oTemplateIdentifier->getParameter('data')); $mResult = $oModule->cachedFrontend($bIsPreview); if (($sCss = $oModule->getCssForFrontend()) !== null) { ResourceIncluder::defaultIncluder()->addCustomCss($sCss); } if (($sJs = $oModule->getJsForFrontend()) !== null) { ResourceIncluder::defaultIncluder()->addCustomJs($sJs); } return $mResult; }, null, Template::NO_HTML_ESCAPE); }
public function testWriteResourceIncludes() { $sTemplateText = <<<EOT {{writeResourceIncludes;consolidate=false}} EOT; $oTemplate = new Template($sTemplateText, null, true); $oIncluder = ResourceIncluder::defaultIncluder(); $oIncluder->clearIncludedResources(); $oIncluder->addResource('admin/accept.png', null, null, array('template' => 'icons')); $oIncluder->addResource(array('web', 'js', 'widget', 'ckeditor', 'skins', 'moono', 'editor.css')); $oIncluder->addJavaScriptLibrary('jqueryui', 1); $oIncluder->addResource('admin/admin-ui.css'); $oIncluder->addResource('widget/ckeditor/ckeditor.js'); $this->assertSame('<link rel="icon" href="' . MAIN_DIR_FE . DIRNAME_BASE . '/web/images/admin/accept.png" />' . "\n" . '<link rel="stylesheet" media="all" href="' . MAIN_DIR_FE . DIRNAME_BASE . '/web/js/widget/ckeditor/skins/moono/editor.css" />' . "\n" . '<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>' . "\n" . '<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>' . "\n" . '<link rel="stylesheet" media="all" href="' . MAIN_DIR_FE . DIRNAME_BASE . '/web/css/admin/admin-ui.css" />' . "\n" . '<script type="text/javascript" src="' . MAIN_DIR_FE . DIRNAME_BASE . '/web/js/widget/ckeditor/ckeditor.js"></script>' . "\n", $oTemplate->render()); }
public function display(Template $oTemplate, $bIsPreview = false) { if ($bIsPreview) { $this->bIsPreview = true; } $this->setFilters(); $this->fillAuxilliaryContainers($oTemplate); if (Settings::getSetting("frontend", "protect_email_addresses", false)) { ResourceIncluder::defaultIncluder()->addResource('e-mail-defuscate.js'); } if (!$oTemplate->hasIdentifier('container', $this->sContainer)) { return; } $sMethod = "overview_{$this->sOverviewMode}"; if ($this->oNavigationItem instanceof VirtualNavigationItem) { $sMethod = substr($this->oNavigationItem->getType(), strlen('journal-')); if ($this->oNavigationItem->getData() instanceof JournalEntry) { $this->oEntry = $this->oNavigationItem->getData(); } } // whenever there is no detail requested, store current navigation item for return_to_list_view link if ($this->oEntry === null) { Session::getSession()->setAttribute(self::SESSION_LAST_OVERVIEW_ITEM_LINK, $this->oNavigationItem->getLink()); } $sMethod = StringUtil::camelize("display_{$sMethod}"); return $this->{$sMethod}($oTemplate); }
/** * fillContainerWithModule() */ private function fillContainerWithModule($oContentObject, $oTemplate, $iModuleId) { $oPageContents = $oContentObject->getLanguageObject($this->sLanguageId); if ($this->bIsPreview && $oPageContents === null) { //Need to get unsaved drafts in preview $oPageContents = new LanguageObject(); $oPageContents->setLanguageId($this->sLanguageId); $oPageContents->setContentObject($oContentObject); $oPageContents = $oPageContents->getDraft(true); } if ($oPageContents === null) { return false; } if ($oContentObject->getConditionSerialized() !== null && !$this->bIsPreview) { $oConditionTemplate = unserialize(stream_get_contents($oContentObject->getConditionSerialized())); if ($oConditionTemplate->render() === '') { return false; } } $sObjectType = $oContentObject->getObjectType(); if (!Module::moduleExists($sObjectType, FrontendModule::getType()) || !Module::isModuleEnabled(FrontendModule::getType(), $sObjectType)) { $sLink = implode('/', $this->oNavigationItem->getLink()); ErrorHandler::handleError(E_WARNING, "Disabled or non-existing frontend module {$sObjectType} in use on page {$sLink} ({$this->sLanguageId})", __FILE__, __LINE__, null, debug_backtrace(), true); if ($this->bIsPreview) { $oTemplate->replaceIdentifierMultiple("container", "<strong>Disabled or non-existing frontend module {$sObjectType} in use!</strong>", null, Template::NO_HTML_ESCAPE); return true; } return false; } if ($this->bIsPreview) { $oModule = FrontendModule::getModuleInstance($oContentObject->getObjectType(), $oPageContents->getDraft(), $iModuleId); } else { $oModule = FrontendModule::getModuleInstance($oContentObject->getObjectType(), $oPageContents, $iModuleId); } $sFrontentContents = $this->getModuleContents($oModule); if ($sFrontentContents === null) { return false; } // module_id FilterModule::getFilters()->handleDefaultPageTypeFilledContainerWithModule($oContentObject, $oModule, $oTemplate, $this->oFrontendTemplate, $this->iModuleId); if ($this->bIsPreview) { $sFrontentContents = $this->getPreviewMarkup($oContentObject, $sFrontentContents); } $oTemplate->replaceIdentifierMultiple("container", $sFrontentContents, null, Template::NO_HTML_ESCAPE); if (($sCss = $oModule->getCssForFrontend()) !== null) { ResourceIncluder::defaultIncluder()->addCustomCss($sCss, ResourceIncluder::PRIORITY_LAST); } if (($sJs = $oModule->getJsForFrontend()) !== null) { ResourceIncluder::defaultIncluder()->addCustomJs($sJs, ResourceIncluder::PRIORITY_LAST); } return true; }
public function onPageHasBeenSet($oPage, $bIsNotFound, $oNavigationItem) { if ($bIsNotFound || !$oPage->isOfType('journal')) { return; } // If is feed then render feed if ($oNavigationItem instanceof VirtualNavigationItem && $oNavigationItem->getType() === 'journal-feed') { $oFeed = new JournalFileModule(false, $oPage, $oNavigationItem->getData()); $oFeed->renderFile(); exit; } else { if ($oNavigationItem instanceof VirtualNavigationItem && $oNavigationItem->getType() === 'journal-add_comment' && Manager::isPost()) { $oEntry = $oNavigationItem->getData(); if (!$oEntry->commentsEnabled()) { LinkUtil::redirect(LinkUtil::link($oEntry->getLink())); } $this->handleNewJournalComment($oPage, $oEntry); } } //Add the feed include ResourceIncluder::defaultIncluder()->addCustomResource(array('template' => 'feed', 'location' => LinkUtil::link($oPage->getLinkArray('feed')))); }
private function getJSON(&$aRequest) { if ($this->sAction === 'destroy') { foreach ($aRequest['session_key'] as $sSessionKey) { Session::getSession()->setArrayAttributeValueForKey(WidgetModule::WIDGET_SESSION_KEY, $sSessionKey, null); } return; } $sWidgetClass = WidgetModule::getClassNameByName($this->sWidgetType); $bIsPersistent = $sWidgetClass::isPersistent(); if (!$bIsPersistent) { // Close session early on readonly calls Session::close(); } if ($this->sAction == 'widgetInformation') { $aInformation = array(); $sWidgetClass::includeResources(); $aInformation['resources'] = ResourceIncluder::defaultIncluder()->getIncludes()->render(); $aInformation['methods'] = $sWidgetClass::getCustomMethods(); $aInformation['is_singleton'] = $sWidgetClass::isSingleton(); $aInformation['is_persistent'] = $bIsPersistent; return $aInformation; } if ($this->sAction == 'staticMethodCall') { $this->checkPermissions($sWidgetClass); $sMethodName = isset($aRequest['method']) ? $aRequest['method'] : Manager::usePath(); if (!method_exists($sWidgetClass, $sMethodName)) { throw new LocalizedException('wns.file.widget_json.method_does_not_exist', array('method' => $sMethodName, 'widget' => $sWidgetClass)); } return array("result" => call_user_func_array(array($sWidgetClass, $sMethodName), isset($aRequest['method_parameters']) ? $aRequest['method_parameters'] : array())); } $aInstanceArgs = array(@$aRequest['session_key']); if (isset($aRequest['instance_args'])) { $aInstanceArgs = $aRequest['instance_args']; } $aNewArgs = array_merge(array($this->sWidgetType), $aInstanceArgs); $oWidget = call_user_func_array(array('WidgetModule', 'getWidget'), $aNewArgs); if ($this->sAction === 'instanciateWidget') { $this->checkPermissions($sWidgetClass); $aInformation = array(); $aInformation['session_id'] = $oWidget->getSessionKey(); $oWidgetContents = $oWidget->doWidget(); if ($oWidgetContents instanceof Template) { $oWidgetContents = $oWidgetContents->render(); } $aInformation['content'] = $oWidgetContents; $aInformation['is_new'] = $oWidget->isNew(); $aInformation['initial_settings'] = $oWidget->allSettings(); return $aInformation; } if ($this->sAction === 'methodCall') { $this->checkPermissions($sWidgetClass); $sMethodName = isset($aRequest['method']) ? $aRequest['method'] : Manager::usePath(); if (!method_exists($oWidget, $sMethodName)) { throw new LocalizedException('wns.file.widget_json.method_does_not_exist', array('method' => $sMethodName, 'widget' => $oWidget->getName())); } return array("result" => call_user_func_array(array($oWidget, $sMethodName), isset($aRequest['method_parameters']) ? $aRequest['method_parameters'] : array())); } }
private function addNamespacedCss($mLocation) { array_unshift($mLocation, 'namespaced_preview_css'); $oResourceIncluder = ResourceIncluder::defaultIncluder(); $oResourceIncluder->addResource(LinkUtil::link($mLocation, 'FileManager'), ResourceIncluder::RESOURCE_TYPE_CSS); }