/** * @loadFixture * @test */ public function defaultCss() { $headBlock = new Mage_Page_Block_Html_Head(); $headBlock->addCss('css/styles.css'); $html = $headBlock->getCssJsHtml(); $this->assertContains('css/styles.css', $html); }
/** * @loadFixture * @test */ public function checkVersionOnUnmergedCssFiles() { $this->assertEquals('1', Mage::getStoreConfig('dev/css/addTstampToCssFiles')); $headBlock = new Mage_Page_Block_Html_Head(); $headBlock->addCss('css/styles.css'); $html = $headBlock->getCssJsHtml(); $this->assertNotContains('css/styles.css', $html); $this->assertRegExp('/[0-9]{10}\\.css/', $html); $this->assertRegExp('/css\\/styles\\.[0-9]{10}\\.css/', $html); }
/** * @loadFixture * @test */ public function defaultMergeCss() { $headBlock = new Mage_Page_Block_Html_Head(); $headBlock->addCss('css/styles.css'); $html = $headBlock->getCssJsHtml(); $this->assertNotContains('css/styles.css', $html); $matches = array(); $result = preg_match('/\\/media\\/css\\/[u|s]\\.[a-f0-9]{32}\\.[0-9]{10}\\.css/', $html, $matches); $this->assertEquals(1, $result); $file = Mage::getBaseDir() . $matches[0]; $this->assertTrue(file_exists($file)); $this->assertContains('/* FILE: styles.css */', file_get_contents($file)); }
protected function _toHtml() { if (!Mage::helper('sailthruemail')->isHorizonEnabled()) { return ''; } return parent::_toHtml(); }
/** * Initialize template * */ protected function _construct() { parent::_construct(); if (Mage::helper('ves_tempcp/theme')->isVenusTheme()) { $this->setTemplate('venustheme/tempcp/head.phtml'); } }
/** * Use file storage fileExists * * @param string $filename * @return bool */ protected function _isFile($filename) { if (!Mage::helper('uaudio_storage')->isEnabled()) { return parent::_isFile($filename); } return Mage::getSingleton('core/file_storage')->getStorageModel()->fileExists($filename); }
/** * Get HEAD HTML with CSS/JS/RSS definitions * (actually it also renders other elements, TODO: fix it up or rename this method) * * @return string */ public function getCssJsHtml() { if (!isset($this->_data['items'])) { return ''; } return parent::getCssJsHtml(); }
/** * This will inject the optimizely embed payload into the top of the head tag and remove it from the block stack. * If this isn't ran for some reason, the layout updates should ensure this is still rendered somewhere within * the head tag. * * I considered using an observer here, but core_block_abstract_to_html_before seems to be the only good canidate and this * feels more surgical, considering there's a fallback mechanism in place if there's a rewrite that supercedes this. * * @return string */ public function _toHtml() { $embed = $this->getChildHtml('optimizely_head'); if ($embed) { $this->unsetChild('optimizely_head'); } return $embed . parent::_toHtml(); }
/** * Customize meta robots tags when viewing product. * * @return string */ public function getRobots() { parent::getRobots(); if (($_product = Mage::registry('current_product')) && ($robots = $_product->getAttributeText('inchoo_meta_robots'))) { $this->_data['robots'] = $robots; } return $this->_data['robots']; }
/** * Get HEAD HTML with CSS/JS/RSS definitions * (actually it also renders other elements, TODO: fix it up or rename this method) * * @return string */ public function getCssJsHtml() { foreach ($this->_data['items'] as $itemKey => $itemValue) { $sortedItems[$itemKey] = $itemValue['sort']; } array_multisort($sortedItems, SORT_NUMERIC, $this->_data['items']); array_multisort($this->_data['items'], SORT_STRING, $sortedItems); return parent::getCssJsHtml(); }
/** * {@inheritdoc} */ protected function &_prepareStaticAndSkinElements($format, array $staticItems, array $skinItems, $mergeCallback = null) { $html = parent::_prepareStaticAndSkinElements($format, $staticItems, $skinItems, $mergeCallback); if (Mage::getStoreConfigFlag('web/cache_buster/active')) { $add = sprintf('?%s=%s', Mage::getStoreConfig('web/cache_buster/param'), Mage::getStoreConfig('web/cache_buster/value')); $html = preg_replace('/\\.(css|js)"/i', '.$1' . $add . '"', $html); } return $html; }
public function __construct() { parent::__construct(); $blacklist = array_merge(explode(',', Mage::getStoreConfig('dev/js/speedster_merge_blacklist')), explode(',', Mage::getStoreConfig('dev/css/speedster_merge_blacklist'))); foreach ($blacklist as $listItem) { $listItem = Mage::helper('speedsterAdvanced')->normaliseUrl($listItem); if ($listItem) { $this->_speedsterMergeBlacklist[$listItem] = true; } } }
public function getCssJsHtml() { if ($this->getRequest()->getModuleName() == 'anattadesign_awesomecheckout' && $this->getRequest()->getControllerName() == 'onepage' && $this->getRequest()->getActionName() != 'success') { $whitelisted = $this->getWhitelistedCssJsItems(); foreach ($this->_data['items'] as $item) { if (in_array($item['name'], $whitelisted)) { continue; // Don't touch it, let it rain over me } else { $this->removeItem($item['type'], $item['name']); } } } return parent::getCssJsHtml(); }
/** * Render HTML for the added head items * * @return string */ public function getCssJsHtml() { /** @var $block Mage_DesignEditor_Block_Page_Html_Head_Vde */ $block = $this->getLayout()->getBlock('vde_head'); if ($block) { // remove all current JS files foreach (array_keys($this->_data['items']) as $itemKey) { if (strpos($itemKey, 'js/') === 0) { unset($this->_data['items'][$itemKey]); } } // add data from VDE head $vdeItems = $block->getData('items'); $this->_data['items'] = array_merge($this->_data['items'], $vdeItems); } return parent::getCssJsHtml(); }
/** * Functionality @see Mage_Page_Block_Html_Head * Adds to parameters to influence the ordering * * @param string $type @see Mage_Page_Block_Html_Head * @param string $name @see Mage_Page_Block_Html_Head * @param null $params @see Mage_Page_Block_Html_Head * @param null $if @see Mage_Page_Block_Html_Head * @param null $cond @see Mage_Page_Block_Html_Head * @param string $referenceName name of the item to insert the element before. If name is not found, insert at the end, * has special meaning (before all / before all) * @param bool $before If true insert before the $referenceName instead of after * @return N98_LayoutHelper_Block_Page_Html_Head */ public function addItem($type, $name, $params = null, $if = null, $cond = null, $referenceName = "*", $before = false) { // allow skipping of parameters in the layout XML files via empty-string if ($params == '') { $params = null; } if ($if == '') { $if = null; } if ($cond == '') { $cond = null; } parent::addItem($type, $name, $params, $if, $cond); // that is the standard behaviour if ($referenceName == '*' && $before == false) { return $this; } $this->_sortItems($referenceName, $before, $type); return $this; }
public function getCssJsHtml() { $helper = Mage::helper('magicthumb/settings'); if (!method_exists($helper, 'isModuleOutputEnabled') && !Mage::getStoreConfigFlag('advanced/modules_disable_output/MagicToolbox_MagicThumb') || $helper->isModuleOutputEnabled()) { //check Magento version $mageVersion = Mage::getVersion(); $pattern = "/([0-9]+\\.[0-9]+\\.[0-9]+)(?:\\.(?:[0-9]+))*/"; $matches = array(); if (preg_match($pattern, $mageVersion, $matches)) { if (version_compare($matches[1], '1.4.1', '<')) { if (isset($this->_data['items']['js/varien/menu.js'])) { $this->_data['items']['js/varien/menu.js']['name'] = 'magicthumb/menu.js'; } if (isset($this->_data['items']['js/varien/iehover-fix.js'])) { $this->_data['items']['js/varien/iehover-fix.js']['name'] = 'magicthumb/iehover-fix.js'; } } } } return parent::getCssJsHtml(); }
public function getCssJsHtml() { $helper = Mage::helper('magicslideshow/settings'); if ($helper->isModuleOutputEnabled()) { //check Magento version $mageVersion = Mage::getVersion(); $pattern = "/([0-9]+\\.[0-9]+\\.[0-9]+)(?:\\.(?:[0-9]+))*/"; $matches = array(); if (preg_match($pattern, $mageVersion, $matches)) { if (version_compare($matches[1], '1.4.1', '<')) { if (isset($this->_data['items']['js/varien/menu.js'])) { $this->_data['items']['js/varien/menu.js']['name'] = 'magicslideshow/menu.js'; } if (isset($this->_data['items']['js/varien/iehover-fix.js'])) { $this->_data['items']['js/varien/iehover-fix.js']['name'] = 'magicslideshow/iehover-fix.js'; } } } } return parent::getCssJsHtml(); }
/** * Get HEAD HTML with CSS/JS/RSS definitions * (actually it also renders other elements, TODO: fix it up or rename this method) * * @return string */ public function getCssJsHtml() { $isVenusTheme = $this->_isVenusTheme; if (!$isVenusTheme) { //check if not venus theme return parent getCssJsHtml return parent::getCssJsHtml(); } //venustheme compress js,css $ves = Mage::helper('themesettings'); $compress_css_type = $ves->getConfig("compression/compress_css_type"); $compress_js_type = $ves->getConfig("compression/compress_js_type"); $js_excludes = $css_excludes = $excludeItems = array(); if ($compress_js_type != '') { $exclude_js_files = $ves->getConfig("compression/exclude_js_files"); $exclude_js_files = trim($exclude_js_files); $js_excludes = explode(",", $exclude_js_files); if (!empty($js_excludes)) { foreach ($js_excludes as $k => $item) { $js_excludes[$k] = trim($item); } if (count($js_excludes) == 0) { $js_excludes[0] = $exclude_js_files; } } } if ($compress_css_type != '') { $exclude_css_files = $ves->getConfig("compression/exclude_css_files"); $exclude_css_files = trim($exclude_css_files); $excludes = explode(",", $exclude_css_files); if (!empty($excludes)) { foreach ($excludes as $k => $item) { $css_excludes[$k] = trim($item); } if (count($css_excludes) == 0) { $css_excludes[0] = $exclude_css_files; } } } // separate items by types $lines = array(); foreach ($this->_data['items'] as $item) { if (!is_null($item['cond']) && !$this->getData($item['cond']) || !isset($item['name'])) { continue; } $if = !empty($item['if']) ? $item['if'] : ''; $params = !empty($item['params']) ? $item['params'] : ''; switch ($item['type']) { case 'js': // js/*.js // js/*.js case 'skin_js': // skin/*/*.js $lines[$if][$item['type']][$params][$item['name']] = $item['name']; // Ves Compression if ($isVenusTheme && count($js_excludes) > 0 && in_array($item['name'], $js_excludes) && $compress_js_type != '') { $excludeItems[$if][$item['type']][$params][$item['name']] = $item['name']; unset($lines[$if][$item['type']][$params][$item['name']]); } break; case 'js_css': // js/*.css // js/*.css case 'skin_css': // skin/*/*.css $lines[$if][$item['type']][$params][$item['name']] = $item['name']; // Ves Compression if ($isVenusTheme && count($css_excludes) > 0 && in_array($item['name'], $css_excludes) && $compress_css_type != '') { $excludeItems[$if][$item['type']][$params][$item['name']] = $item['name']; unset($lines[$if][$item['type']][$params][$item['name']]); } break; default: $this->_separateOtherHtmlHeadElements($lines, $if, $item['type'], $params, $item['name'], $item); break; } } // prepare HTML $shouldMergeJs = Mage::getStoreConfigFlag('dev/js/merge_files'); $shouldMergeCss = Mage::getStoreConfigFlag('dev/css/merge_css_files'); // Override if ($isVenusTheme) { $shouldMergeJs = $compress_js_type; $shouldMergeCss = $compress_css_type; } $html = ''; foreach ($lines as $if => $items) { if (empty($items)) { continue; } if (!empty($if)) { // open !IE conditional using raw value if (strpos($if, "><!-->") !== false) { $html .= $if . "\n"; } else { $html .= '<!--[if ' . $if . ']>' . "\n"; } } // static and skin css $html .= $this->_prepareStaticAndSkinElements('<link rel="stylesheet" type="text/css" href="%s"%s />' . "\n", empty($items['js_css']) ? array() : $items['js_css'], empty($items['skin_css']) ? array() : $items['skin_css'], $shouldMergeCss ? array(Mage::getDesign(), 'getMergedCssUrl') : null); // static and skin javascripts $html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n", empty($items['js']) ? array() : $items['js'], empty($items['skin_js']) ? array() : $items['skin_js'], $shouldMergeJs ? array(Mage::getDesign(), 'getMergedJsUrl') : null); // other stuff if (!empty($items['other'])) { $html .= $this->_prepareOtherHtmlHeadElements($items['other']) . "\n"; } if (!empty($if)) { // close !IE conditional comments correctly if (strpos($if, "><!-->") !== false) { $html .= '<!--<![endif]-->' . "\n"; } else { $html .= '<![endif]-->' . "\n"; } } } if ($isVenusTheme && is_array($excludeItems) && count($excludeItems) > 0) { // Vess Compression $shouldMergeJs = false; $shouldMergeCss = false; foreach ($excludeItems as $if => $items) { if (empty($items)) { continue; } if (!empty($if)) { // open !IE conditional using raw value if (strpos($if, "><!-->") !== false) { $html .= $if . "\n"; } else { $html .= '<!--[if ' . $if . ']>' . "\n"; } } // static and skin css $html .= $this->_prepareStaticAndSkinElements('<link rel="stylesheet" type="text/css" href="%s"%s />' . "\n", empty($items['js_css']) ? array() : $items['js_css'], empty($items['skin_css']) ? array() : $items['skin_css'], $shouldMergeCss ? array(Mage::getDesign(), 'getMergedCssUrl') : null); // static and skin javascripts $html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n", empty($items['js']) ? array() : $items['js'], empty($items['skin_js']) ? array() : $items['skin_js'], $shouldMergeJs ? array(Mage::getDesign(), 'getMergedJsUrl') : null); // other stuff if (!empty($items['other'])) { $html .= $this->_prepareOtherHtmlHeadElements($items['other']) . "\n"; } if (!empty($if)) { // close !IE conditional comments correctly if (strpos($if, "><!-->") !== false) { $html .= '<!--<![endif]-->' . "\n"; } else { $html .= '<![endif]-->' . "\n"; } } } } return $html; }
public function testGetCssJsHtml() { $this->_block->addJs('zero.js', '', null, 'nonexisting_condition')->addJs('varien/js.js')->addJs('Mage_Bundle::bundle.js')->addCss('tiny_mce/themes/advanced/skins/default/ui.css')->addCss('css/styles.css', ' media="print" ')->addRss('RSS Feed', 'http://example.com/feed.xml')->addLinkRel('next', 'http://example.com/page1.html')->addJs('varien/form.js', '', 'lt IE 7'); $this->assertEquals('<script type="text/javascript" src="http://localhost/pub/js/varien/js.js"></script>' . "\n" . '<script type="text/javascript" ' . 'src="http://localhost/pub/media/skin/frontend/default/default/default/en_US/Mage_Bundle/bundle.js">' . '</script>' . "\n" . '<link rel="stylesheet" type="text/css" media="all"' . ' href="http://localhost/pub/js/tiny_mce/themes/advanced/skins/default/ui.css" />' . "\n" . '<link rel="stylesheet" type="text/css" media="print" ' . 'href="http://localhost/pub/media/skin/frontend/default/default/default/en_US/css/styles.css" />' . "\n" . '<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://example.com/feed.xml" />' . "\n" . '<link rel="next" href="http://example.com/page1.html" />' . "\n" . '<!--[if lt IE 7]>' . "\n" . '<script type="text/javascript" src="http://localhost/pub/js/varien/form.js"></script>' . "\n" . '<![endif]-->' . "\n", $this->_block->getCssJsHtml()); }
/** * Changes output file format and add version * * @param string $format * @param array $staticItems * @param array $skinItems * @param null|callback $mergeCallback * @return string */ protected function &_prepareStaticAndSkinElements($format, array $staticItems, array $skinItems, $mergeCallback = null) { $helper = Mage::helper('oro_asset'); if ($helper->isEnabled()) { // css if (preg_match('#<link.*href="([^"]+)"#', $format, $match)) { $search = sprintf('href="%s"', $match[1]); $replace = sprintf('href="%s?ver=%d"', $match[1], $helper->getCssVersion()); $format = str_replace($search, $replace, $format); } // js if (preg_match('#<script.*src="([^"]+)"#', $format, $match)) { $search = sprintf('src="%s"', $match[1]); $replace = sprintf('src="%s?ver=%d"', $match[1], $helper->getCssVersion()); $format = str_replace($search, $replace, $format); } foreach ($staticItems as &$rows) { foreach ($rows as &$name) { $pos = strpos($name, '?'); if ($pos !== false) { $name = substr($name, 0, $pos); } } } foreach ($skinItems as &$rows) { foreach ($rows as &$name) { $pos = strpos($name, '?'); if ($pos !== false) { $name = substr($name, 0, $pos); } } } } return parent::_prepareStaticAndSkinElements($format, $staticItems, $skinItems, $mergeCallback); }
public function getChunkedItems($items, $prefix = '', $maxLen = 2000) { if (!Mage::getStoreConfigFlag('foomanspeedster/settings/enabled')) { return parent::getChunkedItems($items, $prefix, 450); } $chunks = array(); $chunk = $prefix; foreach ($items as $item) { if (strlen($chunk . ',' . $item) > $maxLen) { $chunks[] = $chunk; $chunk = $prefix; } //this is the first item if ($chunk === $prefix) { //remove first slash, only needed to create double slash for minify shortcut to document root $chunk .= substr($item, 1); } else { //remove first slash, only needed to create double slash for minify shortcut to document root $chunk .= ',' . substr($item, 1); } } $chunks[] = $chunk; return $chunks; }
/** * Test getRobots * * @magentoConfigFixture default_store design/search_engine_robots/default_robots INDEX,NOFOLLOW */ public function testGetRobots() { $this->assertEquals('INDEX,NOFOLLOW', $this->_block->getRobots()); }
/** * @param Mage_Page_Block_Html_Head $head * @param string $rel * @param string $url */ public function addLinkRel($head, $rel, $url) { $items = $head->getData('items'); $items['link_rel_prev/' . $url] = array('type' => 'link_rel', 'name' => $url, 'params' => 'rel="' . $rel . '"', 'if' => null, 'cond' => null); $head->setData('items', $items); }
/** * @param Mage_Core_Controller_Request_Http $request * @param Mage_Core_Model_Layout $layout * @param Mage_Core_Model_Event_Manager $eventManager * @param Mage_Backend_Model_Url $urlBuilder * @param Mage_Core_Model_Translate $translator * @param Mage_Core_Model_Cache $cache * @param Mage_Core_Model_Design_Package $designPackage * @param Mage_Core_Model_Session $session * @param Mage_Core_Model_Store_Config $storeConfig * @param Mage_Core_Controller_Varien_Front $frontController * @param Mage_Core_Model_Factory_Helper $helperFactory * @param Magento_Filesystem $filesystem * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(Mage_Core_Controller_Request_Http $request, Mage_Core_Model_Layout $layout, Mage_Core_Model_Event_Manager $eventManager, Mage_Backend_Model_Url $urlBuilder, Mage_Core_Model_Translate $translator, Mage_Core_Model_Cache $cache, Mage_Core_Model_Design_Package $designPackage, Mage_Core_Model_Session $session, Mage_Core_Model_Store_Config $storeConfig, Mage_Core_Controller_Varien_Front $frontController, Mage_Core_Model_Factory_Helper $helperFactory, Magento_Filesystem $filesystem, array $data = array()) { parent::__construct($request, $layout, $eventManager, $urlBuilder, $translator, $cache, $designPackage, $session, $storeConfig, $frontController, $helperFactory, $filesystem, $data); }
/** * @param Mage_Page_Block_Html_Head $head * @return string */ protected function _getInitialDescription($head) { $result = $head->getData('description'); return $result; }
public function getCssJsHtml() { $js_files = ''; $html = ''; $test = ''; $baseJs = Mage::getBaseUrl('js'); $script = '<script type="text/javascript" src="%s" %s></script>'; if (Mage::getStoreConfig('mxperts/jquerysettings/active') == 1) { $js_files = $this->getjQueryFilenames(); if (is_array($this->additional_files) && count($this->additional_files) > 0) { foreach ($this->additional_files as $filename) { $js_files[] = $filename; } } foreach ($js_files as $filename) { if (Mage::getStoreConfigFlag('dev/js/merge_files')) { $html .= ',' . $filename; } else { $html .= sprintf($script, $baseJs . $filename, '') . "\n"; } } if (Mage::getStoreConfigFlag('dev/js/merge_files')) { $html = sprintf($script, $baseJs . 'index.php?c=auto&f=' . $html, '') . "\n"; } } // .../active') == 1 $html .= parent::getCssJsHtml() . $this->getjQueryScript('1') . $this->getjQueryScript('2') . $this->getSkinJs() . $this->getSkinCSS(); return $html; }
/** * Remove External Item from HEAD entity * * @param string $type * @param string $name * @return Mage_Page_Block_Html_Head */ public function removeExternalItem($type, $name) { parent::removeItem($type, $name); }
/** * @param Mage_Page_Block_Html_Head $head * @return string */ protected function getOldMetaTitle($head) { $title = $head->getTitle(); // trim prefix if any $prefix = Mage::getStoreConfig('design/head/title_prefix'); $prefix = htmlspecialchars(html_entity_decode(trim($prefix), ENT_QUOTES, 'UTF-8')); if ($prefix) { $title = substr($title, strlen($prefix)); } $suffix = Mage::getStoreConfig('design/head/title_suffix'); $suffix = htmlspecialchars(html_entity_decode(trim($suffix), ENT_QUOTES, 'UTF-8')); if ($suffix) { $title = substr($title, 0, -1 - strlen($suffix)); } return $title; }
/** * Classify HTML head item and queue it into "lines" array * * @param array &$lines * @param string $itemIf * @param string $itemType * @param string $itemParams * @param string $itemName * @param array $itemThe */ protected function _separateOtherHtmlHeadElements(&$lines, $itemIf, $itemType, $itemParams, $itemName, $itemThe) { parent::_separateOtherHtmlHeadElements($lines, $itemIf, $itemType, $itemParams, $itemName, $itemThe); $params = $itemParams ? ' ' . $itemParams : ''; $href = $itemName; switch ($itemType) { case 'ext_js': $lines[$itemIf]['other'][] = sprintf('<script type="text/javascript" src="%s"%s></script>', $href, $params); break; case 'ext_css': $lines[$itemIf]['other'][] = sprintf('<link rel="stylesheet" type="text/css" href="%s"%s />', $href, $params); break; } }