Inheritance: extends Zend_View
Example #1
0
 /**
  * @param null $path
  * @param null $prefix
  * @param array $options
  */
 public function initView($path = null, $prefix = null, array $options = array())
 {
     if (null === $this->view) {
         $view = new View();
         $view->setRequest($this->getRequest());
         $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "\\Pimcore\\View\\Helper\\");
         $this->setView($view);
     }
     parent::initView($path, $prefix, $options);
     $this->setViewSuffix(View::getViewScriptSuffix());
     // this is very important, the initView could be called multiple times.
     // if we add the path on every call, we have big performance issues.
     if ($this->isInitialized) {
         return;
     }
     $this->isInitialized = true;
     $paths = $this->view->getScriptPaths();
     // script pathes for layout path
     foreach (array_reverse($paths) as $path) {
         $path = str_replace("\\", "/", $path);
         if (!in_array($path, $paths)) {
             $this->view->addScriptPath($path);
         }
         $path = str_replace("/scripts", "/layouts", $path);
         if (!in_array($path, $paths)) {
             $this->view->addScriptPath($path);
         }
     }
 }
Example #2
0
 /**
  * @return null|\Zend_Layout
  * @throws \Zend_Controller_Action_Exception
  */
 protected function enableLayout()
 {
     $viewRenderer = \Zend_Controller_Action_HelperBroker::getExistingHelper("viewRenderer");
     $viewRenderer->setIsInitialized(false);
     // reset so that the view get's initialized again, because of error page from other modules
     $viewRenderer->initView();
     \Zend_Layout::startMvc();
     $layout = \Zend_Layout::getMvcInstance();
     $layout->enableLayout();
     $layout->setViewSuffix(\Pimcore\View::getViewScriptSuffix());
     return $layout;
 }
Example #3
0
 public function getAvailableTemplatesAction()
 {
     $templates = [];
     $viewPath = PIMCORE_WEBSITE_PATH . DIRECTORY_SEPARATOR . "views" . DIRECTORY_SEPARATOR . "scripts";
     $files = rscandir($viewPath . DIRECTORY_SEPARATOR);
     foreach ($files as $file) {
         $dat = [];
         if (strpos($file, \Pimcore\View::getViewScriptSuffix()) !== false) {
             $dat["path"] = str_replace($viewPath, "", $file);
             $dat["path"] = str_replace("\\", "/", $dat["path"]);
             // unix directory separator are compatible with windows, not the reverse
             $templates[] = $dat;
         }
     }
     $this->_helper->json(["data" => $templates]);
 }
Example #4
0
 /**
  * @param $content
  * @param $id
  * @return string
  */
 public static function addComponentIdToHtml($content, $id)
 {
     if (\Pimcore\View::addComponentIds()) {
         // generate a crc of the current URL and cache it
         $crc = self::getCurrentRequestUrlCrc32();
         if ($crc) {
             $id = "uri:" . $crc . "." . $id;
         }
         // well the regex here is not the perfect solution, but it should work for most cases and is much faster than
         // using a HTML/XML parser or simple_dom_html, as this is not a critical information, the regex is fine here
         $content = preg_replace("@<([a-z]+)([^>]*)(?<!\\/)>@", '<$1$2 data-component-id="' . $id . '">', $content, 1);
     }
     return $content;
 }
 private static function parseConfig($type, $config, View $view)
 {
     $parsedConfig = array();
     foreach ($config as $c) {
         $elConf = array();
         $elValid = TRUE;
         if (!isset($c['type'])) {
             throw new \Exception('toolbox config type (' . $type . ') is not set.');
         }
         $elConf['type'] = $c['type'];
         $elConf['name'] = $c['name'];
         $elConf['title'] = $view->translateAdmin($c['title']);
         $elConf['reload'] = isset($c['reload']) ? $c['reload'] : TRUE;
         $elConf['default'] = isset($c['default']) ? $c['default'] : NULL;
         if (isset($c['conditions'])) {
             $elConf['conditions'] = $c['conditions'];
         }
         switch ($c['type']) {
             case 'select':
                 if (!isset($c['values'])) {
                     throw new \Exception('toolbox config value (' . $type . ') is not set.');
                 }
                 $store = array();
                 foreach ($c['values'] as $k => $v) {
                     $store[] = array($k, $view->translateAdmin($v));
                 }
                 $elConf['store'] = $store;
                 $value = $view->select($elConf['name'])->getData();
                 $elConf['__selectedValue'] = !empty($value) ? $value : $elConf['default'];
                 break;
             case 'additionalClasses':
                 if (empty($c['values'])) {
                     $elValid = FALSE;
                 }
                 $store = array();
                 $store[] = array('default', $view->translateAdmin('Default'));
                 foreach ($c['values'] as $k => $v) {
                     $store[] = array($k, $v);
                 }
                 $elConf['type'] = 'select';
                 $elConf['name'] = $type . 'AdditionalClasses';
                 $elConf['title'] = $view->translateAdmin('Additional');
                 $elConf['reload'] = TRUE;
                 $elConf['store'] = $store;
                 if (is_null($elConf['default'])) {
                     $elConf['default'] = 'default';
                 }
                 $value = $view->select($type . 'AdditionalClasses')->getData();
                 $elConf['__selectedValue'] = !empty($value) ? $value : $elConf['default'];
                 break;
             case 'checkbox':
                 $value = $view->checkbox($elConf['name'])->isChecked();
                 $elConf['__selectedValue'] = !empty($value) ? $value : $elConf['default'];
                 break;
             case 'input':
                 $value = $view->input($elConf['name'])->getData();
                 $elConf['__selectedValue'] = !empty($value) ? $value : $elConf['default'];
                 $elConf['width'] = isset($c['width']) ? $c['width'] : 150;
                 break;
             default:
                 throw new \Exception($c['type'] . ' is not a valid toolbox config element');
         }
         if ($elValid) {
             $parsedConfig[] = $elConf;
         }
     }
     $parsedConfig = self::checkCondition($parsedConfig);
     return $parsedConfig;
 }
