Pastoid

authorurls.plugin.php

The page you are looking at now is at this URL: http://pastoid.com/by5

This paste was last updated on January 13, 2010 at 4:24 pm.

Pasted Coderaw

<?php
 
class AuthorUrls extends Plugin
{
	public function info() 
	{
		return array(
			'name' => 'Author URLs',
			'version' => '1.0',
			'url' =>  'http://habariproject.org/',
			'author' => 'The Habari Community',
			'authorurl' => 'http://habariproject.org/',
			'license' => 'Apache License 2.0',
			'description' => 'Create additional URLs for author-specific searches and content.',
		);
	}
 
 
	public function action_update_check()
	{
		Update::add( 'AuthorURLs', 'd16fb23f-acf4-413c-a0f8-5ba55c4b3775',$this->info->version );
	}
 
	/**
	 * Add an author rewrite rule
	 * @param Array $rules Current rewrite rules
	 **/
	public function filter_default_rewrite_rules( $rules ) {
		$rule = array( 	'name' => 'display_entries_by_author', 
				'parse_regex' => '%^author/(?P<author>[^/]*)(?:/page/(?P<page>\d+))?/?$%i',
				'build_str' => 'author/{$author}(/page/{$page})', 
				'handler' => 'UserThemeHandler', 
				'action' => 'display_entries_by_author', 
				'priority' => 5, 
				'description' => 'Return posts matching specified author.', 
		);
 
		$rules[] = $rule;	
		return $rules;
	}
 
	/**
	 * function filter_template_where_filters
	 * Limit the Posts::get call to authors 
	 **/
	public function filter_template_where_filters( $filters ) {
		$vars = Controller::get_handler_vars();
		if( isset( $vars['author'] ) ) {
			$filters['user_id']= User::get( $vars['author'] )->id;
		}
		return $filters;
	}
 
 
	/**
	 * function filter_theme_act_display_entries_by_author
	 * Helper function: Display the posts for an author. Probably should be more generic eventually.
	 */
	public function filter_theme_act_display_entries_by_author( $handled, $theme ) {
		$paramarray = array();
		$vars = Controller::get_handler_vars();
		$author = User::get( $vars['author'] )->id;
 
		if ( isset( $author ) ) {
			$paramarray['fallback'][] = 'author.{$author}';
		}
 
		$paramarray['fallback'][] = 'author';
		$paramarray['fallback'][] = 'multiple';
		$paramarray['fallback'][] = 'home';
 
		$default_filters = array(
 			'content_type' => Post::type( 'entry' ),
		);
 
		$paramarray[ 'user_filters' ] = $default_filters;
 
		$theme->act_display( $paramarray );
		return true;
	}
 
}
 
?>

Toggle wordwrap

Referring DomainHits
Unknown Referer 127
pastoid.com 12
www.google.com 2
drunkenmonkey.org 1
Is this paste spam?
<Hide