Example #1
0
 /**
  * Add all element into the form
  */
 protected function loadForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         /**
          * If the fields are disabled we don't have any values in the post.
          * When an error occurs in the other fields of the form the meta-fields would be cleared
          * therefore we alter the POST so it contains the initial values.
          */
         if (!isset($_POST['page_title'])) {
             $_POST['page_title'] = isset($this->data['title']) ? $this->data['title'] : null;
         }
         if (!isset($_POST['meta_description'])) {
             $_POST['meta_description'] = isset($this->data['description']) ? $this->data['description'] : null;
         }
         if (!isset($_POST['meta_keywords'])) {
             $_POST['meta_keywords'] = isset($this->data['keywords']) ? $this->data['keywords'] : null;
         }
         if (!isset($_POST['url'])) {
             $_POST['url'] = isset($this->data['url']) ? $this->data['url'] : null;
         }
         if ($this->custom && !isset($_POST['meta_custom'])) {
             $_POST['meta_custom'] = isset($this->data['custom']) ? $this->data['custom'] : null;
         }
         if (!isset($_POST['seo_index'])) {
             $_POST['seo_index'] = isset($this->data['data']['seo_index']) ? $this->data['data']['seo_index'] : 'none';
         }
         if (!isset($_POST['seo_follow'])) {
             $_POST['seo_follow'] = isset($this->data['data']['seo_follow']) ? $this->data['data']['seo_follow'] : 'none';
         }
     }
     // add page title elements into the form
     $this->frm->addCheckbox('page_title_overwrite', isset($this->data['title_overwrite']) && $this->data['title_overwrite'] == 'Y');
     $this->frm->addText('page_title', isset($this->data['title']) ? $this->data['title'] : null);
     // add meta description elements into the form
     $this->frm->addCheckbox('meta_description_overwrite', isset($this->data['description_overwrite']) && $this->data['description_overwrite'] == 'Y');
     $this->frm->addText('meta_description', isset($this->data['description']) ? $this->data['description'] : null);
     // add meta keywords elements into the form
     $this->frm->addCheckbox('meta_keywords_overwrite', isset($this->data['keywords_overwrite']) && $this->data['keywords_overwrite'] == 'Y');
     $this->frm->addText('meta_keywords', isset($this->data['keywords']) ? $this->data['keywords'] : null);
     // add URL elements into the form
     $this->frm->addCheckbox('url_overwrite', isset($this->data['url_overwrite']) && $this->data['url_overwrite'] == 'Y');
     $this->frm->addText('url', isset($this->data['url']) ? urldecode($this->data['url']) : null);
     // advanced SEO
     $indexValues = array(array('value' => 'none', 'label' => BackendLanguage::getLabel('None')), array('value' => 'index', 'label' => 'index'), array('value' => 'noindex', 'label' => 'noindex'));
     $this->frm->addRadiobutton('seo_index', $indexValues, isset($this->data['data']['seo_index']) ? $this->data['data']['seo_index'] : 'none');
     $followValues = array(array('value' => 'none', 'label' => BackendLanguage::getLabel('None')), array('value' => 'follow', 'label' => 'follow'), array('value' => 'nofollow', 'label' => 'nofollow'));
     $this->frm->addRadiobutton('seo_follow', $followValues, isset($this->data['data']['seo_follow']) ? $this->data['data']['seo_follow'] : 'none');
     // should we add the meta-custom field
     if ($this->custom) {
         // add meta custom element into the form
         $this->frm->addTextarea('meta_custom', isset($this->data['custom']) ? $this->data['custom'] : null);
     }
     $this->frm->addHidden('meta_id', $this->id);
     $this->frm->addHidden('base_field_name', $this->baseFieldName);
     $this->frm->addHidden('custom', $this->custom);
     $this->frm->addHidden('class_name', $this->callback['class']);
     $this->frm->addHidden('method_name', $this->callback['method']);
     $this->frm->addHidden('parameters', \SpoonFilter::htmlspecialchars(serialize($this->callback['parameters'])));
 }
Example #2
0
 /**
  * Load the form.
  */
 private function loadForm()
 {
     $this->frm = new BackendForm('settingsThemes');
     // fetch the themes
     $themes = $this->installedThemes;
     // set selected theme
     $selected = isset($_POST['installedThemes']) ? $_POST['installedThemes'] : $this->get('fork.settings')->get('Core', 'theme', 'core');
     // no themes found
     if (empty($themes)) {
         $this->redirect(BackendModel::createURLForAction('Edit') . '&id=' . $this->id . '&step=1&error=no-themes');
     }
     // loop the templates
     foreach ($themes as &$record) {
         // reformat custom variables
         $record['variables']['thumbnail'] = $record['thumbnail'];
         $record['variables']['installed'] = $record['installed'];
         $record['variables']['installable'] = $record['installable'];
         // set selected template
         if ($record['value'] == $selected) {
             $record['variables']['selected'] = true;
         }
         // unset the variable field
         unset($record['thumbnail'], $record['installed'], $record['installable']);
     }
     // templates
     $this->frm->addRadiobutton('installedThemes', $themes, $selected);
 }
