PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Croogo/View/Helper/CroogoHtmlHelper.php

https://github.com/kareypowell/croogo
PHP | 171 lines | 133 code | 18 blank | 20 comment | 19 complexity | f0416d4ba6cebd28dc55cafde7eb8b8b MD5 | raw file
  1. <?php
  2. App::uses('HtmlHelper', 'View/Helper');
  3. /**
  4. * Croogo Html Helper
  5. *
  6. * @package Croogo.Croogo.View.Helper
  7. */
  8. class CroogoHtmlHelper extends HtmlHelper {
  9. public function __construct(View $View, $settings = array()) {
  10. parent::__construct($View, $settings);
  11. $this->_tags['beginbox'] =
  12. '<div class="row-fluid">
  13. <div class="span12">
  14. <div class="box">
  15. <div class="box-title">
  16. <i class="icon-list"></i>
  17. %s
  18. </div>
  19. <div class="box-content %s">';
  20. $this->_tags['endbox'] =
  21. '</div>
  22. </div>
  23. </div>
  24. </div>';
  25. $this->_tags['icon'] = '<i class="%s"%s></i> ';
  26. }
  27. public function beginBox($title, $isHidden = false, $isLabelHidden = false) {
  28. $isHidden = $isHidden ? 'hidden' : '';
  29. $isLabelHidden = $isLabelHidden ? 'label-hidden' : '';
  30. $class = $isHidden . ' ' . $isLabelHidden;
  31. return $this->useTag('beginbox', $title, $class);
  32. }
  33. public function endBox() {
  34. return $this->useTag('endbox');
  35. }
  36. public function icon($name, $options = array()) {
  37. $defaults = array('class' => '');
  38. $options = array_merge($defaults, $options);
  39. $class = '';
  40. foreach ((array)$name as $iconName) {
  41. $class .= ' icon-' . $iconName;
  42. }
  43. $class .= ' ' . $options['class'];
  44. $class = trim($class);
  45. unset($options['class']);
  46. $attributes = '';
  47. foreach ($options as $attr => $value) {
  48. $attributes .= $attr . '="' . $value . '" ';
  49. }
  50. if ($attributes) {
  51. $attributes = ' ' . $attributes;
  52. }
  53. return sprintf($this->_tags['icon'], $class, $attributes);
  54. }
  55. public function status($value, $url = array()) {
  56. $icon = $value == CroogoStatus::PUBLISHED ? 'ok' : 'remove';
  57. $class = $value == CroogoStatus::PUBLISHED ? 'green' : 'red';
  58. if (empty($url)) {
  59. return $this->icon($icon, array('class' => $class));
  60. } else {
  61. return $this->link('', 'javascript:void(0);', array(
  62. 'data-url' => $this->url($url),
  63. 'class' => 'icon-' . $icon . ' ' . $class . ' ajax-toggle',
  64. ));
  65. }
  66. }
  67. /**
  68. * Add possibilities to parent::link() method
  69. *
  70. * ### Options
  71. *
  72. * - `escape` Set to true to enable escaping of title and attributes.
  73. * - `button` 'primary', 'info', 'success', 'warning', 'danger', 'inverse', 'link'. http://twitter.github.com/bootstrap/base-css.html#buttons
  74. * - `icon` 'ok', 'remove' ... http://fortawesome.github.com/Font-Awesome/
  75. *
  76. * @param string $title The content to be wrapped by <a> tags.
  77. * @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
  78. * @param array $options Array of HTML attributes.
  79. * @param string $confirmMessage JavaScript confirmation message.
  80. * @return string An `<a />` element.
  81. */
  82. public function link($title, $url = null, $options = array(), $confirmMessage = false) {
  83. $defaults = array('escape' => false);
  84. $options = is_null($options) ? array() : $options;
  85. $options = array_merge($defaults, $options);
  86. if (!empty($options['button'])) {
  87. $buttons = array('btn');
  88. foreach ((array)$options['button'] as $button) {
  89. if ($button == 'default') {
  90. continue;
  91. }
  92. $buttons[] = 'btn-' . $button;
  93. }
  94. $options['class'] = trim(join(' ', $buttons));
  95. unset($options['button']);
  96. }
  97. if (isset($options['icon'])) {
  98. $iconSize = 'icon-large';
  99. if (isset($options['iconSize']) && $options['iconSize'] === 'small') {
  100. $iconSize = '';
  101. unset($options['iconSize']);
  102. }
  103. if (empty($options['iconInline'])) {
  104. $title = $this->icon($options['icon'], array('class' => $iconSize)) . $title;
  105. } else {
  106. $icon = trim($iconSize . ' icon-' . $options['icon']);
  107. if (isset($options['class'])) {
  108. $options['class'] .= ' ' . $icon;
  109. } else {
  110. $options['class'] = ' ' . $icon;
  111. }
  112. unset($options['iconInline']);
  113. }
  114. unset($options['icon']);
  115. }
  116. if (isset($options['tooltip'])) {
  117. $tooltipOptions = array(
  118. 'rel' => 'tooltip',
  119. 'data-placement' => 'top',
  120. 'data-trigger' => 'hover',
  121. );
  122. if (is_string($options['tooltip'])) {
  123. $tooltipOptions = array_merge(array(
  124. 'data-title' => $options['tooltip'],
  125. ), $tooltipOptions);
  126. $options = array_merge($options, $tooltipOptions);
  127. } else {
  128. $options['tooltip'] = array_merge($tooltipOptions, $options['tooltip']);
  129. $options = array_merge($options, $options['tooltip']);
  130. }
  131. unset($options['tooltip']);
  132. }
  133. return parent::link($title, $url, $options, $confirmMessage);
  134. }
  135. public function addPath($path, $separator) {
  136. $path = explode($separator, $path);
  137. $currentPath = '';
  138. foreach ($path as $p) {
  139. if (!is_null($p)) {
  140. $currentPath .= $p . $separator;
  141. $this->addCrumb($p, $currentPath);
  142. }
  143. }
  144. return $this;
  145. }
  146. public function addCrumb($name, $link = null, $options = null) {
  147. parent::addCrumb($name, $link, $options);
  148. return $this;
  149. }
  150. public function hasCrumbs() {
  151. return !empty($this->_crumbs);
  152. }
  153. }