本文整理汇总了PHP中probe_url函数的典型用法代码示例。如果您正苦于以下问题:PHP probe_url函数的具体用法?PHP probe_url怎么用?PHP probe_url使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了probe_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gprobe_run
function gprobe_run($argv, $argc)
{
global $a, $db;
if (is_null($a)) {
$a = new App();
}
if (is_null($db)) {
@(include ".htconfig.php");
require_once "dba.php";
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
require_once 'include/session.php';
require_once 'include/datetime.php';
load_config('config');
load_config('system');
$a->set_baseurl(get_config('system', 'url'));
load_hooks();
if ($argc != 2) {
return;
}
$url = hex2bin($argv[1]);
$r = q("select * from gcontact where nurl = '%s' limit 1", dbesc(normalise_link($url)));
if (!count($r)) {
$arr = probe_url($url);
if (count($arr) && x($arr, 'network') && $arr['network'] === NETWORK_DFRN) {
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`)\n\t\t\t\tvalues ( '%s', '%s', '%s', '%s') ", dbesc($arr['name']), dbesc($arr['url']), dbesc(normalise_link($arr['url'])), dbesc($arr['photo']));
}
$r = q("select * from gcontact where nurl = '%s' limit 1", dbesc(normalise_link($url)));
}
if (count($r)) {
poco_load(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
}
return;
}
示例2: ostatus_follow_friends
function ostatus_follow_friends($uid, $url)
{
$contact = probe_url($url);
if (!$contact) {
return;
}
$api = $contact["baseurl"] . "/api/";
// Fetching friends
$data = z_fetch_url($api . "statuses/friends.json?screen_name=" . $contact["nick"]);
if (!$data["success"]) {
return;
}
$friends = json_decode($data["body"]);
foreach ($friends as $friend) {
$url = $friend->statusnet_profile_url;
$r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND\n\t\t\t(`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND\n\t\t\t`network` != '%s' LIMIT 1", intval($uid), dbesc(normalise_link($url)), dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
if (!$r) {
$data = probe_url($friend->statusnet_profile_url);
if ($data["network"] == NETWORK_OSTATUS) {
$result = new_contact($uid, $friend->statusnet_profile_url);
if ($result["success"]) {
logger($friend->name . " " . $url . " - success", LOGGER_DEBUG);
} else {
logger($friend->name . " " . $url . " - failed", LOGGER_DEBUG);
}
} else {
logger($friend->name . " " . $url . " - not OStatus", LOGGER_DEBUG);
}
}
}
}
示例3: follow_content
function follow_content(&$a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$uid = local_user();
$url = notags(trim($_REQUEST['url']));
$r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND\n\t\t(`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND\n\t\t`network` != '%s' LIMIT 1", intval(local_user()), dbesc(normalise_link($url)), dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
if ($r) {
notice(t('You already added this contact.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$ret = probe_url($url);
if ($ret['network'] === NETWORK_DFRN) {
$request = $ret["request"];
$tpl = get_markup_template('dfrn_request.tpl');
} else {
$request = $a->get_baseurl() . "/follow";
$tpl = get_markup_template('auto_request.tpl');
}
$r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
if (!$r) {
notice(t('Permission denied.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$myaddr = $r[0]["url"];
// Makes the connection request for friendica contacts easier
$_SESSION["fastlane"] = $ret["url"];
$o = replace_macros($tpl, array('$header' => $ret["name"] . " (" . $ret["addr"] . ")", '$photo' => $ret["photo"], '$desc' => "", '$pls_answer' => t('Please answer the following:'), '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'), $ret["name"]), false, '', array(t('No'), t('Yes'))), '$add_note' => t('Add a personal note:'), '$page_desc' => "", '$friendica' => "", '$statusnet' => "", '$diaspora' => "", '$diasnote' => "", '$your_address' => t('Your Identity Address:'), '$invite_desc' => "", '$emailnet' => "", '$submit' => t('Submit Request'), '$cancel' => t('Cancel'), '$nickname' => "", '$name' => $ret["name"], '$url' => $ret["url"], '$myaddr' => $myaddr, '$request' => $request));
return $o;
}
示例4: ostatus_subscribe_content
function ostatus_subscribe_content(&$a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$o = "<h2>" . t("Subsribing to OStatus contacts") . "</h2>";
$uid = local_user();
$a = get_app();
$counter = intval($_REQUEST['counter']);
if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
if ($_REQUEST["url"] == "") {
return $o . t("No contact provided.");
}
$contact = probe_url($_REQUEST["url"]);
if (!$contact) {
return $o . t("Couldn't fetch information for contact.");
}
$api = $contact["baseurl"] . "/api/";
// Fetching friends
$data = z_fetch_url($api . "statuses/friends.json?screen_name=" . $contact["nick"]);
if (!$data["success"]) {
return $o . t("Couldn't fetch friends for contact.");
}
set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
}
$friends = json_decode(get_pconfig($uid, "ostatus", "legacy_friends"));
$total = sizeof($friends);
if ($counter >= $total) {
$a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . $a->get_baseurl() . '/settings/connectors">';
del_pconfig($uid, "ostatus", "legacy_friends");
del_pconfig($uid, "ostatus", "legacy_contact");
$o .= t("Done");
return $o;
}
$friend = $friends[$counter++];
$url = $friend->statusnet_profile_url;
$o .= "<p>" . $counter . "/" . $total . ": " . $url;
$data = probe_url($url);
if ($data["network"] == NETWORK_OSTATUS) {
$result = new_contact($uid, $url, true);
if ($result["success"]) {
$o .= " - " . t("success");
} else {
$o .= " - " . t("failed");
}
} else {
$o .= " - " . t("ignored");
}
$o .= "</p>";
$o .= "<p>" . t("Keep this window open until done.") . "</p>";
$a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . $a->get_baseurl() . '/ostatus_subscribe?counter=' . $counter . '">';
return $o;
}
示例5: acctlink_init
function acctlink_init(&$a)
{
if (x($_GET, 'addr')) {
$addr = trim($_GET['addr']);
$res = probe_url($addr);
//logger('acctlink: ' . print_r($res,true));
if ($res['url']) {
goaway($res['url']);
killme();
}
}
}
示例6: gprobe_run
function gprobe_run(&$argv, &$argc)
{
global $a, $db;
if (is_null($a)) {
$a = new App();
}
if (is_null($db)) {
@(include ".htconfig.php");
require_once "include/dba.php";
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
require_once 'include/session.php';
require_once 'include/datetime.php';
load_config('config');
load_config('system');
$a->set_baseurl(get_config('system', 'url'));
load_hooks();
if ($argc != 2) {
return;
}
$url = hex2bin($argv[1]);
$r = q("select * from gcontact where nurl = '%s' limit 1", dbesc(normalise_link($url)));
logger("gprobe start for " . normalise_link($url), LOGGER_DEBUG);
if (!count($r)) {
// Is it a DDoS attempt?
$urlparts = parse_url($url);
$result = Cache::get("gprobe:" . $urlparts["host"]);
if (!is_null($result)) {
$result = unserialize($result);
if ($result["network"] == NETWORK_FEED) {
logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
return;
}
}
$arr = probe_url($url);
if (is_null($result)) {
Cache::set("gprobe:" . $urlparts["host"], serialize($arr));
}
if (count($arr) && x($arr, 'network') && $arr['network'] === NETWORK_DFRN) {
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`)\n\t\t\t\tvalues ( '%s', '%s', '%s', '%s') ", dbesc($arr['name']), dbesc($arr['url']), dbesc(normalise_link($arr['url'])), dbesc($arr['photo']));
}
$r = q("select * from gcontact where nurl = '%s' limit 1", dbesc(normalise_link($url)));
}
if (count($r)) {
poco_load(0, 0, $r[0]['id'], str_replace('/profile/', '/poco/', $r[0]['url']));
}
logger("gprobe end for " . normalise_link($url), LOGGER_DEBUG);
return;
}
示例7: probe_content
function probe_content(&$a)
{
$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')) {
$addr = trim($_GET['addr']);
$res = probe_url($addr);
$o .= '<pre>';
$o .= str_replace("\n", '<br />', print_r($res, true));
$o .= '</pre>';
}
return $o;
}
示例8: find_diaspora_person_by_handle
function find_diaspora_person_by_handle($handle)
{
$update = false;
$r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1", dbesc(NETWORK_DIASPORA), dbesc($handle));
if (count($r)) {
logger('find_diaspora_person_by handle: in cache ' . print_r($r, true), LOGGER_DEBUG);
// update record occasionally so it doesn't get stale
$d = strtotime($r[0]['updated'] . ' +00:00');
if ($d > strtotime('now - 14 days')) {
return $r[0];
}
$update = true;
}
logger('find_diaspora_person_by_handle: refresh', LOGGER_DEBUG);
require_once 'include/Scrape.php';
$r = probe_url($handle, PROBE_DIASPORA);
if (count($r) && $r['network'] === NETWORK_DIASPORA) {
add_fcontact($r, $update);
return $r;
}
return false;
}
示例9: _contact_update_profile
function _contact_update_profile($contact_id)
{
$r = q("SELECT `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
if (!$r) {
return;
}
$data = probe_url($r[0]["url"]);
// "Feed" is mostly a sign of communication problems
if ($data["network"] == NETWORK_FEED and $data["network"] != $r[0]["network"]) {
return;
}
$updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm", "poco", "network", "alias", "pubkey");
$update = array();
foreach ($updatefields as $field) {
if (isset($data[$field]) and $data[$field] != "") {
$update[$field] = $data[$field];
}
}
$update["nurl"] = normalise_link($data["url"]);
$query = "";
if (isset($data["priority"]) and $data["priority"] != 0) {
$query = "`priority` = " . intval($data["priority"]);
}
foreach ($update as $key => $value) {
if ($query != "") {
$query .= ", ";
}
$query .= "`" . $key . "` = '" . dbesc($value) . "'";
}
if ($query == "") {
return;
}
$r = q("UPDATE `contact` SET {$query} WHERE `id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
$photos = import_profile_photo($data['photo'], local_user(), $contact_id);
$r = q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t`thumb` = '%s',\n\t\t\t`micro` = '%s',\n\t\t\t`name-date` = '%s',\n\t\t\t`uri-date` = '%s',\n\t\t\t`avatar-date` = '%s'\n\t\t\tWHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($contact_id));
}
示例10: handle_tag
/**
* This function removes the tag $tag from the text $body and replaces it with
* the appropiate link.
*
* @param unknown_type $body the text to replace the tag in
* @param unknown_type $inform a comma-seperated string containing everybody to inform
* @param unknown_type $str_tags string to add the tag to
* @param unknown_type $profile_uid
* @param unknown_type $tag the tag to replace
*
* @return boolean true if replaced, false if not replaced
*/
function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "")
{
$replaced = false;
$r = null;
//is it a person tag?
if (strpos($tag, '@') === 0) {
//is it already replaced?
if (strpos($tag, '[url=')) {
//append tag to str_tags
if (!stristr($str_tags, $tag)) {
if (strlen($str_tags)) {
$str_tags .= ',';
}
$str_tags .= $tag;
}
// Checking for the alias that is used for OStatus
$pattern = "/@\\[url\\=(.*?)\\](.*?)\\[\\/url\\]/ism";
if (preg_match($pattern, $tag, $matches)) {
$data = probe_url($matches[1]);
if ($data["alias"] != "") {
$newtag = '@[url=' . $data["alias"] . ']' . $data["name"] . '[/url]';
if (!stristr($str_tags, $newtag)) {
if (strlen($str_tags)) {
$str_tags .= ',';
}
$str_tags .= $newtag;
}
}
}
return $replaced;
}
$stat = false;
//get the person's name
$name = substr($tag, 1);
//is it a link or a full dfrn address?
if (strpos($name, '@') || strpos($name, 'http://')) {
$newname = $name;
//get the profile links
$links = @lrdd($name);
if (count($links)) {
//for all links, collect how is to inform and how's profile is to link
foreach ($links as $link) {
if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
$profile = $link['@attributes']['href'];
}
if ($link['@attributes']['rel'] === 'salmon') {
if (strlen($inform)) {
$inform .= ',';
}
$inform .= 'url:' . str_replace(',', '%2c', $link['@attributes']['href']);
}
}
}
} elseif ($network != NETWORK_OSTATUS and $network != NETWORK_TWITTER and $network != NETWORK_STATUSNET and $network != NETWORK_APPNET) {
//if it is a name rather than an address
$newname = $name;
$alias = '';
$tagcid = 0;
//is it some generated name?
if (strrpos($newname, '+')) {
//get the id
$tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
//remove the next word from tag's name
if (strpos($name, ' ')) {
$name = substr($name, 0, strpos($name, ' '));
}
}
if ($tagcid) {
//if there was an id
//select contact with that id from the logged in user's contact list
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($tagcid), intval($profile_uid));
} else {
$newname = str_replace('_', ' ', $name);
// At first try to fetch a contact according to the given network
if ($network != "") {
//select someone from this user's contacts by name
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), dbesc($network), intval($profile_uid));
if (!$r) {
//select someone by attag or nick and the name passed in
$r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), dbesc($name), dbesc($network), intval($profile_uid));
}
} else {
$r = false;
}
if (!$r) {
//select someone from this user's contacts by name
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval($profile_uid));
}
//.........这里部分代码省略.........
示例11: poco_last_updated
function poco_last_updated($profile, $force = false)
{
$gcontacts = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profile)));
if ($gcontacts[0]["created"] == "0000-00-00 00:00:00") {
q("UPDATE `gcontact` SET `created` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile)));
}
if ($gcontacts[0]["server_url"] != "") {
$server_url = $gcontacts[0]["server_url"];
} else {
$server_url = poco_detect_server($profile);
}
if ($server_url != "") {
if (!poco_check_server($server_url, $gcontacts[0]["network"], $force)) {
if ($force) {
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile)));
}
return false;
}
q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'", dbesc($server_url), dbesc(normalise_link($profile)));
}
if (in_array($gcontacts[0]["network"], array("", NETWORK_FEED))) {
$server = q("SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''", dbesc(normalise_link($server_url)));
if ($server) {
q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'", dbesc($server[0]["network"]), dbesc(normalise_link($profile)));
} else {
return;
}
}
// noscrape is really fast so we don't cache the call.
if ($gcontacts[0]["server_url"] != "" and $gcontacts[0]["nick"] != "") {
// Use noscrape if possible
$server = q("SELECT `noscrape` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
if ($server) {
$noscraperet = z_fetch_url($server[0]["noscrape"] . "/" . $gcontacts[0]["nick"]);
if ($noscraperet["success"] and $noscraperet["body"] != "") {
$noscrape = json_decode($noscraperet["body"], true);
if ($noscrape["fn"] != "" and $noscrape["fn"] != $gcontacts[0]["name"]) {
q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["fn"]), dbesc(normalise_link($profile)));
}
if ($noscrape["photo"] != "" and $noscrape["photo"] != $gcontacts[0]["photo"]) {
q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["photo"]), dbesc(normalise_link($profile)));
}
if ($noscrape["updated"] != "" and $noscrape["updated"] != $gcontacts[0]["updated"]) {
q("UPDATE `gcontact` SET `updated` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["updated"]), dbesc(normalise_link($profile)));
}
if ($noscrape["gender"] != "" and $noscrape["gender"] != $gcontacts[0]["gender"]) {
q("UPDATE `gcontact` SET `gender` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["gender"]), dbesc(normalise_link($profile)));
}
if ($noscrape["pdesc"] != "" and $noscrape["pdesc"] != $gcontacts[0]["about"]) {
q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["pdesc"]), dbesc(normalise_link($profile)));
}
if ($noscrape["about"] != "" and $noscrape["about"] != $gcontacts[0]["about"]) {
q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'", dbesc($noscrape["about"]), dbesc(normalise_link($profile)));
}
if (isset($noscrape["comm"]) and $noscrape["comm"] != $gcontacts[0]["community"]) {
q("UPDATE `gcontact` SET `community` = %d WHERE `nurl` = '%s'", intval($noscrape["comm"]), dbesc(normalise_link($profile)));
}
if (isset($noscrape["tags"])) {
$keywords = implode(" ", $noscrape["tags"]);
} else {
$keywords = "";
}
if ($keywords != "" and $keywords != $gcontacts[0]["keywords"]) {
q("UPDATE `gcontact` SET `keywords` = '%s' WHERE `nurl` = '%s'", dbesc($keywords), dbesc(normalise_link($profile)));
}
$location = $noscrape["locality"];
if ($noscrape["region"] != "") {
if ($location != "") {
$location .= ", ";
}
$location .= $noscrape["region"];
}
if ($noscrape["country-name"] != "") {
if ($location != "") {
$location .= ", ";
}
$location .= $noscrape["country-name"];
}
if ($location != "" and $location != $gcontacts[0]["location"]) {
q("UPDATE `gcontact` SET `location` = '%s' WHERE `nurl` = '%s'", dbesc($location), dbesc(normalise_link($profile)));
}
// If we got data from noscrape then mark the contact as reachable
if (is_array($noscrape) and count($noscrape)) {
q("UPDATE `gcontact` SET `last_contact` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile)));
}
return $noscrape["updated"];
}
}
}
// If we only can poll the feed, then we only do this once a while
if (!$force and !poco_do_update($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
return $gcontacts[0]["updated"];
}
$data = probe_url($profile);
// Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
// Then check the other link and delete this one
if ($data["network"] == NETWORK_OSTATUS and poco_alternate_ostatus_url($profile) and normalise_link($profile) == normalise_link($data["alias"]) and normalise_link($profile) != normalise_link($data["url"])) {
// Delete the old entry
q("DELETE FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profile)));
q("DELETE FROM `glink` WHERE `gcid` = %d", intval($gcontacts[0]["id"]));
//.........这里部分代码省略.........
示例12: dirfind_content
function dirfind_content(&$a, $prefix = "")
{
$community = false;
$discover_user = false;
$local = get_config('system', 'poco_local_search');
$search = $prefix . notags(trim($_REQUEST['search']));
if (strpos($search, '@') === 0) {
$search = substr($search, 1);
if (valid_email($search) and validate_email($search) or substr(normalise_link($search), 0, 7) == "http://") {
$user_data = probe_url($search);
$discover_user = in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA));
}
}
if (strpos($search, '!') === 0) {
$search = substr($search, 1);
$community = true;
}
$o = '';
if ($search) {
if ($discover_user) {
$j = new stdClass();
$j->total = 1;
$j->items_page = 1;
$j->page = $a->pager['page'];
$objresult = new stdClass();
$objresult->cid = 0;
$objresult->name = $user_data["name"];
$objresult->addr = $user_data["addr"];
$objresult->url = $user_data["url"];
$objresult->photo = $user_data["photo"];
$objresult->tags = "";
$objresult->network = $user_data["network"];
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", dbesc(normalise_link($user_data["url"])), intval(local_user()));
if ($contact) {
$objresult->cid = $contact[0]["id"];
}
$j->results[] = $objresult;
poco_check($user_data["url"], $user_data["name"], $user_data["network"], $user_data["photo"], "", "", "", "", "", datetime_convert(), 0);
} elseif ($local) {
if ($community) {
$extra_sql = " AND `community`";
} else {
$extra_sql = "";
}
$perpage = 80;
$startrec = $a->pager['page'] * $perpage - $perpage;
if (get_config('system', 'diaspora_enabled')) {
$diaspora = NETWORK_DIASPORA;
} else {
$diaspora = NETWORK_DFRN;
}
if (!get_config('system', 'ostatus_disabled')) {
$ostatus = NETWORK_OSTATUS;
} else {
$ostatus = NETWORK_DFRN;
}
$count = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND\n\t\t\t\t\t(`url` REGEXP '%s' OR `name` REGEXP '%s' OR `location` REGEXP '%s' OR\n\t\t\t\t\t\t`about` REGEXP '%s' OR `keywords` REGEXP '%s')" . $extra_sql, dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)));
$results = q("SELECT `contact`.`id` AS `cid`, `gcontact`.`url`, `gcontact`.`name`, `gcontact`.`photo`, `gcontact`.`network`, `gcontact`.`keywords`, `gcontact`.`addr`\n\t\t\t\t\tFROM `gcontact`\n\t\t\t\t\tLEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl`\n\t\t\t\t\t\tAND `contact`.`uid` = %d AND NOT `contact`.`blocked`\n\t\t\t\t\t\tAND NOT `contact`.`pending` AND `contact`.`rel` IN ('%s', '%s')\n\t\t\t\t\tWHERE `gcontact`.`network` IN ('%s', '%s', '%s') AND\n\t\t\t\t\t((`gcontact`.`last_contact` >= `gcontact`.`last_failure`) OR (`gcontact`.`updated` >= `gcontact`.`last_failure`)) AND\n\t\t\t\t\t(`gcontact`.`url` REGEXP '%s' OR `gcontact`.`name` REGEXP '%s' OR `gcontact`.`location` REGEXP '%s' OR\n\t\t\t\t\t\t`gcontact`.`about` REGEXP '%s' OR `gcontact`.`keywords` REGEXP '%s') {$extra_sql}\n\t\t\t\t\t\tGROUP BY `gcontact`.`nurl`\n\t\t\t\t\t\tORDER BY `gcontact`.`updated` DESC LIMIT %d, %d", intval(local_user()), dbesc(CONTACT_IS_SHARING), dbesc(CONTACT_IS_FRIEND), dbesc(NETWORK_DFRN), dbesc($ostatus), dbesc($diaspora), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), dbesc(escape_tags($search)), intval($startrec), intval($perpage));
$j = new stdClass();
$j->total = $count[0]["total"];
$j->items_page = $perpage;
$j->page = $a->pager['page'];
foreach ($results as $result) {
if (poco_alternate_ostatus_url($result["url"])) {
continue;
}
if ($result["name"] == "") {
$urlparts = parse_url($result["url"]);
$result["name"] = end(explode("/", $urlparts["path"]));
}
$objresult = new stdClass();
$objresult->cid = $result["cid"];
$objresult->name = $result["name"];
$objresult->addr = $result["addr"];
$objresult->url = $result["url"];
$objresult->photo = $result["photo"];
$objresult->tags = $result["keywords"];
$objresult->network = $result["network"];
$j->results[] = $objresult;
}
// Add found profiles from the global directory to the local directory
proc_run('php', 'include/discover_poco.php', "dirsearch", urlencode($search));
} else {
$p = $a->pager['page'] != 1 ? '&p=' . $a->pager['page'] : '';
if (strlen(get_config('system', 'directory'))) {
$x = fetch_url(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search));
}
$j = json_decode($x);
}
if ($j->total) {
$a->set_pager_total($j->total);
$a->set_pager_itemspage($j->items_page);
}
if (count($j->results)) {
$id = 0;
foreach ($j->results as $jj) {
$alt_text = "";
$contact_details = get_contact_details_by_url($jj->url, local_user());
$itemurl = $contact_details["addr"] != "" ? $contact_details["addr"] : $jj->url;
// If We already know this contact then don't show the "connect" button
//.........这里部分代码省略.........
示例13: probe_url
function probe_url($url, $mode = PROBE_NORMAL, $level = 1)
{
require_once 'include/email.php';
$result = array();
if (!$url) {
return $result;
}
$result = Cache::get("probe_url:" . $mode . ":" . $url);
if (!is_null($result)) {
$result = unserialize($result);
return $result;
}
$network = null;
$diaspora = false;
$diaspora_base = '';
$diaspora_guid = '';
$diaspora_key = '';
$has_lrdd = false;
$email_conversant = false;
$connectornetworks = false;
$appnet = false;
if (strpos($url, 'twitter.com')) {
$connectornetworks = true;
$network = NETWORK_TWITTER;
}
// Twitter is deactivated since twitter closed its old API
//$twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
$lastfm = strpos($url, 'last.fm/user') !== false ? true : false;
$at_addr = strpos($url, '@') !== false ? true : false;
if (!$appnet && !$lastfm && !$connectornetworks) {
if (strpos($url, 'mailto:') !== false && $at_addr) {
$url = str_replace('mailto:', '', $url);
$links = array();
} else {
$links = lrdd($url);
}
if (count($links)) {
$has_lrdd = true;
logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA);
foreach ($links as $link) {
if ($link['@attributes']['rel'] === NAMESPACE_ZOT) {
$zot = unamp($link['@attributes']['href']);
}
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']);
}
if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
$hcard = unamp($link['@attributes']['href']);
}
if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
$profile = unamp($link['@attributes']['href']);
}
if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') {
$poco = unamp($link['@attributes']['href']);
}
if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
$diaspora_base = unamp($link['@attributes']['href']);
$diaspora = true;
}
if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') {
$diaspora_guid = unamp($link['@attributes']['href']);
$diaspora = true;
}
if ($link['@attributes']['rel'] === 'diaspora-public-key') {
$diaspora_key = base64_decode(unamp($link['@attributes']['href']));
if (strstr($diaspora_key, 'RSA ')) {
$pubkey = rsatopem($diaspora_key);
} else {
$pubkey = $diaspora_key;
}
$diaspora = true;
}
if ($link['@attributes']['rel'] === 'http://ostatus.org/schema/1.0/subscribe' and $mode == PROBE_NORMAL) {
$diaspora = false;
}
}
// Status.Net can have more than one profile URL. We need to match the profile URL
// to a contact on incoming messages to prevent spam, and we won't know which one
// to match. So in case of two, one of them is stored as an alias. Only store URL's
// and not webfinger user@host aliases. If they've got more than two non-email style
// aliases, let's hope we're lucky and get one that matches the feed author-uri because
// otherwise we're screwed.
foreach ($links as $link) {
if ($link['@attributes']['rel'] === 'alias') {
if (strpos($link['@attributes']['href'], '@') === false) {
if (isset($profile)) {
if ($link['@attributes']['href'] !== $profile) {
$alias = unamp($link['@attributes']['href']);
}
} else {
$profile = unamp($link['@attributes']['href']);
}
}
}
//.........这里部分代码省略.........
示例14: poco_check
function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid = 0, $uid = 0, $zcid = 0)
{
$a = get_app();
// Generation:
// 0: No definition
// 1: Profiles on this server
// 2: Contacts of profiles on this server
// 3: Contacts of contacts of profiles on this server
// 4: ...
$gcid = "";
if ($profile_url == "") {
return $gcid;
}
// Don't store the statusnet connector as network
// We can't simply set this to NETWORK_OSTATUS since the connector could have fetched posts from friendica as well
if ($network == NETWORK_STATUSNET) {
$network = "";
}
// The global contacts should contain the original picture, not the cached one
if ($generation != 1 and stristr(normalise_link($profile_photo), normalise_link($a->get_baseurl() . "/photo/"))) {
$profile_photo = "";
}
$r = q("SELECT `network` FROM `contact` WHERE `nurl` = '%s' AND `network` != '' AND `network` != '%s' LIMIT 1", dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET));
if (count($r)) {
$network = $r[0]["network"];
}
if ($network == "" or $network == NETWORK_OSTATUS) {
$r = q("SELECT `network`, `url` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `network` != '' AND `network` != '%s' LIMIT 1", dbesc($profile_url), dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET));
if (count($r)) {
$network = $r[0]["network"];
$profile_url = $r[0]["url"];
}
}
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($profile_url)));
if (count($x) and $network == "" and $x[0]["network"] != NETWORK_STATUSNET) {
$network = $x[0]["network"];
}
if ($network == "" or $name == "" or $profile_photo == "") {
require_once "include/Scrape.php";
$data = probe_url($profile_url);
$network = $data["network"];
$name = $data["name"];
$profile_url = $data["url"];
$profile_photo = $data["photo"];
}
if (count($x) and $x[0]["network"] == "" and $network != "") {
q("UPDATE `gcontact` SET `network` = '%s' WHERE `nurl` = '%s'", dbesc($network), dbesc(normalise_link($profile_url)));
}
if ($name == "" or $profile_photo == "") {
return $gcid;
}
if (!in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
return $gcid;
}
logger("profile-check generation: " . $generation . " Network: " . $network . " URL: " . $profile_url . " name: " . $name . " avatar: " . $profile_photo, LOGGER_DEBUG);
if (count($x)) {
$gcid = $x[0]['id'];
if ($location == "" and $x[0]['location'] != "") {
$location = $x[0]['location'];
}
if ($about == "" and $x[0]['about'] != "") {
$about = $x[0]['about'];
}
if ($gender == "" and $x[0]['gender'] != "") {
$gender = $x[0]['gender'];
}
if ($keywords == "" and $x[0]['keywords'] != "") {
$keywords = $x[0]['keywords'];
}
if ($generation == 0 and $x[0]['generation'] > 0) {
$generation = $x[0]['generation'];
}
if ($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
q("UPDATE `gcontact` SET `name` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s',\n\t\t\t\t`updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s', `generation` = %d\n\t\t\t\tWHERE (`generation` >= %d OR `generation` = 0) AND `nurl` = '%s'", dbesc($name), dbesc($network), dbesc($profile_photo), dbesc($connect_url), dbesc($profile_url), dbesc($updated), dbesc($location), dbesc($about), dbesc($keywords), dbesc($gender), intval($generation), intval($generation), dbesc(normalise_link($profile_url)));
}
} else {
q("INSERT INTO `gcontact` (`name`,`network`, `url`,`nurl`,`photo`,`connect`, `updated`, `location`, `about`, `keywords`, `gender`, `generation`)\n\t\t\tVALUES ('%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', %d)", dbesc($name), dbesc($network), dbesc($profile_url), dbesc(normalise_link($profile_url)), dbesc($profile_photo), dbesc($connect_url), dbesc($updated), dbesc($location), dbesc($about), dbesc($keywords), dbesc($gender), intval($generation));
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($profile_url)));
if (count($x)) {
$gcid = $x[0]['id'];
}
}
if (!$gcid) {
return $gcid;
}
$r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1", intval($cid), intval($uid), intval($gcid), intval($zcid));
if (!count($r)) {
q("INSERT INTO `glink` (`cid`,`uid`,`gcid`,`zcid`, `updated`) VALUES (%d,%d,%d,%d, '%s') ", intval($cid), intval($uid), intval($gcid), intval($zcid), dbesc(datetime_convert()));
} else {
q("UPDATE `glink` SET `updated` = '%s' WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d", dbesc(datetime_convert()), intval($cid), intval($uid), intval($gcid), intval($zcid));
}
// For unknown reasons there are sometimes duplicates
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND\n\t\tNOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)", dbesc(normalise_link($profile_url)), intval($gcid));
return $gcid;
}
示例15: follow_init
function follow_init(&$a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$url = $orig_url = notags(trim($_REQUEST['url']));
// remove ajax junk, e.g. Twitter
$url = str_replace('/#!/', '/', $url);
if (!allowed_url($url)) {
notice(t('Disallowed profile URL.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
if (!$url) {
notice(t('Connect URL missing.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$ret = probe_url($url);
if ($ret['network'] === NETWORK_DFRN) {
if (strlen($a->path)) {
$myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
} else {
$myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
}
goaway($ret['request'] . "&addr={$myaddr}");
// NOTREACHED
} else {
if (get_config('system', 'dfrn_only')) {
notice(t('This site is not configured to allow communications with other networks.') . EOL);
notice(t('No compatible communication protocols or feeds were discovered.') . EOL);
goaway($_SESSION['return_url']);
}
}
// do we have enough information?
if (!(x($ret, 'name') && x($ret, 'poll') && (x($ret, 'url') || x($ret, 'addr')))) {
notice(t('The profile address specified does not provide adequate information.') . EOL);
if (!x($ret, 'poll')) {
notice(t('No compatible communication protocols or feeds were discovered.') . EOL);
}
if (!x($ret, 'name')) {
notice(t('An author or name was not found.') . EOL);
}
if (!x($ret, 'url')) {
notice(t('No browser URL could be matched to this address.') . EOL);
}
if (strpos($url, '@') !== false) {
notice('Unable to match @-style Identity Address with a known protocol or email contact');
}
goaway($_SESSION['return_url']);
}
if ($ret['network'] === NETWORK_OSTATUS && get_config('system', 'ostatus_disabled')) {
notice(t('The profile address specified belongs to a network which has been disabled on this site.') . EOL);
$ret['notify'] = '';
}
if (!$ret['notify']) {
notice(t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
}
$writeable = $ret['network'] === NETWORK_OSTATUS && $ret['notify'] ? 1 : 0;
$hidden = $ret['network'] === NETWORK_MAIL ? 1 : 0;
if ($ret['network'] === NETWORK_MAIL) {
$writeable = 1;
}
if ($ret['network'] === NETWORK_DIASPORA) {
$writeable = 1;
}
// check if we already have a contact
// the poll url is more reliable than the profile url, as we may have
// indirect links or webfinger links
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1", intval(local_user()), dbesc($ret['poll']));
if (count($r)) {
// update contact
if ($r[0]['rel'] == CONTACT_IS_FOLLOWER || $network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING) {
q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1", intval(CONTACT_IS_FRIEND), intval($r[0]['id']), intval(local_user()));
}
} else {
$new_relation = $ret['network'] === NETWORK_MAIL ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING;
if ($ret['network'] === NETWORK_DIASPORA) {
$new_relation = CONTACT_IS_FOLLOWER;
}
// create contact record
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `batch`, `notify`, `poll`, `poco`, `name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,\n\t\t\t`writable`, `hidden`, `blocked`, `readonly`, `pending` )\n\t\t\tVALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, 0, 0, 0 ) ", intval(local_user()), dbesc(datetime_convert()), dbesc($ret['url']), dbesc(normalise_link($ret['url'])), dbesc($ret['addr']), dbesc($ret['alias']), dbesc($ret['batch']), dbesc($ret['notify']), dbesc($ret['poll']), dbesc($ret['poco']), dbesc($ret['name']), dbesc($ret['nick']), dbesc($ret['photo']), dbesc($ret['network']), dbesc($ret['pubkey']), intval($new_relation), intval($ret['priority']), intval($writeable), intval($hidden));
}
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($ret['url']), intval(local_user()));
if (!count($r)) {
notice(t('Unable to retrieve contact information.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$contact = $r[0];
$contact_id = $r[0]['id'];
require_once "Photo.php";
$photos = import_profile_photo($ret['photo'], local_user(), $contact_id);
$r = q("UPDATE `contact` SET `photo` = '%s', \n\t\t\t`thumb` = '%s',\n\t\t\t`micro` = '%s', \n\t\t\t`name-date` = '%s', \n\t\t\t`uri-date` = '%s', \n\t\t\t`avatar-date` = '%s'\n\t\t\tWHERE `id` = %d LIMIT 1\n\t\t", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($contact_id));
// pull feed and consume it, which should subscribe to the hub.
proc_run('php', "include/poller.php", "{$contact_id}");
// create a follow slap
$tpl = get_markup_template('follow_slap.tpl');
//.........这里部分代码省略.........