From 68b215972fb7cde8bb8290499ed5980893fb4b29 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Fri, 3 Jun 2011 18:39:32 +0200 Subject: [PATCH] Adding a table creation and update method. --- owark/owark.iml | 4 +-- wordpress/plugins/owark/owark.php | 46 +++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/owark/owark.iml b/owark/owark.iml index 76b7163..bc73aa3 100644 --- a/owark/owark.iml +++ b/owark/owark.iml @@ -2,9 +2,7 @@ - - - + diff --git a/wordpress/plugins/owark/owark.php b/wordpress/plugins/owark/owark.php index fb0156f..32c8a4a 100644 --- a/wordpress/plugins/owark/owark.php +++ b/wordpress/plugins/owark/owark.php @@ -18,7 +18,7 @@ /* Plugin Name: owark Plugin URI: http://owark.org -Description: Tired of broken links? Archive yours with the Open Web Archive! +Description: Tired of broken links? Archive yours with owark, the Open Web Archive! Version: 0.1 Author: Eric van der Vlist Author URI: http://eric.van-der-vlist.com @@ -32,6 +32,7 @@ if (!class_exists("Owark")) { private $broken_links = array(); private $post_id = -1; private $post_type = ""; + private $version = '0.1'; /** * Class constructor @@ -43,7 +44,11 @@ if (!class_exists("Owark")) { */ function Owark() { - add_action('admin_menu', array($this, 'owark_admin_menu')); + + if (is_admin()) { + add_action('admin_menu', array($this, 'owark_admin_menu')); + add_action('plugins_loaded', array($this, 'sanity_checks')); + } // See http://stackoverflow.com/questions/2210826/need-help-with-wp-rewrite-in-a-wordpress-plugin // Using a filter instead of an action to create the rewrite rules. @@ -63,6 +68,43 @@ if (!class_exists("Owark")) { } + /** + * Check we have everything we need... + * + * @package owark + * @since 0.1 + * + * + */ + function sanity_checks(){ + $installed_ver = get_option( "owark_db_version" ); + if ($installed_ver != $this->version) { + global $wpdb; + $table = $wpdb->prefix."owark"; + $sql = "CREATE TABLE $table ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + url text NOT NULL, + status varchar(20) NOT NULL DEFAULT 'to-archive', + arc_date datetime, + arc_location text, + PRIMARY KEY(`id`), + KEY `url` (`url`(150)) )"; + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + dbDelta($sql); + + update_option( "owark_db_version", $this->version ); + + } + } + + /** + * Admin menus + * + * @package owark + * @since 0.1 + * + * + */ function owark_admin_menu() { add_management_page(__('The Open Web Archive', 'owark'), __('Web Archive', 'owark'), 'edit_others_posts', 'owark', array($this, 'management_page')); }