section.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. public $widgetOpts;
  45. public $scoped;
  46. /**
  47. * Show the form
  48. *
  49. * Uses a recipe to output the form.
  50. *
  51. * @return void
  52. * @see Widget::show()
  53. */
  54. function show()
  55. {
  56. $this->out->elementStart('div',
  57. array('id' => $this->divId(),
  58. 'class' => 'section'));
  59. $this->showTitle();
  60. $have_more = $this->showContent();
  61. if ($have_more) {
  62. $this->showMore();
  63. }
  64. $this->out->elementEnd('div');
  65. }
  66. function showTitle()
  67. {
  68. $link = $this->link();
  69. if (!empty($link)) {
  70. $this->out->elementStart('h2');
  71. $this->out->element('a', array('href' => $link), $this->title());
  72. $this->out->elementEnd('h2');
  73. } else {
  74. $this->out->element('h2', null,
  75. $this->title());
  76. }
  77. }
  78. function showMore()
  79. {
  80. $this->out->elementStart('p');
  81. $this->out->element('a', array('href' => $this->moreUrl(),
  82. 'class' => 'more'),
  83. $this->moreTitle());
  84. $this->out->elementEnd('p');
  85. }
  86. abstract public function divId();
  87. function title()
  88. {
  89. // TRANS: Default title for section/sidebar widget.
  90. return _('Untitled section');
  91. }
  92. function link()
  93. {
  94. return null;
  95. }
  96. function showContent()
  97. {
  98. $this->out->element('p', null,
  99. // TRANS: Default content for section/sidebar widget.
  100. _('(None)'));
  101. return false;
  102. }
  103. function moreUrl()
  104. {
  105. return null;
  106. }
  107. function moreTitle()
  108. {
  109. // TRANS: Default "More..." title for section/sidebar widget.
  110. return _('More...');
  111. }
  112. }