Exemplo n.º 1
0
function network_to_name($s, $profile = "")
{
    $nets = array(NETWORK_DFRN => t('Friendica'), NETWORK_OSTATUS => t('OStatus'), NETWORK_FEED => t('RSS/Atom'), NETWORK_MAIL => t('Email'), NETWORK_DIASPORA => t('Diaspora'), NETWORK_FACEBOOK => t('Facebook'), NETWORK_ZOT => t('Zot!'), NETWORK_LINKEDIN => t('LinkedIn'), NETWORK_XMPP => t('XMPP/IM'), NETWORK_MYSPACE => t('MySpace'), NETWORK_MAIL2 => t('Email'), NETWORK_GPLUS => t('Google+'), NETWORK_PUMPIO => t('pump.io'), NETWORK_TWITTER => t('Twitter'), NETWORK_DIASPORA2 => t('Diaspora Connector'), NETWORK_STATUSNET => t('Statusnet'), NETWORK_APPNET => t('App.net'));
    call_hooks('network_to_name', $nets);
    $search = array_keys($nets);
    $replace = array_values($nets);
    $networkname = str_replace($search, $replace, $s);
    if ($s == NETWORK_DIASPORA and $profile != "" and diaspora_is_redmatrix($profile)) {
        $networkname = t("Redmatrix");
    }
    return $networkname;
}
Exemplo n.º 2
0
function diaspora_post($importer, $xml, $msg)
{
    $a = get_app();
    $guid = notags(unxmlify($xml->guid));
    $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
    if ($diaspora_handle != $msg['author']) {
        logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
        return 202;
    }
    $contact = diaspora_get_contact_by_handle($importer['uid'], $diaspora_handle);
    if (!$contact) {
        logger('diaspora_post: A Contact for handle ' . $diaspora_handle . ' and user ' . $importer['uid'] . ' was not found');
        return 203;
    }
    if (!diaspora_post_allow($importer, $contact, false)) {
        logger('diaspora_post: Ignoring this author.');
        return 202;
    }
    $message_id = $diaspora_handle . ':' . $guid;
    $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($importer['uid']), dbesc($guid));
    if (count($r)) {
        logger('diaspora_post: message exists: ' . $guid);
        return 208;
    }
    $created = unxmlify($xml->created_at);
    $private = unxmlify($xml->public) == 'false' ? 1 : 0;
    $body = diaspora2bb($xml->raw_message);
    $datarray = array();
    $datarray["object"] = json_encode($xml);
    if ($xml->photo->remote_photo_path and $xml->photo->remote_photo_name) {
        $datarray["object-type"] = ACTIVITY_OBJ_PHOTO;
    } else {
        $datarray['object-type'] = ACTIVITY_OBJ_NOTE;
        // Add OEmbed and other information to the body
        if (!diaspora_is_redmatrix($contact['url'])) {
            $body = add_page_info_to_body($body, false, true);
        }
    }
    $str_tags = '';
    $cnt = preg_match_all('/@\\[url=(.*?)\\[\\/url\\]/ism', $body, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            if (strlen($str_tags)) {
                $str_tags .= ',';
            }
            $str_tags .= '@[url=' . $mtch[1] . '[/url]';
        }
    }
    $plink = diaspora_plink($diaspora_handle, $guid);
    $datarray['uid'] = $importer['uid'];
    $datarray['contact-id'] = $contact['id'];
    $datarray['wall'] = 0;
    $datarray['network'] = NETWORK_DIASPORA;
    $datarray['verb'] = ACTIVITY_POST;
    $datarray['guid'] = $guid;
    $datarray['uri'] = $datarray['parent-uri'] = $message_id;
    $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC', 'UTC', $created);
    $datarray['private'] = $private;
    $datarray['parent'] = 0;
    $datarray['plink'] = $plink;
    $datarray['owner-name'] = $contact['name'];
    $datarray['owner-link'] = $contact['url'];
    //$datarray['owner-avatar'] = $contact['thumb'];
    $datarray['owner-avatar'] = x($contact, 'thumb') ? $contact['thumb'] : $contact['photo'];
    $datarray['author-name'] = $contact['name'];
    $datarray['author-link'] = $contact['url'];
    $datarray['author-avatar'] = $contact['thumb'];
    $datarray['body'] = $body;
    $datarray['tag'] = $str_tags;
    if ($xml->provider_display_name) {
        $datarray["app"] = unxmlify($xml->provider_display_name);
    } else {
        $datarray['app'] = 'Diaspora';
    }
    // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible.
    $datarray['visible'] = strlen($body) ? 1 : 0;
    DiasporaFetchGuid($datarray);
    $message_id = item_store($datarray);
    logger("Stored item with message id " . $message_id, LOGGER_DEBUG);
    return 201;
}
Exemplo n.º 3
0
 /**
  * Get data in a form usable by a conversation template
  *
  * Returns:
  *      _ The data requested on success
  *      _ false on failure
  */
 public function get_template_data($conv_responses, $thread_level = 1)
 {
     require_once "mod/proxy.php";
     $result = array();
     $a = $this->get_app();
     $item = $this->get_data();
     $edited = false;
     if (strcmp($item['created'], $item['edited']) != 0) {
         $edited = array('label' => t('This entry was edited'), 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), 'relative' => relative_date($item['edited']));
     }
     $commentww = '';
     $sparkle = '';
     $buttons = '';
     $dropping = false;
     $star = false;
     $ignore = false;
     $isstarred = "unstarred";
     $indent = '';
     $shiny = '';
     $osparkle = '';
     $total_children = $this->count_descendants();
     $conv = $this->get_conversation();
     $lock = $item['private'] == 1 || $item['uid'] == local_user() && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false;
     $shareable = $conv->get_profile_owner() == local_user() && $item['private'] != 1 ? true : false;
     if (local_user() && link_compare($a->contact['url'], $item['author-link'])) {
         if ($item["event-id"] != 0) {
             $edpost = array($a->get_baseurl($ssl_state) . "/events/event/" . $item['event-id'], t("Edit"));
         } else {
             $edpost = array($a->get_baseurl($ssl_state) . "/editpost/" . $item['id'], t("Edit"));
         }
     } else {
         $edpost = false;
     }
     if ($this->get_data_value('uid') == local_user() || $this->is_visiting()) {
         $dropping = true;
     }
     $drop = array('dropping' => $dropping, 'pagedrop' => feature_enabled($conv->get_profile_owner(), 'multi_delete') ? $item['pagedrop'] : '', 'select' => t('Select'), 'delete' => t('Delete'));
     $filer = $conv->get_profile_owner() == local_user() ? t("save to folder") : false;
     $diff_author = link_compare($item['url'], $item['author-link']) ? false : true;
     $profile_name = htmlentities(strlen($item['author-name']) && $diff_author ? $item['author-name'] : $item['name']);
     if ($item['author-link'] && !$item['author-name']) {
         $profile_name = $item['author-link'];
     }
     $sp = false;
     $profile_link = best_link_url($item, $sp);
     if ($profile_link === 'mailbox') {
         $profile_link = '';
     }
     if ($sp) {
         $sparkle = ' sparkle';
     } else {
         $profile_link = zrl($profile_link);
     }
     $normalised = normalise_link(strlen($item['author-link']) ? $item['author-link'] : $item['url']);
     if ($normalised != 'mailbox' && x($a->contacts, $normalised)) {
         $profile_avatar = $a->contacts[$normalised]['thumb'];
     } else {
         $profile_avatar = strlen($item['author-avatar']) && $diff_author ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_data_value('thumb'));
     }
     $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
     call_hooks('render_location', $locate);
     $location = strlen($locate['html']) ? $locate['html'] : render_location_dummy($locate);
     $searchpath = $a->get_baseurl() . "/search?tag=";
     $tags = array();
     $hashtags = array();
     $mentions = array();
     /*foreach(explode(',',$item['tag']) as $tag){
     			$tag = trim($tag);
     			if ($tag!="") {
     				$t = bbcode($tag);
     				$tags[] = $t;
     				if($t[0] == '#')
     					$hashtags[] = $t;
     				elseif($t[0] == '@')
     					$mentions[] = $t;
     			}
     		}*/
     // process action responses - e.g. like/dislike/attend/agree/whatever
     $response_verbs = array('like');
     if (feature_enabled($conv->get_profile_owner(), 'dislike')) {
         $response_verbs[] = 'dislike';
     }
     if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
         $response_verbs[] = 'attendyes';
         $response_verbs[] = 'attendno';
         $response_verbs[] = 'attendmaybe';
         if ($conv->is_writable()) {
             $isevent = true;
             $attend = array(t('I will attend'), t('I will not attend'), t('I might attend'));
         }
     }
     $responses = get_responses($conv_responses, $response_verbs, $this, $item);
     foreach ($response_verbs as $value => $verbs) {
         $responses[$verbs][output] = x($conv_responses[$verbs], $item['uri']) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : '';
     }
     /*
      * We should avoid doing this all the time, but it depends on the conversation mode
      * And the conv mode may change when we change the conv, or it changes its mode
      * Maybe we should establish a way to be notified about conversation changes
      */
     $this->check_wall_to_wall();
     if ($this->is_wall_to_wall() && $this->get_owner_url() == $this->get_redirect_url()) {
         $osparkle = ' sparkle';
     }
     if ($this->is_toplevel()) {
         if ($conv->get_profile_owner() == local_user()) {
             $isstarred = $item['starred'] ? "starred" : "unstarred";
             $star = array('do' => t("add star"), 'undo' => t("remove star"), 'toggle' => t("toggle star status"), 'classdo' => $item['starred'] ? "hidden" : "", 'classundo' => $item['starred'] ? "" : "hidden", 'starred' => t('starred'));
             $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", intval($item['uid']), intval($item['id']));
             if (count($r)) {
                 $ignore = array('do' => t("ignore thread"), 'undo' => t("unignore thread"), 'toggle' => t("toggle ignore status"), 'classdo' => $r[0]['ignored'] ? "hidden" : "", 'classundo' => $r[0]['ignored'] ? "" : "hidden", 'ignored' => t('ignored'));
             }
             $tagger = '';
             if (feature_enabled($conv->get_profile_owner(), 'commtag')) {
                 $tagger = array('add' => t("add tag"), 'class' => "");
             }
         }
     } else {
         $indent = 'comment';
     }
     if ($conv->is_writable()) {
         $buttons = array('like' => array(t("I like this (toggle)"), t("like")), 'dislike' => feature_enabled($conv->get_profile_owner(), 'dislike') ? array(t("I don't like this (toggle)"), t("dislike")) : '');
         if ($shareable) {
             $buttons['share'] = array(t('Share this'), t('share'));
         }
     }
     $comment = $this->get_comment_box($indent);
     if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
         $shiny = 'shiny';
     }
     localize_item($item);
     if ($item["postopts"] and !get_config("system", "suppress_language")) {
         //$langdata = explode(";", $item["postopts"]);
         //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
         $langstr = "";
         if (substr($item["postopts"], 0, 5) == "lang=") {
             $postopts = substr($item["postopts"], 5);
             $languages = explode(":", $postopts);
             if (sizeof($languages) == 1) {
                 $languages = array();
                 $languages[] = $postopts;
             }
             foreach ($languages as $language) {
                 $langdata = explode(";", $language);
                 if ($langstr != "") {
                     $langstr .= ", ";
                 }
                 //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
                 $langstr .= round($langdata[1] * 100, 1) . "% " . $langdata[0];
             }
         }
     }
     $body = prepare_body($item, true);
     list($categories, $folders) = get_cats_and_terms($item);
     if ($a->theme['template_engine'] === 'internal') {
         $body_e = template_escape($body);
         $text_e = strip_tags(template_escape($body));
         $name_e = template_escape($profile_name);
         $title_e = template_escape($item['title']);
         $location_e = template_escape($location);
         $owner_name_e = template_escape($this->get_owner_name());
     } else {
         $body_e = $body;
         $text_e = strip_tags($body);
         $name_e = $profile_name;
         $title_e = $item['title'];
         $location_e = $location;
         $owner_name_e = $this->get_owner_name();
     }
     // Disable features that aren't available in several networks
     if ($item["item_network"] != NETWORK_DFRN and isset($buttons["dislike"])) {
         unset($buttons["dislike"], $isevent);
         $tagger = '';
     }
     if ($item["item_network"] == NETWORK_FEED and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     if ($item["item_network"] == NETWORK_MAIL and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     // Diaspora isn't able to do likes on comments - but red does
     if ($item["item_network"] == NETWORK_DIASPORA and $indent == 'comment' and !diaspora_is_redmatrix($item["owner-link"]) and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     // Diaspora doesn't has multithreaded comments
     if ($item["item_network"] == NETWORK_DIASPORA and $indent == 'comment') {
         unset($comment);
     }
     // Facebook can like comments - but it isn't programmed in the connector yet.
     if ($item["item_network"] == NETWORK_FACEBOOK and $indent == 'comment' and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     $tmp_item = array('template' => $this->get_template(), 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), 'tags' => $item['tags'], 'hashtags' => $item['hashtags'], 'mentions' => $item['mentions'], 'txt_cats' => t('Categories:'), 'txt_folders' => t('Filed under:'), 'has_cats' => count($categories) ? 'true' : '', 'has_folders' => count($folders) ? 'true' : '', 'categories' => $categories, 'folders' => $folders, 'body' => $body_e, 'text' => $text_e, 'id' => $this->get_id(), 'guid' => urlencode($item['guid']), 'isevent' => $isevent, 'attend' => $attend, 'linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['author-link']) ? $item['author-link'] : $item['url']), 'olinktitle' => sprintf(t('View %s\'s profile @ %s'), htmlentities($this->get_owner_name()), strlen($item['owner-link']) ? $item['owner-link'] : $item['url']), 'to' => t('to'), 'via' => t('via'), 'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $name_e, 'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title_e, 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'ago' => $item['app'] ? sprintf(t('%s from %s'), relative_date($item['created']), $item['app']) : relative_date($item['created']), 'app' => $item['app'], 'created' => relative_date($item['created']), 'lock' => $lock, 'location' => $location_e, 'indent' => $indent, 'shiny' => $shiny, 'owner_url' => $this->get_owner_url(), 'owner_photo' => proxy_url($this->get_owner_photo(), false, PROXY_SIZE_THUMB), 'owner_name' => htmlentities($owner_name_e), 'plink' => get_plink($item), 'edpost' => feature_enabled($conv->get_profile_owner(), 'edit_posts') ? $edpost : '', 'isstarred' => $isstarred, 'star' => feature_enabled($conv->get_profile_owner(), 'star_posts') ? $star : '', 'ignore' => feature_enabled($conv->get_profile_owner(), 'ignore_posts') ? $ignore : '', 'tagger' => $tagger, 'filer' => feature_enabled($conv->get_profile_owner(), 'filing') ? $filer : '', 'drop' => $drop, 'vote' => $buttons, 'like' => $responses['like']['output'], 'dislike' => $responses['dislike']['output'], 'responses' => $responses, 'switchcomment' => t('Comment'), 'comment' => $comment, 'previewing' => $conv->is_preview() ? ' preview ' : '', 'wait' => t('Please wait'), 'thread_level' => $thread_level, 'postopts' => $langstr, 'edited' => $edited, 'network' => $item["item_network"], 'network_name' => network_to_name($item['item_network'], $profile_link));
     $arr = array('item' => $item, 'output' => $tmp_item);
     call_hooks('display_item', $arr);
     $result = $arr['output'];
     $result['children'] = array();
     $children = $this->get_children();
     $nb_children = count($children);
     if ($nb_children > 0) {
         foreach ($children as $child) {
             $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1);
         }
         // Collapse
         if ($nb_children > 2 || $thread_level > 1) {
             $result['children'][0]['comment_firstcollapsed'] = true;
             $result['children'][0]['num_comments'] = sprintf(tt('%d comment', '%d comments', $total_children), $total_children);
             $result['children'][0]['hidden_comments_num'] = $total_children;
             $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
             $result['children'][0]['hide_text'] = t('show more');
             if ($thread_level > 1) {
                 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
             } else {
                 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
             }
         }
     }
     if ($this->is_toplevel()) {
         $result['total_comments_num'] = "{$total_children}";
         $result['total_comments_text'] = tt('comment', 'comments', $total_children);
     }
     $result['private'] = $item['private'];
     $result['toplevel'] = $this->is_toplevel() ? 'toplevel_item' : '';
     if ($this->is_threaded()) {
         $result['flatten'] = false;
         $result['threaded'] = true;
     } else {
         $result['flatten'] = true;
         $result['threaded'] = false;
     }
     return $result;
 }