public
Description: custom plugins for the habari blogging platform
Homepage:
Clone URL: git://github.com/stan/habari-plugins.git
habari-plugins / colophon / colophon.plugin.php
100644 93 lines (84 sloc) 2.595 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/*
* Colophon Habari Plugin
* This plugin allows the blog owner to include an about/colophon somewhere on the blog
* without having to rely on a page or theme rewrite, since the about option got killed
*
* Example usage in PHP template:
*
* <?php if (Plugins::is_loaded('Colophon')) { ?>
* <h2><?php echo $colophon_title; ?></h2>
* <?php echo $colophon; ?>
* <?php } ?>
*
*/
 
class Colophon extends Plugin
{
const VERSION= '0.2';
 
/**
* Required plugin information
* @return array The array of information
*/
function info()
{
return array(
'name' => 'Colophon Plugin',
'version' => self::VERSION,
'url' => 'http://github.com/stan/habari-plugins/tree/master',
'author' => 'stanislas mazurek',
'authorurl' => 'http://stanbar.jp',
'licence' => 'Apache licence 2.0',
'description' => 'Adds an About / Colophon to your blog'
);
}
 
/**
* Add actions to the plugin page for this plugin
* @param array $actions An array of actions to apply to this plugin
* @param string $plugin_id The string with the plugin id, generated by the system
* @return array $actions Array of actions to atach to the specified $plugin_id
*/
public function filter_plugin_config($actions,$plugin_id)
{
if( $plugin_id == $this->plugin_id()) {
$actions[] = _t('Configure');
}
return $actions;
}
 
/**
* Method that responds to the user selecting an action on the plugin page
* @param string $plugin_id String containning the id of the plugin
* @param string $action The action string suplied via the filter_plugin_config hook
**/
public function action_plugin_ui( $plugin_id, $action )
{
if ( $plugin_id == $this->plugin_id() ) {
switch( $action ) {
case _t('Configure'):
$ui = new FormUI ( strtolower( get_class( $this ) ) );
$colophontitle = $ui->add('text','colophon_title',_t('Enter your Title:'));
$colophontext = $ui->add('textarea','colophon_text',_t('Enter your Text:'));
$ui->on_success( array( $this, 'updated_config' ) );
$ui->out();
break;
}
}
 
}
 
/**
* Assigns output code to the template variables
* @param Theme $theme The theme that will display the template
*/
function action_add_template_vars( $theme )
{
$theme->colophon = Format::autop(Options::get( 'colophon:colophon_text' ));
$theme->colophon_title = Options::get( 'colophon:colophon_title' );
}
 
/**
* Returns true if plugin config form values defined in action_plugin_ui whould be stored by habari
* @return bool True if options should be stored
*/
public function updated_config($ui)
{
return true;
}
 
}
?>