diff --git a/doc/Home.md b/doc/Home.md index ff991e3d2a..10948fa3b1 100644 --- a/doc/Home.md +++ b/doc/Home.md @@ -10,7 +10,7 @@ Friendica Documentation and Resources * [BBCode tag reference](help/BBCode) * [Comment, sort and delete posts](help/Text_comment) * [Profiles](help/Profiles) - * [Accesskey reference](help/Accesskeys + * [Accesskey reference](help/Accesskeys) * [Events](help/events) * You and other users * [Connectors](help/Connectors) diff --git a/doc/snarty3-templates.md b/doc/smarty3-templates.md similarity index 100% rename from doc/snarty3-templates.md rename to doc/smarty3-templates.md diff --git a/include/items.php b/include/items.php index 6378267570..2d05488bcd 100644 --- a/include/items.php +++ b/include/items.php @@ -1096,6 +1096,48 @@ function add_guid($item) { dbesc($item["uri"]), dbesc($item["network"])); } +// Adds a "lang" specification in a "postopts" element of given $arr, +// if possible and not already present. +// Expects "body" element to exist in $arr. +// TODO: add a parameter to request forcing override +function item_add_language_opt(&$arr) { + + if (version_compare(PHP_VERSION, '5.3.0', '<')) return; // LanguageDetect.php not available ? + + if ( x($arr, 'postopts') ) + { + if ( strstr($arr['postopts'], 'lang=') ) + { + // do not override + // TODO: add parameter to request overriding + return; + } + $postopts = $arr['postopts']; + } + else + { + $postopts = ""; + } + + require_once('library/langdet/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'] : ''); + $lng = $l->detect($naked_body, 3); + + if (sizeof($lng) > 0) { + if ($postopts != "") $postopts .= '&'; // arbitrary separator, to be reviewed + $postopts .= 'lang='; + $sep = ""; + foreach ($lng as $language => $score) { + $postopts .= $sep . $language.";".$score; + $sep = ':'; + } + $arr['postopts'] = $postopts; + } +} + function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) { // If it is a posting where users should get notifications, then define it as wall posting @@ -1185,29 +1227,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) // $arr['body'] = strip_tags($arr['body']); - - if (version_compare(PHP_VERSION, '5.3.0', '>=')) { - require_once('library/langdet/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'] : ''); - $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; - } - $arr['postopts'] = $postopts; - } - } + item_add_language_opt($arr); if ($notify) $guid_prefix = ""; diff --git a/mod/item.php b/mod/item.php index d203ce64d4..91a94974e9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -18,7 +18,6 @@ require_once('include/crypto.php'); require_once('include/enotify.php'); require_once('include/email.php'); -require_once('library/langdet/Text/LanguageDetect.php'); require_once('include/tags.php'); require_once('include/files.php'); require_once('include/threads.php'); @@ -268,32 +267,8 @@ function item_post(&$a) { $guid = get_guid(32); - $naked_body = preg_replace('/\[(.+?)\]/','',$body); - - if (version_compare(PHP_VERSION, '5.3.0', '>=')) { - $l = new Text_LanguageDetect; - //$lng = $l->detectConfidence($naked_body); - //$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); - } - else - $postopts = ''; + item_add_language_opt($_REQUEST); + $postopts = $_REQUEST['postopts'] ? $_REQUEST['postopts'] : ""; $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);