diff options
author | friendica <info@friendica.com> | 2012-07-12 03:50:05 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2012-07-12 03:50:05 -0700 |
commit | 3f7b93ce6542219858014c4d6f075fe9b46a18e2 (patch) | |
tree | 2df86cf1fb2ff82f4484df1fe4990f5ea90ce2fc | |
parent | bb6d8e9597b893591854645273b6ee04ee022384 (diff) | |
download | volse-hubzilla-3f7b93ce6542219858014c4d6f075fe9b46a18e2.tar.gz volse-hubzilla-3f7b93ce6542219858014c4d6f075fe9b46a18e2.tar.bz2 volse-hubzilla-3f7b93ce6542219858014c4d6f075fe9b46a18e2.zip |
language detection and sparkle links added to plinks where appropriate
-rw-r--r-- | boot.php | 9 | ||||
-rw-r--r-- | include/conversation.php | 10 | ||||
-rwxr-xr-x | include/items.php | 3 | ||||
-rw-r--r-- | mod/item.php | 18 | ||||
-rw-r--r-- | view/theme/diabook/wall_item.tpl | 2 | ||||
-rw-r--r-- | view/theme/diabook/wallwall_item.tpl | 2 | ||||
-rw-r--r-- | view/theme/dispy/wall_item.tpl | 2 | ||||
-rw-r--r-- | view/theme/dispy/wallwall_item.tpl | 2 | ||||
-rw-r--r-- | view/theme/quattro/wall_item.tpl | 4 | ||||
-rw-r--r-- | view/theme/quattro/wallwall_item.tpl | 4 | ||||
-rw-r--r-- | view/wall_item.tpl | 2 | ||||
-rw-r--r-- | view/wallwall_item.tpl | 2 |
12 files changed, 45 insertions, 15 deletions
@@ -35,6 +35,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 * length that pictures are allowed to be (for non-square pictures, it will apply @@ -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 @@ <div class="wall-item-actions-author"> <a href="$item.profile_url" target="redir" title="$item.linktitle" class="wall-item-name-link"><span class="wall-item-name$item.sparkle">$item.name</span></a> <span class="wall-item-ago">- - {{ if $item.plink }}<a class="link" title="$item.plink.title" href="$item.plink.href" style="color: #999">$item.ago</a>{{ else }} $item.ago {{ endif }} + {{ if $item.plink }}<a class="link$item.sparkle" title="$item.plink.title" href="$item.plink.href" style="color: #999">$item.ago</a>{{ else }} $item.ago {{ endif }} {{ if $item.lock }} - <span class="fakelink" style="color: #999" onclick="lockview(event,$item.id);">$item.lock</span> {{ endif }} </span> </div> 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 @@ <a href="$item.profile_url" target="redir" title="$item.linktitle" class="wall-item-name-link"><span class="wall-item-name$item.sparkle">$item.name</span></a> $item.to <a href="$item.owner_url" target="redir" title="$item.olinktitle" class="wall-item-name-link"><span class="wall-item-name$item.osparkle" id="wall-item-ownername-$item.id">$item.owner_name</span></a> $item.vwall <span class="wall-item-ago">- - {{ if $item.plink }}<a class="link" title="$item.plink.title" href="$item.plink.href" style="color: #999">$item.ago</a>{{ else }} $item.ago {{ endif }} + {{ if $item.plink }}<a class="link$item.sparkle" title="$item.plink.title" href="$item.plink.href" style="color: #999">$item.ago</a>{{ else }} $item.ago {{ endif }} {{ if $item.lock }} - <span class="fakelink" style="color: #999" onclick="lockview(event,$item.id);">$item.lock</span> {{ endif }} </span> </div> 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 @@ <li><a href="#" id="filer-$item.id" onclick="itemFiler($item.id); return false;" class="filer-item icon file-as" title="$item.filer"></a></li> {{ endif }} {{ if $item.plink }} - <li class="wall-item-links-wrapper"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link"></a></li> + <li class="wall-item-links-wrapper$item.sparkle"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link"></a></li> {{ endif }} {{ if $item.edpost }} <li><a class="editpost icon pencil" href="$item.edpost.0" title="$item.edpost.1"></a></li> 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 <li class="wall-item-filer-wrapper"><a href="#" id="filer-$item.id" onclick="itemFiler($item.id); return false;" class="filer-item icon file-as" title="$item.star.filer"></a></li> {{ endif }} {{ if $item.plink }} - <li class="wall-item-links-wrapper"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link"></a></li> + <li class="wall-item-links-wrapper$item.sparkle"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link"></a></li> {{ endif }} {{ if $item.edpost }} <li><a class="editpost icon pencil" href="$item.edpost.0" title="$item.edpost.1"></a></li> 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 @@ <div class="wall-item-location">$item.location</div> </div> <div class="wall-item-content"> - {{ if $item.title }}<h2><a href="$item.plink.href">$item.title</a></h2>{{ endif }} + {{ if $item.title }}<h2><a href="$item.plink.href" class="$item.sparkle">$item.title</a></h2>{{ endif }} $item.body </div> </div> @@ -38,7 +38,7 @@ </div> <div class="wall-item-bottom"> <div class=""> - {{ if $item.plink }}<a class="icon s16 link" title="$item.plink.title" href="$item.plink.href">$item.plink.title</a>{{ endif }} + {{ if $item.plink }}<a class="icon s16 link$item.sparkle" title="$item.plink.title" href="$item.plink.href">$item.plink.title</a>{{ endif }} </div> <div class="wall-item-actions"> <div class="wall-item-actions-author"> 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 @@ <div class="wall-item-location">$item.location</div> </div> <div class="wall-item-content"> - {{ if $item.title }}<h2><a href="$item.plink.href">$item.title</a></h2>{{ endif }} + {{ if $item.title }}<h2><a href="$item.plink.href" class="$item.sparkle">$item.title</a></h2>{{ endif }} $item.body </div> </div> @@ -42,7 +42,7 @@ </div> <div class="wall-item-bottom"> <div class="wall-item-links"> - {{ if $item.plink }}<a class="icon s16 link" title="$item.plink.title" href="$item.plink.href">$item.plink.title</a>{{ endif }} + {{ if $item.plink }}<a class="icon s16 link$item.sparkle" title="$item.plink.title" href="$item.plink.href">$item.plink.title</a>{{ endif }} </div> <div class="wall-item-actions"> <div class="wall-item-actions-author"> 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 @@ </div> {{ endif }} {{ if $item.plink }} - <div class="wall-item-links-wrapper"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link"></a></div> + <div class="wall-item-links-wrapper"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link$item.sparkle"></a></div> {{ endif }} {{ if $item.edpost }} <a class="editpost icon pencil" href="$item.edpost.0" title="$item.edpost.1"></a> 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 @@ </div> {{ endif }} {{ if $item.plink }} - <div class="wall-item-links-wrapper"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link"></a></div> + <div class="wall-item-links-wrapper"><a href="$item.plink.href" title="$item.plink.title" target="external-link" class="icon remote-link$item.sparkle"></a></div> {{ endif }} {{ if $item.edpost }} <a class="editpost icon pencil" href="$item.edpost.0" title="$item.edpost.1"></a> |