Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Catalog_Block_Seo_Sitemap_Tree_Pager
  • Mage_Page_Block_Html
  • Mage_Page_Block_Html_Breadcrumbs
  • Mage_Page_Block_Html_Footer
  • Mage_Page_Block_Html_Head
  • Mage_Page_Block_Html_Header
  • Mage_Page_Block_Html_Notices
  • Mage_Page_Block_Html_Pager
  • Mage_Page_Block_Html_Topmenu
  • Mage_Page_Block_Html_Welcome
  • Mage_Page_Block_Html_Wrapper
  • Mage_Page_Block_Js_Cookie
  • Mage_Page_Block_Redirect
  • Mage_Page_Helper_Data
  • Mage_Page_Helper_Html
  • Mage_Page_Helper_Layout
  • Mage_Page_Model_Config
  • Mage_Page_Model_Source_Layout
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Page
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Html page block
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_Page
 33:  * @author     Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Page_Block_Html_Head extends Mage_Core_Block_Template
 36: {
 37:     /**
 38:      * Initialize template
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->setTemplate('page/html/head.phtml');
 44:     }
 45: 
 46:     /**
 47:      * Add CSS file to HEAD entity
 48:      *
 49:      * @param string $name
 50:      * @param string $params
 51:      * @return Mage_Page_Block_Html_Head
 52:      */
 53:     public function addCss($name, $params = "")
 54:     {
 55:         $this->addItem('skin_css', $name, $params);
 56:         return $this;
 57:     }
 58: 
 59:     /**
 60:      * Add JavaScript file to HEAD entity
 61:      *
 62:      * @param string $name
 63:      * @param string $params
 64:      * @return Mage_Page_Block_Html_Head
 65:      */
 66:     public function addJs($name, $params = "")
 67:     {
 68:         $this->addItem('js', $name, $params);
 69:         return $this;
 70:     }
 71: 
 72:     /**
 73:      * Add CSS file for Internet Explorer only to HEAD entity
 74:      *
 75:      * @param string $name
 76:      * @param string $params
 77:      * @return Mage_Page_Block_Html_Head
 78:      */
 79:     public function addCssIe($name, $params = "")
 80:     {
 81:         $this->addItem('skin_css', $name, $params, 'IE');
 82:         return $this;
 83:     }
 84: 
 85:     /**
 86:      * Add JavaScript file for Internet Explorer only to HEAD entity
 87:      *
 88:      * @param string $name
 89:      * @param string $params
 90:      * @return Mage_Page_Block_Html_Head
 91:      */
 92:     public function addJsIe($name, $params = "")
 93:     {
 94:         $this->addItem('js', $name, $params, 'IE');
 95:         return $this;
 96:     }
 97: 
 98:     /**
 99:      * Add Link element to HEAD entity
100:      *
101:      * @param string $rel forward link types
102:      * @param string $href URI for linked resource
103:      * @return Mage_Page_Block_Html_Head
104:      */
105:     public function addLinkRel($rel, $href)
106:     {
107:         $this->addItem('link_rel', $href, 'rel="' . $rel . '"');
108:         return $this;
109:     }
110: 
111:     /**
112:      * Add HEAD Item
113:      *
114:      * Allowed types:
115:      *  - js
116:      *  - js_css
117:      *  - skin_js
118:      *  - skin_css
119:      *  - rss
120:      *
121:      * @param string $type
122:      * @param string $name
123:      * @param string $params
124:      * @param string $if
125:      * @param string $cond
126:      * @return Mage_Page_Block_Html_Head
127:      */
128:     public function addItem($type, $name, $params=null, $if=null, $cond=null)
129:     {
130:         if ($type==='skin_css' && empty($params)) {
131:             $params = 'media="all"';
132:         }
133:         $this->_data['items'][$type.'/'.$name] = array(
134:             'type'   => $type,
135:             'name'   => $name,
136:             'params' => $params,
137:             'if'     => $if,
138:             'cond'   => $cond,
139:        );
140:         return $this;
141:     }
142: 
143:     /**
144:      * Remove Item from HEAD entity
145:      *
146:      * @param string $type
147:      * @param string $name
148:      * @return Mage_Page_Block_Html_Head
149:      */
150:     public function removeItem($type, $name)
151:     {
152:         unset($this->_data['items'][$type.'/'.$name]);
153:         return $this;
154:     }
155: 
156:     /**
157:      * Get HEAD HTML with CSS/JS/RSS definitions
158:      * (actually it also renders other elements, TODO: fix it up or rename this method)
159:      *
160:      * @return string
161:      */
162:     public function getCssJsHtml()
163:     {
164:         // separate items by types
165:         $lines  = array();
166:         foreach ($this->_data['items'] as $item) {
167:             if (!is_null($item['cond']) && !$this->getData($item['cond']) || !isset($item['name'])) {
168:                 continue;
169:             }
170:             $if     = !empty($item['if']) ? $item['if'] : '';
171:             $params = !empty($item['params']) ? $item['params'] : '';
172:             switch ($item['type']) {
173:                 case 'js':        // js/*.js
174:                 case 'skin_js':   // skin/*/*.js
175:                 case 'js_css':    // js/*.css
176:                 case 'skin_css':  // skin/*/*.css
177:                     $lines[$if][$item['type']][$params][$item['name']] = $item['name'];
178:                     break;
179:                 default:
180:                     $this->_separateOtherHtmlHeadElements($lines, $if, $item['type'], $params, $item['name'], $item);
181:                     break;
182:             }
183:         }
184: 
185:         // prepare HTML
186:         $shouldMergeJs = Mage::getStoreConfigFlag('dev/js/merge_files');
187:         $shouldMergeCss = Mage::getStoreConfigFlag('dev/css/merge_css_files');
188:         $html   = '';
189:         foreach ($lines as $if => $items) {
190:             if (empty($items)) {
191:                 continue;
192:             }
193:             if (!empty($if)) {
194:                 $html .= '<!--[if '.$if.']>'."\n";
195:             }
196: 
197:             // static and skin css
198:             $html .= $this->_prepareStaticAndSkinElements('<link rel="stylesheet" type="text/css" href="%s"%s />' . "\n",
199:                 empty($items['js_css']) ? array() : $items['js_css'],
200:                 empty($items['skin_css']) ? array() : $items['skin_css'],
201:                 $shouldMergeCss ? array(Mage::getDesign(), 'getMergedCssUrl') : null
202:             );
203: 
204:             // static and skin javascripts
205:             $html .= $this->_prepareStaticAndSkinElements('<script type="text/javascript" src="%s"%s></script>' . "\n",
206:                 empty($items['js']) ? array() : $items['js'],
207:                 empty($items['skin_js']) ? array() : $items['skin_js'],
208:                 $shouldMergeJs ? array(Mage::getDesign(), 'getMergedJsUrl') : null
209:             );
210: 
211:             // other stuff
212:             if (!empty($items['other'])) {
213:                 $html .= $this->_prepareOtherHtmlHeadElements($items['other']) . "\n";
214:             }
215: 
216:             if (!empty($if)) {
217:                 $html .= '<![endif]-->'."\n";
218:             }
219:         }
220:         return $html;
221:     }
222: 
223:     /**
224:      * Merge static and skin files of the same format into 1 set of HEAD directives or even into 1 directive
225:      *
226:      * Will attempt to merge into 1 directive, if merging callback is provided. In this case it will generate
227:      * filenames, rather than render urls.
228:      * The merger callback is responsible for checking whether files exist, merging them and giving result URL
229:      *
230:      * @param string $format - HTML element format for sprintf('<element src="%s"%s />', $src, $params)
231:      * @param array $staticItems - array of relative names of static items to be grabbed from js/ folder
232:      * @param array $skinItems - array of relative names of skin items to be found in skins according to design config
233:      * @param callback $mergeCallback
234:      * @return string
235:      */
236:     protected function &_prepareStaticAndSkinElements($format, array $staticItems, array $skinItems, $mergeCallback = null)
237:     {
238:         $designPackage = Mage::getDesign();
239:         $baseJsUrl = Mage::getBaseUrl('js');
240:         $items = array();
241:         if ($mergeCallback && !is_callable($mergeCallback)) {
242:             $mergeCallback = null;
243:         }
244: 
245:         // get static files from the js folder, no need in lookups
246:         foreach ($staticItems as $params => $rows) {
247:             foreach ($rows as $name) {
248:                 $items[$params][] = $mergeCallback ? Mage::getBaseDir() . DS . 'js' . DS . $name : $baseJsUrl . $name;
249:             }
250:         }
251: 
252:         // lookup each file basing on current theme configuration
253:         foreach ($skinItems as $params => $rows) {
254:             foreach ($rows as $name) {
255:                 $items[$params][] = $mergeCallback ? $designPackage->getFilename($name, array('_type' => 'skin'))
256:                     : $designPackage->getSkinUrl($name, array());
257:             }
258:         }
259: 
260:         $html = '';
261:         foreach ($items as $params => $rows) {
262:             // attempt to merge
263:             $mergedUrl = false;
264:             if ($mergeCallback) {
265:                 $mergedUrl = call_user_func($mergeCallback, $rows);
266:             }
267:             // render elements
268:             $params = trim($params);
269:             $params = $params ? ' ' . $params : '';
270:             if ($mergedUrl) {
271:                 $html .= sprintf($format, $mergedUrl, $params);
272:             } else {
273:                 foreach ($rows as $src) {
274:                     $html .= sprintf($format, $src, $params);
275:                 }
276:             }
277:         }
278:         return $html;
279:     }
280: 
281:     /**
282:      * Classify HTML head item and queue it into "lines" array
283:      *
284:      * @see self::getCssJsHtml()
285:      * @param array &$lines
286:      * @param string $itemIf
287:      * @param string $itemType
288:      * @param string $itemParams
289:      * @param string $itemName
290:      * @param array $itemThe
291:      */
292:     protected function _separateOtherHtmlHeadElements(&$lines, $itemIf, $itemType, $itemParams, $itemName, $itemThe)
293:     {
294:         $params = $itemParams ? ' ' . $itemParams : '';
295:         $href   = $itemName;
296:         switch ($itemType) {
297:             case 'rss':
298:                 $lines[$itemIf]['other'][] = sprintf('<link href="%s"%s rel="alternate" type="application/rss+xml" />',
299:                     $href, $params
300:                 );
301:                 break;
302:             case 'link_rel':
303:                 $lines[$itemIf]['other'][] = sprintf('<link%s href="%s" />', $params, $href);
304:                 break;
305:         }
306:     }
307: 
308:     /**
309:      * Render arbitrary HTML head items
310:      *
311:      * @see self::getCssJsHtml()
312:      * @param array $items
313:      * @return string
314:      */
315:     protected function _prepareOtherHtmlHeadElements($items)
316:     {
317:         return implode("\n", $items);
318:     }
319: 
320:     /**
321:      * Retrieve Chunked Items
322:      *
323:      * @param array $items
324:      * @param string $prefix
325:      * @param int $maxLen
326:      * @return array
327:      */
328:     public function getChunkedItems($items, $prefix = '', $maxLen = 450)
329:     {
330:         $chunks = array();
331:         $chunk  = $prefix;
332:         foreach ($items as $item) {
333:             if (strlen($chunk.','.$item)>$maxLen) {
334:                 $chunks[] = $chunk;
335:                 $chunk = $prefix;
336:             }
337:             $chunk .= ','.$item;
338:         }
339:         $chunks[] = $chunk;
340:         return $chunks;
341:     }
342: 
343:     /**
344:      * Retrieve Content Type
345:      *
346:      * @return string
347:      */
348:     public function getContentType()
349:     {
350:         if (empty($this->_data['content_type'])) {
351:             $this->_data['content_type'] = $this->getMediaType().'; charset='.$this->getCharset();
352:         }
353:         return $this->_data['content_type'];
354:     }
355: 
356:     /**
357:      * Retrieve Media Type
358:      *
359:      * @return string
360:      */
361:     public function getMediaType()
362:     {
363:         if (empty($this->_data['media_type'])) {
364:             $this->_data['media_type'] = Mage::getStoreConfig('design/head/default_media_type');
365:         }
366:         return $this->_data['media_type'];
367:     }
368: 
369:     /**
370:      * Retrieve Charset
371:      *
372:      * @return string
373:      */
374:     public function getCharset()
375:     {
376:         if (empty($this->_data['charset'])) {
377:             $this->_data['charset'] = Mage::getStoreConfig('design/head/default_charset');
378:         }
379:         return $this->_data['charset'];
380:     }
381: 
382:     /**
383:      * Set title element text
384:      *
385:      * @param string $title
386:      * @return Mage_Page_Block_Html_Head
387:      */
388:     public function setTitle($title)
389:     {
390:         $this->_data['title'] = Mage::getStoreConfig('design/head/title_prefix') . ' ' . $title
391:             . ' ' . Mage::getStoreConfig('design/head/title_suffix');
392:         return $this;
393:     }
394: 
395:     /**
396:      * Retrieve title element text (encoded)
397:      *
398:      * @return string
399:      */
400:     public function getTitle()
401:     {
402:         if (empty($this->_data['title'])) {
403:             $this->_data['title'] = $this->getDefaultTitle();
404:         }
405:         return htmlspecialchars(html_entity_decode(trim($this->_data['title']), ENT_QUOTES, 'UTF-8'));
406:     }
407: 
408:     /**
409:      * Retrieve default title text
410:      *
411:      * @return string
412:      */
413:     public function getDefaultTitle()
414:     {
415:         return Mage::getStoreConfig('design/head/default_title');
416:     }
417: 
418:     /**
419:      * Retrieve content for description tag
420:      *
421:      * @return string
422:      */
423:     public function getDescription()
424:     {
425:         if (empty($this->_data['description'])) {
426:             $this->_data['description'] = Mage::getStoreConfig('design/head/default_description');
427:         }
428:         return $this->_data['description'];
429:     }
430: 
431:     /**
432:      * Retrieve content for keyvords tag
433:      *
434:      * @return string
435:      */
436:     public function getKeywords()
437:     {
438:         if (empty($this->_data['keywords'])) {
439:             $this->_data['keywords'] = Mage::getStoreConfig('design/head/default_keywords');
440:         }
441:         return $this->_data['keywords'];
442:     }
443: 
444:     /**
445:      * Retrieve URL to robots file
446:      *
447:      * @return string
448:      */
449:     public function getRobots()
450:     {
451:         if (empty($this->_data['robots'])) {
452:             $this->_data['robots'] = Mage::getStoreConfig('design/head/default_robots');
453:         }
454:         return $this->_data['robots'];
455:     }
456: 
457:     /**
458:      * Get miscellanious scripts/styles to be included in head before head closing tag
459:      *
460:      * @return string
461:      */
462:     public function getIncludes()
463:     {
464:         if (empty($this->_data['includes'])) {
465:             $this->_data['includes'] = Mage::getStoreConfig('design/head/includes');
466:         }
467:         return $this->_data['includes'];
468:     }
469: 
470:     /**
471:      * Getter for path to Favicon
472:      *
473:      * @return string
474:      */
475:     public function getFaviconFile()
476:     {
477:         if (empty($this->_data['favicon_file'])) {
478:             $this->_data['favicon_file'] = $this->_getFaviconFile();
479:         }
480:         return $this->_data['favicon_file'];
481:     }
482: 
483:     /**
484:      * Retrieve path to Favicon
485:      *
486:      * @return string
487:      */
488:     protected function _getFaviconFile()
489:     {
490:         $folderName = Mage_Adminhtml_Model_System_Config_Backend_Image_Favicon::UPLOAD_DIR;
491:         $storeConfig = Mage::getStoreConfig('design/head/shortcut_icon');
492:         $faviconFile = Mage::getBaseUrl('media') . $folderName . '/' . $storeConfig;
493:         $absolutePath = Mage::getBaseDir('media') . '/' . $folderName . '/' . $storeConfig;
494: 
495:         if(!is_null($storeConfig) && $this->_isFile($absolutePath)) {
496:             $url = $faviconFile;
497:         } else {
498:             $url = $this->getSkinUrl('favicon.ico');
499:         }
500:         return $url;
501:     }
502: 
503:     /**
504:      * If DB file storage is on - find there, otherwise - just file_exists
505:      *
506:      * @param string $filename
507:      * @return bool
508:      */
509:     protected function _isFile($filename) {
510:         if (Mage::helper('core/file_storage_database')->checkDbUsage() && !is_file($filename)) {
511:             Mage::helper('core/file_storage_database')->saveFileToFilesystem($filename);
512:         }
513:         return is_file($filename);
514:     }
515: }
516: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0