]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/DFRN.php
convert line endings
[friendica.git] / src / Protocol / DFRN.php
index db1ded496b7014b7f4cd713439a0d39e42029e31..509d05e6c63431d6368bf8c12bf0a343dab19b19 100644 (file)
@@ -8,30 +8,33 @@
  */
 namespace Friendica\Protocol;
 
-use Friendica\App;
+use Friendica\Content\OEmbed;
 use Friendica\Core\Config;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
-use Friendica\Model\GlobalContact;
-use Friendica\Object\Contact;
-use Friendica\Object\Photo;
-use Friendica\Object\Profile;
+use Friendica\Model\Contact;
+use Friendica\Model\GContact;
+use Friendica\Model\Group;
+use Friendica\Model\Profile;
+use Friendica\Model\Term;
+use Friendica\Model\User;
+use Friendica\Object\Image;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\XML;
 
 use dba;
 use DOMDocument;
-use DomXPath;
+use DOMXPath;
 
+require_once 'boot.php';
+require_once 'include/dba.php';
 require_once "include/enotify.php";
 require_once "include/threads.php";
 require_once "include/items.php";
 require_once "include/tags.php";
-require_once "include/files.php";
 require_once "include/event.php";
 require_once "include/text.php";
-require_once "include/oembed.php";
 require_once "include/html2bbcode.php";
 require_once "include/bbcode.php";
 
@@ -165,7 +168,7 @@ class DFRN
 
                        $contact = $r[0];
                        include_once 'include/security.php';
-                       $groups = init_groups_visitor($contact['id']);
+                       $groups = Group::getIdsByContactId($contact['id']);
 
                        if (count($groups)) {
                                for ($x = 0; $x < count($groups); $x ++)
@@ -340,19 +343,15 @@ class DFRN
                $items = $r;
                $item = $r[0];
 
-               $r = q(
-                       "SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
-                       FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
-                       WHERE `contact`.`self` AND `user`.`uid` = %d LIMIT 1",
-                       intval($item['uid'])
-               );
-
-               if (!DBM::is_result($r)) {
-                       killme();
+               if ($item['uid'] != 0) {
+                       $owner = User::getOwnerDataById($item['uid']);
+                       if (!$owner) {
+                               killme();
+                       }
+               } else {
+                       $owner = ['uid' => 0, 'nick' => 'feed-item'];
                }
 
-               $owner = $r[0];
-
                $doc = new DOMDocument('1.0', 'utf-8');
                $doc->formatOutput = true;
                $type = 'html';
@@ -465,7 +464,7 @@ class DFRN
                /* get site pubkey. this could be a new installation with no site keys*/
                $pubkey = Config::get('system', 'site_pubkey');
                if (! $pubkey) {
-                       $res = new_keypair(1024);
+                       $res = Crypto::newKeypair(1024);
                        Config::set('system', 'site_prvkey', $res['prvkey']);
                        Config::set('system', 'site_pubkey', $res['pubkey']);
                }
@@ -476,7 +475,7 @@ class DFRN
                        $uid
                );
                $photos = array();
-               $ext = Photo::supportedTypes();
+               $ext = Image::supportedTypes();
 
                foreach ($rp as $p) {
                        $photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
@@ -1298,7 +1297,7 @@ class DFRN
                                case 2:
                                        // RINO 2 based on php-encryption
                                        try {
-                                               $key = \Crypto::createNewRandomKey();
+                                               $key = \Crypto::CreateNewRandomKey();
                                        } catch (\CryptoTestFailedException $ex) {
                                                logger('Cannot safely create a key');
                                                return -4;
@@ -1307,7 +1306,7 @@ class DFRN
                                                return -5;
                                        }
                                        try {
-                                               $data = \Crypto::encrypt($postvars['data'], $key);
+                                               $data = \Crypto::Encrypt($postvars['data'], $key);
                                        } catch (\CryptoTestFailedException $ex) {
                                                logger('Cannot safely perform encryption');
                                                return -6;
@@ -1442,7 +1441,7 @@ class DFRN
         * @param bool   $onlyfetch Should the data only be fetched or should it update the contact record as well
         * @param string $xml       optional, default empty
         *
-        * @return Returns an array with relevant data of the author
+        * @return array Relevant data of the author
         * @todo Find good type-hints for all parameter
         */
        private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "")
@@ -1660,7 +1659,7 @@ class DFRN
                                );
                        }
 
