/**
  * Convert JSON which stored from post_excerpt to array to store on post_content
  * 
  * @param  string/json $json_object Json Object
  * 
  * @return mixed array
  */
 private function parse()
 {
     // By default, when get json form raw post data. It will have backslashes.
     // so remember to add stripslahses before decode
     $this->meta_box = json_decode(stripslashes($this->meta_box), true);
     $this->normalize_field($this->meta_box)->parse_attrs($this->meta_box)->normalize_conditional_logic($this->meta_box)->set_fields_tab();
     // Clean Show / Hide, Include / Exlucde
     $cleans = array('showhide', 'includeexclude');
     unset($this->meta_box['show'], $this->meta_box['hide'], $this->meta_box['include'], $this->meta_box['exclude']);
     foreach ($cleans as $clean) {
         if (isset($this->meta_box[$clean])) {
             foreach ($this->meta_box[$clean] as $key => $val) {
                 if (empty($val)) {
                     unset($this->meta_box[$clean][$key]);
                 }
             }
             if (isset($this->meta_box[$clean]['type']) && $this->meta_box[$clean]['type'] != 'off') {
                 $this->meta_box[$this->meta_box[$clean]['type']] = $this->meta_box[$clean];
             }
             unset($this->meta_box[$this->meta_box[$clean]['type']]['type']);
             unset($this->meta_box[$clean]);
         }
     }
     // Sanitize all fields, because some extra fields or different structure
     foreach ($this->meta_box['fields'] as $index => $field) {
         $this->normalize_field($field)->parse_attrs($field)->normalize_conditional_logic($field);
         if ($field['type'] === 'group' && !empty($field['fields'])) {
             foreach ($field['fields'] as $i => $f) {
                 $this->normalize_field($f)->parse_attrs($f)->normalize_conditional_logic($f);
                 $field['fields'][$i] = $f;
             }
         }
         $this->meta_box['fields'][$index] = $field;
         if ($field['type'] === 'tab') {
             unset($this->meta_box['fields'][$index]);
         }
     }
     // Allows user define multidimmesional array by dot(.) notation
     $this->meta_box = array_unflatten($this->meta_box);
 }
Example #2
0
 /**
  * Convert flatten collection (with dot notation) to multiple dimmensionals array
  * @param  Collection $collection Collection to be flatten
  * @return Array
  */
 function array_unflatten($collection)
 {
     $collection = (array) $collection;
     $output = array();
     foreach ($collection as $key => $value) {
         array_set($output, $key, $value);
         if (is_array($value) && !strpos($key, '.')) {
             $nested = array_unflatten($value);
             $output[$key] = $nested;
         }
     }
     return $output;
 }