loadXML($xml); return new DOMXPath($dom); } //TODO: move this into a template function badge_render_section($params) { global $path_prefix, $base_url; // organise input into headings and rows $current_section = ""; $sections = array("" => array()); foreach ($params as $item) { list($k, $v) = $item; if ($k == 'heading') { $current_section = $v; $sections[$v] = array(); } else { $sections[$current_section][] = $v; } } $html = ''; foreach ($sections as $section_name => $items) { if ($section_name) { $img_path = "$path_prefix/web/images/{$section_name}-logo.png"; if (file_exists($img_path)) { $sz = getimagesize($img_path); $section_name = ''; } $html .= ''; } $n = count($items); for ($start = 0; $start < $n; $start += 2) { $html .= ''; for ($pos = $start; $pos < $n && $pos < $start + 2; ++$pos) { $html .= ''; } $html .= ''; } } $html .= "
'.$section_name.'
'.$items[$pos].'
"; return $html; } $path = @$_SERVER['PATH_INFO']; $html = $error = ""; $format = "js"; $url_params = array(); if (preg_match("~^/(js|jscb|jsdiv|html)/(\d+)/([a-z]+)/([a-zA-Z0-9\-\_\.]+)/(.*)$~", $path, $m)) { list($all, $format, $uid, $show_what, $param, $rest_of_url) = $m; foreach (explode("/", $rest_of_url) as $item) { if (!trim($item)) continue; list($k, $v) = explode("=", $item, 2); $url_params[$k] = preg_replace("~[^a-zA-Z0-9\-\_]~", "_", $v); } $uid = (int)$uid; $perpage = (int)$param; $page = 1; $user = new User(); $user->load($uid); $cols = 2; $col_width_pix = 90; $badge_width_pix = $cols * $col_width_pix; //FIXME: If you take out the below, it breaks the badge display in IE. I don't have a clue why, // but it seems that we need something between the
and the EOF; if ($show_what == 'show') { // new-style sidebar widget $badge_tag = $param; try { $widget = $user->load_widget($badge_tag); $badge =& $widget->config; } catch (PAException $e) { switch ($e->code) { case ROW_DOES_NOT_EXIST: $html = "

User has not yet created a sidebar widget.

"; break; default: throw $e; } $badge = array(); } $profile =& $badge['profile']; if (@$profile['enabled']) { $html .= '

About me

'; $prof = get_profile_info($user->user_id, BASIC); $html .= '

'.htmlspecialchars($prof['first_name'].' '.$prof['last_name']).'

'; $prof = get_profile_info($user->user_id, "flickr"); if (count($prof)) { $html .= '

Flickr: '.htmlspecialchars($prof['username']).'

'; } $prof = get_profile_info($user->user_id, "facebook"); if (count($prof)) { $html .= "

Facebook

"; $xp = badge_parse_xml($prof['school_info']); if ($xp) { $html .= "

School: ".htmlspecialchars($xp->query("name/text()")->item(0)->data.", ". $xp->query("year/text()")->item(0)->data).'

'; } $xp = badge_parse_xml($prof['affiliations']); if ($xp) { $html .= "

Affiliations: ".htmlspecialchars($xp->query("name/text()")->item(0)->data." ". $xp->query("status/text()")->item(0)->data.", ". $xp->query("year/text()")->item(0)->data).'

'; } } } foreach (array( array("friends", "friends", "internal"), array("friends_ext", "imported friends", "external"), ) as $args) { list ($group_key, $display_name, $rel_scope) = $args; $friends =& $badge[$group_key]; if (@$friends['enabled']) { $html .= "

My $display_name

"; // $rel = Relation::get_relations($user->user_id); // echo "relations: "; var_dump($rel); $rel = Relation::get_all_relations($user->user_id, 0, FALSE, 'ALL', 0, 'created', 'DESC', $rel_scope); // echo "

all relations: "; var_dump($rel); echo "

"; $rel_incl = @$friends['included']; $max_friends = 8; // show max 8 friends in the widget $rel_show = select_random_subset($rel_incl, $friends['show'], $rel, 'objects', $max_friends); // sort by network $sorted_friends = array(); foreach ($rel_show as $rel_info) { $net = &$sorted_friends[$rel_info['network']]; if (!isset($net)) $net = array(); $net[] = $rel_info; unset($net); // drop reference } $items_html = array(); foreach ($sorted_friends as $sorted_friend_group) { $n = $sorted_friend_group[0]['network']; if (trim($n)) $items_html[] = array("heading", $n); // $html .= "
".$sorted_friend_group[0]['network'].'
'; foreach ($sorted_friend_group as $rel_info) { if ($rel_scope == 'internal') { $person_url_enc = $base_url."/user.php?uid=".$rel_info['user_id']; $img = uihelper_resize_mk_user_img($rel_info['picture'], 75, 75); } else { $person_url_enc = htmlspecialchars($rel_info['user_id']); $img = ''; } $person_name_enc = htmlspecialchars($rel_info['display_name']); $item_html = <<
$img
$person_name_enc
EOS; $items_html[] = array("item", $item_html); } } $html .= badge_render_section($items_html); } } $groups =& $badge['groups']; if (@$groups['enabled']) { $html .= "

My groups

"; $grp = Group::get_user_groups($user->user_id, FALSE, 1000, 1); $grp_ids = array(); foreach ($grp as $g) $grp_ids[] = $g['gid']; $grp_incl = @$groups['included']; $max_groups = 8; // show 8 groups (this should be configurable) $grp_show = select_random_subset($grp_incl, $groups['show'], $grp_ids, 'ids', $max_groups); $items_html = array(); foreach ($grp_show as $grp_id) { $group_url_enc = "$base_url/group.php?gid=$grp_id"; $grp = new Group(); $grp->load((int)$grp_id); $img = uihelper_resize_mk_img("files/".$grp->picture, 75, 75, DEFAULT_USER_PHOTO_REL); $group_name_enc = htmlspecialchars($grp->title); $h = <<
$img
$group_name_enc
EOS; $items_html[] = array("item", $h); } $html .= badge_render_section($items_html); } $networks =& $badge['networks']; if (@$networks['enabled']) { $html .= "

My networks

"; $nets = Network::get_user_networks($user->user_id, FALSE, 1000, 1); $net_ids = array(); $net_lookup = array(); foreach ($nets as $n) { $net_ids[] = $n->network_id; $net_lookup[$n->network_id] = $n; } $net_incl = @$networks['included']; $max_networks = 8; // need to make this configurable $net_show = select_random_subset($net_incl, $networks['show'], $net_ids, 'ids', $max_networks); $items_html = array(); foreach ($net_show as $net_id) { $net = $net_lookup[$net_id]; $network_url_enc = 'http://'.$net->address.'.'.$domain_suffix.BASE_URL_REL; $extra = unserialize($net->extra) ; $network_image_name = $extra['basic']['header_image']['name']; $img = uihelper_resize_mk_img("files/".$network_image_name, 75, 75, DEFAULT_USER_PHOTO_REL); $network_name_enc = htmlspecialchars($net->name); $h = <<
$img
$network_name_enc
EOS; $items_html[] = array("item", $h); } $html .= badge_render_section($items_html); } $posts =& $badge['posts']; if (@$posts['enabled']) { $html .= <<My posts
    ENS; // get all recent posts + sb content $entries = Content::load_content_id_array($user->user_id, NULL, FALSE, 8, 1); foreach ($entries as $entry) { $url_enc = htmlspecialchars("$base_url/content.php?cid=".$entry['content_id']); $title_enc = htmlspecialchars($entry['title']); $html .= <<$title_enc ENS; } $html .= << ENS; } foreach (array( array("images", IMAGE, "image_file", NULL, "image_file", "image", "photos"), array("audio", AUDIO, NULL, "images/audio-icon.gif", "audio_file", "audio", "audio"), array("video", VIDEO, NULL, "images/video-icon.gif", "video_file", "video", "video"), ) as $info) { list($badge_key, $content_type, $thumbnail_key, $icon_file, $filename_key, $mfv_type, $display_name) = $info; $images =& $badge[$badge_key]; if (@$images['enabled']) { $html .= <<My $display_name ENS; $recent = Content::get_recent_content_for_user($user->user_id, $content_type, 8); $items_html = array(); foreach ($recent as $obj) { if ($thumbnail_key) { $img = uihelper_resize_mk_img("files/".$obj[$thumbnail_key], 75, 75); } else { $img = uihelper_resize_mk_img("$current_theme_rel_path/$icon_file", 75, 75, NULL, "", RESIZE_FIT_NO_EXPAND); } $url_enc = htmlspecialchars("$base_url/media_full_view.php?cid=".$obj['content_id']."&type=".$mfv_type); $title_enc = htmlspecialchars($obj['title']); $h = <<
    $img
    $title_enc
    EOS; $items_html[] = array("item", $h); } $html .= badge_render_section($items_html); } } } else { // old-style friends / groups badge $html .= "

    user_id\">$user->first_name $user->last_name's $show_what:

    "; $show_all_url = ""; switch ($show_what) { case 'friends': $perpage = (int)$param; $relations = Relation::get_all_relations($user->user_id, 0, FALSE, $param, $page); $n = count($relations); $rows = intval($n/3) + ($n % 3 ? 1 : 0); $pos = 0; $html .= ""; for ($y = 0; $y < $rows; ++$y) { $html .= ""; for ($x = 0; $x < $cols && $pos < $n; ++$x, ++$pos) { $html .= '"; } $html .= ""; } $show_all_url = "$base_url/view_all_members.php?view_type=relations&uid=$user->user_id"; $html .= ""; for ($i = 0; $i < $cols - 1; ++$i) $html .= ''; $html .= ""; $html .= "
    '; $rel = $relations[$pos]; $html .= ''; if ($rel['picture'] && file_exists("files/".$rel['picture'])) { $html .= uihelper_resize_mk_user_img($rel['picture'], 50, 50) . "
    "; } $html .= htmlspecialchars($rel['login_name']).'
    '; $html .= "
    show all
    "; break; case 'groups': $perpage = (int)$param; $html .= ""; break; } } $html .= '

    '; $html .= ""; } else { $html = "Error parsing URL ($path)."; } function js_quote($html) { return "'".str_replace("\n", "\\n", str_replace("'", "\\'", $html))."'"; } switch ($format) { case 'js': header("Content-Type: application/x-javascript"); echo "document.write(".js_quote($html).");"; break; case 'jscb': header("Content-Type: application/x-javascript"); $cb = @$url_params['cb']; if (!$cb) { echo 'alert("Missing cb parameter to PA JS call! Check that your PeopleAggregator badge script is correct.");'; } else { echo "$cb(".js_quote($html).");"; } break; case 'jsdiv': header("Content-Type: application/x-javascript"); $div = @$url_params['div']; if (!$div) { echo 'alert("Missing div parameter to PA JS call! Check that your PeopleAggregator badge script is correct.");'; } else { echo "document.getElementById('$div').innerHTML = ".js_quote($html).";"; } break; case 'html': echo $html; break; } ?>