-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathyst_plugin_tools.php
164 lines (143 loc) · 5.15 KB
/
yst_plugin_tools.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
/**
* Backend Class for use in all Yoast plugins
* Version 0.2
*/
if (!class_exists('Yoast_Plugin_Admin')) {
class Yoast_Plugin_Admin {
var $hook = '';
var $filename = '';
var $longname = '';
var $shortname = '';
var $ozhicon = '';
var $optionname = '';
var $homepage = '';
var $accesslvl = 'manage_options';
function Yoast_Plugin_Admin() {
add_action( 'admin_menu', array(&$this, 'register_settings_page') );
add_filter( 'plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
add_filter( 'ozh_adminmenu_icon', array(&$this, 'add_ozh_adminmenu_icon' ) );
add_action('admin_print_scripts', array(&$this,'config_page_scripts'));
add_action('admin_print_styles', array(&$this,'config_page_styles'));
}
function add_ozh_adminmenu_icon( $hook ) {
if ($hook == $this->hook)
return WP_CONTENT_URL . '/plugins/' . plugin_basename(dirname($filename)). '/'.$this->ozhicon;
return $hook;
}
function config_page_styles() {
if (isset($_GET['page']) && $_GET['page'] == $this->hook) {
wp_enqueue_style('dashboard');
wp_enqueue_style('thickbox');
wp_enqueue_style('global');
wp_enqueue_style('wp-admin');
wp_enqueue_style('ov-admin-css', WP_CONTENT_URL . '/plugins/' . plugin_basename(dirname(__FILE__)). '/yst_plugin_tools.css');
}
}
function register_settings_page() {
add_options_page($this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
}
function plugin_options_url() {
return admin_url( 'options-general.php?page='.$this->hook );
}
/**
* Add a link to the settings page to the plugins list
*/
function add_action_link( $links, $file ) {
static $this_plugin;
if( empty($this_plugin) ) $this_plugin = $this->filename;
if ( $file == $this_plugin ) {
$settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
array_unshift( $links, $settings_link );
}
return $links;
}
function config_page() {
}
function config_page_scripts() {
if (isset($_GET['page']) && $_GET['page'] == $this->hook) {
wp_enqueue_script('postbox');
wp_enqueue_script('dashboard');
wp_enqueue_script('thickbox');
wp_enqueue_script('media-upload');
}
}
/**
* Create a Checkbox input field
*/
function checkbox($id, $label) {
$options = get_option($this->optionname);
$val = ( isset( $options[$id] ) ) ? $options[$id] : false;
return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked( $val, true, false).'/> <label for="'.$id.'">'.$label.'</label><br/>';
}
/**
* Create a Text input field
*/
function textinput($id, $label) {
$options = get_option($this->optionname);
$val = isset( $options[$id] ) ? htmlentities( stripslashes( $options[$id] ) ) : '';
return '<label for="'.$id.'">'.$label.':</label><br/><input size="45" type="text" id="'.$id.'" name="'.$id.'" value="'.$val.'"/><br/><br/>';
}
/**
* Create a potbox widget
*/
function postbox($id, $title, $content) {
?>
<div id="<?php echo $id; ?>" class="postbox">
<div class="handlediv" title="Click to toggle"><br /></div>
<h3 class="hndle"><span><?php echo $title; ?></span></h3>
<div class="inside">
<?php echo $content; ?>
</div>
</div>
<?php
}
/**
* Create a form table from an array of rows
*/
function form_table($rows) {
$content = '<table class="form-table">';
foreach ($rows as $row) {
$content .= '<tr><th valign="top" scrope="row">';
if (isset($row['id']) && $row['id'] != '')
$content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
else
$content .= $row['label'];
if (isset($row['desc']) && $row['desc'] != '')
$content .= '<br/><small>'.$row['desc'].'</small>';
$content .= '</th><td valign="top">';
$content .= $row['content'];
$content .= '</td></tr>';
}
$content .= '</table>';
return $content;
}
/**
* Create a "plugin like" box.
*/
function plugin_like() {
$content = '<p>'.__('Why not do any or all of the following:','ystplugin').'</p>';
$content .= '<ul>';
$content .= '<li><a href="'.$this->homepage.'">'.__('Link to it so other folks can find out about it.','ystplugin').'</a></li>';
$content .= '<li><a href="http://wordpress.org/extend/plugins/'.$this->hook.'/">'.__('Give it a good rating on WordPress.org.','ystplugin').'</a></li>';
$content .= '</ul>';
$this->postbox($this->hook.'like', 'Like this plugin?', $content);
}
/**
* Info box with link to the support forums.
*/
function plugin_support() {
$content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','ystplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'ystplugin').'</a>.</p>';
$this->postbox($this->hook.'support', 'Need support?', $content);
}
function text_limit( $text, $limit, $finish = ' […]') {
if( strlen( $text ) > $limit ) {
$text = substr( $text, 0, $limit );
$text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
$text .= $finish;
}
return $text;
}
}
}
?>