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


PHP import_xchan函数代码示例

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


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

示例1: get

 function get()
 {
     $o .= '<h3>Probe Diagnostic</h3>';
     $o .= '<form action="probe" method="get">';
     $o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . $_GET['addr'] . '" />';
     $o .= '<input type="submit" name="submit" value="Submit" /></form>';
     $o .= '<br /><br />';
     if (x($_GET, 'addr')) {
         $channel = \App::get_channel();
         $addr = trim($_GET['addr']);
         $do_import = intval($_GET['import']) && is_site_admin() ? true : false;
         $j = \Zotlabs\Zot\Finger::run($addr, $channel, false);
         //			$res = zot_finger($addr,$channel,false);
         $o .= '<pre>';
         if (!$j['success']) {
             $o .= sprintf(t('Fetching URL returns error: %1$s'), $res['error'] . "\r\n\r\n");
             $o .= "<strong>https connection failed. Trying again with auto failover to http.</strong>\r\n\r\n";
             $j = \Zotlabs\Zot\Finger::run($addr, $channel, true);
             if (!$j['success']) {
                 $o .= sprintf(t('Fetching URL returns error: %1$s'), $res['error'] . "\r\n\r\n");
             }
         }
         if ($do_import && $j) {
             $x = import_xchan($j);
         }
         if ($j && $j['permissions'] && $j['permissions']['iv']) {
             $j['permissions'] = json_decode(crypto_unencapsulate($j['permissions'], $channel['channel_prvkey']), true);
         }
         $o .= str_replace("\n", '<br />', print_r($j, true));
         $o .= '</pre>';
     }
     return $o;
 }
开发者ID:einervonvielen,项目名称:hubzilla,代码行数:33,代码来源:Probe.php

示例2: GetHublocs

 function GetHublocs($address)
 {
     // Try and find a hubloc for the person attempting to auth.
     // Since we're matching by address, we have to return all entries
     // some of which may be from re-installed hubs; and we'll need to
     // try each sequentially to see if one can pass the test
     $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash \n\t\t\twhere hubloc_addr = '%s' order by hubloc_id desc", dbesc($address));
     if (!$x) {
         // finger them if they can't be found.
         $ret = zot_finger($address, null);
         if ($ret['success']) {
             $j = json_decode($ret['body'], true);
             if ($j) {
                 import_xchan($j);
             }
             $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash \n\t\t\t\t\twhere hubloc_addr = '%s' order by hubloc_id desc", dbesc($address));
         }
     }
     if (!$x) {
         logger('mod_zot: auth: unable to finger ' . $address);
         $this->Debug('no hubloc found for ' . $address . ' and probing failed.');
         $this->Finalise();
     }
     return $x;
 }
开发者ID:TamirAl,项目名称:hubzilla,代码行数:25,代码来源:Auth.php

示例3: gprobe_run

function gprobe_run($argv, $argc)
{
    cli_startup();
    $a = get_app();
    if ($argc != 2) {
        return;
    }
    $url = hex2bin($argv[1]);
    $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($url));
    if (!$r) {
        $x = zot_finger($url, null);
        if ($x['success']) {
            $j = json_decode($x['body'], true);
            $y = import_xchan($j);
        }
    }
    return;
}
开发者ID:redmatrix,项目名称:red,代码行数:18,代码来源:gprobe.php

示例4: run

 public static function run($argc, $argv)
 {
     if ($argc != 2) {
         return;
     }
     $url = hex2bin($argv[1]);
     if (!strpos($url, '@')) {
         return;
     }
     $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($url));
     if (!$r) {
         $j = \Zotlabs\Zot\Finger::run($url, null);
         if ($j['success']) {
             $y = import_xchan($j);
         }
     }
     return;
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:18,代码来源:Gprobe.php

示例5: GetHublocs

 function GetHublocs($address)
 {
     // Try and find a hubloc for the person attempting to auth
     $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash \n\t\t\twhere hubloc_addr = '%s' order by hubloc_id desc", dbesc($address));
     if (!$x) {
         // finger them if they can't be found.
         $ret = zot_finger($address, null);
         if ($ret['success']) {
             $j = json_decode($ret['body'], true);
             if ($j) {
                 import_xchan($j);
             }
             $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash \n\t\t\t\t\twhere hubloc_addr = '%s' order by hubloc_id desc", dbesc($address));
         }
     }
     if (!$x) {
         logger('mod_zot: auth: unable to finger ' . $address);
         $this->reply_die('no hubloc found for ' . $address . ' and probing failed.');
     }
     return $x;
 }
