Ejemplo n.º 1
0
/**
* Function to create the database and to add options into WordPress.
* This function should be called by an action.
*
* @access public
*/
function sk_activate()
{
    global $wpdb;
    global $db_version;
    //Create new capabilitie
    $role1 = get_role('administrator');
    $role2 = get_role('editor');
    $role3 = get_role('author');
    // add SK_CAP to the roles if the administrator doesn't have the capabilitie.
    if (!$role1->has_cap(SK_CAP)) {
        $role1->add_cap(SK_CAP);
        $role2->add_cap(SK_CAP);
        $role3->add_cap(SK_CAP);
    }
    $table_name = $wpdb->prefix . "schreikasten";
    $blacklist_name = $wpdb->prefix . "schreikasten_blacklist";
    $db_version = get_option('sk_db_version');
    switch ($db_version) {
        case 1:
            //SQL code to update from SK1 to SK4
            $sql = "ALTER TABLE {$table_name} ADD user_id int NOT NULL";
            $wpdb->query($sql);
            $sql = "ALTER TABLE {$table_name} ADD email tinytext NOT NULL";
            $wpdb->query($sql);
            $sql = "ALTER TABLE {$table_name} CONVERT TO CHARACTER SET utf8";
            $wpdb->query($sql);
            $sql = "CREATE TABLE {$blacklist_name}(\r\n\t\tid bigint(1) NOT NULL AUTO_INCREMENT,\r\n\t\tpc bigint(1) NOT NULL,\r\n\t\tdate datetime NOT NULL,\r\n\t\tforever tinyint(4) NOT NULL,\r\n\t\tPRIMARY KEY (id)\r\n\t\t) CHARSET=utf8;";
            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
            dbDelta($sql);
            update_option('sk_db_version', SK_DB_VERSION);
            break;
        case 2:
            //SQL code to update from SK2 to SK4
            $sql = "ALTER TABLE {$table_name} ADD reply int NOT NULL";
            $wpdb->query($sql);
            $sql = "ALTER TABLE {$table_name} CONVERT TO CHARACTER SET utf8";
            $wpdb->query($sql);
            $sql = "ALTER TABLE {$blacklist_name} CONVERT TO CHARACTER SET utf8";
            $wpdb->query($sql);
            update_option('sk_db_version', SK_DB_VERSION);
            break;
        case 3:
            //SQL code to update from SK3 to SK4
            $sql = "ALTER TABLE {$table_name} CONVERT TO CHARACTER SET utf8";
            $wpdb->query($sql);
            $sql = "ALTER TABLE {$blacklist_name} CONVERT TO CHARACTER SET utf8";
            $wpdb->query($sql);
            update_option('sk_db_version', SK_DB_VERSION);
            break;
        case 4:
            //We are in SK3, so theres nothing we have to do
            break;
        default:
            //It's a fresh installation, create the table.
            if ($wpdb->get_var("show tables like '{$table_name}'") != $table_name) {
                $sql = "CREATE TABLE {$table_name}(\r\n\t\t\t\tid bigint(1) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\talias tinytext NOT NULL,\r\n\t\t\t\ttext text NOT NULL,\r\n\t\t\t\tdate datetime NOT NULL,\r\n\t\t\t\tip char(32) NOT NULL,\r\n\t\t\t\tstatus int NOT NULL,\r\n\t\t\t\tuser_id int NOT NULL,\r\n\t\t\t\temail tinytext NOT NULL,\r\n\t\t\t\treply int NOT NULL,\r\n\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t) CHARSET=utf8;";
                require_once ABSPATH . 'wp-admin/includes/upgrade.php';
                dbDelta($sql);
            }
            if ($wpdb->get_var("show tables like '{$blacklist_name}'") != $blacklist_name) {
                $sql = "CREATE TABLE {$blacklist_name}(\r\n\t\t\t\tid bigint(1) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\tpc bigint(1) NOT NULL,\r\n\t\t\t\tdate datetime NOT NULL,\r\n\t\t\t\tforever tinyint(4) NOT NULL,\r\n\t\t\t\tPRIMARY KEY (id)\r\n\t\t\t\t) CHARSET=utf8;";
                require_once ABSPATH . 'wp-admin/includes/upgrade.php';
                dbDelta($sql);
            }
            //Widget options
            $options = array('title' => __('Schreikasten', 'sk'), 'registered' => false, 'avatar' => true, 'layout' => SK_LAYOUT_SHOUTBOX, 'alert_about_emails' => true, 'items' => '5', 'refresh' => 0, 'bl_days' => '7', 'bl_maxpending' => '2', 'announce' => '1', 'requiremail' => '1', 'maxchars' => '225', 'rss' => false, 'moderation' => SK_MODERATION_CONFIG, 'date_format' => 'l, M j. Y h:i A');
            add_option('sk_options', $options);
            add_option('sk_db_version', SK_DB_VERSION);
            add_option('sk_api_key', '');
            add_option('sk_api_key_accepted', false);
            sk_verify_key();
            //if we have an old sk_api_key, verify it;
            break;
    }
    //Widget options
    $options = array('title' => __('Schreikasten', 'sk'), 'registered' => false, 'avatar' => true, 'layout' => SK_LAYOUT_SHOUTBOX, 'alert_about_emails' => true, 'items' => '5', 'refresh' => 0, 'bl_days' => '7', 'bl_maxpending' => '2', 'announce' => '1', 'requiremail' => '1', 'maxchars' => '225', 'rss' => false, 'moderation' => SK_MODERATION_CONFIG, 'delete_type' => 1, 'delete_num' => 0, 'maxperday' => 0);
    add_option('sk_options', $options);
    //Have we updated or no?
    //Is this widget a multiwidget?
    $options = get_option('widget_sk');
    if (is_array($options) && !array_key_exists('_multiwidget', $options)) {
        //Update the widget into multiple widgets
        skLegacy_updateWidget();
    }
    //Update layout configuration
    $options = get_option('sk_options');
    if (isset($options['replies'])) {
        if ($options['replies']) {
            $options['layout'] = SK_LAYOUT_BOARD;
        } else {
            $options['layout'] = SK_LAYOUT_SHOUTBOX;
        }
        unset($options['replies']);
        update_option('sk_options', $options);
    }
    if (!isset($options['date_format'])) {
        $options['date_format'] = 'l, M j. Y g:i A';
        update_option('sk_options', $options);
    }
    if (!isset($options['delete_type'])) {
        $options['delete_type'] = 1;
        $options['delete_num'] = 0;
        update_option('sk_options', $options);
    }
    if (!isset($options['maxperday'])) {
        $options['maxperday'] = 0;
        update_option('sk_options', $options);
    }
    //The cron function
    wp_clear_scheduled_hook('sk_cron');
    wp_schedule_event(time(), 'hourly', 'sk_cron');
}
Ejemplo n.º 2
0
				<td style="width: 300px;"><?php 
