hello.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Give a warm greeting to our friendly user
  4. *
  5. * PHP version 5
  6. *
  7. * @category Sample
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2009, StatusNet, Inc.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Give a warm greeting to our friendly user
  34. *
  35. * This sample action shows some basic ways of doing output in an action
  36. * class.
  37. *
  38. * Action classes have several output methods that they override from
  39. * the parent class.
  40. *
  41. * @category Sample
  42. * @package StatusNet
  43. * @author Evan Prodromou <evan@status.net>
  44. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  45. * @link http://status.net/
  46. */
  47. class HelloAction extends Action
  48. {
  49. var $user = null;
  50. var $gc = null;
  51. /**
  52. * Take arguments for running
  53. *
  54. * This method is called first, and it lets the action class get
  55. * all its arguments and validate them. It's also the time
  56. * to fetch any relevant data from the database.
  57. *
  58. * Action classes should run parent::prepare($args) as the first
  59. * line of this method to make sure the default argument-processing
  60. * happens.
  61. *
  62. * @param array $args $_REQUEST args
  63. *
  64. * @return boolean success flag
  65. */
  66. function prepare($args)
  67. {
  68. parent::prepare($args);
  69. $this->user = common_current_user();
  70. if (!empty($this->user)) {
  71. $this->gc = User_greeting_count::inc($this->user->id);
  72. }
  73. return true;
  74. }
  75. /**
  76. * Handle request
  77. *
  78. * This is the main method for handling a request. Note that
  79. * most preparation should be done in the prepare() method;
  80. * by the time handle() is called the action should be
  81. * more or less ready to go.
  82. *
  83. * @param array $args $_REQUEST args; handled in prepare()
  84. *
  85. * @return void
  86. */
  87. function handle($args)
  88. {
  89. parent::handle($args);
  90. $this->showPage();
  91. }
  92. /**
  93. * Title of this page
  94. *
  95. * Override this method to show a custom title.
  96. *
  97. * @return string Title of the page
  98. */
  99. function title()
  100. {
  101. if (empty($this->user)) {
  102. // TRANS: Page title for sample plugin.
  103. return _m('Hello');
  104. } else {
  105. // TRANS: Page title for sample plugin. %s is a user nickname.
  106. return sprintf(_m('Hello, %s!'), $this->user->nickname);
  107. }
  108. }
  109. /**
  110. * Show content in the content area
  111. *
  112. * The default StatusNet page has a lot of decorations: menus,
  113. * logos, tabs, all that jazz. This method is used to show
  114. * content in the content area of the page; it's the main
  115. * thing you want to overload.
  116. *
  117. * This method also demonstrates use of a plural localized string.
  118. *
  119. * @return void
  120. */
  121. function showContent()
  122. {
  123. if (empty($this->user)) {
  124. $this->element('p', array('class' => 'greeting'),
  125. // TRANS: Message in sample plugin.
  126. _m('Hello, stranger!'));
  127. } else {
  128. $this->element('p', array('class' => 'greeting'),
  129. // TRANS: Message in sample plugin. %s is a user nickname.
  130. sprintf(_m('Hello, %s'), $this->user->nickname));
  131. $this->element('p', array('class' => 'greeting_count'),
  132. // TRANS: Message in sample plugin.
  133. // TRANS: %d is the number of times a user is greeted.
  134. sprintf(_m('I have greeted you %d time.',
  135. 'I have greeted you %d times.',
  136. $this->gc->greeting_count),
  137. $this->gc->greeting_count));
  138. }
  139. }
  140. /**
  141. * Return true if read only.
  142. *
  143. * Some actions only read from the database; others read and write.
  144. * The simple database load-balancer built into StatusNet will
  145. * direct read-only actions to database mirrors (if they are configured),
  146. * and read-write actions to the master database.
  147. *
  148. * This defaults to false to avoid data integrity issues, but you
  149. * should make sure to overload it for performance gains.
  150. *
  151. * @param array $args other arguments, if RO/RW status depends on them.
  152. *
  153. * @return boolean is read only action?
  154. */
  155. function isReadOnly($args)
  156. {
  157. return false;
  158. }
  159. }