Example #6
0
 /**
  * static function to render a document outside of a view
  *
  * @static
  * @param Document $document
  * @param array $params
  * @param bool $useLayout
  * @return string
  */
 public static function render(Document $document, $params = array(), $useLayout = false)
 {
     $layout = null;
     $existingActionHelper = null;
     if (\Zend_Controller_Action_HelperBroker::hasHelper("layout")) {
         $existingActionHelper = \Zend_Controller_Action_HelperBroker::getExistingHelper("layout");
     }
     $layoutInCurrentAction = \Zend_Layout::getMvcInstance() instanceof \Zend_Layout ? \Zend_Layout::getMvcInstance()->getLayout() : false;
     $viewHelper = \Zend_Controller_Action_HelperBroker::getExistingHelper("ViewRenderer");
     if ($viewHelper) {
         if ($viewHelper->view === null) {
             $viewHelper->initView(PIMCORE_WEBSITE_PATH . "/views");
         }
         $view = $viewHelper->view;
     } else {
         $view = new \Pimcore\View();
     }
     // add the view script path from the website module to the view, because otherwise it's not possible to call
     // this method out of other modules to render documents, eg. sending e-mails out of an plugin with Pimcore_Mail
     $moduleDirectory = \Zend_Controller_Front::getInstance()->getModuleDirectory($document->getModule());
     if (!empty($moduleDirectory)) {
         $view->addScriptPath($moduleDirectory . "/views/layouts");
         $view->addScriptPath($moduleDirectory . "/views/scripts");
     } else {
         $view->addScriptPath(PIMCORE_FRONTEND_MODULE . "/views/layouts");
         $view->addScriptPath(PIMCORE_FRONTEND_MODULE . "/views/scripts");
     }
     $documentBackup = null;
     if ($view->document) {
         $documentBackup = $view->document;
     }
     $view->document = $document;
     if ($useLayout) {
         if (!($layout = \Zend_Layout::getMvcInstance())) {
             $layout = \Zend_Layout::startMvc();
             $layout->setViewSuffix(View::getViewScriptSuffix());
             if ($layoutHelper = $view->getHelper("layout")) {
                 $layoutHelper->setLayout($layout);
             }
         }
         $layout->setLayout("--modification-indicator--");
     }
     $params["document"] = $document;
     foreach ($params as $key => $value) {
         if (!$view->{$key}) {
             $view->{$key} = $value;
         }
     }
     $content = $view->action($document->getAction(), $document->getController(), $document->getModule(), $params);
     //has to be called after $view->action so we can determine if a layout is enabled in $view->action()
     if ($useLayout) {
         if ($layout instanceof \Zend_Layout) {
             $layout->{$layout->getContentKey()} = $content;
             if (is_array($params)) {
                 foreach ($params as $key => $value) {
                     $layout->getView()->{$key} = $value;
                 }
             }
             // when using Document\Service::render() you have to set a layout in the view ($this->layout()->setLayout("mylayout"))
             if ($layout->getLayout() != "--modification-indicator--") {
                 $content = $layout->render();
             }
             //deactivate the layout if it was not activated in the called action
             //otherwise we would activate the layout in the called action
             \Zend_Layout::resetMvcInstance();
             if (!$layoutInCurrentAction) {
                 $layout->disableLayout();
             } else {
                 $layout = \Zend_Layout::startMvc();
                 $layout->setViewSuffix(View::getViewScriptSuffix());
                 // set pimcore specifiy view suffix
                 $layout->setLayout($layoutInCurrentAction);
                 $view->getHelper("Layout")->setLayout($layout);
                 if ($existingActionHelper) {
                     \Zend_Controller_Action_HelperBroker::removeHelper("layout");
                     \Zend_Controller_Action_HelperBroker::addHelper($existingActionHelper);
                     $pluginClass = $layout->getPluginClass();
                     $front = $existingActionHelper->getFrontController();
                     if ($front->hasPlugin($pluginClass)) {
                         $plugin = $front->getPlugin($pluginClass);
                         $plugin->setLayoutActionHelper($existingActionHelper);
                     }
                 }
             }
             $layout->{$layout->getContentKey()} = null;
             //reset content
         }
     }
     if ($documentBackup) {
         $view->document = $documentBackup;
     }
     if (\Pimcore\Config::getSystemConfig()->outputfilters->less) {
         $content = \Pimcore\Tool\Less::processHtml($content);
     }
     return $content;
 }
