Esempio n. 1
0
function gmedia_quite_update()
{
    global $wpdb, $gmDB, $gmCore, $gmGallery;
    $current_version = get_option('gmediaVersion', null);
    //$current_db_version = get_option( 'gmediaDbVersion', null );
    if (null !== $current_version) {
        $options = get_option('gmediaOptions');
        if (!is_array($options)) {
            $options = array();
        }
        require_once dirname(__FILE__) . '/setup.php';
        $default_options = gmedia_default_options();
        if (!get_option('gmediaInstallDate')) {
            $date = $wpdb->get_var("SELECT {$wpdb->prefix}gmedia.date FROM {$wpdb->prefix}gmedia ORDER BY ID ASC");
            if (!$date) {
                $date = '1 month ago';
            }
            $installDate = strtotime($date);
            add_option('gmediaInstallDate', $installDate);
        }
        if (version_compare($current_version, '0.9.23', '<')) {
            if (isset($options['license_name'])) {
                $default_options['license_name'] = $options['license_name'];
                $default_options['license_key'] = $options['license_key'];
                $default_options['license_key2'] = $options['license_key2'];
            } elseif (isset($options['product_name'])) {
                $default_options['license_name'] = $options['product_name'];
                $default_options['license_key'] = $options['gmedia_key'];
                $default_options['license_key2'] = $options['gmedia_key2'];
            }
        }
        if (version_compare($current_version, '1.2.0', '<')) {
            gmedia_capabilities();
        }
        if (version_compare($current_version, '1.4.4', '<')) {
            if (!get_option('GmediaHashID_salt')) {
                $ustr = wp_generate_password(12, false);
                add_option('GmediaHashID_salt', $ustr);
            }
        }
        if (version_compare($current_version, '1.6.3', '<')) {
            $wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_cover'), array('meta_key' => 'cover'));
            $wpdb->update($wpdb->prefix . 'gmedia_meta', array('meta_key' => '_rating'), array('meta_key' => 'rating'));
        }
        if (version_compare($current_version, '1.6.5', '<')) {
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_edited'), array('meta_key' => 'edited'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_settings'), array('meta_key' => 'settings'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_query'), array('meta_key' => 'query'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_module'), array('meta_key' => 'module'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_order'), array('meta_key' => 'order'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_key' => '_orderby'), array('meta_key' => 'orderby'));
        }
        if (version_compare($current_version, '1.6.6', '<')) {
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'ID'), array('meta_key' => '_orderby', 'meta_value' => ''));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'DESC'), array('meta_key' => '_order', 'meta_value' => ''));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'title'), array('meta_key' => '_orderby', 'meta_value' => 'title ID'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'date'), array('meta_key' => '_orderby', 'meta_value' => 'date ID'));
            $wpdb->update($wpdb->prefix . 'gmedia_term_meta', array('meta_value' => 'modified'), array('meta_key' => '_orderby', 'meta_value' => 'modified ID'));
        }
        if (version_compare($current_version, '1.7.1', '<')) {
            $gmedia_ids = $gmDB->get_gmedias(array('mime_type' => 'audio', 'fields' => 'ids'));
            foreach ($gmedia_ids as $id) {
                $gmDB->update_metadata($meta_type = 'gmedia', $id, $meta_key = '_metadata', $gmDB->generate_gmedia_metadata($id));
            }
        }
        if (version_compare($current_version, '1.7.20', '<')) {
            gmedia_restore_original_images();
        }
        if (version_compare($current_version, '1.8.08', '<')) {
            if (is_file($gmCore->upload['path'] . '/module/mosaic/js/mosaic.min.js')) {
                @unlink($gmCore->upload['path'] . '/module/mosaic/js/jquery.prettyPhoto-min.js');
                @unlink($gmCore->upload['path'] . '/module/mosaic/js/mosaic.js');
            }
        }
        if (version_compare($current_version, '1.8.12', '<')) {
            $categories = $gmDB->get_terms('gmedia_category');
            if (!empty($categories)) {
                $cats = array('abstract' => __('Abstract', 'grand-media'), 'animals' => __('Animals', 'grand-media'), 'black-and-white' => __('Black and White', 'grand-media'), 'celebrities' => __('Celebrities', 'grand-media'), 'city-and-architecture' => __('City & Architecture', 'grand-media'), 'commercial' => __('Commercial', 'grand-media'), 'concert' => __('Concert', 'grand-media'), 'family' => __('Family', 'grand-media'), 'fashion' => __('Fashion', 'grand-media'), 'film' => __('Film', 'grand-media'), 'fine-art' => __('Fine Art', 'grand-media'), 'food' => __('Food', 'grand-media'), 'journalism' => __('Journalism', 'grand-media'), 'landscapes' => __('Landscapes', 'grand-media'), 'macro' => __('Macro', 'grand-media'), 'nature' => __('Nature', 'grand-media'), 'nude' => __('Nude', 'grand-media'), 'people' => __('People', 'grand-media'), 'performing-arts' => __('Performing Arts', 'grand-media'), 'sport' => __('Sport', 'grand-media'), 'still-life' => __('Still Life', 'grand-media'), 'street' => __('Street', 'grand-media'), 'transportation' => __('Transportation', 'grand-media'), 'travel' => __('Travel', 'grand-media'), 'underwater' => __('Underwater', 'grand-media'), 'urban-exploration' => __('Urban Exploration', 'grand-media'), 'wedding' => __('Wedding', 'grand-media'));
                foreach ($categories as $c) {
                    if (isset($cats[$c->name])) {
                        $wpdb->update($wpdb->prefix . 'gmedia_term', array('name' => $cats[$c->name]), array('term_id' => $c->term_id));
                        $gmDB->clean_term_cache($c->term_id, 'gmedia_category');
                    }
                }
            }
            $role = $gmDB->get_role('gmedia_tag_manage');
            $gmDB->set_capability($role, 'gmedia_category_manage');
        }
        if (version_compare($current_version, '1.8.20', '<')) {
            $queries = $wpdb->get_results("SELECT meta_id, meta_key, meta_value FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_query'", ARRAY_A);
            if (!empty($queries)) {
                foreach ($queries as $query) {
                    $query['meta_value'] = maybe_unserialize($query['meta_value']);
                    $gmCore->replace_array_keys($query['meta_value'], array('album__in' => 'gmedia_album', 'tag__in' => 'gmedia_tag', 'category__in' => 'gmedia_category'));
                    foreach ($query['meta_value'] as $key => $value) {
                        if ('gmedia_filter' == $key) {
                            $new_query = array();
                            foreach ($value as $filter_id) {
                                $filter_query = $gmDB->get_metadata('gmedia_term', $filter_id, '_query', true);
                                $new_query = array_merge($filter_query, $new_query);
                            }
                            foreach ($new_query as $new_key => $new_val) {
                                if (is_array($new_val)) {
                                    $new_query[$new_key] = implode(',', $new_val);
                                }
                            }
                            $query['meta_value'] = $new_query;
                        } else {
                            if (is_array($value)) {
                                $query['meta_value'][$key] = implode(',', $value);
                            }
                        }
                    }
                    $gmDB->update_metadata_by_mid($meta_type = 'gmedia_term', $query['meta_id'], $query['meta_value']);
                }
            }
            $filters = $gmDB->get_terms('gmedia_filter');
            if (!empty($filters)) {
                foreach ($filters as $filter) {
                    $gmDB->delete_term($filter->term_id);
                }
            }
        }
        if (version_compare($current_version, '1.8.22', '<')) {
            $queries = $wpdb->get_results("SELECT meta_id, meta_key, meta_value FROM {$wpdb->prefix}gmedia_term_meta WHERE meta_key = '_query'", ARRAY_A);
            if (!empty($queries)) {
                foreach ($queries as $query) {
                    $query['meta_value'] = maybe_unserialize($query['meta_value']);
                    if (isset($query['meta_value']['gmedia__in'])) {
                        $query['meta_value'] = $query['meta_value'] + array('order' => 'ASC', 'orderby' => 'gmedia__in');
                        $gmDB->update_metadata_by_mid($meta_type = 'gmedia_term', $query['meta_id'], $query['meta_value']);
                    }
                }
            }
        }
        if (version_compare($current_version, '1.8.55', '<')) {
            $wpdb->query("CREATE INDEX `_hash` ON {$wpdb->prefix}gmedia_meta ( meta_value(32) );");
            $ajax_operations = get_option('gmedia_ajax_long_operations', array());
            $ajax_operations['gmedia_hash_files'] = 'gmedia_hash_files';
            update_option('gmedia_ajax_long_operations', $ajax_operations);
        }
        if (version_compare($current_version, '1.8.63', '<')) {
            $default_options['purchase_key'] = $options['license_key'];
        }
        if (version_compare($current_version, '1.8.85', '<')) {
            foreach ($_COOKIE as $key => $value) {
                if ('gmuser' === substr($key, 0, 6)) {
                    setcookie($key, '', time() - 3600);
                }
            }
        }
        $new_options = $gmCore->array_diff_key_recursive($default_options, $options);
        $gmGallery->options = $gmCore->array_replace_recursive($options, $new_options);
        update_option('gmediaOptions', $gmGallery->options);
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/afflux');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/jq-mplayer');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/minima');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/phantom');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/wp-videoplayer');
        update_option("gmediaVersion", GMEDIA_VERSION);
        if ((int) $gmGallery->options['mobile_app']) {
            $gmCore->app_service('app_updatecron');
        }
    }
}
Esempio n. 2
0
function gmedia_quite_update()
{
    global $gmDB, $gmCore, $gmGallery;
    $current_version = get_option('gmediaVersion', null);
    //$current_db_version = get_option( 'gmediaDbVersion', null );
    if (null !== $current_version) {
        $options = get_option('gmediaOptions');
        require_once dirname(__FILE__) . '/setup.php';
        $default_options = gmedia_default_options();
        if (version_compare($current_version, '0.9.23', '<')) {
            if (isset($options['license_name'])) {
                $default_options['license_name'] = $options['license_name'];
                $default_options['license_key'] = $options['license_key'];
                $default_options['license_key2'] = $options['license_key2'];
            } elseif (isset($options['product_name'])) {
                $default_options['license_name'] = $options['product_name'];
                $default_options['license_key'] = $options['gmedia_key'];
                $default_options['license_key2'] = $options['gmedia_key2'];
            }
            update_option('gmediaOptions', $default_options);
        } else {
            $new_options = $gmCore->array_diff_key_recursive($default_options, $options);
            $gmGallery->options = $gmCore->array_replace_recursive($options, $new_options);
            update_option('gmediaOptions', $gmGallery->options);
        }
        if (version_compare($current_version, '1.2.0', '<')) {
            gmedia_capabilities();
        }
        if (version_compare($current_version, '1.4.4', '<')) {
            if (!get_option('GmediaHashID_salt')) {
                $ustr = wp_generate_password(12, false);
                add_option('GmediaHashID_salt', $ustr);
            }
        }
        if (version_compare($current_version, '1.6.01', '<')) {
            $gmDB->set_capability('administrator', 'gmedia_filter_manage');
        }
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/afflux');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/jq-mplayer');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/minima');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/phantom');
        $gmCore->delete_folder($gmCore->upload['path'] . '/module/wp-videoplayer');
        update_option("gmediaVersion", GMEDIA_VERSION);
    }
}
Esempio n. 3
0
/**
 * creates all tables for the plugin
 * called during register_activation hook
 * @access internal
 * @return void
 **/
