Exemple #1
0
/**
 * 1.3.0
 */
function yit_update_1_3_0()
{
    /* ====== Update CPTU ====== */
    global $wpdb;
    $temp = array();
    $prefixes = array('sliders' => 'sl_', 'portfolios' => 'po_', 'feature-tabs' => 'ft_', 'teams' => 'team_');
    foreach ($prefixes as $post_type => $prefix) {
        $args = array('post_type' => $post_type, 'posts_per_page' => -1, 'post_status' => 'publish');
        $post_types = get_posts($args);
        foreach ($post_types as $the) {
            $from = substr($prefix . $the->post_name, 0, 20);
            $to = yit_avoid_duplicate(str_replace('-', '_', substr($prefix . $the->post_name, 0, 16)), $temp);
            $temp[] = $to;
            $to_parent = substr($to, 3);
            /* Update Child Post Type*/
            $wpdb->update($wpdb->posts, array('post_type' => $to), array('post_type' => $from));
            /* Update Parent Post Name */
            $wpdb->update($wpdb->posts, array('post_name' => $to_parent), array('post_name' => $the->post_name));
            /* Update Slider Name in Post Meta */
            if ('sliders' == $post_type) {
                $where = array('meta_key' => '_slider_name', 'meta_value' => $the->post_name);
                $wpdb->update($wpdb->postmeta, array('meta_value' => $to_parent), $where);
            }
        }
    }
    set_transient('cptu_1_3_0_update', true);
}
 /**
  * Check if something exists. If yes, add a -N to the value where N is a number.
  *
  * @param mixed $value
  * @param array $array
  * @param string $check
  * @return mixed
  * @since 2.0.0
  * @author Antonino Scarf� <*****@*****.**>
  */
 function yit_avoid_duplicate($value, $array, $check = 'value')
 {
     $match = array();
     if (!is_array($array)) {
         return $value;
     }
     if ($check == 'value' && !in_array($value, $array) || $check == 'key' && !isset($array[$value])) {
         return $value;
     } else {
         if (!preg_match('/([a-z]+)-([0-9]+)/', $value, $match)) {
             $i = 2;
         } else {
             $i = intval($match[2]) + 1;
             $value = $match[1];
         }
         return yit_avoid_duplicate($value . '-' . $i, $array, $check);
     }
 }
    /**
     * Register portfolio post types
     *
     * Register the post types for each portfolio created by admin
     *
     * @return void
     * @since 1.0
     * @author Antonino Scarfi' <*****@*****.**>
     */
    public function register_cptu_post_types() {
        $post_types = $this->get_post_types();
        $pts = array();

        foreach ( $post_types as $pt ) {

            extract( $this->_cpt_args( $pt ) );

            $name  = $pt->post_name;
            $title = $pt->post_title;

            $labels = array(
                'name'               => $title,
                'singular_name'      => $label_singular,
                'add_new'            => sprintf( __( 'Add %s', 'yith-plugin-fw' ), $label_singular ),
                'add_new_item'       => sprintf( __( 'Add New %s', 'yith-plugin-fw' ), $label_singular ),
                'edit_item'          => sprintf( __( 'Edit %s', 'yith-plugin-fw' ), $label_singular ),
                'new_item'           => sprintf( __( 'New %s', 'yith-plugin-fw' ), $label_singular ),
                'all_items'          => sprintf( __( 'All %s', 'yith-plugin-fw' ), $label_plural ),
                'view_item'          => sprintf( __( 'View %s', 'yith-plugin-fw' ), $label_singular ),
                'search_items'       => sprintf( __( 'Search %s', 'yith-plugin-fw' ), $label_plural ),
                'not_found'          => sprintf( __( 'No %s found', 'yith-plugin-fw' ), $label_plural ),
                'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'yith-plugin-fw' ), $label_plural ),
                'parent_item_colon'  => '',
                'menu_name'          => $title
            );

            $args = array(
                'labels'             => apply_filters( 'yit_' . $this->_prefix_cpt . $name . '_labels', $labels ),
                'public'             => true,
                'publicly_queryable' => true,
                'show_ui'            => true,
                'show_in_menu'       => false,
                'query_var'          => true,
                'capability_type'    => 'post',
                'hierarchical'       => false,
                'menu_position'      => null,
                'supports'           => array( 'title', 'editor', 'thumbnail' )
            );

            if ( ! $this->_args['has_single'] ) {
                $args['public'] = false;
                $args['publicly_queryable'] = false;
                $args['query_var'] = false;
            }

            if ( $this->_args['manage_layouts'] && isset($this->layouts[ $layout ]) && ! $this->layouts[ $layout ]['support']['description'] ) {
                unset( $args['supports'][1] );  // remove 'editor'
            }

            if ( ! empty( $rewrite ) ) {
                $args['rewrite'] = array( 'slug' => $rewrite );
            }

            // register post type
            $post_type = yit_avoid_duplicate( str_replace( '-', '_', substr( $this->_prefix_cpt . $name, 0, 16) ), $post_types );
            register_post_type( $post_type, apply_filters( 'yit_' . $this->_prefix_cpt . $name . '_args', $args, $pt ) );  // save the post type in post meta

            update_post_meta( $pt->ID, '_post_type', $post_type );
            $pts[] = $post_type;

            // register taxonomy
            if ( $this->_args['has_taxonomy'] && ! empty( $taxonomy ) ) {

                $labels = array(
                    'name'              => sprintf( _x( '%s Categories', 'taxonomy general name', 'yith-plugin-fw' ), $label_singular ),
                    'singular_name'     => _x( 'Category', 'taxonomy singular name', 'yith-plugin-fw' ),
                    'search_items'      => __( 'Search Categories', 'yith-plugin-fw' ),
                    'all_items'         => __( 'All Categories', 'yith-plugin-fw' ),
                    'parent_item'       => __( 'Parent Category', 'yith-plugin-fw' ),
                    'parent_item_colon' => __( 'Parent Category:', 'yith-plugin-fw' ),
                    'edit_item'         => __( 'Edit Category', 'yith-plugin-fw' ),
                    'update_item'       => __( 'Update Category', 'yith-plugin-fw' ),
                    'add_new_item'      => __( 'Add New Category', 'yith-plugin-fw' ),
                    'new_item_name'     => __( 'New Category Name', 'yith-plugin-fw' ),
                    'menu_name'         => __( 'Category', 'yith-plugin-fw' ),
                );

                $args = array(
                    'hierarchical'      => true,
                    'labels'            => $labels,
                    'show_ui'           => true,
                    'show_admin_column' => true,
                    'query_var'         => true,
                );

                if ( ! empty( $taxonomy_rewrite ) ) {
                    $args['rewrite'] = array( 'slug' => $taxonomy_rewrite );
                }

                register_taxonomy( substr( $taxonomy, 0, 32 ), $post_type, $args );

            }

        }

        wp_cache_set( 'yit_cptu_post_types', $post_types );
    }
