Created
August 6, 2012 04:23
-
-
Save ringmaster/3270381 to your computer and use it in GitHub Desktop.
habari test plugin
This file contains hidden or 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
<?php | |
class Test extends Plugin | |
{ | |
public function action_init() | |
{ | |
// Not sure what the heck this was for. | |
$this->add_template('block.pbi', dirname( __FILE__ ) . '/block.pbi.php' ); | |
$this->add_rule( | |
'"testplugin"', | |
'foo', | |
array($this, 'route_foo') | |
); | |
DB::register_table('entries'); | |
} | |
/* public function action_plugin_act_foo($handler) | |
{ | |
Utils::debug($handler); | |
exit(); | |
}*/ | |
public function route_foo($theme, $handler) | |
{ | |
$theme->posts = Posts::get('home'); | |
$theme->display('home'); | |
} | |
/** | |
* Simple plugin configuration | |
* @return FormUI The configuration form | |
**/ | |
public function configure() | |
{ | |
/* | |
$form = new FormUI( 'test' ); | |
$terms = Vocabulary::get('categories')->get_tree(); | |
$options = array(); | |
foreach($terms as $term) { | |
$options[$term->id] = $term->term_display; | |
} | |
$form->append( 'tree', 'tree', $terms, 'test'); | |
//$form->append( 'tree', 'tree2', 'null:null', 'test', $options); | |
$form->append( 'submit', 'save', _t( 'Save' ) ); | |
return $form; | |
*/ | |
$form = new FormUI( 'test' ); | |
//$form->append( new FormControlText('name', 'soup__name', 'Soup Name')); | |
$form->append( new FormControlText('name', 'user:testing_value', 'Testing Value')); | |
$form->append( new FormControlSelect('type', 'soup__type', 'Soup Type', array('stock', 'cream'))); | |
$form->append( new FormControlSubmit('save', _t( 'Save' ))); | |
/* $dom = new DOMDocument('1.0'); | |
$dom->preserveWhiteSpace = false; | |
$dom->formatOutput = true; | |
$dom->loadXML($form->get_xml()->asXML()); | |
Utils::debug($dom->saveXML());*/ | |
return $form; | |
//DB::query('delete from {terms} where id in (14,17)'); | |
/* | |
if($_SERVER['REQUEST_METHOD'] == 'POST') { | |
Utils::debug($_POST->get_array_copy_raw()); | |
} | |
echo <<< FORM | |
<form method="post"> | |
<input type="text" name="properties[element1][type]" value="textarea"> | |
<input type="text" name="properties[element2][type]" value="select"> | |
<input type="submit" value="Submit"> | |
</form> | |
FORM; | |
*/ | |
} | |
function filter_posts_search_to_get ( $arguments, $flag, $value, $match, $search_string) | |
{ | |
if($flag == 'fruit') { | |
$arguments['info'] = array('fruit'=>$value); | |
} | |
return $arguments; | |
} | |
function filter_default_rewrite_rules($rules) | |
{ | |
$rules[] = array( | |
'name' => 'display_column', | |
'parse_regex' => '%^column/(?P<slug>[^/]*)(?:/page/(?P<page>\d+))?/?$%i', | |
'build_str' => 'column/{$slug}(/page/{$page})', | |
'handler' => 'PluginHandler', | |
'action' => 'display_column', | |
'priority' => 4, | |
'description' => 'Return articles matching specified column.', | |
); | |
return $rules; | |
} | |
/* function filter_rewrite_rules($rules) | |
{ | |
// $rules[] = new RewriteRule( array( | |
// 'name' => 'fruit', | |
// 'parse_regex' => '%fruit/(?P<fruit>.+)/?$%i', | |
// 'build_str' => 'fruit/{$fruit}', | |
// 'handler' => 'PluginHandler', | |
// 'action' => 'fruit', | |
// 'priority' => 7, | |
// 'is_active' => 1, | |
// 'description' => 'Displays the fruit page', | |
// )); | |
$rules[] = RewriteRule::create_url_rule('"fruit"/fruit_name', 'PluginHandler', 'fruit'); | |
return $rules; | |
}*/ | |
/** | |
* Add needed rewrite rules | |
*/ | |
public function filter_rewrite_rules($rules) | |
{ | |
// foreach( $rules as $rule ) | |
// { | |
// if( $rule->name == 'display_post' ) | |
// { | |
// $rule->parse_regex= '%fund/(?P<slug>[^/]+)(?:/page/(?P<page>\d+))?/?$%i'; | |
// $rule->build_str= 'fund/{$slug}(/page/{$page})'; | |
// } | |
// } | |
// | |
// $rules[] = new RewriteRule( array( | |
// 'name' => 'display_fund_trades', | |
// 'parse_regex' => '%fund/(?P<slug>[^/]+)/trades(?:/page/(?P<page>\d+))?/?$%i', | |
// 'build_str' => 'fund/{$slug}/trades', | |
// 'handler' => 'FundHandler', | |
// 'action' => 'display_fund_trades', | |
// 'priority' => 7, | |
// 'is_active' => 1, | |
// 'description' => 'Show all trades for a fund', | |
// )); | |
$rules[] = new RewriteRule( array( | |
'name' => 'display_fund_holdings', | |
'parse_regex' => '%fund/(?P<slug>[^/]+)/holdings(?:/page/(?P<page>\d+))?/?$%i', | |
'build_str' => 'fund/{$slug}/holdings', | |
'handler' => 'PluginHandler', | |
'action' => 'display_fund_holdings', | |
'priority' => 7, | |
'is_active' => 1, | |
'description' => 'Show all holdings for a fund', | |
)); | |
return $rules; | |
} | |
public function action_plugin_act_display_fund_holdings($handler) | |
{ | |
echo 'got it'; | |
} | |
public function action_plugin_act_display_column($handler) | |
{ | |
Utils::debug( | |
Posts::get( array('content_type' => Post::type('section'), 'nolimit' => TRUE, 'status' => Post::status('published'), 'orderby' => 'title ASC', 'fetch_fn' => 'get_perms') ) | |
); | |
// Utils::debug($handler->handler_vars); | |
} | |
function action_plugin_act_fruit($handler) | |
{ | |
$handler->theme->act_display_entries(array('info'=>array('fruit'=>$handler->handler_vars['fruit_name']))); | |
} | |
function action_post_get_perm_where($perm_where, $paramarray) | |
{ | |
//$perm_where->add('(1=0)'); | |
} | |
function action_upgrade($oldversion) | |
{ | |
Session::notice('upgrade ' . $oldversion); | |
} | |
function action_theme_deactivated($themename) | |
{ | |
Session::notice(_t('test deactivated %s', array($themename))); | |
} | |
function action_theme_activated($themename) | |
{ | |
Session::notice(_t('test activated %s', array($themename))); | |
} | |
function action_theme_deactivated_any($themename, $theme) | |
{ | |
Session::notice(_t('test any deactivated %s', array($themename))); | |
} | |
function action_theme_activated_any($themename) | |
{ | |
Session::notice(_t('test any activated %s', array($themename))); | |
} | |
public function filter_block_list($block_list) | |
{ | |
$block_list['postsbyinfo'] = _t( 'Posts By Info'); | |
return $block_list; | |
} | |
public function action_block_content_postsbyinfo($block, $theme) | |
{ | |
/* $params = array(); | |
$params["content_type"] = Post::type('event'); | |
//$params["not:all:info"] = array("ankündigung" => "1"); | |
$params["status"] = Post::status('published'); | |
$params["nolimit"] = ""; | |
$params["has:info"] = "eventdate"; | |
$params["orderby"] = "cast(hipi1.value as unsigned) DESC"; | |
$params['fetch_fn'] = 'get_results'; | |
// Utils::debug(Posts::get(array_merge($params, array('fetch_fn'=>'get_query')))); | |
$events = Posts::get($params); | |
// Utils::debug($events); | |
$content = 'This is where the content should appear:'; | |
$content .= Posts::get(array_merge($params, array('fetch_fn'=>'get_query'))); | |
foreach($events as $event) { | |
$content .= $theme->content($event); | |
}*/ | |
$content = date('M j, Y H:i:s') . '<br>'; | |
$content .= '<a href="' . $block->_ajax_url . '" onclick="t=$(this);t.parents(\'.block\').load(t.attr(\'href\'));return false;">Reload</a>'; | |
$block->content = $content; | |
$block->_ajax = true; | |
} | |
public function filter_post_content_out($content, $post) | |
{ | |
if(strpos($content, '<!--postform-->') !== false) { | |
$p = $post; //new Post(); | |
$p->content_type = 'page'; | |
$form = $p->get_form('public'); | |
$form->on_success(array($this, 'success')); | |
//Utils::debug($form); | |
$content = preg_replace('#<!--postform-->#i', $form->out(), $content); | |
} | |
return $content; | |
} | |
public function success($form) | |
{ | |
//Utils::debug($form);die(); | |
Session::notice('Submitted form'); | |
} | |
public function filter_areas($areas, $scope) | |
{ | |
if($scope != 0) { | |
$areas['foo'] = 'FOO'; | |
} | |
return $areas; | |
} | |
public function filter_admin_groups_visible($groups) | |
{ | |
$groups = $groups->getArrayCopy(); | |
$hidden_groups = array( | |
'new test group', | |
//'family', | |
); | |
foreach($groups as $index => $group) { | |
if(in_array($group->name, $hidden_groups)) { | |
unset($groups[$index]); | |
} | |
} | |
return $groups; | |
} | |
public function filter_list_unit_tests($tests) | |
{ | |
$unit_tests = glob(dirname(__FILE__). '/units/test_*.php'); | |
$tests = array_merge($tests, $unit_tests); | |
return $tests; | |
} | |
function filter_post_get_6($out, $name, $post) | |
{ | |
if($name == 'myfield') { | |
if(isset($post->info->myfield)) { | |
$out = $post->info->myfield; | |
} | |
} | |
return $out; | |
} | |
function filter_shortcode_fields($fields, $post) | |
{ | |
$fields[] = 'myfield'; | |
return $fields; | |
} | |
function filter_shortcode_currentdate($content, $code, $attrs, $context) | |
{ | |
return HabariDateTime::date_create()->format(isset($attrs['format']) ? $attrs['format'] : 'M j, Y'); | |
} | |
function filter_shortcode_rev($content, $code, $attrs, $context) | |
{ | |
return strrev($context); | |
} | |
/* | |
public function filter_post_schema_map_entry($schema, $post) { | |
// Take all of the fields in this post that aren't stored in the posts table, | |
// and store them in the invoices table | |
$schema['entries'] = $schema['*']; | |
$schema['entries']['body'] = 'content'; | |
// Store the id of the post in the post_id field of the invoices table | |
$schema['entries']['post_id'] = '*id'; | |
return $schema; | |
} | |
public function filter_posts_get_paramarray($paramarray) { | |
$paramarray['post_join'] = array('{entries}'); | |
$e = isset($paramarray['default_fields']) ? $paramarray['default_fields'] : array(); | |
$e['{entries}.body'] = ''; | |
$paramarray['default_fields'] = $e; | |
return $paramarray; | |
}*/ | |
/* public function filter_post_default_fields($fields, $params) { | |
$fields['{entries}.body'] = ''; | |
return $fields; | |
}*/ | |
/* public function filter_posts_get_update_preset($preset_parameters, $presetname, $paramarray) { | |
switch($presetname) { | |
case 'home': | |
$notallinfo = isset($preset_parameters['not:all:info']) ? Utils::single_array($preset_parameters['not:all:info']) : array(); | |
$notallinfo['debate'] = 0; | |
$preset_parameters['not:all:info'] = $notallinfo; | |
break; | |
} | |
return $preset_parameters; | |
}*/ | |
} | |
?> |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8" ?> | |
<pluggable type="plugin"> | |
<name>Test Plugin</name> | |
<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license> | |
<author url="http://owenw.com/">Owen Winkler</author> | |
<version>0.17</version> | |
<url>http://owenw.com/</url> | |
<description xml:lang="en-us"><![CDATA[Test plugin for Habari.]]></description> | |
<description xml:lang="sv"><![CDATA[Bork bork bork de piggy guinea bork bork bork.]]></description> | |
<copyright>2010</copyright> | |
<guid>3e2e7dea-a180-4331-b21a-c8bc586de7fb</guid> | |
<help> | |
<value><![CDATA[ | |
<p>This plugin tests stuff.</p> | |
]]></value> | |
</help> | |
<help name="main"> | |
<value><![CDATA[ | |
<p>This is the main plugin help.</p> | |
]]></value> | |
</help> | |
<help name="secondary"> | |
<value><![CDATA[ | |
<p>This plugin doesn't do a very good job of testing anything.</p> | |
]]></value> | |
</help> | |
<!-- | |
<requires> | |
<feature url="http://wiki.habariproject.org/en/feature/menu">menu</feature> | |
</requires> | |
--> | |
<recommends> | |
<feature url="http://wiki.habariproject.org/en/feature/test_harness">test harness</feature> | |
</recommends> | |
<provides> | |
<feature url="http://wiki.habariproject.org/en/feature/sample">sample</feature> | |
</provides> | |
<conflicts> | |
<feature url="http://wiki.habariproject.org/en/feature/sample">sample</feature> | |
</conflicts> | |
</pluggable> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment