PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/widgets/Breadcrumbs.php

https://bitbucket.org/rohitrox/hotc
PHP | 84 lines | 31 code | 11 blank | 42 comment | 6 complexity | 20eccceedacf58ab530c883ca925e359 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. *http://www.yiiframework.com/extension/ac-breadcrumbs-microdata/
  4. */
  5. class Breadcrumbs extends CWidget {
  6. /**
  7. * @var string the tag name for the breadcrumbs container tag. Defaults to 'div'.
  8. */
  9. public $tagName = 'div';
  10. /**
  11. * @var array the HTML attributes for the breadcrumbs container tag.
  12. */
  13. public $htmlOptions = array('class' => 'breadcrumbs');
  14. /**
  15. * @var boolean whether to HTML encode the link labels. Defaults to true.
  16. */
  17. public $encodeLabel = true;
  18. /**
  19. * @var string the first hyperlink in the breadcrumbs (called home link).
  20. * If this property is not set, it defaults to a link pointing to {@link CWebApplication::homeUrl} with label 'Home'.
  21. * If this property is false, the home link will not be rendered.
  22. */
  23. public $homeLink;
  24. /**
  25. * @var array list of hyperlinks to appear in the breadcrumbs. If this property is empty,
  26. * the widget will not render anything. Each key-value pair in the array
  27. * will be used to generate a hyperlink by calling CHtml::link(key, value). For this reason, the key
  28. * refers to the label of the link while the value can be a string or an array (used to
  29. * create a URL). For more details, please refer to {@link CHtml::link}.
  30. * If an element's key is an integer, it means the element will be rendered as a label only (meaning the current page).
  31. *
  32. * The following example will generate breadcrumbs as "Home > Sample post > Edit", where "Home" points to the homepage,
  33. * "Sample post" points to the "index.php?r=post/view&id=12" page, and "Edit" is a label. Note that the "Home" link
  34. * is specified via {@link homeLink} separately.
  35. *
  36. * <pre>
  37. * array(
  38. * 'Sample post'=>array('post/view', 'id'=>12),
  39. * 'Edit',
  40. * )
  41. * </pre>
  42. */
  43. public $links = array();
  44. /**
  45. * @var string the separator between links in the breadcrumbs. Defaults to ' &raquo; '.
  46. */
  47. public $separator = ' &raquo; ';
  48. /**
  49. * Renders the content of the portlet.
  50. */
  51. public function run() {
  52. if (empty($this->links))
  53. return;
  54. $this->htmlOptions['itemprop'] = 'breadcrumb';
  55. $this->htmlOptions['itemscope'] = '';
  56. $this->htmlOptions['itemtype'] = 'http://data-vocabulary.org/Breadcrumb';
  57. $htmlOptionsLinks = array('itemprop' => 'url');
  58. echo CHtml::openTag($this->tagName, $this->htmlOptions) . "\n";
  59. $links = array();
  60. if ($this->homeLink === null)
  61. $links[] = CHtml::link(Yii::t('zii', '<span itemprop="title">Home</span>'), Yii::app()->homeUrl, $htmlOptionsLinks);
  62. else if ($this->homeLink !== false)
  63. $links[] = $this->homeLink;
  64. foreach ($this->links as $label => $url) {
  65. if (is_string($label) || is_array($url))
  66. $links[] = CHtml::link($this->encodeLabel ? '<span itemprop="title">' . CHtml::encode($label) . '</span>' : '<span itemprop="title">' . $label . '</span>', $url, $htmlOptionsLinks);
  67. else
  68. $links[] = '<span itemprop="title">' . ($this->encodeLabel ? CHtml::encode($url) : $url) . '</span>';
  69. }
  70. echo implode($this->separator, $links);
  71. echo CHtml::closeTag($this->tagName);
  72. }
  73. }