-                       Photo::updateContactAvatar(
+                       Contact::updateAvatar(
                                $author["avatar"],
                                $importer["uid"],
                                $contact["id"],
@@ -1678,9 +1677,9 @@ class DFRN
                        $poco["photo"] = $author["avatar"];
                        $poco["hide"] = $hide;
                        $poco["contact-type"] = $contact["contact-type"];
-                       $gcid = GlobalContact::update($poco);
+                       $gcid = GContact::update($poco);
 
-                       GlobalContact::link($gcid, $importer["uid"], $contact["id"]);
+                       GContact::link($gcid, $importer["uid"], $contact["id"]);
                }
 
                return($author);
@@ -1691,7 +1690,7 @@ class DFRN
         *
         * @param object $xpath    XPath object
         * @param object $activity Activity object
-        * @param text   $element  element name
+        * @param string $element  element name
         *
         * @return string XML string
         * @todo Find good type-hints for all parameter
@@ -2035,7 +2034,7 @@ class DFRN
                        dbesc(normalise_link($old["url"]))
                );
 
-               Photo::updateContactAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
+               Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
 
                if ($x === false) {
                        return false;
@@ -2499,19 +2498,20 @@ class DFRN
 
                /// @todo Do we really need this check for HTML elements? (It was copied from the old function)
                if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) {
+                       $base_url = get_app()->get_baseurl();
                        $item['body'] = reltoabs($item['body'], $base_url);
 
                        $item['body'] = html2bb_video($item['body']);
 
-                       $item['body'] = oembed_html2bbcode($item['body']);
+                       $item['body'] = OEmbed::HTML2BBCode($item['body']);
 
-                       $config = HTMLPurifier_Config::createDefault();
+                       $config = \HTMLPurifier_Config::createDefault();
                        $config->set('Cache.DefinitionImpl', null);
 
                        // we shouldn't need a whitelist, because the bbcode converter
                        // will strip out any unsupported tags.
 
-                       $purifier = new HTMLPurifier($config);
+                       $purifier = new \HTMLPurifier($config);
                        $item['body'] = $purifier->purify($item['body']);
 
                        $item['body'] = @html2bbcode($item['body']);
@@ -2912,7 +2912,7 @@ class DFRN
                                        intval($importer["uid"])
                                );
                                create_tags_from_itemuri($uri, $importer["uid"]);
-                               create_files_from_itemuri($uri, $importer["uid"]);
+                               Term::createFromItemURI($uri, $importer["uid"]);
                                update_thread_uri($uri, $importer["uid"]);
                        } else {
                                $r = q(
@@ -2925,7 +2925,7 @@ class DFRN
                                        intval($importer["uid"])
                                );
                                create_tags_from_itemuri($uri, $importer["uid"]);
-                               create_files_from_itemuri($uri, $importer["uid"]);
+                               Term::createFromItemURI($uri, $importer["uid"]);
                                update_thread_uri($uri, $importer["importer_uid"]);
                                if ($item["last-child"]) {
                                        // ensure that last-child is set in case the comment that had it just got wiped.
@@ -2962,9 +2962,9 @@ class DFRN
        /**
         * @brief Imports a DFRN message
         *
-        * @param text  $xml          The DFRN message
-        * @param array $importer     Record of the importer user mixed with contact of the content
-        * @param bool  $sort_by_date Is used when feeds are polled
+        * @param string $xml          The DFRN message
+        * @param array  $importer     Record of the importer user mixed with contact of the content
+        * @param bool   $sort_by_date Is used when feeds are polled
         * @return integer Import status
         * @todo set proper type-hints
         */
@@ -2977,7 +2977,7 @@ class DFRN
                $doc = new DOMDocument();
                @$doc->loadXML($xml);
 
-               $xpath = new DomXPath($doc);
+               $xpath = new DOMXPath($doc);
                $xpath->registerNamespace("atom", NAMESPACE_ATOM1);
                $xpath->registerNamespace("thr", NAMESPACE_THREAD);
                $xpath->registerNamespace("at", NAMESPACE_TOMB);
@@ -3013,7 +3013,7 @@ class DFRN
 
                // The account type is new since 3.5.1
                if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) {
-                       $accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()", $context)->item(0)->nodeValue);
+                       $accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()")->item(0)->nodeValue);
 
                        if ($accounttype != $importer["contact-type"]) {
                                dba::update('contact', array('contact-type' => $accounttype), array('id' => $importer["id"]));
@@ -3022,7 +3022,7 @@ class DFRN
 
                // is it a public forum? Private forums aren't supported with this method
                // This is deprecated since 3.5.1
-               $forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()", $context)->item(0)->nodeValue);
+               $forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()")->item(0)->nodeValue);
 
                if ($forum != $importer["forum"]) {
                        $condition = array('`forum` != ? AND `id` = ?', $forum, $importer["id"]);