]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Merge pull request #67 from tomtom84/master
[friendica.git] / mod / item.php
old mode 100644 (file)
new mode 100755 (executable)
index b5db29d..81d7c75
@@ -4,7 +4,7 @@
  *
  * This is the POST destination for most all locally posted
  * text stuff. This function handles status, wall-to-wall status, 
- * local comments, and remote coments that are posted on this site 
+ * local comments, and remote coments that are posted on this site 
  * (as opposed to being delivered in a feed).
  * Also processed here are posts and comments coming through the 
  * statusnet/twitter API. 
 
 require_once('include/crypto.php');
 require_once('include/enotify.php');
+require_once('include/email.php');
 
 function item_post(&$a) {
 
-       if((! local_user()) && (! remote_user()))
+       if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter')))
                return;
 
        require_once('include/security.php');
@@ -38,10 +39,11 @@ function item_post(&$a) {
 
        call_hooks('post_local_start', $_REQUEST);
 //     logger('postinput ' . file_get_contents('php://input'));
-       logger('postvars' . print_r($_REQUEST,true), LOGGER_DATA);
+       logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA);
 
        $api_source = ((x($_REQUEST,'api_source') && $_REQUEST['api_source']) ? true : false);
        $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
+       $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
 
        /**
         * Is this a reply to something?
@@ -56,8 +58,6 @@ function item_post(&$a) {
        $parid = 0;
        $r = false;
 
-       $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
-
        if($parent || $parent_uri) {
 
                if(! x($_REQUEST,'type'))
@@ -114,7 +114,29 @@ function item_post(&$a) {
        $post_id     = ((x($_REQUEST,'post_id'))     ? intval($_REQUEST['post_id'])     : 0);
        $app         = ((x($_REQUEST,'source'))      ? strip_tags($_REQUEST['source'])  : '');
 
-       if(! can_write_wall($a,$profile_uid)) {
+       $allow_moderated = false;
+
+       // here is where we are going to check for permission to post a moderated comment.
+
+       // First check that the parent exists and it is a wall item.
+
+       if((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) {
+               notice( t('Permission denied.') . EOL) ;
+               if(x($_REQUEST,'return')) 
+                       goaway($a->get_baseurl() . "/" . $return_path );
+               killme();
+       }
+
+       // Now check that it is a page_type of PAGE_BLOG, and that valid personal details
+       // have been provided, and run any anti-spam plugins
+
+
+       // TODO
+
+
+
+
+       if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) {
                notice( t('Permission denied.') . EOL) ;
                if(x($_REQUEST,'return')) 
                        goaway($a->get_baseurl() . "/" . $return_path );
@@ -378,6 +400,8 @@ function item_post(&$a) {
 
        $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); 
 
+       $body = scale_external_images($body,false);
+
        /**
         * Look for any tags and linkify them
         */
@@ -582,6 +606,7 @@ function item_post(&$a) {
        $datarray['thr-parent']    = $thr_parent;
        $datarray['postopts']      = '';
        $datarray['origin']        = $origin;
+       $datarray['moderated']     = $allow_moderated;
 
        /**
         * These fields are for the convenience of plugins...
@@ -611,9 +636,24 @@ function item_post(&$a) {
 
        call_hooks('post_local',$datarray);
 
+       if(x($datarray,'cancel')) {
+               logger('mod_item: post cancelled by plugin.');
+               if($return_path) {
+                       goaway($a->get_baseurl() . "/" . $return_path);
+               }
+
+               $json = array('cancel' => 1);
+               if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
+                       $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
+
+               echo json_encode($json);
+               killme();
+       }
+
 
        if($orig_post) {
-               $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+               $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+                       dbesc($title),
                        dbesc($body),
                        dbesc(datetime_convert()),
                        intval($post_id),
@@ -633,8 +673,8 @@ function item_post(&$a) {
 
        $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, 
                `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, 
-               `tag`, `inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin` )
-               VALUES( '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d )",
+               `tag`, `inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin`, `moderated` )
+               VALUES( '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d )",
                dbesc($datarray['guid']),
                intval($datarray['uid']),
                dbesc($datarray['type']),
@@ -671,7 +711,8 @@ function item_post(&$a) {
                intval($datarray['pubmail']),
                dbesc($datarray['attach']),
                intval($datarray['bookmark']),
-               intval($datarray['origin'])
+               intval($datarray['origin']),
+               intval($datarry['moderated'])
        );
 
        $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
@@ -707,13 +748,15 @@ function item_post(&$a) {
                                        'language'     => $user['language'],
                                        'to_name'      => $user['username'],
                                        'to_email'     => $user['email'],
+                                       'uid'          => $user['uid'],
                                        'item'         => $datarray,
                                        'link'             => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
                                        'source_name'  => $datarray['author-name'],
                                        'source_link'  => $datarray['author-link'],
                                        'source_photo' => $datarray['author-avatar'],
                                        'verb'         => ACTIVITY_POST,
-                                       'otype'        => 'item'
+                                       'otype'        => 'item',
+                                       'parent'       => $parent,
                                ));
                        
                        }
@@ -749,6 +792,7 @@ function item_post(&$a) {
                                        'language'     => $user['language'],
                                        'to_name'      => $user['username'],
                                        'to_email'     => $user['email'],
+                                       'uid'          => $user['uid'],
                                        'item'         => $datarray,
                                        'link'             => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
                                        'source_name'  => $datarray['author-name'],
@@ -816,8 +860,8 @@ function item_post(&$a) {
                                $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
                                $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; 
 
-                               $subject  = '[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
-                               $headers  = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
+                               $subject  = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']),'UTF-8');
+                               $headers  = 'From: ' . email_header_encode($a->user['username'],'UTF-8') . ' <' . $a->user['email'] . '>' . "\n";
                                $headers .= 'MIME-Version: 1.0' . "\n";
                                $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
                                $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";