]> git.mxchange.org Git - friendica.git/commitdiff
language detection - result is stored in item['postopts']
authorfriendica <info@friendica.com>
Thu, 12 Jul 2012 05:45:14 +0000 (22:45 -0700)
committerfriendica <info@friendica.com>
Thu, 12 Jul 2012 05:45:14 +0000 (22:45 -0700)
boot.php
include/items.php
mod/item.php

index 63a2ad33851e2db68f4c1244f36f76eea0da8a02..3d81c3c391945df81473e448ac860afc2bc953fb 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -413,6 +413,7 @@ if(! class_exists('App')) {
                                        . 'include' . PATH_SEPARATOR
                                        . 'library' . PATH_SEPARATOR
                                        . 'library/phpsec' . PATH_SEPARATOR
+                                       . 'library/langdet' . PATH_SEPARATOR
                                        . '.' );
 
                        if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
index a88246cd6b6b00efe6179f037cae455410c09a8c..388b27a196c685ba8359c0bb32274bd97924d709 100755 (executable)
@@ -816,6 +816,12 @@ function item_store($arr,$force_parent = false) {
        if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) 
                $arr['body'] = strip_tags($arr['body']);
 
+       require_once('Text/LanguageDetect.php');
+       $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']);
+       $l = new Text_LanguageDetect;
+       $lng = $l->detectConfidence($naked_body);
+       $arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
+
 
        $arr['wall']          = ((x($arr,'wall'))          ? intval($arr['wall'])                : 0);
        $arr['uri']           = ((x($arr,'uri'))           ? notags(trim($arr['uri']))           : random_string());
index da9185cb8ed6d13626f4ef55f19cf49dbd95b444..b4e894337e3c9073c00507d45491cac7583a1411 100644 (file)
@@ -18,6 +18,7 @@
 require_once('include/crypto.php');
 require_once('include/enotify.php');
 require_once('include/email.php');
+require_once('Text/LanguageDetect.php');
 
 function item_post(&$a) {
 
@@ -216,6 +217,15 @@ function item_post(&$a) {
                $emailcc           = notags(trim($_REQUEST['emailcc']));
                $body              = escape_tags(trim($_REQUEST['body']));
 
+
+               $naked_body = preg_replace('/\[(.+?)\]/','',$body);
+               $l = new Text_LanguageDetect;
+               $lng = $l->detectConfidence($naked_body);
+
+               $postopts = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
+
+               logger('mod_item: detect language' . print_r($lng,true) . $naked_body, LOGGER_DATA);
+
                $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
 
                // If this is a comment, set the permissions from the parent.
@@ -561,7 +571,7 @@ function item_post(&$a) {
        $datarray['attach']        = $attachments;
        $datarray['bookmark']      = intval($bookmark);
        $datarray['thr-parent']    = $thr_parent;
-       $datarray['postopts']      = '';
+       $datarray['postopts']      = $postopts;
        $datarray['origin']        = $origin;
        $datarray['moderated']     = $allow_moderated;