root/releases/0.8rc1/profile/index.php

Revision 1046, 11.0 kB (checked in by sven, 2 years ago)

fixes for profile stuff: whitespace, html validation, php notices, cache-unfriendly queries, missing functions

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