diff --git a/boot.php b/boot.php index 55f18432a..096587bb7 100644 --- a/boot.php +++ b/boot.php @@ -34,6 +34,14 @@ define ( 'JPEG_QUALITY', 100 ); */ define ( 'PNG_QUALITY', 8 ); +/** + * Language detection parameters + */ + +define ( 'LANGUAGE_DETECT_MIN_LENGTH', 128 ); +define ( 'LANGUAGE_DETECT_MIN_CONFIDENCE', 0.01 ); + + /** * * An alternate way of limiting picture upload sizes. Specify the maximum pixel @@ -415,6 +423,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=") { diff --git a/include/conversation.php b/include/conversation.php index ce8f5779c..25a2911e9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -242,6 +242,16 @@ function localize_item(&$item){ } } + // add sparkle links to appropriate permalinks + + $x = stristr($item['plink'],'/display/'); + if($x) { + $sparkle = false; + $y = best_link_url($item,$sparkle,true); + if(strstr($y,'/redir/')) + $item['plink'] = $y . '?f=&url=' . $item['plink']; + } + } diff --git a/include/items.php b/include/items.php index 5094c60c2..bc1346e92 100755 --- a/include/items.php +++ b/include/items.php @@ -826,6 +826,9 @@ function item_store($arr,$force_parent = false) { if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) $arr['body'] = strip_tags($arr['body']); + require_once('include/language.php'); + $arr['lang'] = detect_language($arr['body']); + $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string()); diff --git a/mod/item.php b/mod/item.php index 7e8d0499d..36ee05016 100644 --- a/mod/item.php +++ b/mod/item.php @@ -217,6 +217,12 @@ function item_post(&$a) { $emailcc = notags(trim($_REQUEST['emailcc'])); $body = escape_tags(trim($_REQUEST['body'])); + + require_once('include/language.php'); + $language = detect_language($body); + + logger('detected language: ' . $language); + $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. @@ -553,6 +559,7 @@ function item_post(&$a) { $datarray['title'] = $title; $datarray['body'] = $body; $datarray['app'] = $app; + $datarray['lang'] = $language; $datarray['location'] = $location; $datarray['coord'] = $coord; $datarray['tag'] = $str_tags; @@ -641,9 +648,9 @@ function item_post(&$a) { $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`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, + `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `lang`, `location`, `coord`, `tag`, `inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`,`origin`, `moderated`, `file` ) - 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', '%s', '%s', %d, %d, '%s', %d, %d, '%s' )", + 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', '%s', '%s', '%s', %d, %d, '%s', %d, %d, '%s' )", dbesc($datarray['guid']), intval($datarray['uid']), dbesc($datarray['type']), @@ -666,6 +673,7 @@ function item_post(&$a) { dbesc($datarray['title']), dbesc($datarray['body']), dbesc($datarray['app']), + dbesc($datarray['lang']), dbesc($datarray['location']), dbesc($datarray['coord']), dbesc($datarray['tag']), @@ -680,9 +688,9 @@ function item_post(&$a) { intval($datarray['pubmail']), dbesc($datarray['attach']), intval($datarray['origin']), - intval($datarray['moderated']), - dbesc($datarray['file']) - ); + intval($datarray['moderated']), + dbesc($datarray['file']) + ); $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($datarray['uri'])); diff --git a/view/theme/diabook/wall_item.tpl b/view/theme/diabook/wall_item.tpl index 123834064..5b9de2968 100644 --- a/view/theme/diabook/wall_item.tpl +++ b/view/theme/diabook/wall_item.tpl @@ -22,7 +22,7 @@
$item.name - - {{ if $item.plink }}$item.ago{{ else }} $item.ago {{ endif }} + {{ if $item.plink }}$item.ago{{ else }} $item.ago {{ endif }} {{ if $item.lock }} - $item.lock {{ endif }}
diff --git a/view/theme/diabook/wallwall_item.tpl b/view/theme/diabook/wallwall_item.tpl index bee75ad99..b2c980c78 100644 --- a/view/theme/diabook/wallwall_item.tpl +++ b/view/theme/diabook/wallwall_item.tpl @@ -28,7 +28,7 @@ $item.name $item.to $item.owner_name $item.vwall -   - {{ if $item.plink }}$item.ago{{ else }} $item.ago {{ endif }} + {{ if $item.plink }}$item.ago{{ else }} $item.ago {{ endif }} {{ if $item.lock }} - $item.lock {{ endif }} diff --git a/view/theme/dispy/wall_item.tpl b/view/theme/dispy/wall_item.tpl index 8ffae0403..8d6f258e6 100644 --- a/view/theme/dispy/wall_item.tpl +++ b/view/theme/dispy/wall_item.tpl @@ -52,7 +52,7 @@
  • {{ endif }} {{ if $item.plink }} - + {{ endif }} {{ if $item.edpost }}
  • diff --git a/view/theme/dispy/wallwall_item.tpl b/view/theme/dispy/wallwall_item.tpl index 84da598cd..f5187b710 100644 --- a/view/theme/dispy/wallwall_item.tpl +++ b/view/theme/dispy/wallwall_item.tpl @@ -59,7 +59,7 @@ class="icon recycle wall-item-share-buttons" title="$item.vote.share.0" onclick
  • {{ endif }} {{ if $item.plink }} - + {{ endif }} {{ if $item.edpost }}
  • diff --git a/view/theme/quattro/wall_item.tpl b/view/theme/quattro/wall_item.tpl index e771db068..2b12ce632 100644 --- a/view/theme/quattro/wall_item.tpl +++ b/view/theme/quattro/wall_item.tpl @@ -23,7 +23,7 @@
    $item.location
    - {{ if $item.title }}

    $item.title

    {{ endif }} + {{ if $item.title }}

    $item.title

    {{ endif }} $item.body
    @@ -38,7 +38,7 @@
    - {{ if $item.plink }}$item.plink.title{{ endif }} + {{ if $item.plink }}$item.plink.title{{ endif }}
    diff --git a/view/theme/quattro/wallwall_item.tpl b/view/theme/quattro/wallwall_item.tpl index 693ebaba6..a1d92773b 100644 --- a/view/theme/quattro/wallwall_item.tpl +++ b/view/theme/quattro/wallwall_item.tpl @@ -27,7 +27,7 @@
    $item.location
    - {{ if $item.title }}

    $item.title

    {{ endif }} + {{ if $item.title }}

    $item.title

    {{ endif }} $item.body
    @@ -42,7 +42,7 @@
    diff --git a/view/wall_item.tpl b/view/wall_item.tpl index dae33b3f7..60dde7600 100644 --- a/view/wall_item.tpl +++ b/view/wall_item.tpl @@ -48,7 +48,7 @@
    {{ endif }} {{ if $item.plink }} - + {{ endif }} {{ if $item.edpost }} diff --git a/view/wallwall_item.tpl b/view/wallwall_item.tpl index a48acfec5..b7cca3fab 100644 --- a/view/wallwall_item.tpl +++ b/view/wallwall_item.tpl @@ -52,7 +52,7 @@
    {{ endif }} {{ if $item.plink }} - + {{ endif }} {{ if $item.edpost }}