root/elgg/trunk/profile/index.php

Revision 151, 11.1 kB (checked in by cedenoj, 1 year ago)

fixes #2833 The profile module now uses PARAM_SAFEDIR as defined in lib/constants.php to allow usernames that include underscores. This should allow the dino users to view and create their profiles. The .htaccess file was also modified so that dino users get pretty urls as well.

Line 
1 <?php
2
3 //    ELGG profile view page
4
5 // Run includes
6 require_once(dirname(dirname(__FILE__)) . '/includes.php');
7 require_once($CFG->dirroot . 'profile/profile.class.php');
8
9 // define what profile to show
10 $profile_name = optional_param('profile_name', '', PARAM_SAFEDIR);
11 if (!empty($profile_name)) {
12     $profile_id = user_info_username('ident', $profile_name);
13 }
14 if (empty($profile_id)) {
15     $profile_id = optional_param('profile_id', -1, PARAM_INT);
16 }
17 // and the page_owner naturally
18 $page_owner = $profile_id;
19
20 define("context", "profile");
21 templates_page_setup();
22
23 // two column version
24
25 class ElggProfile2 extends ElggProfile {
26     
27     function view () {
28
29         global $data;
30         global $page_owner;
31         global $CFG;
32         
33         $run_result = '';
34         $usertype = user_type($page_owner);
35         
36         $icon = user_info('icon',$page_owner);
37         $username = user_info('username',$page_owner);
38         $icon_url = $CFG->wwwroot.'_icon/user/'.$icon.'/w/240';
39         
40         // $first_column_fields = array('biography','likes','dislikes');
41         // $id_block_fields = array('gender','town','country','birth_date');
42
43         
44         // Cycle through all defined profile detail fields and display them
45
46         $allvalues = get_records('profile_data','owner',$this->id);
47         $first_column_fields = array();
48         $second_column_fields = array();
49         $firstcol = "";
50         $secondcol = "";
51         foreach($data['profile:details'] as $field) {
52             if (is_array($field)) {
53                 $flabel = !empty($field[0]) ? $field[0] : '';
54                 $fname  = !empty($field[1]) ? $field[1] : '';
55                 $ftype  = !empty($field[2]) ? $field[2] : '';
56                 $fblurb = !empty($field[3]) ? $field[3] : '';
57                 $fusertype = !empty($field[4]) ? $field[4] : '';
58                 $finvisible = false;
59                 $frequired = false;
60                 $fcat = __gettext("Main");
61             // Otherwise map things the new way!
62             } else {
63                 $flabel = $field->name;
64                 $fname = $field->internal_name;
65                 $ftype = $field->field_type;
66                 $fblurb = $field->description;
67                 $fusertype = $field->user_type;
68                 $finvisible = $field->invisible;
69                 $frequired = $field->required;
70                 if (!isset($field->col1)) {
71                     $col1 = false;
72                 } else {
73                     $col1 = $field->col1;
74                     $first_column_fields[] = $fname;
75                 }
76                 if (!isset($field->col2)) {
77                     $col2 = false;
78                 } else {
79                     $col2 = $field->col2;
80                     $second_column_fields[] = $fname;
81                 }
82                 if (!empty($field->category)) {
83                     $fcat = $field->category;
84                 } else {
85                     $fcat = __gettext("Main");
86                 }
87             }
88             if (empty($fusertype) || $usertype == $fusertype) {
89             // $field is an array, with the name
90             // of the field in $field[0]
91                 if (in_array($fname,$first_column_fields)) {
92                     $firstcol .= $this->field_display($field,$allvalues);
93                 } else if (in_array($fname,$second_column_fields)) {
94                     $secondcol .= $this->field_display($field,$allvalues);
95                 }
96             }
97         }
98         // $other_fields = array_merge($first_column_fields,$second_column_fields);
99         $run_result .= '<div class="profile_main">'."\n";
100         $run_result .= '<div class="profile_primary">'."\n";
101         // $run_result .= '<div class="profile_icon"><img src="'.$icon_url.'"></div>'."\n";
102         $run_result .= $firstcol;
103         $run_result .= templates_draw(array(
104                                                            'context' => 'databox1',
105                                                            'name' => __gettext("Extended profile"),
106                                                            'column1' => "<a href=\"{$CFG->wwwroot}profile/extended.php?profile_name={$username}\">" . __gettext("Click here to view extended profile") . "</a>"
107                                                            )
108                                    );
109         $run_result .= '</div>'."\n";       
110         $run_result .= '<div class="profile_secondary">'."\n";
111         
112         $run_result .= $secondcol;
113         $run_result .= "</div>\n";
114         $run_result .= '<div class="profile_main_bottom"></div>'."</div>\n";
115
116                 
117         // Draw the user's comment wall
118         if (function_exists("commentwall_displayonprofile")) {
119             
120             $offset = optional_param('offset', 0);
121             $limit = optional_param('limit', 3);
122             $run_result .= commentwall_displayonprofile($page_owner, $limit, $offset);
123         } 
124         
125         $view = array();
126         $view['body'] = $run_result;
127         
128         $run_result = '';
129         
130         $username = user_info('username',$this->id);
131         $run_result .= '<div id="profile_widgets">'."\n";
132         $run_result .= widget_page_display($page_owner,'profile',0,2);     
133
134         $run_result .= "</div>\n";
135         
136         $view['body'] .= $run_result;
137         
138         return $view;
139     }
140     
141     function bare_field_display ($field, $allvalues) {
142
143         global $data;
144
145         $run_result = '';
146
147         if (is_array($field)) {
148             $flabel = !empty($field[0]) ? $field[0] : '';
149             $fname  = !empty($field[1]) ? $field[1] : '';
150             $ftype  = !empty($field[2]) ? $field[2] : '';
151             $fblurb = !empty($field[3]) ? $field[3] : '';
152             $fusertype = !empty($field[4]) ? $field[4] : '';
153             $finvisible = false;
154             $frequired = false;
155             $fcat = __gettext("Main");
156         // Otherwise map things the new way!
157         } else {
158             $flabel = $field->name;
159             $fname = $field->internal_name;
160             $ftype = $field->field_type;
161             $fblurb = $field->description;
162             $fusertype = $field->user_type;
163             $finvisible = $field->invisible;
164             $frequired = $field->required;
165             if (!empty($field->category)) {
166                 $fcat = $field->category;
167             } else {
168                 $fcat = __gettext("Main");
169             }
170         }
171     
172         // $value = get_record('profile_data','name',$field[1],'owner',$this->id);
173     
174         foreach($allvalues as $curvalue) {
175             if ($curvalue->name == stripslashes($fname)) {
176                 $value = $curvalue;
177                 break; // found it, done!
178             }
179         }
180
181         if (!isset($value)) {
182             return '';
183         }
184
185         if ((($value->value != "" && $value->value != "blank"))
186             && run("users:access_level_check", $value->access)) {
187             $column1 = display_output_field(array($value->value,$ftype,$fname,$flabel,$value->ident));
188             $run_result .= $column1;
189         }
190         return $run_result;
191     }
192
193         
194     function get_value ($field, $allvalues) {
195
196         global $data;
197
198         $run_result = '';
199
200         if (is_array($field)) {
201             $flabel = !empty($field[0]) ? $field[0] : '';
202             $fname  = !empty($field[1]) ? $field[1] : '';
203             $ftype  = !empty($field[2]) ? $field[2] : '';
204             $fblurb = !empty($field[3]) ? $field[3] : '';
205             $fusertype = !empty($field[4]) ? $field[4] : '';
206             $finvisible = false;
207             $frequired = false;
208             $fcat = __gettext("Main");
209         // Otherwise map things the new way!
210         } else {
211             $flabel = $field->name;
212             $fname = $field->internal_name;
213             $ftype = $field->field_type;
214             $fblurb = $field->description;
215             $fusertype = $field->user_type;
216             $finvisible = $field->invisible;
217             $frequired = $field->required;
218             if (!empty($field->category)) {
219                 $fcat = $field->category;
220             } else {
221                 $fcat = __gettext("Main");
222             }
223         }
224     
225         // $value = get_record('profile_data','name',$field[1],'owner',$this->id);
226     
227         foreach($allvalues as $curvalue) {
228             if ($curvalue->name == stripslashes($fname)) {
229                 $value = $curvalue;
230                 break; // found it, done!
231             }
232         }
233
234         if (!isset($value)) {
235             return '';
236         }
237
238         if ((($value->value != "" && $value->value != "blank"))
239             && run("users:access_level_check", $value->access)) {
240             return $value->value;
241         }
242
243         return '';
244     }
245     
246
247     function doRelativeDate($in_seconds) {
248         /**
249             This function returns either a relative date or a formatted date depending
250             on the difference between the current datetime and the datetime passed.
251                 $posted_date should be in the following format: YYYYMMDDHHMMSS
252             
253             Relative dates look something like this:
254                 3 weeks, 4 days ago
255             
256             The function includes 'ago' or 'on' and assumes you'll properly add a word
257             like 'Posted ' before the function output.
258         **/
259     
260         $diff = time()-$in_seconds;
261         $months = floor($diff/2592000);
262         $diff -= $months*2419200;
263         $weeks = floor($diff/604800);
264         $diff -= $weeks*604800;
265         $days = floor($diff/86400);
266         $diff -= $days*86400;
267         $hours = floor($diff/3600);
268         $diff -= $hours*3600;
269         $minutes = floor($diff/60);
270         $diff -= $minutes*60;
271         $seconds = $diff;
272         
273         $relative_date = '';
274     
275         if ($months>0) {
276             // over a month old, just show date (mm/dd/yyyy format)
277             return 'on '.date('r',$in_seconds);
278         } else {
279             if ($weeks>0) {
280                 // weeks and days
281                 $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks>1?'s':'');
282                 $relative_date .= $days>0?($relative_date?', ':'').$days.' day'.($days>1?'s':''):'';
283             } elseif ($days>0) {
284                 // days and hours
285                 $relative_date .= ($relative_date?', ':'').$days.' day'.($days>1?'s':'');
286                 $relative_date .= $hours>0?($relative_date?', ':'').$hours.' hour'.($hours>1?'s':''):'';
287             } elseif ($hours>0) {
288                 // hours and minutes
289                 $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours>1?'s':'');
290                 $relative_date .= $minutes>0?($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':''):'';
291             } elseif ($minutes>0) {
292                 // minutes only
293                 $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes>1?'s':'');
294             } else {
295                 // seconds only
296                 $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds>1?'s':'');
297             }
298         }
299         // show relative date and add proper verbiage
300         return $relative_date.' ago';
301     }           
302 }
303
304 // init library
305 $profile = new ElggProfile2($profile_id);
306         
307 $title = $profile->display_name();
308 // $title = 'Profile';
309 $view  = $profile->view();
310
311 templates_page_output($title, $view['body']);
312
313 ?>
314
Note: See TracBrowser for help on using the browser.