Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/annotation/annotation_plugin.php
blob: c2e23bcfe114e42449775b693a3eb04cbd57124c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
Plugin Name: Annotation plugin
Plugin URI:  http://www.andreasgros.net
Description: This plugin turns your wordpress blog into an annotation server 
Author: Andreas Gros
Author URI: http://www.andreasgros.net/author/andi

*/

if(!class_exists("AnnotationPlugin"))
	{

	class AnnotationPlugin 
		{

		function AnnotationPlugin()
			{
			global $wpdb;

			$table_name = $wpdb->prefix . "annotation";

      $sql = "CREATE TABLE " . $table_name . " (
						id mediumint(9) NOT NULL AUTO_INCREMENT,
            clientuuid VARCHAR(100) NULL,
            annotationurl VARCHAR(100) NULL,
            page VARCHAR(10) NULL,
						creator VARCHAR(100) NOT NULL,
						created datetime DEFAULT 0,
						modified timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
						body text NOT NULL,
						bodyurl VARCHAR(255) NOT NULL,
            bodysvg text NULL,
						contentcontext text NOT NULL,
            contextwhen datetime DEFAULT 0,
						targetcontext text NOT NULL,
						title VARCHAR(255) NOT NULL,
						annotates VARCHAR(255) NOT NULL,
            target VARCHAR(255) NULL,
            mimetype VARCHAR(100) NULL,
						rdf text NOT NULL,
						UNIQUE KEY id (id)
					);";


			if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 
				{
				require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
				dbDelta($sql);
				}
      else //TO DELETE: just for testing purposes
        {
        //$tsql = "DROP TABLE " . $table_name;
        //dbDelta($tsql);
        //dbDelta($sql);
        }
      
      $table_name = $wpdb->prefix . "annotation_userid";
      $sql = "CREATE TABLE " . $table_name . " ( userid VARCHAR(64) );";
      if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 
				{
				require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
				dbDelta($sql);
				}
			}

		/**
		 * Get a specific annotation record
		 *
		 * @param string $record URL of the annotated resource 
		 */
		function annotation_record($record=null) 
			{
			//return $this->get_annotation_record($record);
			}

		function get_author_info_from_request_uri()
			{
			if (preg_match('/author\/(.+)\/$/', $_SERVER["REQUEST_URI"], $result)) 
				{
				$_GET['author_name'] =  $result[1];
				return $result[1];
				} 
			return false;
			}

		}//class AnnotationPlugin

	}//if(!class_exists("AnnotationPlugin"))


	//
	// crate the pubman plugin
	//
	if(class_exists("AnnotationPlugin") && !isset($annotationPlugin))
		{
		$annotationPlugin = new AnnotationPlugin();	
		register_activation_hook('annotation/annotation_plugin.php', 'annotation_activate');
		if ( function_exists('register_uninstall_hook') ) {
			register_uninstall_hook('annotation/annotation_plugin.php', 'annotation_uninstall');
		}


		/**
		 * Activate plugin.
		 */

		if(!function_exists('annotation_activate'))
		{
			function annotation_activate() 
				{
				global $annotationPlugin;
				if(!$annotationPlugin) 
					{
					$annotationPlugin = new AnnotationPlugin();	
					}
				}
		}

		/**
		 * Uninstall plugin.
		 */
		if(!function_exists('annotation_uninstall'))
			{	 
			function annotation_uninstall() 
				{
				//delete_option('annotation_option');
				}
			}



		}


?>