]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
The CSS code for shared messages is moved from "vier" to the global.css, so that...
[friendica.git] / include / items.php
index a1eddb2eebef9b95bae68158b4c9cbc3d0c84a6d..27be613d70996e082360efee9b57ecc53eb8ead2 100755 (executable)
@@ -52,6 +52,8 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
 
        $birthday = feed_birthday($owner_id,$owner['timezone']);
 
+       $sql_post_table = "";
+
        if(! $public_feed) {
 
                $sql_extra = '';
@@ -85,18 +87,18 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                $groups = init_groups_visitor($contact['id']);
 
                if(count($groups)) {
-                       for($x = 0; $x < count($groups); $x ++) 
+                       for($x = 0; $x < count($groups); $x ++)
                                $groups[$x] = '<' . intval($groups[$x]) . '>' ;
                        $gs = implode('|', $groups);
                }
                else
-                       $gs = '<<>>' ; // Impossible to match 
+                       $gs = '<<>>' ; // Impossible to match
 
-               $sql_extra = sprintf(" 
-                       AND ( `allow_cid` = '' OR     `allow_cid` REGEXP '<%d>' ) 
-                       AND ( `deny_cid`  = '' OR NOT `deny_cid`  REGEXP '<%d>' ) 
+               $sql_extra = sprintf("
+                       AND ( `allow_cid` = '' OR     `allow_cid` REGEXP '<%d>' )
+                       AND ( `deny_cid`  = '' OR NOT `deny_cid`  REGEXP '<%d>' )
                        AND ( `allow_gid` = '' OR     `allow_gid` REGEXP '%s' )
-                       AND ( `deny_gid`  = '' OR NOT `deny_gid`  REGEXP '%s') 
+                       AND ( `deny_gid`  = '' OR NOT `deny_gid`  REGEXP '%s')
                ",
                        intval($contact['id']),
                        intval($contact['id']),
@@ -114,7 +116,9 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                $last_update = 'now -30 days';
 
        if(isset($category)) {
-               $sql_extra .= file_tag_file_query('item',$category,'category');
+               $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
+                               dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($owner_id));
+               //$sql_extra .= file_tag_file_query('item',$category,'category');
        }
 
        if($public_feed) {
@@ -133,7 +137,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
                `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
                `contact`.`id` AS `contact-id`, `contact`.`uid` AS `contact-uid`,
                `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
-               FROM `item`
+               FROM `item` $sql_post_table
                INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
@@ -852,9 +856,10 @@ function get_atom_elements($feed, $item, $contact = array()) {
        }
 
        if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) {
-               $res["body"] = $res["title"]."\n\n[class=type-link]".fetch_siteinfo($res['plink'])."[/class]";
+               $res["body"] = $res["title"].add_page_info($res['plink']);
                $res["title"] = "";
-       }
+       } elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_OSTATUS))
+               $res["body"] = add_page_info_to_body($res["body"]);
 
        $arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
 
@@ -870,29 +875,63 @@ function get_atom_elements($feed, $item, $contact = array()) {
        return $res;
 }
 
-function fetch_siteinfo($url) {
-       require_once("mod/parse_url.php");
+function add_page_info($url, $no_photos = false) {
+        require_once("mod/parse_url.php");
+        $data = parseurl_getsiteinfo($url, true);
 
-       // Fetch site infos - but only from the meta data
-       $data = parseurl_getsiteinfo($url, true);
+        logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG);
 
-       $text = "";
+       // It maybe is a rich content, but if it does have everything that a link has,
+       // then treat it that way
+       if (($data["type"] == "rich") AND is_string($data["title"]) AND
+               is_string($data["text"]) AND (sizeof($data["images"]) > 0))
+               $data["type"] = "link";
 
-       if (!is_string($data["text"]) AND (sizeof($data["images"]) == 0) AND ($data["title"] == $url))
+        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 (is_string($data["title"]))
-               $text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]\n";
+        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"] != "photo") AND is_string($data["text"]))
+                $text .= "[quote]".$data["text"]."[/quote]";
+
+        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);
+
+        $URLSearchString = "^\[\]";
+
+        // 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);
+
+       // Convert urls without bbcode elements
+       if (!$matches AND $texturl) {
+               preg_match("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", " ".$body, $matches);
 
-       if (sizeof($data["images"]) > 0) {
-               $imagedata = $data["images"][0];
-               $text .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n";
+               // Yeah, a hack. I really hate regular expressions :)
+               if ($matches)
+                       $matches[1] = $matches[2];
        }
 
-       if (is_string($data["text"]))
-               $text .= "[quote]".$data["text"]."[/quote]";
+        if ($matches)
+                $body .= add_page_info($matches[1], $no_photos);
 
-       return($text);
+        return $body;
 }
 
 function encode_rel_links($links) {