function gmedia_install()
{
    /** @var $wpdb wpdb */
    global $wpdb, $gmGallery, $gmCore;
    // Check for capability
    if (!current_user_can('activate_plugins')) {
        return;
    }
    gmedia_capabilities();
    // upgrade function changed in WordPress 2.3
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    // add charset & collate like wp core
    $charset_collate = '';
    if ($wpdb->has_cap('collation')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    $charset_collate .= ' ROW_FORMAT=DYNAMIC';
    $gmedia = $wpdb->prefix . 'gmedia';
    $gmedia_meta = $wpdb->prefix . 'gmedia_meta';
    $gmedia_term = $wpdb->prefix . 'gmedia_term';
    $gmedia_term_meta = $wpdb->prefix . 'gmedia_term_meta';
    $gmedia_term_relationships = $wpdb->prefix . 'gmedia_term_relationships';
    if ($wpdb->get_var("show tables like '{$gmedia}'") != $gmedia) {
        $sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
        $sql .= "CREATE TABLE {$gmedia} (\n\t\t\tID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\tauthor BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tdate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\tdescription LONGTEXT NOT NULL,\n\t\t\ttitle TEXT NOT NULL,\n\t\t\tgmuid VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\tlink VARCHAR(255) NOT NULL DEFAULT '',\n\t\t\tmodified DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n\t\t\tmime_type VARCHAR(100) NOT NULL DEFAULT '',\n\t\t\tstatus VARCHAR(20) NOT NULL DEFAULT 'publish',\n\t\t\tpost_id BIGINT(20) UNSIGNED DEFAULT NULL,\n\t\t\tPRIMARY KEY  (ID),\n\t\t\tKEY gmuid (gmuid),\n\t\t\tKEY type_status_date (mime_type,status,date,ID),\n\t\t\tKEY author (author),\n\t\t\tKEY post_id (post_id)\n\t\t) {$charset_collate}";
        dbDelta($sql);
    }
    if ($wpdb->get_var("show tables like '{$gmedia_meta}'") != $gmedia_meta) {
        $sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
        $sql .= "CREATE TABLE {$gmedia_meta} (\n\t\t\tmeta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\tgmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tmeta_key VARCHAR(255) DEFAULT NULL,\n\t\t\tmeta_value LONGTEXT,\n\t\t\tPRIMARY KEY  (meta_id),\n\t\t\tKEY gmedia_id (gmedia_id),\n\t\t\tKEY meta_key (meta_key),\n\t\t\tINDEX `_hash` (meta_value(32))\n\t\t) {$charset_collate}";
        dbDelta($sql);
    }
    if ($wpdb->get_var("show tables like '{$gmedia_term}'") != $gmedia_term) {
        $sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
        $sql .= "CREATE TABLE {$gmedia_term} (\n\t\t\tterm_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\tname VARCHAR(200) NOT NULL DEFAULT '',\n\t\t\ttaxonomy VARCHAR(32) NOT NULL DEFAULT '',\n\t\t\tdescription LONGTEXT NOT NULL,\n\t\t\tglobal BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tcount BIGINT(20) NOT NULL DEFAULT '0',\n\t\t\tstatus VARCHAR(20) NOT NULL DEFAULT 'publish',\n\t\t\tPRIMARY KEY  (term_id),\n\t\t\tKEY taxonomy (taxonomy),\n\t\t\tKEY name (name)\n\t\t) {$charset_collate}";
        dbDelta($sql);
    }
    if ($wpdb->get_var("show tables like '{$gmedia_term_meta}'") != $gmedia_term_meta) {
        $sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
        $sql .= "CREATE TABLE {$gmedia_term_meta} (\n\t\t\tmeta_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\tgmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tmeta_key VARCHAR(255) DEFAULT NULL,\n\t\t\tmeta_value LONGTEXT,\n\t\t\tPRIMARY KEY  (meta_id),\n\t\t\tKEY gmedia_term_id (gmedia_term_id),\n\t\t\tKEY meta_key (meta_key)\n\t\t) {$charset_collate}";
        dbDelta($sql);
    }
    if ($wpdb->get_var("show tables like '{$gmedia_term_relationships}'") != $gmedia_term_relationships) {
        $sql = "SET GLOBAL innodb_file_format = Barracuda, innodb_large_prefix = ON;";
        $sql .= "CREATE TABLE {$gmedia_term_relationships} (\n\t\t\tgmedia_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tgmedia_term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',\n\t\t\tterm_order INT(11) NOT NULL DEFAULT '0',\n\t\t\tgmedia_order INT(11) NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY  (gmedia_id,gmedia_term_id),\n\t\t\tKEY gmedia_term_id (gmedia_term_id)\n\t\t) {$charset_collate}";
        dbDelta($sql);
    }
    // check one table again, to be sure
    if ($wpdb->get_var("show tables like '{$gmedia}'") != $gmedia) {
        update_option("gmediaInitCheck", __('GmediaGallery: Tables could not created, please check your database settings', 'grand-media'));
        return;
    }
    if (!get_option('GmediaHashID_salt')) {
        $ustr = wp_generate_password(12, false);
        add_option('GmediaHashID_salt', $ustr);
    }
    // set the default settings, if we didn't upgrade
    if (empty($gmGallery->options)) {
        $gmGallery->options = gmedia_default_options();
        // Set installation date
        if (!get_option('gmediaInstallDate')) {
            $installDate = time();
            add_option('gmediaInstallDate', $installDate);
        }
        update_option('gmediaOptions', $gmGallery->options);
    } else {
        $default_options = gmedia_default_options();
        unset($gmGallery->options['folder'], $gmGallery->options['taxonomies']);
        $new_options = $gmCore->array_diff_key_recursive($default_options, $gmGallery->options);
        $gmGallery->options = $gmCore->array_replace_recursive($gmGallery->options, $new_options);
        update_option('gmediaOptions', $gmGallery->options);
    }
    // try to make gallery dirs if not exists
    foreach ($gmGallery->options['folder'] as $folder) {
        wp_mkdir_p($gmCore->upload['path'] . '/' . $folder);
    }
    wp_clear_scheduled_hook('gmedia_app_cronjob');
    wp_schedule_event(time(), 'gmedia_app', 'gmedia_app_cronjob');
    add_option('gmediaActivated', time());
}