]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
using the recycle sign instead of "RD" for statusnet.
[friendica.git] / include / items.php
old mode 100755 (executable)
new mode 100644 (file)
index 76bcbc7..d71c0e2
@@ -438,6 +438,12 @@ function get_atom_elements($feed, $item, $contact = array()) {
        $res['body'] = unxmlify($item->get_content());
        $res['plink'] = unxmlify($item->get_link(0));
 
+       if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND strstr($res['plink'], ".app.net/")) {
+               logger("get_atom_elements: detected app.net posting: ".print_r($res, true), LOGGER_DEBUG);
+               $res['title'] = "";
+               $res['body'] = nl2br($res['body']);
+       }
+
        // removing the content of the title if its identically to the body
        // This helps with auto generated titles e.g. from tumblr
        if (title_is_body($res["title"], $res["body"]))
@@ -860,26 +866,23 @@ function get_atom_elements($feed, $item, $contact = array()) {
                $res["title"] = "";
        } elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_OSTATUS))
                $res["body"] = add_page_info_to_body($res["body"]);
+       elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND strstr($res['plink'], ".app.net/")) {
+               $res["body"] = add_page_info_to_body($res["body"]);
+       }
 
        $arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
 
        call_hooks('parse_atom', $arr);
 
-       //if (($res["title"] != "") or (strpos($res["body"], "RT @") > 0)) {
-       //if (strpos($res["body"], "RT @") !== false) {
-       /*if (strpos($res["body"], "@") !== false) {
-               $debugfile = tempnam("/var/www/virtual/pirati.ca/phptmp/", "item-res2-");
-               file_put_contents($debugfile, serialize($arr));
-       }*/
-
        return $res;
 }
 
-function add_page_info($url, $no_photos = false) {
-        require_once("mod/parse_url.php");
-        $data = parseurl_getsiteinfo($url, true);
+function add_page_info($url, $no_photos = false, $photo = "") {
+       require_once("mod/parse_url.php");
 
-        logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG);
+       $data = parseurl_getsiteinfo($url, true);
+
+       logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG);
 
        // It maybe is a rich content, but if it does have everything that a link has,
        // then treat it that way
@@ -887,51 +890,53 @@ function add_page_info($url, $no_photos = false) {
                is_string($data["text"]) AND (sizeof($data["images"]) > 0))
                $data["type"] = "link";
 
-        if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $url))
-                return("");
+       if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $url))
+               return("");
 
        if ($no_photos AND ($data["type"] == "photo"))
                return("");
 
-        if (($data["type"] != "photo") AND is_string($data["title"]))
-                $text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]";
+       if (($data["type"] != "photo") AND is_string($data["title"]))
+               $text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]";
 
-        if (($data["type"] != "video") AND (sizeof($data["images"]) > 0)) {
-                $imagedata = $data["images"][0];
-                $text .= '[img]'.$imagedata["src"].'[/img]';
-        }
+       if (($data["type"] != "video") AND ($photo != ""))
+               $text .= '[img]'.$photo.'[/img]';
+       elseif (($data["type"] != "video") AND (sizeof($data["images"]) > 0)) {
+               $imagedata = $data["images"][0];
+               $text .= '[img]'.$imagedata["src"].'[/img]';
+       }
 
-        if (($data["type"] != "photo") AND is_string($data["text"]))
-                $text .= "[quote]".$data["text"]."[/quote]";
+       if (($data["type"] != "photo") AND is_string($data["text"]))
+               $text .= "[quote]".$data["text"]."[/quote]";
 
-        return("\n[class=type-".$data["type"]."]".$text."[/class]");
+       return("\n[class=type-".$data["type"]."]".$text."[/class]");
 }
 
 function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
 
-        logger('add_page_info_to_body: fetch page info for body '.$body, LOGGER_DEBUG);
+       logger('add_page_info_to_body: fetch page info for body '.$body, LOGGER_DEBUG);
 
-        $URLSearchString = "^\[\]";
+       $URLSearchString = "^\[\]";
 
-        // Adding these spaces is a quick hack due to my problems with regular expressions :)
-        preg_match("/[^!#@]\[url\]([$URLSearchString]*)\[\/url\]/ism", " ".$body, $matches);
+       // Adding these spaces is a quick hack due to my problems with regular expressions :)
+       preg_match("/[^!#@]\[url\]([$URLSearchString]*)\[\/url\]/ism", " ".$body, $matches);
 
-        if (!$matches)
-                preg_match("/[^!#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", " ".$body, $matches);
+       if (!$matches)
+               preg_match("/[^!#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", " ".$body, $matches);
 
        // Convert urls without bbcode elements
        if (!$matches AND $texturl) {
                preg_match("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", " ".$body, $matches);
 
                // Yeah, a hack. I really hate regular expressions :)
-               if ($matches)
-                       $matches[1] = $matches[2];
+               if ($matches)
+                       $matches[1] = $matches[2];
        }
 
-        if ($matches)
-                $body .= add_page_info($matches[1], $no_photos);
+       if ($matches)
+               $body .= add_page_info($matches[1], $no_photos);
 
-        return $body;
+       return $body;
 }
 
 function encode_rel_links($links) {
@@ -974,7 +979,7 @@ function item_store($arr,$force_parent = false) {
 
        if (isset($arr["ostatus_conversation"])) {
                $ostatus_conversation = $arr["ostatus_conversation"];
-               unset($arr["ostatus_conversation"]);
+               unset($arr["ostatus_conversation"]);
        }
 
        if(x($arr, 'gravity'))
@@ -1006,6 +1011,19 @@ function item_store($arr,$force_parent = false) {
                }
        }
 
+       // If there is no guid then take the same guid that was taken before for the same uri
+       if ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "")) {
+               logger('item_store: checking for an existing guid for uri '.$arr['uri'], LOGGER_DEBUG);
+               $r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `guid` != '' LIMIT 1",
+                       dbesc(trim($arr['uri']))
+               );
+
+               if(count($r)) {
+                       $arr['guid'] = $r[0]["guid"];
+                       logger('item_store: found guid '.$arr['guid'].' for uri '.$arr['uri'], LOGGER_DEBUG);
+               }
+       }
+
        // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin.
        // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<"
        //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
