small css tweak
[elgg.git] / profile / profile.class.php
blob6cc409c4e7aa7846210c9afecbd3ae22347960cc
1 <?php
2 /*
3 Penny note: none of the queries in this file
4 that are get_something_sql or
5 get_something_select can be converted to use
6 prepared statements because they all have $where
7 that has come from some function somewhere...
8 */
10 Class ElggProfile {
12 function ElggProfile ($profile_id) {
14 global $data;
15 global $page_owner;
16 global $PAGE;
18 // ELGG profile system initialisation
19 // ID of profile to view / edit
21 if (!empty($profile_id)) {
22 $this->id = $profile_id;
23 } else {
24 $this->id = -1;
27 $page_owner = $profile_id;
29 // Profile initialisation
30 // very strange init sequence from the old main() call follows
31 $this->editfield_defaults();
32 // $this->actions(); // not from here --
33 // $this->upload_foaf();
37 function edit_link () {
40 global $page_owner;
41 global $data;
42 global $CFG;
44 $run_result = '';
46 if (run("permissions:check", "profile")) {
48 $editMsg = gettext("Click here to edit this profile.");
50 $run_result .= <<<END
52 <p>
53 <a href="{$CFG->wwwroot}profile/edit.php?profile_id=$page_owner">$editMsg</a>
54 </p>
55 END;
57 $run_result .= run("profile:edit:link");
60 return $run_result;
63 function display_name () {
65 global $name_cache;
66 global $data;
68 if (!isset($name_cache[$this->id]) || (time() - $name_cache[$this->id]->created > 60)) {
70 $name_cache[$this->id]->created = time();
71 $name_cache[$this->id]->data = htmlspecialchars(get_field('users','name','ident',$this->id), ENT_COMPAT, 'utf-8');
74 $run_result = $name_cache[$this->id]->data;
75 return $run_result;
78 function display_form () {
80 global $page_owner;
82 global $data;
84 $run_result = '';
86 $body = "<p>\n" . gettext(" This screen allows you to edit your profile. Blank fields will not show up on your profile screen in any view; you can change the access level for each piece of information in order to prevent it from falling into the wrong hands. For example, we strongly recommend you keep your address to yourself or a few trusted parties.") . "</p>\n";
88 if (run("permissions:check", "profile")) {
90 $profile_username = run("users:id_to_name",$page_owner);
94 $body .= "<form action=\"".url . "profile/edit.php?profile_id=".$page_owner."\" method=\"post\" enctype=\"multipart/form-data\">";
95 $body .= "<p>" . gettext("You can import some profile data by uploading a FOAF file here:") . "</p>";
96 $body .=templates_draw(array(
97 'context' => 'databox',
98 'name' => gettext("Upload a FOAF file:"),
99 'column1' => "<input name=\"foaf_file\" id=\"foaf_file\" type=\"file\" />",
100 'column2' => "<input type=\"submit\" value=\"".gettext("Upload") . "\" />"
103 $body .= <<<END
105 <input type="hidden" name="action" value="profile:foaf:upload" />
106 <input type="hidden" name="profile_id" value="$page_owner" />
107 </form>
109 END;
110 $body .= "<p>" .gettext("Or you can fill in your profile directly below:") . "</p>";
111 $body .= "<form action=\"".url . "profile/edit.php?profile_id=".$page_owner."\" method=\"post\">";
113 // Cycle through all defined profile detail fields and display them
115 if (!empty($data['profile:details']) && sizeof($data['profile:details']) > 0) {
117 foreach($data['profile:details'] as $field) {
118 $body .= $this->editfield_display($field);
123 $submitMsg = gettext("Submit details:");
124 $saveProfile = gettext("Save your profile");
125 $body .= <<< END
127 <p align="center">
128 <label>
129 $submitMsg
130 <input type="submit" name="submit" value="$saveProfile" />
131 </label>
132 <input type="hidden" name="action" value="profile:edit" />
133 <input type="hidden" name="profile_id" value="$page_owner" />
134 </p>
136 </form>
137 END;
139 $run_result .= $body;
142 return $run_result;
145 function editfield_defaults () {
147 global $data;
148 $run_result = '';
149 // Initial profile data
151 /* Profile info is of the format:
153 $data['profile:details'][] = array(
154 Description,
155 Short / unique internal name,
156 Type of field,
157 User instructions for entering data
159 e.g.
160 $data['profile:details'][] = array(gettext("Interests"),"interests","keywords",gettext("Separated with commas."));
162 Additions to this data structure will input/output a corresponding FOAF field
164 $data['foaf:profile'][] = array(
165 Short / unique internal name,
166 Corresponding FOAF schema field
167 "collated" or "individual" - whether multiple data elements (eg interests)
168 should be in separate tags ("individual") or
169 in the same tag separated by commas
170 (collated = default)
171 "resource" or "enclosed" - whether the data is an rdf:resource="" attribute
172 or enclosed within the tag
173 (resource = default)
175 e.g.
176 $data['foaf:profile'][] = array("interests","foaf:interest");
178 Also present is $data['vcard:profile:adr'][] for VCard ADR elements within the FOAF file
179 e.g.
180 $data['vcard:profile:adr'][] = array("streetaddress","vCard:Street","collated");
183 $data['profile:details'][] = array(gettext("Who am I?"),"biography","longtext",gettext("A short introduction for you."));
184 $data['foaf:profile'][] = array("biography","bio:olb","collated","enclosed");
186 $data['profile:details'][] = array(gettext("Brief description"),"minibio","text",gettext("For use in your sidebar profile."));
188 // $data['profile:details'][] = array(gettext("Postal address"),"postaladdress","mediumtext");
189 $data['profile:details'][] = array(gettext("Street address"),"streetaddress","text");
190 $data['vcard:profile:adr'][] = array("streetaddress","vCard:Street","collated","enclosed");
192 $data['profile:details'][] = array(gettext("Town"),"town","keywords");
193 $data['vcard:profile:adr'][] = array("town","vCard:Locality","collated","enclosed");
195 $data['profile:details'][] = array(gettext("State / Region"),"state","keywords");
196 $data['vcard:profile:adr'][] = array("state","vCard:Region","collated","enclosed");
198 $data['profile:details'][] = array(gettext("Postal code"),"postcode","text");
199 $data['vcard:profile:adr'][] = array("postcode","vCard:Pcode","collated","enclosed");
201 $data['profile:details'][] = array(gettext("Country"),"country","keywords");
202 $data['vcard:profile:adr'][] = array("country","vCard:Country","collated","enclosed");
204 $data['profile:details'][] = array(gettext("Email address"),"emailaddress","email");
206 $data['profile:details'][] = array(gettext("Work telephone"),"workphone","text");
207 $data['foaf:profile'][] = array("workphone","foaf:phone","individual","resource");
209 $data['profile:details'][] = array(gettext("Home telephone"),"homephone","text");
210 $data['foaf:profile'][] = array("homephone","foaf:phone","individual","resource");
212 $data['profile:details'][] = array(gettext("Mobile telephone"),"mobphone","text");
213 $data['foaf:profile'][] = array("mobphone","foaf:phone","individual","resource");
215 $data['profile:details'][] = array(gettext("Official website address"),"workweb","web",gettext("The URL to your official website, if you have one."));
216 $data['foaf:profile'][] = array("workweb","foaf:workplaceHomepage","individual","resource");
218 $data['profile:details'][] = array(gettext("Personal website address"),"personalweb","web",gettext("The URL to your personal website, if you have one."));
219 $data['foaf:profile'][] = array("personalweb","foaf:homepage","individual","resource");
221 $data['profile:details'][] = array(gettext("ICQ number"),"icq","icq");
222 $data['foaf:profile'][] = array("icq","foaf:icqChatID","individual","enclosed");
224 $data['profile:details'][] = array(gettext("MSN chat"),"msn","msn");
225 $data['foaf:profile'][] = array("msn","foaf:msnChatID","individual","enclosed");
227 $data['profile:details'][] = array(gettext("AIM screenname"),"aim","aim");
228 $data['foaf:profile'][] = array("aim","foaf:aimChatID","individual","enclosed");
230 $data['profile:details'][] = array(gettext("Skype username"),"skype","skype");
232 $data['profile:details'][] = array(gettext("Jabber username"),"jabber","text");
233 $data['foaf:profile'][] = array("jabber","foaf:jabberChatID","individual","enclosed");
235 $data['profile:details'][] = array(gettext("Interests"),"interests","keywords",gettext("Separated with commas."));
236 $data['foaf:profile'][] = array("interests","foaf:interest","individual","resource");
237 // $data['foaf:profile'][] = array("interests","bio:keywords","collated","enclosed");
239 $data['profile:details'][] = array(gettext("Likes"),"likes","keywords",gettext("Separated with commas."));
240 $data['profile:details'][] = array(gettext("Dislikes"),"dislikes","keywords",gettext("Separated with commas."));
241 $data['profile:details'][] = array(gettext("Occupation"),"occupation","text");
242 $data['profile:details'][] = array(gettext("Industry"),"industry","keywords");
244 $data['profile:details'][] = array(gettext("Company / Institution"),"organisation","text");
245 $data['foaf:profile'][] = array("organisation","foaf:organization","collated","enclosed");
247 $data['profile:details'][] = array(gettext("Job Title"),"jobtitle","text");
248 $data['profile:details'][] = array(gettext("Job Description"),"jobdescription","text");
249 $data['profile:details'][] = array(gettext("I would like to ..."),"goals","keywords",gettext("Separated with commas."));
250 $data['profile:details'][] = array(gettext("Career Goals"),"careergoals","longtext",gettext("Freeform: let colleagues and potential employers know what you'd like to get out of your career."));
251 $data['profile:details'][] = array(gettext("Level of Education"),"educationlevel","text");
252 $data['profile:details'][] = array(gettext("High School"),"highschool","text");
253 $data['profile:details'][] = array(gettext("University / College"),"university","text");
254 $data['profile:details'][] = array(gettext("Degree"),"universitydegree","text");
255 $data['profile:details'][] = array(gettext("Main Skills"),"skills","keywords",gettext("Separated with commas."));
256 return $run_result;
259 // the field parameter seems to be an array of unknown structure...
260 function editfield_display ($field) {
262 // copy array element with default to ''
263 $flabel = !empty($field[0]) ? $field[0] : '';
264 $fname = !empty($field[1]) ? $field[1] : '';
265 $ftype = !empty($field[2]) ? $field[2] : '';
266 $fblurb = !empty($field[3]) ? $field[3] : '';
268 global $page_owner;
269 global $data;
270 global $CFG;
272 $run_result = '';
274 if (empty($flabel) && empty($fname)) {
275 return '';
278 if (!isset($data['profile:preload'][$flabel])) {
279 if (!$value = get_record('profile_data','name',$fname,'owner',$page_owner)) {
280 $value = "";
281 $value->value = "";
282 $value->access = $CFG->default_access;
284 } else {
285 $value = "";
286 $value->value = $data['profile:preload'][$fname];
287 $value->access = $CFG->default_access;
291 $name = "<label for=\"$fname\"><b>{$flabel}</b>";
292 if (!empty($fblurb)) {
293 $name .= "<br /><i>" . $fblurb . "</i>";
295 $name .= '</label>';
297 if (empty($ftype)) {
298 $ftype = "text";
301 $column1 = display_input_field(array("profiledetails[" . $fname . "]",$value->value,$ftype,$fname,@$value->ident,$page_owner));
302 $column2 = "<label>". gettext("Access Restriction:") ."<br />";
303 $column2 .= run("display:access_level_select",array("profileaccess[".$fname . "]",$value->access)) . "</label>";
305 $run_result .=templates_draw(array(
306 'context' => 'databox',
307 'name' => $name,
308 'column1' => $column1,
309 'column2' => $column2
313 return $run_result;
317 function field_display ($field, $allvalues) {
319 global $data;
321 $run_result = '';
323 if (sizeof($field) >= 2) {
325 // $value = get_record('profile_data','name',$field[1],'owner',$this->id);
327 foreach($allvalues as $curvalue) {
328 if ($curvalue->name == stripslashes($field[1])) {
329 $value = $curvalue;
330 break; // found it, done!
334 if (!isset($value)) {
335 return '';
338 if ((($value->value != "" && $value->value != "blank"))
339 && run("users:access_level_check", $value->access)) {
340 $name = $field[0];
341 $column1 = display_output_field(array($value->value,$field[2],$field[1],$field[0],$value->ident));
342 $run_result .=templates_draw(array(
343 'context' => 'databox1',
344 'name' => $name,
345 'column1' => $column1
350 return $run_result;
353 function search ($tagtype, $tagvalue) {
355 global $data, $CFG, $db;
357 $handle = 0;
358 $run_result = '';
360 foreach($data['profile:details'] as $profiletype) {
361 if ($profiletype[1] == $tagtype && $profiletype[2] == "keywords") {
362 $handle = 1;
366 if ($handle) {
368 $searchline = "tagtype = " . $db->qstr($tagtype) . " AND tag = " . $db->qstr($tagvalue) . "";
369 $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ") AND " . $searchline;
370 $searchline = str_replace("owner","t.owner",$searchline);
371 $tagvalue = stripslashes($tagvalue);
372 if ($result = get_record_sql('SELECT DISTINCT u.* FROM '.$CFG->prefix.'tags t
373 LEFT JOIN '.$CFG->prefix.'users u ON u.ident = t.owner
374 WHERE '.$searchline)) {
375 $profilesMsg = gettext("Profiles where");
376 $body = <<< END
378 <h2>
379 $profilesMsg
380 END;
381 $body .= "'".gettext($tagtype)."' = '".$tagvalue."':";
382 $body .= <<< END
383 </h2>
384 END;
385 $body .= <<< END
386 <table class="userlist">
387 <tr>
388 END;
389 $i = 1;
390 foreach($result as $key => $info) {
391 $width = 50;
392 if (sizeof($tagvalue) > 4) {
393 $width = 25;
395 $friends_username = $info->username;
396 $friends_name = htmlspecialchars(stripslashes($info->name), ENT_COMPAT, 'utf-8');
397 $friends_menu = run("users:infobox:menu",array($info->ident));
398 $body .= <<< END
399 <td align="center">
401 <a href="{$CFG->wwwroot}{$friends_username}/">
402 <img src="{$CFG->wwwroot}{$friends_username}/icons/{$info->icon}/w/{$width}" alt="{$friends_name}" border="0" /></a><br />
403 <span class="userdetails">
404 {$friends_name}
405 {$friends_menu}
406 </span>
407 </p>
408 </td>
409 END;
410 if ($i % 5 == 0) {
411 $body .= "</tr><tr>";
413 $i++;
415 $body .= <<< END
416 </tr>
417 </table>
418 END;
419 $run_result .= $body;
422 return $run_result;
425 function search_all_tagtypes () {
427 global $data;
429 foreach($data['profile:details'] as $profiletype) {
430 if ($profiletype[2] == "keywords") {
431 $data['search:tagtypes'][] = $profiletype[1];
434 return true;
437 function search_all_tagtypes_rss () {
439 global $data;
441 foreach($data['profile:details'] as $profiletype) {
442 if ($profiletype[2] == "keywords") {
443 $data['search:tagtypes:rss'][] = $profiletype[1];
446 return true;
449 function search_ecl ($tagtype, $tagvalue) {
451 global $data, $CFG, $db;
453 $handle = 0;
454 $run_result = '';
456 foreach($data['profile:details'] as $profiletype) {
457 if ($profiletype[1] == $tagtype && $profiletype[2] == "keywords") {
458 $handle = 1;
462 if ($handle) {
464 $sub_result = "";
466 $searchline = "tagtype = " . $db->qstr($tagtype) . " AND tag = " . $db->qstr($tagvalue) . "";
467 $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ") AND " . $searchline;
468 $searchline = str_replace("owner", "t.owner", $searchline);
469 $tagvalue = stripslashes($tagvalue);
470 if ($result = get_record_sql('SELECT DISTINCT u.* FROM '.$CFG->prefix.'tags t
471 LEFT JOIN '.$CFG->prefix.'users u ON u.ident = t.owner
472 WHERE '.$searchline)) {
473 foreach($result as $key => $info) {
474 $icon = url . $info->username . '/icons/'.$post->icon;
475 $sub_result .= "\t\t\t<item>\n";
476 $sub_result .= "\t\t\t\t<name><![CDATA[" . htmlspecialchars(stripslashes($info->name), ENT_COMPAT, 'utf-8') . "]]></name>\n";
477 $sub_result .= "\t\t\t\t<link>" . url . htmlspecialchars($info->username, ENT_COMPAT, 'utf-8') . "</link>\n";
478 $sub_result .= "\t\t\t\t<link>$icon</link>\n";
479 $sub_result .= "\t\t\t</item>\n";
483 if ($sub_result != "") {
485 $run_result .= "\t\t<profiles tagtype=\"".addslashes(htmlspecialchars($tagtype, ENT_COMPAT, 'utf-8'))."\">\n" . $sub_result . "\t\t</profiles>\n";
490 return $run_result;
493 function search_rss ($tagtype, $tagvalue) {
495 global $data, $CFG, $db;
497 $handle = 0;
498 $run_result = '';
500 foreach($data['profile:details'] as $profiletype) {
501 if ($profiletype[1] == $tagtype && $profiletype[2] == "keywords") {
502 $handle = 1;
506 if ($handle) {
508 $searchline = "tagtype = " . $db->qstr($tagtype) . " AND tag = " . $db->qstr($tagvalue) . "";
509 $searchline = "(" . run("users:access_level_sql_where",$_SESSION['userid']) . ") AND " . $searchline;
510 $searchline = str_replace("owner", "t.owner", $searchline);
511 $tagvalue = stripslashes($tagvalue);
512 if ($result = get_records_sql('SELECT DISTINCT u.* FROM '.$CFG->prefix.'tags t
513 LEFT JOIN '.$CFG->prefix.'users u ON u.ident = t.owner
514 WHERE '.$searchline)) {
515 foreach($result as $key => $info) {
516 $run_result .= "\t<item>\n";
517 $run_result .= "\t\t<title><![CDATA['" . htmlspecialchars($tagtype, ENT_COMPAT, 'utf-8') . "' = " . htmlspecialchars($tagvalue, ENT_COMPAT, 'utf-8') . " :: " . htmlspecialchars(stripslashes($info->name), ENT_COMPAT, 'utf-8') . "]]></title>\n";
518 $run_result .= "\t\t<link>" . url . htmlspecialchars($info->username, ENT_COMPAT, 'utf-8') . "</link>\n";
519 $run_result .= "\t</item>\n";
523 return $run_result;
526 function upload_foaf () {
528 global $data,$CFG;
530 $action = optional_param('action');
531 if (!empty($action) && $action == "profile:foaf:upload" && logged_on && run("permissions:check", "profile")) {
532 require_once($CFG->dirroot.'lib/uploadlib.php');
533 $um = new upload_manager('foaf_file',false,true,0,true);
534 $dir = $CFG->dataroot . 'tmp/foaf/';
535 if (!$um->process_file_uploads($dir)) {
536 $messages[] = gettext("There was an error uploading the file. Possibly the file was too large, or the upload was interrupted.");
537 $messages[] = $um->get_errors();
538 return false;
540 $file = $um->get_new_filepath();
541 $foaf = @GetXMLTreeProfile($file);
543 $data['profile:preload'] = array();
545 if (isset($foaf['RDF:RDF'][0]['PERSON'][0]) && !isset($foaf['RDF:RDF'][0]['FOAF:PERSON'][0])) {
546 $foaf['RDF:RDF'][0]['FOAF:PERSON'][0] = $foaf['RDF:RDF'][0]['PERSON'][0];
549 if (isset($foaf['RDF:RDF'][0]['FOAF:PERSON'][0])) {
551 $foaf = $foaf['RDF:RDF'][0]['FOAF:PERSON'][0];
553 if (!empty($data['foaf:profile']) && sizeof($data['foaf:profile']) > 0) {
554 foreach($data['foaf:profile'] as $foaf_element) {
556 $profile_value = addslashes($foaf_element[0]);
557 $foaf_name = $foaf_element[1];
558 $individual = $foaf_element[2];
559 $resource = $foaf_element[3];
560 if (isset($foaf[strtoupper($foaf_name)])) {
561 $values = $foaf[strtoupper($foaf_name)];
562 foreach($values as $value) {
563 $thisvalue = "";
564 if (trim($value['VALUE']) != "") {
565 $thisvalue = trim($value['VALUE']);
566 } else if (isset($value['ATTRIBUTES']['DC:TITLE']) && trim($value['ATTRIBUTES']['DC:TITLE'] != "")){
567 $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']);
568 } else if (isset($value['ATTRIBUTES']['RDF:RESOURCE']) && trim($value['ATTRIBUTES']['RDF:RESOURCE'] != "")) {
569 $thisvalue = trim($value['ATTRIBUTES']['RDF:RESOURCE']);
571 if ($thisvalue != "") {
572 if (!isset($data['profile:preload'][$profile_value])) {
573 $data['profile:preload'][$profile_value] = $thisvalue;
574 } else {
575 $data['profile:preload'][$profile_value] .= ", " . $thisvalue;
582 if (!empty($foaf['VCARD:ADR']) && sizeof($foaf['VCARD:ADR']) > 0) {
583 if (!empty($data['vcard:profile:adr']) && sizeof($data['vcard:profile:adr']) > 0) {
585 $foaf = $foaf['VCARD:ADR'][0];
587 foreach($data['vcard:profile:adr'] as $foaf_element) {
588 $profile_value = addslashes($foaf_element[0]);
589 $foaf_name = $foaf_element[1];
590 $individual = $foaf_element[2];
591 $resource = $foaf_element[3];
592 if (isset($foaf[strtoupper($foaf_name)])) {
593 $values = $foaf[strtoupper($foaf_name)];
594 foreach($values as $value) {
595 $thisvalue = "";
596 if (trim($value['VALUE']) != "") {
597 $thisvalue = trim($value['VALUE']);
598 } else if (isset($value['ATTRIBUTES']['DC:TITLE']) && trim($value['ATTRIBUTES']['DC:TITLE'] != "")){
599 $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']);
600 } else if (isset($value['ATTRIBUTES']['RDF:RESOURCE']) && trim($value['ATTRIBUTES']['RDF:RESOURECE'] != "")) {
601 $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']);
603 if ($thisvalue != "") {
604 if (!isset($data['profile:preload'][$profile_value])) {
605 $data['profile:preload'][$profile_value] = $thisvalue;
606 } else {
607 $data['profile:preload'][$profile_value] .= ", " . $thisvalue;
616 $messages[] = gettext("Data from your FOAF file has been preloaded. You must click Save at the bottom of the page for the changes to take effect.");
618 } else {
620 $messages[] = gettext("Error: supplied file did not appear to be a FOAF file.");
625 return true;
628 function view () {
630 global $data;
631 $run_result = '';
633 // Cycle through all defined profile detail fields and display them
635 if (!empty($data['profile:details']) && sizeof($data['profile:details']) > 0) {
637 if ($allvalues = get_records('profile_data','owner',$this->id)) {
638 foreach($data['profile:details'] as $field) {
639 // $field is an array, with the name
640 // of the field in $field[0]
641 $run_result .= $this->field_display($field,$allvalues);
646 return $run_result;
649 function generate_foaf_fields ($user_id) {
651 global $data;
652 $run_result = '';
653 // If $data['foaf:profile'] is set and has elements in it ...
655 $user_id = (int) $user_id;
657 $foaf_elements = "";
658 $where = run("users:access_level_sql_where",$_SESSION['userid']);
660 if (!empty($data['foaf:profile']) && sizeof($data['foaf:profile']) > 0) {
662 foreach($data['foaf:profile'] as $foaf_element) {
665 $value = "";
666 $value_type = "";
668 $profile_value = addslashes($foaf_element[0]);
669 $foaf_name = $foaf_element[1];
670 $individual = $foaf_element[2];
671 $resource = $foaf_element[3];
672 foreach($data['profile:details'] as $profile_element) {
673 if ($profile_element[1] == $profile_value) {
674 $value_type = $profile_element[2];
678 if ($value_type != "keywords") {
679 $result = get_records_select('profile_data',"name = '$profile_value' AND ($where) AND owner = ".$user_id,'','ident,value');
680 } else {
681 $result = get_records_select('tags',"tagtype = '$profile_value' and ($where) AND owner = $user_id",'','ident,tag AS value');
683 if (is_array($result)) {
684 if ($individual == "individual") {
685 foreach($result as $element) {
686 if (trim($element->value) != "") {
687 $value = stripslashes($element->value);
688 if ($resource == "resource") {
689 $enclosure = "\t\t<" . $foaf_name . " ";
690 if ($value_type == "keywords") {
691 $enclosure .= "dc:title=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" ";
692 $enclosure .= "rdf:resource=\"" . url . "tag/".urlencode($value)."\" />\n";
693 } else {
694 $enclosure .= "rdf:resource=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" />\n";
696 $foaf_elements .= $enclosure;
697 } else {
698 $enclosure = "\t\t<" . $foaf_name . "><![CDATA[" . htmlspecialchars(($value), ENT_COMPAT, 'utf-8') . "]]></" . $foaf_name . ">\n";
699 $foaf_elements .= $enclosure;
703 } else {
704 foreach($result as $element) {
705 if (trim($element->value) != "") {
706 if ($value != "") {
707 $value .= ", ";
709 $value .= stripslashes($element->value);
711 if ($resource == "resource") {
712 $enclosure = "\t\t<" . $foaf_name . " ";
713 if ($value_type == "keywords") {
714 $enclosure .= "dc:title=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" ";
715 $enclosure .= "rdf:resource=\"" . url . "tag/".urlencode($value)."\" />\n";
716 } else {
717 $enclosure .= "rdf:resource=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" />\n";
719 } else {
720 $enclosure = "\t\t<" . $foaf_name . "><![CDATA[" . htmlspecialchars(($value), ENT_COMPAT, 'utf-8') . "]]></" . $foaf_name . ">\n";
723 $foaf_elements .= $enclosure;
731 $run_result .= $foaf_elements;
732 return $run_result;
735 function generate_vcard_adr_fields ($user_id) {
737 global $data;
738 $run_results = '';
739 // If $data['vcard:profile:adr'] is set and has elements in it ...
741 $user_id = (int)$user_id;
743 $foaf_elements = "";
744 $where = run("users:access_level_sql_where",$_SESSION['userid']);
746 if (!empty($data['vcard:profile:adr']) && sizeof($data['vcard:profile:adr']) > 0) {
748 foreach($data['vcard:profile:adr'] as $foaf_element) {
751 $value = "";
752 $value_type = "";
754 $profile_value = addslashes($foaf_element[0]);
755 $foaf_name = $foaf_element[1];
756 $individual = $foaf_element[2];
757 $resource = $foaf_element[3];
758 foreach($data['profile:details'] as $profile_element) {
759 if ($profile_element[1] == $profile_value) {
760 $value_type = $profile_element[2];
764 if ($value_type != "keywords") {
765 $result = get_records_select('profile_data',"name = '$profile_value' AND ($where) AND owner = ".$user_id,'','ident,value');
766 } else {
767 $result = get_records_select('tags',"tagtype = '$profile_value' and ($where) AND owner = $user_id",'','ident,tag AS value');
769 if (is_array($result)) {
770 if ($individual == "individual") {
771 foreach($result as $element) {
772 if (trim($element->value) != "") {
773 $value = stripslashes($element->value);
774 if ($resource == "resource") {
775 $enclosure = "\t\t\t<" . $foaf_name . " ";
776 if ($value_type == "keywords") {
777 $enclosure .= "dc:title=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" ";
778 $enclosure .= "rdf:resource=\"" . url . "tag/".urlencode($value)."\" />\n";
779 } else {
780 $enclosure .= "rdf:resource=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" />\n";
782 $foaf_elements .= $enclosure;
783 } else {
784 $enclosure = "\t\t\t<" . $foaf_name . "><![CDATA[" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "]]></" . $foaf_name . ">\n";
785 $foaf_elements .= $enclosure;
789 } else {
790 foreach($result as $element) {
791 if (trim($element->value) != "") {
792 if ($value != "") {
793 $value .= ", ";
795 $value .= stripslashes($element->value);
797 if ($resource == "resource") {
798 $enclosure = "\t\t\t<" . $foaf_name . " ";
799 if ($value_type == "keywords") {
800 $enclosure .= "dc:title=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" ";
801 $enclosure .= "rdf:resource=\"" . url . "tag/".urlencode($value)."\" />\n";
802 } else {
803 $enclosure .= "rdf:resource=\"" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "\" />\n";
805 } else {
806 $enclosure = "\t\t\t<" . $foaf_name . "><![CDATA[" . htmlspecialchars($value, ENT_COMPAT, 'utf-8') . "]]></" . $foaf_name . ">\n";
809 $foaf_elements .= $enclosure;
817 $run_result .= $foaf_elements;
818 return $run_result;
821 function groups_delete ($group_id) {
822 global $data, $USER;
823 // groups:delete
824 // When an access group is deleted, revert all profile items restricted to that group to private
825 $group_id = (int)$group_id;
827 if (!empty($group_id) && logged_on) {
828 // Create 'private' access string for current user
829 $access = "user" . $_SESSION['userid'];
831 // Update profile_data table, setting access to $access
832 // where the owner is the current user and access = 'group$group_id'
833 return set_field('profile_data','access',$access,'access','group'.$group_id,'owner',$USER->ident);
836 return true;
839 function main () {
842 // ELGG Profile system
846 // Initialisation for the search function
847 $function['search:init'][] = path . "units/profile/function_init.php";
848 $function['search:init'][] = path . "units/profile/function_editfield_defaults.php";
849 $function['search:all:tagtypes'][] = path . "units/profile/function_search_all_tagtypes.php";
850 $function['search:all:tagtypes:rss'][] = path . "units/profile/function_search_all_tagtypes_rss.php";
852 // Function to search through profiles
853 $function['search:display_results'][] = path . "units/profile/function_search.php";
854 $function['search:display_results:rss'][] = path . "units/profile/function_search_rss.php";
856 // Functions to view and edit individual profile fields
857 $function['profile:editfield:display'][] = path . "units/profile/function_editfield_display.php";
858 $function['profile:field:display'][] = path . "units/profile/function_field_display.php";
860 // Function to view all profile fields
861 $function['profile:view'][] = path . "units/profile/function_view.php";
863 // Function to display user's name
864 $function['profile:display:name'][] = path . "units/profile/function_display_name.php";
866 $function['profile:user:info'][] = path . "units/profile/profile_user_info.php";
868 // Descriptive text
869 $function['content:profile:edit'][] = path . "units/profile/content_edit.php";
871 // Establish permissions
872 $function['permissions:check'][] = path . "units/profile/permissions_check.php";
874 // FOAF
875 $function['foaf:generate:fields'][] = path . "units/profile/generate_foaf_fields.php";
876 $function['vcard:generate:fields:adr'][] = path . "units/profile/generate_vcard_adr_fields.php";
878 // Actions to perform when an access group is deleted
879 $function['groups:delete'][] = path . "units/profile/groups_delete.php";
886 function permissions_check ($object) {
887 global $page_owner;
888 if ($object === "profile" && $page_owner == $_SESSION['userid']) {
889 return true;
891 return false;
894 function profile_user_info () {
896 global $data;
897 global $page_owner;
899 // If this is someone else's portfolio, display the user's icon
900 $run_result = "<div class=\"box_user\">";
902 $info = get_record('users','ident',$page_owner);
904 if (!$tagline = get_field_sql('SELECT value FROM '.$CFG->prefix.'profile_data
905 WHERE owner = '.$page_owner." AND name = 'minibio'
906 AND (".run("users:access_level_sql_where",$USER->ident).")")) {
907 $tagline = "&nbsp;";
910 $icon = "<img alt=\"\" src=\"".url.$info->username.'icons/'.$info->icon.'/w/67" />';
911 $name = stripslashes($info->name);
912 $url = url . $info->username . "/";
914 $body =templates_draw(array(
915 'context' => 'ownerbox',
916 'name' => $name,
917 'profileurl' => $url,
918 'usericon' => $icon,
919 'tagline' => $tagline,
920 'lmshosts' => 'foo',
921 'usermenu' => run("users:infobox:menu:text",array($page_owner))
925 if ($page_owner != -1) {
926 if ($page_owner != $_SESSION['userid']) {
927 $title = gettext("Profile Owner");
928 } else {
929 $title = gettext("You");
933 $run_result .=templates_draw(array(
934 'context' => 'contentholder',
935 'title' => $title,
936 'body' => $body,
937 'submenu' => ""
941 $run_result .= "</div>";
943 return $run_result;
946 } // End Class ElggProfile