开发者ID:msooon,项目名称:hubzilla,代码行数:21,代码来源:Auth.php

示例6: update_directory_entry

/**
 * @brief
 *
 * Given an update record, probe the channel, grab a zot-info packet and refresh/sync the data.
 *
 * Ignore updating records marked as deleted.
 *
 * If successful, sets ud_last in the DB to the current datetime for this
 * reddress/webbie.
 *
 * @param array $ud Entry from update table
 */
function update_directory_entry($ud)
{
    logger('update_directory_entry: ' . print_r($ud, true), LOGGER_DATA);
    if ($ud['ud_addr'] && !($ud['ud_flags'] & UPDATE_FLAGS_DELETED)) {
        $success = false;
        $x = zot_finger($ud['ud_addr'], '');
        if ($x['success']) {
            $j = json_decode($x['body'], true);
            if ($j) {
                $success = true;
            }
            $y = import_xchan($j, 0, $ud);
        }
        if (!$success) {
            q("update updates set ud_last = '%s' where ud_addr = '%s'", dbesc(datetime_convert()), dbesc($ud['ud_addr']));
        }
    }
}
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:30,代码来源:dir_fns.php

示例7: mail_post

function mail_post(&$a)
{
    if (!local_user()) {
        return;
    }
    $replyto = x($_REQUEST, 'replyto') ? notags(trim($_REQUEST['replyto'])) : '';
    $subject = x($_REQUEST, 'subject') ? notags(trim($_REQUEST['subject'])) : '';
    $body = x($_REQUEST, 'body') ? escape_tags(trim($_REQUEST['body'])) : '';
    $recipient = x($_REQUEST, 'messageto') ? notags(trim($_REQUEST['messageto'])) : '';
    $rstr = x($_REQUEST, 'messagerecip') ? notags(trim($_REQUEST['messagerecip'])) : '';
    $expires = x($_REQUEST, 'expires') ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['expires']) : NULL_DATE;
    // If we have a raw string for a recipient which hasn't been auto-filled,
    // it means they probably aren't in our address book, hence we don't know
    // if we have permission to send them private messages.
    // finger them and find out before we try and send it.
    if (!$recipient) {
        $channel = $a->get_channel();
        $ret = zot_finger($rstr, $channel);
        if (!$ret['success']) {
            notice(t('Unable to lookup recipient.') . EOL);
            return;
        }
        $j = json_decode($ret['body'], true);
        logger('message_post: lookup: ' . $url . ' ' . print_r($j, true));
        if (!($j['success'] && $j['guid'])) {
            notice(t('Unable to communicate with requested channel.'));
            return;
        }
        $x = import_xchan($j);
        if (!$x['success']) {
            notice(t('Cannot verify requested channel.'));
            return;
        }
        $recipient = $x['hash'];
        $their_perms = 0;
        $global_perms = get_perms();
        if ($j['permissions']['data']) {
            $permissions = crypto_unencapsulate($j['permissions'], $channel['channel_prvkey']);
            if ($permissions) {
                $permissions = json_decode($permissions);
            }
            logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
        } else {
            $permissions = $j['permissions'];
        }
        foreach ($permissions as $k => $v) {
            if ($v) {
                $their_perms = $their_perms | intval($global_perms[$k][1]);
            }
        }
        if (!($their_perms & PERMS_W_MAIL)) {
            notice(t('Selected channel has private message restrictions. Send failed.'));
            return;
        }
    }
    //	if(feature_enabled(local_user(),'richtext')) {
    //		$body = fix_mce_lf($body);
    //	}
    if (!$recipient) {
        notice('No recipient found.');
        $a->argc = 2;
        $a->argv[1] = 'new';
        return;
    }
    // We have a local_user, let send_message use the session channel and save a lookup
    $ret = send_message(0, $recipient, $body, $subject, $replyto, $expires);
    if (!$ret['success']) {
        notice($ret['message']);
    }
    goaway(z_root() . '/message');
}
开发者ID:Mauru,项目名称:red,代码行数:71,代码来源:mail.php

