section.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Base class for sections (sidebar widgets)
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Widget
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
  30. /**
  31. * Base class for sections
  32. *
  33. * These are the widgets that show interesting data about a person
  34. * group, or site.
  35. *
  36. * @category Widget
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. */
  42. abstract class Section extends Widget
  43. {
  44. /**
  45. * Show the form
  46. *
  47. * Uses a recipe to output the form.
  48. *
  49. * @return void
  50. * @see Widget::show()
  51. */
  52. function show()
  53. {
  54. $this->out->elementStart('div',
  55. array('id' => $this->divId(),
  56. 'class' => 'section'));
  57. $this->showTitle();
  58. $have_more = $this->showContent();
  59. if ($have_more) {
  60. $this->showMore();
  61. }
  62. $this->out->elementEnd('div');
  63. }
  64. function showTitle()
  65. {
  66. $link = $this->link();
  67. if (!empty($link)) {
  68. $this->out->elementStart('h2');
  69. $this->out->element('a', array('href' => $link), $this->title());
  70. $this->out->elementEnd('h2');
  71. } else {
  72. $this->out->element('h2', null,
  73. $this->title());
  74. }
  75. }
  76. function showMore()
  77. {
  78. $this->out->elementStart('p');
  79. $this->out->element('a', array('href' => $this->moreUrl(),
  80. 'class' => 'more'),
  81. $this->moreTitle());
  82. $this->out->elementEnd('p');
  83. }
  84. abstract public function divId();
  85. function title()
  86. {
  87. // TRANS: Default title for section/sidebar widget.
  88. return _('Untitled section');
  89. }
  90. function link()
  91. {
  92. return null;
  93. }
  94. function showContent()
  95. {
  96. $this->out->element('p', null,
  97. // TRANS: Default content for section/sidebar widget.
  98. _('(None)'));
  99. return false;
  100. }
  101. function moreUrl()
  102. {
  103. return null;
  104. }
  105. function moreTitle()
  106. {
  107. // TRANS: Default "More..." title for section/sidebar widget.
  108. return _('More...');
  109. }
  110. }