当前位置: 首页>>代码示例>>PHP>>正文


PHP parse_xml_string函数代码示例

本文整理汇总了PHP中parse_xml_string函数的典型用法代码示例。如果您正苦于以下问题:PHP parse_xml_string函数的具体用法?PHP parse_xml_string怎么用?PHP parse_xml_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_xml_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: local_delivery


//.........这里部分代码省略.........
                    // Specifically, the recipient?
                    $is_a_remote_delete = false;
                    // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used?
                    $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`,\n\t\t\t\t\t\t`contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`\n\t\t\t\t\t\tINNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`\n\t\t\t\t\t\tWHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s')\n\t\t\t\t\t\tAND `item`.`uid` = %d\n\t\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t\tLIMIT 1", dbesc($parent_uri), dbesc($parent_uri), dbesc($parent_uri), intval($importer['importer_uid']));
                    if ($r && count($r)) {
                        $is_a_remote_delete = true;
                    }
                    // Does this have the characteristics of a community or private group comment?
                    // If it's a reply to a wall post on a community/prvgroup page it's a
                    // valid community comment. Also forum_mode makes it valid for sure.
                    // If neither, it's not.
                    if ($is_a_remote_delete && $community) {
                        if (!$r[0]['forum_mode'] && !$r[0]['wall']) {
                            $is_a_remote_delete = false;
                            logger('local_delivery: not a community delete');
                        }
                    }
                    if ($is_a_remote_delete) {
                        logger('local_delivery: received remote delete');
                    }
                }
                $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN contact on `item`.`contact-id` = `contact`.`id`\n\t\t\t\t\tWHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", dbesc($uri), intval($importer['importer_uid']), intval($importer['id']));
                if (count($r)) {
                    $item = $r[0];
                    if ($item['deleted']) {
                        continue;
                    }
                    logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
                    if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
                        logger("Deleting event " . $item['event-id'], LOGGER_DEBUG);
                        event_delete($item['event-id']);
                    }
                    if ($item['verb'] === ACTIVITY_TAG && $item['object-type'] === ACTIVITY_OBJ_TAGTERM) {
                        $xo = parse_xml_string($item['object'], false);
                        $xt = parse_xml_string($item['target'], false);
                        if ($xt->type === ACTIVITY_OBJ_NOTE) {
                            $i = q("select * from `item` where uri = '%s' and uid = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
                            if (count($i)) {
                                // For tags, the owner cannot remove the tag on the author's copy of the post.
                                $owner_remove = $item['contact-id'] == $i[0]['contact-id'] ? true : false;
                                $author_remove = $item['origin'] && $item['self'] ? true : false;
                                $author_copy = $item['origin'] ? true : false;
                                if ($owner_remove && $author_copy) {
                                    continue;
                                }
                                if ($author_remove || $owner_remove) {
                                    $tags = explode(',', $i[0]['tag']);
                                    $newtags = array();
                                    if (count($tags)) {
                                        foreach ($tags as $tag) {
                                            if (trim($tag) !== trim($xo->body)) {
                                                $newtags[] = trim($tag);
                                            }
                                        }
                                    }
                                    q("update item set tag = '%s' where id = %d", dbesc(implode(',', $newtags)), intval($i[0]['id']));
                                    create_tags_from_item($i[0]['id']);
                                }
                            }
                        }
                    }
                    if ($item['uri'] == $item['parent-uri']) {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',\n\t\t\t\t\t\t\t`body` = '', `title` = ''\n\t\t\t\t\t\t\tWHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($when), dbesc(datetime_convert()), dbesc($item['uri']), intval($importer['importer_uid']));
                        create_tags_from_itemuri($item['uri'], $importer['importer_uid']);
                        create_files_from_itemuri($item['uri'], $importer['importer_uid']);
                        update_thread_uri($item['uri'], $importer['importer_uid']);
开发者ID:EmilienB,项目名称:friendica,代码行数:67,代码来源:items.php

示例2: zot_unencapsulate

function zot_unencapsulate($data, $prvkey)
{
    $ret = array();
    $c = array();
    $x = parse_xml_string($data);
    $c = array('key' => $x->key, 'iv' => $x->iv, 'data' => $x->data);
    openssl_private_decrypt(base64url_decode($x->sender), $s, $prvkey);
    $ret['sender'] = $s;
    $ret['data'] = aes_unencapsulate($x, $prvkey);
    return $ret;
}
开发者ID:nextgensh,项目名称:friendica,代码行数:11,代码来源:crypto.php

示例3: notifications_content

function notifications_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('notifications');
    $json = $a->argc > 1 && $a->argv[$a->argc - 1] === 'json' ? true : false;
    $o = '';
    $tabs = array(array('label' => t('System'), 'url' => $a->get_baseurl(true) . '/notifications/system', 'sel' => $a->argv[1] == 'system' ? 'active' : ''), array('label' => t('Network'), 'url' => $a->get_baseurl(true) . '/notifications/network', 'sel' => $a->argv[1] == 'network' ? 'active' : ''), array('label' => t('Personal'), 'url' => $a->get_baseurl(true) . '/notifications/personal', 'sel' => $a->argv[1] == 'personal' ? 'active' : ''), array('label' => t('Home'), 'url' => $a->get_baseurl(true) . '/notifications/home', 'sel' => $a->argv[1] == 'home' ? 'active' : ''), array('label' => t('Introductions'), 'url' => $a->get_baseurl(true) . '/notifications/intros', 'sel' => $a->argv[1] == 'intros' ? 'active' : ''));
    $o = "";
    if ($a->argc > 1 && $a->argv[1] == 'intros' || $a->argc == 1) {
        nav_set_selected('introductions');
        if ($a->argc > 2 && $a->argv[2] == 'all') {
            $sql_extra = '';
        } else {
            $sql_extra = " AND `ignore` = 0 ";
        }
        $notif_tpl = get_markup_template('notifications.tpl');
        $notif_content .= '<a href="' . (strlen($sql_extra) ? 'notifications/intros/all' : 'notifications/intros') . '" id="notifications-show-hide-link" >' . (strlen($sql_extra) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
        $r = q("SELECT COUNT(*)\tAS `total` FROM `intro`\n\t\t\tWHERE `intro`.`uid` = %d {$sql_extra} AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']));
        if ($r && count($r)) {
            $a->set_pager_total($r[0]['total']);
            $a->set_pager_itemspage(20);
        }
        $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest`\n\t\t\tFROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d {$sql_extra} AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']));
        if ($r !== false && count($r)) {
            $sugg = get_markup_template('suggestions.tpl');
            $tpl = get_markup_template("intros.tpl");
            foreach ($r as $rr) {
                if ($rr['fid']) {
                    $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . ($a->path ? '/' . $a->path : ''));
                    $notif_content .= replace_macros($sugg, array('$str_notifytype' => t('Notification type: '), '$notify_type' => t('Friend Suggestion'), '$intro_id' => $rr['intro_id'], '$madeby' => sprintf(t('suggested by %s'), $rr['name']), '$contact_id' => $rr['contact-id'], '$photo' => x($rr, 'fphoto') ? $rr['fphoto'] : "images/person-175.jpg", '$fullname' => $rr['fname'], '$url' => zrl($rr['furl']), '$hidden' => array('hidden', t('Hide this contact from others'), $rr['hidden'] == 1, ''), '$activity' => array('activity', t('Post a new friend activity'), intval(get_pconfig(local_user(), 'system', 'post_newfriend')) ? '1' : 0, t('if applicable')), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $rr['note'], '$request' => $rr['frequest'] . '?addr=' . $return_addr, '$ignore' => t('Ignore'), '$discard' => t('Discard')));
                    continue;
                }
                $friend_selected = $rr['network'] !== NETWORK_OSTATUS ? ' checked="checked" ' : ' disabled ';
                $fan_selected = $rr['network'] === NETWORK_OSTATUS ? ' checked="checked" disabled ' : '';
                $dfrn_tpl = get_markup_template('netfriend.tpl');
                $knowyou = '';
                $dfrn_text = '';
                if ($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
                    if ($rr['network'] === NETWORK_DFRN) {
                        $knowyou = t('Claims to be known to you: ') . ($rr['knowyou'] ? t('yes') : t('no'));
                        $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: ');
                    } else {
                        $knowyou = '';
                        $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: ');
                    }
                    $dfrn_text = replace_macros($dfrn_tpl, array('$intro_id' => $rr['intro_id'], '$friend_selected' => $friend_selected, '$fan_selected' => $fan_selected, '$approve_as' => $helptext, '$as_friend' => t('Friend'), '$as_fan' => $rr['network'] == NETWORK_DIASPORA ? t('Sharer') : t('Fan/Admirer')));
                }
                $notif_content .= replace_macros($tpl, array('$str_notifytype' => t('Notification type: '), '$notify_type' => $rr['network'] !== NETWORK_OSTATUS ? t('Friend/Connect Request') : t('New Follower'), '$dfrn_text' => $dfrn_text, '$dfrn_id' => $rr['issued-id'], '$uid' => $_SESSION['uid'], '$intro_id' => $rr['intro_id'], '$contact_id' => $rr['contact-id'], '$photo' => x($rr, 'photo') ? $rr['photo'] : "images/person-175.jpg", '$fullname' => $rr['name'], '$hidden' => array('hidden', t('Hide this contact from others'), $rr['hidden'] == 1, ''), '$activity' => array('activity', t('Post a new friend activity'), intval(get_pconfig(local_user(), 'system', 'post_newfriend')) ? '1' : 0, t('if applicable')), '$url' => zrl($rr['url']), '$knowyou' => $knowyou, '$approve' => t('Approve'), '$note' => $rr['note'], '$ignore' => t('Ignore'), '$discard' => t('Discard')));
            }
        } else {
            info(t('No introductions.') . EOL);
        }
        $o .= replace_macros($notif_tpl, array('$notif_header' => t('Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
        $o .= paginate($a);
        return $o;
    } else {
        if ($a->argc > 1 && $a->argv[1] == 'network') {
            $notif_tpl = get_markup_template('notifications.tpl');
            $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`,\n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC", intval(local_user()));
            $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
            $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
            $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
            $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
            $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
            $notif_content = '';
            if ($r) {
                foreach ($r as $it) {
                    switch ($it['verb']) {
                        case ACTIVITY_LIKE:
                            $notif_content .= replace_macros($tpl_item_likes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                            break;
                        case ACTIVITY_DISLIKE:
                            $notif_content .= replace_macros($tpl_item_dislikes, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']), '$item_when' => relative_date($it['created'])));
                            break;
                        case ACTIVITY_FRIEND:
                            $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
                            $obj = parse_xml_string($xmlhead . $it['object']);
                            $it['fname'] = $obj->title;
                            $notif_content .= replace_macros($tpl_item_friends, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']), '$item_when' => relative_date($it['created'])));
                            break;
                        default:
                            $item_text = $it['id'] == $it['parent'] ? sprintf(t("%s created a new post"), $it['author-name']) : sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
                            $tpl = $it['id'] == $it['parent'] ? $tpl_item_posts : $tpl_item_comments;
                            $notif_content .= replace_macros($tpl, array('$item_link' => $a->get_baseurl(true) . '/display/' . $it['pguid'], '$item_image' => $it['author-avatar'], '$item_text' => $item_text, '$item_when' => relative_date($it['created'])));
                    }
                }
            } else {
                $notif_content = t('No more network notifications.');
            }
            $o .= replace_macros($notif_tpl, array('$notif_header' => t('Network Notifications'), '$tabs' => $tabs, '$notif_content' => $notif_content));
        } else {
            if ($a->argc > 1 && $a->argv[1] == 'system') {
                $notif_tpl = get_markup_template('notifications.tpl');
                $not_tpl = get_markup_template('notify.tpl');
                require_once 'include/bbcode.php';
                $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc", intval(local_user()));
                if (count($r) > 0) {
//.........这里部分代码省略.........
开发者ID:rahmiyildiz,项目名称:friendica,代码行数:101,代码来源:notifications.php

示例4: dfrn_poll_content

function dfrn_poll_content(&$a)
{
    $dfrn_id = x($_GET, 'dfrn_id') ? $_GET['dfrn_id'] : '';
    $type = x($_GET, 'type') ? $_GET['type'] : 'data';
    $last_update = x($_GET, 'last_update') ? $_GET['last_update'] : '';
    $destination_url = x($_GET, 'destination_url') ? $_GET['destination_url'] : '';
    $sec = x($_GET, 'sec') ? $_GET['sec'] : '';
    $dfrn_version = x($_GET, 'dfrn_version') ? (double) $_GET['dfrn_version'] : 2.0;
    $perm = x($_GET, 'perm') ? $_GET['perm'] : 'r';
    $direction = -1;
    if (strpos($dfrn_id, ':') == 1) {
        $direction = intval(substr($dfrn_id, 0, 1));
        $dfrn_id = substr($dfrn_id, 2);
    }
    if ($dfrn_id != '') {
        // initial communication from external contact
        $hash = random_string();
        $status = 0;
        $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time()));
        if ($type !== 'profile') {
            $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` )\n\t\t\t\tVALUES( '%s', '%s', '%s', '%s', '%s' ) ", dbesc($hash), dbesc($dfrn_id), intval(time() + 60), dbesc($type), dbesc($last_update));
        }
        $sql_extra = '';
        switch ($direction) {
            case -1:
                if ($type === 'profile') {
                    $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id));
                } else {
                    $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id));
                }
                $my_id = $dfrn_id;
                break;
            case 0:
                $sql_extra = sprintf(" AND `issued-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
                $my_id = '1:' . $dfrn_id;
                break;
            case 1:
                $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
                $my_id = '0:' . $dfrn_id;
                break;
            default:
                goaway(z_root());
                break;
                // NOTREACHED
        }
        $r = q("SELECT `contact`.*, `user`.`username`, `user`.`nickname` \n\t\t\tFROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`\n\t\t\tWHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0 \n\t\t\tAND `user`.`nickname` = '%s' {$sql_extra} LIMIT 1", dbesc($a->argv[1]));
        if (count($r)) {
            $challenge = '';
            $encrypted_id = '';
            $id_str = $my_id . '.' . mt_rand(1000, 9999);
            if ($r[0]['duplex'] && strlen($r[0]['pubkey'])) {
                openssl_public_encrypt($hash, $challenge, $r[0]['pubkey']);
                openssl_public_encrypt($id_str, $encrypted_id, $r[0]['pubkey']);
            } else {
                openssl_private_encrypt($hash, $challenge, $r[0]['prvkey']);
                openssl_private_encrypt($id_str, $encrypted_id, $r[0]['prvkey']);
            }
            $challenge = bin2hex($challenge);
            $encrypted_id = bin2hex($encrypted_id);
        } else {
            $status = 1;
            $challenge = '';
            $encrypted_id = '';
        }
        if ($type === 'profile' && strlen($sec)) {
            // URL reply
            if ($dfrn_version < 2.2) {
                $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&challenge=' . $challenge . '&sec=' . $sec);
            } else {
                $s = post_url($r[0]['poll'], array('dfrn_id' => $encrypted_id, 'type' => 'profile-check', 'dfrn_version' => DFRN_PROTOCOL_VERSION, 'challenge' => $challenge, 'sec' => $sec));
            }
            $profile = $r[0]['nickname'];
            switch ($destination_url) {
                case 'profile':
                    $dest = $a->get_baseurl() . '/profile/' . $profile . '?tab=profile';
                    break;
                case 'photos':
                    $dest = $a->get_baseurl() . '/photos/' . $profile;
                    break;
                case 'status':
                case '':
                    $dest = $a->get_baseurl() . '/profile/' . $profile;
                    break;
                default:
                    $dest = $destination_url;
                    break;
            }
            logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA);
            if (strlen($s) && strstr($s, '<?xml')) {
                $xml = parse_xml_string($s);
                logger('dfrn_poll: profile: parsed xml: ' . print_r($xml, true), LOGGER_DATA);
                logger('dfrn_poll: secure profile: challenge: ' . $xml->challenge . ' expecting ' . $hash);
                logger('dfrn_poll: secure profile: sec: ' . $xml->sec . ' expecting ' . $sec);
                if ((int) $xml->status == 0 && $xml->challenge == $hash && $xml->sec == $sec) {
                    $_SESSION['authenticated'] = 1;
                    $_SESSION['visitor_id'] = $r[0]['id'];
                    $_SESSION['visitor_home'] = $r[0]['url'];
                    $_SESSION['visitor_visiting'] = $r[0]['uid'];
                    info(sprintf(t('%s welcomes %s'), $r[0]['username'], $r[0]['name']) . EOL);
                    // Visitors get 1 day session.
//.........这里部分代码省略.........
开发者ID:nphyx,项目名称:friendica,代码行数:101,代码来源:dfrn_poll.php

示例5: diaspora_reshare

function diaspora_reshare($importer, $xml, $msg)
{
    logger('diaspora_reshare: init: ' . print_r($xml, true));
    $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) {
        return;
    }
    if (!diaspora_post_allow($importer, $contact)) {
        logger('diaspora_reshare: Ignoring this author: ' . $diaspora_handle . ' ' . print_r($xml, true));
        return 202;
    }
    $message_id = $diaspora_handle . ':' . $guid;
    $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", intval($importer['uid']), dbesc($message_id), dbesc($guid));
    if (count($r)) {
        logger('diaspora_reshare: message exists: ' . $guid);
        return;
    }
    $orig_author = notags(unxmlify($xml->root_diaspora_id));
    $orig_guid = notags(unxmlify($xml->root_guid));
    $source_url = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1) . '/p/' . $orig_guid . '.xml';
    $orig_url = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1) . '/posts/' . $orig_guid;
    $x = fetch_url($source_url);
    if (!$x) {
        $x = fetch_url(str_replace('https://', 'http://', $source_url));
    }
    if (!$x) {
        logger('diaspora_reshare: unable to fetch source url ' . $source_url);
        return;
    }
    logger('diaspora_reshare: source: ' . $x);
    $x = str_replace(array('<activity_streams-photo>', '</activity_streams-photo>'), array('<asphoto>', '</asphoto>'), $x);
    $source_xml = parse_xml_string($x, false);
    if (strlen($source_xml->post->asphoto->objectId) && $source_xml->post->asphoto->objectId != 0 && $source_xml->post->asphoto->image_url) {
        $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n";
        $body = scale_external_images($body, false);
    } elseif ($source_xml->post->asphoto->image_url) {
        $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n";
        $body = scale_external_images($body);
    } elseif ($source_xml->post->status_message) {
        $body = diaspora2bb($source_xml->post->status_message->raw_message);
        // Checking for embedded pictures
        if ($source_xml->post->status_message->photo->remote_photo_path and $source_xml->post->status_message->photo->remote_photo_name) {
            $remote_photo_path = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_path));
            $remote_photo_name = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_name));
            $body = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n" . $body;
            logger('diaspora_reshare: embedded picture link found: ' . $body, LOGGER_DEBUG);
        }
        $body = scale_external_images($body);
        // Add OEmbed and other information to the body
        $body = add_page_info_to_body($body, false, true);
    } else {
        // Maybe it is a reshare of a photo that will be delivered at a later time (testing)
        logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml, true));
        $body = "";
        //return;
    }
    //if(! $body) {
    //	logger('diaspora_reshare: empty body: source= ' . $x);
    //	return;
    //}
    $person = find_diaspora_person_by_handle($orig_author);
    /*if(is_array($person) && x($person,'name') && x($person,'url'))
    		$details = '[url=' . $person['url'] . ']' . $person['name'] . '[/url]';
    	else
    		$details = $orig_author;
    
    	$prefix = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8') . $details . "\n";*/
    // allocate a guid on our system - we aren't fixing any collisions.
    // we're ignoring them
    $g = q("select * from guid where guid = '%s' limit 1", dbesc($guid));
    if (!count($g)) {
        q("insert into guid ( guid ) values ( '%s' )", dbesc($guid));
    }
    $created = unxmlify($xml->created_at);
    $private = unxmlify($xml->public) == 'false' ? 1 : 0;
    $datarray = array();
    $str_tags = '';
    $tags = get_tags($body);
    if (count($tags)) {
        foreach ($tags as $tag) {
            if (strpos($tag, '#') === 0) {
                if (strpos($tag, '[url=')) {
                    continue;
                }
                // don't link tags that are already embedded in links
                if (preg_match('/\\[(.*?)' . preg_quote($tag, '/') . '(.*?)\\]/', $body)) {
                    continue;
                }
                if (preg_match('/\\[(.*?)\\]\\((.*?)' . preg_quote($tag, '/') . '(.*?)\\)/', $body)) {
                    continue;
                }
                $basetag = str_replace('_', ' ', substr($tag, 1));
                $body = str_replace($tag, '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]', $body);
//.........这里部分代码省略.........
开发者ID:jzacman,项目名称:friendica,代码行数:101,代码来源:diaspora.php

示例6: localize_item

/**
 * Render actions localized
 */
function localize_item(&$item)
{
    $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
    if ($item['verb'] === ACTIVITY_LIKE || $item['verb'] === ACTIVITY_DISLIKE) {
        $r = q("SELECT * from `item`,`contact` WHERE \n\t\t\t\t`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", dbesc($item['parent-uri']));
        if (count($r) == 0) {
            return;
        }
        $obj = $r[0];
        $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
        $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
        switch ($obj['verb']) {
            case ACTIVITY_POST:
                switch ($obj['object-type']) {
                    case ACTIVITY_OBJ_EVENT:
                        $post_type = t('event');
                        break;
                    default:
                        $post_type = t('status');
                }
                break;
            default:
                if ($obj['resource-id']) {
                    $post_type = t('photo');
                    $m = array();
                    preg_match("/\\[url=([^]]*)\\]/", $obj['body'], $m);
                    $rr['plink'] = $m[1];
                } else {
                    $post_type = t('status');
                }
        }
        $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
        switch ($item['verb']) {
            case ACTIVITY_LIKE:
                $bodyverb = t('%1$s likes %2$s\'s %3$s');
                break;
            case ACTIVITY_DISLIKE:
                $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
                break;
        }
        $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
    }
    if ($item['verb'] === ACTIVITY_FRIEND) {
        if ($item['object-type'] == "" || $item['object-type'] !== ACTIVITY_OBJ_PERSON) {
            return;
        }
        $Aname = $item['author-name'];
        $Alink = $item['author-link'];
        $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
        $obj = parse_xml_string($xmlhead . $item['object']);
        $links = parse_xml_string($xmlhead . "<links>" . unxmlify($obj->link) . "</links>");
        $Bname = $obj->title;
        $Blink = "";
        $Bphoto = "";
        foreach ($links->link as $l) {
            $atts = $l->attributes();
            switch ($atts['rel']) {
                case "alternate":
                    $Blink = $atts['href'];
                case "photo":
                    $Bphoto = $atts['href'];
            }
        }
        $A = '[url=' . $Alink . ']' . $Aname . '[/url]';
        $B = '[url=' . $Blink . ']' . $Bname . '[/url]';
        if ($Bphoto != "") {
            $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
        }
        $item['body'] = sprintf(t('%1$s is now friends with %2$s'), $A, $B) . "\n\n\n" . $Bphoto;
    }
    if ($item['verb'] === ACTIVITY_TAG) {
        $r = q("SELECT * from `item`,`contact` WHERE \n\t\t`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", dbesc($item['parent-uri']));
        if (count($r) == 0) {
            return;
        }
        $obj = $r[0];
        $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
        $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
        switch ($obj['verb']) {
            case ACTIVITY_POST:
                switch ($obj['object-type']) {
                    case ACTIVITY_OBJ_EVENT:
                        $post_type = t('event');
                        break;
                    default:
                        $post_type = t('status');
                }
                break;
            default:
                if ($obj['resource-id']) {
                    $post_type = t('photo');
                    $m = array();
                    preg_match("/\\[url=([^]]*)\\]/", $obj['body'], $m);
                    $rr['plink'] = $m[1];
                } else {
                    $post_type = t('status');
                }
//.........这里部分代码省略.........
开发者ID:nphyx,项目名称:friendica,代码行数:101,代码来源:conversation.php

示例7: localize_item

/**
 * Render actions localized
 */
function localize_item(&$item)
{
    $Text = $item['body'];
    $saved_image = '';
    $img_start = strpos($Text, '[img]data:');
    $img_end = strpos($Text, '[/img]');
    if ($img_start !== false && $img_end !== false && $img_end > $img_start) {
        $start_fragment = substr($Text, 0, $img_start);
        $img_start += strlen('[img]');
        $saved_image = substr($Text, $img_start, $img_end - $img_start);
        $end_fragment = substr($Text, $img_end + strlen('[/img]'));
        $Text = $start_fragment . '[!#saved_image#!]' . $end_fragment;
        $search = '/\\[url\\=(.*?)\\]\\[!#saved_image#!\\]\\[\\/url\\]' . '/is';
        $replace = '[url=' . z_path() . '/redir/' . $item['contact-id'] . '?f=1&url=' . '$1' . '][!#saved_image#!][/url]';
        $Text = preg_replace($search, $replace, $Text);
        if (strlen($saved_image)) {
            $item['body'] = str_replace('[!#saved_image#!]', '[img]' . $saved_image . '[/img]', $Text);
        }
    }
    $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
    if ($item['verb'] === ACTIVITY_LIKE || $item['verb'] === ACTIVITY_DISLIKE) {
        $r = q("SELECT * from `item`,`contact` WHERE \n\t\t\t\t`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", dbesc($item['parent-uri']));
        if (count($r) == 0) {
            return;
        }
        $obj = $r[0];
        $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
        $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
        switch ($obj['verb']) {
            case ACTIVITY_POST:
                switch ($obj['object-type']) {
                    case ACTIVITY_OBJ_EVENT:
                        $post_type = t('event');
                        break;
                    default:
                        $post_type = t('status');
                }
                break;
            default:
                if ($obj['resource-id']) {
                    $post_type = t('photo');
                    $m = array();
                    preg_match("/\\[url=([^]]*)\\]/", $obj['body'], $m);
                    $rr['plink'] = $m[1];
                } else {
                    $post_type = t('status');
                }
        }
        $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
        switch ($item['verb']) {
            case ACTIVITY_LIKE:
                $bodyverb = t('%1$s likes %2$s\'s %3$s');
                break;
            case ACTIVITY_DISLIKE:
                $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
                break;
        }
        $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
    }
    if ($item['verb'] === ACTIVITY_FRIEND) {
        if ($item['object-type'] == "" || $item['object-type'] !== ACTIVITY_OBJ_PERSON) {
            return;
        }
        $Aname = $item['author-name'];
        $Alink = $item['author-link'];
        $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
        $obj = parse_xml_string($xmlhead . $item['object']);
        $links = parse_xml_string($xmlhead . "<links>" . unxmlify($obj->link) . "</links>");
        $Bname = $obj->title;
        $Blink = "";
        $Bphoto = "";
        foreach ($links->link as $l) {
            $atts = $l->attributes();
            switch ($atts['rel']) {
                case "alternate":
                    $Blink = $atts['href'];
                case "photo":
                    $Bphoto = $atts['href'];
            }
        }
        $A = '[url=' . zrl($Alink) . ']' . $Aname . '[/url]';
        $B = '[url=' . zrl($Blink) . ']' . $Bname . '[/url]';
        if ($Bphoto != "") {
            $Bphoto = '[url=' . zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
        }
        $item['body'] = sprintf(t('%1$s is now friends with %2$s'), $A, $B) . "\n\n\n" . $Bphoto;
    }
    if ($item['verb'] === ACTIVITY_TAG) {
        $r = q("SELECT * from `item`,`contact` WHERE \n\t\t`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';", dbesc($item['parent-uri']));
        if (count($r) == 0) {
            return;
        }
        $obj = $r[0];
        $author = '[url=' . zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
        $objauthor = '[url=' . zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
        switch ($obj['verb']) {
            case ACTIVITY_POST:
//.........这里部分代码省略.........
开发者ID:robhell,项目名称:friendica,代码行数:101,代码来源:conversation.php

示例8: poller_run


//.........这里部分代码省略.........
                continue;
            }
            $importer = $r[0];
            logger("poller: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
            $last_update = $contact['last-update'] === '0000-00-00 00:00:00' ? datetime_convert('UTC', 'UTC', 'now - 30 days', ATOM_TIME) : datetime_convert('UTC', 'UTC', $contact['last-update'], ATOM_TIME);
            if ($contact['network'] === NETWORK_DFRN) {
                $idtosend = $orig_id = $contact['dfrn-id'] ? $contact['dfrn-id'] : $contact['issued-id'];
                if (intval($contact['duplex']) && $contact['dfrn-id']) {
                    $idtosend = '0:' . $orig_id;
                }
                if (intval($contact['duplex']) && $contact['issued-id']) {
                    $idtosend = '1:' . $orig_id;
                }
                // they have permission to write to us. We already filtered this in the contact query.
                $perm = 'rw';
                $url = $contact['poll'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=data&last_update=' . $last_update . '&perm=' . $perm;
                $handshake_xml = fetch_url($url);
                logger('poller: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA);
                if (!$handshake_xml) {
                    logger("poller: {$url} appears to be dead - marking for death ");
                    // dead connection - might be a transient event, or this might
                    // mean the software was uninstalled or the domain expired.
                    // Will keep trying for one month.
                    mark_for_death($contact);
                    // set the last-update so we don't keep polling
                    $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id']));
                    continue;
                }
                if (!strstr($handshake_xml, '<?xml')) {
                    logger('poller: response from ' . $url . ' did not contain XML.');
                    $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id']));
                    continue;
                }
                $res = parse_xml_string($handshake_xml);
                if (intval($res->status) == 1) {
                    logger("poller: {$url} replied status 1 - marking for death ");
                    // we may not be friends anymore. Will keep trying for one month.
                    // set the last-update so we don't keep polling
                    $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($contact['id']));
                    mark_for_death($contact);
                } else {
                    if ($contact['term-date'] != '0000-00-00 00:00:00') {
                        logger("poller: {$url} back from the dead - removing mark for death");
                        unmark_for_death($contact);
                    }
                }
                if (intval($res->status) != 0 || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
                    continue;
                }
                if ((double) $res->dfrn_version > 2.21 && $contact['poco'] == '') {
                    q("update contact set poco = '%s' where id = %d limit 1", dbesc(str_replace('/profile/', '/poco/', $contact['url'])), intval($contact['id']));
                }
                $postvars = array();
                $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
                $challenge = hex2bin((string) $res->challenge);
                $final_dfrn_id = '';
                if ($contact['duplex'] && strlen($contact['prvkey'])) {
                    openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
                    openssl_private_decrypt($challenge, $postvars['challenge'], $contact['prvkey']);
                } else {
                    openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
                    openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']);
                }
                $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
                if (strpos($final_dfrn_id, ':') == 1) {
                    $final_dfrn_id = substr($final_dfrn_id, 2);
开发者ID:nextgensh,项目名称:friendica,代码行数:67,代码来源:poller.php

示例9: diaspora_decode

/**
 *
 * diaspora_decode($importer,$xml,$format)
 *   array $importer -> from user table
 *   string $xml -> urldecoded Diaspora salmon
 *   string $format 'legacy', 'salmon', or 'json' 
 *
 * Returns array
 * 'message' -> decoded Diaspora XML message
 * 'author' -> author diaspora handle
 * 'key' -> author public key (converted to pkcs#8)
 *
 * Author and key are used elsewhere to save a lookup for verifying replies and likes
 */
function diaspora_decode($importer, $xml, $format)
{
    $public = false;
    if ($format === 'json') {
        $json = json_decode($xml, true);
        if ($json['aes_key']) {
            $key_bundle = '';
            $result = openssl_private_decrypt(base64_decode($json['aes_key']), $key_bundle, $importer['channel_prvkey']);
            if (!$result) {
                logger('decrypting key_bundle for ' . $importer['channel_address'] . ' failed: ' . $json['aes_key'], LOGGER_NORMAL, LOG_ERR);
                http_status_exit(400);
            }
            $jkey = json_decode($key_bundle, true);
            $xml = AES256CBC_decrypt(base64_decode($json['encrypted_magic_envelope']), base64_decode($jkey['key']), base64_decode($jkey['iv']));
            if (!$xml) {
                logger('decrypting magic_envelope for ' . $importer['channel_address'] . ' failed: ' . $json['aes_key'], LOGGER_NORMAL, LOG_ERR);
                http_status_exit(400);
            }
        }
    }
    $basedom = parse_xml_string($xml);
    if ($format !== 'legacy') {
        $children = $basedom->children('http://salmon-protocol.org/ns/magic-env');
        $public = true;
        $author_link = str_replace('acct:', '', base64url_decode($children->key_id));
        /**
        			SimpleXMLElement Object
        			(
        			    [encoding] => base64url
        			    [alg] => RSA-SHA256
        			    [data] => ((base64url-encoded payload message))
        			    [sig] => ((the RSA-SHA256 signature of the above data))
        			    [key_id] => ((base64url-encoded Alice's diaspora ID))
        			)
        		**/
    } else {
        $children = $basedom->children('https://joindiaspora.com/protocol');
        if ($children->header) {
            $public = true;
            $author_link = str_replace('acct:', '', $children->header->author_id);
        } else {
            $encrypted_header = json_decode(base64_decode($children->encrypted_header));
            $encrypted_aes_key_bundle = base64_decode($encrypted_header->aes_key);
            $ciphertext = base64_decode($encrypted_header->ciphertext);
            $outer_key_bundle = '';
            openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $importer['channel_prvkey']);
            $j_outer_key_bundle = json_decode($outer_key_bundle);
            $outer_iv = base64_decode($j_outer_key_bundle->iv);
            $outer_key = base64_decode($j_outer_key_bundle->key);
            $decrypted = AES256CBC_decrypt($ciphertext, $outer_key, $outer_iv);
            /**
             * $decrypted now contains something like
             *
             *  <decrypted_header>
             *	 <iv>8e+G2+ET8l5BPuW0sVTnQw==</iv>
             *	 <aes_key>UvSMb4puPeB14STkcDWq+4QE302Edu15oaprAQSkLKU=</aes_key>
             ***** OBSOLETE
             *	 <author>
             *	   <name>Ryan Hughes</name>
             *	   <uri>acct:galaxor@diaspora.pirateship.org</uri>
             *	 </author>
             ***** CURRENT/LEGACY
             *	 <author_id>galaxor@diaspora.pirateship.org</author_id>
             ***** END DIFFS
             *  </decrypted_header>
             */
            logger('decrypted: ' . $decrypted, LOGGER_DATA);
            $idom = parse_xml_string($decrypted, false);
            $inner_iv = base64_decode($idom->iv);
            $inner_aes_key = base64_decode($idom->aes_key);
            $author_link = str_replace('acct:', '', $idom->author_id);
        }
    }
    $dom = $basedom->children(NAMESPACE_SALMON_ME);
    // figure out where in the DOM tree our data is hiding
    if ($dom->provenance->data) {
        $base = $dom->provenance;
    } elseif ($dom->env->data) {
        $base = $dom->env;
    } elseif ($dom->data) {
        $base = $dom;
    }
    if (!$base) {
        logger('mod-diaspora: unable to locate salmon data in xml ', LOGGER_NORMAL, LOG_ERR);
        http_status_exit(400);
    }
//.........这里部分代码省略.........
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:101,代码来源:inbound.php

示例10: ping_init

function ping_init(&$a)
{
    header("Content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\t\t<result>";
    $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
    if (local_user()) {
        // Different login session than the page that is calling us.
        if (intval($_GET['uid']) && intval($_GET['uid']) != local_user()) {
            echo '<invalid>1</invalid></result>';
            killme();
        }
        $notifs = ping_get_notifications(local_user());
        $sysnotify = 0;
        // we will update this in a moment
        $tags = array();
        $comments = array();
        $likes = array();
        $dislikes = array();
        $friends = array();
        $posts = array();
        $home = 0;
        $network = 0;
        $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,\n\t\t\t\t`item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,\n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`\n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `pitem`.`parent` != 0\n\t\t\t\tORDER BY `item`.`created` DESC", intval(local_user()));
        if (count($r)) {
            $arr = array('items' => $r);
            call_hooks('network_ping', $arr);
            foreach ($r as $it) {
                if ($it['wall']) {
                    $home++;
                } else {
                    $network++;
                }
                switch ($it['verb']) {
                    case ACTIVITY_TAG:
                        $obj = parse_xml_string($xmlhead . $it['object']);
                        $it['tname'] = $obj->content;
                        $tags[] = $it;
                        break;
                    case ACTIVITY_LIKE:
                        $likes[] = $it;
                        break;
                    case ACTIVITY_DISLIKE:
                        $dislikes[] = $it;
                        break;
                    case ACTIVITY_FRIEND:
                        $obj = parse_xml_string($xmlhead . $it['object']);
                        $it['fname'] = $obj->title;
                        $friends[] = $it;
                        break;
                    default:
                        if ($it['parent'] != $it['id']) {
                            $comments[] = $it;
                        } else {
                            if (!$it['wall']) {
                                $posts[] = $it;
                            }
                        }
                }
            }
        }
        $intros1 = q("SELECT  `intro`.`id`, `intro`.`datetime`,\n\t\t\t`fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo`\n\t\t\tFROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0", intval(local_user()));
        $intros2 = q("SELECT `intro`.`id`, `intro`.`datetime`,\n\t\t\t`contact`.`name`, `contact`.`url`, `contact`.`photo`\n\t\t\tFROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d  AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0", intval(local_user()));
        $intro = count($intros1) + count($intros2);
        $intros = $intros1 + $intros2;
        $myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
        $mails = q("SELECT * FROM `mail`\n\t\t\tWHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", intval(local_user()), dbesc($myurl));
        $mail = count($mails);
        if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()) {
            $regs = q("SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created`, COUNT(*) as `total` FROM `contact` RIGHT JOIN `register` ON `register`.`uid`=`contact`.`uid` WHERE `contact`.`self`=1");
            if ($regs) {
                $register = $regs[0]['total'];
            }
        } else {
            $register = "0";
        }
        $all_events = 0;
        $all_events_today = 0;
        $events = 0;
        $events_today = 0;
        $birthdays = 0;
        $birthdays_today = 0;
        $ev = q("SELECT count(`event`.`id`) as total, type, start, adjust FROM `event`\n\t\t\tWHERE `event`.`uid` = %d AND `start` < '%s' AND `finish` > '%s' and `ignore` = 0\n\t\t\tORDER BY `start` ASC ", intval(local_user()), dbesc(datetime_convert('UTC', 'UTC', 'now + 7 days')), dbesc(datetime_convert('UTC', 'UTC', 'now')));
        if ($ev && count($ev)) {
            $all_events = intval($ev[0]['total']);
            if ($all_events) {
                $str_now = datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d');
                foreach ($ev as $x) {
                    $bd = false;
                    if ($x['type'] === 'birthday') {
                        $birthdays++;
                        $bd = true;
                    } else {
                        $events++;
                    }
                    if (datetime_convert('UTC', intval($x['adjust']) ? $a->timezone : 'UTC', $x['start'], 'Y-m-d') === $str_now) {
                        $all_events_today++;
                        if ($bd) {
                            $birthdays_today++;
                        } else {
                            $events_today++;
//.........这里部分代码省略.........
开发者ID:ZerGabriel,项目名称:friendica,代码行数:101,代码来源:ping.php

示例11: local_delivery


//.........这里部分代码省略.........
    $rawtags = $feed->get_feed_tags(NAMESPACE_DFRN, 'community');
    if ($rawtags) {
        $community_page = intval($rawtags[0]['data']);
    }
    if (intval($importer['forum']) != $community_page) {
        q("update contact set forum = %d where id = %d limit 1", intval($community_page), intval($importer['id']));
        $importer['forum'] = (string) $community_page;
    }
    logger('local_delivery: feed item count = ' . $feed->get_item_quantity());
    // process any deleted entries
    $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
    if (is_array($del_entries) && count($del_entries)) {
        foreach ($del_entries as $dentry) {
            $deleted = false;
            if (isset($dentry['attribs']['']['ref'])) {
                $uri = $dentry['attribs']['']['ref'];
                $deleted = true;
                if (isset($dentry['attribs']['']['when'])) {
                    $when = $dentry['attribs']['']['when'];
                    $when = datetime_convert('UTC', 'UTC', $when, 'Y-m-d H:i:s');
                } else {
                    $when = datetime_convert('UTC', 'UTC', 'now', 'Y-m-d H:i:s');
                }
            }
            if ($deleted) {
                $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`\n\t\t\t\t\tWHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d AND NOT `item`.`file` LIKE '%%[%%' LIMIT 1", dbesc($uri), intval($importer['importer_uid']), intval($importer['id']));
                if (count($r)) {
                    $item = $r[0];
                    if ($item['deleted']) {
                        continue;
                    }
                    logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
                    if ($item['verb'] === ACTIVITY_TAG && $item['object-type'] === ACTIVITY_OBJ_TAGTERM) {
                        $xo = parse_xml_string($item['object'], false);
                        $xt = parse_xml_string($item['target'], false);
                        if ($xt->type === ACTIVITY_OBJ_NOTE) {
                            $i = q("select * from `item` where uri = '%s' and uid = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
                            if (count($i)) {
                                // For tags, the owner cannot remove the tag on the author's copy of the post.
                                $owner_remove = $item['contact-id'] == $i[0]['contact-id'] ? true : false;
                                $author_remove = $item['origin'] && $item['self'] ? true : false;
                                $author_copy = $item['origin'] ? true : false;
                                if ($owner_remove && $author_copy) {
                                    continue;
                                }
                                if ($author_remove || $owner_remove) {
                                    $tags = explode(',', $i[0]['tag']);
                                    $newtags = array();
                                    if (count($tags)) {
                                        foreach ($tags as $tag) {
                                            if (trim($tag) !== trim($xo->body)) {
                                                $newtags[] = trim($tag);
                                            }
                                        }
                                    }
                                    q("update item set tag = '%s' where id = %d limit 1", dbesc(implode(',', $newtags)), intval($i[0]['id']));
                                }
                            }
                        }
                    }
                    if ($item['uri'] == $item['parent-uri']) {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'\n\t\t\t\t\t\t\tWHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($when), dbesc(datetime_convert()), dbesc($item['uri']), intval($importer['importer_uid']));
                    } else {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' \n\t\t\t\t\t\t\tWHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($when), dbesc(datetime_convert()), dbesc($uri), intval($importer['importer_uid']));
                        if ($item['last-child']) {
                            // ensure that last-child is set in case the comment that had it just got wiped.
开发者ID:robhell,项目名称:friendica,代码行数:67,代码来源:items.php

示例12: onepoll_run


//.........这里部分代码省略.........
        $idtosend = $orig_id = $contact['dfrn-id'] ? $contact['dfrn-id'] : $contact['issued-id'];
        if (intval($contact['duplex']) && $contact['dfrn-id']) {
            $idtosend = '0:' . $orig_id;
        }
        if (intval($contact['duplex']) && $contact['issued-id']) {
            $idtosend = '1:' . $orig_id;
        }
        // they have permission to write to us. We already filtered this in the contact query.
        $perm = 'rw';
        // But this may be our first communication, so set the writable flag if it isn't set already.
        if (!intval($contact['writable'])) {
            q("update contact set writable = 1 where id = %d", intval($contact['id']));
        }
        $url = $contact['poll'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=data&last_update=' . $last_update . '&perm=' . $perm;
        $handshake_xml = fetch_url($url);
        $html_code = $a->get_curl_code();
        logger('onepoll: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA);
        if (!strlen($handshake_xml) || $html_code >= 400 || !$html_code) {
            logger("poller: {$url} appears to be dead - marking for death ");
            // dead connection - might be a transient event, or this might
            // mean the software was uninstalled or the domain expired.
            // Will keep trying for one month.
            mark_for_death($contact);
            // set the last-update so we don't keep polling
            $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id']));
            return;
        }
        if (!strstr($handshake_xml, '<')) {
            logger('poller: response from ' . $url . ' did not contain XML.');
            mark_for_death($contact);
            $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id']));
            return;
        }
        $res = parse_xml_string($handshake_xml);
        if (intval($res->status) == 1) {
            logger("poller: {$url} replied status 1 - marking for death ");
            // we may not be friends anymore. Will keep trying for one month.
            // set the last-update so we don't keep polling
            $r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($contact['id']));
            mark_for_death($contact);
        } else {
            if ($contact['term-date'] != '0000-00-00 00:00:00') {
                logger("poller: {$url} back from the dead - removing mark for death");
                unmark_for_death($contact);
            }
        }
        if (intval($res->status) != 0 || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
            return;
        }
        if ((double) $res->dfrn_version > 2.21 && $contact['poco'] == '') {
            q("update contact set poco = '%s' where id = %d", dbesc(str_replace('/profile/', '/poco/', $contact['url'])), intval($contact['id']));
        }
        $postvars = array();
        $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
        $challenge = hex2bin((string) $res->challenge);
        $final_dfrn_id = '';
        if ($contact['duplex'] && strlen($contact['prvkey'])) {
            openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
            openssl_private_decrypt($challenge, $postvars['challenge'], $contact['prvkey']);
        } else {
            openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
            openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']);
        }
        $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
        if (strpos($final_dfrn_id, ':') == 1) {
            $final_dfrn_id = substr($final_dfrn_id, 2);
开发者ID:rahmiyildiz,项目名称:friendica,代码行数:67,代码来源:onepoll.php

示例13: dfrn_confirm_post


//.........这里部分代码省略.........
            logger('Confirm: posting data to ' . $dfrn_confirm . ': ' . print_r($params, true), LOGGER_DATA);
            /**
             *
             * POST all this stuff to the other site.
             * Temporarily raise the network timeout to 120 seconds because the default 60
             * doesn't always give the other side quite enough time to decrypt everything.
             *
             */
            $a->config['system']['curl_timeout'] = 120;
            $res = post_url($dfrn_confirm, $params);
            logger(' Confirm: received data: ' . $res, LOGGER_DATA);
            // Now figure out what they responded. Try to be robust if the remote site is
            // having difficulty and throwing up errors of some kind.
            $leading_junk = substr($res, 0, strpos($res, '<?xml'));
            $res = substr($res, strpos($res, '<?xml'));
            if (!strlen($res)) {
                // No XML at all, this exchange is messed up really bad.
                // We shouldn't proceed, because the xml parser might choke,
                // and $status is going to be zero, which indicates success.
                // We can hardly call this a success.
                notice(t('Response from remote site was not understood.') . EOL);
                return;
            }
            if (strlen($leading_junk) && get_config('system', 'debugging')) {
                // This might be more common. Mixed error text and some XML.
                // If we're configured for debugging, show the text. Proceed in either case.
                notice(t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL);
            }
            if (stristr($res, "<status") === false) {
                // wrong xml! stop here!
                notice(t('Unexpected response from remote site: ') . EOL . htmlspecialchars($res) . EOL);
                return;
            }
            $xml = parse_xml_string($res);
            $status = (int) $xml->status;
            $message = unxmlify($xml->message);
            // human readable text of what may have gone wrong.
            switch ($status) {
                case 0:
                    info(t("Confirmation completed successfully.") . EOL);
                    if (strlen($message)) {
                        notice(t('Remote site reported: ') . $message . EOL);
                    }
                    break;
                case 1:
                    // birthday paradox - generate new dfrn-id and fall through.
                    $new_dfrn_id = random_string();
                    $r = q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($new_dfrn_id), intval($contact_id), intval($uid));
                case 2:
                    notice(t("Temporary failure. Please wait and try again.") . EOL);
                    if (strlen($message)) {
                        notice(t('Remote site reported: ') . $message . EOL);
                    }
                    break;
                case 3:
                    notice(t("Introduction failed or was revoked.") . EOL);
                    if (strlen($message)) {
                        notice(t('Remote site reported: ') . $message . EOL);
                    }
                    break;
            }
            if ($status == 0 && $intro_id) {
                // Success. Delete the notification.
                $r = q("DELETE FROM `intro` WHERE `id` = %d AND `uid` = %d", intval($intro_id), intval($uid));
            }
            if ($status != 0) {
开发者ID:vinzv,项目名称:friendica,代码行数:67,代码来源:dfrn_confirm.php

示例14: local_delivery


//.........这里部分代码省略.........
            // use the EmailNotification library to send the message
            require_once "include/EmailNotification.php";
            EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], $msg['notificationfromemail'], $msg['notificationfromemail'], $importer['email'], t('New mail received at ') . $a->config['sitename'], $email_html_body_tpl, $email_text_body_tpl);
            pop_lang();
        }
        return 0;
        // NOTREACHED
    }
    logger('local_delivery: feed item count = ' . $feed->get_item_quantity());
    // process any deleted entries
    $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
    if (is_array($del_entries) && count($del_entries)) {
        foreach ($del_entries as $dentry) {
            $deleted = false;
            if (isset($dentry['attribs']['']['ref'])) {
                $uri = $dentry['attribs']['']['ref'];
                $deleted = true;
                if (isset($dentry['attribs']['']['when'])) {
                    $when = $dentry['attribs']['']['when'];
                    $when = datetime_convert('UTC', 'UTC', $when, 'Y-m-d H:i:s');
                } else {
                    $when = datetime_convert('UTC', 'UTC', 'now', 'Y-m-d H:i:s');
                }
            }
            if ($deleted) {
                $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`\n\t\t\t\t\tWHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d LIMIT 1", dbesc($uri), intval($importer['importer_uid']), intval($importer['id']));
                if (count($r)) {
                    $item = $r[0];
                    if ($item['deleted']) {
                        continue;
                    }
                    logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
                    if ($item['verb'] === ACTIVITY_TAG && $item['object-type'] === ACTVITY_OBJ_TAGTERM) {
                        $xo = parse_xml_string($item['object'], false);
                        $xt = parse_xml_string($item['target'], false);
                        if ($xt->type === ACTIVITY_OBJ_NOTE) {
                            $i = q("select * from `item` where uri = '%s' and uid = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
                            if (count($i)) {
                                // For tags, the owner cannot remove the tag on the author's copy of the post.
                                $owner_remove = $item['contact-id'] == $i[0]['contact-id'] ? true : false;
                                $author_remove = $item['origin'] && $item['self'] ? true : false;
                                $author_copy = $item['origin'] ? true : false;
                                if ($owner_remove && $author_copy) {
                                    continue;
                                }
                                if ($author_remove || $owner_remove) {
                                    $tags = explode(',', $i[0]['tag']);
                                    $newtags = array();
                                    if (count($tags)) {
                                        foreach ($tags as $tag) {
                                            if (trim($tag) !== trim($xo->body)) {
                                                $newtags[] = trim($tag);
                                            }
                                        }
                                    }
                                    q("update item set tag = '%s' where id = %d limit 1", dbesc(implode(',', $newtags)), intval($i[0]['id']));
                                }
                            }
                        }
                    }
                    if ($item['uri'] == $item['parent-uri']) {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'\n\t\t\t\t\t\t\tWHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($when), dbesc(datetime_convert()), dbesc($item['uri']), intval($importer['importer_uid']));
                    } else {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' \n\t\t\t\t\t\t\tWHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($when), dbesc(datetime_convert()), dbesc($uri), intval($importer['importer_uid']));
                        if ($item['last-child']) {
                            // ensure that last-child is set in case the comment that had it just got wiped.
开发者ID:ryivhnn,项目名称:friendica,代码行数:67,代码来源:items.php

示例15: fetch_xrd_links

function fetch_xrd_links($url)
{
    logger('fetch_xrd_links: ' . $url);
    $redirects = 0;
    $x = z_fetch_url($url, false, $redirects, array('timeout' => 20));
    if (!$x['success']) {
        return array();
    }
    $xml = $x['body'];
    logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
    if (!$xml || !stristr($xml, '<xrd')) {
        return array();
    }
    // fix diaspora's bad xml
    $xml = str_replace(array('href=&quot;', '&quot;/>'), array('href="', '"/>'), $xml);
    $h = parse_xml_string($xml);
    if (!$h) {
        return array();
    }
    $arr = convert_xml_element_to_array($h);
    $links = array();
    if (isset($arr['xrd']['link'])) {
        $link = $arr['xrd']['link'];
        if (!isset($link[0])) {
            $links = array($link);
        } else {
            $links = $link;
        }
    }
    if (isset($arr['xrd']['alias'])) {
        $alias = $arr['xrd']['alias'];
        if (!isset($alias[0])) {
            $aliases = array($alias);
        } else {
            $aliases = $alias;
        }
        if (is_array($aliases) && count($aliases)) {
            foreach ($aliases as $alias) {
                $links[]['@attributes'] = array('rel' => 'alias', 'href' => $alias);
            }
        }
    }
    logger('fetch_xrd_links: ' . print_r($links, true), LOGGER_DATA);
    return $links;
}
开发者ID:bashrc,项目名称:hubzilla,代码行数:45,代码来源:network.php


注:本文中的parse_xml_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。