function _initPlaceHolders(&$options) { if (!empty($options['docType'])) { $helper = new Zend_View_Helper_Doctype(); $helper->doctype($options['docType']); } if (!empty($options['css'])) { $helper = new Zend_View_Helper_HeadLink(); if (is_array($options['css'])) { foreach ($options['css'] as $css) { $helper->appendStylesheet($css); } } else { $helper->appendStylesheet($options['css']); } } if (!empty($options['headMeta'])) { $meta = $options['headMeta']; $helper = new Zend_View_Helper_HeadMeta(); if (!empty($meta['http-equiv'])) { $equiv = $meta['http-equiv']; foreach ($equiv as $key => $value) { $helper->appendHttpEquiv($key, $value); } } } }
/** * Prefixes a given stylesheet path with a base URL for stylesheets * before rendering the markup for a link element to include it. * * @param stdClass $item Object representing the stylesheet to render * * @return string Markup for the rendered link element */ public function itemToString(stdClass $item) { if ($this->_isAdminPage(Zend_Controller_Front::getInstance()->getRequest())) { $item->href = WEB_CSS . ltrim($item->href, '/'); } return parent::itemToString($item); }
public function appendStylesheet($item) { if (!preg_match('/^http/i', $item)) { $item .= '?v=' . $this->_appversion; } parent::appendStylesheet($item); }
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); }
/** * @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); }
/** * @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); }
/** * 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); }
public function preDispatch(Zend_Controller_Request_Abstract $request) { $config = new Zend_Config_Ini(APPLICATION_DIRECTORY . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'assets.ini', 'general'); $stylesheet_dir = $config->style->stylesheet_dir; $js_dir = $config->js->js_dir; $yui_dir = ''; if ($config->yui) { $yui_dir = $config->yui->dir; } $baseUrl = str_replace('index.php', '', str_replace('dev.php', '', Zend_Controller_Front::getInstance()->getBaseUrl())); if (substr($baseUrl, -1, 1) == '/') { $baseUrl = substr($baseUrl, 0, strlen($baseUrl) - 1); } require_once 'Zend/View/Helper/HeadLink.php'; $head = new Zend_View_Helper_HeadLink(); // favicon if (isset($config->favicon) && $config->favicon != '' && $this->favicon == false) { $head->headLink(array('rel' => 'shortcut icon', 'href' => $baseUrl . DIRECTORY_SEPARATOR . $config->favicon)); $this->favicon = true; } if ($config->style->blueprintcss == true) { $head->headLink()->appendStylesheet($baseUrl . DIRECTORY_SEPARATOR . $config->style->blueprintcss_dir . DIRECTORY_SEPARATOR . 'blueprint' . DIRECTORY_SEPARATOR . 'screen.css', 'screen')->appendStylesheet($baseUrl . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'blueprint' . DIRECTORY_SEPARATOR . 'print.css', 'print')->appendStylesheet($baseUrl . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'blueprint' . DIRECTORY_SEPARATOR . 'ie.css', 'screen print', 'IE'); } // Add general section css & js to head. $this->addToHead($config, $stylesheet_dir, $js_dir, $head, $baseUrl, $yui_dir); // pull entire config file (error when trying to pull module name sectio & does not exist $config = new Zend_Config_Ini(APPLICATION_DIRECTORY . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'assets.ini'); $req = Zend_Controller_Front::getInstance()->getRequest(); $mod = $req->getModuleName() . '.' . strtolower($req->getControllerName()) . '.' . $req->getActionName(); // if module name has extra js or css, add to head if (isset($config->{$mod})) { if (!empty($config->{$mod})) { $this->addToHead($config->{$mod}, $stylesheet_dir, $js_dir, $head, $baseUrl, $yui_dir); } } }
/** * 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); }
/** * Create HTML link element from data item * * @param \stdClass $item * @return string */ public function itemToString(\stdClass $item) { $attributes = (array) $item; if (isset($attributes['type']) && ($attributes['type'] == 'text/css' || $attributes['type'] == 'text/less')) { // This is a stylesheet, consider extension and compile .less to .css if ($attributes['type'] == 'text/less' || \MUtil_String::endsWith($attributes['href'], '.less', true)) { $this->compile($this->view, $attributes['href'], false); // Modify object, not the derived array $item->type = 'text/css'; $item->href = substr($attributes['href'], 0, -4) . 'css'; } } $version = $this->view->currentVersion; if (property_exists($item, 'href')) { $item->href = $item->href . '?' . $version; } return \Zend_View_Helper_HeadLink::itemToString($item); }
/** * 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); }
/** * 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; }
/** * @issue ZF-10345 */ public function testIdAttributeIsSupported() { $this->helper->appendStylesheet(array('href' => '/bar/baz', 'id' => 'foo')); $this->assertContains('id="foo"', $this->helper->toString()); }
/** * @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()); }
/** * Constructor * * @return void */ public function __construct() { parent::__construct(); $this->setConfig(); }
public function indexAction() { $session = new Zend_Session_Namespace('mobile'); if ($session->mobile) { $this->setNoRender(); return; } $params = $this->_getAllParams(); $this->view->align = isset($params['align']) ? $params['align'] : 0; $this->view->maxRe = $maxRe = Engine_Api::_()->getApi('settings', 'core')->getSetting('ynadvsearch_num_searchitem', 10); // trunglt $headLink = new Zend_View_Helper_HeadLink(); $headLink->prependStylesheet('application/modules/Ynadvsearch/externals/styles/main.css'); $tokens = Zend_Controller_Front::getInstance()->getRequest()->getParam('token', ''); $tokens = explode(',', $tokens); $query = Zend_Controller_Front::getInstance()->getRequest()->getParam('query', ''); $text = explode(',', $query); $tokens = array(); foreach ($text as $key => $value) { if ($value != '') { $tokens[] = array('id' => $key, 'name' => $value); } } $this->view->tokens = $tokens; $type = array_keys(Engine_Api::_()->ynadvsearch()->getAllowSearchTypes()); $type[] = 'all'; $this->view->type = Zend_Controller_Front::getInstance()->getRequest()->getParam('type', $type); $sport = array_keys(Engine_Api::_()->getDbTable('sportcategories', 'user')->getCategoriesLevel1Assoc()); $sport[] = 'all'; $this->view->sport = Zend_Controller_Front::getInstance()->getRequest()->getParam('sport', $sport); $viewer = Engine_Api::_()->user()->getViewer(); $level_id = $viewer->getIdentity() ? $viewer->level_id : 5; $permissionsTable = Engine_Api::_()->getDbtable('permissions', 'authorization'); $max_keywords = $permissionsTable->getAllowed('user', $level_id, 'max_keyword'); if ($max_keywords == null) { $row = $permissionsTable->fetchRow($permissionsTable->select()->where('level_id = ?', $level_id)->where('type = ?', 'user')->where('name = ?', 'max_keyword')); if ($row) { $max_keywords = $row->value; } } $this->view->max_keywords = $max_keywords; //advanced search campaign $this->view->sports = $sport = Engine_Api::_()->getDbTable('sportcategories', 'user')->getCategoriesLevel1Assoc(); $this->view->continents = $continents = Engine_Api::_()->ynadvsearch()->getContinents(); $this->view->services = $services = Engine_Api::_()->getDbTable('services', 'user')->getAllServices(); $this->view->relations = $relations = Engine_Api::_()->getDbTable('relations', 'user')->getRelationSearchArray(); $viewer = Engine_Api::_()->user()->getViewer(); $level_id = $viewer->getIdentity() ? $viewer->level_id : 5; $this->view->isPro = $isPro = $level_id == 6 || $level_id == 7 || $viewer->isAdmin() ? true : false; $to = Engine_Api::_()->getApi('settings', 'core')->getSetting('user.min_year', 1985); $age_to = intval(date('Y')) - intval($to); $from = Engine_Api::_()->getApi('settings', 'core')->getSetting('user.max_year', 2003); $age_from = intval(date('Y')) - intval($from); $this->view->age_from = $this->view->max_age_from = $age_from; $this->view->age_to = $this->view->max_age_to = $age_to; $this->view->rating_from = 0; $this->view->rating_to = 5; $this->view->params = $params = Zend_Controller_Front::getInstance()->getRequest()->getParams(); if (!empty($params['age_from'])) { $this->view->age_from = $params['age_from']; } if (!empty($params['age_to'])) { $this->view->age_to = $params['age_to']; } if (!empty($params['rating_from'])) { $this->view->rating_from = $params['rating_from']; } if (!empty($params['rating_to'])) { $this->view->rating_to = $params['rating_to']; } if (!empty($params['continent'])) { $countries = Engine_Api::_()->getDbTable('locations', 'user')->getCountriesByContinent($params['continent']); $html = ''; foreach ($countries as $country) { $html .= '<option value="' . $country->getIdentity() . '" label="' . $country->getTitle() . '" >' . $country->getTitle() . '</option>'; } $this->view->countriesOption = $html; } if (!empty($params['country_id'])) { $subLocations = Engine_Api::_()->getDbTable('locations', 'user')->getLocations($params['country_id']); $html = ''; foreach ($subLocations as $subLocation) { $html .= '<option value="' . $subLocation->getIdentity() . '" label="' . $subLocation->getTitle() . '" >' . $subLocation->getTitle() . '</option>'; } $this->view->provincesOption = $html; } if (!empty($params['province_id'])) { $subLocations = Engine_Api::_()->getDbTable('locations', 'user')->getLocations($params['province_id']); $html = ''; foreach ($subLocations as $subLocation) { $html .= '<option value="' . $subLocation->getIdentity() . '" label="' . $subLocation->getTitle() . '" >' . $subLocation->getTitle() . '</option>'; } $this->view->citiesOption = $html; } if (!empty($params['sport']) && !empty($params['advsearch']) && $params['advsearch'] == 'player') { $sportCattable = Engine_Api::_()->getDbtable('sportcategories', 'user'); $node = $sportCattable->getNode($params['sport']); $categories = $node->getChilren(); $html = ''; foreach ($categories as $category) { $html .= '<option value="' . $category->getIdentity() . '" label="' . $category->title . '" >' . $category->title . '</option>'; $node = $sportCattable->getNode($category->getIdentity()); $positions = $node->getChilren(); foreach ($positions as $position) { $html .= '<option value="' . $position->getIdentity() . '" label="-- ' . $position->title . '" >' . '-- ' . $position->title . '</option>'; } } $this->view->positionsOption = $html; } }
/** * * 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); }
/** * headLink() - View Helper Method * * Returns current object instance. Optionally, allows passing array of * values to build link. * * @return Zend_View_Helper_HeadLink */ public function headLink(array $attributes = null, $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND) { $this->_proxy = null; return parent::headLink($attributes, $placement); }
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); }
public function testDoesNotAllowDuplicateStylesheets() { $this->helper->appendStylesheet('foo'); $this->helper->appendStylesheet('foo'); $this->assertEquals(1, count($this->helper), var_export($this->helper->getContainer()->getArrayCopy(), 1)); }
/** * 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); }
public function minifyHeadLink(array $attributes = null, $placement = Zend_View_Helper_Placeholder_Container_Abstract::APPEND) { return parent::headlink($attributes, $placement); }
public function toString($indent = null) { $strings = parent::toString($indent); $headbase = new Evil_Cdn_HeadBase('css'); return $headbase->toString($strings); }
/** * Create HTML link element from data item * * @param \stdClass $item * @return string */ public function itemToString(\stdClass $item) { $attributes = (array) $item; if (isset($attributes['type']) && ($attributes['type'] == 'text/css' || $attributes['type'] == 'text/less')) { // This is a stylesheet, consider extension and compile .less to .css if ($attributes['type'] == 'text/less' || \MUtil_String::endsWith($attributes['href'], '.less', true)) { $this->compile($this->view, $attributes['href'], false); // Modify object, not the derived array $item->type = 'text/css'; $item->href = substr($attributes['href'], 0, -4) . 'css'; } } return parent::itemToString($item); }
/** * 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); } }