diff --git a/include/ajax.content.php b/include/ajax.content.php index d7863cb880c48e781059e4db60049341bd48154e..f535d3c2dd745b498c005fbddeb3c8d44ca152c7 100644 --- a/include/ajax.content.php +++ b/include/ajax.content.php @@ -130,21 +130,35 @@ class ContentAjaxAPI extends AjaxController { } function manageContent($id, $lang=false) { - global $thisstaff; + global $thisstaff, $cfg; if (!$thisstaff) Http::response(403, 'Login Required'); $content = Page::lookup($id, $lang); + + $langs = $cfg->getSecondaryLanguages(); + $tags = array( + $content->getTranslateTag('body') => 'body', + $content->getTranslateTag('title') => 'title', + ); + $translations = CustomDataTranslation::allTranslations( + array_keys($tags), 'article'); + foreach ($translations as $t) { + $info[$tags[$t->object_hash]][$t->lang] = $t->text; + } + include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; } function manageNamedContent($type, $lang=false) { - global $thisstaff; + global $thisstaff, $cfg; if (!$thisstaff) Http::response(403, 'Login Required'); + $langs = $cfg->getSecondaryLanguages(); + $content = Page::lookup(Page::getIdByType($type, $lang)); include STAFFINC_DIR . 'templates/content-manage.tmpl.php'; } diff --git a/include/class.page.php b/include/class.page.php index 5eea8eacd32cb941d0b094f757bc2cf3e79e7ce3..617190f3a97cf5a40c981ef3c2824351915030c2 100644 --- a/include/class.page.php +++ b/include/class.page.php @@ -302,39 +302,46 @@ class Page { function saveTranslations($vars, &$errors) { global $thisstaff; - $tag = $this->getTranslateTag('body'); - $translations = CustomDataTranslation::allTranslations($tag,'article'); + $tags = array( + 'body' => $this->getTranslateTag('body'), + 'title' => $this->getTranslateTag('title'), + $this->getTranslateTag('body') => 'body', + $this->getTranslateTag('title') => 'title', + ); + $translations = CustomDataTranslation::allTranslations(array_values($tags), 'article'); foreach ($translations as $t) { - foreach ($vars['trans'] as $lang=>$content) { - if (strcasecmp($lang, $t->lang) !== 0) - continue; + $content = @$vars['trans'][$t->lang][$tags[$t->object_hash]]; + if (!$content) + continue; + $content = Format::sanitize($content); + // Content is not new and shouldn't be added below + unset($vars['trans'][$t->lang][$tags[$t->object_hash]]); + if ($content == $t->text) + continue; + $t->text = $content; + $t->agent_id = $thisstaff->getId(); + if (!$t->save()) + return false; + } + // New translations (?) + foreach ($vars['trans'] as $lang=>$parts) { + foreach ($parts as $tag=>$content) { $content = Format::sanitize($content); - unset($vars['trans'][$lang]); - if ($content == $t->text) + if (!$content || !isset($tags[$tag])) continue; - $t->text = $content; - $t->agent_id = $thisstaff->getId(); + $t = CustomDataTranslation::create(array( + 'type' => 'article', + 'object_hash' => $tags[$tag], + 'lang' => $lang, + 'text' => $content, + 'revision' => 1, + 'agent_id' => $thisstaff->getId(), + 'updated' => SqlFunction::NOW(), + )); if (!$t->save()) return false; } } - // New translations (?) - foreach ($vars['trans'] as $lang=>$content) { - $content = Format::sanitize($content); - if (!$content) - continue; - $t = CustomDataTranslation::create(array( - 'type' => 'article', - 'object_hash' => $tag, - 'lang' => $lang, - 'text' => $content, - 'revision' => 1, - 'agent_id' => $thisstaff->getId(), - 'updated' => new SqlFunction('NOW'), - )); - if (!$t->save()) - return false; - } return true; } } diff --git a/include/class.translation.php b/include/class.translation.php index e6fb8301d6b80442257136b7b54ecb21cb079632..b01d8bfc8cffa16148aece8bfd9bb18fc3d50bfb 100644 --- a/include/class.translation.php +++ b/include/class.translation.php @@ -935,10 +935,14 @@ class CustomDataTranslation extends VerySimpleModel { } static function allTranslations($msgid, $type='phrase') { - return static::objects()->filter(array( - 'type' => $type, - 'object_hash' => $msgid - ))->all(); + $criteria = array('type' => $type); + + if (is_array($msgid)) + $criteria['object_hash__in'] = $msgid; + else + $criteria['object_hash'] = $msgid; + + return static::objects()->filter($criteria)->all(); } static function getDepartmentNames($ids) { diff --git a/include/staff/page.inc.php b/include/staff/page.inc.php index a83de55b377fbccd3a56aeab43dd5fd347dc3f88..ab74e82311201b63ff834cc0300bf83457f50e46 100644 --- a/include/staff/page.inc.php +++ b/include/staff/page.inc.php @@ -149,7 +149,7 @@ $($('option:selected', this).val()).show(); "> <?php if ($langs && $page) { foreach ($langs as $tag) { ?> <div id="translation-<?php echo $tag; ?>" style="display:none" lang="<?php echo $tag; ?>"> - <textarea name="trans[<?php echo $tag; ?>]" cols="21" rows="12" + <textarea name="trans[<?php echo $tag; ?>][body]" cols="21" rows="12" style="width:98%;" class="richtext draft" <?php list($draft, $attrs) = Draft::getDraftAndDataAttrs('page', $info['id'].'.'.$tag, $info['trans'][$tag]); diff --git a/include/staff/templates/content-manage.tmpl.php b/include/staff/templates/content-manage.tmpl.php index ddf9892ad4a5eef850ac4927571538f7580ec9c0..bba002f97e5b652fd582a8ebc675ac412c110ae1 100644 --- a/include/staff/templates/content-manage.tmpl.php +++ b/include/staff/templates/content-manage.tmpl.php @@ -1,14 +1,51 @@ <h3><?php echo __('Manage Content'); ?> — <?php echo Format::htmlchars($content->getName()); ?></h3> <a class="close" href=""><i class="icon-remove-circle"></i></a> <hr/> +<?php if ($langs) { ?> +<div class="banner"> + <span class="pull-left"> + <i class="icon-globe icon-large"></i> + <?php echo __('This content is translatable'); ?> + </span> + <span class="pull-right"> + <select onchange="javascript: + $('option', this).each(function(){$($(this).val()).hide()}); + $($('option:selected', this).val()).show(); "> + <option value="#reference-text"><?php echo + Internationalization::getLanguageDescription($cfg->getPrimaryLanguage()); + ?> — <?php echo __('Primary'); ?></option> +<?php foreach ($langs as $tag) { ?> + <option value="#translation-<?php echo $tag; ?>"><?php echo + Internationalization::getLanguageDescription($tag); + ?></option> +<?php } ?> + </select> + </span> +</div> +<?php } ?> <form method="post" action="#content/<?php echo $content->getId(); ?>"> + <div id="reference-text" lang="<?php echo $cfg->getPrimaryLanguage(); ?>"> <input type="text" style="width: 100%; font-size: 14pt" name="name" value="<?php echo Format::htmlchars($content->getName()); ?>" /> <div style="margin-top: 5px"> <textarea class="richtext no-bar" name="body"><?php - echo Format::viewableImages($content->getBody()); + echo Format::htmlchars(Format::viewableImages($content->getBody())); +?></textarea> + </div> + </div> + +<?php foreach ($langs as $tag) { ?> + <div id="translation-<?php echo $tag; ?>" style="display:none" lang="<?php echo $tag; ?>"> + <input type="text" style="width: 100%; font-size: 14pt" name="trans[<?php echo $tag; ?>][title]" value="<?php + echo Format::htmlchars($info['title'][$tag]); ?>" /> + <div style="margin-top: 5px"> + <textarea class="richtext no-bar" name="trans[<?php echo $tag; ?>][body]"><?php + echo Format::htmlchars(Format::viewableImages($info['body'][$tag])); ?></textarea> </div> + </div> +<?php } ?> + <div id="msg_info" style="margin-top:7px"><?php echo $content->getNotes(); ?></div> <hr/>