You are here

public function GatherContentCurl::getFieldConfig in GatherContent 7.2

Process config field to return field array.

1 call to GatherContentCurl::getFieldConfig()
GatherContentCurl::generateFormSettings in includes/curl.inc
Generate page settings for pages_import page.

File

includes/curl.inc, line 32
Contains functions used to process and retrieve data from GatherContent.

Class

GatherContentCurl
@file Contains functions used to process and retrieve data from GatherContent.

Code

public function getFieldConfig($obj, $files = array()) {
  if ($obj->config != '') {
    $config = json_decode(base64_decode($obj->config));
    $new_config = array();
    $total_fields = 0;
    if ($this
      ->foreachSafe($config)) {
      foreach ($config as $tab_pane) {
        $new_fields = array();
        if ($this
          ->foreachSafe($tab_pane->elements)) {
          foreach ($tab_pane->elements as $element) {
            switch ($element->type) {
              case 'text':
                $val = $element->value;
                if (!$element->plain_text) {
                  $val = preg_replace_callback('#\\<p\\>(.+?)\\<\\/p\\>#s', create_function('$matches', 'return "<p>".str_replace(array("\\n","\\r\\n","\\r"), " ", $matches[1])."</p>";'), $val);
                  $val = str_replace('</ul><', "</ul>\n<", $val);
                  $val = preg_replace('/\\s*<\\//m', '</', $val);
                  $val = preg_replace('/<\\/p>\\s*<p>/m', "</p>\n<p>", $val);
                  $val = preg_replace('/<\\/p>\\s*</m', "</p>\n<", $val);
                  $val = preg_replace('/<p>\\s*<\\/p>/m', '<p>&nbsp;</p>', $val);
                  $val = str_replace(array(
                    '<ul><li',
                    '</li><li>',
                    '</li></ul>',
                  ), array(
                    "<ul>\n\t<li",
                    "</li>\n\t<li>",
                    "</li>\n</ul>",
                  ), $val);
                  $val = html_entity_decode($val);
                  $val = trim(preg_replace('/\\s+/', ' ', $val));
                  $val = preg_replace("/<p>\\s/m", "<p>", $val);
                }
                break;
              case 'choice_radio':
                $val = '';
                foreach ($element->options as $idx => $option) {
                  if ($option->selected) {
                    if (isset($option->value)) {
                      $val = $option->value;
                    }
                    else {
                      $val = $option->label;
                    }
                  }
                }
                break;
              case 'choice_checkbox':
                $val = array();
                foreach ($element->options as $option) {
                  if ($option->selected) {
                    $val[] = $option->label;
                  }
                }
                break;
              case 'files':
                $val = $this
                  ->val($files, $element->name, array());
                break;
              default:
                continue 2;
                break;
            }
            $new_fields[$element->name] = array(
              'name' => $element->name,
              'label' => $element->label,
              'type' => $element->type,
              'value' => $val,
            );
          }
        }
        $total_fields += count($new_fields);
        $new_config[strtolower($tab_pane->name)] = array(
          'label' => $tab_pane->label,
          'elements' => $new_fields,
        );
      }
    }
    $new_config['field_count'] = $total_fields;
    return $new_config;
  }
  return array();
}