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/
50 class HelloAction extends Action
56 * Take arguments for running
58 * This method is called first, and it lets the action class get
59 * all its arguments and validate them. It's also the time
60 * to fetch any relevant data from the database.
62 * Action classes should run parent::prepare($args) as the first
63 * line of this method to make sure the default argument-processing
66 * @param array $args $_REQUEST args
68 * @return boolean success flag
71 function prepare($args)
73 parent::prepare($args);
75 $this->user = common_current_user();
77 if (!empty($this->user)) {
78 $this->gc = User_greeting_count::inc($this->user->id);
87 * This is the main method for handling a request. Note that
88 * most preparation should be done in the prepare() method;
89 * by the time handle() is called the action should be
90 * more or less ready to go.
92 * @param array $args $_REQUEST args; handled in prepare()
97 function handle($args)
99 parent::handle($args);
107 * Override this method to show a custom title.
109 * @return string Title of the page
114 if (empty($this->user)) {
117 return sprintf(_m('Hello, %s'), $this->user->nickname);
122 * Show content in the content area
124 * The default StatusNet page has a lot of decorations: menus,
125 * logos, tabs, all that jazz. This method is used to show
126 * content in the content area of the page; it's the main
127 * thing you want to overload.
129 * This method also demonstrates use of a plural localized string.
134 function showContent()
136 if (empty($this->user)) {
137 $this->element('p', array('class' => 'greeting'),
138 _m('Hello, stranger!'));
140 $this->element('p', array('class' => 'greeting'),
141 sprintf(_m('Hello, %s'), $this->user->nickname));
142 $this->element('p', array('class' => 'greeting_count'),
143 sprintf(_m('I have greeted you %d time.',
144 'I have greeted you %d times.',
145 $this->gc->greeting_count),
146 $this->gc->greeting_count));
151 * Return true if read only.
153 * Some actions only read from the database; others read and write.
154 * The simple database load-balancer built into StatusNet will
155 * direct read-only actions to database mirrors (if they are configured),
156 * and read-write actions to the master database.
158 * This defaults to false to avoid data integrity issues, but you
159 * should make sure to overload it for performance gains.
161 * @param array $args other arguments, if RO/RW status depends on them.
163 * @return boolean is read only action?
166 function isReadOnly($args)