require_once('include/Photo.php');
require_once('include/tags.php');
require_once('include/text.php');
+require_once('include/email.php');
+require_once('include/ostatus_conversation.php');
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
if(! function_exists('limit_body_size')) {
function limit_body_size($body) {
- logger('limit_body_size: start', LOGGER_DEBUG);
+// logger('limit_body_size: start', LOGGER_DEBUG);
$maxlen = get_max_import_size();
}
}
+ // Search for ostatus conversation url
+ $links = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://www.w3.org/2005/Atom"]["link"];
+
+ if (is_array($links)) {
+ foreach ($links as $link) {
+ $conversation = array_shift($link["attribs"]);
+
+ if ($conversation["rel"] == "ostatus:conversation") {
+ $res["ostatus_conversation"] = $conversation["href"];
+ logger('get_atom_elements: found conversation url '.$res["ostatus_conversation"]);
+ }
+ };
+ }
+
$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) {
- // $debugfile = tempnam("/home/ike/log", "item-res2-");
- // file_put_contents($debugfile, serialize($arr));
- //}
+ /*if (strpos($res["body"], "@") !== false) {
+ $debugfile = tempnam("/var/www/virtual/pirati.ca/phptmp/", "item-res2-");
+ file_put_contents($debugfile, serialize($arr));
+ }*/
return $res;
}
unset($arr['dsprsig']);
}
+ // if an OStatus conversation url was passed in, it is stored and then
+ // removed from the array.
+ $ostatus_conversation = null;
+
+ if (isset($arr["ostatus_conversation"])) {
+ $ostatus_conversation = $arr["ostatus_conversation"];
+ unset($arr["ostatus_conversation"]);
+ }
+
if(x($arr, 'gravity'))
$arr['gravity'] = intval($arr['gravity']);
elseif($arr['parent-uri'] === $arr['uri'])
$deny_cid = $arr['deny_cid'];
$deny_gid = $arr['deny_gid'];
}
- else {
+ else {
- // find the parent and snarf the item id and ACL's
+ // find the parent and snarf the item id and ACLs
// and anything else we need to inherit
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1",
);
create_tags_from_item($current_post);
+ // Complete ostatus threads
+ if ($ostatus_conversation)
+ complete_conversation($current_post, $ostatus_conversation);
+
$arr['id'] = $current_post;
$arr['parent'] = $parent_id;
$arr['allow_cid'] = $allow_cid;
$arr['deny_gid'] = $deny_gid;
$arr['private'] = $private;
$arr['deleted'] = $parent_deleted;
- call_hooks('post_remote_end',$arr);
// update the commented timestamp on the parent
);
}
- tag_deliver($arr['uid'],$current_post);
+ $deleted = tag_deliver($arr['uid'],$current_post);
- // Store the fresh generated item into the cache
- $cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body']));
+ // current post can be deleted if is for a communuty page and no mention are
+ // in it.
+ if (!$deleted) {
+
+ // Store the fresh generated item into the cache
+ $cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body']));
- if (($cachefile != '') AND !file_exists($cachefile)) {
- $s = prepare_text($arr['body']);
- file_put_contents($cachefile, $s);
- logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
- }
+ if (($cachefile != '') AND !file_exists($cachefile)) {
+ $s = prepare_text($arr['body']);
+ $a = get_app();
+ $stamp1 = microtime(true);
+ file_put_contents($cachefile, $s);
+ $a->save_timestamp($stamp1, "file");
+ 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);
+ }
+ }
return $current_post;
}
return false;
}
-
+/**
+ * look for mention tags and setup a second delivery chain for forum/community posts if appropriate
+ * @param int $uid
+ * @param int $item_id
+ * @return bool true if item was deleted, else false
+ */
function tag_deliver($uid,$item_id) {
- // look for mention tags and setup a second delivery chain for forum/community posts if appropriate
+ //
$a = get_app();
}
}
- if(! $mention)
+ if(! $mention){
+ if ( ($community_page || $prvgroup) &&
+ (!$item['wall']) && (!$item['origin']) && ($item['id'] == $item['parent'])){
+ // mmh.. no mention.. community page or private group... no wall.. no origin.. top-post (not a comment)
+ // delete it!
+ logger("tag_deliver: no-mention top-level post to communuty or private group. delete.");
+ q("DELETE FROM item WHERE id = %d and uid = %d limit 1",
+ intval($item_id),
+ intval($uid)
+ );
+ return true;
+ }
return;
+ }
+
// send a notification
}
+/*
+ This function returns true if $update has an edited timestamp newer
+ than $existing, i.e. $update contains new data which should override
+ what's already there. If there is no timestamp yet, the update is
+ assumed to be newer. If the update has no timestamp, the existing
+ item is assumed to be up-to-date. If the timestamps are equal it
+ assumes the update has been seen before and should be ignored.
+ */
+function edited_timestamp_is_newer($existing, $update) {
+ if (!x($existing,'edited') || !$existing['edited']) {
+ return true;
+ }
+ if (!x($update,'edited') || !$update['edited']) {
+ return false;
+ }
+ $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']);
+ $update_edited = datetime_convert('UTC', 'UTC', $update['edited']);
+ return (strcmp($existing_edited, $update_edited) < 0);
+}
+
/**
*
* consume_feed - process atom feed and update anything/everything we might need to update
// Update content if 'updated' changes
if(count($r)) {
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ if (edited_timestamp_is_newer($r[0], $datarray)) {
// do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
// Update content if 'updated' changes
if(count($r)) {
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ if (edited_timestamp_is_newer($r[0], $datarray)) {
// do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
if(count($r)) {
$iid = $r[0]['id'];
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ if (edited_timestamp_is_newer($r[0], $datarray)) {
// do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
// Update content if 'updated' changes
if(count($r)) {
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ if (edited_timestamp_is_newer($r[0], $datarray)) {
// do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
// Update content if 'updated' changes
if(count($r)) {
- if((x($datarray,'edited') !== false) && (datetime_convert('UTC','UTC',$datarray['edited']) !== $r[0]['edited'])) {
+ if (edited_timestamp_is_newer($r[0], $datarray)) {
// do not accept (ignore) an earlier edit than one we currently have.
if(datetime_convert('UTC','UTC',$datarray['edited']) < $r[0]['edited'])
'$sitename' => $a->config['sitename']
));
$res = mail($r[0]['email'],
- (($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],
+ email_header_encode((($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],'UTF-8'),
$email,
- 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
+ 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
}
function fix_private_photos($s, $uid, $item = null, $cid = 0) {
+
+ if(get_config('system','disable_embedded'))
+ return $s;
+
$a = get_app();
- logger('fix_private_photos', LOGGER_DEBUG);
+ logger('fix_private_photos: check for photos', LOGGER_DEBUG);
$site = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://'));
$orig_body = $s;
// Only embed locally hosted photos
$replace = false;
$i = basename($image);
- $i = str_replace(array('.jpg','.png'),array('',''),$i);
+ $i = str_replace(array('.jpg','.png','.gif'),array('','',''),$i);
$x = strpos($i,'-');
if($x) {
intval($res),
intval($uid)
);
- if(count($r)) {
+ if($r) {
// Check to see if we should replace this photo link with an embedded image
// 1. No need to do so if the photo is public
function item_getfeedattach($item) {
$ret = '';
- $arr = explode(',',$item['attach']);
+ $arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
foreach($arr as $r) {
$matches = false;
- $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
+ $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches);
if($cnt) {
$ret .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
if(intval($matches[2]))
if((local_user() == $item['uid']) || ($cid) || (! $interactive)) {
+ // Check if we should do HTML-based delete confirmation
+ if($_REQUEST['confirm']) {
+ // <form> can't take arguments in its "action" parameter
+ // so add any arguments as hidden inputs
+ $query = explode_querystring($a->query_string);
+ $inputs = array();
+ foreach($query['args'] as $arg) {
+ if(strpos($arg, 'confirm=') === false) {
+ $arg_parts = explode('=', $arg);
+ $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
+ }
+ }
+
+ return replace_macros(get_markup_template('confirm.tpl'), array(
+ '$method' => 'get',
+ '$message' => t('Do you really want to delete this item?'),
+ '$extra_inputs' => $inputs,
+ '$confirm' => t('Yes'),
+ '$confirm_url' => $query['base'],
+ '$confirm_name' => 'confirmed',
+ '$cancel' => t('Cancel'),
+ ));
+ }
+ // Now check how the user responded to the confirmation query
+ if($_REQUEST['canceled']) {
+ goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
+ }
+
logger('delete item: ' . $item['id'], LOGGER_DEBUG);
// delete the item