]> git.mxchange.org Git - friendica.git/commitdiff
Removed the legacy function calls, removed unused functions
authorMichael Vogel <icarus@dabo.de>
Mon, 4 Jul 2016 06:05:30 +0000 (08:05 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 4 Jul 2016 06:05:30 +0000 (08:05 +0200)
include/Probe.php
include/Scrape.php
include/network.php
include/socgraph.php
mod/dfrn_request.php

index 51349c4f06dd379da9e7bfde3de9adcb6843b3f3..7619a127fb9a107104d95a97767019943faec5a4 100644 (file)
@@ -9,6 +9,7 @@ use \Friendica\Core\PConfig;
 
 require_once("include/feed.php");
 require_once('include/email.php');
+require_once('include/network.php');
 
 class Probe {
 
@@ -82,12 +83,14 @@ class Probe {
                return $xrd_data;
        }
 
-       public static function uri($uri, $network = "") {
+       public static function uri($uri, $network = "", $cache = true) {
 
-               $result = Cache::get("probe_url:".$network.":".$uri);
-               if (!is_null($result)) {
-                       $result = unserialize($result);
-                       return $result;
+               if ($cache) {
+                       $result = Cache::get("probe_url:".$network.":".$uri);
+                       if (!is_null($result)) {
+                               $result = unserialize($result);
+                               return $result;
+                       }
                }
 
                $data = self::detect($uri, $network);
@@ -336,6 +339,50 @@ class Probe {
                return $data;
        }
 
+       public static function valid_dfrn($data) {
+               $errors = 0;
+               if(!isset($data['key']))
+                       $errors ++;
+               if(!isset($data['dfrn-request']))
+                       $errors ++;
+               if(!isset($data['dfrn-confirm']))
+                       $errors ++;
+               if(!isset($data['dfrn-notify']))
+                       $errors ++;
+               if(!isset($data['dfrn-poll']))
+                       $errors ++;
+               return $errors;
+       }
+
+       public static function profile($profile) {
+
+               $data = array();
+
+               // Fetch data via noscrape - this is faster
+               $noscrape = str_replace(array("/hcard/", "/profile/"), "/noscrape/", $profile);
+               $data = self::poll_noscrape($noscrape, $data);
+
+               if (!isset($data["notify"]) OR !isset($data["confirm"]) OR
+                       !isset($data["request"]) OR !isset($data["poll"]) OR
+                       !isset($data["poco"]) OR !isset($data["name"]) OR
+                       !isset($data["photo"]))
+                       $data = self::poll_hcard($profile, $data, true);
+
+               $prof_data = array();
+               $prof_data["addr"] = $data["addr"];
+               $prof_data["nick"] = $data["nick"];
+               $prof_data["dfrn-request"] = $data["request"];
+               $prof_data["dfrn-confirm"] = $data["confirm"];
+               $prof_data["dfrn-notify"] = $data["notify"];
+               $prof_data["dfrn-poll"] = $data["poll"];
+               $prof_data["dfrn-poco"] = $data["poco"];
+               $prof_data["photo"] = $data["photo"];
+               $prof_data["fn"] = $data["name"];
+               $prof_data["key"] = $data["pubkey"];
+
+               return $prof_data;
+       }
+
        private function dfrn($webfinger) {
 
                $hcard = "";
index 5c176fa36be1cedced589f72819f65ad57bc1346..bb9af60d703b355ecea490d2ad431041898d7ead 100644 (file)
@@ -1,144 +1,6 @@
 <?php
-
-require_once('library/HTML5/Parser.php');
-require_once('include/crypto.php');
-require_once('include/feed.php');
 require_once('include/Probe.php');
 
-if(! function_exists('scrape_dfrn')) {
-function scrape_dfrn($url, $dont_probe = false) {
-
-       $a = get_app();
-
-       $ret = array();
-
-       logger('scrape_dfrn: url=' . $url);
-
-       // Try to fetch the data from noscrape. This is faster than parsing the HTML
-       $noscrape = str_replace("/hcard/", "/noscrape/", $url);
-       $noscrapejson = fetch_url($noscrape);
-       $noscrapedata = array();
-       if ($noscrapejson) {
-               $noscrapedata = json_decode($noscrapejson, true);
-
-               if (is_array($noscrapedata)) {
-                       if ($noscrapedata["nick"] != "")
-                               return($noscrapedata);
-                       else
-                               unset($noscrapedata["nick"]);
-               } else
-                       $noscrapedata = array();
-       }
-
-       $s = fetch_url($url);
-
-       if (!$s)
-               return $ret;
-
-       if (!$dont_probe) {
-               $probe = probe_url($url);
-
-               if (isset($probe["addr"]))
-                       $ret["addr"] = $probe["addr"];
-       }
-
-       $headers = $a->get_curl_headers();
-       logger('scrape_dfrn: headers=' . $headers, LOGGER_DEBUG);
-
-
-       $lines = explode("\n",$headers);
-       if(count($lines)) {
-               foreach($lines as $line) {
-                       // don't try and run feeds through the html5 parser
-                       if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
-                               return ret;
-               }
-       }
-
-       try {
-               $dom = HTML5_Parser::parse($s);
-       } catch (DOMException $e) {
-               logger('scrape_dfrn: parse error: ' . $e);
-       }
-
-       if(! $dom)
-               return $ret;
-
-       $items = $dom->getElementsByTagName('link');
-
-       // get DFRN link elements
-
-       foreach($items as $item) {
-               $x = $item->getAttribute('rel');
-               if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
-                       $ret['feed_atom'] = $item->getAttribute('href');
-               if(substr($x,0,5) == "dfrn-") {
-                       $ret[$x] = $item->getAttribute('href');
-               }
-               if($x === 'lrdd') {
-                       $decoded = urldecode($item->getAttribute('href'));
-                       if(preg_match('/acct:([^@]*)@/',$decoded,$matches))
-                               $ret['nick'] = $matches[1];
-               }
-       }
-
-       // Pull out hCard profile elements
-
-       $largest_photo = 0;
-
-       $items = $dom->getElementsByTagName('*');
-       foreach($items as $item) {
-               if(attribute_contains($item->getAttribute('class'), 'vcard')) {
-                       $level2 = $item->getElementsByTagName('*');
-                       foreach($level2 as $x) {
-                               if(attribute_contains($x->getAttribute('class'),'uid'))
-                                       $ret['guid'] = $x->textContent;
-                               if(attribute_contains($x->getAttribute('class'),'nickname'))
-                                       $ret['nickname'] = $x->textContent;
-                               if(attribute_contains($x->getAttribute('class'),'fn'))
-                                       $ret['fn'] = $x->textContent;
-                               if(attribute_contains($x->getAttribute('class'),'searchable'))
-                                       $ret['searchable'] = $x->textContent;
-                               if(attribute_contains($x->getAttribute('class'),'key'))
-                                       $ret['key'] = $x->textContent;
-                               if(attribute_contains($x->getAttribute('class'),'url'))
-                                       $ret['url'] = $x->textContent;
-                               if((attribute_contains($x->getAttribute('class'),'photo'))
-                                       || (attribute_contains($x->getAttribute('class'),'avatar'))) {
-                                       $size = intval($x->getAttribute('width'));
-                                       // dfrn prefers 175, so if we find this, we set largest_size so it can't be topped.
-                                       if(($size > $largest_photo) || ($size == 175) || (! $largest_photo)) {
-                                               $ret['photo'] = $x->getAttribute('src');
-                                               $largest_photo = (($size == 175) ? 9999 : $size);
-                                       }
-                               }
-                       }
-               }
-       }
-       return array_merge($ret, $noscrapedata);
-}}
-
-
-
-
-
-
-if(! function_exists('validate_dfrn')) {
-function validate_dfrn($a) {
-       $errors = 0;
-       if(! x($a,'key'))
-               $errors ++;
-       if(! x($a,'dfrn-request'))
-               $errors ++;
-       if(! x($a,'dfrn-confirm'))
-               $errors ++;
-       if(! x($a,'dfrn-notify'))
-               $errors ++;
-       if(! x($a,'dfrn-poll'))
-               $errors ++;
-       return $errors;
-}}
-
 /**
  *
  * Probe a network address to discover what kind of protocols we need to communicate with it.
@@ -157,7 +19,6 @@ function validate_dfrn($a) {
  *
  */
 
-
 define('PROBE_NORMAL',   0);
 define('PROBE_DIASPORA', 1);
 
@@ -172,57 +33,3 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
 
        return $data;
 }
-
-/**
- * @brief Find the matching part between two url
- *
- * @param string $url1
- * @param string $url2
- * @return string The matching part
- */
-function matching_url($url1, $url2) {
-
-       if (($url1 == "") OR ($url2 == ""))
-               return "";
-
-       $url1 = normalise_link($url1);
-       $url2 = normalise_link($url2);
-
-       $parts1 = parse_url($url1);
-       $parts2 = parse_url($url2);
-
-       if (!isset($parts1["host"]) OR !isset($parts2["host"]))
-               return "";
-
-       if ($parts1["scheme"] != $parts2["scheme"])
-               return "";
-
-       if ($parts1["host"] != $parts2["host"])
-               return "";
-
-       if ($parts1["port"] != $parts2["port"])
-               return "";
-
-       $match = $parts1["scheme"]."://".$parts1["host"];
-
-       if ($parts1["port"])
-               $match .= ":".$parts1["port"];
-
-       $pathparts1 = explode("/", $parts1["path"]);
-       $pathparts2 = explode("/", $parts2["path"]);
-
-       $i = 0;
-       $path = "";
-       do {
-               $path1 = $pathparts1[$i];
-               $path2 = $pathparts2[$i];
-
-               if ($path1 == $path2)
-                       $path .= $path1."/";
-
-       } while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
-
-       $match .= $path;
-
-       return normalise_link($match);
-}
index d27a090fe247543af2a10cec5a01f580448873db..64b6d07c6c623076ce444666b90fe924e0c03295 100644 (file)
@@ -1123,7 +1123,7 @@ function short_link($url) {
  * This function encodes an array to json format
  * and adds an application/json HTTP header to the output.
  * After finishing the process is getting killed.
- * 
+ *
  * @param array $x The input content
  */
 function json_return_and_die($x) {
@@ -1131,3 +1131,57 @@ function json_return_and_die($x) {
        echo json_encode($x);
        killme();
 }
+
+/**
+ * @brief Find the matching part between two url
+ *
+ * @param string $url1
+ * @param string $url2
+ * @return string The matching part
+ */
+function matching_url($url1, $url2) {
+
+       if (($url1 == "") OR ($url2 == ""))
+               return "";
+
+       $url1 = normalise_link($url1);
+       $url2 = normalise_link($url2);
+
+       $parts1 = parse_url($url1);
+       $parts2 = parse_url($url2);
+
+       if (!isset($parts1["host"]) OR !isset($parts2["host"]))
+               return "";
+
+       if ($parts1["scheme"] != $parts2["scheme"])
+               return "";
+
+       if ($parts1["host"] != $parts2["host"])
+               return "";
+
+       if ($parts1["port"] != $parts2["port"])
+               return "";
+
+       $match = $parts1["scheme"]."://".$parts1["host"];
+
+       if ($parts1["port"])
+               $match .= ":".$parts1["port"];
+
+       $pathparts1 = explode("/", $parts1["path"]);
+       $pathparts2 = explode("/", $parts2["path"]);
+
+       $i = 0;
+       $path = "";
+       do {
+               $path1 = $pathparts1[$i];
+               $path2 = $pathparts2[$i];
+
+               if ($path1 == $path2)
+                       $path .= $path1."/";
+
+       } while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
+
+       $match .= $path;
+
+       return normalise_link($match);
+}
index 3718f82306fc7336e8d7db61747bacc540744b2c..cb2fd97b39b33140f4ef69675e34ad08a839b29a 100644 (file)
@@ -9,6 +9,7 @@
 
 require_once('include/datetime.php');
 require_once("include/Scrape.php");
+require_once("include/network.php");
 require_once("include/html2bbcode.php");
 require_once("include/Contact.php");
 require_once("include/Photo.php");
index 2a9f68eabd7f8e82ed24903295475d03df925c1c..20c47bebf08db188555db27db9c9cc8bfa556dd5 100644 (file)
@@ -11,6 +11,7 @@
 
 require_once('include/enotify.php');
 require_once('include/Scrape.php');
+require_once('include/Probe.php');
 require_once('include/group.php');
 
 if(! function_exists('dfrn_request_init')) {
@@ -116,7 +117,7 @@ function dfrn_request_post(&$a) {
                                         * Scrape the other site's profile page to pick up the dfrn links, key, fn, and photo
                                         */
 
-                                       $parms = scrape_dfrn($dfrn_url);
+                                       $parms = Probe::profile($dfrn_url);
 
                                        if(! count($parms)) {
                                                notice( t('Profile location is not valid or does not contain profile information.') . EOL );
@@ -127,7 +128,7 @@ function dfrn_request_post(&$a) {
                                                        notice( t('Warning: profile location has no identifiable owner name.') . EOL );
                                                if(! x($parms,'photo'))
                                                        notice( t('Warning: profile location has no profile photo.') . EOL );
-                                               $invalid = validate_dfrn($parms);
+                                               $invalid = Probe::valid_dfrn($parms);
                                                if($invalid) {
                                                        notice( sprintf( tt("%d required parameter was not found at the given location",
                                                                                                "%d required parameters were not found at the given location",
@@ -511,7 +512,7 @@ function dfrn_request_post(&$a) {
 
                                require_once('include/Scrape.php');
 
-                               $parms = scrape_dfrn(($hcard) ? $hcard : $url);
+                               $parms = Probe::profile(($hcard) ? $hcard : $url);
 
                                if(! count($parms)) {
                                        notice( t('Profile location is not valid or does not contain profile information.') . EOL );
@@ -522,7 +523,7 @@ function dfrn_request_post(&$a) {
                                                notice( t('Warning: profile location has no identifiable owner name.') . EOL );
                                        if(! x($parms,'photo'))
                                                notice( t('Warning: profile location has no profile photo.') . EOL );
-                                       $invalid = validate_dfrn($parms);
+                                       $invalid = Probe::valid_dfrn($parms);
                                        if($invalid) {
                                                notice( sprintf( tt("%d required parameter was not found at the given location",
                                                                                        "%d required parameters were not found at the given location",