root/releases/0.672/lib/displaylib.php

Revision 659, 17.0 kB (checked in by misja, 2 years ago)

Taking gettext to a new level, see message <http://lists.elgg.org/pipermail/development/2006-October/000590.html>. In a nutshell: all gettext calls are replaced by gettext, revamped gettext handling plus some additional fixes.

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