Example #3
0
 /**
  * Parse a field and return the HTML.
  *
  * @param array $field Field data.
  * @return string
  */
 public static function parseField(array $field)
 {
     if (!empty($field)) {
         // init
         $frm = new BackendForm('tmp', '');
         $tpl = BackendModel::getContainer()->has('template') ? BackendModel::getContainer()->get('template') : new BackendTemplate();
         $fieldHTML = '';
         $fieldName = 'field' . $field['id'];
         $values = isset($field['settings']['values']) ? $field['settings']['values'] : null;
         $defaultValues = isset($field['settings']['default_values']) ? $field['settings']['default_values'] : null;
         $placeholder = isset($field['settings']['placeholder']) ? $field['settings']['placeholder'] : null;
         /**
          * Create form and parse to HTML
          */
         // dropdown
         if ($field['type'] == 'dropdown') {
             // values and labels are the same
             $values = array_combine($values, $values);
             // get index of selected item
             $defaultIndex = array_search($defaultValues, $values, true);
             if ($defaultIndex === false) {
                 $defaultIndex = null;
             }
             // create element
             $ddm = $frm->addDropdown($fieldName, $values, $defaultIndex);
             // empty default element
             $ddm->setDefaultElement('');
             // get content
             $fieldHTML = $ddm->parse();
         } elseif ($field['type'] == 'datetime') {
             // create element
             if ($field['settings']['input_type'] == 'date') {
                 // calculate default value
                 $amount = $field['settings']['value_amount'];
                 $type = $field['settings']['value_type'];
                 if ($type != '') {
                     switch ($type) {
                         case 'today':
                             $defaultValues = date('d/m/Y');
                             break;
                         case 'day':
                         case 'week':
                         case 'month':
                         case 'year':
                             if ($amount != '') {
                                 $defaultValues = date('d/m/Y', strtotime('+' . $amount . ' ' . $type));
                             }
                             break;
                     }
                 }
                 $datetime = $frm->addText($fieldName, $defaultValues);
             } else {
                 $datetime = $frm->addTime($fieldName, $defaultValues);
             }
             $datetime->setAttribute('disabled', 'disabled');
             // get content
             $fieldHTML = $datetime->parse();
         } elseif ($field['type'] == 'radiobutton') {
             // create element
             $rbt = $frm->addRadiobutton($fieldName, $values, $defaultValues);
             // get content
             $fieldHTML = $rbt->parse();
         } elseif ($field['type'] == 'checkbox') {
             // rebuild values
             foreach ($values as $value) {
                 $newValues[] = array('label' => $value, 'value' => $value);
             }
             // create element
             $chk = $frm->addMultiCheckbox($fieldName, $newValues, $defaultValues);
             // get content
             $fieldHTML = $chk->parse();
         } elseif ($field['type'] == 'textbox') {
             // create element
             $txt = $frm->addText($fieldName, $defaultValues);
             $txt->setAttribute('disabled', 'disabled');
             $txt->setAttribute('placeholder', $placeholder);
             // get content
             $fieldHTML = $txt->parse();
         } elseif ($field['type'] == 'textarea') {
             // create element
             $txt = $frm->addTextarea($fieldName, $defaultValues);
             $txt->setAttribute('cols', 30);
             $txt->setAttribute('disabled', 'disabled');
             $txt->setAttribute('placeholder', $placeholder);
             // get content
             $fieldHTML = $txt->parse();
         } elseif ($field['type'] == 'heading') {
             $fieldHTML = '<h3>' . $values . '</h3>';
         } elseif ($field['type'] == 'paragraph') {
             $fieldHTML = $values;
         }
         /**
          * Parse the field into the template
          */
         // init
         $tpl->assign('plaintext', false);
         $tpl->assign('simple', false);
         $tpl->assign('multiple', false);
         $tpl->assign('id', $field['id']);
         $tpl->assign('required', isset($field['validations']['required']));
         // plaintext items
         if ($field['type'] == 'heading' || $field['type'] == 'paragraph') {
             // assign
             $tpl->assign('content', $fieldHTML);
             $tpl->assign('plaintext', true);
         } elseif ($field['type'] == 'checkbox' || $field['type'] == 'radiobutton') {
             // name (prefixed by type)
             $name = $field['type'] == 'checkbox' ? 'chk' . \SpoonFilter::ucfirst($fieldName) : 'rbt' . \SpoonFilter::ucfirst($fieldName);
             // rebuild so the html is stored in a general name (and not rbtName)
             foreach ($fieldHTML as &$item) {
                 $item['field'] = $item[$name];
             }
             // show multiple
             $tpl->assign('label', $field['settings']['label']);
             $tpl->assign('items', $fieldHTML);
             $tpl->assign('multiple', true);
         } else {
             // assign
             $tpl->assign('label', $field['settings']['label']);
             $tpl->assign('field', $fieldHTML);
             $tpl->assign('simple', true);
         }
         return $tpl->getContent(BACKEND_MODULES_PATH . '/FormBuilder/Layout/Templates/Field.tpl');
     } else {
         // empty field so return empty string
         return '';
     }
 }