widget.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Base class for UI 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. * @author Sarven Capadisli <csarven@status.net>
  26. * @copyright 2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. /**
  34. * Base class for UI widgets
  35. *
  36. * A widget is a cluster of HTML elements that provide some functionality
  37. * that's used on different parts of the site. Examples would be profile
  38. * lists, notice lists, navigation menus (tabsets) and common forms.
  39. *
  40. * @category Widget
  41. * @package StatusNet
  42. * @author Evan Prodromou <evan@status.net>
  43. * @author Sarven Capadisli <csarven@status.net>
  44. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  45. * @link http://status.net/
  46. *
  47. * @see HTMLOutputter
  48. */
  49. class Widget
  50. {
  51. protected $avatarSize = AVATAR_STREAM_SIZE;
  52. /**
  53. * Action (HTMLOutputter) to use for output
  54. */
  55. var $out = null;
  56. /**
  57. * Prepare the widget for use
  58. *
  59. * @param Action $out output helper, defaults to null
  60. */
  61. function __construct(Action $out=null)
  62. {
  63. $this->out = $out;
  64. }
  65. /**
  66. * Show the widget
  67. *
  68. * Emit the HTML for the widget, using the configured outputter.
  69. *
  70. * @return void
  71. */
  72. function show()
  73. {
  74. }
  75. /**
  76. * Get HTMLOutputter
  77. *
  78. * Return the HTMLOutputter for the widget.
  79. *
  80. * @return HTMLOutputter the output helper
  81. */
  82. function getOut()
  83. {
  84. return $this->out;
  85. }
  86. /**
  87. * Delegate output methods to the outputter attribute.
  88. *
  89. * @param string $name Name of the method
  90. * @param array $arguments Arguments called
  91. *
  92. * @return mixed Return value of the method.
  93. */
  94. function __call($name, $arguments)
  95. {
  96. return call_user_func_array(array($this->out, $name), $arguments);
  97. }
  98. /**
  99. * Default avatar size for this widget.
  100. */
  101. public function avatarSize()
  102. {
  103. return $this->avatarSize;
  104. }
  105. protected function showAvatar(Profile $profile, $size=null)
  106. {
  107. $avatar_url = $profile->avatarUrl($size ?: $this->avatarSize());
  108. $this->out->element('img', array('src' => $avatar_url,
  109. 'class' => 'avatar u-photo',
  110. 'width' => $this->avatarSize(),
  111. 'height' => $this->avatarSize(),
  112. 'alt' => $profile->getBestName()));
  113. }
  114. }