Ejemplo n.º 1
0
 /**
  * getNewInstanceAction
  *
  * @return Response
  */
 public function getNewInstanceAction()
 {
     $routeMatch = $this->getEvent()->getRouteMatch();
     $pluginType = $routeMatch->getParam('pluginType');
     $instanceId = $routeMatch->getParam('instanceId');
     $pluginManager = $this->getServiceLocator()->get('Rcm\\Service\\PluginManager');
     if ($instanceId < 0) {
         $instanceConfig = $pluginManager->getDefaultInstanceConfig($pluginType);
     } else {
         $instanceConfig = $pluginManager->getInstanceConfig($instanceId);
     }
     //Allow plugins to preview with an unsaved instance configuration
     $instanceConfigPreview = $this->params()->fromPost('previewInstanceConfig');
     if ($instanceConfigPreview) {
         $instanceConfig = array_merge($instanceConfig, $instanceConfigPreview);
     }
     $viewData = $pluginManager->getPluginViewData($pluginType, $instanceId, $instanceConfig);
     $html = $viewData['html'];
     $headLink = new HeadLink();
     foreach ($viewData['css'] as $css) {
         $cssInfo = unserialize($css);
         $headLink->append($cssInfo);
     }
     $headScript = new HeadScript();
     foreach ($viewData['js'] as $js) {
         $jsInfo = unserialize($js);
         $headScript->append($jsInfo);
     }
     $html = $headLink->toString() . $headScript->toString() . $html;
     $response = new Response();
     $response->setContent($html);
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Find an initialize Dojo helper before rendering head scripts
  * 
  * @see \Zend\View\Helper\HeadScript::toString()
  * @param string $indent
  * @return string
  */
 public function toString($indent = null)
 {
     $helperManager = $this->getView()->getHelperPluginManager();
     if ($helperManager->has('dojo')) {
         $dojo = $helperManager->get('dojo');
         $dojo->initialize();
     }
     return parent::toString($indent);
 }
Ejemplo n.º 3
0
 /**
  * @issue ZF-5435
  */
 public function testContainerMaintainsCorrectOrderOfItems()
 {
     $this->helper->offsetSetFile(1, 'test1.js');
     $this->helper->offsetSetFile(20, 'test2.js');
     $this->helper->offsetSetFile(10, 'test3.js');
     $this->helper->offsetSetFile(5, 'test4.js');
     $test = $this->helper->toString();
     $expected = '<script type="text/javascript" src="test1.js"></script>' . PHP_EOL . '<script type="text/javascript" src="test4.js"></script>' . PHP_EOL . '<script type="text/javascript" src="test3.js"></script>' . PHP_EOL . '<script type="text/javascript" src="test2.js"></script>';
     $this->assertEquals($expected, $test);
 }
 /**
  * Ensure JS error handler is the first JS on page
  *
  * @param  string|int $indent Amount of whitespaces or string to use for indention
  *
  * @return string
  */
 public function toString($indent = null)
 {
     return "\n<script type=\"text/javascript\" src=\"/modules/rcm-error-handler/js-error-logger.js\"></script>\n" . parent::toString($indent);
 }
Ejemplo n.º 5
0
 /**
  * Combine all files and retrieve minified file
  *
  * @param string|int $indent
  *            Amount of whitespaces or string to use for indention
  * @return string
  */
 public function toString($indent = null)
 {
     try {
         if ($this->minifyEnabled === false) {
             return parent::toString($indent);
         }
         $indent = null !== $indent ? $this->getWhitespace($indent) : $this->getIndent();
         if ($this->view) {
             $useCdata = $this->view->plugin('doctype')->isXhtml();
         } else {
             $useCdata = $this->useCdata;
         }
         $escapeStart = $useCdata ? '//<![CDATA[' : '//<!--';
         $escapeEnd = $useCdata ? '//]]>' : '//-->';
         $filesToMinify = array();
         $lastModifiedTime = 0;
         $items = [];
         $this->getContainer()->ksort();
         foreach ($this as $item) {
             if (!$this->isValid($item)) {
                 continue;
             }
             $itemSrcPath = !empty($item->attributes) && !empty($item->attributes['src']) ? $this->minifyDocRootPath . trim($item->attributes['src'], '/\\ ') : null;
             if ($item->type === 'text/javascript' && $itemSrcPath && file_exists($itemSrcPath) && empty($item->attributes['conditional']) && (!isset($item->attributes['minify']) || $item->attributes['minify'] !== false)) {
                 $filesToMinify[] = $itemSrcPath;
                 $lastModifiedTime = max(filemtime($itemSrcPath), $lastModifiedTime);
             } else {
                 if (isset($item->attributes['minify'])) {
                     unset($item->attributes['minify']);
                 }
                 $items[] = $this->itemToString($item, $indent, $escapeStart, $escapeEnd);
             }
         }
         if (count($filesToMinify) > 0) {
             $minifiedFileName = md5(implode('|', $filesToMinify)) . '.min.js';
             $minifiedFileBasePath = $this->view->basePath($this->minifyCacheDir . '/' . $minifiedFileName);
             $minifiedFilePath = $this->minifyDocRootPath . trim($minifiedFileBasePath, '\\/ ');
             $lockFilePath = sys_get_temp_dir() . '/' . $minifiedFileName . '.lock';
             $isMinifiedFileBuildRequired = !file_exists($minifiedFilePath) || filemtime($minifiedFilePath) < $lastModifiedTime;
             $isMinifiedFileBuildLocked = file_exists($lockFilePath);
             if ($isMinifiedFileBuildRequired && !$isMinifiedFileBuildLocked) {
                 file_put_contents($lockFilePath, 'locked', LOCK_EX);
                 try {
                     $pieces = array();
                     foreach ($filesToMinify as $filePath) {
                         $pieces[] = file_get_contents($filePath);
                     }
                     $content = implode($this->getSeparator(), $pieces);
                     $content = $this->minifyService->minify($content);
                     file_put_contents($minifiedFilePath, $content, LOCK_EX);
                 } catch (\Exception $e) {
                     unlink($lockFilePath);
                     throw new \Exception($e->getMessage());
                 }
                 unlink($lockFilePath);
                 //clean out old files
                 $flattened = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->minifyCachePath));
                 $files = new \RegexIterator($flattened, '/^[a-f0-9]{32}\\.min\\.js$/i');
                 foreach ($files as $file) {
                     if (filemtime($file) < time() - 86400 * 7) {
                         unlink($file);
                     }
                 }
             }
             $attributes = array('src' => $minifiedFileBasePath);
             if (isset($this->minifyConfig['minifyJS']['async']) && $this->minifyConfig['minifyJS']['async'] === true) {
                 $attributes['async'] = true;
             }
             $item = $this->createData('text/javascript', $attributes);
             array_unshift($items, $this->itemToString($item, $indent, $escapeStart, $escapeEnd));
         }
         return implode($this->getSeparator(), $items);
     } catch (\Exception $e) {
         die("Fatal VcoZfMinify Error: " . $e->getMessage());
     }
 }
Ejemplo n.º 6
0
 /**
  * Retrieve string representation
  *
  * @param  string|int $indent Amount of whitespaces or string to use for indention
  * @return string
  */
 public function toString($indent = null)
 {
     $this->preToString();
     return parent::toString($indent);
 }