示例8: init

 function init()
 {
     $result = array('success' => false);
     $url = $_REQUEST['url'];
     $access_token = $_REQUEST['t'];
     $valid = 0;
     // we probably don't need the realm as we will find out in the probe.
     // What we may want to die is throw an error if you're trying to register in a different realm
     // so this configuration issue can be discovered.
     $realm = $_REQUEST['realm'];
     if (!$realm) {
         $realm = DIRECTORY_REALM;
     }
     if ($realm === DIRECTORY_REALM) {
         $valid = 1;
     } else {
         $token = get_config('system', 'realm_token');
         if ($token && $access_token != $token) {
             $result['message'] = 'This realm requires an access token';
             return;
         }
         $valid = 1;
     }
     $dirmode = intval(get_config('system', 'directory_mode'));
     if ($dirmode == DIRECTORY_MODE_NORMAL) {
         $ret['message'] = t('This site is not a directory server');
         json_return_and_die($ret);
     }
     $m = null;
     if ($url) {
         $m = parse_url($url);
         if (!$m || !@dns_get_record($m['host'], DNS_A + DNS_CNAME + DNS_PTR) && !filter_var($m['host'], FILTER_VALIDATE_IP)) {
             $result['message'] = 'unparseable url';
             json_return_and_die($result);
         }
         $j = \Zotlabs\Zot\Finger::run('[system]@' . $m['host']);
         if ($j['success'] && $j['guid']) {
             $x = import_xchan($j);
             if ($x['success']) {
                 $result['success'] = true;
             }
         }
         if (!$result['success']) {
             $valid = 0;
         }
         q("update site set site_valid = %d where site_url = '%s' limit 1", intval($valid), strtolower($url));
         json_return_and_die($result);
     } else {
         // We can put this in the sql without the condition after 31 august 2015 assuming
         // most directory servers will have updated by then
         // This just makes sure it happens if I forget
         $sql_extra = datetime_convert() > datetime_convert('UTC', 'UTC', '2015-08-31') ? ' and site_valid = 1 ' : '';
         if ($dirmode == DIRECTORY_MODE_STANDALONE) {
             $r = array(array('site_url' => z_root()));
         } else {
             $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s' and site_type = %d {$sql_extra} ", dbesc(get_directory_realm()), intval(SITE_TYPE_ZOT));
         }
         if ($r) {
             $result['success'] = true;
             $result['directories'] = array();
             foreach ($r as $rr) {
                 $result['directories'][] = $rr['site_url'];
             }
             json_return_and_die($result);
         }
     }
     json_return_and_die($result);
 }
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:68,代码来源:Regdir.php

示例9: poco_load


