PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Core/Block/Html/Link.php

https://bitbucket.org/kdms/sh-magento
PHP | 97 lines | 41 code | 7 blank | 49 comment | 2 complexity | 6faffb1a8179e9b4395dc0ace51ea03f MD5 | raw file
  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  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_Core
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * HTML anchor element block
  28. *
  29. * @category Mage
  30. * @package Mage_Core
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Core_Block_Html_Link extends Mage_Core_Block_Template
  34. {
  35. /**
  36. * Internal constructor
  37. *
  38. */
  39. protected function _construct()
  40. {
  41. $this->setTemplate('core/link.phtml');
  42. parent::_construct();
  43. }
  44. /**
  45. * Prepare link attributes as serialized and formated string
  46. *
  47. * @return string
  48. */
  49. public function getLinkAttributes()
  50. {
  51. $allow = array(
  52. 'href', 'title', 'charset', 'name', 'hreflang', 'rel', 'rev', 'accesskey', 'shape',
  53. 'coords', 'tabindex', 'onfocus', 'onblur', // %attrs
  54. 'id', 'class', 'style', // %coreattrs
  55. 'lang', 'dir', // %i18n
  56. 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove',
  57. 'onmouseout', 'onkeypress', 'onkeydown', 'onkeyup' // %events
  58. );
  59. $attributes = array();
  60. foreach ($allow as $attribute) {
  61. $value = $this->getDataUsingMethod($attribute);
  62. if (!is_null($value)) {
  63. $attributes[$attribute] = $this->htmlEscape($value);
  64. }
  65. }
  66. if (!empty($attributes)) {
  67. return $this->serialize($attributes);
  68. }
  69. return '';
  70. }
  71. /**
  72. * serialize attributes
  73. *
  74. * @param array $attributes
  75. * @param string $valueSeparator
  76. * @param string $fieldSeparator
  77. * @param string $quote
  78. * @return string
  79. */
  80. public function serialize($attributes = array(), $valueSeparator='=', $fieldSeparator=' ', $quote='"')
  81. {
  82. $res = '';
  83. $data = array();
  84. foreach ($attributes as $key => $value) {
  85. $data[] = $key . $valueSeparator . $quote . $value . $quote;
  86. }
  87. $res = implode($fieldSeparator, $data);
  88. return $res;
  89. }
  90. }