1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 JFormHelper::loadFieldClass('user');
12
13 14 15 16 17 18 19
20 class FOFFormFieldUser extends JFormFieldUser implements FOFFormField
21 {
22 protected $static;
23
24 protected $repeatable;
25
26
27 public $item;
28
29
30 public $rowid;
31
32 33 34 35 36 37 38 39 40
41 public function __get($name)
42 {
43 switch ($name)
44 {
45 case 'static':
46 if (empty($this->static))
47 {
48 $this->static = $this->getStatic();
49 }
50
51 return $this->static;
52 break;
53
54 case 'repeatable':
55 if (empty($this->repeatable))
56 {
57 $this->repeatable = $this->getRepeatable();
58 }
59
60 return $this->repeatable;
61 break;
62
63 default:
64 return parent::__get($name);
65 }
66 }
67
68 69 70 71 72 73 74 75
76 public function getStatic()
77 {
78
79 $show_username = true;
80 $show_email = false;
81 $show_name = false;
82 $show_id = false;
83 $class = '';
84
85
86 if ($this->element['class'])
87 {
88 $class = ' class="' . (string) $this->element['class'] . '"';
89 }
90
91 if ($this->element['show_username'] == 'false')
92 {
93 $show_username = false;
94 }
95
96 if ($this->element['show_email'] == 'true')
97 {
98 $show_email = true;
99 }
100
101 if ($this->element['show_name'] == 'true')
102 {
103 $show_name = true;
104 }
105
106 if ($this->element['show_id'] == 'true')
107 {
108 $show_id = true;
109 }
110
111
112 $user = JFactory::getUser($this->value);
113
114
115 $html = '<div id="' . $this->id . '" ' . $class . '>';
116
117 if ($show_username)
118 {
119 $html .= '<span class="fof-userfield-username">' . $user->username . '</span>';
120 }
121
122 if ($show_id)
123 {
124 $html .= '<span class="fof-userfield-id">' . $user->id . '</span>';
125 }
126
127 if ($show_name)
128 {
129 $html .= '<span class="fof-userfield-name">' . $user->name . '</span>';
130 }
131
132 if ($show_email)
133 {
134 $html .= '<span class="fof-userfield-email">' . $user->email . '</span>';
135 }
136
137 $html .= '</div>';
138
139 return $html;
140 }
141
142 143 144 145 146 147 148 149
150 public function getRepeatable()
151 {
152
153 $show_username = true;
154 $show_email = true;
155 $show_name = true;
156 $show_id = true;
157 $show_avatar = true;
158 $show_link = false;
159 $link_url = null;
160 $avatar_method = 'gravatar';
161 $avatar_size = 64;
162 $class = '';
163
164
165 $user = JFactory::getUser($this->value);
166
167
168 if ($this->element['class'])
169 {
170 $class = ' class="' . (string) $this->element['class'] . '"';
171 }
172
173 if ($this->element['show_username'] == 'false')
174 {
175 $show_username = false;
176 }
177
178 if ($this->element['show_email'] == 'false')
179 {
180 $show_email = false;
181 }
182
183 if ($this->element['show_name'] == 'false')
184 {
185 $show_name = false;
186 }
187
188 if ($this->element['show_id'] == 'false')
189 {
190 $show_id = false;
191 }
192
193 if ($this->element['show_avatar'] == 'false')
194 {
195 $show_avatar = false;
196 }
197
198 if ($this->element['avatar_method'])
199 {
200 $avatar_method = strtolower($this->element['avatar_method']);
201 }
202
203 if ($this->element['avatar_size'])
204 {
205 $avatar_size = $this->element['avatar_size'];
206 }
207
208 if ($this->element['show_link'] == 'true')
209 {
210 $show_link = true;
211 }
212
213 if ($this->element['link_url'])
214 {
215 $link_url = $this->element['link_url'];
216 }
217 else
218 {
219 if (FOFPlatform::getInstance()->isBackend())
220 {
221
222
223 $link_url = 'index.php?option=com_users&task=user.edit&id=[USER:ID]';
224 }
225 else
226 {
227
228
229 $show_link = false;
230 }
231 }
232
233
234 if ($show_link)
235 {
236 $replacements = array(
237 '[USER:ID]' => $user->id,
238 '[USER:USERNAME]' => $user->username,
239 '[USER:EMAIL]' => $user->email,
240 '[USER:NAME]' => $user->name,
241 );
242
243 foreach ($replacements as $key => $value)
244 {
245 $link_url = str_replace($key, $value, $link_url);
246 }
247 }
248
249
250 if ($show_avatar)
251 {
252 $avatar_url = '';
253
254 if ($avatar_method == 'plugin')
255 {
256
257 FOFPlatform::getInstance()->importPlugin('user');
258 $jResponse = FOFPlatform::getInstance()->runPlugins('onUserAvatar', array($user, $avatar_size));
259
260 if (!empty($jResponse))
261 {
262 foreach ($jResponse as $response)
263 {
264 if ($response)
265 {
266 $avatar_url = $response;
267 }
268 }
269 }
270
271 if (empty($avatar_url))
272 {
273 $show_avatar = false;
274 }
275 }
276 else
277 {
278
279 $md5 = md5($user->email);
280
281 if (FOFPlatform::getInstance()->isCli())
282 {
283 $scheme = 'http';
284 }
285 else
286 {
287 $scheme = JURI::getInstance()->getScheme();
288 }
289
290 if ($scheme == 'http')
291 {
292 $avatar_url = 'http://www.gravatar.com/avatar/' . $md5 . '.jpg?s='
293 . $avatar_size . '&d=mm';
294 }
295 else
296 {
297 $avatar_url = 'https://secure.gravatar.com/avatar/' . $md5 . '.jpg?s='
298 . $avatar_size . '&d=mm';
299 }
300 }
301 }
302
303
304 $html = '<div id="' . $this->id . '" ' . $class . '>';
305
306 if ($show_avatar)
307 {
308 $html .= '<img src="' . $avatar_url . '" align="left" class="fof-usersfield-avatar" />';
309 }
310
311 if ($show_link)
312 {
313 $html .= '<a href="' . $link_url . '">';
314 }
315
316 if ($show_username)
317 {
318 $html .= '<span class="fof-usersfield-username">' . $user->username
319 . '</span>';
320 }
321
322 if ($show_id)
323 {
324 $html .= '<span class="fof-usersfield-id">' . $user->id
325 . '</span>';
326 }
327
328 if ($show_name)
329 {
330 $html .= '<span class="fof-usersfield-name">' . $user->name
331 . '</span>';
332 }
333
334 if ($show_email)
335 {
336 $html .= '<span class="fof-usersfield-email">' . $user->email
337 . '</span>';
338 }
339
340 if ($show_link)
341 {
342 $html .= '</a>';
343 }
344
345 $html .= '</div>';
346
347 return $html;
348 }
349 }
350