//.........这里部分代码省略.........
        } else {
            logger('poco_load: returns ' . print_r($s, true));
        }
        return;
    }
    $j = json_decode($s['body'], true);
    if (!$j) {
        logger('poco_load: unable to json_decode returned data.');
        return;
    }
    logger('poco_load: ' . print_r($j, true), LOGGER_DATA);
    if ($xchan) {
        if (array_key_exists('chatrooms', $j) && is_array($j['chatrooms'])) {
            foreach ($j['chatrooms'] as $room) {
                if (!$room['url'] || !$room['desc']) {
                    continue;
                }
                $r = q("select * from xchat where xchat_url = '%s' and xchat_xchan = '%s' limit 1", dbesc($room['url']), dbesc($xchan));
                if ($r) {
                    q("update xchat set xchat_edited = '%s' where xchat_id = %d", dbesc(datetime_convert()), intval($r[0]['xchat_id']));
                } else {
                    $x = q("insert into xchat ( xchat_url, xchat_desc, xchat_xchan, xchat_edited )\n\t\t\t\t\t\tvalues ( '%s', '%s', '%s', '%s' ) ", dbesc(escape_tags($room['url'])), dbesc(escape_tags($room['desc'])), dbesc($xchan), dbesc(datetime_convert()));
                }
            }
        }
        q("delete from xchat where xchat_edited < %s - INTERVAL %s and xchat_xchan = '%s' ", db_utcnow(), db_quoteinterval('7 DAY'), dbesc($xchan));
    }
    if (!(x($j, 'entry') && is_array($j['entry']))) {
        logger('poco_load: no entries');
        return;
    }
    $total = 0;
    foreach ($j['entry'] as $entry) {
        $profile_url = '';
        $profile_photo = '';
        $address = '';
        $name = '';
        $hash = '';
        $rating = 0;
        $name = $entry['displayName'];
        $hash = $entry['hash'];
        if (x($entry, 'urls') && is_array($entry['urls'])) {
            foreach ($entry['urls'] as $url) {
                if ($url['type'] == 'profile') {
                    $profile_url = $url['value'];
                    continue;
                }
                if ($url['type'] == 'zot' || $url['type'] == 'diaspora' || $url['type'] == 'friendica') {
                    $network = $url['type'];
                    $address = str_replace('acct:', '', $url['value']);
                    continue;
                }
            }
        }
        if (x($entry, 'photos') && is_array($entry['photos'])) {
            foreach ($entry['photos'] as $photo) {
                if ($photo['type'] == 'profile') {
                    $profile_photo = $photo['value'];
                    continue;
                }
            }
        }
        if (!$name || !$profile_url || !$profile_photo || !$hash || !$address) {
            logger('poco_load: missing data');
            continue;
        }
        $x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", dbesc($hash));
        // We've never seen this person before. Import them.
        if ($x !== false && !count($x)) {
            if ($address) {
                if ($network === 'zot') {
                    $j = Zotlabs\Zot\Finger::run($address, null);
                    if ($j['success']) {
                        import_xchan($j);
                    }
                    $x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", dbesc($hash));
                    if (!$x) {
                        continue;
                    }
                } else {
                    $x = import_author_diaspora(array('address' => $address));
                    if (!$x) {
                        continue;
                    }
                }
            } else {
                continue;
            }
        }
        $total++;
        $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 0 limit 1", dbesc($xchan), dbesc($hash));
        if (!$r) {
            q("insert into xlink ( xlink_xchan, xlink_link, xlink_updated, xlink_static ) values ( '%s', '%s', '%s', 0 ) ", dbesc($xchan), dbesc($hash), dbesc(datetime_convert()));
        } else {
            q("update xlink set xlink_updated = '%s' where xlink_id = %d", dbesc(datetime_convert()), intval($r[0]['xlink_id']));
        }
    }
    logger("poco_load: loaded {$total} entries", LOGGER_DEBUG);
    q("delete from xlink where xlink_xchan = '%s' and xlink_updated < %s - INTERVAL %s and xlink_static = 0", dbesc($xchan), db_utcnow(), db_quoteinterval('2 DAY'));
}
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:101,代码来源:socgraph.php

示例10: new_contact

