+
+if(! function_exists('item_photo_menu')){
+function item_photo_menu($item){
+ $a = get_app();
+
+ if (!isset($a->authors)){
+ $rr = q("SELECT `id`, `network`, `url` FROM `contact` WHERE `uid`=%d AND `self`=0 AND `blocked`=0 ", intval(local_user()));
+ $authors = array();
+ foreach($rr as $r) $authors[$r['url']]= $r;
+ $a->authors = $authors;
+ }
+
+ $contact_url="";
+ $pm_url="";
+
+ $status_link="";
+ $photo_link="";
+ $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
+ $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
+
+ // $item['contact-uid'] is only set on profile page and indicates the uid of the user who owns the profile.
+
+ $profile_owner = ((x($item,'contact-uid')) && intval($item['contact-uid']) ? intval($item['contact-uid']) : 0);
+
+ // So we are checking that this is a logged in user on some page that *isn't* a profile page
+ // OR a profile page where the viewer owns the profile.
+ // Then check if we can use a sparkle (redirect) link to the profile by virtue of it being our contact
+ // or a friend's contact that we both have a connection to.
+
+ if((local_user() && ($profile_owner == 0))
+ || ($profile_owner && $profile_owner == local_user())) {
+
+ if(strlen($item['author-link']) && link_compare($item['author-link'],$item['url']))
+ $redir = $redirect_url;
+ elseif(isset($a->authors[$item['author-link']])) {
+ $redir = $a->get_baseurl() . '/redir/' . $a->authors[$item['author-link']]['id'];
+ $cid = $a->authors[$item['author-link']]['id'];
+ }
+
+ if($item['network'] === 'dfrn' && (! $item['self'])) {
+ $status_link = $redir . "?url=status";
+ $profile_link = $redir . "?url=profile";
+ $photos_link = $redir . "?url=photos";
+ $pm_url = $a->get_baseurl() . '/message/new/' . $cid;
+ }
+
+ $contact_url = $item['self']?"":$a->get_baseurl() . '/contacts/' . (($item['cid']) ? $item['cid'] : $cid);
+ }
+
+
+ $menu = Array(
+ t("View status") => $status_link,
+ t("View profile") => $profile_link,
+ t("View photos") => $photos_link,
+ t("Edit contact") => $contact_url,
+ t("Send PM") => $pm_url,
+ );
+
+
+ $args = array($item, &$menu);
+
+ call_hooks('item_photo_menu', $args);
+
+ $o = "";
+ foreach($menu as $k=>$v){
+ if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
+ }
+ return $o;
+}}
+
+if(! function_exists('lang_selector')) {
+function lang_selector() {
+ global $lang;
+ $o .= '<div id="language-selector" style="display: none;" >';
+ $o .= '<form action="" method="post" ><select name="system_language" onchange="this.form.submit();" >';
+ $langs = glob('view/*/strings.php');
+ if(is_array($langs) && count($langs)) {
+ if(! in_array('view/en/strings.php',$langs))
+ $langs[] = 'view/en/';
+ foreach($langs as $l) {
+ $ll = substr($l,5);
+ $ll = substr($ll,0,strrpos($ll,'/'));
+ $selected = (($ll === $lang) ? ' selected="selected" ' : '');
+ $o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
+ }
+ }
+ $o .= '</select></form></div>';
+ return $o;
+}}
+
+
+if(! function_exists('parse_xml_string')) {
+function parse_xml_string($s) {
+ if(! strstr($s,'<?xml'))
+ return false;
+ $s2 = substr($s,strpos($s,'<?xml'));
+ libxml_use_internal_errors(true);
+ $x = @simplexml_load_string($s2);
+ if(count(libxml_get_errors()))
+ foreach(libxml_get_errors() as $err)
+ logger('libxml: parse: ' . $err, LOGGER_DATA);
+ libxml_clear_errors();
+ return $x;
+}}