intial checkin of wordpress integration module
authorgreg gay <ggay@ocad.ca>
Wed, 22 Jun 2011 20:15:47 +0000 (20:15 -0000)
committergreg gay <ggay@ocad.ca>
Wed, 22 Jun 2011 20:15:47 +0000 (20:15 -0000)
19 files changed:
mods/wordpress/README [new file with mode: 0644]
mods/wordpress/index.php [new file with mode: 0644]
mods/wordpress/index_admin.php [new file with mode: 0644]
mods/wordpress/index_instructor.php [new file with mode: 0644]
mods/wordpress/index_mystart.php [new file with mode: 0644]
mods/wordpress/index_public.php [new file with mode: 0644]
mods/wordpress/module.css [new file with mode: 0644]
mods/wordpress/module.php [new file with mode: 0644]
mods/wordpress/module.sql [new file with mode: 0644]
mods/wordpress/module.xml [new file with mode: 0644]
mods/wordpress/module_delete.php [new file with mode: 0644]
mods/wordpress/module_install.php [new file with mode: 0644]
mods/wordpress/module_news.php [new file with mode: 0644]
mods/wordpress/module_uninstall.php [new file with mode: 0644]
mods/wordpress/sublinks.php [new file with mode: 0644]
mods/wordpress/wordpress_icon_sm.png [new file with mode: 0644]
mods/wordpress/wordpress_logo.png [new file with mode: 0644]
mods/wordpress/wp_plugin/external-database-authentication/ext_db_auth.php [new file with mode: 0644]
mods/wordpress/wp_plugin/external-database-authentication/readme.txt [new file with mode: 0644]

