]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Merge branch 'newui' of github.com:fabrixxm/friendika into newui
[friendica.git] / mod / item.php
index b71c35041c29ea8dd7af7d801e590bc11d5f6c58..b4ec7666fd9fb250111a9dda056cdd6637da4d36 100644 (file)
@@ -15,6 +15,8 @@
  *
  */  
 
+require_once('include/crypto.php');
+
 function item_post(&$a) {
 
        if((! local_user()) && (! remote_user()))
@@ -35,7 +37,7 @@ function item_post(&$a) {
 
        call_hooks('post_local_start', $_POST);
 
-       $api_source = ((x($_POST,'api_source')) ? true : false);
+       $api_source = ((x($_POST,'api_source') && $_POST['api_source']) ? true : false);
 
        /**
         * Is this a reply to something?
@@ -178,6 +180,20 @@ function item_post(&$a) {
        
                $pubmail_enable    = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
 
+               // if using the API, we won't see pubmail_enable - figure out if it should be set
+
+               if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
+                       $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
+                       if(! $mail_disabled) {
+                               $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
+                                       intval(local_user())
+                               );
+                               if(count($r) && intval($r[0]['pubmail']))
+                                       $pubmail_enabled = true;
+                       }
+               }
+
+
                if(! strlen($body)) {
                        info( t('Empty post discarded.') . EOL );
                        if(x($_POST,'return')) 
@@ -304,6 +320,10 @@ function item_post(&$a) {
                                if(count($r)) {
                                        $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
                                                WHERE `uid` = %d AND `id` = %d LIMIT 1",
+                                               dbesc($str_contact_allow),
+                                               dbesc($str_group_allow),
+                                               dbesc($str_contact_deny),
+                                               dbesc($str_group_deny),
                                                intval($profile_uid),
                                                intval($attach)
                                        );
@@ -312,6 +332,15 @@ function item_post(&$a) {
                }
        }
 
+       // embedded bookmark in post? convert to regular url and set bookmark flag
+
+       $bookmark = 0;
+       if(preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/m",$body,$match)) {
+               $bookmark = 1;
+               $body = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/m",'[url=$1]$2[/url]',$body);
+       }
+
+
        /**
         * Fold multi-line [code] sequences
         */
@@ -333,7 +362,7 @@ function item_post(&$a) {
         * and we are replying, and there isn't one already
         */
 
-       if(($parent_contact) && ($parent_contact['network'] === 'stat'
+       if(($parent_contact) && ($parent_contact['network'] === NETWORK_OSTATUS
                && ($parent_contact['nick']) && (! in_array('@' . $parent_contact['nick'],$tags))) {
                $body = '@' . $parent_contact['nick'] . ' ' . $body;
                $tags[] = '@' . $parent_contact['nick'];
@@ -384,7 +413,8 @@ function item_post(&$a) {
                                                );
                                        }
                                        else {
-                                               $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
+                                               $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
+                                                       dbesc($name),
                                                        dbesc($name),
                                                        intval($profile_uid)
                                                );
@@ -436,7 +466,7 @@ function item_post(&$a) {
                        if(count($r)) {
                                if(strlen($attachments))
                                        $attachments .= ',';
-                               $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" size="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : ' ') . '"[/attach]'; 
+                               $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]'; 
                        }
                        $body = str_replace($match[1],'',$body);
                }
@@ -488,6 +518,7 @@ function item_post(&$a) {
        $datarray['private']       = $private;
        $datarray['pubmail']       = $pubmail_enable;
        $datarray['attach']        = $attachments;
+       $datarray['bookmark']      = intval($bookmark);
        $datarray['thr-parent']    = $thr_parent;
 
        /**
@@ -502,6 +533,9 @@ function item_post(&$a) {
 
        if($orig_post)
                $datarray['edit']      = true;
+       else
+               $datarray['guid']      = get_guid();
+
 
        call_hooks('post_local',$datarray);
 
@@ -525,10 +559,11 @@ function item_post(&$a) {
                $post_id = 0;
 
 
-       $r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, 
+       $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`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, 
-               `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach` )
-               VALUES( %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', %d, %d, '%s' )",
+               `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark` )
+               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', %d, %d, '%s', %d )",
+               dbesc($datarray['guid']),
                intval($datarray['uid']),
                dbesc($datarray['type']),
                intval($datarray['wall']),
@@ -560,7 +595,8 @@ function item_post(&$a) {
                dbesc($datarray['deny_gid']),
                intval($datarray['private']),
                intval($datarray['pubmail']),
-               dbesc($datarray['attach'])
+               dbesc($datarray['attach']),
+               intval($datarray['bookmark'])
        );
 
        $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
@@ -652,6 +688,27 @@ function item_post(&$a) {
 
                                pop_lang();
                        }
+
+                       // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
+
+                       if($self) {
+                               require_once('include/bb2diaspora.php');
+                               $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
+                               $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
+                               if($datarray['verb'] === ACTIVITY_LIKE) 
+                                       $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
+                               else
+                               $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
+
+                               $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha'));
+
+                               q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
+                                       intval($post_id),
+                       dbesc($signed_text),
+                       dbesc(base64_encode($authorsig)),
+                       dbesc($myaddr)
+                       );
+                       }
                }
                else {
                        $parent = $post_id;
@@ -777,6 +834,12 @@ function item_post(&$a) {
                }
        }
 
+
+
+
+
+
+
        logger('post_complete');
 
        // figure out how to return, depending on from whence we came