/**
  * @return void
  * @since 1.0.0
  */
 function yit_install_sampledata_callback()
 {
     global $wpdb;
     $gz = YIT_THEME_ASSETS_DIR . '/sample-data/' . YIT_THEME_NAME . '.gz';
     if (file_exists($gz)) {
         require_once YIT_CORE_LIB . '/yit/Backup/Backup.php';
         if (YIT_Backup::import_backup($gz)) {
             yit_get_model('message')->addMessage(__('Sample data installed correctly!', 'yit'));
         } else {
             yit_get_model('message')->addMessage(__('Error. Unable to install sample data!', 'yit') . ' SQL ERROR: ' . $wpdb->last_error, 'error');
         }
     } else {
         yit_get_model('message')->addMessage(__('Error. The file ' . $gz . ' does not exists!', 'yit'), 'error');
     }
     yit_get_model('message')->printGlobalMessages();
     die;
 }
Beispiel #2
0
 /**
  * @return void
  * @since 1.0.0
  */
 function yit_install_sampledata_callback()
 {
     global $wpdb;
     $gz = YIT_THEME_ASSETS_DIR . '/sample-data/' . YIT_THEME_NAME . '.gz';
     global $woocommerce;
     if (!empty($woocommerce) && version_compare(preg_replace('/-beta-([0-9]+)/', '', $woocommerce->version), '2.1', '<')) {
         $gz = YIT_THEME_ASSETS_DIR . '/sample-data/' . YIT_THEME_NAME . '_woo_2.0.x.gz';
     }
     if (file_exists($gz)) {
         require_once YIT_CORE_LIB . '/yit/Backup/Backup.php';
         if (YIT_Backup::import_backup($gz)) {
             yit_get_model('message')->addMessage(__('Sample data installed correctly!', 'yit'));
         } else {
             yit_get_model('message')->addMessage(__('Error. Unable to install sample data!', 'yit') . ' SQL ERROR: ' . $wpdb->last_error, 'error');
         }
     } else {
         yit_get_model('message')->addMessage(__('Error. The file ' . $gz . ' does not exists!', 'yit'), 'error');
     }
     yit_get_model('message')->printGlobalMessages();
     die;
 }