Exemple #4
0
 /**
  * Create a backup file
  *
  * This method create an encrypt backup file to save theme options settings
  * The file will be save in <theme_folder>/theme/assets/backups
  *
  * @param string $name the file name
  *
  * @return void
  * @since  2.0.0
  * @author Andrea Grillo <*****@*****.**>
  *
  */
 public function create_backup($name = '')
 {
     $options = YIT_Registry::get_instance()->options->get_options_from_prefix(YIT_Registry::get_instance()->options->options_name);
     if ($_POST['backup_name']) {
         $name = preg_replace("/[^a-zA-Z0-9_-]/", "", trim(str_replace(' ', '-', $_POST['backup_name'])));
     }
     $name = !empty($name) ? $name : 'backup';
     $name = yit_avoid_duplicate($name, $this->_backups_list);
     array_walk_recursive($options, array($this, 'convert_url'), 'in_export');
     $error = file_put_contents($this->_backups_upload_dir . $name, base64_encode(serialize($options[YIT_Registry::get_instance()->options->options_name])));
     if (!$error) {
         YIT_Registry::get_instance()->message->addMessage(__('Error. Unable to create backup!', 'yit'), 'error');
     } else {
         YIT_Registry::get_instance()->message->addMessage(__('Success. Backup created!', 'yit'));
     }
     YIT_Registry::get_instance()->message->printGlobalMessages();
     echo '<div class="hide" id="backup-temp-name" data-name="' . $name . '"></div>';
     die;
 }
 /**
  * Add category via AJAX
  *
  * @since 1.0.0
  */
 public function add_category()
 {
     $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : false;
     $new_category = isset($_POST['new_category']) ? $_POST['new_category'] : null;
     if (empty($post_id) && empty($new_category)) {
         return;
     }
     $cats = $this->get_setting('categories', $post_id);
     $new_cat_slug = yit_avoid_duplicate(sanitize_key($new_category), $cats, 'key');
     // add category
     $cats[$new_cat_slug] = $new_category;
     // sort alphabetical
     ksort($cats);
     // update in the database
     $this->update_setting('categories', $cats, $post_id);
     // echo JSON for the javascript of only new element
     echo json_encode(array('slug' => $new_cat_slug, 'name' => $new_category));
     die;
 }
Exemple #6
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;
     }
 }
Exemple #7
0
 /**
  * Save the options in the database
  *
  * Get the options send by the theme options form and then save the options value
  * in the database.
  *
  *
  * @param mixed $save_data
  *
  * @return mixed
  * @since  2.0.0
  * @author Antonino Scarfi' <*****@*****.**>
  */
 public function save_options($save_data = null)
 {
     if (($this->request->post('action') != 'yit-panel-save' || !$this->request->verify_nonce('yit_panel')) && $this->request->post('action') != 'yit_restore_backup') {
         return;
     }
     if ($this->request->post('action') == 'yit-panel-save') {
         $post_data = $this->request->post('yit_panel_option');
     } else {
         $post_data = $save_data;
     }
     /* Change Skin */
     if (isset($post_data['general-skin']) && (defined('YIT_DEV') && !YIT_DEV || !defined('YIT_DEV'))) {
         unset($post_data['general-skin']);
     }
     /* Change Theme Options Value */
     if (empty($this->_panel)) {
         $this->_panel = $this->getModel('panel')->get_theme_options_from_files();
     }
     $page_options = !$this->request->post('yit-subpage') ? $this->_panel['theme-options'] : $this->_panel[$this->request->post('yit-subpage')];
     foreach ($page_options as $tab => $subtabs) {
         foreach ($subtabs as $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');
                 $multicheck_type = array('cat', 'pag', 'checklist');
                 // 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']] = 'no';
                 }
                 // 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);
             }
         }
     }
     // Add a CSS Rule to an array ready to write on dynamics.css file
     $this->getModel('css')->save_css();
     // add the feedback message
     if ($this->request->post('action') == 'yit-panel-save') {
         $this->getModel('message')->addMessage(__('Options Saved!', 'yit'), 'updated', 'panel');
         // if AJAX, print the message and die
         if ($this->request->is_ajax) {
             $this->update_db_options();
             $this->getModel('message')->printMessages();
             die;
         }
     } elseif ($this->request->post('action') == 'yit_restore_backup') {
         $this->update_db_options();
         return true;
     }
 }