aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Item.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Module/Item.php')
-rw-r--r--Zotlabs/Module/Item.php83
1 files changed, 39 insertions, 44 deletions
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 344e839f4..7f2813076 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -21,6 +21,7 @@ require_once('include/crypto.php');
require_once('include/items.php');
require_once('include/attach.php');
require_once('include/bbcode.php');
+require_once('include/security.php');
use \Zotlabs\Lib as Zlib;
@@ -34,9 +35,7 @@ class Item extends \Zotlabs\Web\Controller {
if((! local_channel()) && (! remote_channel()) && (! x($_REQUEST,'commenter')))
return;
-
- require_once('include/security.php');
-
+
$uid = local_channel();
$channel = null;
$observer = null;
@@ -126,6 +125,8 @@ class Item extends \Zotlabs\Web\Controller {
$ret = $this->item_check_service_class($uid,(($_REQUEST['webpage'] == ITEM_TYPE_WEBPAGE) ? true : false));
if (!$ret['success']) {
notice( t($ret['message']) . EOL) ;
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'service class exception' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -180,6 +181,8 @@ class Item extends \Zotlabs\Web\Controller {
if(($r === false) || (! count($r))) {
notice( t('Unable to locate original post.') . EOL);
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'invalid post id' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -214,6 +217,8 @@ class Item extends \Zotlabs\Web\Controller {
if(! $can_comment) {
notice( t('Permission denied.') . EOL) ;
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'permission denied' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -222,6 +227,8 @@ class Item extends \Zotlabs\Web\Controller {
else {
if(! perm_is_allowed($profile_uid,$observer['xchan_hash'],($webpage) ? 'write_pages' : 'post_wall')) {
notice( t('Permission denied.') . EOL) ;
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'permission denied' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -276,6 +283,8 @@ class Item extends \Zotlabs\Web\Controller {
if(! $channel) {
logger("mod_item: no channel.");
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'no channel' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -291,6 +300,8 @@ class Item extends \Zotlabs\Web\Controller {
}
else {
logger("mod_item: no owner.");
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'no owner' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -433,6 +444,8 @@ class Item extends \Zotlabs\Web\Controller {
if($preview)
killme();
info( t('Empty post discarded.') . EOL );
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'no content' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -473,6 +486,8 @@ class Item extends \Zotlabs\Web\Controller {
}
else {
notice( t('Executable content type not permitted to this channel.') . EOL);
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'forbidden content type' ] );
if(x($_REQUEST,'return'))
goaway(z_root() . "/" . $return_path );
killme();
@@ -540,42 +555,8 @@ class Item extends \Zotlabs\Web\Controller {
if($x)
$body .= "\n\n@group+" . $x[0]['abook_id'] . "\n";
}
-
- /**
- * fix naked links by passing through a callback to see if this is a hubzilla site
- * (already known to us) which will get a zrl, otherwise link with url, add bookmark tag to both.
- * First protect any url inside certain bbcode tags so we don't double link it.
- */
-
-
- $body = preg_replace_callback('/\[code(.*?)\[\/(code)\]/ism','\red_escape_codeblock',$body);
- $body = preg_replace_callback('/\[url(.*?)\[\/(url)\]/ism','\red_escape_codeblock',$body);
- $body = preg_replace_callback('/\[zrl(.*?)\[\/(zrl)\]/ism','\red_escape_codeblock',$body);
-
- $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]+)/ism", 'nakedoembed', $body);
- $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]+)/ism", '\red_zrl_callback', $body);
-
- $body = preg_replace_callback('/\[\$b64zrl(.*?)\[\/(zrl)\]/ism','\red_unescape_codeblock',$body);
- $body = preg_replace_callback('/\[\$b64url(.*?)\[\/(url)\]/ism','\red_unescape_codeblock',$body);
- $body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','\red_unescape_codeblock',$body);
-
-
- // fix any img tags that should be zmg
-
- $body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','\red_zrlify_img_callback',$body);
-
-
- $body = bb_translate_video($body);
-
- /**
- * Fold multi-line [code] sequences
- */
-
- $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
-
- $body = scale_external_images($body,false);
-
+ $body = cleanup_bbcode($body);
// Look for tags and linkify them
$results = linkify_tags($a, $body, ($uid) ? $uid : $profile_uid);
@@ -863,7 +844,8 @@ class Item extends \Zotlabs\Web\Controller {
logger('mod_item: post cancelled by plugin or duplicate suppressed.');
if($return_path)
goaway(z_root() . "/" . $return_path);
-
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'operation cancelled' ] );
$json = array('cancel' => 1);
$json['reload'] = z_root() . '/' . $_REQUEST['jsreload'];
echo json_encode($json);
@@ -916,6 +898,10 @@ class Item extends \Zotlabs\Web\Controller {
if(! $nopush)
\Zotlabs\Daemon\Master::Summon(array('Notifier', 'edit_post', $post_id));
+
+ if($api_source)
+ return($x);
+
if((x($_REQUEST,'return')) && strlen($return_path)) {
logger('return: ' . $return_path);
goaway(z_root() . "/" . $return_path );
@@ -990,8 +976,11 @@ class Item extends \Zotlabs\Web\Controller {
else {
logger('mod_item: unable to retrieve post that was just stored.');
notice( t('System error. Post not saved.') . EOL);
- goaway(z_root() . "/" . $return_path );
- // NOTREACHED
+ if($return_path)
+ goaway(z_root() . "/" . $return_path );
+ if($api_source)
+ return ( [ 'success' => false, 'message' => 'system error' ] );
+ killme();
}
if(($parent) && ($parent != $post_id)) {
@@ -1046,9 +1035,7 @@ class Item extends \Zotlabs\Web\Controller {
if((! local_channel()) && (! remote_channel()))
return;
-
- require_once('include/security.php');
-
+
if((argc() == 3) && (argv(1) === 'drop') && intval(argv(2))) {
require_once('include/items.php');
@@ -1084,6 +1071,14 @@ class Item extends \Zotlabs\Web\Controller {
else {
// complex deletion that needs to propagate and be performed in phases
drop_item($i[0]['id'],true,DROPITEM_PHASE1);
+ $r = q("select * from item where id = %d",
+ intval($i[0]['id'])
+ );
+ if($r) {
+ xchan_query($r);
+ $sync_item = fetch_post_tags($r);
+ build_sync_packet($i[0]['uid'],array('item' => array(encode_item($sync_item[0],true))));
+ }
tag_deliver($i[0]['uid'],$i[0]['id']);
}
}