コード例 #1
0
 public function testLinkRendersAsPlainHtmlIfDoctypeNotXhtml()
 {
     $this->view->doctype('HTML4_STRICT');
     $this->helper->headLink(array('rel' => 'icon', 'src' => '/foo/bar'))
                  ->headLink(array('rel' => 'foo', 'href' => '/bar/baz'));
     $test = $this->helper->toString();
     $this->assertNotContains(' />', $test);
 }
コード例 #2
0
ファイル: HeadLinkTest.php プロジェクト: travisj/zf
 /**
  * @issue ZF-5435
  */
 public function testContainerMaintainsCorrectOrderOfItems()
 {
     $this->helper->headLink()->offsetSetStylesheet(1, '/test1.css');
     $this->helper->headLink()->offsetSetStylesheet(10, '/test2.css');
     $this->helper->headLink()->offsetSetStylesheet(20, '/test3.css');
     $this->helper->headLink()->offsetSetStylesheet(5, '/test4.css');
     $test = $this->helper->toString();
     $expected = '<link href="/test1.css" media="screen" rel="stylesheet" type="text/css" >' . PHP_EOL . '<link href="/test4.css" media="screen" rel="stylesheet" type="text/css" >' . PHP_EOL . '<link href="/test2.css" media="screen" rel="stylesheet" type="text/css" >' . PHP_EOL . '<link href="/test3.css" media="screen" rel="stylesheet" type="text/css" >';
     $this->assertEquals($expected, $test);
 }
コード例 #3
0
    public function testIndentationIsHonored()
    {
        $this->helper->setIndent(4);
        $this->helper->appendStylesheet('/css/screen.css');
        $this->helper->appendStylesheet('/css/rules.css');
        $string = $this->helper->toString();

        $scripts = substr_count($string, '    <link ');
        $this->assertEquals(2, $scripts);
    }
コード例 #4
0
 /**
  * @group GH-515
  */
 public function testConditionalStylesheetCreationNoIEWidthSpaces()
 {
     $this->helper->setStylesheet('/styles.css', 'screen', '! IE');
     $item = $this->helper->getValue();
     $this->assertObjectHasAttribute('conditionalStylesheet', $item);
     $this->assertEquals('! IE', $item->conditionalStylesheet);
     $string = $this->helper->toString();
     $this->assertContains('/styles.css', $string);
     $this->assertContains('<!--[if ! IE]><!--><', $string);
     $this->assertContains('<!--<![endif]-->', $string);
 }
コード例 #5
0
ファイル: HeadLink.php プロジェクト: solverat/pimcore
 /**
  * Render link elements as string
  *
  * @param  string|int $indent
  * @return string
  */
 public function toString($indent = null)
 {
     // adds the automatic cache buster functionality
     foreach ($this as $item) {
         if (isset($item->href)) {
             $realFile = PIMCORE_DOCUMENT_ROOT . $item->href;
             if (file_exists($realFile)) {
                 $item->href = $item->href . "?_dc=" . filemtime($realFile);
             }
         }
     }
     return parent::toString($indent);
 }
コード例 #6
0
ファイル: HeadLink.php プロジェクト: pimcore/pimcore
 /**
  * Render link elements as string
  *
  * @param  string|int $indent
  * @return string
  */
 public function toString($indent = null)
 {
     foreach ($this as &$item) {
         if ($this->isCacheBuster()) {
             // adds the automatic cache buster functionality
             if (isset($item->href)) {
                 $realFile = PIMCORE_DOCUMENT_ROOT . $item->href;
                 if (file_exists($realFile)) {
                     $item->href = "/cache-buster-" . filemtime($realFile) . $item->href;
                 }
             }
         }
         \Pimcore::getEventManager()->trigger("frontend.view.helper.head-link", $this, ["item" => $item]);
     }
     return parent::toString($indent);
 }
コード例 #7
0
ファイル: HeadLinkTest.php プロジェクト: jsnshrmn/Suma
 /**
  * @group ZF-11643
  */
 public function testSizesAttributeIsSupported()
 {
     $this->helper->headLink(array('rel' => 'icon', 'href' => 'favicon.png', 'sizes' => '16x16', 'type' => 'image/png'));
     $expected = '<link href="favicon.png" rel="icon" type="image/png" sizes="16x16" >';
     $this->assertEquals($expected, $this->helper->toString());
 }
コード例 #8
0
 /**
  * @issue ZF-10345
  */
 public function testIdAttributeIsSupported()
 {
     $this->helper->appendStylesheet(array('href' => '/bar/baz', 'id' => 'foo'));
     $this->assertContains('id="foo"', $this->helper->toString());
 }
