Skip to content
Snippets Groups Projects
Commit 59c31e92 authored by Jared Hancock's avatar Jared Hancock
Browse files

AMENDME: kb: Use vertical tabs to separate translations

Also complete the translation client-side
parent 38e6f10c
Branches
Tags
No related merge requests found
...@@ -332,7 +332,7 @@ body .redactor_box_fullscreen { ...@@ -332,7 +332,7 @@ body .redactor_box_fullscreen {
.redactor_toolbar:after { .redactor_toolbar:after {
content: ""; content: "";
display: table; display: table;
clear: both; /* clear: both; */
} }
.redactor_toolbar.redactor-toolbar-overflow { .redactor_toolbar.redactor-toolbar-overflow {
overflow-y: auto; overflow-y: auto;
......
...@@ -158,10 +158,10 @@ class FAQ { ...@@ -158,10 +158,10 @@ class FAQ {
return $this->_local; return $this->_local;
} }
function getLocalQuestion($lang=false) { function getLocalQuestion($lang=false) {
return $this->_getLocal('q', $lang); return $this->_getLocal('question', $lang);
} }
function getLocalBodyWithImages($lang=false) { function getLocalAnswerWithImages($lang=false) {
return $this->_getLocal('a', $lang); return $this->_getLocal('answer', $lang);
} }
function _getLocal($what, $lang=false) { function _getLocal($what, $lang=false) {
if (!$lang) { if (!$lang) {
...@@ -169,7 +169,7 @@ class FAQ { ...@@ -169,7 +169,7 @@ class FAQ {
} }
$translations = $this->getAllTranslations(); $translations = $this->getAllTranslations();
foreach ($translations as $t) { foreach ($translations as $t) {
if ($lang == $t->lang) { if (0 === strcasecmp($lang, $t->lang)) {
$data = $t->getComplex(); $data = $t->getComplex();
if (isset($data[$what])) if (isset($data[$what]))
return $data[$what]; return $data[$what];
...@@ -177,6 +177,12 @@ class FAQ { ...@@ -177,6 +177,12 @@ class FAQ {
} }
return $this->ht[$what]; return $this->ht[$what];
} }
function getLocalAttachments($lang=false) {
if (!$lang) {
$lang = Internationalization::getCurrentLanguage();
}
return $this->attachments->getSeparates($lang);
}
function updateTopics($ids){ function updateTopics($ids){
...@@ -212,11 +218,13 @@ class FAQ { ...@@ -212,11 +218,13 @@ class FAQ {
// General attachments (for all languages) // General attachments (for all languages)
// --------------------- // ---------------------
// Delete removed attachments. // Delete removed attachments.
$keepers = $vars['files']; if (isset($vars['files'])) {
if (($attachments = $this->attachments->getSeparates())) { $keepers = $vars['files'];
foreach($attachments as $file) { if (($attachments = $this->attachments->getSeparates())) {
if($file['id'] && !in_array($file['id'], $keepers)) foreach($attachments as $file) {
$this->attachments->delete($file['id']); if($file['id'] && !in_array($file['id'], $keepers))
$this->attachments->delete($file['id']);
}
} }
} }
// Upload new attachments IF any. // Upload new attachments IF any.
...@@ -228,6 +236,10 @@ class FAQ { ...@@ -228,6 +236,10 @@ class FAQ {
if ($langs) { if ($langs) {
$langs[] = $cfg->getPrimaryLanguage(); $langs[] = $cfg->getPrimaryLanguage();
foreach ($langs as $lang) { foreach ($langs as $lang) {
if (!isset($vars['files_'.$lang]))
// Not updating the FAQ
continue;
$keepers = $vars['files_'.$lang]; $keepers = $vars['files_'.$lang];
// Delete removed attachments. // Delete removed attachments.
...@@ -246,7 +258,7 @@ class FAQ { ...@@ -246,7 +258,7 @@ class FAQ {
$this->attachments->deleteInlines(); $this->attachments->deleteInlines();
$this->attachments->upload(Draft::getAttachmentIds($vars['answer'])); $this->attachments->upload(Draft::getAttachmentIds($vars['answer']));
if (!$this->saveTranslations($vars)) if (isset($vars['trans']) && !$this->saveTranslations($vars))
return false; return false;
$this->reload(); $this->reload();
...@@ -260,13 +272,14 @@ class FAQ { ...@@ -260,13 +272,14 @@ class FAQ {
foreach ($this->getAllTranslations() as $t) { foreach ($this->getAllTranslations() as $t) {
$trans = @$vars['trans'][$t->lang]; $trans = @$vars['trans'][$t->lang];
if (!array_filter($trans)); if (!$trans || !array_filter($trans));
// Not updating translations
continue; continue;
// Content is not new and shouldn't be added below // Content is not new and shouldn't be added below
unset($vars['trans'][$t->lang]); unset($vars['trans'][$t->lang]);
$content = array('q' => $trans['question'], $content = array('question' => $trans['question'],
'a' => Format::sanitize($trans['answer'])); 'answer' => Format::sanitize($trans['answer']));
// Don't update content which wasn't updated // Don't update content which wasn't updated
if ($content == $t->getComplex()) if ($content == $t->getComplex())
...@@ -281,8 +294,8 @@ class FAQ { ...@@ -281,8 +294,8 @@ class FAQ {
// New translations (?) // New translations (?)
$tag = $this->getTranslateTag('q:a'); $tag = $this->getTranslateTag('q:a');
foreach ($vars['trans'] as $lang=>$parts) { foreach ($vars['trans'] as $lang=>$parts) {
$content = array('q' => @$parts['question'], $content = array('question' => @$parts['question'],
'a' => Format::sanitize(@$parts['answer'])); 'answer' => Format::sanitize(@$parts['answer']));
if (!array_filter($content)) if (!array_filter($content))
continue; continue;
$t = CustomDataTranslation::create(array( $t = CustomDataTranslation::create(array(
...@@ -303,7 +316,10 @@ class FAQ { ...@@ -303,7 +316,10 @@ class FAQ {
function getAttachmentsLinks($separator=' ',$target='') { function getAttachmentsLinks($separator=' ',$target='') {
$str=''; $str='';
if(($attachments=$this->attachments->getSeparates())) { $attachments = array_merge(
$this->attachments->getSeparates() ?: array(),
$this->getLocalAttachments());
if ($attachments) {
foreach($attachments as $attachment ) { foreach($attachments as $attachment ) {
/* The h key must match validation in file.php */ /* The h key must match validation in file.php */
$hash=$attachment['key'].md5($attachment['id'].session_id().strtolower($attachment['key'])); $hash=$attachment['key'].md5($attachment['id'].session_id().strtolower($attachment['key']));
......
...@@ -10,12 +10,12 @@ $category=$faq->getCategory(); ...@@ -10,12 +10,12 @@ $category=$faq->getCategory();
&raquo; <a href="faq.php?cid=<?php echo $category->getId(); ?>"><?php echo $category->getName(); ?></a> &raquo; <a href="faq.php?cid=<?php echo $category->getId(); ?>"><?php echo $category->getName(); ?></a>
</div> </div>
<div style="width:700px;padding-top:2px;" class="pull-left"> <div style="width:700px;padding-top:2px;" class="pull-left">
<strong style="font-size:16px;"><?php echo $faq->getQuestion() ?></strong> <strong style="font-size:16px;"><?php echo $faq->getLocalQuestion() ?></strong>
</div> </div>
<div class="pull-right flush-right" style="padding-top:5px;padding-right:5px;"></div> <div class="pull-right flush-right" style="padding-top:5px;padding-right:5px;"></div>
<div class="clear"></div> <div class="clear"></div>
<p> <p>
<?php echo Format::safe_html($faq->getAnswerWithImages()); ?> <?php echo Format::safe_html($faq->getLocalAnswerWithImages()); ?>
</p> </p>
<p> <p>
<?php <?php
......
...@@ -19,8 +19,8 @@ if($faq){ ...@@ -19,8 +19,8 @@ if($faq){
if (strcasecmp($t->lang, $tag) === 0) { if (strcasecmp($t->lang, $tag) === 0) {
$trans = $t->getComplex(); $trans = $t->getComplex();
$info['trans'][$tag] = array( $info['trans'][$tag] = array(
'question' => $trans['q'], 'question' => $trans['question'],
'answer' => Format::viewableImages($trans['a']), 'answer' => Format::viewableImages($trans['answer']),
); );
break; break;
} }
...@@ -51,7 +51,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -51,7 +51,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<div> <div>
<b><?php echo __('Category Listing');?></b>: <b><?php echo __('Category Listing');?></b>:
<span class="error">*</span> <span class="error">*</span>
<span class="faded"><?php echo __('FAQ category the question belongs to.');?></span> <div class="faded"><?php echo __('FAQ category the question belongs to.');?></div>
</div> </div>
<select name="category_id" style="width:350px;"> <select name="category_id" style="width:350px;">
<option value="0"><?php echo __('Select FAQ Category');?> </option> <option value="0"><?php echo __('Select FAQ Category');?> </option>
...@@ -71,16 +71,19 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -71,16 +71,19 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<div class="error"><?php echo $errors['category_id']; ?></div> <div class="error"><?php echo $errors['category_id']; ?></div>
<?php <?php
if ($topics = Topic::getAllHelpTopics()) { ?> if ($topics = Topic::getAllHelpTopics()) {
if (!is_array(@$info['topics']))
$info['topics'] = array();
?>
<div style="padding-top:9px"> <div style="padding-top:9px">
<strong><?php echo __('Help Topics');?></strong>: <strong><?php echo __('Help Topics');?></strong>:
<?php echo __('Check all help topics related to this FAQ.');?> <div class="faded"><?php echo __('Check all help topics related to this FAQ.');?></div>
</div> </div>
<select multiple="multiple" name="topics[]" class="multiselect" <select multiple="multiple" name="topics[]" class="multiselect"
id="help-topic-selection" style="width:350px;"> id="help-topic-selection" style="width:350px;">
<?php while (list($topicId,$topic) = each($topics)) { ?> <?php while (list($topicId,$topic) = each($topics)) { ?>
<option value="<?php echo $topicId; ?>" <?php <option value="<?php echo $topicId; ?>" <?php
if (in_array($topicID, $info['topics'])) echo 'selected="selected"'; if (in_array($topicId, $info['topics'])) echo 'selected="selected"';
?>><?php echo $topic; ?></option> ?>><?php echo $topic; ?></option>
<?php } ?> <?php } ?>
</select> </select>
...@@ -108,111 +111,78 @@ if ($topics = Topic::getAllHelpTopics()) { ?> ...@@ -108,111 +111,78 @@ if ($topics = Topic::getAllHelpTopics()) { ?>
</div> </div>
<ul class="tabs" style="margin-top:9px;"> <ul class="tabs" style="margin-top:9px;">
<li class="active"><a class="active" href="#article"><?php echo __('Article Content'); ?></a></li> <li class="active"><a href="#article"><?php echo __('Article Content'); ?></a></li>
<li><a href="#attachments"><?php echo __('Attachments') . sprintf(' (%d)', <li><a href="#attachments"><?php echo __('Attachments') . sprintf(' (%d)',
count($faq->attachments->getSeparates(''))); ?></a></li> count($faq->attachments->getSeparates(''))); ?></a></li>
<li><a href="#notes"><?php echo __('Internal Notes'); ?></a></li> <li><a href="#notes"><?php echo __('Internal Notes'); ?></a></li>
</ul> </ul>
<div class="tab_content" id="article"> <div class="tab_content" id="article">
<?php if ($faq && ($langs = $cfg->getSecondaryLanguages())) { ?> <strong>Knowledgebase Article Content</strong><br/>
<div class="banner" style="margin-top:12px;">&nbsp; Here you can manage the question and answer for the article. Multiple
<span class="pull-left" style="padding-top:2px"> languages are available if enabled in the admin panel.
<i class="icon-globe icon-large"></i> <div class="clear"></div>
<?php echo __('This content is translatable'); ?> <?php
</span> $langs = Internationalization::getConfiguredSystemLanguages();
<span class="pull-right"> if ($faq) { ?>
<?php echo __('View'); ?>: <ul class="vertical tabs left" style="margin-top:10px;">
<select onchange="javascript: <li class="empty"><i class="icon-globe" title="This content is translatable"></i></li>
$('option', this).each(function(){$($(this).val()).hide()}); <?php foreach ($langs as $tag=>$i) {
$($('option:selected', this).val()).show(); "> list($lang, $locale) = explode('_', $tag);
<option value="#reference-text"><?php echo ?>
Internationalization::getLanguageDescription($cfg->getPrimaryLanguage()); <li class="<?php if ($tag == $cfg->getPrimaryLanguage()) echo "active";
?><?php echo __('Primary'); ?></option> ?>"><a href="#lang-<?php echo $tag; ?>" title="<?php
<?php foreach ($langs as $tag) { ?> echo Internationalization::getLanguageDescription($tag);
<option value="#translation-<?php echo $tag; ?>"><?php echo ?>"><span class="flag flag-<?php echo strtolower($locale ?: $info['flag'] ?: $lang); ?>"></span>
Internationalization::getLanguageDescription($tag); </a></li>
?></option>
<?php } ?>
</select>
</span>
</div>
<?php } ?> <?php } ?>
</ul>
<?php
} ?>
<div id="reference-text"> <?php foreach ($langs as $tag=>$i) {
$code = $i['code'];
if ($tag == $cfg->getPrimaryLanguage()) {
$namespace = $faq ? $faq->getId() : false;
$answer = $info['answer'];
$question = $info['question'];
$qname = 'question';
$aname = 'answer';
}
else {
$namespace = $faq->getId() . $code;
$answer = $info['trans'][$code]['answer'];
$question = $info['trans'][$code]['question'];
$qname = 'trans['.$code.'][question]';
$aname = 'trans['.$code.'][answer]';
}
?>
<div class="tab_content" style="margin-left:45px;<?php
if ($code != $cfg->getPrimaryLanguage()) echo "display:none;";
?>" id="lang-<?php echo $tag; ?>">
<div style="padding-top:9px;"> <div style="padding-top:9px;">
<b><?php echo __('Question');?> <b><?php echo __('Question');?>
<span class="error">*</span> <span class="error">*</span>
</b> </b>
<div class="error"><?php echo $errors['question']; ?></div> <div class="error"><?php echo $errors['question']; ?></div>
</div> </div>
<input type="text" size="70" name="question" <input type="text" size="70" name="<?php echo $qname; ?>"
style="font-size:105%;display:block;width:98%" style="font-size:105%;display:block;width:98%"
value="<?php echo $info['question']; ?>"> value="<?php echo $question; ?>">
<div style="margin-bottom:0.5em;margin-top:9px"> <div style="margin-bottom:0.5em;margin-top:9px">
<b><?php echo __('Answer');?></b> <b><?php echo __('Answer');?></b>
<span class="error">*</span> <span class="error">*</span>
<div class="error"><?php echo $errors['answer']; ?></div> <div class="error"><?php echo $errors['answer']; ?></div>
</div> </div>
<textarea name="answer" cols="21" rows="12" <div>
style="width:98%;" class="richtext draft" <?php <textarea name="<?php echo $aname; ?>" cols="21" rows="12"
list($draft, $attrs) = Draft::getDraftAndDataAttrs('faq', class="richtext draft" <?php
is_object($faq) ? $faq->getId() : false, $info['answer']); list($draft, $attrs) = Draft::getDraftAndDataAttrs('faq', $namespace, $answer);
echo $attrs; ?>><?php echo $draft ?: $info['answer']; echo $attrs; ?>><?php echo $draft ?: $answer;
?></textarea> ?></textarea>
<?php if (count($langs)) {
$lang = $cfg->getPrimaryLanguage(); ?>
<div style="padding-top:9px">
<strong><?php echo sprintf(__(
/* %s is the name of a language */ 'Attachments for %s'),
Internationalization::getLanguageDescription($lang));
?></strong>
<div style="margin:0 0 3px"><em class="faded"><?php echo __(
'These attachments are only available when article is rendered in this language.'
); ?></em></div>
</div> </div>
<?php
print $faq_form->getField('attachments.'.$lang)->render(); ?>
<?php } ?>
</div> <!-- end of reference-text -->
<?php if ($langs && $faq) {
foreach ($langs as $tag) { ?>
<div id="translation-<?php echo $tag; ?>" style="display:none" lang="<?php echo $tag; ?>">
<div style="padding-top:9px;">
<b><?php echo __('Question');?>
<span class="error">*</span>
</b>
<div class="error"><?php echo $errors['question']; ?></div>
</div> </div>
<input type="text" size="70" name="trans[<?php echo $tag; ?>][question]"
style="font-size:105%;display:block;width:98%"
value="<?php echo $info['trans'][$tag]['question']; ?>">
<div style="margin-bottom:0.5em;margin-top:9px">
<b><?php echo __('Answer');?></b>
<span class="error">*</span>
<div class="error"><?php echo $errors['answer']; ?></div>
</div>
<textarea name="trans[<?php echo $tag; ?>][answer]" cols="21" rows="12"
style="width:98%;" class="richtext draft" <?php
list($draft, $attrs) = Draft::getDraftAndDataAttrs('faq', $faq->getId().'.'.$tag,
$info['trans'][$tag]['answer']);
echo $attrs; ?>><?php echo $draft ?: $info['trans'][$tag]['answer'];
?></textarea>
<div style="padding-top:9px">
<strong><?php echo sprintf(__('Attachments for %s'),
Internationalization::getLanguageDescription($tag));
?></strong>
<div style="margin:0 0 3px"><em class="faded"><?php echo __(
'These attachments are only available when article is rendered in this language.'
); ?></em></div>
</div>
<?php
print $faq_form->getField('attachments.'.$tag)->render(); ?>
</div> <!-- End of this language -->
<?php } ?>
<?php } ?> <?php } ?>
</div> </div>
...@@ -225,9 +195,31 @@ echo $attrs; ?>><?php echo $draft ?: $info['trans'][$tag]['answer']; ...@@ -225,9 +195,31 @@ echo $attrs; ?>><?php echo $draft ?: $info['trans'][$tag]['answer'];
</div> </div>
<?php <?php
print $faq_form->getField('attachments')->render(); ?> print $faq_form->getField('attachments')->render(); ?>
<?php if (count($langs) > 1) {
foreach ($langs as $lang=>$i) {
$code = $i['code']; ?>
<div style="padding-top:9px">
<strong><?php echo sprintf(__(
/* %s is the name of a language */ 'Attachments for %s'),
Internationalization::getLanguageDescription($lang));
?></strong>
<div style="margin:0 0 3px"><em class="faded"><?php echo __(
'These attachments are only available when article is rendered in this language.'
); ?></em></div>
</div>
<?php
print $faq_form->getField('attachments.'.$code)->render();
}
} ?>
</div> </div>
<div class="tab_content" style="display:none;" id="notes"> <div class="tab_content" style="display:none;" id="notes">
<div>
<b><?php echo __('Internal Notes');?></b>:
<div class="faded"><?php echo __("Be liberal, they're internal");?></div>
</div>
<div style="margin-top:10px"></div>
<textarea class="richtext no-bar" name="notes" cols="21" <textarea class="richtext no-bar" name="notes" cols="21"
rows="8" style="width: 80%;"><?php echo $info['notes']; ?></textarea> rows="8" style="width: 80%;"><?php echo $info['notes']; ?></textarea>
</div> </div>
......
...@@ -955,6 +955,11 @@ ul.tabs li.active a { ...@@ -955,6 +955,11 @@ ul.tabs li.active a {
font-weight: bold; font-weight: bold;
} }
ul.tabs li.empty {
padding: 5px;
border: none !important;
}
ul.tabs.vertical { ul.tabs.vertical {
display: inline-block; display: inline-block;
height: auto; height: auto;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment