aboutsummaryrefslogtreecommitdiffstats
path: root/include/items.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/items.php')
-rwxr-xr-xinclude/items.php197
1 files changed, 79 insertions, 118 deletions
diff --git a/include/items.php b/include/items.php
index 328079b9d..5a0ca01c6 100755
--- a/include/items.php
+++ b/include/items.php
@@ -8,6 +8,7 @@ use Zotlabs\Lib as Zlib;
require_once('include/bbcode.php');
require_once('include/oembed.php');
require_once('include/crypto.php');
+require_once('include/message.php');
require_once('include/feedutils.php');
require_once('include/photo/photo_driver.php');
require_once('include/permissions.php');
@@ -175,6 +176,13 @@ function item_normal() {
and item.item_blocked = 0 ";
}
+function item_normal_search() {
+ return " and item.item_hidden = 0 and item.item_type in (0,3) and item.item_deleted = 0
+ and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
+ and item.item_blocked = 0 ";
+}
+
+
/**
* @brief
*
@@ -212,6 +220,11 @@ function can_comment_on_post($observer_xchan, $item) {
// logger('can_comment_on_post: comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG);
+ $x = [ 'observer_hash' => $observer_xchan, 'item' => $item, 'allowed' => 'unset' ];
+ call_hooks('can_comment_on_post',$x);
+ if($x['allowed'] !== 'unset')
+ return $x['allowed'];
+
if(! $observer_xchan)
return false;
@@ -248,8 +261,6 @@ function can_comment_on_post($observer_xchan, $item) {
}
if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red'))
return true;
- if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'diaspora'))
- return true;
if(strstr($item['comment_policy'],'site:') && strstr($item['comment_policy'],App::get_hostname()))
return true;
@@ -587,11 +598,6 @@ function get_item_elements($x,$allow_code = false) {
$arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : '');
- if(array_key_exists('diaspora_signature',$x) && is_array($x['diaspora_signature']))
- $x['diaspora_signature'] = json_encode($x['diaspora_signature']);
-
- $arr['diaspora_meta'] = (($x['diaspora_signature']) ? $x['diaspora_signature'] : '');
-
$arr['obj'] = activity_sanitise($x['object']);
$arr['target'] = activity_sanitise($x['target']);
@@ -797,8 +803,10 @@ function import_author_xchan($x) {
if((! array_key_exists('network', $x)) || ($x['network'] === 'zot')) {
$y = import_author_zot($x);
}
- if(! $y)
- $y = import_author_diaspora($x);
+
+ // if we were told that it's a zot connection, don't probe/import anything else
+ if(array_key_exists('network',$x) && $x['network'] === 'zot')
+ return $y;
if($x['network'] === 'rss') {
$y = import_author_rss($x);
@@ -809,36 +817,7 @@ function import_author_xchan($x) {
}
return($y);
-}
-
-/**
- * @brief Imports an author from Diaspora.
- *
- * @param array $x an associative array with
- * * \e string \b address
- * @return boolean|string false on error, otherwise xchan_hash of the new entry
- */
-function import_author_diaspora($x) {
- if(! $x['address'])
- return false;
-
- $r = q("select * from xchan where xchan_addr = '%s' limit 1",
- dbesc($x['address'])
- );
- if($r) {
- logger('in_cache: ' . $x['address'], LOGGER_DATA);
- return $r[0]['xchan_hash'];
- }
-
- if(discover_by_webbie($x['address'])) {
- $r = q("select xchan_hash from xchan where xchan_addr = '%s' limit 1",
- dbesc($x['address'])
- );
- if($r)
- return $r[0]['xchan_hash'];
- }
- return false;
}
/**
@@ -850,6 +829,7 @@ function import_author_diaspora($x) {
* * \e string \b guid
* @return boolean|string
*/
+
function import_author_rss($x) {
if(! $x['url'])
return false;
@@ -897,6 +877,11 @@ function import_author_rss($x) {
function import_author_unknown($x) {
+ $arr = [ 'author' => $x, 'result' => false ];
+ call_hooks('import_author', $arr);
+ if($arr['result'])
+ return $arr['result'];
+
if(! $x['url'])
return false;
@@ -926,7 +911,7 @@ function import_author_unknown($x) {
$photos = import_xchan_photo($x['photo']['src'],$x['url']);
if($photos) {
- $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_url = '%s' and xchan_network = 'unknown'",
+ $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' and xchan_network = 'unknown'",
dbesc(datetime_convert()),
dbesc($photos[0]),
dbesc($photos[1]),
@@ -1056,17 +1041,7 @@ function encode_item($item,$mirror = false) {
if($item['iconfig'])
$x['meta'] = encode_item_meta($item['iconfig'],$mirror);
- if($item['diaspora_meta']) {
- $z = json_decode($item['diaspora_meta'],true);
- if($z) {
- if(is_array($z) && array_key_exists('iv',$z))
- $x['diaspora_signature'] = crypto_unencapsulate($z,$key);
- else
- $x['diaspora_signature'] = $z;
- if(! is_array($z))
- logger('encode_item: diaspora meta is not an array: ' . print_r($z,true));
- }
- }
+
logger('encode_item: ' . print_r($x,true), LOGGER_DATA);
return $x;
@@ -1347,11 +1322,12 @@ function encode_mail($item,$extended = false) {
$x['message_parent'] = $item['parent_mid'];
$x['created'] = $item['created'];
$x['expires'] = $item['expires'];
- $x['diaspora_meta'] = $item['diaspora_meta'];
$x['title'] = $item['title'];
$x['body'] = $item['body'];
$x['from'] = encode_item_xchan($item['from']);
$x['to'] = encode_item_xchan($item['to']);
+ $x['raw'] = $item['mail_raw'];
+ $x['mimetype'] = $item['mail_mimetype'];
if($item['attach'])
$x['attach'] = json_decode($item['attach'],true);
@@ -1385,9 +1361,16 @@ function get_mail_elements($x) {
$arr = array();
- $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : '');
- $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : '');
+ if(intval($x['raw'])) {
+ $arr['mail_raw'] = intval($x['raw']);
+ $arr['body'] = $x['body'];
+ }
+ else {
+ $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'], ENT_COMPAT,'UTF-8',false) : '');
+ }
+ $arr['title'] = (($x['title'])? htmlspecialchars($x['title'],ENT_COMPAT,'UTF-8',false) : '');
+ $arr['mail_mimetype'] = (($x['mimetype']) ? htmlspecialchars($x['mimetype'],ENT_COMPAT,'UTF-8',false) : 'text/bbcode');
$arr['conv_guid'] = (($x['conv_guid'])? htmlspecialchars($x['conv_guid'],ENT_COMPAT,'UTF-8',false) : '');
$arr['created'] = datetime_convert('UTC','UTC',$x['created']);
@@ -1560,7 +1543,6 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
$arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : '');
$arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : '');
- $arr['diaspora_meta'] = ((x($arr,'diaspora_meta')) ? $arr['diaspora_meta'] : '');
$arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
$arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : '');
$arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
@@ -1755,7 +1737,7 @@ logger('revision: ' . $arr['revision']);
if($r[0]['owner_xchan'] !== $arr['owner_xchan']) {
$arr['owner_xchan'] = $r[0]['owner_xchan'];
-// $uplinked_comment = true;
+ // $uplinked_comment = true;
}
// if the parent is private, force privacy for the entire conversation
@@ -2060,7 +2042,7 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) {
$arr['changed'] = $orig[0]['changed'];
$arr['route'] = ((array_key_exists('route',$arr)) ? trim($arr['route']) : $orig[0]['route']);
- $arr['diaspora_meta'] = ((x($arr,'diaspora_meta')) ? $arr['diaspora_meta'] : $orig[0]['diaspora_meta']);
+
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']);
$arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : $orig[0]['coord']);
$arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : $orig[0]['verb']);
@@ -2219,55 +2201,6 @@ function item_store_update($arr,$allow_exec = false, $deliver = true) {
-function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, $walltowall = false) {
-
- // We won't be able to sign Diaspora comments for authenticated visitors
- // - we don't have their private key
-
- // since Diaspora doesn't handle edits we can only do this for the original text and not update it.
-
- require_once('include/markdown.php');
- $signed_body = bb2diaspora_itembody($datarray,$walltowall);
-
- if($walltowall) {
- logger('wall to wall comment',LOGGER_DEBUG);
- // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author.
- $signed_body = "\n\n"
- . '![' . $datarray['author']['xchan_name'] . '](' . $datarray['author']['xchan_photo_m'] . ')'
- . '[' . $datarray['author']['xchan_name'] . '](' . $datarray['author']['xchan_url'] . ')' . "\n\n"
- . $signed_body;
- }
-
- logger('storing diaspora comment signature',LOGGER_DEBUG);
-
- $diaspora_handle = channel_reddress($channel);
-
- $signed_text = $datarray['mid'] . ';' . $parent_item['mid'] . ';' . $signed_body . ';' . $diaspora_handle;
-
-
- if( $channel && $channel['channel_prvkey'] )
- $authorsig = base64_encode(rsa_sign($signed_text, $channel['channel_prvkey'], 'sha256'));
- else
- $authorsig = '';
-
- $x = array('signer' => $diaspora_handle, 'body' => $signed_body, 'signed_text' => $signed_text, 'signature' => $authorsig);
-
- $y = json_encode($x);
-
- $r = q("update item set diaspora_meta = '%s' where id = %d",
- dbesc($y),
- intval($post_id)
- );
-
-
- if(! $r)
- logger('store_diaspora_comment_sig: DB write failed');
-
- return;
-}
-
-
-
function send_status_notifications($post_id,$item) {
// only send notifications for comments
@@ -3000,6 +2933,8 @@ function mail_store($arr) {
return 0;
}
+ $channel = channelx_by_n($arr['channel_id']);
+
if(! $arr['mail_obscured']) {
if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
$arr['body'] = escape_tags($arr['body']);
@@ -3025,14 +2960,39 @@ function mail_store($arr) {
$arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');
$arr['sig'] = ((x($arr,'sig')) ? trim($arr['sig']) : '');
$arr['conv_guid'] = ((x($arr,'conv_guid')) ? trim($arr['conv_guid']) : '');
+ $arr['mail_mimetype'] = ((x($arr,'mail_mimetype')) ? trim($arr['mail_mimetype']) : 'text/bbcode');
$arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 );
+ $arr['mail_raw'] = ((x($arr,'mail_raw')) ? intval($arr['mail_raw']) : 0 );
- if(! $arr['parent_mid']) {
+
+
+ if($arr['parent_mid']) {
+ $parent_item = q("select * from mail where mid = '%s' and channel_id = %d limit 1",
+ dbesc($arr['parent_mid']),
+ intval($arr['channel_id'])
+ );
+ if(($parent_item) && (! $arr['conv_guid'])) {
+ $arr['conv_guid'] = $parent_item[0]['conv_guid'];
+ }
+ }
+ else {
logger('mail_store: missing parent');
$arr['parent_mid'] = $arr['mid'];
}
+ if($arr['from_xchan'] === $channel['channel_hash'])
+ $conversant = $arr['to_xchan'];
+ else
+ $conversant = $arr['from_xchan'];
+
+
+ if(! $arr['conv_guid']) {
+ $x = create_conversation($channel,$conversant,(($arr['title']) ? base64url_decode(str_rot47($arr['title'])) : ''));
+ $arr['conv_guid'] = (($x) ? $x['guid'] : '');
+ }
+
+
$r = q("SELECT id FROM mail WHERE mid = '%s' AND channel_id = %d LIMIT 1",
dbesc($arr['mid']),
intval($arr['channel_id'])
@@ -3097,6 +3057,14 @@ function mail_store($arr) {
Zlib\Enotify::submit($notif_params);
}
+ if($arr['conv_guid']) {
+ $c = q("update conv set updated = '%s' where guid = '%s' and uid = %d",
+ dbesc(datetime_convert()),
+ dbesc($arr['conv_guid']),
+ intval($arr['channel_id'])
+ );
+ }
+
call_hooks('post_mail_end',$arr);
return $current_post;
}
@@ -3961,8 +3929,8 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
}
}
- if(intval($arr['compat']) === 1) {
- $sql_extra = " AND author_xchan = owner_xchan and item_wall = 1 and item_private = 0 ";
+ if($channel && intval($arr['compat']) === 1) {
+ $sql_extra = " AND author_xchan = '" . $channel['channel_hash'] . "' and item_private = 0 ";
}
if ($arr['datequery']) {
@@ -3972,11 +3940,6 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
$sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery2']))));
}
- if(! array_key_exists('nouveau',$arr)) {
- $sql_extra2 = " AND item.parent = item.id ";
-// $sql_extra3 = '';
- }
-
if($arr['search']) {
if(strpos($arr['search'],'#') === 0)
@@ -4048,7 +4011,8 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
if($arr['item_type'] === '*')
$item_restrict = '';
- if ($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD) && $channel) {
+ if ((($arr['compat']) || ($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD))) && $channel) {
+
// "New Item View" - show all items unthreaded in reverse created date order
$items = q("SELECT item.*, item.id AS item_id FROM item
@@ -4343,10 +4307,7 @@ function sync_an_item($channel_id,$item_id) {
if($r) {
xchan_query($r);
$sync_item = fetch_post_tags($r);
- $rid = q("select * from item_id where iid = %d",
- intval($item_id)
- );
- build_sync_packet($channel_d,array('item' => array(encode_item($sync_item[0],true)),'item_id' => $rid));
+ build_sync_packet($channel_d,array('item' => array(encode_item($sync_item[0],true))));
}
}