コード例 #9
0
ファイル: MinifyHeadLink.php プロジェクト: zelimirus/yard
 /**
  * 
  * Gets a string representation of the headLinks suitable for inserting
  * in the html head section. 
  * 
  * It is important to note that the minified files will be minified
  * in reverse order of being added to this object, and ALL files will be rendered
  * prior to inline being rendered.
  *
  * @see Zend_View_Helper_HeadScript->toString()
  * @param  string|int $indent
  * @return string
  */
 public function toString($indent = null)
 {
     if (!$this->_doMinify) {
         return parent::toString($indent);
         // Do not minify output
     }
     $indent = null !== $indent ? $this->getWhitespace($indent) : $this->getIndent();
     $trimmedBaseUrl = trim($this->getBaseUrl(), '/');
     $items = array();
     $stylesheets = array();
     $this->getContainer()->ksort();
     foreach ($this as $item) {
         if ($item->type == 'text/css' && $item->conditionalStylesheet === false && strpos($item->href, 'http://') === false && $this->isValidStyleSheetExtension($item->href)) {
             $stylesheets[$item->media][] = str_replace($this->getBaseUrl(), '', $item->href);
         } else {
             // first get all the stylsheets up to this point, and get them into
             // the items array
             $seen = array();
             foreach ($stylesheets as $media => $styles) {
                 $minStyles = new stdClass();
                 $minStyles->rel = 'stylesheet';
                 $minStyles->type = 'text/css';
                 $minStyles->href = $this->getMinUrl() . '?f=' . implode(',', $styles);
                 if ($trimmedBaseUrl) {
                     $minStyles->href .= '&b=' . $trimmedBaseUrl;
                 }
                 $minStyles->media = $media;
                 $minStyles->conditionalStylesheet = false;
                 if (in_array($this->itemToString($minStyles), $seen)) {
                     continue;
                 }
                 $items[] = $this->itemToString($minStyles);
                 // add the minified item
                 $seen[] = $this->itemToString($minStyles);
                 // remember we saw it
             }
             $stylesheets = array();
             // Empty our stylesheets array
             $items[] = $this->itemToString($item);
             // Add the item
         }
     }
     // Make sure we pick up the final minified item if it exists.
     $seen = array();
     foreach ($stylesheets as $media => $styles) {
         $minStyles = new stdClass();
         $minStyles->rel = 'stylesheet';
         $minStyles->type = 'text/css';
         $minStyles->href = $this->getMinUrl() . '?f=' . implode(',', $styles);
         if ($trimmedBaseUrl) {
             $minStyles->href .= '&b=' . $trimmedBaseUrl;
         }
         $minStyles->media = $media;
         $minStyles->conditionalStylesheet = false;
         if (in_array($this->itemToString($minStyles), $seen)) {
             continue;
         }
         $items[] = $this->itemToString($minStyles);
         $seen[] = $this->itemToString($minStyles);
     }
     return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items);
 }
コード例 #10
0
ファイル: BundleLink.php プロジェクト: shrekuu/bundle-phu
 /**
  * Iterates over stylesheets, concatenating, optionally minifying,
  * optionally compressiong, and caching them.
  *
  * This detects updates to the source stylesheets using filemtime.
  * A file with an mtime more recent than the mtime of the cached bundle will
  * invalidate the cached bundle.
  *
  * Modifications of captured css cannot be detected by this.
  *
  * @param string $indent
  * @return void
  * @throws UnexpectedValueException if item has no src attribute or contains no captured source
  */
 public function toString($indent = null)
 {
     if (isset($_REQUEST['bundle_off'])) {
         return parent::toString($indent);
     }
     $this->getContainer()->ksort();
     $filelist = '';
     $mostrecent = 0;
     foreach ($this as $item) {
         if (!$this->_isValid($item)) {
             continue;
         }
         if (isset($item->href)) {
             $href = $item->href;
             if ($this->_baseUrl && strpos($href, $this->_baseUrl) !== false) {
                 $href = substr($href, strlen($this->_baseUrl));
             }
             $mtime = filemtime($this->_docRoot . $href);
             if ($mtime > $mostrecent) {
                 $mostrecent = $mtime;
             }
         } else {
             if (!empty($item->source)) {
                 $href = $item->source;
             }
         }
         $filelist .= $href;
     }
     $hash = md5($filelist);
     $cacheFile = "{$this->_cacheDir}/bundle_{$hash}.css";
     $cacheTime = @filemtime($cacheFile);
     if (false === $cacheTime || $cacheTime < $mostrecent) {
         $data = $this->_getCssData();
         $this->_writeUncompressed($cacheFile, $data);
         if ($this->_doGzip) {
             $this->_writeCompressed($cacheFile, $data);
         }
         $cacheTime = filemtime($cacheFile);
     }
     $urlPath = "{$this->_baseUrl}/{$this->_urlPrefix}/bundle_{$hash}.css?{$cacheTime}";
     $ret = '<link href="' . $urlPath . '" media="screen" rel="stylesheet" type="text/css" />';
     return $ret;
 }