diff --git a/mods/wordpress/README b/mods/wordpress/README
new file mode 100644 (file)
index 0000000..876eda8
--- /dev/null
@@ -0,0 +1,28 @@
+## WordPress Integration module for ATutor
+
+####################
+
+**Wordpress needs to be installed and configured before installing this module. See the Wordpress documentation for instruction on installing and configuring Wordpress.
+
+http://codex.wordpress.org/Installing_WordPress
+
+
+####################
+Installation the ATutor WordPress Module:
+1. Unzip the atutor_wordpress.x.x.x.zip file into the ATutor mods/ directory to create a "wordpress directory.
+2. Login to ATutor as the admin, click on the Modules tab then click Install Modules. Wordpress should be listed. Select it and press the Install button.
+3. Follow the installer instructions.
+4. Once the module is installed, select the WordPress module now listed in the available modules in the module manager, then press the Enable button. This inserts another main navigation tab above.
+5. Click the WordPress tab then enter the URL to the base directory under which WordPress is installed, then press the Save button. WordPress should then appear below.
+6. Next set the database access information for WordPress in the wp_config.php file in the module directory, then save the file. This information is required if you intended on using the module detailed view to display recent posts on a course home page, or student tools page.
+
+#####################
+Authenticate Wordpress Users from ATutor Members
+To remove the need to setup separate accounts in WordPress and ATutor, you can install the WordPress External DB  Authentication plugin. 
+
+Plugin details can be found at:
+http://wordpress.org/extend/plugins/external-database-authentication/
+
+Note that this is not a single sign-on, but rather just a way to ensure anyone registered in ATutor, is automatically registered in Wordpress. When a users logs into Wordpress for the first time, the member information in ATutor is copied over to WordPress. If you find you are unable to login with an account you know esits in ATutor, review the cookies you have set in your browser, and remove and WordPress related ones. Then try to login again.
+
+Note also that you will probably want to install this Wordpress plugin before you start using Wordpress with ATutor. Otherwise you will need to recreate any Wordpress accounts in ATutor.
\ No newline at end of file
diff --git a/mods/wordpress/index.php b/mods/wordpress/index.php
new file mode 100644 (file)
index 0000000..f47aca2
--- /dev/null
@@ -0,0 +1,16 @@
+<?php\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/wordpress/module.css'; // use a custom stylesheet\r
+\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+?>\r
+\r
+<a href="<?php echo $_config['wp-url']; ?>wp-login.php" target="toolframe">\r
+<?php echo _AT('wordpress_login'); ?></a>\r
+<iframe name="toolframe"  src="<?php echo $_config['wp-url']; ?><?php if($p !=''){ echo '?p='.$p;} ?>" width="95%" height="450" style="border:none;">\r
+<p><?php echo _AT('wordpress_no_iframe',$_config['wp-url']); ?>"><?php echo _AT('wordpress_login'); ?></a></p>\r
+</iframe>\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>\r
+\r
diff --git a/mods/wordpress/index_admin.php b/mods/wordpress/index_admin.php
new file mode 100644 (file)
index 0000000..ccb4dea
--- /dev/null
@@ -0,0 +1,46 @@
+<?php\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/wordpress/module.css'; // use a custom stylesheet\r
+admin_authenticate(AT_ADMIN_PRIV_WORDPRESS);\r
+\r
+$_POST['wp-url'] = $addslashes($_POST['wp-url']);\r
+\r
+if($_POST['submit']){\r
+       foreach($_POST as $key=>$wp_config)\r
+       if($key != "submit"){\r
+       $sql="REPLACE INTO ".TABLE_PREFIX."config SET name='$key', value='".$wp_config."'";\r
+       if($result= mysql_query($sql, $db)){\r
+               $msg->addFeedback("WP_CONFIG_SAVED");\r
+               $_config['wp-url'] = $_POST['wp-url'];\r
+       }else{\r
+               $msg->addError("WP_CONFIG_FAIL");\r
+       }\r
+\r
+       }\r
+}\r
+\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+?>\r
+\r
+<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">\r
+<label for="wp-url"><?php echo _AT('wordpress_base_url'); ?></label>\r
+<input type="text" name="wp-url" id="wp-url" value="<?php if($_config['wp-url']){echo $_config['wp-url'];}else{ echo 'http://';} ?>" size="60" /><br />\r
+\r
+<input type="submit" name="submit" value="<?php echo _AT('wordpress_save'); ?>">\r
+</form>\r
+\r
+<h3><?php echo _AT('wordpress_admin_login');  ?></h3>\r
+<a href="<?php echo $_config['wp-url']; ?>wp-login.php" target="toolframe"><?php echo _AT('wordpress_login'); ?></a>\r
+<?php\r
+if($_config['wp-url']){?>\r
+       <iframe frameborder="0" border="0" name="toolframe" src="<?php echo $_config['wp-url']; ?>" width="95%" height="450" id="frame_set" onload="if (window.parent &amp;&amp; window.parent.autoIframe) {window.parent.autoIframe('tree');}">\r
+       <p><?php echo _AT('wordpress_no_iframes',$_config['wp-url']); ?> </p>\r
+       </iframe>\r
+<?php }else{ ?>\r
+       <p><?php echo _AT('wordpress_do_setup'); ?></p>\r
+\r
+<?php } ?>\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/wordpress/index_instructor.php b/mods/wordpress/index_instructor.php
new file mode 100644 (file)
index 0000000..cbdc742
--- /dev/null
@@ -0,0 +1,13 @@
+<?php\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+authenticate(AT_PRIV_WORDPRESS);\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+?>\r
+<a href="<?php echo $_config['wp-url']; ?>wp-login.php" target="tool_frame">\r
+<?php echo _AT('wordpress_login'); ?></a>\r
+<iframe src="<?php echo $_config['wp-url']; ?>" width="95%" height="450" style="border:none;" name="tool_frame">\r
+<p><?php echo _AT('wordpress_no_iframe',$_config['wp-url']); ?>wp-login.php"><?php echo _AT('wordpress_login'); ?></a></p>\r
+</iframe>\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/wordpress/index_mystart.php b/mods/wordpress/index_mystart.php
new file mode 100644 (file)
index 0000000..071534e
--- /dev/null
@@ -0,0 +1,15 @@
+<?php\r
+$_user_location        = 'users';\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/wordpress/module.css'; // use a custom stylesheet\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+\r
+?>\r
+\r
+<a href="<?php echo $_config['wp-url']; ?>wp-login.php" target="toolframe">\r
+<?php echo _AT('wordpress_login'); ?></a>\r
+<iframe name="toolframe"  src="<?php echo $_config['wp-url']; ?><?php if($p !=''){ echo 'index.php?p='.$p;} ?>" width="95%" height="450" style="border:none;">\r
+<p><?php echo _AT('wordpress_no_iframe',$_config['wp-url']); ?>"><?php echo _AT('wordpress_login'); ?></a></p>\r
+</iframe>\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>\r
diff --git a/mods/wordpress/index_public.php b/mods/wordpress/index_public.php
new file mode 100644 (file)
index 0000000..cf2ca95
--- /dev/null
@@ -0,0 +1,17 @@
+<?php\r
+\r
+$_user_location        = 'public';\r
+\r
+define('AT_INCLUDE_PATH', '../../include/');\r
+require (AT_INCLUDE_PATH.'vitals.inc.php');\r
+$_custom_css = $_base_path . 'mods/wordpress/module.css'; // use a custom stylesheet\r
+require (AT_INCLUDE_PATH.'header.inc.php');\r
+?>\r
+\r
+<a href="<?php echo $_config['wp-url']; ?>" target="toolwin">\r
+<?php echo _AT('wordpress_login'); ?><?php echo _AT('wordpress_login_newwin'); ?></a>\r
+<iframe src="<?php echo $_config['wp-url']; ?>" width="95%" height="450" style="border:none;" name="blog_frame">\r
+<p><?php echo _AT('wordpress_no_iframe',$_config['wp-url']); ?>"><?php echo _AT('wordpress_login'); ?></a></p>\r
+</iframe>\r
+\r
+<?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\ No newline at end of file
diff --git a/mods/wordpress/module.css b/mods/wordpress/module.css
new file mode 100644 (file)
index 0000000..c9fce7a
--- /dev/null
@@ -0,0 +1,15 @@
+div#helloworld {\r
+       border: 1px solid #ccc;\r
+       padding: 10px;\r
+       width: 50%;\r
+       margin-right: auto;\r
+       margin-left: auto;\r
+       background-color: #efefef;\r
+       color: #444;\r
+       margin-top: 30px;\r
+       margin-bottom: 30px;\r
+}\r
+\r
+#frame_set{\r
+       border:none;\r
+}
\ No newline at end of file
diff --git a/mods/wordpress/module.php b/mods/wordpress/module.php
new file mode 100644 (file)
index 0000000..a8134c0
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/*******
+ * doesn't allow this file to be loaded with a browser.
+ */
+if (!defined('AT_INCLUDE_PATH')) { exit; }
+
+/******
+ * this file must only be included within a Module obj
+ */
+if (!isset($this) || (isset($this) && (strtolower(get_class($this)) != 'module'))) { exit(__FILE__ . ' is not a Module'); }
+
+/*******
+ * assign the instructor and admin privileges to the constants.
+ */
+define('AT_PRIV_WORDPRESS',       $this->getPrivilege());
+define('AT_ADMIN_PRIV_WORDPRESS', $this->getAdminPrivilege());
+
+/*******
+ * create a side menu box/stack.
+ */
+//$this->_stacks['wordpress'] = array('title_var'=>'wordpress', 'file'=>'mods/wordpress/side_menu.inc.php');
+// ** possible alternative: **
+// $this->addStack('wordpress', array('title_var' => 'wordpress', 'file' => './side_menu.inc.php');
+
+/*******
+ * create optional sublinks for module "detail view" on course home page
+ * when this line is uncommented, "mods/wordpress/sublinks.php" need to be created to return an array of content to be displayed
+ */
+$this->_list['wordpress'] = array('title_var'=>'wordpress','file'=>'mods/wordpress/sublinks.php');
+
+// Uncomment for tiny list bullet icon for module sublinks "icon view" on course home page
+$this->_pages['mods/wordpress/index.php']['icon']      = 'mods/wordpress/wordpress_icon_sm.png';
+
+// Uncomment for big icon for module sublinks "detail view" on course home page
+//$this->_pages['mods/wordpress/index.php']['img']      = 'mods/wordpress/wordpress.jpg';
+
+// ** possible alternative: **
+// the text to display on module "detail view" when sublinks are not available
+$this->_pages['mods/wordpress/index.php']['text']      = _AT('wordpress_text');
+
+/*******
+ * if this module is to be made available to students on the Home or Main Navigation.
+ */
+$_group_tool = $_student_tool = 'mods/wordpress/index.php';
+
+/*******
+ * add the admin pages when needed.
+ */
+if (admin_authenticate(AT_ADMIN_PRIV_WORDPRESS, TRUE) || admin_authenticate(AT_ADMIN_PRIV_ADMIN, TRUE)) {
+       $this->_pages[AT_NAV_ADMIN] = array('mods/wordpress/index_admin.php');
+       $this->_pages['mods/wordpress/index_admin.php']['title_var'] = 'wordpress';
+       $this->_pages['mods/wordpress/index_admin.php']['parent']    = AT_NAV_ADMIN;
+}
+
+/*******
+ * instructor Manage section:
+ */
+$this->_pages['mods/wordpress/index_instructor.php']['title_var'] = 'wordpress';
+$this->_pages['mods/wordpress/index_instructor.php']['parent']   = 'tools/index.php';
+// ** possible alternative: **
+// $this->pages['./index_instructor.php']['title_var'] = 'wordpress';
+// $this->pages['./index_instructor.php']['parent']    = 'tools/index.php';
+
+/*******
+ * student page.
+ */
+$this->_pages['mods/wordpress/index.php']['title_var'] = 'wordpress';
+$this->_pages['mods/wordpress/index.php']['img']       = 'mods/wordpress/wordpress_logo.png';
+
+/* public pages */
+//$this->_pages[AT_NAV_PUBLIC] = array('mods/wordpress/index_public.php');
+//$this->_pages['mods/wordpress/index_public.php']['title_var'] = 'wordpress';
+//$this->_pages['mods/wordpress/index_public.php']['parent'] = AT_NAV_PUBLIC;
+
+/* my start page pages */
+$this->_pages[AT_NAV_START]  = array('mods/wordpress/index_mystart.php');
+$this->_pages['mods/wordpress/index_mystart.php']['title_var'] = 'wordpress';
+$this->_pages['mods/wordpress/index_mystart.php']['parent'] = AT_NAV_START;
+
+function wordpress_get_group_url($group_id) {
+       return 'mods/wordpress/index.php';
+}
+
+?>
\ No newline at end of file
diff --git a/mods/wordpress/module.sql b/mods/wordpress/module.sql
new file mode 100644 (file)
index 0000000..d668004
--- /dev/null
@@ -0,0 +1,29 @@
+# sql file for hello world module\r
+\r
+CREATE TABLE `wordpress` (\r
+   `wordpress_id` mediumint(8) unsigned NOT NULL,\r
+   `course_id` mediumint(8) unsigned NOT NULL,\r
+   `value` VARCHAR( 30 ) NOT NULL ,\r
+   PRIMARY KEY ( `wordpress_id` )\r
+) ENGINE = MyISAM;\r
+\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress','WordPress',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_admin_login','Login to Administer WordPress',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_base_url','WordPress base URL',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_login','WordPress Login',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_host_url','WordPress Host URL',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_db_name','WordPress Database Name',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_db_port','WordPress Database Port',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_db_user','WordPress Database User',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_db_pwd','WordPress Database Password',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_db_prefix','WordPress Database Table Prefix',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_save','Save',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_no_iframes','Your browser does not support iframes. Go to <a href="'.%s.'">WordPress Login</a>',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_do_setup','Enter the URL to the WordPress based directory in the form field above, including a trailing slash (/), to have WordPress appear here.',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_module','wordpress_no_db_info','To access current information here, modify the wp_config.php file in the WordPress module.',NOW(),'');\r
+\r
+\r
+\r
+\r
+INSERT INTO `language_text` VALUES ('en', '_msgs','AT_FEEDBACK_WP_CONFIG_SAVED','Wordpress configuration successfully saved',NOW(),'');\r
+INSERT INTO `language_text` VALUES ('en', '_msgs','AT_FEEDBACK_WP_CONFIG_FAIL','Wordpress configuration failed to save. ',NOW(),'');
\ No newline at end of file
diff --git a/mods/wordpress/module.xml b/mods/wordpress/module.xml
new file mode 100644 (file)
index 0000000..ce996a6
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="ISO-8859-1"?> \r
+<module version="0.1"> \r
+    <name lang="en">Wordpress Integration</name> \r
+    <description lang="en">This module integrate wordpress with ATutor, opening it in an iframe either as a course tool, or as My Start Page Blog. With the Wordpress external DB authentication plugin installed, available in the wp_plugins directory of the module, it synchronizes Wordpress users with ATutor members. See the README file for additional details.</description> \r
+    <maintainers>\r
+        <maintainer> \r
+            <name>ATutor Team</name> \r
+            <email>info@atutor.ca</email> \r
+        </maintainer>\r
+    </maintainers> \r
+    <url>http://atutor.ca</url> \r
+    <license>BSD</license> \r
+       <release> \r
+        <version>1.0</version> \r
+        <date>2011-06-21</date> \r
+        <state>beta</state> \r
+        <notes>Once installed, enable the module then under the new Wordpress tab, enter the URL to the base directory in which Wordpress is installed.</notes> \r
+    </release> \r
+</module>\r
diff --git a/mods/wordpress/module_delete.php b/mods/wordpress/module_delete.php
new file mode 100644 (file)
index 0000000..322d3a6
--- /dev/null
@@ -0,0 +1,21 @@
+<?php\r
+/*******\r
+ * this function named [module_name]_delete is called whenever a course content is deleted\r
+ * which includes when restoring a backup with override set, or when deleting an entire course.\r
+ * the function must delete all module-specific material associated with this course.\r
+ * $course is the ID of the course to delete.\r
+ */\r
+\r
+function hello_world_delete($course) {\r
+       global $db;\r
+\r
+       // delete hello_world course table entries\r
+       $sql = "DELETE FROM ".TABLE_PREFIX."hello_world WHERE course_id=$course";\r
+       mysql_query($sql, $db);\r
+\r
+       // delete hello_world course files\r
+       $path = AT_CONTENT_DIR .'hello_world/' . $course .'/';\r
+       clr_dir($path);\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/mods/wordpress/module_install.php b/mods/wordpress/module_install.php
new file mode 100644 (file)
index 0000000..9a82811
--- /dev/null
@@ -0,0 +1,67 @@
+<?php\r
+/*******\r
+ * the line below safe-guards this file from being accessed directly from\r
+ * a web browser. It will only execute if required from within an ATutor script,\r
+ * in our case the Module::install() method.\r
+ */\r
+if (!defined('AT_INCLUDE_PATH')) { exit; }\r
+\r
+/*******\r
+ * Note: the many options for these variables are used to decrease confusion.\r
+ *       TRUE | FALSE | 1 will be the convention.\r
+ *\r
+ * $_course_privilege\r
+ *     specifies the type of instructor privilege this module uses.\r
+ *     set to empty | FALSE | 0   to disable any privileges.\r
+ *     set to 1 | AT_PRIV_ADMIN   to use the instructor only privilege.\r
+ *     set to TRUE | 'new'        to create a privilege specifically for this module:\r
+ *                                will make this module available as a student privilege.\r
+ *\r
+ * $_admin_privilege\r
+ *    specifies the type of ATutor administrator privilege this module uses.\r
+ *    set to FALSE | AT_ADMIN_PRIV_ADMIN   to use the super administrator only privilege.\r
+ *    set to TRUE | 'new'                  to create a privilege specifically for this module:\r
+ *                                         will make this module available as an administrator privilege.\r
+ *\r
+ *\r
+ * $_cron_interval\r
+ *    if non-zero specifies in minutes how often the module's cron job should be run.\r
+ *    set to 0 or not set to disable.\r
+ */\r
+$_course_privilege = TRUE; // possible values: FALSE | AT_PRIV_ADMIN | TRUE\r
+$_admin_privilege  = TRUE; // possible values: FALSE | TRUE\r
+$_cron_interval    = 35; // run every 30 minutes\r
+\r
+\r
+/********\r
+ * the following code is used for creating a module-specific directory.\r
+ * it generates appropriate error messages to aid in its creation.\r
+ */\r
+$directory = AT_CONTENT_DIR .'hello_world';\r
+\r
+// check if the directory is writeable\r
+if (!is_dir($directory) && !@mkdir($directory)) {\r
+       $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' does not exist. Please create it.</li>'));\r
+} else if (!is_writable($directory) && @chmod($directory, 0666)) {\r
+       $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' is not writeable. On Unix issue the command <kbd>chmod a+rw</kbd>.</li>'));\r
+}\r
+\r
+\r
+/******\r
+ * the following code checks if there are any errors (generated previously)\r
+ * then uses the SqlUtility to run any database queries it needs, ie. to create\r
+ * its own tables.\r
+ */\r
+if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {\r
+       // deal with the SQL file:\r
+       require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');\r
+       $sqlUtility =& new SqlUtility();\r
+\r
+       /*\r
+        * the SQL file could be stored anywhere, and named anything, "module.sql" is simply\r
+        * a convention we're using.\r
+        */\r
+       $sqlUtility->queryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/mods/wordpress/module_news.php b/mods/wordpress/module_news.php
new file mode 100644 (file)
index 0000000..81b3968
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/*
+* Rename the function to match the name of the module. Names of all news functions must be unique
+* across all modules installed on a system. Return a variable called $news
+*/
+require('wp_connect.php');
+               // Number of links to be displayed on "detail view" box
+function wordpress_news() {
+       global $db_wp, $_config;
+if($_GET['p'] != "all"){
+       $link_limit = "LIMIT 3";
+}
+
+       $news = array();
+
+       $sql = "SELECT ID, post_title, guid, post_modified FROM ".WP_DB_PREFIX."posts ORDER BY post_modified DESC ".$link_limit;
+       
+
+$result = mysql_query($sql, $db_wp);
+
+       if($result){
+               //$news_count = 0;
+               //$page_ids = array();
+               $post_title = array();
+               while($row = mysql_fetch_assoc($result)){
+
+                               if(!in_array($row['post_title'], $post_title)){
+                               $post_title[] = $row['post_title'];
+                               $news[] = array('time'=> $row['post_modified'], 
+                                       'alt'=>_AT('wordpress_update'),
+                                       'thumb'=>'mods/wordpress/wordpress_icon_sm.png', 
+                                       'link'=>'<a href="'.AT_BASE_HREF.url_rewrite('mods/wordpress/index_mystart.php?p='.$row['ID']).'"'.
+                                       (strlen($row['post_title']) > SUBLINK_TEXT_LEN ? ' title="'.$row['post_title'].'"' : '') .'>'. 
+                                       validate_length($row['post_title'], SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a>');
+                               }
+               }
+       }
+
+       return $news;
+
+}
+?>
diff --git a/mods/wordpress/module_uninstall.php b/mods/wordpress/module_uninstall.php
new file mode 100644 (file)
index 0000000..9ed6969
--- /dev/null
@@ -0,0 +1,44 @@
+<?php\r
+/*******\r
+ * module_uninstall.php performs reversion of module_install.php\r
+ */\r
+\r
+/*******\r
+ * the line below safe-guards this file from being accessed directly from\r
+ * a web browser. It will only execute if required from within an ATutor script,\r
+ * in our case the Module::uninstall() method.\r
+ */\r
+if (!defined('AT_INCLUDE_PATH')) { exit; }\r
+\r
+/********\r
+ * the following code is used for removing a module-specific directory created in module_install.php.\r
+ * it generates appropriate error messages to aid in its creation.\r
+ */\r
+$directory = AT_CONTENT_DIR .'hello_world';\r
+\r
+// check if the directory exists\r
+if (is_dir($directory)) {\r
+       require(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php');\r
+\r
+       if (!clr_dir($directory))\r
+               $msg->addError(array('MODULE_UNINSTALL', '<li>'.$directory.' can not be removed. Please manually remove it.</li>'));\r
+}\r
+\r
+/******\r
+ * the following code checks if there are any errors (generated previously)\r
+ * then uses the SqlUtility to run reverted database queries of module.sql, \r
+ * ie. "create table" statement in module.sql is run as drop according table.\r
+ */\r
+if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {\r
+       // deal with the SQL file:\r
+       require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');\r
+       $sqlUtility = new SqlUtility();\r
+\r
+       /*\r
+        * the SQL file could be stored anywhere, and named anything, "module.sql" is simply\r
+        * a convention we're using.\r
+        */\r
+       $sqlUtility->revertQueryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);\r
+}\r
+\r
+?>
\ No newline at end of file
diff --git a/mods/wordpress/sublinks.php b/mods/wordpress/sublinks.php
new file mode 100644 (file)
index 0000000..334a252
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+if (!defined('AT_INCLUDE_PATH')) { exit; }
+
+/*****
+* Free form PHP can appear here to retreive current information
+* from the module, or a text description of the module where there is
+* not current information
+*****/
+require('wp_connect.php');
+
+global $db_wp;
+
+
+
+$link_limit = 3;               // Number of links to be displayed on "detail view" box
+$sql = "SELECT ID, post_title, guid FROM ".WP_DB_PREFIX."posts ORDER BY post_modified DESC LIMIT $link_limit";
+
+//$sql = "SELECT hello_world_id, value FROM ".TABLE_PREFIX."hello_world WHERE course_id=".$_SESSION[course_id].
+//       " ORDER BY value LIMIT $link_limit";
+if(!$result = mysql_query($sql, $db_wp)){
+       echo _AT('wordpress_no_db_info');
+       return 0;
+
+}
+
+if (mysql_num_rows($result) > 0) {
+       while ($row = mysql_fetch_assoc($result)) {
+               /****
+               * SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY are defined in include/lib/constance.lib.inc
+               * SUBLINK_TEXT_LEN determins the maxium length of the string to be displayed on "detail view" box.
+               *****/
+               $list[] = '<a href="'.AT_BASE_HREF.url_rewrite('mods/wordpress/index.php?p='. $row['ID']).'"'.
+                         (strlen($row['value']) > SUBLINK_TEXT_LEN ? ' title="'.$row['value'].'"' : '') .'>'. 
+                         validate_length($row['post_title'], SUBLINK_TEXT_LEN, VALIDATE_LENGTH_FOR_DISPLAY) .'</a>';
+       }
+       return $list;   
+} else {
+       return 0;
+}
+
+?>
\ No newline at end of file
diff --git a/mods/wordpress/wordpress_icon_sm.png b/mods/wordpress/wordpress_icon_sm.png
new file mode 100644 (file)
index 0000000..ea59600
Binary files /dev/null and b/mods/wordpress/wordpress_icon_sm.png differ
diff --git a/mods/wordpress/wordpress_logo.png b/mods/wordpress/wordpress_logo.png
new file mode 100644 (file)
index 0000000..88e20b9
Binary files /dev/null and b/mods/wordpress/wordpress_logo.png differ
diff --git a/mods/wordpress/wp_plugin/external-database-authentication/ext_db_auth.php b/mods/wordpress/wp_plugin/external-database-authentication/ext_db_auth.php
new file mode 100644 (file)
index 0000000..abf690d
--- /dev/null
@@ -0,0 +1,536 @@
+<?php
+/*
+Plugin Name: External DB authentication
+Plugin URI: http://www.ploofle.com/tag/ext_db_auth/
+Description: Used to externally authenticate WP users with an existing user DB.
+Version: 3.15
+Author: Charlene Barina
+Author URI: http://www.ploofle.com
+
+    Copyright 2007  Charlene Barina  (email : cbarina@u.washington.edu)
+
+    This program is free software; you can redistribute it and/or modify
+    it  under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+//backwords compatability with php < 5 for htmlspecialchars_decode
+if ( !function_exists('htmlspecialchars_decode') )
+{
+    function htmlspecialchars_decode($text)
+    {
+        return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
+    }
+}
+
+function ext_db_auth_activate() {
+       add_option('ext_db_type',"MySQL","External database type");
+       add_option('ext_db_mdb2_path',"","Path to MDB2 (if non-standard)");
+       add_option('ext_host',"","External database hostname");
+       add_option('ext_db_port',"","Database port (if non-standard)");
+       add_option('ext_db',"","External database name");
+       add_option('ext_db_user',"","External database username");
+       add_option('ext_db_pw',"","External database password");
+       add_option('ext_db_table',"","External database table for authentication");
+       add_option('ext_db_namefield',"","External database field for username");
+       add_option('ext_db_pwfield',"","External database field for password");
+       add_option('ext_db_first_name',"");
+       add_option('ext_db_last_name',"");
+       add_option('ext_db_user_url',"");
+       add_option('ext_db_user_email',"");
+       add_option('ext_db_description',"");
+       add_option('ext_db_aim',"");
+       add_option('ext_db_yim',"");
+       add_option('ext_db_jabber',"");
+       add_option('ext_db_enc',"","Type of encoding for external db (default SHA1? or MD5?)");
+       add_option('ext_db_error_msg',"","Custom login message");   
+       add_option('ext_db_other_enc','$password2 = $password;');
+       add_option('ext_db_role_bool','');
+       add_option('ext_db_role','');
+       add_option('ext_db_role_value','');
+}
+
+function ext_db_auth_init(){
+       register_setting('ext_db_auth','ext_db_type');
+       register_setting('ext_db_auth','ext_db_mdb2_path');
+       register_setting('ext_db_auth','ext_host');
+       register_setting('ext_db_auth','ext_db_port');
+       register_setting('ext_db_auth','ext_db');
+       register_setting('ext_db_auth','ext_db_user');
+       register_setting('ext_db_auth','ext_db_pw');
+       register_setting('ext_db_auth','ext_db_table');
+       register_setting('ext_db_auth','ext_db_namefield');
+       register_setting('ext_db_auth','ext_db_pwfield');
+       register_setting('ext_db_auth','ext_db_first_name');
+       register_setting('ext_db_auth','ext_db_last_name');
+       register_setting('ext_db_auth','ext_db_user_url');
+       register_setting('ext_db_auth','ext_db_user_email');
+       register_setting('ext_db_auth','ext_db_description');
+       register_setting('ext_db_auth','ext_db_aim');
+       register_setting('ext_db_auth','ext_db_yim');
+       register_setting('ext_db_auth','ext_db_jabber');
+       register_setting('ext_db_auth','ext_db_enc');
+       register_setting('ext_db_auth','ext_db_error_msg');   
+       register_setting('ext_db_auth','ext_db_other_enc');
+       register_setting('ext_db_auth','ext_db_role');
+       register_setting('ext_db_auth','ext_db_role_bool');
+       register_setting('ext_db_auth','ext_db_role_value');
+}
+
+//page for config menu
+function ext_db_auth_add_menu() {
+       add_options_page("External DB settings", "External DB settings", 10, __FILE__,"ext_db_auth_display_options");
+}
+
+//actual configuration screen
+function ext_db_auth_display_options() { 
+    $db_types[] = "MySQL";
+    $db_types[] = "MSSQL";
+    $db_types[] = "PgSQL";
+?>
+       <div class="wrap">
+       <h2>External Database Authentication Settings</h2>        
+       <form method="post" action="options.php">
+       <?php settings_fields('ext_db_auth'); ?>
+        <h3>External Database Settings</h3>
+          <strong>Make sure your WP admin account exists in the external db prior to saving these settings.</strong>
+        <table class="form-table">
+        <tr valign="top">
+            <th scope="row">Database type</th>
+                <td><select name="ext_db_type" >
+                <?php 
+                    foreach ($db_types as $key=>$value) { //print out radio buttons
+                        if ($value == get_option('ext_db_type'))
+                            echo '<option value="'.$value.'" selected="selected">'.$value.'<br/>';
+                        else echo '<option value="'.$value.'">'.$value.'<br/>';;
+                    }                
+                ?>
+                </select> 
+                               </td>
+                               <td>
+                                       <span class="description"><strong style="color:red;">required</strong>; If not MySQL, requires <a href="http://pear.php.net/package/MDB2/" target="_blank">PEAR MDB2 package</a> and relevant database driver package installation.</span>
+                               </td>
+        </tr>        
+        <tr valign="top">
+            <th scope="row"><label>Path to MDB2.php</label></th>
+                               <td><input type="text" name="ext_db_mdb2_path" value="<?php echo get_option('ext_db_mdb2_path'); ?>" /> </td>
+                               <td><span class="description">Only when using non-MySQL database and in case this isn't in some sort of include path in your PHP configuration.  No trailing slash! e.g., /home/username/php </span></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Host</label></th>
+                               <td><input type="text" name="ext_host" value="<?php echo get_option('ext_host'); ?>" /> </td>
+                               <td><span class="description"><strong style="color:red;">required</strong>; (often localhost)</span> </td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Port</label></th>
+                               <td><input type="text" name="ext_db_port" value="<?php echo get_option('ext_db_port'); ?>" /> </td>
+                               <td><span class="description">Only set this if you have a non-standard port for connecting.</span></td>
+        </tr>        
+        <tr valign="top">
+            <th scope="row"><label>Name</label></th>
+                               <td><input type="text" name="ext_db" value="<?php echo get_option('ext_db'); ?>" /></td>
+                               <td><span class="description"><strong style="color:red;">required</strong></span></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Username</label></th>
+                               <td><input type="text" name="ext_db_user" value="<?php echo get_option('ext_db_user'); ?>" /></td>
+                               <td><span class="description"><strong style="color:red;">required</strong>; (recommend select privileges only)</span></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Password</label></th>
+                               <td><input type="password" name="ext_db_pw" value="<?php echo get_option('ext_db_pw'); ?>" /></td>
+                               <td><span class="description"><strong style="color:red;">required</strong></span></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>User table</label></th>
+                               <td><input type="text" name="ext_db_table" value="<?php echo get_option('ext_db_table'); ?>" /></td>
+                               <td><span class="description"><strong style="color:red;">required</strong></span></td>
+        </tr>
+        </table>
+        
+        <h3>External Database Source Fields</h3>
+        <table class="form-table">
+        <tr valign="top">
+            <th scope="row"><label>Username</label></th>
+                               <td><input type="text" name="ext_db_namefield" value="<?php echo get_option('ext_db_namefield'); ?>" /></td>
+                               <td><span class="description"><strong style="color:red;">required</strong></span></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Password</label></th>
+                               <td><input type="text" name="ext_db_pwfield" value="<?php echo get_option('ext_db_pwfield'); ?>" /></td>
+                               <td><span class="description"><strong style="color:red;">required</strong></span><td>
+        </tr>
+        <tr valign="top">
+            <th scope="row">Password encryption method</th>
+                <td><select name="ext_db_enc">
+                <?php 
+                    switch(get_option('ext_db_enc')) {
+                    case "SHA1" :
+                        echo '<option selected="selected">SHA1</option><option>MD5</option><option>Other</option>';
+                        break;
+                    case "MD5" :
+                        echo '<option>SHA1</option><option selected="selected">MD5</option><option>Other</option>';
+                        break;                
+                    case "Other" :
+                        echo '<option>SHA1</option><option  selected="selected">MD5</option><option selected="selected">Other</option>';
+                        break;                                        
+                    default :
+                        echo '<option selected="selected">SHA1</option><option>MD5</option><option>Other</option>';
+                        break;
+                    }
+                ?>
+                               </select></td>
+                       <td><span class="description"><strong style="color:red;">required</strong>; (using "Other" requires you to enter PHP code below!)</td>            
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Hash code</label></th>
+                               <td><input type="text" name="ext_db_other_enc" size="50" value="<?php echo get_option('ext_db_other_enc'); ?>" /></td>
+                               <td><span class="description">Only will run if "Other" is selected and needs to be PHP code. Variable you need to set is $password2, and you have access to (original) $username and $password.</td>
+        </tr>
+               <tr valign="top">
+            <th scope="row"><label>Role check</label></th>
+                       <td><input type="text" name="ext_db_role" value="<?php echo get_option('ext_db_role'); ?>" />
+                               <br />
+                               <select name="ext_db_role_bool">
+                <?php 
+                    switch(get_option('ext_db_role_bool')) {
+                    case "is" :
+                        echo '<option selected="selected">is</option><option>greater than</option><option>less than</option>';
+                        break;
+                    case "greater than" :
+                        echo '<option>is</option><option selected="selected">greater than</option><option>less than</option>';
+                        break;                
+                    case "less than" :
+                        echo '<option>is</option><option>greater than</option><option selected="selected">less than</option>';
+                        break;                                        
+                    default :
+                        echo '<option selected="selected">is</option><option>greater than</option><option>less than</option>';
+                        break;
+                    }
+                ?>
+                               </select><br />
+                               <input type="text" name="ext_db_role_value" value="<?php echo get_option('ext_db_role_value'); ?>" /></td>
+                               <td><span class="description">Use this if you have certain user role ids in your external database to further restrict allowed logins.  If unused, leave fields blank.</span></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>First name</label></th>
+                       <td><input type="text" name="ext_db_first_name" value="<?php echo get_option('ext_db_first_name'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Last name</label></th>
+                       <td><input type="text" name="ext_db_last_name" value="<?php echo get_option('ext_db_last_name'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Homepage</label></th>
+                       <td><input type="text" name="ext_db_user_url" value="<?php echo get_option('ext_db_user_url'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Email</label></th>
+                       <td><input type="text" name="ext_db_user_email" value="<?php echo get_option('ext_db_user_email'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>Bio/description</label></th>
+                       <td><input type="text" name="ext_db_description" value="<?php echo get_option('ext_db_description'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>AIM screen name</label></th>
+                       <td><input type="text" name="ext_db_aim" value="<?php echo get_option('ext_db_aim'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>YIM screen name</label></th>
+                       <td><input type="text" name="ext_db_yim" value="<?php echo get_option('ext_db_yim'); ?>" /></td>
+        </tr>
+        <tr valign="top">
+            <th scope="row"><label>JABBER screen name</label></th>
+                       <td><input type="text" name="ext_db_jabber" value="<?php echo get_option('ext_db_jabber'); ?>" /></td>
+        </tr>
+        </table>
+        <h3>Other</h3>
+        <table class="form-table">
+        <tr valign="top">
+                <th scope="row">Custom login message</th>
+                <td><textarea name="ext_db_error_msg" cols=40 rows=4><?php echo htmlspecialchars(get_option('ext_db_error_msg'));?></textarea></td>
+                <td><span class="description">Shows up in login box, e.g., to tell them where to get an account. You can use HTML in this text.</td>
+        </tr>        
+    </table>
+       
+       <p class="submit">
+       <input type="submit" name="Submit" value="Save changes" />
+       </p>
+       </form>
+       </div>
+<?php
+}
+
+//sort-of wrapper for all DB interactions
+function db_functions($driver,$process,$resource,$query) {
+    if ($driver == "MySQL") {  //use built-in PHP mysql connection
+        switch($process) {
+            case "connect" :
+                $port = get_option('ext_db_port');                
+                if (!empty($port))   $port = ":".get_option('ext_db_port');
+                $resource = mysql_connect(get_option('ext_host').$port, get_option('ext_db_user'), get_option('ext_db_pw'),true) or die(mysql_error());                
+                mysql_select_db(get_option('ext_db'),$resource) or die(mysql_error());
+                return $resource;
+                break;
+            case "query":
+                $result = mysql_query($query,$resource) or die(mysql_error());
+                return $result;
+                break;            
+            case "numrows":
+                return mysql_num_rows($resource);
+                break;
+            case "fetch":
+                return mysql_fetch_assoc($resource);            
+                break;
+            case "close":
+                mysql_close($resource);            
+                break;
+        }
+    }
+    else {  //Use MDB2   
+        $mdbpath = get_option('ext_db_mdb2_path')."/MDB2.php";        
+        require_once($mdbpath);
+        switch($process) {
+            case "connect" :                
+                $port = get_option('ext_db_port');                
+                if (!empty($port))   $port = ":".get_option('ext_db_port');                
+                $url = strtolower($driver)."://".get_option('ext_db_user').":".get_option('ext_db_pw')."@".get_option('ext_host').$port."/".get_option('ext_db');                
+                $resource =& MDB2::connect($url);
+                if(PEAR::isError($resource)) die("Error while connecting : " . $resource->getMessage());
+                return $resource;        
+                break;
+            case "query":    
+                $result = $resource->query($query);
+                if(PEAR::isError($result)) die('Failed to issue query, error message : ' . $result->getMessage());                            
+                return $result;
+                break;            
+            case "numrows":
+                return $resource->numRows();
+                break;
+            case "fetch":
+                return $resource->fetchRow(MDB2_FETCHMODE_ASSOC);                
+                break;
+            case "close":
+                $resource->disconnect();                
+                break;
+        }
+    }
+}
+
+//actual meat of plugin - essentially, you're setting $username and $password to pass on to the system.
+//You check from your external system and insert/update users into the WP system just before WP actually
+//authenticates with its own database.
+function ext_db_auth_check_login($username,$password) {
+       require_once('./wp-includes/registration.php');
+     
+    //first figure out the DB type and connect...
+    $driver = get_option('ext_db_type');
+       //if on same host have to use resource id to make sure you don't lose the wp db connection        
+        
+    $mdbpath = get_option('ext_db_mdb2_path')."/MDB2.php";        
+    if ($mdbpath != "/MDB2.php") @require_once($mdbpath);
+    
+    $resource = db_functions($driver,"connect","","");
+       //prepare the db for unicode queries
+       //to pick up umlauts, non-latin text, etc., without choking
+       $utfquery = "SET NAMES 'utf8'";
+       $resultutf = db_functions($driver,"query",$resource,$utfquery);  
+
+       //do the password hash for comparing
+       switch(get_option('ext_db_enc')) {
+               case "SHA1" :
+                       $password2 = sha1($password);
+                       break;
+               case "MD5" :
+                       $password2 = md5($password);
+                       break;                  
+        case "Other" :             //right now defaulting to plaintext.  People can change code here for their own special hash
+            eval(get_option('ext_db_other_enc'));
+            break;
+       }
+        
+   
+   //first check to see if login exists in external db
+   $query = "SELECT count(*) AS numrows FROM " . get_option('ext_db_table') . " WHERE ".get_option('ext_db_namefield')." = '$username'";
+   $result = db_functions($driver,"query",$resource,$query);    
+   $numrows = db_functions($driver,"fetch",$result,"");
+   $numrows = $numrows["numrows"];
+       
+    if ($numrows) {
+            //then check to see if pw matches and get other fields...
+        $sqlfields['first_name'] = get_option('ext_db_first_name');
+        $sqlfields['last_name'] = get_option('ext_db_last_name');
+        $sqlfields['user_url'] = get_option('ext_db_user_url');
+        $sqlfields['user_email'] = get_option('ext_db_user_email');
+        $sqlfields['description'] = get_option('ext_db_description');
+        $sqlfields['aim'] = get_option('ext_db_aim');
+        $sqlfields['yim'] = get_option('ext_db_yim');
+        $sqlfields['jabber'] = get_option('ext_db_jabber');    
+               $sqlfields['ext_db_role'] = get_option('ext_db_role');
+                 
+        foreach($sqlfields as $key=>$value) {                          
+            if ($value == "") unset($sqlfields[$key]);
+        }
+        $sqlfields2 = implode(", ",$sqlfields);
+    
+        //just so queries won't error out if there are no relevant fields for extended data.
+        if (empty($sqlfields2)) $sqlfields2 = get_option('ext_db_namefield');
+                 
+           $query = "SELECT $sqlfields2 FROM " . get_option('ext_db_table') . " WHERE ".get_option('ext_db_namefield')." = '$username' AND ".get_option('ext_db_pwfield')." = '$password2'";                                                   
+           $result = db_functions($driver,"query",$resource,$query);    
+        $numrows = db_functions($driver,"numrows",$result,"");         
+               
+               if ($numrows) {    //create/update wp account from external database if login/pw exact match exists in that db          
+            $extfields = db_functions($driver,"fetch",$result,""); 
+                       $process = TRUE;
+                               
+                       //check role, if present.
+                       $role = get_option('ext_db_role');
+                       if (!empty($role)) {    //build the role checker too                                    
+                               $rolevalue = $extfields[$sqlfields['ext_db_role']];                     
+                               $rolethresh = get_option('ext_db_role_value');
+                               $rolebool = get_option('ext_db_role_bool');                                     
+                               global $ext_error;
+                               if ($rolebool == 'is') {
+                                       if ($rolevalue == $rolethresh) {}
+                                       else {
+                                               $username = NULL;
+                                               $ext_error = "wrongrole";                                                                                                       
+                                               $process = FALSE;
+                                       }
+                               }
+                               if ($rolebool == 'greater than') {
+                                       if ($rolevalue > $rolethresh) {}
+                                       else {                                  
+                                               $username = NULL;
+                                               $ext_error = "wrongrole";                                                                                                               
+                                               $process = FALSE;
+                                       }
+                               }
+                               if ($rolebool == 'less than') {
+                                       if ($rolevalue < $rolethresh) {}
+                                       else {
+                                               $username = NULL;
+                                               $ext_error = "wrongrole";
+                                               $process = FALSE;
+                                       }
+                               }                       
+                       }                                                               
+                       //only continue with user update/creation if login/pw is valid AND, if used, proper role perms
+                       if ($process) {
+                               $userarray['user_login'] = $username;
+                               $userarray['user_pass'] = $password;                    
+                               $userarray['first_name'] = $extfields[$sqlfields['first_name']];
+                               $userarray['last_name'] = $extfields[$sqlfields['last_name']];        
+                               $userarray['user_url'] = $extfields[$sqlfields['user_url']];
+                               $userarray['user_email'] = $extfields[$sqlfields['user_email']];
+                               $userarray['description'] = $extfields[$sqlfields['description']];
+                               $userarray['aim'] = $extfields[$sqlfields['aim']];
+                               $userarray['yim'] = $extfields[$sqlfields['yim']];
+                               $userarray['jabber'] = $extfields[$sqlfields['jabber']];
+                               $userarray['display_name'] = $extfields[$sqlfields['first_name']]." ".$extfields[$sqlfields['last_name']];            
+                               
+                               //also if no extended data fields
+                               if ($userarray['display_name'] == " ") $userarray['display_name'] = $username;
+                               
+                               db_functions($driver,"close",$resource,"");
+                               
+                               //looks like wp functions clean up data before entry, so I'm not going to try to clean out fields beforehand.
+                               if ($id = username_exists($username)) {   //just do an update
+                                        $userarray['ID'] = $id;
+                                        wp_update_user($userarray);
+                               }
+                               else wp_insert_user($userarray);          //otherwise create
+                       }
+        }                        
+               else {  //username exists but wrong password...                 
+                       global $ext_error;
+                       $ext_error = "wrongpw";                         
+                       $username = NULL;
+               }
+       }
+       else {  //don't let login even if it's in the WP db - it needs to come only from the external db.
+               global $ext_error;
+               $ext_error = "notindb";
+               $username = NULL;
+       }            
+}
+
+
+//gives warning for login - where to get "source" login
+function ext_db_auth_warning() {
+   echo "<p class=\"message\">".get_option('ext_db_error_msg')."</p>";
+}
+
+function ext_db_errors() {
+       global $error;
+       global $ext_error;
+       if ($ext_error == "notindb")
+               return "<strong>ERROR:</strong> Username not found.";
+       else if ($ext_error == "wrongrole")
+               return "<strong>ERROR:</strong> You don't have permissions to log in.";
+       else if ($ext_error == "wrongpw")
+               return "<strong>ERROR:</strong> Invalid password.";
+       else
+               return $error;
+}
+
+//hopefully grays stuff out.
+function ext_db_warning() {
+       echo '<strong style="color:red;">Any changes made below WILL NOT be preserved when you login again. You have to change your personal information per instructions found in the <a href="../wp-login.php">login box</a>.</strong>'; 
+}
+
+//disables the (useless) password reset option in WP when this plugin is enabled.
+function ext_db_show_password_fields() {
+       return 0;
+}
+
+
+/*
+ * Disable functions.  Idea taken from http auth plugin.
+ */
+function disable_function_register() { 
+       $errors = new WP_Error();
+       $errors->add('registerdisabled', __('User registration is not available from this site, so you can\'t create an account or retrieve your password from here. See the message above.'));
+       ?></form><br /><div id="login_error">User registration is not available from this site, so you can't create an account or retrieve your password from here. See the message above.</div>
+               <p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('&larr; Back to %s'), get_bloginfo('title', 'display' )); ?></a></p>
+       <?php
+       exit();
+}
+
+function disable_function() {  
+       $errors = new WP_Error();
+       $errors->add('registerdisabled', __('User registration is not available from this site, so you can\'t create an account or retrieve your password from here. See the message above.'));
+       login_header(__('Log In'), '', $errors);
+       ?>
+       <p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('&larr; Back to %s'), get_bloginfo('title', 'display' )); ?></a></p>
+       <?php
+       exit();
+}
+
+
+add_action('admin_init', 'ext_db_auth_init' );
+add_action('admin_menu', 'ext_db_auth_add_menu');
+add_action('wp_authenticate', 'ext_db_auth_check_login', 1, 2 );
+add_action('lost_password', 'disable_function');
+add_action('user_register', 'disable_function');
+add_action('register_form', 'disable_function_register');
+add_action('retrieve_password', 'disable_function');
+add_action('password_reset', 'disable_function');
+add_action('profile_personal_options','ext_db_warning');
+add_filter('login_errors','ext_db_errors');
+add_filter('show_password_fields','ext_db_show_password_fields');
+add_filter('login_message','ext_db_auth_warning');
+
+register_activation_hook( __FILE__, 'ext_db_auth_activate' );
diff --git a/mods/wordpress/wp_plugin/external-database-authentication/readme.txt b/mods/wordpress/wp_plugin/external-database-authentication/readme.txt
new file mode 100644 (file)
index 0000000..83ebefd
--- /dev/null
@@ -0,0 +1,70 @@
+=== Plugin Name ===\r
+Contributors: charlener\r
+Donate link: none\r
+Tags: authentication, login, database, MSSQL, MySQL, PostgreSQL\r
+Requires at least: 2.7\r
+Tested up to: 2.9\r
+Stable tag: 3.15\r
+\r
+A plugin that allows the use of an external database (MySQL, PostgreSQL, or MSSQL) for authentication into wordpress.  Supports various password hashing methods and user role checks from the external database.\r
+\r
+== Description ==\r
+A plugin that allows the use of an external MySQL, PostgreSQL, or MSSQL database for authentication into wordpress.  It requires you know the encryption method for the passwords stored in the external database and allows you to use MD5, SHA1, plaintext, or enter the hash/salt method yourself.  It disables password reset/retrieval and account creation within the wordpress system on the user-end, and it doesn't allow updating from the wordpress end back into the external authentication source. \r
+\r
+In addition to authentication the plugin allows you to:\r
+1. Choose additional fields, such as first name/last name and website, to be imported into the wordpress user system.\r
+1. Enter a custom message for users concerning logins. \r
+1. Do user role checks from the external database: you can set the plugin to check from a specific role field and compare to a value to allow login to wordpress.  \r
+\r
+PostgreSQL or MSSQL database authentication requires MDB2 PEAR database abstraction package and relevant database drivers. MySQL continues to use the built-in PHP functions.\r
+\r
+== Installation ==\r
+\r
+1. Prepare your WP admin account on your external database: make a login with username 'admin' and password hashed the way accounts are handled on that database.\r
+1. If using PostgreSQL or MSSQL, install the MDB2 PEAR database abstraction package and relevant database drivers and confirm its include path.\r
+1. Change "New User Default Role" in Settings->General, if desired, to whatever level of control you wish externally authenticated users to have.\r
+1. Upload `ext_db_auth.php` to the `/wp-content/plugins/` directory\r
+1. Activate the plugin through the 'Plugins' menu in WordPress\r
+1. Enter your external database settings in Settings->External DB settings\r
+\r
+\r
+== Frequently Asked Questions ==\r
+\r
+= My admin account for WP doesn't work anymore! =\r
+\r
+We're authenticating externally, right?  Take that admin account you initially created in your WP setup and make sure it's in your external database.  Once it's in there you'll be able to log in as admin with no problems.  If you can't do this, delete the plugin and it'll restore access using your WP admin account.\r
+\r
+= Can I still create accounts within WordPress? =\r
+\r
+You could, but they don't work properly as it's not checking against the WP database, just the external then making sure the WP user info is the same as what's currently on the external database.\r
+\r
+= Can I update user information within WordPress? =\r
+\r
+Nope.\r
+\r
+= My external database's passwords are hashed with a salt/datestamp/phases of the moon/etc =\r
+\r
+Choose "Other" as your encoding method, then enter the method you use in the "Other" textbox as PHP code. If it involves more than the username and password, though, you may need to modify the plugin source code.\r
+\r
+= I'm locked out! =\r
+\r
+Delete or rename the plugin; if it's a DB connection-related error most likely you have the wrong connection, etc. information for the external database.\r
+\r
+== Screenshots ==\r
+\r
+1. Plugin config screen\r
+2. Example login warning message upon access to wp-login.php\r
+3. Example "Lost my password" retrieval attempt\r
+\r
+== Changelog ==\r
+\r
+= 3.15 =\r
+* Disables password reset on user profile screen and has warning concerning updating profile within Wordpress\r
+* Changes to config screen form for improved usability.\r
+* Made lost your password and register error messages less fugly.\r
+* Updated readme.txt\r
+\r
+= 3.12 =\r
+* Now correctly imports unicode text into user profile fields\r
+* Checked with 2.8x WP, 2.8x WPMU, and 2.9 WP\r
+* Added in line as noted in forum post http://wordpress.org/support/topic/277235?replies=4
\ No newline at end of file