]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Move Object\Contact to Model\Contact
[friendica.git] / include / items.php
index ed2204f608db4a79197f6a0c783ebf966f742e58..44fca51d8f9713648b06bf42157f38c44bb2548d 100644 (file)
@@ -1,34 +1,30 @@
 <?php
-
 /**
  * @file include/items.php
  */
-
 use Friendica\App;
 use Friendica\ParseUrl;
+use Friendica\Content\Feature;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Core\Worker;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Model\Contact;
 use Friendica\Model\GlobalContact;
+use Friendica\Object\Image;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\OStatus;
-use Friendica\Util\Lock;
 
 require_once 'include/bbcode.php';
 require_once 'include/oembed.php';
-require_once 'include/salmon.php';
 require_once 'include/crypto.php';
-require_once 'include/Photo.php';
 require_once 'include/tags.php';
 require_once 'include/files.php';
 require_once 'include/text.php';
-require_once 'include/email.php';
 require_once 'include/threads.php';
 require_once 'include/plaintext.php';
 require_once 'include/feed.php';
-require_once 'include/Contact.php';
 require_once 'mod/share.php';
 require_once 'include/enotify.php';
 require_once 'include/group.php';
@@ -207,7 +203,8 @@ function add_page_info_data($data) {
                $preview = str_replace(array("[", "]"), array("&#91;", "&#93;"), htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false));
                // if the preview picture is larger than 500 pixels then show it in a larger mode
                // But only, if the picture isn't higher than large (To prevent huge posts)
-               if (($data["images"][0]["width"] >= 500) && ($data["images"][0]["width"] >= $data["images"][0]["height"])) {
+               if (!Config::get('system', 'always_show_preview') && ($data["images"][0]["width"] >= 500)
+                       && ($data["images"][0]["width"] >= $data["images"][0]["height"])) {
                        $text .= " image='".$preview."'";
                } else {
                        $text .= " preview='".$preview."'";
@@ -426,7 +423,7 @@ function uri_to_guid($uri, $host = "") {
  * @return array Item array with removed conversation data
  */
 function store_conversation($arr) {
-       if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
+       if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)) && !empty($arr['uri'])) {
                $conversation = array('item-uri' => $arr['uri'], 'received' => DBM::date());
 
                if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
@@ -718,12 +715,12 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
                 * This is done only for comments (See below explanation at "gcontact-id")
                 */
                if ($arr['parent-uri'] != $arr['uri']) {
-                       $arr["contact-id"] = get_contact($arr['author-link'], $uid);
+                       $arr["contact-id"] = Contact::getIdForURL($arr['author-link'], $uid);
                }
 
                // If not present then maybe the owner was found
                if ($arr["contact-id"] == 0) {
-                       $arr["contact-id"] = get_contact($arr['owner-link'], $uid);
+                       $arr["contact-id"] = Contact::getIdForURL($arr['owner-link'], $uid);
                }
 
                // Still missing? Then use the "self" contact of the current user
@@ -754,19 +751,19 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
        }
 
        if ($arr["author-id"] == 0) {
-               $arr["author-id"] = get_contact($arr["author-link"], 0);
+               $arr["author-id"] = Contact::getIdForURL($arr["author-link"], 0);
        }
 
-       if (blockedContact($arr["author-id"])) {
+       if (Contact::isBlocked($arr["author-id"])) {
                logger('Contact '.$arr["author-id"].' is blocked, item '.$arr["uri"].' will not be stored');
                return 0;
        }
 
        if ($arr["owner-id"] == 0) {
-               $arr["owner-id"] = get_contact($arr["owner-link"], 0);
+               $arr["owner-id"] = Contact::getIdForURL($arr["owner-link"], 0);
        }
 
-       if (blockedContact($arr["owner-id"])) {
+       if (Contact::isBlocked($arr["owner-id"])) {
                logger('Contact '.$arr["owner-id"].' is blocked, item '.$arr["uri"].' will not be stored');
                return 0;
        }
@@ -1154,6 +1151,19 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
  * @param array $arr Contains the just posted item record
  */
 function item_set_last_item($arr) {
+       // Unarchive the author
+       $contact = dba::select('contact', [], ['id' => $arr["author-link"]], ['limit' => 1]);
+       if ($contact['term-date'] > NULL_DATE) {
+                Contact::unmarkForArchival($contact);
+       }
+
+       // Unarchive the contact if it is a toplevel posting
+       if ($arr["parent-uri"] === $arr["uri"]) {
+               $contact = dba::select('contact', [], ['id' => $arr["contact-id"]], ['limit' => 1]);
+               if ($contact['term-date'] > NULL_DATE) {
+                        Contact::unmarkForArchival($contact);
+               }
+       }
 
        $update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
 
@@ -1682,8 +1692,8 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
                        dbesc($name),
                        dbesc($nick),
                        dbesc($photo),
-                       dbesc(($sharing) ? NETWORK_ZOT : NETWORK_OSTATUS),
-                       intval(($sharing) ? CONTACT_IS_SHARING : CONTACT_IS_FOLLOWER)
+                       dbesc(NETWORK_OSTATUS),
+                       intval(CONTACT_IS_FOLLOWER)
                );
                $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
                                intval($importer['uid']),
@@ -1691,7 +1701,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
                );
                if (DBM::is_result($r)) {
                        $contact_record = $r[0];
-                       update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true);
+                       Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
                }
 
                /// @TODO Encapsulate this into a function/method
@@ -1750,7 +1760,7 @@ function lose_follower($importer, $contact, array $datarray = array(), $item = "
        if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) {
                dba::update('contact', array('rel' => CONTACT_IS_SHARING), array('id' => $contact['id']));
        } else {
-               contact_remove($contact['id']);
+               Contact::remove($contact['id']);
        }
 }
 
