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/ostatus_conversation.php');
$birthday = feed_birthday($owner_id,$owner['timezone']);
+ $sql_post_table = "";
+
if(! $public_feed) {
$sql_extra = '';
$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']),
$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) {
$check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s');
+ // AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
+ // dbesc($check_date),
+
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`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` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
+ 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`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`parent` != 0
- AND `item`.`wall` = 1 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- AND ( `item`.`edited` > '%s' OR `item`.`changed` > '%s' )
+ AND `item`.`wall` = 1 AND `item`.`changed` > '%s'
$sql_extra
ORDER BY `parent` %s, `created` ASC LIMIT 0, 300",
intval($owner_id),
dbesc($check_date),
- dbesc($check_date),
dbesc($sort)
);
$res['edited'] = unxmlify($rawedited[0]['data']);
if((x($res,'edited')) && (! (x($res,'created'))))
- $res['created'] = $res['edited'];
+ $res['created'] = $res['edited'];
if(! $res['created'])
$res['created'] = $item->get_date('c');
}
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);
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);
+
+ logger('add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG);
- // Fetch site infos - but only from the meta data
- $data = parseurl_getsiteinfo($url, true);
+ // 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";
- $text = "";
+ if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $url))
+ return("");
- if (!is_string($data["text"]) AND (sizeof($data["images"]) == 0) AND ($data["title"] == $url))
+ 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 (sizeof($data["images"]) > 0) {
- $imagedata = $data["images"][0];
- $text .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n";
+ 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 (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) {
if(count($r)) {
$current_post = $r[0]['id'];
logger('item_store: created item ' . $current_post);
- create_tags_from_item($r[0]['id']);
// Only check for notifications on start posts
if ($arr['parent-uri'] === $arr['uri']) {
intval($parent_deleted),
intval($current_post)
);
- create_tags_from_item($current_post);
// Complete ostatus threads
if ($ostatus_conversation)
logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
}
- $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
- if (count($r) == 1) {
- call_hooks('post_remote_end', $r[0]);
- }
- else {
- logger('item_store: new item not found in DB, id ' . $current_post);
- }
+ $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
+ if (count($r) == 1) {
+ call_hooks('post_remote_end', $r[0]);
+ } else {
+ logger('item_store: new item not found in DB, id ' . $current_post);
+ }
}
+
+ create_tags_from_item($current_post);
+ create_files_from_item($current_post);
+
return $current_post;
}
-
+// return - test
function get_item_contact($item,$contacts) {
if(! count($contacts) || (! is_array($item)))
return false;
* thing regardless of feed ordering. This won't be adequate in a fully-threaded
* model where comments can have sub-threads. That would require some massive sorting
* to get all the feed items into a mostly linear ordering, and might still require
- * recursion.
+ * recursion.
*/
function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) {
intval($importer['uid'])
);
create_tags_from_itemuri($item['uri'], $importer['uid']);
+ create_files_from_itemuri($item['uri'], $importer['uid']);
update_thread_uri($item['uri'], $importer['uid']);
}
else {
intval($importer['uid'])
);
create_tags_from_itemuri($uri, $importer['uid']);
+ create_files_from_itemuri($uri, $importer['uid']);
if($item['last-child']) {
// ensure that last-child is set in case the comment that had it just got wiped.
q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue;
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+ $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc(datetime_convert()),
dbesc($item_id),
intval($importer['uid'])
);
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue;
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+ $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc(datetime_convert()),
dbesc($item_id),
intval($importer['uid'])
);
intval($importer['importer_uid'])
);
create_tags_from_itemuri($item['uri'], $importer['importer_uid']);
+ create_files_from_itemuri($item['uri'], $importer['importer_uid']);
update_thread_uri($item['uri'], $importer['importer_uid']);
}
else {
intval($importer['importer_uid'])
);
create_tags_from_itemuri($uri, $importer['importer_uid']);
+ create_files_from_itemuri($uri, $importer['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.
continue;
logger('received updated comment' , LOGGER_DEBUG);
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+ $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc(datetime_convert()),
dbesc($item_id),
intval($importer['importer_uid'])
);
intval($importer['importer_uid'])
);
if(count($i) && ! intval($i[0]['blocktags'])) {
- q("UPDATE item SET tag = '%s', `edited` = '%s' WHERE id = %d",
+ q("UPDATE item SET tag = '%s', `edited` = '%s', `changed` = '%s' WHERE id = %d",
dbesc($tagp[0]['tag'] . (strlen($tagp[0]['tag']) ? ',' : '') . $newtag),
intval($tagp[0]['id']),
+ dbesc(datetime_convert()),
dbesc(datetime_convert())
);
create_tags_from_item($tagp[0]['id']);
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue;
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+ $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc(datetime_convert()),
dbesc($item_id),
intval($importer['importer_uid'])
);
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
continue;
- $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
+ $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
dbesc($datarray['title']),
dbesc($datarray['body']),
dbesc($datarray['tag']),
dbesc(datetime_convert('UTC','UTC',$datarray['edited'])),
+ dbesc(datetime_convert()),
dbesc($item_id),
intval($importer['importer_uid'])
);
$mentioned = get_mentions($item);
if($mentioned)
$o .= $mentioned;
-
+
call_hooks('atom_entry', $o);
$o .= '</entry>' . "\r\n";
-
+
return $o;
}
}
-
+
function item_expire($uid,$days) {
if((! $uid) || ($days < 1))
intval($item['id'])
);
create_tags_from_item($item['id']);
+ create_files_from_item($item['id']);
delete_thread($item['id']);
// clean up categories and tags so they don't end up as orphans
intval($item['uid'])
);
create_tags_from_item($item['parent-uri'], $item['uid']);
+ create_files_from_item($item['parent-uri'], $item['uid']);
delete_thread_uri($item['parent-uri'], $item['uid']);
// ignore the result
}