_e("Akismet API", 'sk');
?>
:</td>
				<td><input type="text" name="sk_api_key" size="30" value="<?php 
echo $sk_api_key;
?>
" /></td>
			</tr>
			<tr>
				<?php 
if (strlen(get_option('sk_api_key')) == 0) {
    update_option('sk_api_key_accepted', false);
    echo "<td colspan='2' style='padding-left: 190px;'><strong>" . sprintf(__("Set the <a href='%s' target='_BLANK'>API Key</a> if you require the antispam filter.", 'sk'), 'http://wordpress.com/api-keys/') . "</strong></td>";
} else {
    if (sk_verify_key()) {
        update_option('sk_api_key_accepted', true);
        echo "<td colspan='2' style='background: #00FF00; padding-left: 190px;'><strong>" . __("API Key is valid.", 'sk') . "</strong></td>";
    } else {
        update_option('sk_api_key_accepted', false);
        echo "<td colspan='2' style='background: #FF0000; padding-left: 190px;'><strong>" . __("API Key is not valid.", 'sk') . "<br/>" . sprintf(__("Set the <a href='%s' target='_BLANK'>API Key</a> if you require the antispam filter.", 'sk'), 'http://wordpress.com/api-keys/') . "</strong></td>";
    }
}
?>
			</tr>

<tr>
	<td><?php 
_e("Date format", 'sk');
?>
: </td>