Exemplo n.º 1
0
 /**
  * static function to render a document outside of a view
  *
  * @static
  * @param Document $document
  * @param array $params
  * @return
  */
 public static function render(Document $document, $params = array())
 {
     $view = new Pimcore_View();
     $params["document"] = $document;
     $content = $view->action($document->getAction(), $document->getController(), null, $params);
     return $content;
 }
Exemplo n.º 2
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)
 {
     $layoutEnabledInCurrentAction = Zend_Layout::getMvcInstance() instanceof Zend_Layout ? true : 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
     $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;
     $params["document"] = $document;
     $content = $view->action($document->getAction(), $document->getController(), null, $params);
     //has to be called after $view->action so we can determine if a layout is enabled in $view->action()
     if ($useLayout) {
         $layout = Zend_Layout::getMvcInstance();
         if ($layout instanceof Zend_Layout) {
             $layout->{$layout->getContentKey()} = $content;
             if (is_array($params)) {
                 foreach ($params as $key => $value) {
                     if (!$layout->getView()->{$key}) {
                         //otherwise we could overwrite e.g. controller, content...
                         $layout->getView()->{$key} = $value;
                     }
                 }
             }
             $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
             if (!$layoutEnabledInCurrentAction) {
                 $layout->disableLayout();
             }
             $layout->{$layout->getContentKey()} = null;
             //reset content
             $layout->resetMvcInstance();
         }
     }
     if ($documentBackup) {
         $view->document = $documentBackup;
     }
     return $content;
 }
Exemplo n.º 3
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 Pimcore_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(Pimcore_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);
         }
     }
 }
Exemplo n.º 4
0
 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->setViewSuffix(Pimcore_View::getViewScriptSuffix());
 }
Exemplo n.º 5
0
 protected function initCustomView()
 {
     $viewHelper = Zend_Controller_Action_HelperBroker::getExistingHelper("ViewRenderer");
     $view = new Pimcore_View();
     // script pathes
     foreach ($viewHelper->view->getScriptPaths() as $path) {
         $view->addScriptPath($path);
         $view->addScriptPath(str_replace(DIRECTORY_SEPARATOR . "scripts", DIRECTORY_SEPARATOR . "layouts", $path));
     }
     // view helper
     foreach ($viewHelper->view->getHelperPaths() as $prefix => $path) {
         $view->addHelperPath($path, $prefix);
     }
     $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "Pimcore_View_Helper_");
     // add helper to controller
     $viewHelper->setView($view);
     $viewHelper->setViewSuffix($this->getViewSuffix());
     Zend_Controller_Action_HelperBroker::addHelper($viewHelper);
     $this->view = $view;
     Zend_Registry::set("pimcore_custom_view", true);
 }
Exemplo n.º 6
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 Pimcore_View();
         $view->setRequest($this->getRequest());
         $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "Pimcore_View_Helper_");
         $this->setView($view);
     }
     parent::initView($path, $prefix, $options);
     // script pathes for layout path
     foreach (array_reverse($this->view->getScriptPaths()) as $path) {
         $path = str_replace("\\", "/", $path);
         $this->view->addScriptPath($path);
         $this->view->addScriptPath(str_replace("/scripts", "/layouts", $path));
     }
     $this->setViewSuffix(Pimcore_View::getViewScriptSuffix());
 }
 public function getAvailableTemplatesAction()
 {
     $templates = array();
     $viewPath = PIMCORE_WEBSITE_PATH . "/views/scripts";
     $files = rscandir($viewPath . "/");
     foreach ($files as $file) {
         $dat = array();
         if (strpos($file, Pimcore_View::getViewScriptSuffix()) !== false) {
             $dat["path"] = str_replace($viewPath, "", $file);
             $templates[] = $dat;
         }
     }
     $this->_helper->json(array("data" => $templates));
 }
Exemplo n.º 8
0
 protected function enableLayout()
 {
     Zend_Layout::startMvc();
     $layout = Zend_Layout::getMvcInstance();
     $layout->setViewSuffix(Pimcore_View::getViewScriptSuffix());
 }