]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/widget.php
*** Privacy Leak fixed: ***
[quix0rs-gnu-social.git] / lib / widget.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Base class for UI widgets
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Widget
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Base class for UI widgets
35  *
36  * A widget is a cluster of HTML elements that provide some functionality
37  * that's used on different parts of the site. Examples would be profile
38  * lists, notice lists, navigation menus (tabsets) and common forms.
39  *
40  * @category Widget
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Sarven Capadisli <csarven@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  *
47  * @see      HTMLOutputter
48  */
49
50 class Widget
51 {
52     protected $avatarSize = AVATAR_STREAM_SIZE;
53
54     /**
55      * Action (HTMLOutputter) to use for output
56      */
57
58     var $out = null;
59
60     /**
61      * Prepare the widget for use
62      *
63      * @param Action $out output helper, defaults to null
64      */
65
66     function __construct(Action $out = null, array $widgetOpts = [])
67     {
68         $this->out = $out;
69         if (!array_key_exists('scoped', $widgetOpts)) {
70             $this->widgetOpts['scoped'] = Profile::current();
71         }
72         $this->scoped = $this->widgetOpts['scoped'];
73     }
74
75     /**
76      * Show the widget
77      *
78      * Emit the HTML for the widget, using the configured outputter.
79      *
80      * @return void
81      */
82
83     function show()
84     {
85     }
86
87     /**
88      * Get HTMLOutputter
89      *
90      * Return the HTMLOutputter for the widget.
91      *
92      * @return HTMLOutputter the output helper
93      */
94
95     function getOut()
96     {
97         return $this->out;
98     }
99
100     /**
101      * Delegate output methods to the outputter attribute.
102      *
103      * @param string $name      Name of the method
104      * @param array  $arguments Arguments called
105      *
106      * @return mixed Return value of the method.
107      */
108     function __call($name, $arguments)
109     {
110         return call_user_func_array(array($this->out, $name), $arguments);
111     }
112
113     /**
114      * Default avatar size for this widget.
115      */
116     public function avatarSize()
117     {
118         return $this->avatarSize;
119     }
120
121     protected function showAvatar(Profile $profile, $size=null)
122     {
123         $avatar_url = $profile->avatarUrl($size ?: $this->avatarSize());
124         $this->out->element('img', array('src' => $avatar_url,
125                                          'class' => 'avatar u-photo',
126                                          'width' => $this->avatarSize(),
127                                          'height' => $this->avatarSize(),
128                                          'alt' => $profile->getBestName()));
129     }
130 }