-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added blogusers plugin to timestreams to supprot API access to only d…
…ata that a user owns or blog that they belong to.
- Loading branch information
Jesse Blum
committed
Dec 10, 2012
1 parent
36eae9f
commit 7c6560e
Showing
9 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Loads admin functionality | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
// Exit if accessed directly | ||
if ( !defined( 'ABSPATH' ) ) exit; | ||
|
||
// Utilites directory | ||
if ( !defined( 'HN_BU_ADMIN_DIR' ) ) | ||
define( 'HN_BU_ADMIN_DIR', HN_BU_PLUGIN_DIR . '/admin' ); | ||
|
||
// Require utility files | ||
require_once( HN_BU_ADMIN_DIR . '/hn_bu_interface.php' ); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Functions to provide admin functionality | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
add_action('admin_menu', 'hn_bu_add_admin_menus'); | ||
require_once( HN_TS_ADMIN_DIR . '/settings.php' ); | ||
|
||
/** | ||
* Blogusers Admin menu structure | ||
*/ | ||
function hn_bu_add_admin_menus(){ | ||
global $hn_bu_admin_timestreams; | ||
$hn_bu_admin_timestreams = add_menu_page('Blogusers', __('Blogusers',HN_TS_NAME), | ||
'administrator', __FILE__, 'hn_bu_main_admin_page'); | ||
} | ||
|
||
/** | ||
* Displays top level timestreams admin page | ||
*/ | ||
function hn_bu_main_admin_page(){ | ||
?> | ||
<div class="wrap"> | ||
<div id="icon-index" class="icon32"></div> | ||
<h2 style="padding-bottom: 1em;"><?php _e('Blogusers',HN_TS_NAME); ?></h2> | ||
<?php | ||
hn_db_showBlogusers(); | ||
?> | ||
</div> | ||
<?php | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
/* | ||
Plugin Name: Blog users | ||
Plugin URI: N/A | ||
Description: Shows a list of blogs that users belong to | ||
Version: 0.1.0 | ||
Author: Horizon Digital Economy Research Institute Jesse Blum (JMB) & Martin Flintham (MDF) | ||
Author URI: http://www.horizon.ac.uk | ||
License: AGPLv3 | ||
*/ | ||
|
||
/* Copyright (C) 2012 Horizon Digital Economy Research Institute, Jesse Blum (JMB) & Martin Flintham (MDF) | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as | ||
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* Sets up common variables and required files | ||
*/ | ||
function hn_bu_setup(){ | ||
// Define the Timestreams version | ||
if ( !defined( 'HN_BU_VERSION' ) ) | ||
define( 'HN_BU_VERSION', '0.1' ); | ||
|
||
// Define the database version | ||
if ( !defined( 'HN_BU_DB_VERSION' ) ) | ||
define( 'HN_BU_DB_VERSION', 0.1 ); | ||
|
||
// Define the plugin name | ||
if ( !defined( 'HN_BU_NAME' ) ) | ||
define( 'HN_BU_NAME', 'Blogusers' ); | ||
|
||
// Define the Timestreams blog id -- idea courtesy of Buddypress | ||
if ( !defined( 'HN_BU_ROOT_BLOG' ) ) { | ||
if( !is_multisite() ) { | ||
$_id = 1; | ||
}else if ( !defined( 'HN_BU_ENABLE_MULTIBLOG' ) ) { | ||
$current_site = get_current_site(); | ||
$_id = $current_site->blog_id; | ||
} else { | ||
$_id = get_current_blog_id(); | ||
} | ||
define( 'HN_BU_ROOT_BLOG', $_id ); | ||
} | ||
|
||
// Path and URL | ||
if ( !defined( 'HN_BU_PLUGIN_DIR' ) ) | ||
define( 'HN_BU_PLUGIN_DIR', WP_PLUGIN_DIR . '/timestreams' ); | ||
|
||
if ( !defined( 'HN_BU_PLUGIN_URL' ) ) | ||
define( 'HN_BU_PLUGIN_URL', plugins_url( 'timestreams' ) ); | ||
|
||
hn_bu_blogusers_checkVersion(3); | ||
|
||
//load_plugin_textdomain('blogusers',false,'blogusers/languages'); | ||
|
||
require_once( HN_BU_PLUGIN_DIR . '/utilities/hn_bu_utilitiesloader.php' ); | ||
require_once( HN_BU_PLUGIN_DIR . '/controllers/hn_bu_controllers-loader.php' ); | ||
require_once( HN_BU_PLUGIN_DIR . '/views/hn_bu_views-loader.php' ); | ||
require_once( HN_BU_PLUGIN_DIR . '/admin/hn_bu_admin-loader.php' ); | ||
|
||
// Hook into the dashboard action | ||
register_activation_hook(__FILE__, 'hn_bu_blogusers_activate'); | ||
register_deactivation_hook(__FILE__, 'hn_bu_blogusers_deactivate'); | ||
} | ||
|
||
function hn_bu_blogusers_init() { | ||
$plugin_path = dirname( plugin_basename( __FILE__ ) ) ; | ||
load_plugin_textdomain(HN_BU_NAME, false, $plugin_path); | ||
} | ||
add_action('init', 'hn_bu_blogusers_init'); | ||
|
||
/** | ||
* Plugin activation. This creates the initial multisite tables. | ||
*/ | ||
function hn_bu_blogusers_activate() { | ||
// Ensure that ABSPATH was defined | ||
if ( !defined( 'ABSPATH' ) ) exit; | ||
|
||
$hn_bu_db = new HN_BU_Database(); | ||
$hn_bu_db->hn_bu_createTables(); | ||
|
||
} | ||
|
||
/** | ||
* Plugin deactivation. Currently this does nothing, | ||
* but in the future should clean up the plugin database tables and files. | ||
*/ | ||
function hn_bu_blogusers_deactivate() { | ||
//To do: remove database tables | ||
} | ||
|
||
/** | ||
* Exits the plugin if the WP version is lower than $minver | ||
* @param $minver is the minimum version of Wordpress supported | ||
*/ | ||
function hn_bu_blogusers_checkVersion($minver){ | ||
global $wp_version; | ||
$exit_msg="HN_BU_NAME requires Wordpress version ".$wp_version.' or newer.'; | ||
if(version_compare($wp_version, $minver,"<")){ | ||
exit($exit_msg); | ||
} | ||
} | ||
|
||
hn_bu_setup(); | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* Loads the controllers | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
// Exit if accessed directly | ||
if ( !defined( 'ABSPATH' ) ) exit; | ||
|
||
// Utilites directory | ||
if ( !defined( 'HN_BU_CONTROLLERS_DIR' ) ) | ||
define( 'HN_BU_CONTROLLERS_DIR', HN_BU_PLUGIN_DIR . '/controllers' ); | ||
|
||
// Require utility files | ||
require_once( HN_BU_CONTROLLERS_DIR . '/hn_bu_users_ctrl.php' ); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Functions to control blog users | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
/** | ||
* ... | ||
*/ | ||
/*function hn_ts_generateKeys(){ | ||
?> | ||
<div id="ts_ds_form"> | ||
<h3><?php _e('API Key Generation'); ?></h3> | ||
<form id="apikeyform" method="post" action=""> | ||
<input type="submit" name='hn_ts_new_api_key' class="button-primary" value="<?php _e('Create New API Keys',HN_TS_NAME) ?>" /> | ||
</form> | ||
</div> | ||
<?php | ||
if(isset($_POST['hn_ts_new_api_key'])) { | ||
$db = new Hn_TS_Database(); | ||
$db->hn_ts_addNewAPIKeys(); | ||
} | ||
echo '<hr />'; | ||
}*/ | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* Class to interact with the wp_ts database tables | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); // provides dbDelta | ||
require_once(ABSPATH . WPINC . '/class-IXR.php'); | ||
require_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); | ||
|
||
/** | ||
* Controls calls to the database for timestreams | ||
* @author pszjmb | ||
* | ||
*/ | ||
class HN_BU_Database { | ||
private $wpserver; | ||
protected $missingcontainername; | ||
protected $missingParameters; | ||
|
||
function HN_BU_Database(){ | ||
$this->wpserver = new wp_xmlrpc_server(); | ||
$this->missingcontainername = new IXR_Error(403, __('Missing container name parameter.',HN_TS_NAME));//"Missing container name parameter."; | ||
$this->missingParameters= new IXR_Error(403, __('Incorrect number of parameters.',HN_TS_NAME)); | ||
} | ||
|
||
/** | ||
* Creates the initial timestreams db tables. This is expected only to | ||
* run at plugin install. | ||
*/ | ||
function hn_bu_createTables(){ | ||
global $wpdb; | ||
$sql = 'CREATE TABLE IF NOT EXISTS '.$wpdb->prefix.'bu_blogusers ( | ||
user_id bigint(20) unsigned NOT NULL, | ||
site_id bigint(20) unsigned NOT NULL, | ||
blog_id bigint(20) unsigned NOT NULL, | ||
PRIMARY KEY (user_id,blog_id,site_id) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;'; | ||
$wpdb->query($sql); | ||
} | ||
|
||
/** | ||
* Returns db rows with all the siteid and blog ids | ||
*/ | ||
function hn_bu_getBloglist(){ | ||
global $wpdb; | ||
return $wpdb->get_results( $wpdb->prepare( | ||
"SELECT site_id, blog_id FROM wp_blogs ORDER BY site_id ASC, blog_id ASC;" ) ); | ||
} | ||
|
||
/** | ||
* Returns db rows with all users | ||
*/ | ||
function hn_bu_getUserlist(){ | ||
global $wpdb; | ||
return $wpdb->get_results( $wpdb->prepare( | ||
"SELECT ID FROM wp_users;" ) ); | ||
} | ||
|
||
/** | ||
* Adds items from the given array to a truncated version of bu_blogusers | ||
*/ | ||
function hn_bu_setUserBloglist($userblogarray){ | ||
global $wpdb; | ||
//$wpdb->query( $wpdb->prepare( "TRUNCATE TABLE wp_bu_blogusers;" ) ); | ||
foreach ($userblogarray AS $user_blog) { | ||
$wpdb->insert( | ||
'wp_bu_blogusers', | ||
array( | ||
'user_id' => $user_blog[0], | ||
'site_id' => $user_blog[1], | ||
'blog_id' => $user_blog[2] | ||
) | ||
); | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* Loads utility files | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
// Exit if accessed directly | ||
if ( !defined( 'ABSPATH' ) ) exit; | ||
|
||
// Utilites directory | ||
if ( !defined( 'HN_BU_UTILITES_DIR' ) ) | ||
define( 'HN_BU_UTILITES_DIR', HN_BU_PLUGIN_DIR . '/utilities' ); | ||
|
||
// Require utility files | ||
require_once( HN_BU_UTILITES_DIR . '/hn_bu_db.php' ); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Functions to display blogs and users | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
/** | ||
* Displays blog users information in a table. | ||
* To do: Complete pagination functionality. | ||
* To do: Complete user sort functionality. | ||
*/ | ||
function hn_db_showBlogusers(){ | ||
?> | ||
<h3>Users and Blogs</h3> | ||
<table class="widefat"> | ||
<thead> | ||
<tr> | ||
<th>User id</th> | ||
<th>Site id</th> | ||
<th>Blog id</th> | ||
</tr> | ||
</thead> | ||
<tfoot> | ||
<tr> | ||
<th>User id</th> | ||
<th>Site id</th> | ||
<th>Blog id</th> | ||
</tr> | ||
</tfoot> | ||
<tbody> | ||
<?php | ||
$hn_bu_db = new HN_BU_Database(); | ||
$user_list = $hn_bu_db->hn_bu_getUserlist(); | ||
$userblogarray = array(); | ||
$counter=0; | ||
foreach ($user_list AS $user) { | ||
$user_blogs = get_blogs_of_user( $user->ID ); | ||
foreach ($user_blogs AS $user_blog) { | ||
echo "<tr><td>$user->ID</td> | ||
<td>$user_blog->site_id</td> | ||
<td>$user_blog->userblog_id</td></tr>"; | ||
$userblogarray[$counter]=array($user->ID, $user_blog->site_id, $user_blog->userblog_id); | ||
$counter+=1; | ||
$hn_bu_db->hn_bu_setUserBloglist($userblogarray); | ||
} | ||
} | ||
?> | ||
</tbody></table> | ||
<?php | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** | ||
* Loads view files. Views are output representations of data. | ||
* Author: Jesse Blum (JMB) | ||
* Date: 2012 | ||
*/ | ||
|
||
// Exit if accessed directly | ||
if ( !defined( 'ABSPATH' ) ) exit; | ||
|
||
// Utilites directory | ||
if ( !defined( 'HN_BU_VIEWS_DIR' ) ) | ||
define( 'HN_BU_VIEWS_DIR', HN_BU_PLUGIN_DIR . '/views' ); | ||
|
||
// Require utility files | ||
require_once( HN_BU_VIEWS_DIR . '/hn_bu_blogusers_view.php' ); | ||
|
||
?> |