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 set_default_settings() { $settings = pl_get_global_settings(); if (!$settings) { $settings = pl_settings_default(); } $settings_defaults = apply_filters('pl_theme_default_settings', get_default_settings()); $region_defaults = apply_filters('pl_theme_default_regions', array()); if (empty($settings['draft'])) { $settings['draft'] = array('settings' => $settings_defaults, 'regions' => $region_defaults); } if (empty($settings['live'])) { $settings['live'] = array('settings' => $settings_defaults, 'regions' => $region_defaults); } pl_update_global_settings($settings); return $settings; }
function publish($response, $data) { global $sections_data_handler, $dms_cache; $pageID = $data['pageID']; $typeID = $data['typeID']; $response['result'] = $sections_data_handler->publish_items($data['store']); $section_handler = new PLCustomSections(); $section_handler->update_objects('publish'); $tpl_handler = new PLCustomTemplates(); $tpl_handler->update_objects('publish'); $settings = array(); $settings['local'] = pl_meta($pageID, PL_SETTINGS); $settings['type'] = pl_meta($typeID, PL_SETTINGS); $settings['global'] = pl_get_global_settings(); foreach ($settings as $scope => $set) { $set = wp_parse_args($set, array('live' => array(), 'draft' => array())); $set['live'] = $set['draft']; $settings[$scope] = $set; } pl_meta_update($pageID, PL_SETTINGS, $settings['local']); pl_meta_update($typeID, PL_SETTINGS, $settings['type']); pl_update_global_settings($settings['global']); // Flush less $dms_cache->purge('live_css'); // run clean post action to trigger caches to clear. Varnish, WPE etc. do_action('clean_post_cache'); return $response; }
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 update_setting($args = array()) { $defaults = array('key' => '', 'val' => '', 'mode' => 'draft', 'scope' => 'global', 'uid' => 'settings'); $a = wp_parse_args($args, $defaults); $scope = $a['scope']; $mode = $a['mode']; $key = $a['key']; $val = $a['val']; $uid = $a['uid']; $parse_value = array($key => $val); if ($scope == 'global') { $settings = pl_get_global_settings(); $old_settings = isset($settings[$mode][$uid]) ? $settings[$mode][$uid] : array(); $settings[$mode][$uid] = wp_parse_args($parse_value, $old_settings); pl_update_global_settings($settings); } elseif ($scope == 'local' || $scope == 'type') { global $plpg; $theID = $scope == 'local' ? $plpg->id : $plpg->typeid; $settings = $this->meta($theID, PL_SETTINGS, pl_settings_default()); $old_settings = isset($settings[$mode][$uid]) ? $settings[$mode][$uid] : array(); $settings[$mode][$uid] = wp_parse_args($parse_value, $old_settings); pl_meta_update($theID, PL_SETTINGS, $settings); } }