Exemple #1
0
/**
 * creates all tables for the gallery
 * called during register_activation hook
 *
 * @access internal
 * @return void
 */
function nggallery_install()
{
    global $wpdb;
    // Check for capability
    if (!current_user_can('activate_plugins')) {
        return;
    }
    // Set the capabilities for the administrator
    $role = get_role('administrator');
    // We need this role, no other chance
    if (empty($role)) {
        update_option("ngg_init_check", __('Sorry, NextCellent Gallery works only with a role called administrator', "nggallery"));
        return;
    }
    $role->add_cap('NextGEN Gallery overview');
    $role->add_cap('NextGEN Use TinyMCE');
    $role->add_cap('NextGEN Upload images');
    $role->add_cap('NextGEN Manage gallery');
    $role->add_cap('NextGEN Manage tags');
    $role->add_cap('NextGEN Manage others gallery');
    $role->add_cap('NextGEN Edit album');
    $role->add_cap('NextGEN Change style');
    $role->add_cap('NextGEN Change options');
    // upgrade function changed in WordPress 2.3
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    // add charset & collate like wp core
    $charset_collate = '';
    if (version_compare($wpdb->get_var("SELECT VERSION() AS `mysql_version`"), '4.1.0', '>=')) {
        if (!empty($wpdb->charset)) {
            $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
        }
        if (!empty($wpdb->collate)) {
            $charset_collate .= " COLLATE {$wpdb->collate}";
        }
    }
    $nggpictures = $wpdb->prefix . 'ngg_pictures';
    $nggallery = $wpdb->prefix . 'ngg_gallery';
    $nggalbum = $wpdb->prefix . 'ngg_album';
    // Create pictures table
    $sql = "CREATE TABLE " . $nggpictures . " (\r\n\tpid BIGINT(20) NOT NULL AUTO_INCREMENT ,\r\n\timage_slug VARCHAR(255) NOT NULL ,\r\n\tpost_id BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\tgalleryid BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\tfilename VARCHAR(255) NOT NULL ,\r\n\tdescription MEDIUMTEXT NULL ,\r\n\talttext MEDIUMTEXT NULL ,\r\n\timagedate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\r\n\texclude TINYINT NULL DEFAULT '0' ,\r\n\tsortorder BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\tmeta_data LONGTEXT,\r\n\tPRIMARY KEY  (pid),\r\n\tKEY post_id (post_id)\r\n\t) {$charset_collate};";
    dbDelta($sql);
    // Create gallery table
    $sql = "CREATE TABLE " . $nggallery . " (\r\n\tgid BIGINT(20) NOT NULL AUTO_INCREMENT ,\r\n\tname VARCHAR(255) NOT NULL ,\r\n\tslug VARCHAR(255) NOT NULL ,\r\n\tpath MEDIUMTEXT NULL ,\r\n\ttitle MEDIUMTEXT NULL ,\r\n\tgaldesc MEDIUMTEXT NULL ,\r\n\tpageid BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\tpreviewpic BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\tauthor BIGINT(20) DEFAULT '0' NOT NULL  ,\r\n\tPRIMARY KEY  (gid)\r\n\t) {$charset_collate};";
    dbDelta($sql);
    // Create albums table
    $sql = "CREATE TABLE " . $nggalbum . " (\r\n\tid BIGINT(20) NOT NULL AUTO_INCREMENT ,\r\n\tname VARCHAR(255) NOT NULL ,\r\n\tslug VARCHAR(255) NOT NULL ,\r\n\tpreviewpic BIGINT(20) DEFAULT '0' NOT NULL ,\r\n\talbumdesc MEDIUMTEXT NULL ,\r\n\tsortorder LONGTEXT NOT NULL,\r\n\tpageid BIGINT(20) DEFAULT '0' NOT NULL,\r\n\tPRIMARY KEY  (id)\r\n\t) {$charset_collate};";
    dbDelta($sql);
    // check one table again, to be sure
    if (!$wpdb->get_var("SHOW TABLES LIKE '{$nggpictures}'")) {
        update_option("ngg_init_check", __('NextCellent Gallery : Tables could not created, please check your database settings', "nggallery"));
        return;
    }
    $options = get_option('ngg_options');
    // set the default settings, if we didn't upgrade
    if (empty($options)) {
        ngg_default_options();
    }
    // if all is passed , save the DBVERSION
    add_option("ngg_db_version", NGG_DBVERSION);
}
Exemple #2
0
function nggallery_admin_setup()
{
    global $wpdb, $ngg;
    if (isset($_POST['resetdefault'])) {
        check_admin_referer('ngg_uninstall');
        include_once dirname(__FILE__) . '/install.php';
        ngg_default_options();
        $ngg->load_options();
        nggGallery::show_message(__('Reset all settings to default parameter', 'nggallery'));
    }
    if (isset($_POST['uninstall'])) {
        check_admin_referer('ngg_uninstall');
        include_once dirname(__FILE__) . '/install.php';
        nggallery_uninstall();
        nggGallery::show_message(__('Uninstall sucessful ! Now delete the plugin and enjoy your life ! Good luck !', 'nggallery'));
    }
    ?>
	<div class="wrap">
	<h2><?php 
    _e('Reset options', 'nggallery');
    ?>
</h2>
		<form name="resetsettings" method="post">
			<?php 
    wp_nonce_field('ngg_uninstall');
    ?>
			<p><?php 
    _e('Reset all options/settings to the default installation.', 'nggallery');
    ?>
</p>
			<div align="center"><input type="submit" class="button" name="resetdefault" value="<?php 
    _e('Reset settings', 'nggallery');
    ?>
" onclick="javascript:check=confirm('<?php 
    _e('Reset all options to default settings ?\\n\\nChoose [Cancel] to Stop, [OK] to proceed.\\n', 'nggallery');
    ?>
');if(check==false) return false;" /></div>
		</form>
	</div>
	<?php 
    if (!is_multisite() || is_super_admin()) {
        ?>
	<div class="wrap">
	<h2><?php 
        _e('Uninstall plugin tables', 'nggallery');
        ?>
</h2>
		
		<form name="resetsettings" method="post">
		<div>
			<?php 
        wp_nonce_field('ngg_uninstall');
        ?>
			<p><?php 
        _e('You don\'t like NextCellent Gallery ?', 'nggallery');
        ?>
</p>
			<p><?php 
        _e('No problem, before you deactivate this plugin press the Uninstall Button, because deactivating NextCellent Gallery does not remove any data that may have been created. ', 'nggallery');
        ?>
		</div>
		<p><font color="red"><strong><?php 
        _e('WARNING:', 'nggallery');
        ?>
</strong><br />
		<?php 
        _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to backup all the tables first. NextCellent gallery is stored in the tables', 'nggallery');
        ?>
 <strong><?php 
        echo $wpdb->nggpictures;
        ?>
</strong>, <strong><?php 
        echo $wpdb->nggalbum;
        ?>
</strong> <?php 
        _e('and', 'nggallery');
        ?>
 <strong><?php 
        echo $wpdb->nggalbum;
        ?>
</strong>.</font></p>
		<div align="center">
			<input type="submit" name="uninstall" class="button delete" value="<?php 
        _e('Uninstall plugin', 'nggallery');
        ?>
" onclick="javascript:check=confirm('<?php 
        _e('You are about to Uninstall this plugin from WordPress.\\nThis action is not reversible.\\n\\nChoose [Cancel] to Stop, [OK] to Uninstall.\\n', 'nggallery');
        ?>
');if(check==false) return false;"/>
		</div>
		</form>
	</div>
	<?php 
    }
    ?>

	<?php 
}
Exemple #3
0
/**
 * creates all tables for the gallery
 * called during register_activation hook
 *
 * @access internal
 * @return void
 */
function nggallery_install () {

   	global $wpdb , $wp_roles, $wp_version;

	// Check for capability
	if ( !current_user_can('activate_plugins') )
		return;

	// Set the capabilities for the administrator
	$role = get_role('administrator');
	// We need this role, no other chance
	if ( empty($role) ) {
		update_option( "ngg_init_check", __('Sorry, NextGEN Gallery works only with a role called administrator',"nggallery") );
		return;
	}

	$role->add_cap('NextGEN Gallery overview');
	$role->add_cap('NextGEN Use TinyMCE');
	$role->add_cap('NextGEN Upload images');
	$role->add_cap('NextGEN Manage gallery');
	$role->add_cap('NextGEN Manage tags');
	$role->add_cap('NextGEN Manage others gallery');
	$role->add_cap('NextGEN Edit album');
	$role->add_cap('NextGEN Change style');
	$role->add_cap('NextGEN Change options');

	// upgrade function changed in WordPress 2.3
	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

	// add charset & collate like wp core
	$charset_collate = '';

	if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
		if ( ! empty($wpdb->charset) )
			$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
		if ( ! empty($wpdb->collate) )
			$charset_collate .= " COLLATE $wpdb->collate";
	}

   	$nggpictures					= $wpdb->prefix . 'ngg_pictures';
	$nggallery						= $wpdb->prefix . 'ngg_gallery';
	$nggalbum						= $wpdb->prefix . 'ngg_album';

    // could be case senstive : http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html
	if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggpictures'" ) ) {

		$sql = "CREATE TABLE " . $nggpictures . " (
		pid BIGINT(20) NOT NULL AUTO_INCREMENT ,
        image_slug VARCHAR(255) NOT NULL ,
		post_id BIGINT(20) DEFAULT '0' NOT NULL ,
		galleryid BIGINT(20) DEFAULT '0' NOT NULL ,
		filename VARCHAR(255) NOT NULL ,
		description MEDIUMTEXT NULL ,
		alttext MEDIUMTEXT NULL ,
		imagedate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
		exclude TINYINT NULL DEFAULT '0' ,
		sortorder BIGINT(20) DEFAULT '0' NOT NULL ,
		meta_data LONGTEXT,
		PRIMARY KEY pid (pid),
		KEY post_id (post_id)
		) $charset_collate;";

      dbDelta($sql);
    }

	if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggallery'" )) {

		$sql = "CREATE TABLE " . $nggallery . " (
		gid BIGINT(20) NOT NULL AUTO_INCREMENT ,
		name VARCHAR(255) NOT NULL ,
        slug VARCHAR(255) NOT NULL ,
		path MEDIUMTEXT NULL ,
		title MEDIUMTEXT NULL ,
		galdesc MEDIUMTEXT NULL ,
		pageid BIGINT(20) DEFAULT '0' NOT NULL ,
		previewpic BIGINT(20) DEFAULT '0' NOT NULL ,
		author BIGINT(20) DEFAULT '0' NOT NULL  ,
		PRIMARY KEY gid (gid)
		) $charset_collate;";

      dbDelta($sql);
   }

	if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggalbum'" )) {

		$sql = "CREATE TABLE " . $nggalbum . " (
		id BIGINT(20) NOT NULL AUTO_INCREMENT ,
		name VARCHAR(255) NOT NULL ,
        slug VARCHAR(255) NOT NULL ,
		previewpic BIGINT(20) DEFAULT '0' NOT NULL ,
		albumdesc MEDIUMTEXT NULL ,
		sortorder LONGTEXT NOT NULL,
		pageid BIGINT(20) DEFAULT '0' NOT NULL,
		PRIMARY KEY id (id)
		) $charset_collate;";

      dbDelta($sql);
    }

	// check one table again, to be sure
	if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggpictures'" ) ) {
		update_option( "ngg_init_check", __('NextGEN Gallery : Tables could not created, please check your database settings',"nggallery") );
		return;
	}

	$options = get_option('ngg_options');
	// set the default settings, if we didn't upgrade
	if ( empty( $options ) )
 		ngg_default_options();

	// if all is passed , save the DBVERSION
	add_option("ngg_db_version", NGG_DBVERSION);

}