Пример #1
0
/**
 * creates all tables for the gallery
 * called during register_activation hook
 * 
 * @access internal
 * @return void
**/
function flag_install()
{
    global $wpdb, $wp_version;
    // Check for capability
    if (!current_user_can('activate_plugins')) {
        return;
    }
    flag_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}";
        }
    }
    $flagpictures = $wpdb->prefix . 'flag_pictures';
    $flaggallery = $wpdb->prefix . 'flag_gallery';
    $flagcomments = $wpdb->prefix . 'flag_comments';
    $flagalbum = $wpdb->prefix . 'flag_album';
    if ($wpdb->get_var("show tables like '{$flagpictures}'") != $flagpictures) {
        $sql = "CREATE TABLE " . $flagpictures . " (\r\n\t\tpid BIGINT(20) NOT NULL AUTO_INCREMENT ,\r\n\t\tgalleryid BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\t\tfilename VARCHAR(255) NOT NULL ,\r\n\t\tdescription MEDIUMTEXT NULL ,\r\n\t\talttext MEDIUMTEXT NULL ,\r\n\t\tlink TEXT NULL ,\r\n\t\timagedate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\t\tmodified TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,\r\n\t\texclude TINYINT NULL DEFAULT '0',\r\n\t\tsortorder BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\t\tlocation TEXT,\r\n\t\tcity TINYTEXT,\r\n\t\tstate TINYTEXT,\r\n\t\tcountry TINYTEXT,\r\n\t\tcredit TEXT,\r\n\t\tcopyright TEXT,\r\n\t\tcommentson INT(1) UNSIGNED NOT NULL DEFAULT '1',\r\n\t\thitcounter INT(11) UNSIGNED DEFAULT '0',\r\n\t\ttotal_value INT(11) UNSIGNED DEFAULT '0',\r\n\t\ttotal_votes INT(11) UNSIGNED DEFAULT '0',\r\n\t\tused_ips LONGTEXT,\r\n\t\tmeta_data LONGTEXT,\r\n\t\tPRIMARY KEY pid (pid)\r\n\t\t) {$charset_collate};";
        dbDelta($sql);
    }
    if ($wpdb->get_var("show tables like '{$flaggallery}'") != $flaggallery) {
        $sql = "CREATE TABLE " . $flaggallery . " (\r\n\t\tgid BIGINT(20) NOT NULL AUTO_INCREMENT ,\r\n\t\tname VARCHAR(255) NOT NULL ,\r\n\t\tpath MEDIUMTEXT NULL ,\r\n\t\ttitle MEDIUMTEXT NULL ,\r\n\t\tgaldesc MEDIUMTEXT NULL ,\r\n\t\tpreviewpic BIGINT(20) NULL DEFAULT '0' ,\r\n\t\tsortorder BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\t\tauthor BIGINT(20) NOT NULL DEFAULT '0' ,\r\n\t\tstatus TINYINT NULL DEFAULT '0' ,\r\n\t\tPRIMARY KEY gid (gid)\r\n\t\t) {$charset_collate};";
        dbDelta($sql);
    }
    if ($wpdb->get_var("show tables like '{$flagcomments}'") != $flagcomments) {
        $sql = "CREATE TABLE " . $flagcomments . " (\r\n\t\tcid int(11) unsigned NOT NULL auto_increment,\r\n\t\townerid int(11) unsigned NOT NULL default '0',\r\n\t\tname varchar(255) NOT NULL default '',\r\n\t\temail varchar(255) NOT NULL default '',\r\n\t\twebsite varchar(255) default NULL,\r\n\t\tdate datetime default NULL,\r\n\t\tcomment text,\r\n\t\tinmoderation int(1) unsigned NOT NULL default '0',\r\n\t\tPRIMARY KEY  (cid),\r\n\t\tKEY ownerid (ownerid)\r\n\t\t) {$charset_collate};";
        dbDelta($sql);
    }
    if (!$wpdb->get_var("SHOW TABLES LIKE '{$flagalbum}'")) {
        $sql = "CREATE TABLE " . $flagalbum . " (\r\n\t\tid BIGINT(20) NOT NULL AUTO_INCREMENT ,\r\n\t\tname VARCHAR(255) NOT NULL ,\r\n\t\tpreviewpic BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\t\talbumdesc MEDIUMTEXT NULL ,\r\n\t\tcategories LONGTEXT NOT NULL,\r\n\t\tPRIMARY KEY id (id)\r\n\t\t) {$charset_collate};";
        dbDelta($sql);
    }
    // check one table again, to be sure
    if (!$wpdb->get_var("SHOW TABLES LIKE '{$flagpictures}'")) {
        update_option("flag_init_check", __('Flash Album Gallery : Tables could not created, please check your database settings', 'flash-album-gallery'));
        return;
    }
    $options = get_option('flag_options');
    // set the default settings, if we didn't upgrade
    if (empty($options)) {
        flag_default_options();
    }
    // if all is passed , save the VERSIONs
    add_option("flag_db_version", FLAG_DBVERSION);
    add_option("flagVersion", FLAGVERSION);
    include_once dirname(__FILE__) . '/tuning.php';
    flag_tune(false);
}
Пример #2
0
 function wp_flag_tune_messages()
 {
     if (get_option('flagVersion') != $this->version) {
         // upgrade plugin
         require_once FLAG_ABSPATH . 'admin/tuning.php';
         $ok = flag_tune($show_error = false);
         include_once dirname(__FILE__) . '/admin/flag_install.php';
         // check for tables
         flag_capabilities();
         update_option("flagVersion", FLAGVERSION);
     }
     // check for upgrade
     if (get_option('flag_db_version') < FLAG_DBVERSION) {
         include_once dirname(__FILE__) . '/admin/functions.php';
         include_once dirname(__FILE__) . '/admin/upgrade.php';
         flag_upgrade();
         add_action('admin_notices', create_function('', 'echo \'<div id="message" class="updated"><p>\' . __(\'Grand Flagallery database upgraded\', "flash-album-gallery" ) . \'</p></div>\';'));
     }
 }