root/releases/0.9/lib/displaylib.php

Revision 1319, 20.0 kB (checked in by rho, 1 year ago)

Tweaked web field display to support multiple url's

Signed-off: Rolando Espinoza La Fuente <rho@prosoftpeople.com>

  • Property svn:eol-style set to native
Line 
1 <?php
2
3
4 /** Set the display object method for a given module.
5  * @param $module A string containing the module name - eg "file"
6  * @param $function The name of your function matching the prototype $name($object_id, $object_type, $view) where $object_type is the description of the object eg "file::file".
7  */
8 function display_set_display_function($module, $function)
9 {
10     global $CFG;
11
12     if (!isset($CFG->displayobjectfunctions))
13         $CFG->displayobjectfunctions = array();
14
15     $CFG->displayobjectfunctions[$module] = $function;
16 }
17
18 /** Call a function's display object code and returns its html
19  * @param $module The module name eg 'file'
20  * @param $object_id The id of the object
21  * @param $object_type The type of the object - eg 'file::file' - largely ignored.
22  * @param $view Do we want to display a full view or a limited view - 'full' or 'summary'?
23  */
24 function display_run_displayobject($module, $object_id, $object_type, $view = 'full')
25 {
26     global $CFG;
27
28     $result = "";
29     if (isset($CFG->displayobjectfunctions[$module]))
30     {
31         $function = $CFG->displayobjectfunctions[$module];
32         if (is_callable($function))
33         {
34             $result = $function($object_id, $object_type, $view);
35         }
36     }
37
38     return $result;
39 }
40
41 /** Add a hook for displaying annotations for an object.
42  * @param $object_type The type of object you're registering the hook for
43  * @param $function The function to register it to
44  */
45 function display_set_display_annotation_function($object_type, $function)
46 {
47     global $CFG;
48
49     if (!isset($CFG->displayobjectannotationfunctions))
50         $CFG->displayobjectannotationfunctions = array();
51
52     $CFG->displayobjectannotationfunctions[$object_type][] = $function;
53 }
54
55 /** Display the annotations for a specific object type.
56  * @param $object The id of the object
57  * @param $object_type The type of the object - eg 'file::file' - largely ignored.
58  * @param $view Do we want to display a full view or a limited view - 'full' or 'summary'?
59  */
60 function display_run_displayobjectannotations($object, $object_type, $view = 'full')
61 {
62     global $CFG;
63
64     $result = "";
65     if (isset($CFG->displayobjectannotationfunctions[$object_type]))
66     {
67         foreach ($CFG->displayobjectannotationfunctions[$object_type] as $function)
68         {
69             if (is_callable($function))
70             {
71                 $result .= $function($object, $object_type, $view);
72             }
73         }
74     }
75
76     return $result;
77 }
78
79 // Function to sanitise RTF edit text
80 /* function RTESafe($strText) {
81     //returns safe code for preloading in the RTE
82     $tmpString = trim($strText);
83     
84     //convert all types of single quotes
85     $tmpString = str_replace(chr(145), chr(39), $tmpString);
86     $tmpString = str_replace(chr(146), chr(39), $tmpString);
87     $tmpString = str_replace("'", "&#39;", $tmpString);
88     
89     //convert all types of double quotes
90     $tmpString = str_replace(chr(147), chr(34), $tmpString);
91     $tmpString = str_replace(chr(148), chr(34), $tmpString);
92     
93     //replace carriage returns & line feeds
94     $tmpString = str_replace(chr(10), " ", $tmpString);
95     $tmpString = str_replace(chr(13), " ", $tmpString);
96     
97     return $tmpString;
98 } */
99
100 function display_input_field ($parameter) {
101     // Displays different HTML depending on input field type
102
103     /*
104     
105     $parameter(
106         
107                         0 => input name to display (for forms etc)
108                         1 => data
109                         2 => type of input field
110                         3 => reference name (for tag fields and so on)
111                         4 => ID number (if any)
112                         5 => Owner
113         
114                     )
115     
116     */
117
118     global $CFG;
119     $run_result = '';
120
121     if (isset($parameter) && sizeof($parameter) > 2) {
122             
123         if (!isset($parameter[4])) {
124             $parameter[4] = -1;
125         }
126             
127         if (!isset($parameter[5])) {
128             $parameter[5] = $_SESSION['userid'];
129         }
130             
131         $cleanid = $parameter[0];
132         if (!ereg("^[A-Za-z][A-Za-z0-9_:\\.-]*$", $cleanid)) {
133             if (!ereg("^[A-Za-z]", $cleanid)) {
134                 $cleanid = "id_" . $cleanid;
135             }
136             $cleanid = ereg_replace("[^A-Za-z0-9_:\\.-]", "__", $cleanid);
137         }
138         
139         switch($parameter[2]) {
140                 
141         case "text":
142             $run_result .= "<input type=\"text\" name=\"".$parameter[0]."\" value=\"".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."\" style=\"width: 95%\" id=\"".$cleanid."\" />";
143             break;
144         case "password":
145             $run_result .= "<input type=\"password\" name=\"".$parameter[0]."\" value=\"".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."\" style=\"width: 95%\" id=\"".$cleanid."\" />";
146             break;
147         case "mediumtext":
148             $run_result .= "<textarea name=\"".$parameter[0]."\" id=\"".$cleanid."\" style=\"width: 95%; height: 100px\">".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."</textarea>";
149             break;
150         case "keywords":
151             /*
152                         $keywords = stripslashes($parameter[1]);
153                         preg_match_all("/\[\[([A-Za-z0-9 ]+)\]\]/i",$keywords,$keyword_list);
154                         $keyword_list = $keyword_list[1];
155                         $keywords = "";
156                         if (is_array($keyword_list) && sizeof($keyword_list) > 0) {
157                             sort($keyword_list);
158                             foreach($keyword_list as $key => $list_item) {
159                                 $keywords .= $list_item;
160                                 if ($key < sizeof($keyword_list) - 1) {
161                                     $keywords .= ", ";
162                                 }
163                             }
164                         }
165                         $parameter[1] = $keywords;
166             */
167             if (!isset($data['profile:preload'][$parameter[3]])) {
168                 $keywords = "";
169                 if ($tags = get_records_select('tags',"tagtype = ? and ref = ? and owner = ?",array($parameter[3],$parameter[4],$parameter[5]),'tag ASC')) {
170                     $first = true;
171                     foreach($tags as $key => $tag) {
172                         if (empty($first)) {
173                             $keywords .= ", ";
174                         }
175                         $keywords .= stripslashes($tag->tag);
176                         $first = false;
177                     }
178                 }
179                 $parameter[1] = $keywords;
180             } else {
181                 // $parameter[1] = $data['profile:preload'][$parameter[3]];
182             }
183             // $parameter[1] = var_export($parameter,true);
184             $run_result .= "<textarea name=\"".$parameter[0]."\" id=\"".$cleanid."\" style=\"width: 95%; height: 100px\">".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."</textarea>";
185             break;
186         case "longtext":
187             $run_result .= "<textarea name=\"".$parameter[0]."\" id=\"".$cleanid."\" style=\"width: 95%; height: 200px\">".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."</textarea>";
188             break;
189         case "richtext":
190             // Rich text editor:
191             $run_result .= <<< END
192                 <script language="JavaScript" type="text/javascript">
193                 <!--
194                 function submitForm() {
195                     //make sure hidden and iframe values are in sync before submitting form
196                     //to sync only 1 rte, use updateRTE(rte)
197                     //to sync all rtes, use updateRTEs
198                     updateRTE('<?php echo $parameter[0]; ?>');
199                     //updateRTEs();
200                     //alert("rte1 = " + document.elggform.<?php echo $parameter[0]; ?>.value);
201                                 
202                     //change the following line to true to submit form
203                     return true;
204                 }
205 END;
206             $content = RTESafe(stripslashes($parameter[1]));
207             $run_result .= <<< END
208                 //Usage: initRTE(imagesPath, includesPath, cssFile)
209                 initRTE("/units/display/rtfedit/images/", "/units/display/rtfedit/", "/units/display/rtfedit/rte.css");
210             </script>
211                   <noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript>
212                   <script language="JavaScript" type="text/javascript">
213                   <!--
214                   writeRichText('<?php echo $parameter[0];?>', '<?php echo $content; ?>', 220, 200, true, false);
215             // -->
216             </script>
217 END;
218             break;
219         case "blank":
220             $run_result .= "<input type=\"hidden\" name=\"".$parameter[0]."\" value=\"blank\" id=\"".$cleanid."\" />";
221             break;
222         case "web":
223         case "email":
224         case "aim":
225         case "msn":
226         case "skype":
227         case "icq":
228             $run_result .= "<input type=\"text\" name=\"".$parameter[0]."\" value=\"".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."\" style=\"width: 95%\" id=\"".$cleanid."\" />";
229             break;
230         case "weblogtext":
231             $run_result .= "<textarea name=\"".$parameter[0]."\" id=\"".$parameter[0]."\" style=\"width: 95%; height: 200px\">".htmlspecialchars(stripslashes($parameter[1]), ENT_COMPAT, 'utf-8')."</textarea>";
232             break;
233         default:
234             if (isset($CFG->display_field_module[$parameter[2]])) {
235                 $callback = $CFG->display_field_module[$parameter[2]] . "_display_input_field";
236                 if (is_callable($callback)) {
237                     $run_result .= $callback($parameter);
238                 }
239             }
240             break;
241         }
242             
243     }
244     
245     return $run_result;
246 }
247
248 function log_on_pane () {
249
250
251     // Elgg default globals
252     global $function;
253     global $log;
254     global $actionlog;
255     global $errorlog;
256     global $messages;
257     global $data;
258
259     global $page_owner;
260     
261     global $CFG;
262         
263     // If this is someone else's portfolio, display the user's icon
264     if ($page_owner != -1) {
265         $run_result .= run("profile:user:info");
266     }
267
268     if ((!defined("logged_on") || logged_on == 0) && $page_owner == -1) {
269
270         $body = '<form action="'.url.'login/index.php" method="post">';
271
272         if ($CFG->publicreg == true && ($CFG->maxusers == 0 || (count_users('person') < $CFG->maxusers))) {
273             $reg_link = '<a href="' . url . 'mod/invite/register.php">'. __gettext("Register") .'</a> |';
274         } else {
275             $reg_link = "";
276         }
277
278         $body .= templates_draw(array(
279                                       'template' => -1,
280                                       'context' => 'contentholder',
281                                       'title' => __gettext("Log On"),
282                                       'submenu' => '',
283                                       'body' => '
284             <table>
285                 <tr>
286                     <td align="right"><p>
287                         <label>' . __gettext("Username") . '&nbsp;<input type="text" name="username" id="username" style="size: 200px" /></label><br />
288                         <label>' . __gettext("Password") . '&nbsp;<input type="password" name="password" id="password" style="size: 200px" />
289                         </label></p>
290                     </td>
291                 </tr>
292                 <tr>
293                     <td align="right"><p>
294                         <input type="hidden" name="action" value="log_on" />
295                         <label>' . __gettext("Log on") . ':<input type="submit" name="submit" value="'.__gettext("Go").'" /></label><br /><br />
296                         <label><input type="checkbox" name="remember" checked="checked" />
297                                 ' . __gettext("Remember Login") . '</label><br />
298                         <small>
299                             ' . $reg_link . '
300                             <a href="' . url . 'mod/invite/forgotten_password.php">'. __gettext("Forgotten password") .'</a>
301                         </small></p>
302                     </td>
303                 </tr>
304             
305             </table>
306
307 '
308                                       )
309                                 );
310         $body .= "</form>";
311
312         $run_result .= $body;
313             
314     }
315
316     return $run_result;
317 }
318
319 function display_output_field ($parameter) {
320     // Displays different HTML depending on input field type
321
322     /*
323     
324     $parameter(
325         
326                         0 => input name to display (for forms etc)
327                         1 => data
328                         2 => type of input field
329                         3 => reference name (for tag fields and so on)
330                         4 => ID number (if any)
331                         5 => Owner (if not specified, current $page_owner is assumed)
332         
333                     )
334     
335     */
336     
337     global $db;
338     global $page_owner;
339     global $CFG;
340
341     $run_result = '';
342     
343     if (isset($parameter) && sizeof($parameter) > 1) {
344         
345         if (!isset($parameter[4])) {
346             $parameter[4] = -1;
347         }
348         if (!isset($parameter[5])) {
349             if (isset($page_owner)) {
350                 $parameter[5] = $page_owner;
351             } else {
352                 $parameter[5] = -1;
353             }
354         }
355         
356         switch($parameter[1]) {
357                 
358         case "icq":
359             $run_result = "<img src=\"http://web.icq.com/whitepages/online?icq=".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."&amp;img=5\" height=\"18\" width=\"18\" />  <b>".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."</b> (<a href=\"http://wwp.icq.com/scripts/search.dll?to=".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."\">" . __gettext("Add User") . "</a>, <a href=\"http://wwp.icq.com/scripts/contact.dll?msgto=".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."\">". __gettext("Send Message") ."</a>)";
360             break;
361         case "skype":
362             $run_result = "<a href=\"callto://".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."\">".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."</a> <img src=\"http://goodies.skype.com/graphics/skypeme_btn_small_white.gif\" alt=\"Skype Me!\" border=\"0\" />";
363             break;
364         case "msn":
365             $run_result = "MSN <b>".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."</b>";
366             break;
367         case "aim":
368             $run_result = "<img src=\"http://big.oscar.aol.com/".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."?on_url=http://www.aol.com/aim/gr/online.gif&amp;off_url=http://www.aol.com/aim/gr/offline.gif\" width=\"14\" height=\"17\" /> <b>".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."</b> (<a href=\"aim:addbuddy?screenname=".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."\">". __gettext("Add Buddy") ."</a>, <a href=\"aim:goim?screenname=".htmlspecialchars(stripslashes($parameter[0]), ENT_COMPAT, 'utf-8')."&amp;message=Hello\">". __gettext("Send Message") ."</a>)";
369             break;
370         case "text":
371         case "mediumtext":
372         case "longtext":
373             $run_result = nl2br(stripslashes($parameter[0]));
374             break;
375         case "keywords":
376             /*
377             $keywords = stripslashes($parameter[0]);
378             preg_match_all("/\[\[([A-Za-z0-9 ]+)\]\]/i",$keywords,$keyword_list);
379             $keyword_list = $keyword_list[1];
380             $keywords = "";
381             if (is_array($keyword_list) && sizeof($keyword_list) > 0) {
382                 sort($keyword_list);
383                 $where = run("users:access_level_sql_where",$_SESSION['userid']);
384                 foreach($keyword_list as $key => $list_item) {
385                     $number = count_records_select('profile_data',"($where) and name = '".$parameter[2]."' and value like \"%[[".$list_item."]]%\"");
386                     if ($number > 1) {
387                         $keywords .= "<a href=\"/profile/search.php?".$parameter[2]."=".$list_item."\" title=\"$number users\">";
388                     }
389                     $keywords .= $list_item;
390                     if ($number > 1) {
391                         $keywords .= "</a>";
392                     }
393                     if ($key < sizeof($keyword_list) - 1) {
394                         $keywords .= ", ";
395                     }
396                 }
397             }
398             $run_result = $keywords;
399             */
400             $where = run("users:access_level_sql_where",$_SESSION['userid']);
401             $keywords = "";
402             if ($tags = get_records_select('tags',"($where) AND tagtype = " . $db->qstr($parameter[2]) . " AND ref = ".$parameter[4],null,'tag ASC')) {
403                 $first = true;
404                 foreach($tags as $tag) {
405                     if (empty($first)) {
406                         $keywords .= ", ";
407                     }
408                     $numberoftags = count_records('tags','tag',$tag->tag);
409                     if ($numberoftags > 1) {
410                         $keywords .= "<a href=\"".url."search/index.php?".$parameter[2]."=".urlencode(stripslashes($tag->tag))."&amp;ref=".$parameter[4]."&amp;owner=".$parameter[5]."\" >";
411                     }
412                     $keywords .= htmlspecialchars(stripslashes($tag->tag), ENT_COMPAT, 'utf-8');
413                     if ($numberoftags > 1) {
414                         $keywords .= "</a>";
415                     }
416                     $first = false;
417                 }
418             }
419             $run_result = $keywords;
420             break;
421         case "email":
422             $run_result = preg_replace("/[\\d\\w\\.\\-_]+@([\\d\\w\\-_\\.]+\\.)+([\\w]{2,6})/i","<a href=\"mailto:$0\">$0</a>",$parameter[0]);
423             break;
424         case "web":
425             $run_result = $parameter[0];
426             if (!preg_match('#^\w+://.*$#', $run_result)) { // seems protocol? if not assume http
427                 $run_result = "http://" . $run_result;
428             }
429             $run_result = "<a href=\"" . $run_result . "\" target=\"_blank\">" . $run_result . "</a>";
430             break;
431         default:
432             if (isset($CFG->display_field_module[$parameter[1]])) {
433                 $callback = $CFG->display_field_module[$parameter[1]] . "_display_output_field";
434                 if (is_callable($callback)) {
435                     $run_result = $callback($parameter);
436                 }
437             }
438             break;
439         }
440     }
441     return $run_result;
442 }
443
444 function displaymenu_top () {
445
446     global $PAGE;
447
448     if (logged_on == 1) {
449         
450         return templates_draw(array(
451                                     'context' => 'topmenu',
452                                     'menuitems' => menu_join('', $PAGE->menu_top)
453                                     )
454                               );
455         
456     }
457
458     return '';
459 }
460
461
462 function displaymenu () {
463
464     global $PAGE;
465
466     return templates_draw(array(
467                                 'context' => 'menu',
468                                 'menuitems' => menu_join('', $PAGE->menu)
469                                 )
470                           );
471
472 }
473
474
475 function displaymenu_sub () {
476
477     global $PAGE;
478
479     if (logged_on == 1) {
480         
481         return templates_draw(array(
482                                     'context' => 'submenu',
483                                     'menuitems' => menu_join('', $PAGE->menu_sub)
484                                     )
485                               );
486         
487     }
488
489     return '';
490 }
491
492 function displaymenu_user () {
493
494     if (logged_on == 1) {
495  &n