use Friendica\App;
use Friendica\Core\Config;
+use dbm;
+use Cache;
+use xml;
+
+use DomXPath;
+use DOMDocument;
+
require_once 'include/feed.php';
require_once 'include/email.php';
require_once 'include/network.php';
return $newdata;
}
+ /**
+ * @brief Check if the hostname belongs to the own server
+ *
+ * @param string $host The hostname that is to be checked
+ *
+ * @return bool Does the testes hostname belongs to the own server?
+ */
+ private function ownHost($host) {
+ $own_host = get_app()->get_hostname();
+
+ $parts = parse_url($host);
+
+ if (!isset($parts['scheme'])) {
+ $parts = parse_url('http://'.$host);
+ }
+
+ if (!isset($parts['host'])) {
+ return false;
+ }
+ return $parts['host'] == $own_host;
+ }
+
/**
* @brief Probes for XRD data
*
$xrd_timeout = Config::get('system', 'xrd_timeout', 20);
$redirects = 0;
+ logger("Probing for ".$host, LOGGER_DEBUG);
+
$ret = z_fetch_url($ssl_url, false, $redirects, array('timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml'));
- if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
+ if (($ret['errno'] == CURLE_OPERATION_TIMEDOUT) AND !self::ownHost($ssl_url)) {
+ logger("Probing timeout for ".$ssl_url, LOGGER_DEBUG);
return false;
}
$xml = $ret['body'];
if (!is_object($xrd)) {
$ret = z_fetch_url($url, false, $redirects, array('timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml'));
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
+ logger("Probing timeout for ".$url, LOGGER_DEBUG);
return false;
}
$xml = $ret['body'];
$xrd = parse_xml_string($xml, false);
}
if (!is_object($xrd)) {
+ logger("No xrd object found for ".$host, LOGGER_DEBUG);
return false;
}
- $links = \xml::element_to_array($xrd);
+ $links = xml::element_to_array($xrd);
if (!isset($links["xrd"]["link"])) {
+ logger("No xrd data found for ".$host, LOGGER_DEBUG);
return false;
}
self::$baseurl = "http://".$host;
+ logger("Probing successful for ".$host, LOGGER_DEBUG);
+
return $xrd_data;
}
}
if (!$lrdd) {
+ logger("No lrdd data found for ".$uri, LOGGER_DEBUG);
return array();
}
}
if (!is_array($webfinger["links"])) {
+ logger("No webfinger links found for ".$uri, LOGGER_DEBUG);
return false;
}
public static function uri($uri, $network = "", $uid = 0, $cache = true) {
if ($cache) {
- $result = \Cache::get("probe_url:".$network.":".$uri);
+ $result = Cache::get("probe_url:".$network.":".$uri);
if (!is_null($result)) {
return $result;
}
// Only store into the cache if the value seems to be valid
if (!in_array($data['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
- \Cache::set("probe_url:".$network.":".$uri, $data, CACHE_DAY);
+ Cache::set("probe_url:".$network.":".$uri, $data, CACHE_DAY);
/// @todo temporary fix - we need a real contact update function that updates only changing fields
/// The biggest problem is the avatar picture that could have a reduced image size.
$lrdd = self::xrd($host);
}
if (!$lrdd) {
+ logger('No XRD data was found for '.$uri, LOGGER_DEBUG);
return self::feed($uri);
}
$nick = array_pop($path_parts);
$lrdd = self::xrd($host);
if (!$lrdd) {
+ logger('No XRD data was found for '.$uri, LOGGER_DEBUG);
return self::mail($uri, $uid);
}
$addr = $uri;
} else {
+ logger("Uri ".$uri." was not detectable", LOGGER_DEBUG);
return false;
}
$webfinger = json_decode($data, true);
if (!isset($webfinger["links"])) {
+ logger("No json webfinger links for ".$url, LOGGER_DEBUG);
return false;
}
return $webfinger;
}
- $xrd_arr = \xml::element_to_array($xrd);
+ $xrd_arr = xml::element_to_array($xrd);
if (!isset($xrd_arr["xrd"]["link"])) {
+ logger("No XML webfinger links for ".$url, LOGGER_DEBUG);
return false;
}
}
$content = $ret['body'];
if (!$content) {
+ logger("Empty body for ".$noscrape_url, LOGGER_DEBUG);
return false;
}
$json = json_decode($content, true);
if (!is_array($json)) {
+ logger("No json data for ".$noscrape_url, LOGGER_DEBUG);
return false;
}
return false;
}
- $doc = new \DOMDocument();
+ $doc = new DOMDocument();
if (!@$doc->loadHTML($content)) {
return false;
}
- $xpath = new \DomXPath($doc);
+ $xpath = new DomXPath($doc);
$vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
if (!is_object($vcards)) {
*/
private function pumpioProfileData($profile_link) {
- $doc = new \DOMDocument();
+ $doc = new DOMDocument();
if (!@$doc->loadHTMLFile($profile_link)) {
return false;
}
- $xpath = new \DomXPath($doc);
+ $xpath = new DomXPath($doc);
$data = array();
* @return string feed link
*/
private function getFeedLink($url) {
- $doc = new \DOMDocument();
+ $doc = new DOMDocument();
if (!@$doc->loadHTMLFile($url)) {
return false;
}
- $xpath = new \DomXPath($doc);
+ $xpath = new DomXPath($doc);
//$feeds = $xpath->query("/html/head/link[@type='application/rss+xml']");
$feeds = $xpath->query("/html/head/link[@type='application/rss+xml' and @rel='alternate']");
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
- if (\dbm::is_result($x) && \dbm::is_result($r)) {
+ if (dbm::is_result($x) && dbm::is_result($r)) {
$mailbox = construct_mailbox_name($r[0]);
$password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);