Exemplo n.º 1
0
 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));
     }
 }
Exemplo n.º 2
0
 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));
     }
 }