function pl_performance_object() { // blob objects to add to json blob // format: array( 'name' => array() ) $blob_objects = apply_filters('pl_performance_object', $this->basic_performance()); $output = ''; if (!empty($blob_objects)) { foreach ($blob_objects as $name => $array) { $output .= sprintf('%s:%s, %s', $name, json_encode(pl_arrays_to_objects($array)), "\n\n"); } } return $output; }
function import($file, $opts = array()) { $def_opts = array('page_tpl_import' => 'checked', 'global_import' => 'checked', 'type_import' => 'checked'); $opts = wp_parse_args($opts, $def_opts); $parsed['opts'] = $opts; $parsed = array('nothing'); $file_contents = pl_file_get_contents($file); $import_defaults = array('draft' => array(), 'live' => array()); $file_data = $this->strip_header($file_contents); $file_data = json_decode($file_data); $file_data = json_decode(json_encode($file_data), true); // IMPORT MAIN if (isset($file_data[PL_SETTINGS]) && 'checked' == $opts['global_import']) { pl_update_global_settings($file_data[PL_SETTINGS]); $parsed[] = 'globals'; } // IMPORT USER MAPS if (isset($file_data['pl-user-templates']) && 'checked' == $opts['page_tpl_import']) { $new = $import_defaults; $old = get_option('pl-user-templates', $import_defaults); $import = wp_parse_args($file_data['pl-user-templates'], $import_defaults); $new['draft'] = array_merge($old['draft'], $import['draft']); $new['live'] = array_merge($old['live'], $import['live']); update_option('pl-user-templates', $new); $parsed[] = 'user_templates'; } // IMPORT AWESOMENESS if (isset($file_data['post_meta']) && 'checked' == $opts['type_import']) { foreach ($file_data['post_meta'] as $key => $data) { update_post_meta($key, 'pl-settings', $data[0]); } $parsed[] = 'meta-data'; } if (isset($file_data['custom'])) { $parsed[] = 'custom'; update_option('pl-user-sections', $file_data['custom']); } if (isset($file_data['section_data'])) { $section_opts = $file_data['section_data']; global $sections_data_handler; if (!is_object($sections_data_handler)) { $sections_data_handler = new PLSectionData(); } $section_data = array(); foreach ($section_opts as $data) { $section_data[$data['uid']] = stripslashes_deep($this->unserialize($data['live'])); } $sections = $sections_data_handler->create_items($section_data); $parsed['section_data'] = $section_data; } return json_encode(pl_arrays_to_objects($parsed)); }
function pl_dms_admin_actions() { $response = array(); $postdata = $_POST; $response['post'] = $_POST; $lessflush = isset($postdata['flag']) ? $postdata['flag'] : false; $field = $postdata['setting']; $value = $postdata['value']; pl_setting_update($field, $value); echo json_encode(pl_arrays_to_objects($response)); if ($lessflush) { global $dms_cache; $dms_cache->purge_all(); } die; }
function json_blob_objects() { // blob objects to add to json blob // format: array( 'name' => array() ) $blob_objects = apply_filters('pl_json_blob_objects', array()); $output = ''; if (!empty($blob_objects)) { foreach ($blob_objects as $name => $array) { $output .= sprintf('%s, %s:%s', "\n", $name, json_encode(pl_arrays_to_objects($array))); } } return $output; }
function import($file, $opts = array()) { $def_opts = array('page_tpl_import' => 'checked', 'global_import' => 'checked', 'type_import' => 'checked'); $opts = wp_parse_args($opts, $def_opts); $parsed['opts'] = $opts; $parsed = array('nothing'); $file_contents = pl_file_get_contents($file); $file_data = $this->strip_header($file_contents); $file_data = json_decode($file_data); $file_data = json_decode(json_encode($file_data), true); // IMPORT MAIN if (isset($file_data[PL_SETTINGS]) && 'checked' == $opts['global_import']) { pl_update_global_settings($file_data[PL_SETTINGS]); $parsed[] = 'globals'; } // IMPORT USER MAPS if (isset($file_data['pl-user-templates']) && 'checked' == $opts['page_tpl_import']) { $existing_templates = get_option('pl-user-templates'); $new = array('draft' => $file_data['pl-user-templates'], 'live' => $file_data['pl-user-templates']); $new_templates = wp_parse_args($new, $existing_templates); $parsed['imported_data'] = $file_data['pl-user-templates']; $parsed['existing'] = $existing_templates; $parsed['merged'] = $new_templates; update_option('pl-user-templates', $new_templates); $parsed[] = 'user_templates'; } // IMPORT AWESOMENESS if (isset($file_data['post_meta']) && 'checked' == $opts['type_import']) { foreach ($file_data['post_meta'] as $key => $data) { update_post_meta($key, 'pl-settings', $data[0]); } $parsed[] = 'meta-data'; } if (isset($file_data['section_data'])) { $section_opts = $file_data['section_data']; global $sections_data_handler; $section_data = array(); foreach ($section_opts as $data) { $section_data[$data['uid']] = unserialize($data['live']); } $sections = $sections_data_handler->create_items($section_data); $parsed['section_data'] = $section_data; } return json_encode(pl_arrays_to_objects($parsed)); }
function pl_dms_admin_actions() { $response = array(); $postdata = $_POST; $response['post'] = $_POST; $lessflush = isset($postdata['flag']) ? $postdata['flag'] : false; $field = $postdata['setting']; $value = $postdata['value']; if ('custom_less' == $field || 'custom_scripts' == $field) { while (strchr($value, '\\')) { $value = stripslashes($value); } } pl_setting_update($field, $value); $response['value'] = $value; $response['field'] = $field; echo json_encode(pl_arrays_to_objects($response)); if ($lessflush) { global $dms_cache; $dms_cache->purge_all(); } die; }
function pl_arrays_to_objects(array $array) { $objects = new stdClass(); if (is_array($array)) { foreach ($array as $key => $val) { if ($key === '') { $key = 0; } if (is_array($val) && !empty($val)) { $objects->{$key} = pl_arrays_to_objects($val); } else { $objects->{$key} = $val; } } } return $objects; }