@@ -1759,7 +1769,7 @@ function lose_sharer($importer, $contact, array $datarray = array(), $item = "")
        if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) {
                dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
        } else {
-               contact_remove($contact['id']);
+               Contact::remove($contact['id']);
        }
 }
 
@@ -1877,11 +1887,11 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
                                                        $width = intval($match[1]);
                                                        $height = intval($match[2]);
 
-                                                       $ph = new Photo($data, $type);
-                                                       if ($ph->is_valid()) {
-                                                               $ph->scaleImage(max($width, $height));
-                                                               $data = $ph->imageString();
-                                                               $type = $ph->getType();
+                                                       $Image = new Image($data, $type);
+                                                       if ($Image->isValid()) {
+                                                               $Image->scaleDown(max($width, $height));
+                                                               $data = $Image->asString();
+                                                               $type = $Image->getType();
                                                        }
                                                }
 
@@ -2122,7 +2132,7 @@ function drop_item($id, $interactive = true) {
        }
 
 
-       if ((local_user() == $item['uid']) || ($contact_id) || (! $interactive)) {
+       if ((local_user() == $item['uid']) || $contact_id || !$interactive) {
 
                // Check if we should do HTML-based delete confirmation
                if ($_REQUEST['confirm']) {
@@ -2189,30 +2199,18 @@ function drop_item($id, $interactive = true) {
                 * generate a resource-id and therefore aren't intimately linked to the item.
                 */
                if (strlen($item['resource-id'])) {
-                       q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
-                               dbesc($item['resource-id']),
-                               intval($item['uid'])
-                       );
-                       // ignore the result
+                       dba::delete('photo', array('resource-id' => $item['resource-id'], 'uid' => $item['uid']));
                }
 
                // If item is a link to an event, nuke the event record.
                if (intval($item['event-id'])) {
-                       q("DELETE FROM `event` WHERE `id` = %d AND `uid` = %d",
-                               intval($item['event-id']),
-                               intval($item['uid'])
-                       );
-                       // ignore the result
+                       dba::delete('event', array('id' => $item['event-id'], 'uid' => $item['uid']));
                }
 
                // If item has attachments, drop them
                foreach (explode(", ", $item['attach']) as $attach) {
                        preg_match("|attach/(\d+)|", $attach, $matches);
-                       q("DELETE FROM `attach` WHERE `id` = %d AND `uid` = %d",
-                               intval($matches[1]),
-                               local_user()
-                       );
-                       // ignore the result
+                       dba::delete('attach', array('id' => $matches[1], 'uid' => $item['uid']));
                }
 
                // The new code splits the queries since the mysql optimizer really has bad problems with subqueries
@@ -2235,7 +2233,6 @@ function drop_item($id, $interactive = true) {
 
                // Now delete them
                if ($parentid != "") {
-                       $r = q("DELETE FROM `item_id` WHERE `iid` IN (%s)", dbesc($parentid));
                        $r = q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
                }
 
@@ -2371,7 +2368,7 @@ function posted_dates($uid, $wall) {
 function posted_date_widget($url, $uid, $wall) {
        $o = '';
 
-       if (! feature_enabled($uid, 'archives')) {
+       if (! Feature::isEnabled($uid, 'archives')) {
                return $o;
        }