]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Sample/hello.php
Add doc comments on saveHTMLFile; drop the extra <div> wrapping the contents to make...
[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
50 class HelloAction extends Action
51 {
52     var $user = null;
53     var $gc   = null;
54
55     /**
56      * Take arguments for running
57      *
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.
61      *
62      * Action classes should run parent::prepare($args) as the first
63      * line of this method to make sure the default argument-processing
64      * happens.
65      *
66      * @param array $args $_REQUEST args
67      *
68      * @return boolean success flag
69      */
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74
75         $this->user = common_current_user();
76
77         if (!empty($this->user)) {
78             $this->gc = User_greeting_count::inc($this->user->id);
79         }
80
81         return true;
82     }
83
84     /**
85      * Handle request
86      *
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.
91      *
92      * @param array $args $_REQUEST args; handled in prepare()
93      *
94      * @return void
95      */
96
97     function handle($args)
98     {
99         parent::handle($args);
100
101         $this->showPage();
102     }
103
104     /**
105      * Title of this page
106      *
107      * Override this method to show a custom title.
108      *
109      * @return string Title of the page
110      */
111
112     function title()
113     {
114         if (empty($this->user)) {
115             return _m('Hello');
116         } else {
117             return sprintf(_m('Hello, %s'), $this->user->nickname);
118         }
119     }
120
121     /**
122      * Show content in the content area
123      *
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.
128      *
129      * This method also demonstrates use of a plural localized string.
130      *
131      * @return void
132      */
133
134     function showContent()
135     {
136         if (empty($this->user)) {
137             $this->element('p', array('class' => 'greeting'),
138                            _m('Hello, stranger!'));
139         } else {
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));
147         }
148     }
149
150     /**
151      * Return true if read only.
152      *
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.
157      *
158      * This defaults to false to avoid data integrity issues, but you
159      * should make sure to overload it for performance gains.
160      *
161      * @param array $args other arguments, if RO/RW status depends on them.
162      *
163      * @return boolean is read only action?
164      */
165
166     function isReadOnly($args)
167     {
168         return false;
169     }
170 }