]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
update IT strings
[friendica.git] / mod / item.php
index 8fe1c05c129ee054b8e06df60c7195954a88e0b6..cca40e3a0216de1fcc955349a0175cb4ae3fbe44 100644 (file)
@@ -18,7 +18,8 @@
 require_once('include/crypto.php');
 require_once('include/enotify.php');
 require_once('include/email.php');
-require_once('Text/LanguageDetect.php');
+require_once('library/langdet/Text/LanguageDetect.php');
+require_once('include/tags.php');
 
 function item_post(&$a) {
 
@@ -46,6 +47,19 @@ function item_post(&$a) {
        $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
        $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
 
+
+       // Check for doubly-submitted posts, and reject duplicates
+       // Note that we have to ignore previews, otherwise nothing will post
+       // after it's been previewed
+       if(!$preview && x($_REQUEST['post_id_random'])) {
+               if(x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
+                       logger("item post: duplicate post", LOGGER_DEBUG);
+                       item_post_return($a->get_baseurl(), $api_source, $return_path);
+               }
+               else
+                       $_SESSION['post-random'] = $_REQUEST['post_id_random'];
+       }
+
        /**
         * Is this a reply to something?
         */
@@ -98,7 +112,7 @@ function item_post(&$a) {
 
                // multi-level threading - preserve the info but re-parent to our single level threading
                //if(($parid) && ($parid != $parent))
-                       $thr_parent = $parent_uri;
+               $thr_parent = $parent_uri;
 
                if($parent_item['contact-id'] && $uid) {
                        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@@ -223,9 +237,23 @@ function item_post(&$a) {
 
                if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
                        $l = new Text_LanguageDetect;
-                       $lng = $l->detectConfidence($naked_body);
+                       //$lng = $l->detectConfidence($naked_body);
+                       //$postopts = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
 
-                       $postopts = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
+                       $lng = $l->detect($naked_body, 3);
+
+                       if (sizeof($lng) > 0) {
+                               $postopts = "";
+
+                               foreach ($lng as $language => $score) {
+                                       if ($postopts == "")
+                                               $postopts = "lang=";
+                                       else
+                                               $postopts .= ":";
+
+                                       $postopts .= $language.";".$score;
+                               }
+                       }
 
                        logger('mod_item: detect language' . print_r($lng,true) . $naked_body, LOGGER_DATA);
                }
@@ -235,6 +263,10 @@ function item_post(&$a) {
 
                $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
 
+
+               if($user['hidewall'])
+                       $private = 2;
+
                // If this is a comment, set the permissions from the parent.
 
                if($parent_item) {
@@ -296,7 +328,11 @@ function item_post(&$a) {
        // First figure out if it's a status post that would've been
        // created using tinymce. Otherwise leave it alone. 
 
-       $plaintext = (local_user() ? intval(get_pconfig(local_user(),'system','plaintext')) : 0);
+/*     $plaintext = (local_user() ? intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled($profile_uid,'richtext') : 0);
+       if((! $parent) && (! $api_source) && (! $plaintext)) {
+               $body = fix_mce_lf($body);
+       }*/
+       $plaintext = (local_user() ? !feature_enabled($profile_uid,'richtext') : 0);
        if((! $parent) && (! $api_source) && (! $plaintext)) {
                $body = fix_mce_lf($body);
        }
@@ -373,7 +409,7 @@ function item_post(&$a) {
 
        $match = null;
 
-       if((! $preview) && preg_match_all("/\[img([\=0-9x]*)\](.*?)\[\/img\]/",$body,$match)) {
+       if((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) {
                $images = $match[2];
                if(count($images)) {
                        foreach($images as $image) {
@@ -654,6 +690,7 @@ function item_post(&$a) {
                        intval($post_id),
                        intval($profile_uid)
                );
+               create_tags_from_itemuri($post_id, $profile_uid);
 
                // update filetags in pconfig
                 file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
@@ -719,10 +756,22 @@ function item_post(&$a) {
        if(count($r)) {
                $post_id = $r[0]['id'];
                logger('mod_item: saved item ' . $post_id);
+               create_tags_from_item($post_id);
 
                // update filetags in pconfig
                 file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
 
+               // Store the fresh generated item into the cache
+               $cachefile = get_cachefile($datarray["guid"]."-".hash("md5", $datarray['body']));
+
+               if (($cachefile != '') AND !file_exists($cachefile)) {
+                       $s = prepare_text($datarray['body']);
+                       $stamp1 = microtime(true);
+                       file_put_contents($cachefile, $s);
+                       $a->save_timestamp($stamp1, "file");
+                       logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile);
+               }
+
                if($parent) {
 
                        // This item is the last leaf and gets the comment box, clear any ancestors
@@ -846,16 +895,25 @@ function item_post(&$a) {
                                        . '<br />';
                                $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  = 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";
+                                if (!$datarray['title']=='') {
+                                    $subject = email_header_encode($datarray['title'],'UTF-8');
+                                } else {
+                                   $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']),'UTF-8');
+                                }
                                $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
                                $html    = prepare_body($datarray);
                                $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
-                               @mail($addr, $subject, $message, $headers);
+                                include_once('include/html2plain.php');
+                                $params = array (
+                                    'fromName' => $a->user['username'],
+                                    'fromEmail' => $a->user['email'],
+                                    'toEmail' => $addr,
+                                    'replyTo' => $a->user['email'],
+                                    'messageSubject' => $subject,
+                                    'htmlVersion' => $message,
+                                    'textVersion' => html2plain($html.$disclaimer),
+                                );
+                                enotify::send($params);
                        }
                }
        }
@@ -873,30 +931,32 @@ function item_post(&$a) {
 
        logger('post_complete');
 
+       item_post_return($a->get_baseurl(), $api_source, $return_path);
+       // NOTREACHED
+}
+
+function item_post_return($baseurl, $api_source, $return_path) {
        // figure out how to return, depending on from whence we came
 
        if($api_source)
                return;
 
        if($return_path) {
-               goaway($a->get_baseurl() . "/" . $return_path);
+               goaway($baseurl . "/" . $return_path);
        }
 
        $json = array('success' => 1);
        if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload']))
-               $json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
+               $json['reload'] = $baseurl . '/' . $_REQUEST['jsreload'];
 
        logger('post_json: ' . print_r($json,true), LOGGER_DEBUG);
 
        echo json_encode($json);
        killme();
-       // NOTREACHED
 }
 
 
 
-
-
 function item_content(&$a) {
 
        if((! local_user()) && (! remote_user()))
@@ -904,10 +964,17 @@ function item_content(&$a) {
 
        require_once('include/security.php');
 
+       $o = '';
        if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
-               require_once('include/items.php');
-               drop_item($a->argv[2]);
+               require_once('include/items.php'); 
+               $o = drop_item($a->argv[2], !is_ajax());
+               if (is_ajax()){
+                       // ajax return: [<item id>, 0 (no perm) | <owner id>] 
+                       echo json_encode(array(intval($a->argv[2]), intval($o)));
+                       kllme();
+               }
        }
+       return $o;
 }
 
 /**
@@ -994,7 +1061,26 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
                                                intval($tagcid),
                                                intval($profile_uid)
                                );
-                       } elseif(strstr($name,'_') || strstr($name,' ')) { //no id
+                       }
+                       else {
+                               $newname = str_replace('_',' ',$name);
+
+                               //select someone from this user's contacts by name
+                               $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
+                                               dbesc($newname),
+                                               intval($profile_uid)
+                               );
+
+                               if(! $r) {
+                                       //select someone by attag or nick and the name passed in
+                                       $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)
+                                       );
+                               }
+                       }
+/*                     } elseif(strstr($name,'_') || strstr($name,' ')) { //no id
                                //get the real name
                                $newname = str_replace('_',' ',$name);
                                //select someone from this user's contacts by name
@@ -1009,7 +1095,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
                                                dbesc($name),
                                                intval($profile_uid)
                                );
-                       }
+                       }*/
                        //$r is set, if someone could be selected
                        if(count($r)) {
                                $profile = $r[0]['url'];