]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Sample/actions/hello.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Sample / actions / hello.php
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
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Give a warm greeting to our friendly user
36  *
37  * This sample action shows some basic ways of doing output in an action
38  * class.
39  *
40  * Action classes have several output methods that they override from
41  * the parent class.
42  *
43  * @category Sample
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47  * @link     http://status.net/
48  */
49 class HelloAction extends Action
50 {
51     var $user = null;
52     var $gc   = null;
53
54     /**
55      * Take arguments for running
56      *
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.
60      *
61      * Action classes should run parent::prepare($args) as the first
62      * line of this method to make sure the default argument-processing
63      * happens.
64      *
65      * @param array $args $_REQUEST args
66      *
67      * @return boolean success flag
68      */
69     function prepare(array $args=array())
70     {
71         parent::prepare($args);
72
73         $this->user = common_current_user();
74
75         if (!empty($this->user)) {
76             $this->gc = User_greeting_count::inc($this->user->id);
77         }
78
79         return true;
80     }
81
82     /**
83      * Handle request
84      *
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.
89      *
90      * @param array $args $_REQUEST args; handled in prepare()
91      *
92      * @return void
93      */
94     function handle(array $args=array())
95     {
96         parent::handle($args);
97
98         $this->showPage();
99     }
100
101     /**
102      * Title of this page
103      *
104      * Override this method to show a custom title.
105      *
106      * @return string Title of the page
107      */
108     function title()
109     {
110         if (empty($this->user)) {
111             // TRANS: Page title for sample plugin.
112             return _m('Hello');
113         } else {
114             // TRANS: Page title for sample plugin. %s is a user nickname.
115             return sprintf(_m('Hello, %s!'), $this->user->nickname);
116         }
117     }
118
119     /**
120      * Show content in the content area
121      *
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.
126      *
127      * This method also demonstrates use of a plural localized string.
128      *
129      * @return void
130      */
131     function showContent()
132     {
133         if (empty($this->user)) {
134             $this->element('p', array('class' => 'greeting'),
135                            // TRANS: Message in sample plugin.
136                            _m('Hello, stranger!'));
137         } else {
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));
148         }
149     }
150
151     /**
152      * Return true if read only.
153      *
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.
158      *
159      * This defaults to false to avoid data integrity issues, but you
160      * should make sure to overload it for performance gains.
161      *
162      * @param array $args other arguments, if RO/RW status depends on them.
163      *
164      * @return boolean is read only action?
165      */
166     function isReadOnly(array $args=array())
167     {
168         return false;
169     }
170 }