Beispiel #3
0
 /**
  * Save all options in the database, after panel submit
  *          
  * @since 1.0.0
  */
 public function save_options_callback()
 {
     if (!(isset($_POST['_yit_theme_options_nonce']) && wp_verify_nonce($_POST['_yit_theme_options_nonce'], 'yit-theme-options'))) {
         return;
     }
     if (isset($_POST['yit-subpage']) && $_POST['yit-subpage'] == 'backup') {
         if ($_POST['yit-action'] == 'import-file' && isset($_FILES['import-file'])) {
             require_once YIT_CORE_LIB . '/yit/Backup/Backup.php';
             if (YIT_Backup::import_backup()) {
                 yit_add_message($this->_messages['imported'], 'updated', 'panel');
             } else {
                 yit_add_message($this->_messages['imported-error'], 'error', 'panel');
             }
         } elseif ($_POST['yit-action'] == 'export-file') {
             require_once YIT_CORE_LIB . '/yit/Backup/Backup.php';
             $backup = YIT_Backup::export_backup();
             header("Content-type: application/gzip-compressed");
             header("Content-Disposition: attachment; filename={$backup['filename']}");
             header("Content-Length: " . strlen($backup['content']));
             header("Content-Transfer-Encoding: binary");
             header('Accept-Ranges: bytes');
             header("Pragma: no-cache");
             header("Expires: 0");
             echo $backup['content'];
         } elseif ($_POST['yit-action'] == 'configuration-save') {
             if (isset($_POST['configuration-name']) && $_POST['configuration-name'] != '') {
                 $configs = get_option($this->configs_name);
                 if ($configs != false) {
                     $configs = maybe_unserialize($configs);
                 } else {
                     $configs = array();
                 }
                 $new_config = array();
                 $new_config_name = esc_attr($_POST['configuration-name']);
                 $new_config_slug = yit_avoid_duplicate(sanitize_title($new_config_name), $configs, 'key');
                 $new_config_backup = base64_encode(serialize($this->db_options));
                 $new_config[$new_config_slug] = array('name' => $new_config_name, 'values' => $new_config_backup);
                 if (update_option($this->configs_name, array_merge($configs, $new_config))) {
                     yit_get_model('message')->addMessage(__('Configuration has been saved.', 'yit'), 'updated', 'panel');
                     if (defined('DOING_AJAX')) {
                         yit_get_model('message')->printMessages();
                         die;
                     }
                 } else {
                     yit_get_model('message')->addMessage(__('An error occurring while trying to save configuration. Please try again.', 'yit'), 'error', 'panel');
                     if (defined('DOING_AJAX')) {
                         yit_get_model('message')->printMessages();
                         die;
                     }
                 }
             } else {
                 yit_get_model('message')->addMessage(__('Configuration name is missing.', 'yit'), 'error', 'panel');
                 if (defined('DOING_AJAX')) {
                     yit_get_model('message')->printMessages();
                     die;
                 }
             }
         } elseif ($_POST['yit-action'] == 'configuration-restore') {
             $configs = get_option($this->configs_name);
             $config_name = $_POST['configuration-restore'];
             $config = unserialize(base64_decode($configs[$config_name]['values']));
             if (is_array($config)) {
                 if (update_option($this->option_name, $config)) {
                     yit_get_model('message')->addMessage(__('Configuration has been restored.', 'yit'), 'updated', 'panel');
                     if (defined('DOING_AJAX')) {
                         yit_get_model('message')->printMessages();
                         die;
                     }
                 } else {
                     yit_get_model('message')->addMessage(__('An error occurring while trying to restore configuration. Please try again.', 'yit'), 'error', 'panel');
                     if (defined('DOING_AJAX')) {
                         yit_get_model('message')->printMessages();
                         die;
                     }
                 }
             } else {
                 yit_get_model('message')->addMessage(__('An error occurring while trying to restore configuration. The backup seems to be damaged.', 'yit'), 'error', 'panel');
                 if (defined('DOING_AJAX')) {
                     yit_get_model('message')->printMessages();
                     die;
                 }
             }
         } elseif ($_POST['yit-action'] == 'configuration-remove') {
             $configs = get_option($this->configs_name);
             if ($configs != false) {
                 $configs = maybe_unserialize($configs);
             } else {
                 $configs = array();
             }
             $to_delete = esc_attr($_POST['configuration-remove']);
             if (isset($configs[$to_delete])) {
                 unset($configs[$to_delete]);
             }
             if (update_option($this->configs_name, $configs)) {
                 yit_get_model('message')->addMessage(__('Configuration has been deleted.', 'yit'), 'updated', 'panel');
                 if (defined('DOING_AJAX')) {
                     yit_get_model('message')->printMessages();
                     die;
                 }
             } else {
                 yit_get_model('message')->addMessage(__('An error occurring while trying to delete the configuration. Please try again.', 'yit'), 'error', 'panel');
                 if (defined('DOING_AJAX')) {
                     yit_get_model('message')->printMessages();
                     die;
                 }
             }
         }
         return;
     } elseif (!(isset($_POST['yit-action']) && $_POST['yit-action'] == 'save-options' && isset($_POST['yit-subpage']) && isset($_POST['yit_panel_option']) && isset($this->panel[$_POST['yit-subpage']]))) {
         return;
     }
     $page_options = $this->panel[$_POST['yit-subpage']];
     $post_data = $_POST['yit_panel_option'];
     foreach ($page_options as $tab_path => $options) {
         foreach ($options as $option) {
             // must be process the saving also when there are the ID and the TYPE set for this option
             if (!(isset($option['id']) && isset($option['type']))) {
                 continue;
             }
             // the option types that are one checkbox
             $checkbox_type = array('checkbox', 'onoff', 'checklist');
             $multicheck_type = array('cat', 'pag');
             // if there isn't this option in the form data sent and it's not a checkbox, can't process this option
             if (!in_array($option['type'], $checkbox_type) && !in_array($option['type'], $multicheck_type) && !isset($post_data[$option['id']])) {
                 continue;
             }
             // if the option is a checkbox and the data it's not sent in the form data, it means that the checkbox is not checked
             if (in_array($option['type'], $checkbox_type) && !isset($post_data[$option['id']])) {
                 $post_data[$option['id']] = false;
             }
             // for the types "cat" and "pag", if there are
             if (in_array($option['type'], $multicheck_type) && !isset($post_data[$option['id']])) {
                 $post_data[$option['id']] = array();
             }
             // get the value from the POST data, after having done all controls
             $value = $post_data[$option['id']];
             // validation
             if (isset($option['validate'])) {
                 if (is_array($option['validate'])) {
                     $validate_filters = $option['validate'];
                 } else {
                     $validate_filters = array($option['validate']);
                 }
                 foreach ($validate_filters as $filter) {
                     switch ($filter) {
                         case 'yit_avoid_duplicate':
                             $value = yit_avoid_duplicate($value, $this->get_option($option['id']));
                             break;
                         default:
                             $value = call_user_func($filter, $value);
                             break;
                     }
                 }
             }
             // check if is defined the "data" index, with 'array-merge', that add the value in an array
             if (isset($option['data']) && 'array-merge' == $option['data']) {
                 if (empty($value)) {
                     continue;
                 }
                 $existing_array = $this->get_option($option['id'], array());
                 if (!is_array($existing_array) || empty($existing_array)) {
                     $value = array($value);
                 } else {
                     $value = array_merge(array($value), $existing_array);
                 }
             }
             // update the option in the database
             $this->update_option($option['id'], $value);
         }
     }
     yit_add_message($this->_messages['saved'], 'updated', 'panel');
     if (defined('DOING_AJAX')) {
         $this->update_db_options();
         yit_get_model('message')->printMessages();
         die;
     }
 }