function translate() { $translate = array(); if (!$this->saved_content['Text']) { $translate[] = 'Text'; } $trFrom = $trSect = $trText = array(); if (!empty($translate)) { $newest = $DB->asArray("SELECT t1.section, t1.* FROM content AS t1\n LEFT JOIN content t2 ON t1.section = t2.section\n AND t1.language = t2.language\n AND t1.revision < t2.revision\n WHERE t2.section IS NULL\n AND t1.id='" . Database::escape($id) . "'\n AND (t1.section='" . implode("' OR t1.section='", Database::escape($translate, true)) . "')\n ORDER BY t1.revision DESC", true); foreach ($newest as $s => $translation) { $trFrom[] = $translation['language']; $trText[] = $translation['content']; $trSect[] = $s; } } if (!$obj->Name && !$_POST['etitle']) { if ($info = $DB->metadata->getRow(array('id' => $obj->ID, 'field' => 'Name'), 'value, metameta')) { $trFrom[] = $info['metameta']; $trText[] = $info['value']; $trSect[] = 'Name'; } } $translation = array(); if (!empty($trText)) { $translation = @array_combine($trSect, google::translate($trText, $trFrom, $language)); } return $translation; }
function editView($id, $language) { global $Controller, $DB; $obj = new FlowItem($id, $language); if (!$obj) { return false; } if (!$obj->mayI(EDIT)) { errorPage(401); } $this->setContent('header', __('Editing') . ' <i>"' . $obj . '"</i>'); if ($_REQUEST['view'] == 'content') { $form = new Form('editN'); $translate = array(); if (!@$obj->content['Text'] && !$_POST['etxt']) { $translate[] = 'Text'; } $trFrom = $trSect = $trText = array(); if (!empty($translate)) { $newest = $DB->asArray("SELECT t1.section, t1.* FROM content AS t1\n LEFT JOIN content t2 ON t1.section = t2.section\n AND t1.language = t2.language\n AND t1.revision < t2.revision\n WHERE t2.section IS NULL\n AND t1.id='" . Database::escape($id) . "'\n AND (t1.section='" . implode("' OR t1.section='", Database::escape($translate, true)) . "')\n ORDER BY t1.revision DESC", true); foreach ($newest as $s => $translation) { $trFrom[] = $translation['language']; $trText[] = $translation['content']; $trSect[] = $s; } } if (!$obj->Name && !$_POST['etitle']) { if ($info = $DB->metadata->getRow(array('id' => $obj->ID, 'field' => 'Name'), 'value, metameta')) { $trFrom[] = $info['metameta']; $trText[] = $info['value']; $trSect[] = 'Name'; } } $translation = array(); if (!empty($trText)) { $translation = @array_combine($trSect, google::translate($trText, $trFrom, $language)); } $cal = false; if ($obj->Cal) { $cal = Calendar::getEvent($obj->Cal); } $calendarSettings = new Accordion(__('Calendar settings'), new Set(new Checkbox(__('Insert into calendar'), 'einscal', $_POST['einscal'] ? true : $cal), Short::datetime(__('Starts'), 'cstart', @$cal->start), Short::datetime(__('Ends'), 'cend', @$cal->end))); $calendarSettings->params = 'collapsible:true' . ($cal || $_POST['einscal'] ? '' : ',active:false'); $active = $obj->getActive(); $this->setContent('main', '<div class="nav"><a href="' . url(null, array('id', 'edit')) . '">' . icon('small/arrow_left') . __('Back') . '</a></div>' . $form->collection($calendarSettings, new Hidden('esave', 1), new Hidden('edit', $id), new Set(new Hidden('lang', $language), new FormText(__('Language'), google::languages($language)), empty($translation) ? null : '<span class="warning">' . __('Warning - Some of the text has been automatically translated') . '</span>', new Input(__('Title'), 'etitle', $_POST['etitle'] ? $_POST['etitle'] : ($obj->Name ? $obj->Name : @$translation['Name'])), new Li(Short::datetime(__('Publish'), 'estart', $active['start']), $obj->mayI(PUBLISH) ? new Minicheck(__('Activate post'), 'activated', $obj->Activated || $obj->Activated === '' || isset($_POST['activated'])) : null), Short::datetime(__('Hide'), 'eend', $active['stop']), new TagInput(__('Flow'), 'flows', Flow::flows(), $_POST['flows'] ? $_POST['flows'] : $obj->Flows, true, false, 'required'), new ImagePicker(__('Image'), 'eimg', $_POST['eimg'] ? $_POST['eimg'] : $obj->Image), new htmlfield(_('Text'), 'etxt', $_POST['etxt'] ? $_POST['etxt'] : (@$obj->content['Text'] ? @$obj->content['Text'] : @$translation['Text'])), new Checkbox(__('Avoid updating time'), 'eupdate')))); } else { PageEditor::saveChanges($obj); $this->setContent('main', PageEditor::editor($id, null, $this->ID)); } }
/** * View the page for editing the user terms * @return string */ function changeTerms() { global $CONFIG, $DB; $languages = google::languages((array) $CONFIG->Site->languages); $terms = $DB->{'aliases,content'}->asList(array('aliases.alias' => 'Terms', 'content.section' => 'Terms'), 'content.language,content.content', false, true); reset($terms); $norm = array('lang' => key($terms), 'text' => current($terms)); $lTabs = array(); foreach ($languages as $l => $lang) { $lTabs[] = new Tab($lang, new htmlfield(__('Terms'), 'terms[' . $l . ']', isset($terms[$l]) ? @$terms[$l] : google::translate(@$norm['text'], @$norm['lang'], $l))); } $form = new Form('saveTerms'); return '<div class="nav"><a href="' . url(null, 'id') . '">' . icon('small/arrow_left') . __('Back') . '</a></div>' . $form->collection(new Tabber('tT', $lTabs)); }
/** * Loads the contents of a page * @access public * @return void */ function loadContent($force = false, $prohibit_translation = false) { if ($this->cLoaded && !$force) { return; } global $DB, $USER, $Templates, $CONFIG; if ($this->ID == false) { return; } if ($force) { $this->content = false; } $this->cLoaded = true; if (is_array($this->content)) { $skip = array_keys($this->content); $m = $this->content; } else { $skip = $m = array(); } // READ THIS: This part is not obvious at all! // Language list, NB: reverse preferred order, fallback languages starting with least preferred language first continued in increasing relevance and primary language last $languagelist = "'" . join("','", array_unique(array('en', $this->loadedLanguage))) . "'"; $this->saved_content = array_merge($m, (array) @$DB->asList("\nSELECT t1.`section`,t1.`content`\nFROM\n (\n `content` AS t1\n LEFT OUTER JOIN `content` t2 ON t1.`section` = t2.`section`\n AND t1.`id` = t2.`id`\n AND t1.`revision` < t2.`revision`\n AND field( t1.`language` , " . $languagelist . " ) = field( t2.`language` , " . $languagelist . " )\n )\n LEFT OUTER JOIN\n (\n `content` AS t3\n LEFT OUTER JOIN `content` t4 ON t3.`section` = t4.`section`\n AND t3.`id` = t4.`id`\n AND t3.`revision` < t4.`revision`\n AND field( t3.`language` , " . $languagelist . " ) = field( t4.`language` , " . $languagelist . " )\n )\n ON t1.`section` = t3.`section`\n AND t1.`id` = t3.`id`\n AND field( t1.`language` , " . $languagelist . " ) < field( t3.`language` , " . $languagelist . " )\nWHERE t1.`id` = " . (int) $this->ID . "\n AND t2.id IS NULL\n AND t4.id IS NULL\n AND t3.id IS NULL" . (empty($skip) ? '' : " AND t1.section NOT IN ('" . join("','", $skip) . "')"), true)); if ($this->AutoTranslate && !$prohibit_translation && $USER->settings['language'] && $USER->settings['auto_Translate'] && $CONFIG->Site->auto_Translate === 'yes') { $diff = array_diff($Templates->current->sections, array_keys($this->content)); if (!empty($diff)) { $c = $DB->content->asList(array("id" => $this->ID, 'section' => $diff), 'section,content,language', false, true, "revision DESC"); $sections = $content = $languages = array(); foreach ($c as $section => $data) { if (!empty($data[0])) { $sections[] = $section; $content[] = $data[0]; $languages[] = $data[1]; } } if (!empty($sections) && ($translation = google::translate($content, $languages, $this->loadedLanguage))) { foreach ($translation as &$tr) { $tr = '<div class="warn_autotranslate">' . __('Warning: auto-translated text') . '</div>' . $tr; } $this->content = array_combine($sections, $translation); } } } }
function editView($id, $language) { global $Controller, $DB; $obj = new NewsItem($id, $language); if (!$obj) { return false; } if (!$obj->mayI(EDIT)) { errorPage(401); } $this->setContent('header', __('Editing') . ' <i>"' . $obj . '"</i>'); if ($_REQUEST['view'] == 'content') { $form = new Form('editN'); $translate = array(); if (!@$obj->content['Preamble'] && !$_POST['apre']) { $translate[] = 'Preamble'; } if (!@$obj->content['Text'] && !$_POST['atxt']) { $translate[] = 'Text'; } $trFrom = $trSect = $trText = array(); if (!empty($translate)) { $newest = $DB->asArray("SELECT t1.section, t1.* FROM content AS t1\n LEFT JOIN content t2 ON t1.section = t2.section\n AND t1.language = t2.language\n AND t1.revision < t2.revision\n WHERE t2.section IS NULL\n AND t1.id='" . Database::escape($id) . "'\n AND (t1.section='" . implode("' OR t1.section='", Database::escape($translate, true)) . "')\n ORDER BY t1.revision DESC", true); foreach ($newest as $s => $translation) { $trFrom[] = $translation['language']; $trText[] = $translation['content']; $trSect[] = $s; } } if (!$obj->Name && !$_POST['atitle']) { if ($info = $DB->metadata->getRow(array('id' => $obj->ID, 'field' => 'Name'), 'value, metameta')) { $trFrom[] = $info['metameta']; $trText[] = $info['value']; $trSect[] = 'Name'; } } $translation = array(); if (!empty($trText)) { $translation = @array_combine($trSect, google::translate($trText, $trFrom, $language)); } $this->setContent('main', '<div class="nav"><a href="' . url(null, array('id', 'edit')) . '">' . icon('small/arrow_left') . __('Back') . '</a></div>' . $form->collection(new Hidden('asave', 1), new Hidden('edit', $id), new Set(new Hidden('lang', $language), new FormText(__('Language'), google::languages($language)), empty($translation) ? null : '<span class="warning">' . __('Warning - Some of the text has been automatically translated') . '</span>', new Input(__('Title'), 'atitle', $_POST['atitle'] ? $_POST['atitle'] : ($obj->Name ? $obj->Name : @$translation['Name'])), new Li(new Datepicker(__('Publish'), 'apubd', $_POST['apubd'] ? $_POST['apubd'] : ($obj->Publish ? date('Y-m-d', $obj->Publish) : '')), new Timepickr(false, 'apubt', $_POST['apubt'] ? $_POST['pubt'] : ($obj->Publish ? date('H:i', $obj->Publish) : ''))), new htmlfield(__('Text'), 'atxt', $_POST['atxt'] ? $_POST['atxt'] : (@$obj->content['Text'] ? @$obj->content['Text'] : @$translation['Text'])), new htmlfield(__('Preamble'), 'apre', $_POST['apre'] ? $_POST['apre'] : (@$obj->content['Preamble'] ? @$obj->content['Preamble'] : @$translation['Preamble']))))); } else { PageEditor::saveChanges($obj); $this->setContent('main', PageEditor::editor($id)); } }