]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Sample/hello.php
Merge branch '0.9.x'
[quix0rs-gnu-social.git] / plugins / Sample / 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($args)
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($args)
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             return _m('Hello');
112         } else {
113             return sprintf(_m('Hello, %s!'), $this->user->nickname);
114         }
115     }
116
117     /**
118      * Show content in the content area
119      *
120      * The default StatusNet page has a lot of decorations: menus,
121      * logos, tabs, all that jazz. This method is used to show
122      * content in the content area of the page; it's the main
123      * thing you want to overload.
124      *
125      * This method also demonstrates use of a plural localized string.
126      *
127      * @return void
128      */
129     function showContent()
130     {
131         if (empty($this->user)) {
132             $this->element('p', array('class' => 'greeting'),
133                            _m('Hello, stranger!'));
134         } else {
135             $this->element('p', array('class' => 'greeting'),
136                            sprintf(_m('Hello, %s'), $this->user->nickname));
137             $this->element('p', array('class' => 'greeting_count'),
138                            sprintf(_m('I have greeted you %d time.',
139                                       'I have greeted you %d times.',
140                                       $this->gc->greeting_count),
141                                    $this->gc->greeting_count));
142         }
143     }
144
145     /**
146      * Return true if read only.
147      *
148      * Some actions only read from the database; others read and write.
149      * The simple database load-balancer built into StatusNet will
150      * direct read-only actions to database mirrors (if they are configured),
151      * and read-write actions to the master database.
152      *
153      * This defaults to false to avoid data integrity issues, but you
154      * should make sure to overload it for performance gains.
155      *
156      * @param array $args other arguments, if RO/RW status depends on them.
157      *
158      * @return boolean is read only action?
159      */
160     function isReadOnly($args)
161     {
162         return false;
163     }
164 }