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

/library/Digitalus/View/Helper/Interface/Link.php

http://digitalus-cms.googlecode.com/
PHP | 119 lines | 66 code | 11 blank | 42 comment | 18 complexity | 6ec5666da3c4cb2f1dd1677eb207f929 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * Link helper
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://digitalus-media.com/license/new-bsd
  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 info@digitalus-media.com so we can send you a copy immediately.
  14. *
  15. * @author Forrest Lyman
  16. * @category Digitalus CMS
  17. * @package Digitalus
  18. * @subpackage Digitalus_View
  19. * @copyright Copyright (c) 2007 - 2010, Digitalus Media USA (digitalus-media.com)
  20. * @license http://digitalus-media.com/license/new-bsd New BSD License
  21. * @version $Id: Link.php 767 2010-05-04 19:22:01Z lowtower@gmx.de $
  22. * @link http://www.digitaluscms.com
  23. * @since Release 1.5.0
  24. */
  25. /**
  26. * @see Zend_View_Helper_Abstract
  27. */
  28. require_once 'Zend/View/Helper/Abstract.php';
  29. /**
  30. * Link helper
  31. *
  32. * @author Forrest Lyman
  33. * @copyright Copyright (c) 2007 - 2010, Digitalus Media USA (digitalus-media.com)
  34. * @license http://digitalus-media.com/license/new-bsd New BSD License
  35. * @version Release: @package_version@
  36. * @link http://www.digitaluscms.com
  37. * @since Release 1.5.0
  38. * @uses viewHelper Digitalus_View_Helper_GetBaseUrl
  39. * @uses viewHelper Digitalus_View_Helper_GetTranslation
  40. */
  41. class Digitalus_View_Helper_Interface_Link extends Zend_View_Helper_Abstract
  42. {
  43. public $link;
  44. public $baseUrl;
  45. /**
  46. *
  47. */
  48. public function link($label, $link, $icon = null, $class = 'link', $target = null, $suppressLabel = false, $translate = true)
  49. {
  50. $this->link = Digitalus_Toolbox_String::stripLeading('/', $link);
  51. $this->baseUrl = Digitalus_Toolbox_String::stripLeading('/', $this->view->getBaseUrl());
  52. // clean the link
  53. if ($this->isRemoteLink($link) || $this->isAnchorLink($link)) {
  54. $cleanLink = $link;
  55. } else {
  56. $cleanLink = '/' . $this->addBaseUrl($this->link);
  57. }
  58. if ($target != null) {
  59. $target = 'target="' . $target . '"';
  60. }
  61. $linkParts[] = '<a href="' . $cleanLink . '" class="' . $class .'" ' . $target . '>';
  62. if (null !== $icon) {
  63. $linkParts[] = $this->getIcon($icon, $label);
  64. }
  65. if (!empty($label) && true != $suppressLabel) {
  66. if (true === (bool)$translate) {
  67. $linkParts[] = $this->view->getTranslation((string)$label);
  68. } else {
  69. $linkParts[] = (string)$label;
  70. }
  71. }
  72. $linkParts[] = '</a>';
  73. return implode(null, $linkParts);
  74. }
  75. public function addBaseUrl($path)
  76. {
  77. if (!empty($this->baseUrl)) {
  78. if (substr($path, 0, strlen($this->baseUrl) != $this->baseUrl)) {
  79. return $this->baseUrl . '/' . $path;
  80. }
  81. }
  82. return $path;
  83. }
  84. public function isAnchorLink($link)
  85. {
  86. if (strpos($link, '#') === false) {
  87. return false;
  88. } else {
  89. return true;
  90. }
  91. }
  92. public function isRemoteLink($link)
  93. {
  94. if (strpos($link, 'http') === false) {
  95. return false;
  96. } else {
  97. return true;
  98. }
  99. }
  100. public function getIcon($icon, $alt)
  101. {
  102. $config = Zend_Registry::get('config');
  103. $this->iconPath = $config->filepath->icons;
  104. $iconPath = $this->iconPath;
  105. $iconPath = $this->addBaseUrl($iconPath . '/' . $icon);
  106. return '<img src="/' . $iconPath . '" title="' . htmlspecialchars($alt) . '" alt="' . htmlspecialchars($alt) . '" class="icon" />';
  107. }
  108. }