upstream patch by ian

This commit is contained in:
Garvin Hicking 2016-09-23 11:27:38 +02:00
parent fc87b5f6d7
commit 97cb741907
3 changed files with 74 additions and 18 deletions

View file

@ -1,5 +1,23 @@
2.32:
-----
* Remove S8y 2.0+ inline style for the fieldset
2.31:
-----
* Better recognize $serendipity['dbType'] query check for all supported
postgres and all sqlite versions
* Set strip_langs() method static
2.30 & 1.15 (sidebar):
----------------------
* Fix Invalid argument supplied for foreach() error in case the
$serendipity['languages'] array is missing (ie. by emerge.sh call)
2.29 & 1.14 (sidebar): 2.29 & 1.14 (sidebar):
--------------- ----------------------
* Fix config sidebar selected langs on save * Fix config sidebar selected langs on save

View file

@ -27,7 +27,7 @@ class serendipity_event_multilingual extends serendipity_event
'php' => '4.1.0' 'php' => '4.1.0'
)); ));
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED', 'BACKEND_EDITOR')); $propbag->add('groups', array('FRONTEND_ENTRY_RELATED', 'BACKEND_EDITOR'));
$propbag->add('version', '2.29'); $propbag->add('version', '2.32');
$propbag->add('configuration', array('copytext', 'placement', 'tagged_title', 'tagged_entries', 'tagged_sidebar', 'langswitch')); $propbag->add('configuration', array('copytext', 'placement', 'tagged_title', 'tagged_entries', 'tagged_sidebar', 'langswitch'));
$propbag->add('event_hooks', array( $propbag->add('event_hooks', array(
'frontend_fetchentries' => true, 'frontend_fetchentries' => true,
@ -39,7 +39,6 @@ class serendipity_event_multilingual extends serendipity_event
'backend_display' => true, 'backend_display' => true,
'frontend_entryproperties' => true, 'frontend_entryproperties' => true,
'backend_sidebar_entries' => true, 'backend_sidebar_entries' => true,
/* 'external_plugin' => true,*/
'css' => true, 'css' => true,
'backend_entryform' => true, 'backend_entryform' => true,
'backend_entry_presave' => true, 'backend_entry_presave' => true,
@ -74,7 +73,9 @@ class serendipity_event_multilingual extends serendipity_event
$_REQUEST['user_language'] = $serendipity['GET']['user_language']; $_REQUEST['user_language'] = $serendipity['GET']['user_language'];
// normal fallback // normal fallback
if (!isset($serendipity['GET']['lang_selected']) && !isset($_REQUEST['user_language'])) { if (!isset($serendipity['GET']['lang_selected']) && !isset($_REQUEST['user_language'])) {
if (!empty($_SESSION['serendipityLanguage'])) $this->showlang = $_SESSION['serendipityLanguage']; if (!empty($_SESSION['serendipityLanguage'])) {
$this->showlang = $_SESSION['serendipityLanguage'];
}
} }
} elseif (!isset($_COOKIE['serendipityLanguage'])) $resetlang = true; // force == false and we only want the translated article, nothing else being touched multilingual } elseif (!isset($_COOKIE['serendipityLanguage'])) $resetlang = true; // force == false and we only want the translated article, nothing else being touched multilingual
} }
@ -287,21 +288,23 @@ class serendipity_event_multilingual extends serendipity_event
$langs[$default_lang] = '<a class="multilingual_default multilingual_' . $default_lang . '" href="' . $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?' . serendipity_archiveURL($id, 'Default', 'serendipityHTTPPath', false) . '&amp;' . $this->urlparam('default') . '">' . $default_lang . '</a>'; $langs[$default_lang] = '<a class="multilingual_default multilingual_' . $default_lang . '" href="' . $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?' . serendipity_archiveURL($id, 'Default', 'serendipityHTTPPath', false) . '&amp;' . $this->urlparam('default') . '">' . $default_lang . '</a>';
} }
$lang = implode(', ', $langs); $lang = implode(', ', $langs);
return $lang; return $lang;
} }
// currently unused method for years
//function neglang($lang) { //function neglang($lang) {
function neglang($lang, $assert = '?!') function neglang($lang, $assert = '?!')
{ {
/* Creates the negation pattern from a two letter language identifier. */ /* Creates the negation pattern from a two letter language identifier. */
// Negative look ahead assertion. ".*" is used because any letter except of the language string shall be allowed, without it, nothing would ever match */ // Negative look ahead assertion. ".*" is used because any letter except of the language string shall be allowed, without it, nothing would ever match
return '(' . $assert . $lang . ').*'; return '(' . $assert . $lang . ').*';
//return '(?!' . $lang . ').*'; //return '(?!' . $lang . ').*';
//return '[^'.$lang[0].'][^'.$lang[1].']'; //return '[^'.$lang[0].'][^'.$lang[1].']';
} }
function strip_langs($msg) static function strip_langs($msg)
{ {
global $serendipity; global $serendipity;
@ -449,6 +452,7 @@ class serendipity_event_multilingual extends serendipity_event
// never init in genpage without adding previously set $vars, which is $view etc! // never init in genpage without adding previously set $vars, which is $view etc!
serendipity_smarty_init($serendipity['plugindata']['smartyvars']); serendipity_smarty_init($serendipity['plugindata']['smartyvars']);
} }
// set lang strip change more global, since we need this in the email subject too for example // set lang strip change more global, since we need this in the email subject too for example
$serendipity['blogTitle'] = $this->strip_langs($serendipity['blogTitle']); $serendipity['blogTitle'] = $this->strip_langs($serendipity['blogTitle']);
$serendipity['blogDescription'] = $this->strip_langs($serendipity['blogDescription']); $serendipity['blogDescription'] = $this->strip_langs($serendipity['blogDescription']);
@ -534,9 +538,9 @@ class serendipity_event_multilingual extends serendipity_event
case 'frontend_display': case 'frontend_display':
// cannot use tag_title() method here and use with Smarty3+ only // cannot use tag_title() method here and use with Smarty3+ only
// check for single entry multilingual context only, to set the correct themes banner title // check for single entry multilingual context only, to set the correct themes banner title
if (defined('Smarty::SMARTY_VERSION') && if (defined('Smarty::SMARTY_VERSION') &&
isset($eventData['properties']['multilingual_title_'.$this->showlang]) && isset($eventData['properties']['multilingual_title_'.$this->showlang]) &&
serendipity_db_bool($this->get_config('tagged_title', 'true')) && serendipity_db_bool($this->get_config('tagged_title', 'true')) &&
$serendipity['view'] == 'entry') $serendipity['view'] == 'entry')
{ {
$serendipity['smarty']->assign('head_title', $eventData['title']); $serendipity['smarty']->assign('head_title', $eventData['title']);
@ -601,7 +605,7 @@ class serendipity_event_multilingual extends serendipity_event
$this->tag_title(); $this->tag_title();
if (serendipity_db_bool($this->get_config('tagged_entries', 'true'))) { if (serendipity_db_bool($this->get_config('tagged_entries', 'true'))) {
foreach ($eventData as $key => $entry) { foreach ($eventData AS $key => $entry) {
if (isset($eventData[$key]['title'])) { if (isset($eventData[$key]['title'])) {
$eventData[$key]['title'] = $this->strip_langs($eventData[$key]['title']); $eventData[$key]['title'] = $this->strip_langs($eventData[$key]['title']);
$eventData[$key]['body'] = $this->strip_langs($eventData[$key]['body']); $eventData[$key]['body'] = $this->strip_langs($eventData[$key]['body']);
@ -638,7 +642,7 @@ class serendipity_event_multilingual extends serendipity_event
<?php <?php
} else { } else {
?> ?>
<fieldset id="edit_entry_multilingual" class="entryproperties_multilingual" style="margin: 1em 0"> <fieldset id="edit_entry_multilingual" class="entryproperties_multilingual">
<span class="wrap_legend"><legend><?php echo PLUGIN_EVENT_MULTILINGUAL_TITLE; ?></legend></span> <span class="wrap_legend"><legend><?php echo PLUGIN_EVENT_MULTILINGUAL_TITLE; ?></legend></span>
<div class="form_field"> <div class="form_field">
<?php <?php
@ -698,7 +702,7 @@ class serendipity_event_multilingual extends serendipity_event
} }
} }
if (serendipity_db_bool($this->get_config('tagged_entries', 'true'))) { if (serendipity_db_bool($this->get_config('tagged_entries', 'true'))) {
foreach ($eventData as $key => $entry) { foreach ($eventData AS $key => $entry) {
$eventData[$key]['title'] = $this->strip_langs($eventData[$key]['title']); $eventData[$key]['title'] = $this->strip_langs($eventData[$key]['title']);
$eventData[$key]['body'] = $this->strip_langs($eventData[$key]['body']); $eventData[$key]['body'] = $this->strip_langs($eventData[$key]['body']);
} }
@ -748,10 +752,10 @@ class serendipity_event_multilingual extends serendipity_event
if ($addData['source'] == 'search' && isset($eventData['find_part'])) { if ($addData['source'] == 'search' && isset($eventData['find_part'])) {
$term =& $addData['term']; $term =& $addData['term'];
$cond =& $eventData; $cond =& $eventData;
if ($serendipity['dbType'] == 'postgres') { if (stristr($serendipity['dbType'], 'postgres')) {
$cond['find_part'] .= " OR (multilingual_body.value ILIKE '%$term%' OR multilingual_extended.value ILIKE '%$term%' OR multilingual_title.value ILIKE '%$term%')"; $cond['find_part'] .= " OR (multilingual_body.value ILIKE '%$term%' OR multilingual_extended.value ILIKE '%$term%' OR multilingual_title.value ILIKE '%$term%')";
} elseif ($serendipity['dbType'] == 'sqlite') { } elseif (stristr($serendipity['dbType'], 'sqlite')) {
$term = serendipity_mb('strtolower', $term); $term = serendipity_mb('strtolower', $term);
$cond['find_part'] .= " OR (lower(multilingual_body.value) LIKE '%$term%' OR lower(multilingual_extended.value) LIKE '%$term%' OR lower(multilingual_title.value) LIKE '%$term%')"; $cond['find_part'] .= " OR (lower(multilingual_body.value) LIKE '%$term%' OR lower(multilingual_extended.value) LIKE '%$term%' OR lower(multilingual_title.value) LIKE '%$term%')";
} else { } else {
if (preg_match('@["\+\-\*~<>\(\)]+@', $term)) { if (preg_match('@["\+\-\*~<>\(\)]+@', $term)) {
@ -780,7 +784,7 @@ class serendipity_event_multilingual extends serendipity_event
case 'frontend_sidebar_plugins': case 'frontend_sidebar_plugins':
if (serendipity_db_bool($this->get_config('tagged_sidebar', 'true'))) { if (serendipity_db_bool($this->get_config('tagged_sidebar', 'true'))) {
foreach ($eventData as $key => $entry) { foreach ($eventData AS $key => $entry) {
$eventData[$key]['title'] = $this->strip_langs($eventData[$key]['title']); $eventData[$key]['title'] = $this->strip_langs($eventData[$key]['title']);
$eventData[$key]['content'] = $this->strip_langs($eventData[$key]['content']); $eventData[$key]['content'] = $this->strip_langs($eventData[$key]['content']);
} }

View file

@ -25,11 +25,45 @@ class serendipity_plugin_multilingual extends serendipity_event
)); ));
$conf = array('title', 'show_submit', 'size'); $conf = array('title', 'show_submit', 'size');
/* Available languages */
if (!is_array($serendipity['languages'])) {
$serendipity['languages'] = array('en' => 'English',
'de' => 'German',
'da' => 'Danish',
'es' => 'Spanish',
'fr' => 'French',
'fi' => 'Finnish',
'cs' => 'Czech (Win-1250)',
'cz' => 'Czech (ISO-8859-2)',
'sk' => 'Slovak',
'nl' => 'Dutch',
'is' => 'Icelandic',
'tr' => 'Turkish',
'se' => 'Swedish',
'pt' => 'Portuguese Brazilian',
'pt_PT' => 'Portuguese European',
'bg' => 'Bulgarian',
'hu' => 'Hungarian',
'no' => 'Norwegian',
'pl' => 'Polish',
'ro' => 'Romanian',
'it' => 'Italian',
'ru' => 'Russian',
'fa' => 'Persian',
'tw' => 'Traditional Chinese (Big5)',
'tn' => 'Traditional Chinese (UTF-8)',
'zh' => 'Simplified Chinese (GB2312)',
'cn' => 'Simplified Chinese (UTF-8)',
'ja' => 'Japanese',
'ko' => 'Korean',
'sa' => 'Arabic',
'ta' => 'Tamil');
}
foreach($serendipity['languages'] AS $lkey => $lval) { foreach($serendipity['languages'] AS $lkey => $lval) {
$conf[] = $lkey; $conf[] = $lkey;
} }
$propbag->add('configuration', $conf); $propbag->add('configuration', $conf);
$propbag->add('version', '1.14'); $propbag->add('version', '1.15');
$propbag->add('groups', array('FRONTEND_VIEWS')); $propbag->add('groups', array('FRONTEND_VIEWS'));
$this->dependencies = array('serendipity_event_multilingual' => 'remove'); $this->dependencies = array('serendipity_event_multilingual' => 'remove');
} }
@ -84,7 +118,7 @@ class serendipity_plugin_multilingual extends serendipity_event
echo '<form id="language_chooser" action="' . $url . '" method="post"><div>'; echo '<form id="language_chooser" action="' . $url . '" method="post"><div>';
echo '<select style="font-size: ' . $this->get_config('size', '9') . 'px" name="user_language" onchange="document.getElementById(\'language_chooser\').submit();">'; echo '<select style="font-size: ' . $this->get_config('size', '9') . 'px" name="user_language" onchange="document.getElementById(\'language_chooser\').submit();">';
// echo '<option value=""> </option>'."\n"; // echo '<option value=""> </option>'."\n";
foreach ($serendipity['languages'] as $lang_key => $language) { foreach ($serendipity['languages'] AS $lang_key => $language) {
if (serendipity_db_bool($this->get_config($lang_key, 'false'))) { if (serendipity_db_bool($this->get_config($lang_key, 'false'))) {
echo '<option value="' . $lang_key . '" ' . ($serendipity['lang'] == $lang_key ? 'selected="selected"' : '') . '>' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($language) : htmlspecialchars($language, ENT_COMPAT, LANG_CHARSET)) . '</option>'; echo '<option value="' . $lang_key . '" ' . ($serendipity['lang'] == $lang_key ? 'selected="selected"' : '') . '>' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($language) : htmlspecialchars($language, ENT_COMPAT, LANG_CHARSET)) . '</option>';
} }