Skip to content

Commit

Permalink
Implemented widgets, fixed handling of namespaced internal links, bum…
Browse files Browse the repository at this point in the history
…ped version number
  • Loading branch information
mgerring committed Jan 18, 2011
1 parent 9a8255e commit 5a1c987
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 21 deletions.
24 changes: 24 additions & 0 deletions controllers/wiki_dashboard_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
class WikiDashboardWidget {
function WikiDashboardWidget() {
$this->WikiHelper = new WikiHelpers();
}

function dashboard_widget_function() {
global $wpdb;
$posts = $wpdb->get_results($wpdb->prepare("select * from $wpdb->posts where ID in (
select post_id from $wpdb->postmeta where
meta_key = 'wiki_page' and meta_value = 1)
or post_type in ('wiki') order by post_modified desc limit 5"));
include(WPWIKI_FILE_PATH.'/views/dashboard_widget.php');
}

function dashboard_widget_hook() {
wp_add_dashboard_widget(
'wpw_dashboard_widget',
'Recent contributions to Wiki',
array($this,'dashboard_widget_function')
);
}
}
?>
40 changes: 40 additions & 0 deletions controllers/wiki_user_contrib_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
class WikiUserContribWidget extends WP_Widget {

function WikiUserContribWidget() {
$widget_ops = array(
'classname' => 'widget_my_contributions',
'description' => __( "My Contributions widget for WordPress Wiki Plugin")
);
$this->WP_Widget('wiki_user_contrib', 'Wiki User Contributions', $widget_ops);
$this->WikiHelper = new WikiHelpers();
}

function widget($args, $instance) {
global $userdata;
get_currentuserinfo();
if ($userdata->ID == 0 || trim($userdata->ID == "")) return;
global $wpdb;
extract($args);
$title = apply_filters('widget_title', $instance['title']);
get_currentuserinfo();
$nos = ($instance['nos'] <= 0) ? 10: $instance['nos'];
$count = 0;
$posts = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_author = %d and post_status = 'publish' and post_type in ('post','page','wiki')", $userdata->ID));
include(WPWIKI_FILE_PATH.'/views/user_contrib_widget.php');
}

function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags(stripslashes($new_instance["title"]));
$instance['nos'] = strip_tags(stripslashes($new_instance["nos"]));
return $instance;
}

function form($instance) {
$title = esc_attr($instance['title']);
$nos = ($instance['nos'] <= 0) ? 10: esc_attr($instance['nos']);
include(WPWIKI_FILE_PATH.'/views/user_contrib_widget_form.php');
}
}
?>
10 changes: 4 additions & 6 deletions lib/WPW_WikiParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WPW_WikiParser extends WikiParser {
// 2011-01-02 arjen adjusted to deal with namespaces
function wiki_link($topic,$namespace='') {
global $wpdb;
$wiki = $wpdb->get_var('SELECT `p`.`id` FROM `' . $wpdb->posts . '` `p` WHERE `p`.`post_type` = "wiki" AND `p`.`post_name` = "' . preg_replace('/[ -]+/', '-', $topic) .'"');
$wiki = $wpdb->get_var('SELECT `p`.`id` FROM `' . $wpdb->posts . '` `p` WHERE `p`.`post_type` = "wiki" AND `p`.`post_name` = "' . strtolower(preg_replace('/[ -]+/', '-', $topic)) .'"');

if (!$wiki)
return 'new?redlink=1&title='.($namespace ? $namespace.':' : '').$topic;
Expand All @@ -16,7 +16,6 @@ function wiki_link($topic,$namespace='') {
// 2011-01-02 arjen adjusted to deal with namespaces
function handle_internallink($matches) {
global $wpdb;
//var_dump($matches);
$nolink = false;

$href = $matches[4];
Expand All @@ -30,22 +29,21 @@ function handle_internallink($matches) {
return $this->handle_image($href,$title,$options);
}

$href = preg_replace('/[^a-zA-Z0-9-\s]/', '', $href);
$href = trim(preg_replace('/[^a-zA-Z0-9-\s]/', '', $href));
$title = preg_replace('/\(.*?\)/','',$title);
$title = preg_replace('/^.*?\:/','',$title);
$wiki = $wpdb->get_var('SELECT `p`.`id` FROM `' . $wpdb->posts . '` `p` WHERE `p`.`post_type` = "wiki" AND `p`.`post_name` = "' . preg_replace('/[ -]+/', '-', $href) .'"');
$wiki = $wpdb->get_var('SELECT `p`.`id` FROM `' . $wpdb->posts . '` `p` WHERE `p`.`post_type` = "wiki" AND `p`.`post_name` = "' . strtolower(preg_replace('/[ -]+/', '-', $href)) .'"');

if(!$wiki)
$redlink = 'style="color:red"';
else
$redlink = false;

if ($this->reference_wiki) {
$href = $this->reference_wiki.$this->wiki_link($href,$namespace);
} else {
$nolink = true;
}

if ($nolink) return $title;

return sprintf(
Expand Down
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Wordpress Wiki ===
Contributors: Dan Milward, Allen Han, Matthew Gerring
Contributors: Dan Milward, Matthew Gerring, Brent Shepard, Arjen Lentz, and the WP-Wiki community
Donate link: http://www.instinct.co.nz/
Tags: wiki
Requires at least: 2.8
Tested up to: 3.0.1
Stable Tag: 0.8
Tested up to: 3.1
Stable Tag: 1.0

== Description ==

Expand Down
18 changes: 18 additions & 0 deletions views/dashboard_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="wpw-dashboard">
<ul>
<?php if (count($posts) > 0):
foreach ($posts as $post):
$name = $this->WikiHelper->get_author($post);
?>

<li>
<a href = "<?php echo get_permalink($post->ID)?>"><?php echo $post->post_title ?></a> (<?php echo $name; ?>) </li>

<?php endforeach; else: ?>

<li><?php _e("No contributions yet.") ?></li>

<?php endif; ?>

</ul>
</div>
22 changes: 22 additions & 0 deletions views/user_contrib_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
?>
<ul>
<?php foreach ($posts as $post):
if ($this->WikiHelper->is_wiki('check_no_post',$post->ID)) {
printf("<li><a href = '%s'>%s</a></li>", get_permalink($post->ID) ,$post->post_title);
$count++;
if ($count == $nos) {
break;
}
}
endforeach;

if ($count == 0):
?>
<li> <?php _e("You have made no contributions"); ?> </li>
<?php endif; ?>
</ul>
<?php echo $after_widget; ?>
10 changes: 10 additions & 0 deletions views/user_contrib_widget_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?><br />
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('nos'); ?>"><?php _e('Number of posts to show:'); ?>
<input name="<?php echo $this->get_field_name('nos'); ?>" id="<?php echo $this->get_field_id('nos'); ?>" class="widefat" type="text" size="3" maxlength="3" value="<?php echo $nos; ?>" />
</label>
</p>
25 changes: 13 additions & 12 deletions wp-wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Plugin Name:WordPress Wiki
Plugin URI: http://wordpress.org/extend/plugins/wordpress-wiki/
Description: Add Wiki functionality to your wordpress site.
Version: 0.9RC1
Author: Instinct Entertainment/Matthew Gerring
Version: 1.0
Author: Dan Milward/Matthew Gerring
Author URI: http://www.instinct.co.nz
*/

Expand All @@ -16,19 +16,19 @@ function __construct() {
function WP_Wiki() {
global $wp_version;

//include the admin page
//include('wpw-admin-menu.php');
//include the class up here so it doesn't get re-declared- fixes issue #4 on GitHub. Thanks Nexiom!
include('lib/WPW_WikiParser.php');

//include component controllers
include('model/wiki_post_type.php');
include('controllers/wiki_pages.php');
include('controllers/wiki_notifications.php');
include('controllers/wiki_feed.php');
include('controllers/wiki_admin.php');
include('controllers/wiki_dashboard_widget.php');
include('controllers/wiki_user_contrib_widget.php');
include('wiki_helpers.php');

//include Wiki Parser class here so it doesn't get re-declared- fixes issue #4 on GitHub. Thanks Nexiom!
include('lib/WPW_WikiParser.php');

/**
* Guess the wp-content and plugin urls/paths
*/
Expand All @@ -48,15 +48,12 @@ function WP_Wiki() {
//Enables Wiki Pages
$WikiPostType = new WikiPostType();

//Create classes for our components. This will be changed to allow
//Create classes for our components. This will be changed to allow filtering in a future release.
$WikiPageController = new WikiPageController();
$WikiNotifications = new WikiNotifications();
$WikiFeed = new WikiFeed();
$WikiAdmin = new WikiAdmin();

//This checks if we're working with a wiki page, rather than running two seperate checks for backwards compatibility

//NEW!
$WikiDashboardWidget = new WikiDashboardWidget();

//Version-specific actions and filters

Expand Down Expand Up @@ -106,6 +103,10 @@ function WP_Wiki() {
add_action('admin_menu', array($WikiAdmin,'register_options_page'));
add_action('save_post',array($WikiAdmin,'replace_current_with_pending'));
add_action('admin_menu', array($WikiAdmin,'add_custom_box'));

//Widgets
add_action('widgets_init', create_function('', 'return register_widget("WikiUserContribWidget");'));
add_action('wp_dashboard_setup', array($WikiDashboardWidget, 'dashboard_widget_hook') );
}
}
$WP_Wiki = new WP_Wiki();
Expand Down

0 comments on commit 5a1c987

Please sign in to comment.