3 // ELGG profile view page
6 require_once(dirname(dirname(__FILE__
)) . '/includes.php');
7 require_once($CFG->dirroot
. 'profile/profile.class.php');
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);
14 if (empty($profile_id)) {
15 $profile_id = optional_param('profile_id', -1, PARAM_INT
);
17 // and the page_owner naturally
18 $page_owner = $profile_id;
20 define("context", "profile");
21 templates_page_setup();
25 class ElggProfile2
extends ElggProfile
{
34 $usertype = user_type($page_owner);
36 $icon = user_info('icon',$page_owner);
37 $username = user_info('username',$page_owner);
38 $icon_url = $CFG->wwwroot
.'_icon/user/'.$icon.'/w/240';
40 // $first_column_fields = array('biography','likes','dislikes');
41 // $id_block_fields = array('gender','town','country','birth_date');
44 // Cycle through all defined profile detail fields and display them
46 $allvalues = get_records('profile_data','owner',$this->id
);
47 $first_column_fields = array();
48 $second_column_fields = array();
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] : '';
60 $fcat = __gettext("Main");
61 // Otherwise map things the new way!
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
)) {
74 $first_column_fields[] = $fname;
76 if (!isset($field->col2
)) {
80 $second_column_fields[] = $fname;
82 if (!empty($field->category
)) {
83 $fcat = $field->category
;
85 $fcat = __gettext("Main");
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);
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>"
109 $run_result .= '</div>'."\n";
110 $run_result .= '<div class="profile_secondary">'."\n";
112 $run_result .= $secondcol;
113 $run_result .= "</div>\n";
114 $run_result .= '<div class="profile_main_bottom"></div>'."</div>\n";
117 // Draw the user's comment wall
118 if (function_exists("commentwall_displayonprofile")) {
120 $offset = optional_param('offset', 0);
121 $limit = optional_param('limit', 3);
122 $run_result .= commentwall_displayonprofile($page_owner, $limit, $offset);
126 $view['body'] = $run_result;
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);
134 $run_result .= "</div>\n";
136 $view['body'] .= $run_result;
141 function bare_field_display ($field, $allvalues) {
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] : '';
155 $fcat = __gettext("Main");
156 // Otherwise map things the new way!
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
;
168 $fcat = __gettext("Main");
172 // $value = get_record('profile_data','name',$field[1],'owner',$this->id);
174 foreach($allvalues as $curvalue) {
175 if ($curvalue->name
== stripslashes($fname)) {
177 break; // found it, done!
181 if (!isset($value)) {
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;
194 function get_value ($field, $allvalues) {
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] : '';
208 $fcat = __gettext("Main");
209 // Otherwise map things the new way!
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
;
221 $fcat = __gettext("Main");
225 // $value = get_record('profile_data','name',$field[1],'owner',$this->id);
227 foreach($allvalues as $curvalue) {
228 if ($curvalue->name
== stripslashes($fname)) {
230 break; // found it, done!
234 if (!isset($value)) {
238 if ((($value->value
!= "" && $value->value
!= "blank"))
239 && run("users:access_level_check", $value->access
)) {
240 return $value->value
;
247 function doRelativeDate($in_seconds) {
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
253 Relative dates look something like this:
256 The function includes 'ago' or 'on' and assumes you'll properly add a word
257 like 'Posted ' before the function output.
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;
276 // over a month old, just show date (mm/dd/yyyy format)
277 return 'on '.date('r',$in_seconds);
281 $relative_date .= ($relative_date?
', ':'').$weeks.' week'.($weeks>1?
's':'');
282 $relative_date .= $days>0?
($relative_date?
', ':'').$days.' day'.($days>1?
's':''):'';
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) {
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) {
293 $relative_date .= ($relative_date?
', ':'').$minutes.' minute'.($minutes>1?
's':'');
296 $relative_date .= ($relative_date?
', ':'').$seconds.' second'.($seconds>1?
's':'');
299 // show relative date and add proper verbiage
300 return $relative_date.' ago';
305 $profile = new ElggProfile2($profile_id);
307 $title = $profile->display_name();
308 // $title = 'Profile';
309 $view = $profile->view();
311 $body = templates_draw( array(
312 'context' => 'contentholder',
314 'body' => $view['body'],
317 //echo templates_page_draw(array($title, $body, NULL, $view['widgets']));
318 echo templates_page_draw(array($title, $body));