@@ -1236,7 +1254,7 @@ function item_store($arr,$force_parent = false) {
                        if(count($r)) {
                                logger('item_store: Send notification for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG);
                                $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
-                                       intval($arr['uid']));
+                                       intval($arr['uid']));
 
                                $item = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d",
                                        intval($current_post),
@@ -1281,7 +1299,7 @@ function item_store($arr,$force_parent = false) {
        if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))
                $parent_id = $current_post;
 
-       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+       if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
                $private = 1;
        else
                $private = $arr['private'];
@@ -1304,14 +1322,14 @@ function item_store($arr,$force_parent = false) {
        if ($ostatus_conversation)
                complete_conversation($current_post, $ostatus_conversation);
 
-        $arr['id'] = $current_post;
-        $arr['parent'] = $parent_id;
-        $arr['allow_cid'] = $allow_cid;
-        $arr['allow_gid'] = $allow_gid;
-        $arr['deny_cid'] = $deny_cid;
-        $arr['deny_gid'] = $deny_gid;
-        $arr['private'] = $private;
-        $arr['deleted'] = $parent_deleted;
+       $arr['id'] = $current_post;
+       $arr['parent'] = $parent_id;
+       $arr['allow_cid'] = $allow_cid;
+       $arr['allow_gid'] = $allow_gid;
+       $arr['deny_cid'] = $deny_cid;
+       $arr['deny_gid'] = $deny_gid;
+       $arr['private'] = $private;
+       $arr['deleted'] = $parent_deleted;
 
        // update the commented timestamp on the parent
 
@@ -1789,10 +1807,10 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
   */
 function edited_timestamp_is_newer($existing, $update) {
     if (!x($existing,'edited') || !$existing['edited']) {
-        return true;
+       return true;
     }
     if (!x($update,'edited') || !$update['edited']) {
-        return false;
+       return false;
     }
     $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']);
     $update_edited = datetime_convert('UTC', 'UTC', $update['edited']);
@@ -1985,7 +2003,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
                        $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`)
                                VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
                                intval($contact['uid']),
-                               intval($contact['id']),
+                               intval($contact['id']),
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert()),
                                dbesc(datetime_convert('UTC','UTC', $birthday)),
@@ -2147,7 +2165,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
 
                logger('consume_feed: feed item count = ' . $feed->get_item_quantity());
 
-        // in inverse date order
+       // in inverse date order
                if ($datedir)
                        $items = array_reverse($feed->get_items());
                else
@@ -3583,16 +3601,16 @@ function local_delivery($importer,$data) {
 
                                        $links = parse_xml_string("<links>".unxmlify($xo->link)."</links>",false);
 
-                               foreach($links->link as $l) {
-                               $atts = $l->attributes();
-                               switch($atts['rel']) {
-                                       case "alternate":
+                               foreach($links->link as $l) {
+                               $atts = $l->attributes();
+                               switch($atts['rel']) {
+                                       case "alternate":
                                                                $Blink = $atts['href'];
                                                                break;
                                                        default:
                                                                break;
-                                   }
-                               }
+                                   }
+                               }
                                        if($Blink && link_compare($Blink,$a->get_baseurl() . '/profile/' . $importer['nickname'])) {
 
                                                // send a notification
@@ -4093,7 +4111,7 @@ function item_getfeedattach($item) {
 
 
 
-function item_expire($uid,$days) {
+function item_expire($uid, $days, $network = "", $force = false) {
 
        if((! $uid) || ($days < 1))
                return;
@@ -4104,9 +4122,17 @@ function item_expire($uid,$days) {
        $expire_network_only = get_pconfig($uid,'expire','network_only');
        $sql_extra = ((intval($expire_network_only)) ? " AND wall = 0 " : "");
 
+       if ($network != "") {
+               $sql_extra .= sprintf(" AND network = '%s' ", dbesc($network));
+               // There is an index "uid_network_received" but not "uid_network_created"
+               // This avoids the creation of another index just for one purpose.
+               // And it doesn't really matter wether to look at "received" or "created"
+               $range = "AND `received` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
+       } else
+               $range = "AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
+
        $r = q("SELECT * FROM `item`
-               WHERE `uid` = %d
-               AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY
+               WHERE `uid` = %d $range
                AND `id` = `parent`
                $sql_extra
                AND `deleted` = 0",
@@ -4120,6 +4146,10 @@ function item_expire($uid,$days) {
        $expire_items = get_pconfig($uid, 'expire','items');
        $expire_items = (($expire_items===false)?1:intval($expire_items)); // default if not set: 1
 
+       // Forcing expiring of items - but not notes and marked items
+       if ($force)
+               $expire_items = true;
+
        $expire_notes = get_pconfig($uid, 'expire','notes');
        $expire_notes = (($expire_notes===false)?1:intval($expire_notes)); // default if not set: 1
 
@@ -4434,7 +4464,7 @@ function posted_dates($uid,$wall) {
                $start_month = datetime_convert('','',$dstart,'Y-m-d');
                $end_month = datetime_convert('','',$dend,'Y-m-d');
                $str = day_translate(datetime_convert('','',$dnow,'F Y'));
-               $ret[] = array($str,$end_month,$start_month);
+               $ret[] = array($str,$end_month,$start_month);
                $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d');
        }
        return $ret;