function new_contact($uid, $url, $channel, $interactive = false, $confirm = false)
{
    $result = array('success' => false, 'message' => '');
    $a = get_app();
    $is_red = false;
    $is_http = strpos($url, '://') !== false ? true : false;
    if ($is_http && substr($url, -1, 1) === '/') {
        $url = substr($url, 0, -1);
    }
    if (!allowed_url($url)) {
        $result['message'] = t('Channel is blocked on this site.');
        return $result;
    }
    if (!$url) {
        $result['message'] = t('Channel location missing.');
        return $result;
    }
    // check service class limits
    $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", intval($uid));
    if ($r) {
        $total_channels = $r[0]['total'];
    }
    if (!service_class_allows($uid, 'total_channels', $total_channels)) {
        $result['message'] = upgrade_message();
        return $result;
    }
    $arr = array('url' => $url, 'channel' => array());
    call_hooks('follow', $arr);
    if ($arr['channel']['success']) {
        $ret = $arr['channel'];
    } elseif (!$is_http) {
        $ret = zot_finger($url, $channel);
    }
    if ($ret && $ret['success']) {
        $is_red = true;
        $j = json_decode($ret['body'], true);
    }
    $my_perms = get_channel_default_perms($uid);
    $role = get_pconfig($uid, 'system', 'permissions_role');
    if ($role) {
        $x = get_role_perms($role);
        if ($x['perms_follow']) {
            $my_perms = $x['perms_follow'];
        }
    }
    if ($is_red && $j) {
        logger('follow: ' . $url . ' ' . print_r($j, true), LOGGER_DEBUG);
        if (!($j['success'] && $j['guid'])) {
            $result['message'] = t('Response from remote channel was incomplete.');
            logger('mod_follow: ' . $result['message']);
            return $result;
        }
        // Premium channel, set confirm before callback to avoid recursion
        if (array_key_exists('connect_url', $j) && $interactive && !$confirm) {
            goaway(zid($j['connect_url']));
        }
        // do we have an xchan and hubloc?
        // If not, create them.
        $x = import_xchan($j);
        if (array_key_exists('deleted', $j) && intval($j['deleted'])) {
            $result['message'] = t('Channel was deleted and no longer exists.');
            return $result;
        }
        if (!$x['success']) {
            return $x;
        }
        $xchan_hash = $x['hash'];
        $their_perms = 0;
        $global_perms = get_perms();
        if (array_key_exists('permissions', $j) && array_key_exists('data', $j['permissions'])) {
            $permissions = crypto_unencapsulate(array('data' => $j['permissions']['data'], 'key' => $j['permissions']['key'], 'iv' => $j['permissions']['iv']), $channel['channel_prvkey']);
            if ($permissions) {
                $permissions = json_decode($permissions, true);
            }
            logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
        } else {
            $permissions = $j['permissions'];
        }
        foreach ($permissions as $k => $v) {
            if ($v) {
                $their_perms = $their_perms | intval($global_perms[$k][1]);
            }
        }
    } else {
        $their_perms = 0;
        $xchan_hash = '';
        $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url));
        if (!$r) {
            // attempt network auto-discovery
            if (strpos($url, '@') && !$is_http) {
                $r = discover_by_webbie($url);
            } elseif ($is_http) {
                $r = discover_by_url($url);
                $r['allowed'] = intval(get_config('system', 'feed_contacts'));
            }
            if ($r) {
                $r['channel_id'] = $uid;
                call_hooks('follow_allow', $r);
                if (!$r['allowed']) {
                    $result['message'] = t('Protocol disabled.');
//.........这里部分代码省略.........
开发者ID:kenrestivo,项目名称:hubzilla,代码行数:101,代码来源:follow.php

示例11: new_contact

function new_contact($uid, $url, $channel, $interactive = false, $confirm = false)
{
    $result = array('success' => false, 'message' => '');
    $is_red = false;
    $is_http = strpos($url, '://') !== false ? true : false;
    if ($is_http && substr($url, -1, 1) === '/') {
        $url = substr($url, 0, -1);
    }
    if (!allowed_url($url)) {
        $result['message'] = t('Channel is blocked on this site.');
        return $result;
    }
    if (!$url) {
        $result['message'] = t('Channel location missing.');
        return $result;
    }
    // check service class limits
    $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", intval($uid));
    if ($r) {
        $total_channels = $r[0]['total'];
    }
    if (!service_class_allows($uid, 'total_channels', $total_channels)) {
        $result['message'] = upgrade_message();
        return $result;
    }
    $arr = array('url' => $url, 'channel' => array());
    call_hooks('follow', $arr);
    if ($arr['channel']['success']) {
        $ret = $arr['channel'];
    } elseif (!$is_http) {
        $ret = Zotlabs\Zot\Finger::run($url, $channel);
    }
    if ($ret && is_array($ret) && $ret['success']) {
        $is_red = true;
        $j = $ret;
    }
    $my_perms = get_channel_default_perms($uid);
    $role = get_pconfig($uid, 'system', 'permissions_role');
    if ($role) {
        $x = \Zotlabs\Access\PermissionRoles::role_perms($role);
        if ($x['perms_connect']) {
            $my_perms = $x['perms_connect'];
        }
    }
    if ($is_red && $j) {
        logger('follow: ' . $url . ' ' . print_r($j, true), LOGGER_DEBUG);
        if (!($j['success'] && $j['guid'])) {
            $result['message'] = t('Response from remote channel was incomplete.');
            logger('mod_follow: ' . $result['message']);
            return $result;
        }
        // Premium channel, set confirm before callback to avoid recursion
        if (array_key_exists('connect_url', $j) && $interactive && !$confirm) {
            goaway(zid($j['connect_url']));
        }
        // do we have an xchan and hubloc?
        // If not, create them.
        $x = import_xchan($j);
        if (array_key_exists('deleted', $j) && intval($j['deleted'])) {
            $result['message'] = t('Channel was deleted and no longer exists.');
            return $result;
        }
        if (!$x['success']) {
            return $x;
        }
        $xchan_hash = $x['hash'];
        if (array_key_exists('permissions', $j) && array_key_exists('data', $j['permissions'])) {
            $permissions = crypto_unencapsulate(array('data' => $j['permissions']['data'], 'key' => $j['permissions']['key'], 'iv' => $j['permissions']['iv']), $channel['channel_prvkey']);
            if ($permissions) {
                $permissions = json_decode($permissions, true);
            }
            logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
        } else {
            $permissions = $j['permissions'];
        }
        if (is_array($permissions) && $permissions) {
            foreach ($permissions as $k => $v) {
                set_abconfig($channel['channel_uid'], $xchan_hash, 'their_perms', $k, intval($v));
            }
        }
    } else {
        $xchan_hash = '';
        $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url));
        if (!$r) {
            // attempt network auto-discovery
            $d = discover_by_webbie($url);
            if (!$d && $is_http) {
                // try RSS discovery
                if (get_config('system', 'feed_contacts')) {
                    $d = discover_by_url($url);
                } else {
                    $result['message'] = t('Protocol disabled.');
                    return $result;
                }
            }
            if ($d) {
                $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", dbesc($url), dbesc($url));
            }
        }
        // if discovery was a success we should have an xchan record in $r
//.........这里部分代码省略.........
开发者ID:BlaBlaNet,项目名称:hubzilla,代码行数:101,代码来源:follow.php

示例12: discover_by_webbie

function discover_by_webbie($webbie)
{
    require_once 'library/HTML5/Parser.php';
    $result = array();
    $network = null;
    $diaspora = false;
    $gnusoc = false;
    $dfrn = false;
    $has_salmon = false;
    $salmon_key = false;
    $atom_feed = false;
    $diaspora_base = '';
    $diaspora_guid = '';
    $diaspora_key = '';
    $webbie = strtolower($webbie);
    $x = webfinger_rfc7033($webbie, true);
    if ($x && array_key_exists('links', $x) && $x['links']) {
        foreach ($x['links'] as $link) {
            if (array_key_exists('rel', $link)) {
                // If we discover zot - don't search further; grab the info and get out of
                // here.
                if ($link['rel'] === PROTOCOL_ZOT) {
                    logger('discover_by_webbie: zot found for ' . $webbie, LOGGER_DEBUG);
                    if (array_key_exists('zot', $x) && $x['zot']['success']) {
                        $i = import_xchan($x['zot']);
                    } else {
                        $z = z_fetch_url($link['href']);
                        if ($z['success']) {
                            $j = json_decode($z['body'], true);
                            $i = import_xchan($j);
                            return true;
                        }
                    }
                }
                if ($link['rel'] == NAMESPACE_DFRN) {
                    $dfrn = $link['href'];
                }
                if ($link['rel'] == 'magic-public-key') {
                    if (substr($link['href'], 0, 5) === 'data:') {
                        $salmon_key = convert_salmon_key($link['href']);
                    }
                }
                if ($link['rel'] == 'salmon') {
                    $has_salmon = true;
                    $salmon = $link['href'];
                }
                if ($link['rel'] == 'http://schemas.google.com/g/2010#updates-from') {
                    $atom_feed = $link['href'];
                }
            }
        }
    }
    logger('webfinger: ' . print_r($x, true), LOGGER_DATA, LOG_INFO);
    $arr = array('address' => $webbie, 'success' => false, 'webfinger' => $x);
    call_hooks('discover_channel_webfinger', $arr);
    if ($arr['success']) {
        return true;
    }
    $aliases = array();
    // Now let's make some decisions on what we may need
    // to obtain further info
    $probe_atom = false;
    $probe_old = false;
    $probe_hcard = false;
    $address = '';
    $location = '';
    $nickname = '';
    $fullname = '';
    $avatar = '';
    $pubkey = '';
    if (is_array($x)) {
        if (array_key_exists('address', $x)) {
            $address = $x['address'];
        }
        if (array_key_exists('location', $x)) {
            $location = $x['location'];
        }
        if (array_key_exists('nickname', $x)) {
            $nickname = $x['nickname'];
        }
    }
    if (!$x) {
        $probe_old = true;
    }
    if (!$dfrn && !$has_salmon) {
        $probe_old = true;
    }
    if ($probe_old) {
        $y = old_webfinger($webbie);
        if ($y) {
            logger('old_webfinger: ' . print_r($x, true));
            foreach ($y as $link) {
                if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
                    $dfrn = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'salmon') {
                    $notify = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === NAMESPACE_FEED) {
                    $poll = unamp($link['@attributes']['href']);
//.........这里部分代码省略.........
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:101,代码来源:network.php

示例13: post_init


//.........这里部分代码省略.........
     *
     *
     *
     */
    if (array_key_exists('auth', $_REQUEST)) {
        $ret = array('success' => false, 'message' => '');
        logger('mod_zot: auth request received.');
        $address = $_REQUEST['auth'];
        $desturl = $_REQUEST['dest'];
        $sec = $_REQUEST['sec'];
        $version = $_REQUEST['version'];
        $test = x($_REQUEST, 'test') ? intval($_REQUEST['test']) : 0;
        // They are authenticating ultimately to the site and not to a particular channel.
        // Any channel will do, providing it's currently active. We just need to have an
        // identity to attach to the packet we send back. So find one.
        $c = q("select * from channel where not ( channel_pageflags & %d ) limit 1", intval(PAGE_REMOVED));
        if (!$c) {
            // nobody here
            logger('mod_zot: auth: unable to find a response channel');
            if ($test) {
                $ret['message'] .= 'no local channels found.' . EOL;
                json_return_and_die($ret);
            }
            goaway($desturl);
        }
        // Try and find a hubloc for the person attempting to auth
        $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc limit 1", dbesc($address));
        if (!$x) {
            // finger them if they can't be found.
            $ret = zot_finger($address, null);
            if ($ret['success']) {
                $j = json_decode($ret['body'], true);
                if ($j) {
                    import_xchan($j);
                }
                $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc limit 1", dbesc($address));
            }
        }
        if (!$x) {
            logger('mod_zot: auth: unable to finger ' . $address);
            if ($test) {
                $ret['message'] .= 'no hubloc found for ' . $address . ' and probing failed.' . EOL;
                json_return_and_die($ret);
            }
            goaway($desturl);
        }
        logger('mod_zot: auth request received from ' . $x[0]['hubloc_addr']);
        // check credentials and access
        // If they are already authenticated and haven't changed credentials,
        // we can save an expensive network round trip and improve performance.
        $remote = remote_user();
        $result = null;
        $remote_service_class = '';
        $remote_level = 0;
        $remote_hub = $x[0]['hubloc_url'];
        $DNT = 0;
        // Also check that they are coming from the same site as they authenticated with originally.
        $already_authed = $remote && $x[0]['hubloc_hash'] == $remote && $x[0]['hubloc_url'] === $_SESSION['remote_hub'] ? true : false;
        $j = array();
        if (!$already_authed) {
            // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the site private key
            // The actual channel sending the packet ($c[0]) is not important, but this provides a generic zot packet with a sender
            // which can be verified
            $p = zot_build_packet($c[0], $type = 'auth_check', array(array('guid' => $x[0]['hubloc_guid'], 'guid_sig' => $x[0]['hubloc_guid_sig'])), $x[0]['hubloc_sitekey'], $sec);
            if ($test) {
                $ret['message'] .= 'auth check packet created using sitekey ' . $x[0]['hubloc_sitekey'] . EOL;
开发者ID:Mauru,项目名称:red,代码行数:67,代码来源:post.php

示例14: mail_post

function mail_post(&$a)
{
    if (!local_channel()) {
        return;
    }
    $replyto = x($_REQUEST, 'replyto') ? notags(trim($_REQUEST['replyto'])) : '';
    $subject = x($_REQUEST, 'subject') ? notags(trim($_REQUEST['subject'])) : '';
    $body = x($_REQUEST, 'body') ? escape_tags(trim($_REQUEST['body'])) : '';
    $recipient = x($_REQUEST, 'messageto') ? notags(trim($_REQUEST['messageto'])) : '';
    $rstr = x($_REQUEST, 'messagerecip') ? notags(trim($_REQUEST['messagerecip'])) : '';
    $preview = x($_REQUEST, 'preview') ? intval($_REQUEST['preview']) : 0;
    $expires = x($_REQUEST, 'expires') ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['expires']) : NULL_DATE;
    // If we have a raw string for a recipient which hasn't been auto-filled,
    // it means they probably aren't in our address book, hence we don't know
    // if we have permission to send them private messages.
    // finger them and find out before we try and send it.
    if (!$recipient) {
        $channel = App::get_channel();
        $ret = zot_finger($rstr, $channel);
        if (!$ret['success']) {
            notice(t('Unable to lookup recipient.') . EOL);
            return;
        }
        $j = json_decode($ret['body'], true);
        logger('message_post: lookup: ' . $url . ' ' . print_r($j, true));
        if (!($j['success'] && $j['guid'])) {
            notice(t('Unable to communicate with requested channel.'));
            return;
        }
        $x = import_xchan($j);
        if (!$x['success']) {
            notice(t('Cannot verify requested channel.'));
            return;
        }
        $recipient = $x['hash'];
        $their_perms = 0;
        $global_perms = get_perms();
        if ($j['permissions']['data']) {
            $permissions = crypto_unencapsulate($j['permissions'], $channel['channel_prvkey']);
            if ($permissions) {
                $permissions = json_decode($permissions);
            }
            logger('decrypted permissions: ' . print_r($permissions, true), LOGGER_DATA);
        } else {
            $permissions = $j['permissions'];
        }
        foreach ($permissions as $k => $v) {
            if ($v) {
                $their_perms = $their_perms | intval($global_perms[$k][1]);
            }
        }
        if (!($their_perms & PERMS_W_MAIL)) {
            notice(t('Selected channel has private message restrictions. Send failed.'));
            // reported issue: let's still save the message and continue. We'll just tell them
            // that nothing useful is likely to happen. They might have spent hours on it.
            //			return;
        }
    }
    //	if(feature_enabled(local_channel(),'richtext')) {
    //		$body = fix_mce_lf($body);
    //	}
    require_once 'include/text.php';
    linkify_tags($a, $body, local_channel());
    if ($preview) {
    }
    if (!$recipient) {
        notice('No recipient found.');
        App::$argc = 2;
        App::$argv[1] = 'new';
        return;
    }
    // We have a local_channel, let send_message use the session channel and save a lookup
    $ret = send_message(0, $recipient, $body, $subject, $replyto, $expires);
    if ($ret['success']) {
        xchan_mail_query($ret['mail']);
        build_sync_packet(0, array('conv' => array($ret['conv']), 'mail' => array(encode_mail($ret['mail'], true))));
    } else {
        notice($ret['message']);
    }
    goaway(z_root() . '/mail/combined');
}
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:81,代码来源:mail.php

示例15: post_init


//.........这里部分代码省略.........
 */
function post_init(&$a)
{
    if (array_key_exists('auth', $_REQUEST)) {
        $ret = array('success' => false, 'message' => '');
        logger('mod_zot: auth request received.');
        $address = $_REQUEST['auth'];
        $desturl = $_REQUEST['dest'];
        $sec = $_REQUEST['sec'];
        $version = $_REQUEST['version'];
        $delegate = $_REQUEST['delegate'];
        $test = x($_REQUEST, 'test') ? intval($_REQUEST['test']) : 0;
        // They are authenticating ultimately to the site and not to a particular channel.
        // Any channel will do, providing it's currently active. We just need to have an
        // identity to attach to the packet we send back. So find one.
        $c = q("select * from channel where channel_removed = 0 limit 1");
        if (!$c) {
            // nobody here
            logger('mod_zot: auth: unable to find a response channel');
            if ($test) {
                $ret['message'] .= 'no local channels found.' . EOL;
                json_return_and_die($ret);
            }
            goaway($desturl);
        }
        // Try and find a hubloc for the person attempting to auth
        $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc", dbesc($address));
        if (!$x) {
            // finger them if they can't be found.
            $ret = zot_finger($address, null);
            if ($ret['success']) {
                $j = json_decode($ret['body'], true);
                if ($j) {
                    import_xchan($j);
                }
                $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc", dbesc($address));
            }
        }
        if (!$x) {
            logger('mod_zot: auth: unable to finger ' . $address);
            if ($test) {
                $ret['message'] .= 'no hubloc found for ' . $address . ' and probing failed.' . EOL;
                json_return_and_die($ret);
            }
            goaway($desturl);
        }
        foreach ($x as $xx) {
            logger('mod_zot: auth request received from ' . $xx['hubloc_addr']);
            // check credentials and access
            // If they are already authenticated and haven't changed credentials,
            // we can save an expensive network round trip and improve performance.
            $remote = remote_channel();
            $result = null;
            $remote_service_class = '';
            $remote_level = 0;
            $remote_hub = $xx['hubloc_url'];
            $DNT = 0;
            // Also check that they are coming from the same site as they authenticated with originally.
            $already_authed = $remote && $xx['hubloc_hash'] == $remote && $xx['hubloc_url'] === $_SESSION['remote_hub'] ? true : false;
            if ($delegate && $delegate !== $_SESSION['delegate_channel']) {
                $already_authed = false;
            }
            $j = array();
            if (!$already_authed) {
                // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the site private key
                // The actual channel sending the packet ($c[0]) is not important, but this provides a generic zot packet with a sender
开发者ID:23n,项目名称:hubzilla,代码行数:67,代码来源:post.php


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