/** * @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); }
/** * 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(); }
/** * 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(); }
/** * @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); }
/** * 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 ''; } if ($this->_sortAssets) { $this->_sortAssets(); $this->_sortAssets = false; } return parent::getCssJsHtml(); }
/** * @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)); }
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(); }
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(); }
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(); }
/** * 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 getCssJsHtml() { if (!Mage::getStoreConfigFlag('foomanspeedster/settings/enabled')) { return parent::getCssJsHtml(); } $webroot = "/"; $lines = array(); $baseJs = Mage::getBaseUrl('js'); $baseJsFast = Mage::getBaseUrl('skin') . 'm/'; Mage::getConfig()->getVarDir('minifycache'); $html = ''; //$html = "<!--".BP."-->\n"; $script = '<script type="text/javascript" src="%s" %s></script>'; $stylesheet = '<link type="text/css" rel="stylesheet" href="%s" %s />'; $alternate = '<link rel="alternate" type="%s" href="%s" %s />'; foreach ($this->_data['items'] as $item) { if (!is_null($item['cond']) && !$this->getData($item['cond'])) { continue; } $if = !empty($item['if']) ? $item['if'] : ''; switch ($item['type']) { case 'js': if (strpos($item['name'], 'packaging.js') !== false) { $item['name'] = $baseJs . $item['name']; $lines[$if]['script_direct'][] = $item; } else { $lines[$if]['script']['global'][] = "/" . $webroot . "js/" . $item['name']; } break; case 'script_direct': $lines[$if]['script_direct'][] = $item; break; case 'css_direct': $lines[$if]['css_direct'][] = $item; break; case 'js_css': $lines[$if]['other'][] = sprintf($stylesheet, $baseJs . $item['name'], $item['params']); break; case 'skin_js': $chunks = explode('/skin', $this->getSkinUrl($item['name']), 2); $skinJsURL = "/" . $webroot . "skin" . $chunks[1]; if (strpos($item['name'], '.min.js') !== false) { $skinJsLoc = BP . DS . "skin" . $chunks[1]; $skinJsContent = file_get_contents($skinJsLoc); if (preg_match('/@ sourceMappingURL=([^\\s]*)/s', $skinJsContent, $matches)) { //create a file without source map $md5 = md5($skinJsContent); $skinJsLoc = str_replace('.min.js', '.' . $md5 . '.min.js', $skinJsLoc); $skinJsURL = str_replace('.min.js', '.' . $md5 . '.min.js', $skinJsURL); if (!file_exists($skinJsLoc)) { file_put_contents($skinJsLoc, str_replace($matches[0], 'orig file with source map: ' . $this->getSkinUrl($item['name']), $skinJsContent)); } } } $lines[$if]['script']['skin'][] = $skinJsURL; break; case 'skin_css': if ($item['params'] == 'media="all"') { $chunks = explode('/skin', $this->getSkinUrl($item['name']), 2); $lines[$if]['stylesheet'][] = "/" . $webroot . "skin" . $chunks[1]; } elseif ($item['params'] == 'media="print"') { $chunks = explode('/skin', $this->getSkinUrl($item['name']), 2); $lines[$if]['stylesheet_print'][] = "/" . $webroot . "skin" . $chunks[1]; } else { $lines[$if]['other'][] = sprintf($stylesheet, $this->getSkinUrl($item['name']), $item['params']); } break; case 'rss': $lines[$if]['other'][] = sprintf($alternate, 'application/rss+xml', $item['name'], $item['params']); break; case 'link_rel': $lines[$if]['other'][] = sprintf('<link %s href="%s" />', $item['params'], $item['name']); break; case 'ext_js': default: $lines[$if]['other'][] = sprintf('<script type="text/javascript" src="%s"></script>', $item['name']); break; } } foreach ($lines as $if => $items) { if (!empty($if)) { // open !IE conditional using raw value if (strpos($if, "><!-->") !== false) { $html .= $if . "\n"; } else { $html .= '<!--[if ' . $if . ']>' . "\n"; } } if (!empty($items['stylesheet'])) { $cssBuild = Mage::getModel('speedster/buildSpeedster', array($items['stylesheet'], BP)); foreach ($this->getChunkedItems($items['stylesheet'], $baseJsFast . $cssBuild->getLastModified()) as $item) { $html .= sprintf($stylesheet, $item, 'media="all"') . "\n"; } } if (!empty($items['script']['global']) || !empty($items['script']['skin'])) { if (!empty($items['script']['global']) && !empty($items['script']['skin'])) { $mergedScriptItems = array_merge($items['script']['global'], $items['script']['skin']); } elseif (!empty($items['script']['global']) && empty($items['script']['skin'])) { $mergedScriptItems = $items['script']['global']; } else { $mergedScriptItems = $items['script']['skin']; } $jsBuild = Mage::getModel('speedster/buildSpeedster', array($mergedScriptItems, BP)); $chunkedItems = $this->getChunkedItems($mergedScriptItems, $baseJsFast . $jsBuild->getLastModified()); foreach ($chunkedItems as $item) { $html .= sprintf($script, $item, '') . "\n"; } } if (!empty($items['css_direct'])) { foreach ($items['css_direct'] as $item) { $html .= sprintf($stylesheet, $item['name']) . "\n"; } } if (!empty($items['script_direct'])) { foreach ($items['script_direct'] as $item) { $html .= sprintf($script, $item['name'], '') . "\n"; } } if (!empty($items['stylesheet_print'])) { $cssBuild = Mage::getModel('speedster/buildSpeedster', array($items['stylesheet_print'], BP)); foreach ($this->getChunkedItems($items['stylesheet_print'], $baseJsFast . $cssBuild->getLastModified()) as $item) { $html .= sprintf($stylesheet, $item, 'media="print"') . "\n"; } } if (!empty($items['other'])) { $html .= join("\n", $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/lib/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/lib/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/lib/varien/form.js"></script>' . "\n" . '<![endif]-->' . "\n", $this->_block->getCssJsHtml()); }
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; }
public function getCssJsHtml() { if (!Mage::getStoreConfigFlag('foomanspeedster/settings/enabled')) { return parent::getCssJsHtml(); } $webroot = "/"; $lines = array(); $baseJs = Mage::getBaseUrl('js'); $baseJsFast = Mage::getBaseUrl('skin') . 'm/'; $html = ''; //$html = "<!--".BP."-->\n"; $script = '<script type="text/javascript" src="%s" %s></script>'; $stylesheet = '<link type="text/css" rel="stylesheet" href="%s" %s />'; $alternate = '<link rel="alternate" type="%s" href="%s" %s />'; foreach ($this->_data['items'] as $item) { if (!is_null($item['cond']) && !$this->getData($item['cond'])) { continue; } $if = !empty($item['if']) ? $item['if'] : ''; switch ($item['type']) { case 'js': if (strpos($item['name'], 'packaging.js') !== false) { $item['name'] = $baseJs . $item['name']; $lines[$if]['script_direct'][] = $item; } else { $lines[$if]['script']['global'][] = "/" . $webroot . "js/" . $item['name']; } break; case 'script_direct': $lines[$if]['script_direct'][] = $item; break; case 'css_direct': $lines[$if]['css_direct'][] = $item; break; case 'js_css': $lines[$if]['other'][] = sprintf($stylesheet, $baseJs . $item['name'], $item['params']); break; case 'skin_js': $chunks = explode('/skin', $this->getSkinUrl($item['name']), 2); $lines[$if]['script']['skin'][] = "/" . $webroot . "skin" . $chunks[1]; break; case 'skin_css': if ($item['params'] == 'media="all"') { $chunks = explode('/skin', $this->getSkinUrl($item['name']), 2); $lines[$if]['stylesheet'][] = "/" . $webroot . "skin" . $chunks[1]; } elseif ($item['params'] == 'media="print"') { $chunks = explode('/skin', $this->getSkinUrl($item['name']), 2); $lines[$if]['stylesheet_print'][] = "/" . $webroot . "skin" . $chunks[1]; } else { $lines[$if]['other'][] = sprintf($stylesheet, $this->getSkinUrl($item['name']), $item['params']); } break; case 'rss': $lines[$if]['other'][] = sprintf($alternate, 'application/rss+xml', $item['name'], $item['params']); break; case 'link_rel': $lines[$if]['other'][] = sprintf('<link %s href="%s" />', $item['params'], $item['name']); break; case 'ext_js': default: $lines[$if]['other'][] = sprintf('<script type="text/javascript" src="%s"></script>', $item['name']); break; } } foreach ($lines as $if => $items) { if (!empty($if)) { $html .= '<!--[if ' . $if . ']>' . "\n"; } if (!empty($items['stylesheet'])) { $cssBuild = Mage::getModel('speedster/buildSpeedster', array($items['stylesheet'], BP)); foreach ($this->getChunkedItems($items['stylesheet'], $baseJsFast . $cssBuild->getLastModified()) as $item) { $html .= sprintf($stylesheet, $item, 'media="all"') . "\n"; } } if (!empty($items['script']['global']) || !empty($items['script']['skin'])) { if (!empty($items['script']['global']) && !empty($items['script']['skin'])) { $mergedScriptItems = array_merge($items['script']['global'], $items['script']['skin']); } elseif (!empty($items['script']['global']) && empty($items['script']['skin'])) { $mergedScriptItems = $items['script']['global']; } else { $mergedScriptItems = $items['script']['skin']; } $jsBuild = Mage::getModel('speedster/buildSpeedster', array($mergedScriptItems, BP)); $chunkedItems = $this->getChunkedItems($mergedScriptItems, $baseJsFast . $jsBuild->getLastModified()); foreach ($chunkedItems as $item) { $html .= sprintf($script, $item, '') . "\n"; } } if (!empty($items['css_direct'])) { foreach ($items['css_direct'] as $item) { $html .= sprintf($stylesheet, $item['name']) . "\n"; } } if (!empty($items['script_direct'])) { foreach ($items['script_direct'] as $item) { $html .= sprintf($script, $item['name'], '') . "\n"; } } if (!empty($items['stylesheet_print'])) { $cssBuild = Mage::getModel('speedster/buildSpeedster', array($items['stylesheet_print'], BP)); foreach ($this->getChunkedItems($items['stylesheet_print'], $baseJsFast . $cssBuild->getLastModified()) as $item) { $html .= sprintf($stylesheet, $item, 'media="print"') . "\n"; } } if (!empty($items['other'])) { $html .= join("\n", $items['other']) . "\n"; } if (!empty($if)) { $html .= '<![endif]-->' . "\n"; } } return $html; }