Example #7
0
 /**
  *
  */
 public function content()
 {
     // create info object and assign it to the view
     $info = new Area\Info();
     try {
         $info->setTag($this);
         $info->setName($this->getName());
         $info->setId($this->currentIndex["type"]);
         $info->setIndex($this->current);
         $info->setPath(str_replace(PIMCORE_DOCUMENT_ROOT, "", $this->getPathForBrick($this->currentIndex["type"])));
         $info->setConfig($this->getBrickConfig($this->currentIndex["type"]));
     } catch (\Exception $e) {
         \Logger::err($e);
     }
     if ($this->getView() instanceof \Zend_View) {
         $this->getView()->brick = $info;
         $areas = $this->getAreaDirs();
         $view = $areas[$this->currentIndex["type"]] . "/view.php";
         $action = $areas[$this->currentIndex["type"]] . "/action.php";
         $edit = $areas[$this->currentIndex["type"]] . "/edit.php";
         $options = $this->getOptions();
         $params = array();
         if (is_array($options["params"]) && array_key_exists($this->currentIndex["type"], $options["params"])) {
             if (is_array($options["params"][$this->currentIndex["type"]])) {
                 $params = $options["params"][$this->currentIndex["type"]];
             }
         }
         // assign parameters to view
         foreach ($params as $key => $value) {
             $this->getView()->assign($key, $value);
         }
         // check for action file
         if (is_file($action)) {
             include_once $action;
             $actionClassFound = true;
             $actionClassname = "\\Pimcore\\Model\\Document\\Tag\\Area\\" . ucfirst($this->currentIndex["type"]);
             if (!class_exists($actionClassname, false)) {
                 // also check the legacy prefixed class name, as this is used by some plugins
                 $actionClassname = "\\Document_Tag_Area_" . ucfirst($this->currentIndex["type"]);
                 if (!class_exists($actionClassname, false)) {
                     $actionClassFound = false;
                 }
             }
             if ($actionClassFound) {
                 $actionObject = new $actionClassname();
                 if ($actionObject instanceof Area\AbstractArea) {
                     $actionObject->setView($this->getView());
                     $areaConfig = new \Zend_Config_Xml($areas[$this->currentIndex["type"]] . "/area.xml");
                     $actionObject->setConfig($areaConfig);
                     // params
                     $params = array_merge($this->view->getAllParams(), $params);
                     $actionObject->setParams($params);
                     if ($info) {
                         $actionObject->setBrick($info);
                     }
                     if (method_exists($actionObject, "action")) {
                         $actionObject->action();
                     }
                     $this->getView()->assign('actionObject', $actionObject);
                 }
             } else {
                 $this->getView()->assign('actionObject', null);
             }
         }
         if (is_file($view)) {
             $editmode = $this->getView()->editmode;
             if (method_exists($actionObject, "getBrickHtmlTagOpen")) {
                 echo $actionObject->getBrickHtmlTagOpen($this);
             } else {
                 $dataComponentAttribute = "";
                 if (\Pimcore\View::addComponentIds()) {
                     $dataComponentId = 'document:' . $this->getDocumentId() . '.type:tag-areablock.name:' . $this->getName() . "--" . ($this->getCurrentIndex() ? $this->getCurrentIndex() : "0") . "--" . $this->currentIndex["type"];
                     $crc = \Pimcore\Tool\Frontend::getCurrentRequestUrlCrc32();
                     if ($crc) {
                         $dataComponentId = "uri:" . $crc . "." . $dataComponentId;
                     }
                     $dataComponentAttribute = 'data-component-id="' . $dataComponentId . '"';
                 }
                 echo '<div class="pimcore_area_' . $this->currentIndex["type"] . ' pimcore_area_content" ' . $dataComponentAttribute . '>';
             }
             if (is_file($edit) && $editmode) {
                 echo '<div class="pimcore_area_edit_button_' . $this->getName() . ' pimcore_area_edit_button"></div>';
                 // forces the editmode in view.php independent if there's an edit.php or not
                 if (!array_key_exists("forceEditInView", $params) || !$params["forceEditInView"]) {
                     $this->getView()->editmode = false;
                 }
             }
             $this->getView()->template($view);
             if (is_file($edit) && $editmode) {
                 $this->getView()->editmode = true;
                 echo '<div class="pimcore_area_editmode_' . $this->getName() . ' pimcore_area_editmode pimcore_area_editmode_hidden">';
                 $this->getView()->template($edit);
                 echo '</div>';
             }
             if (method_exists($actionObject, "getBrickHtmlTagClose")) {
                 echo $actionObject->getBrickHtmlTagClose($this);
             } else {
                 echo '</div>';
             }
             if (is_object($actionObject) && method_exists($actionObject, "postRenderAction")) {
                 $actionObject->postRenderAction();
             }
         }
     }
     $this->current++;
 }