Pastoid

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

This paste was last updated on August 13, 2009 at 9:04 pm.

categories.plugin.phpraw

<?php
 
/**
 * 
 *
 * @version $Id$
 * @copyright 2009
 */
 
/** 
 * 
 *
 */
class Categories extends Plugin
{
/*
	function action_plugin_activation($file){
		if ( Plugins::id_from_file( $file ) == $this->plugin_id ) {
			$v = new Vocabulary(array(
				'name' => 'Categories',
				'description' => 'A basic hierarchical category system to associate to posts.',
				'feature_mask' => Vocabulary::feature_mask(true, false, true, false),
			));
			$v->insert();
		}
	}
 
	function action_plugin_deactivation($file){
		if ( Plugins::id_from_file( $file ) == $this->plugin_id ) {
			$v = Vocabulary::get('Categories');
			$v->delete();
		}		
	}
 
	public function help()
	{
		return <<< HELP
<p>This is help.  It is inadequate.</p>
HELP;
	}	
	*/
 
	public function filter_plugin_config( $actions, $plugin_id )
	{
		if ( $plugin_id == $this->plugin_id() ) {
			$actions['configure']= _t( 'Add Vocabularies' );
			$vs = Vocabulary::get_all();
			foreach($vs as $vocab) {
				if($vocab->category) {
					$actions['vocab_' . $vocab->id] = _t('Configure %s', array($vocab->name));
				}
			}
		}
		return $actions;
	}
 
	public function action_plugin_ui( $plugin_id, $action )
	{
		if ( $plugin_id == $this->plugin_id() ) {
			if($action == 'configure') {
				$form = new FormUI('vocab');
				$form->append('text', 'new_vocab', 'null:null', _t('New Vocabulary Name'));
				$form->append('submit', 'submit', _t('Add Vocabulary'));
				$form->on_success(array($this, '_add_vocab'));
				$form->out();
			}
			if(preg_match('%vocab_(\d+)%', $action, $matches)) {
				$form = new FormUI('vocab');
 
				$vocab = Vocabulary::get_by_id(intval($matches[1]));
 
				$tree = $vocab->get_tree();
				$options = array();
				$depth = 0;
				$rmin = $tree[0]->mptt_right;
				$rlast = $tree[0]->mptt_right;
				foreach ($tree as $term){
					if($term->mptt_left < $rlast) {
						$depth++;
					}
					if($term->mptt_left > $rlast) {
						$depth -= ($term->mptt_left - $rlast - 1);
					}
					$options[$term->id] = str_repeat('-', $depth) . ' ' . $term->term_display;
					$rlast = $term->mptt_right;
				}
				$select = $form->append('select', 'parent', 'null:null', 'Parent Term', $options);
 
				$form->append('hidden', 'vocab_id', 'null:null', $vocab->id);
				$form->append('text', 'new_term', 'null:null', _t('New Term'));
				$form->append('submit', 'submit', _t('Add Term'));
				$form->on_success(array($this, '_add_term'));
				$form->out();
			}
		}
	}
 
	public function _add_vocab($form)
	{
		$v = new Vocabulary(array(
			'name' => $form->new_vocab->value,
			'description' => 'A basic hierarchical category system to associate to posts.',
			'features' => array('hierarchical', 'multiple', 'category'),
		));
		$v->insert();
		Session::notice(_t('Added vocabulary "%s".', array($form->new_vocab->value)));
		Utils::redirect();
		return false;
	}
 
	public function action_form_publish($form, $post, $context)
	{
		$tab = $form->publish_controls->append('fieldset', 'categories', _t('Categories'));
		$vs = Vocabulary::get_all();
		foreach($vs as $key => $vocab) {
			if($vocab->category) {
				$tree = $vocab->get_tree();
				$options = array();
				foreach ($tree as $term){
					$options[$term->id] = $term->term_display;
				}
				$select = $tab->append('select', 'category_' . Utils::slugify($vocab->id), 'null:null', $vocab->name, $options, 'tabcontrol_select');
			}
		}
	}
 
	public function _add_term($form)
	{
		$v = Vocabulary::get_by_id($form->vocab_id->value);
 
		$v->add_term($form->new_term, $v->get_term());
	}
}
 
?>

Toggle wordwrap

categories.plugin.xmlraw

<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="plugin">
	<name>Categories</name>
	<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>
 
	<author url="http://asymptomatic.net/">Owen Winkler</author>
 
	<version>0.1</version>
	<url>http://redalt.com/habari</url>
	<description><![CDATA[Allows assignment of one or more hierarchical categories to a post.]]></description>
 
	<copyright>2009</copyright>
 
	<provides>
		<feature>categories</feature>
	</provides>
 
	<help>
		<value><![CDATA[This is useless help]]></value>
	</help>
 
</pluggable>

Toggle wordwrap

Referring DomainHits
Unknown Referer 185
pastoid.com 9
drunkenmonkey.org 1
Is this paste spam?
<Hide