コード例 #11
0
ファイル: HeadLink.php プロジェクト: hthetiot/basezf
 /**
  * Retrieve string representation
  *
  * @param  string|int $indent
  * @return string
  */
 public function toString($indent = null)
 {
     // if static pack enable use toStringPacked instead of toString
     if (self::$_packsEnable) {
         return $this->toStringPacked($indent);
     } else {
         return parent::toString($indent);
     }
 }
コード例 #12
0
 public function toString($indent = null)
 {
     $strings = parent::toString($indent);
     $headbase = new Evil_Cdn_HeadBase('css');
     return $headbase->toString($strings);
 }
コード例 #13
0
ファイル: HeadLink.php プロジェクト: hartum/basezf
 /**
  * Retrieve string representation
  *
  * @param  string|int $indent
  * @return string
  */
 public function toString($indent = null)
 {
     // if no static pack
     if (self::$_packsEnable == false) {
         return parent::toString($indent);
     }
     // looking for packs
     $container = array();
     foreach ($this as $item) {
         $itemPack = $this->_getItemPack($item);
         if (is_object($itemPack)) {
             $container[] = $itemPack;
         }
     }
     $indent = null !== $indent ? $this->getWhitespace($indent) : $this->getIndent();
     $items = array();
     foreach ($container as $item) {
         // add prefix only if not contain "http://"
         //self::_addItemHrefPrefix($item);
         $items[] = $this->itemToString($item);
     }
     return $indent . implode($this->_escape($this->getSeparator()) . $indent, $items);
 }
コード例 #14
0
ファイル: HeadLink.php プロジェクト: wthielen/zf1e
 public function toString($indent = null)
 {
     // Return early if no minifier has been set up
     if (false === $this->_minifier || !$this->_minifier->doBundle()) {
         return parent::toString($indent);
     }
     ZFE_Util_Stopwatch::trigger(__METHOD__);
     $container = $this->getContainer();
     $container->ksort();
     $items = $container->getArrayCopy();
     // Collect CSS files
     $compressable = array();
     foreach ($items as $key => $item) {
         if ($item->rel == 'stylesheet' && $item->type == 'text/css' && !$item->conditionalStylesheet) {
             $file = basename($item->href);
             if (in_array($file, $this->doNotBundle)) {
                 continue;
             }
             if (ZFE_Util_String::startsWith($item->href, "http://")) {
                 continue;
             }
             if (ZFE_Util_String::startsWith($item->href, "//")) {
                 continue;
             }
             if (!isset($compressable[$item->media])) {
                 $compressable[$item->media] = array();
             }
             $compressable[$item->media][] = $item;
             unset($items[$key]);
         }
     }
     $container->exchangeArray($items);
     // Collect current data of the CSS files
     $hashes = array();
     $mtimes = array();
     foreach ($compressable as $media => $items) {
         $hash = '';
         $_mtimes = array();
         foreach ($items as $item) {
             $file = $_SERVER['DOCUMENT_ROOT'] . $item->href;
             if (Zend_Loader::isReadable($file)) {
                 $hash .= ':' . $item->href;
                 $_mtimes[] = filemtime($file);
             }
         }
         $hashes[$media] = $hash;
         $mtimes[$media] = $_mtimes;
     }
     // Check if the original CSS files have been updated since the
     // last minification
     foreach ($hashes as $media => $hash) {
         $regenerate = true;
         $filename = sha1($media . $hash) . ".css";
         $cachedir = $this->_minifier->getCacheDir();
         $path = $_SERVER['DOCUMENT_ROOT'] . $cachedir;
         // check directory exists. if not, create it
         if (!file_exists($path)) {
             mkdir($path, 0775, true);
         }
         if (file_exists($path . "/" . $filename)) {
             $mtime = filemtime($path . "/" . $filename);
             $regenerate = array_reduce($mtimes[$media], function ($u, $v) use($mtime) {
                 return $u || $v > $mtime;
             }, false);
         }
         // If any CSS file in this media group has been updated since the last
         // minification, collect the content again, and store it in the cached version
         if ($regenerate) {
             $cssContent = '';
             foreach ($compressable[$media] as $item) {
                 $file = $_SERVER['DOCUMENT_ROOT'] . $item->href;
                 if (Zend_Loader::isReadable($file)) {
                     $cssContent .= file_get_contents($file) . PHP_EOL;
                 }
             }
             $cssContent = $this->_minifier->minify($cssContent);
             file_put_contents($path . "/" . $filename, $cssContent);
         }
         $this->appendStylesheet($cachedir . "/" . $filename, $media);
     }
     ZFE_Util_Stopwatch::trigger(__METHOD__);
     return parent::toString($indent);
 }
コード例 #15
0
ファイル: HeadLinkTest.php プロジェクト: lortnus/zf1
 /**
  * test for ZF-2889
  */
 public function testBooleanStylesheet()
 {
     $this->helper->appendStylesheet(array('href' => '/bar/baz', 'conditionalStylesheet' => false));
     $test = $this->helper->toString();
     $this->assertNotContains('[if false]', $test);
 }