3 * Give a warm greeting to our friendly user
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
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.
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.
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/>.
30 if (!defined('STATUSNET')) {
35 * Give a warm greeting to our friendly user
37 * This sample action shows some basic ways of doing output in an action
40 * Action classes have several output methods that they override from
45 * @author Evan Prodromou <evan@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47 * @link http://status.net/
49 class HelloAction extends Action
55 * Take arguments for running
57 * This method is called first, and it lets the action class get
58 * all its arguments and validate them. It's also the time
59 * to fetch any relevant data from the database.
61 * Action classes should run parent::prepare($args) as the first
62 * line of this method to make sure the default argument-processing
65 * @param array $args $_REQUEST args
67 * @return boolean success flag
69 function prepare($args)
71 parent::prepare($args);
73 $this->user = common_current_user();
75 if (!empty($this->user)) {
76 $this->gc = User_greeting_count::inc($this->user->id);
85 * This is the main method for handling a request. Note that
86 * most preparation should be done in the prepare() method;
87 * by the time handle() is called the action should be
88 * more or less ready to go.
90 * @param array $args $_REQUEST args; handled in prepare()
94 function handle($args)
96 parent::handle($args);
104 * Override this method to show a custom title.
106 * @return string Title of the page
110 if (empty($this->user)) {
111 // TRANS: Page title for sample plugin.
114 // TRANS: Page title for sample plugin. %s is a user nickname.
115 return sprintf(_m('Hello, %s!'), $this->user->nickname);
120 * Show content in the content area
122 * The default StatusNet page has a lot of decorations: menus,
123 * logos, tabs, all that jazz. This method is used to show
124 * content in the content area of the page; it's the main
125 * thing you want to overload.
127 * This method also demonstrates use of a plural localized string.
131 function showContent()
133 if (empty($this->user)) {
134 $this->element('p', array('class' => 'greeting'),
135 // TRANS: Message in sample plugin.
136 _m('Hello, stranger!'));
138 $this->element('p', array('class' => 'greeting'),
139 // TRANS: Message in sample plugin. %s is a user nickname.
140 sprintf(_m('Hello, %s'), $this->user->nickname));
141 $this->element('p', array('class' => 'greeting_count'),
142 // TRANS: Message in sample plugin.
143 // TRANS: %d is the number of times a user is greeted.
144 sprintf(_m('I have greeted you %d time.',
145 'I have greeted you %d times.',
146 $this->gc->greeting_count),
147 $this->gc->greeting_count));
152 * Return true if read only.
154 * Some actions only read from the database; others read and write.
155 * The simple database load-balancer built into StatusNet will
156 * direct read-only actions to database mirrors (if they are configured),
157 * and read-write actions to the master database.
159 * This defaults to false to avoid data integrity issues, but you
160 * should make sure to overload it for performance gains.
162 * @param array $args other arguments, if RO/RW status depends on them.
164 * @return boolean is read only action?
166 function isReadOnly($args)