Ejemplo n.º 1
0
 /**
  * @return void
  * @since 1.0.0
  */
 function yit_reset_theme_options_callback()
 {
     global $wpdb;
     $options = $wpdb->get_row("SELECT `option_value` FROM `{$wpdb->options}` WHERE `option_name` = 'yit_panel_options_" . YIT_THEME_NAME . "'", ARRAY_N);
     $options = maybe_unserialize($options[0]);
     $custom_sidebars = array();
     $custom_sidebars['custom-sidebars'] = $options['custom-sidebars'];
     if ($wpdb->update($wpdb->options, array('option_value' => maybe_serialize($custom_sidebars)), array('option_name' => 'yit_panel_options_' . YIT_THEME_NAME))) {
         yit_get_model('message')->addMessage(__('Theme Options resetted successfully!', 'yit'));
     } else {
         yit_get_model('message')->addMessage(__('Error. Unable to reset the theme options!', 'yit') . ' SQL ERROR: ' . $wpdb->last_error, 'error');
     }
     yit_save_css();
     yit_get_model('message')->printGlobalMessages();
     die;
 }
Ejemplo n.º 2
0
 /**
  * Update the all array of all options in the database, if they are updated.
  *          
  * @since 1.0.0
  */
 public function update_db_options()
 {
     if (!$this->_isOptionUpdated) {
         return;
     }
     // save the css generated by some options, in the file custom.css
     yit_save_css();
     update_option($this->option_name, $this->db_options);
     $this->_isOptionUpdated = false;
 }
Ejemplo n.º 3
0
 /**
  * Save the metabox values in the database, for the post of the post type
  * 
  * @param $post_id int   The ID of the new post
  *
  * @since 1.0.0     
  */
 public function save_settings($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // verify this came from the our screen and with proper authorization,
     // because save_post can be triggered at other times
     if (!(isset($_POST['settings_post_type_nonce']) && wp_verify_nonce($_POST['settings_post_type_nonce'], 'post-type-unilimited-settings'))) {
         return;
     }
     // Check permissions
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     // OK, we're authenticated: we need to find and save the data
     $settings = isset($_POST[$this->metabox_name]) ? $_POST[$this->metabox_name] : array();
     // check for the checkboxs
     foreach ($this->_post_types[$_POST['post_type']]['settings'] as $option) {
         if (isset($option['type']) && isset($option['id']) && in_array($option['type'], array('checkbox', 'onoff')) && !isset($_POST[$this->metabox_name][$option['id']])) {
             $settings[$option['id']] = "0";
         }
     }
     // remove the sample item used by the javascript
     unset($settings['items'][0]);
     // add the categories
     $actual_cats = $this->get_setting('categories', $post_id);
     if (empty($actual_cats)) {
         $actual_cats = array();
     }
     $settings['categories'] = $actual_cats;
     // Do something with $settings
     // probably using add_post_meta(), update_post_meta(), or
     // a custom table (see Further Reading section below)
     update_post_meta($post_id, '_' . $this->metabox_name, $settings);
     // save the css in the file for the typography tab
     yit_save_css();
 }
