Beispiel #1
0
 /**
  * Get array from request
  * @param string $arrayName
  * @param array  $default
  * @return array
  */
 public function getArray($arrayName, $default = array())
 {
     $result = $this->_request->get($arrayName, 'array');
     if (is_null($result)) {
         return $default;
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Evaluates the fields and returns them in HTML
  *
  * @param array $fields The fields to process
  *
  * @return string The HTML fields string
  */
 function renderFields($fields)
 {
     // process XML
     if (is_object($fields)) {
         $fields = $this->parseXML($fields);
         // process json string
     } else {
         if ($result = $this->decodeJSON($fields)) {
             $fields = $result;
             // process file
         } else {
             if ($path = $this->app->path->path($fields)) {
                 $ext = pathinfo($path, PATHINFO_EXTENSION);
                 if ($ext == 'json') {
                     $fields = file_get_contents($path);
                 } else {
                     // php
                     $fields = (include $path);
                 }
                 $fields = $this->decodeJSON($fields);
             }
         }
     }
     // check if it's array, if not cancel and raise notice
     if (!is_array($fields)) {
         $this->app->error->raiseError(500, JText::_('Something went wrong. Could be a bad fields format or file not found.'));
         return;
     }
     $result = array();
     foreach ($fields as $id => $fld) {
         $fld = $this->app->data->create($fld);
         // adjust ctrl
         // if($adjust = $fld->get('adjust_ctrl')){
         // 	$final_ctrl = preg_replace($adjust['pattern'], $adjust['replacement'], $ctrl);
         // } else {
         // 	$final_ctrl = $ctrl;
         // }
         // wrapper control if any
         // $final_ctrl = $fld->get('control') ? $final_ctrl.'['.$fld->get('control', '').']' : $final_ctrl;
         $field_type = $fld->get('type', '');
         switch ($field_type) {
             case 'separator':
                 // set layout
                 $layout = $fld->get('layout', 'default');
                 // backward compatibility
                 if ($fld->get('text')) {
                     $layout = $fld->get('big') ? 'section' : 'subsection';
                     $fld->set('specific', array('title' => $fld->get('text')));
                 }
                 // render layout
                 $field = $fld;
                 if ($layout = $this->getLayout("separator/{$layout}.php")) {
                     $result[] = $this->app->zlfw->renderLayout($layout, compact('id', 'field'));
                 }
                 break;
             case 'wrapper':
             case 'control_wrapper':
             case 'toggle':
             case 'fieldset':
                 // backward compatibility
                 // get content
                 $content = array_filter($this->renderFields($fld->get('fields')));
                 // abort if no minimum fields reached
                 if (count($content) == 0 || count($content) < $fld->get('min_count', 0)) {
                     continue;
                 }
                 // init vars
                 $layout = $fld->get('layout', 'default');
                 $content = implode("\n", $content);
                 // backward compatibility
                 if ($field_type == 'control_wrapper') {
                     $result[] = $content;
                     continue;
                 } else {
                     if ($field_type == 'fieldset') {
                         $layout = 'fieldset';
                     } else {
                         if ($field_type == 'toggle') {
                             $layout = 'toggle';
                         }
                     }
                 }
                 // render layout
                 if ($this->renderIf($fld->get('renderif')) && ($layout = $this->getLayout("wrapper/{$layout}.php"))) {
                     $result[] = $this->app->zlfw->renderLayout($layout, compact('id', 'content', 'fld'));
                 }
                 break;
             case 'subfield':
                 // get parent fields data
                 $psv = $this->app->data->create($psv);
                 // replace path {value} if it's string
                 $paths = is_string($psv->get($pid)) ? str_replace('{value}', basename($psv->get($pid), '.php'), $fld->get('path')) : $fld->get('path');
                 // replace parent values in paths
                 foreach ((array) $psv as $key => $pvalue) {
                     $paths = str_replace('{' . $key . '}', basename(@(string) $pvalue, '.php'), $paths);
                 }
                 // build json paths
                 $json = array('paths' => $paths);
                 // create possible arguments objects
                 if ($field_args = $fld->get('arguments')) {
                     foreach ($field_args as $name => $args) {
                         $arguments[$name] = $this->app->data->create($args);
                     }
                 }
                 // parse fields
                 if ($res = $this->renderFields($json)) {
                     $result[] = $res;
                 }
                 break;
             default:
                 // init vars
                 $value = null;
                 // check old values
                 // if($fld->get('check_old_value'))
                 // {
                 // 	// adjust ctrl for old value
                 // 	$old_value_ctrl = $this->control;
                 // 	if($adjust = $fld->find('check_old_value.adjust_ctrl')) $old_value_ctrl = preg_replace($adjust['pattern'], $adjust['replacement'], $old_value_ctrl);
                 // 	// get old value
                 // 	// $value = $this->getFieldValue($fld->find('check_old_value.id'), null, $old_value_ctrl);
                 // 	// translate old value
                 // 	if($translations = $fld->find('check_old_value.translate_value')){
                 // 		foreach($translations as $key => $trans) if($value == $key){
                 // 			if($trans == '_SKIPIT_'){
                 // 				$value = null;
                 // 				break;
                 // 			} else {
                 // 				$value = $trans;
                 // 				break;
                 // 			}
                 // 		}
                 // 	}
                 // }
                 // get inital value dinamicly
                 if (empty($value) && $fld->get('request_value')) {
                     // from url
                     if ($fld->find('request_value.from') == 'url') {
                         $value = $this->request->get($fld->find('request_value.param'), $fld->find('request_value.type'), $fld->find('request_value.default'));
                     }
                 }
                 // if ($psv) $specific['parents_val'] = $psv;
                 $args = $this->app->data->create($fld->get('settings'));
                 // render field
                 $result[] = $this->renderField($fld, $id, $value, $args);
                 // load childs
                 if ($childs = $fld->find('childs.loadfields')) {
                     // create parent values
                     $pid = $id;
                     // add current value to parents array, if empty calculate it
                     // $psv[$id] = $value ? $value : $this->field($params, $value, true);
                     $psv[$id] = $value ? $value : null;
                     $p_task = $this->request->getVar('parent_task') ? $this->request->getVar('parent_task') : $this->request->getVar('task');
                     // parent task necesary if double field load ex: layout / sublayout
                     $url = $this->app->link(array('controller' => 'zlframework', 'format' => 'raw', 'type' => $this->type, 'layout' => $this->layout, 'group' => $this->group, 'path' => $this->request->getVar('path'), 'parent_task' => $p_task, 'zlfieldmode' => $this->mode), false);
                     // rely options to be used by JS later on
                     $json = $fld->find('childs.loadfields.subfield', '') ? array('paths' => $fld->find('childs.loadfields.subfield.path')) : array('fields' => $childs);
                     $pr_opts = json_encode(array('id' => $id, 'url' => $url, 'psv' => $psv, 'json' => json_encode($json)));
                     // all options are stored as data on DOM so can be used from JS
                     $loaded_fields = $this->renderFields($childs);
                     $result[] = '<div class="placeholder" data-relieson-type="' . $field_type . '"' . ($pr_opts ? " data-relieson='{$pr_opts}'" : '') . ' data-control="' . $this->control . '" >';
                     $result[] = $loaded_fields ? '<div class="loaded-fields">' . $loaded_fields . '</div>' : '';
                     $result[] = '</div>';
                 }
         }
     }
     return $result;
 }