]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Preloading of items in the cache when receiving them.
[friendica.git] / mod / item.php
index 6dbe99dfd0fd0918a23b9b9e307876b1084a593a..452ec8a36de917d90b8f18b194895793239782b6 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) {
 
@@ -236,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);
                }
@@ -309,7 +324,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);
        }
@@ -667,6 +686,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');
@@ -732,10 +752,20 @@ 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']);
+                       file_put_contents($cachefile, $s);
+                       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