Ejemplo n.º 4
0
 /**
  * Import backup data
  *
  * @param $file array
  * @return bool
  *
  */
 public static function import_backup($file = '')
 {
     global $wpdb, $yiw_wptables;
     $wpdb->show_errors();
     $error = '';
     if (isset($_FILES['import-file']) && empty($file)) {
         if (!isset($_FILES['import-file'])) {
             wp_die(__("The file you have insert doesn't valid.", 'yit'));
         }
         switch (substr($_FILES['import-file']['name'], -3)) {
             case 'xml':
                 $error = sprintf(__('The file you have insert is a WordPress eXtended RSS (WXR) file. You need to use this into the %s admin page to import this file. Here only <b>.gz</b> file are allowed. <a href="%s" title="Tools -> Import">Tools -> Import</a>', 'yit'), admin_url('import.php', false));
                 break;
             case 'zip':
             case 'rar':
                 $error = sprintf(__('The file you have insert is a ZIP or RAR file, that it doesn\'t allowed in this case. Here only <b>.gz</b> file are allowed. <a href="%s" title="Tools -> Import">Tools -> Import</a>', 'yit'), admin_url('import.php', false));
                 break;
         }
         if (substr($_FILES['import-file']['name'], -2) != 'gz') {
             $error = sprintf(__('The file you have insert is not a valid file. Here only <b>.gz</b> file are allowed. <a href="%s" title="Tools -> Import">Tools -> Import</a>', 'yit'), admin_url('import.php', false));
         }
         if ($error != '') {
             yit_get_model('message')->addMessage($error, 'error');
             return false;
         }
     }
     $file = empty($file) ? $_FILES['import-file']['tmp_name'] : $file;
     // get db encoded
     $content_file = file_get_contents($file);
     $db = unserialize(base64_decode(gzuncompress($content_file)));
     //yit_debug($db); die;
     array_walk_recursive($db, 'yit_convert_url', 'in_import');
     //yit_debug($db); die;
     if (!is_array($db)) {
         wp_die(__('An error encoured during during import. Please try again.', 'yit'));
     }
     set_time_limit(0);
     // tables
     foreach (self::$wptables as $table) {
         if (!isset($db[$table])) {
             continue;
         }
         // delete all row of each table
         $wpdb->query("TRUNCATE TABLE {$wpdb->{$table}}");
         // insert new data
         $error_data = array();
         $insert = array();
         foreach ($db[$table] as $id => $data) {
             $insert[] = YIT_Backup::_makeInsertSQL($data);
         }
         if (!empty($db[$table])) {
             $insert = implode(', ', $insert);
             $fields = implode('`, `', array_keys($db[$table][0]));
             //wp_die("INSERT INTO `{$wpdb->$table}` ( `$fields` ) VALUES " . $insert);
             $wpdb->query("INSERT INTO `{$wpdb->{$table}}` ( `{$fields}` ) VALUES " . $insert);
         }
     }
     $tables = apply_filters('yit_sample_data_tables', array());
     $tables = apply_filters('yit_sample_data_tables_import', $tables);
     if (!empty($tables)) {
         foreach ($tables as $table) {
             if (!isset($db[$table])) {
                 continue;
             }
             if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}{$table}'") == $wpdb->prefix . $table) {
                 #yiw_string_( '<p></p><p><strong>', '// ' . $table, '</strong><br />' );
                 // delete all row of each table
                 $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}{$table}");
                 #yiw_string_( '', sprintf( __( 'Truncated %s table', 'yit' ), $wpdb->prefix . $table ), '...<br />' );
                 // insert new data
                 $insert = array();
                 foreach ($db[$table] as $id => $data) {
                     $insert[] = YIT_Backup::_makeInsertSQL($data);
                 }
                 if (!empty($db[$table])) {
                     $insert = implode(', ', $insert);
                     $fields = implode('`, `', array_keys($db[$table][0]));
                     $wpdb->query("INSERT INTO `{$wpdb->prefix}{$table}` ( `{$fields}` ) VALUES " . $insert);
                 }
             }
         }
     }
     # yiw_string_( '<p></p><p><strong>', '// options', '</strong><br />' );
     // delete options
     $theme = get_option('stylesheet');
     $options = array(yit_get_model('panel')->option_name, 'sidebars_widgets', 'show_on_front', 'page_on_front', 'page_for_posts', 'widget%', 'theme\\_mods\\_%');
     $options = apply_filters('yit_sample_data_options', $options);
     $options = apply_filters('yit_sample_data_options_import', $options);
     $sql_options = array();
     foreach ($options as $option) {
         if (strpos($option, '%') !== FALSE) {
             $operator = 'LIKE';
         } else {
             $operator = '=';
         }
         $sql_options[] = "option_name {$operator} '{$option}'";
     }
     $sql_options = implode(' OR ', $sql_options);
     $sql = "DELETE FROM {$wpdb->options} WHERE {$sql_options};";
     #if( $wpdb->query( $sql ) )
     #yiw_string_( '', sprintf( __( 'Deleted value from %s table', 'yit' ), $wpdb->options ), '...<br />' );
     #else
     #yiw_string_( '', sprintf( __( 'Error during deleting from %s table (SQL: %s)', 'yit' ), $wpdb->options, $sql ), '...<br />' );
     $wpdb->query($sql);
     // update options
     $error_data = array();
     $check = $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_id = 1", ARRAY_A);
     foreach ($db['options'] as $id => $option) {
         if (!isset($check['blog_id'])) {
             unset($option['blog_id']);
         }
         if ($wpdb->insert($wpdb->options, $option)) {
             $insert = true;
         } else {
             $insert = false;
         }
         // save the ID that has error, to show.
         if (!$insert) {
             $wpdb->print_error();
         }
         //$error_data[] = $option['option_name'];
     }
     #if( $insert )
     #    yiw_string_( '', sprintf( __( 'Insert new values, into %s table', 'yit' ), $wpdb->options ), '...</p>' );
     #else
     #    yiw_string_( '', sprintf( __( 'Error during insert new values (IDs: %s), into %s table', 'yit' ), implode( $error_data, ' ' ), $wpdb->options ), '...</p>' );
     # echo '</p>';
     yit_save_css();
     do_action('yit_after_import');
     return true;
 }