Version Description
Be sure to deactivate Dynamic Widgets Plugin before installing the new version following steps 1 and 2 in the installation procedure. After the install you can re-activate the plugin.
Download this release
Release Info
Developer | qurl |
Plugin | Dynamic Widgets |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1.1 to 1.2
- dynamic-widgets.php +321 -30
- dynwid_admin.php +9 -117
- dynwid_admin_dump.php +0 -18
- dynwid_admin_edit.php +198 -74
- dynwid_admin_overview.php +98 -0
- dynwid_admin_save.php +66 -11
- dynwid_class.php +48 -25
- dynwid_class_php4.php +234 -0
- dynwid_worker.php +85 -33
- readme.txt +48 -30
- screenshot-2.jpg +0 -0
- screenshot-3.jpg +0 -0
dynamic-widgets.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Dynamic Widgets
|
4 |
-
* Plugin URI: http://www.qurl.nl/
|
5 |
-
* Description: Dynamic Widgets gives you more control over your widgets. It lets you dynamicly place widgets on pages by excluding or including rules by roles, for the homepage, single posts, pages, categories, archives and the error
|
6 |
* Author: Jacco
|
7 |
-
* Version: 1.
|
8 |
* Author URI: http://www.qurl.nl/
|
9 |
-
* Tags: widget, widgets, dynamic, sidebar, custom, rules
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
@@ -15,19 +15,53 @@
|
|
15 |
*
|
16 |
* Released under the GPL v.2, http://www.gnu.org/copyleft/gpl.html
|
17 |
*
|
18 |
-
* @version $Id: dynamic-widgets.php
|
19 |
*/
|
20 |
|
21 |
// Constants
|
|
|
22 |
define('DW_DB_TABLE', 'dynamic_widgets');
|
23 |
define('DW_LIST_LIMIT', 20);
|
24 |
define('DW_LIST_STYLE', 'style="overflow:auto;height:240px;"');
|
25 |
-
define('DW_VERSION', '1.
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
// Functions
|
29 |
function dynwid_add_admin_menu() {
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
32 |
|
33 |
function dynwid_add_plugin_actions($all) {
|
@@ -37,68 +71,325 @@
|
|
37 |
return array_merge($links, $all);
|
38 |
}
|
39 |
|
40 |
-
function
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
die();
|
43 |
}
|
44 |
|
45 |
function dynwid_admin_page() {
|
46 |
-
|
|
|
47 |
}
|
48 |
|
49 |
function dynwid_init() {
|
|
|
|
|
50 |
if ( is_admin() ) {
|
51 |
-
global $_POST, $wpdb;
|
52 |
if ( $_POST['dynwid_save'] == 'yes' ) {
|
53 |
-
|
|
|
54 |
}
|
55 |
|
56 |
add_action('admin_menu', 'dynwid_add_admin_menu');
|
|
|
|
|
57 |
add_action('plugin_action_links_' . plugin_basename(__FILE__), 'dynwid_add_plugin_actions');
|
|
|
|
|
58 |
} else {
|
59 |
add_action('wp_head', 'dynwid_worker');
|
60 |
}
|
61 |
}
|
62 |
|
63 |
function dynwid_install() {
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
id int(11) NOT NULL auto_increment,
|
69 |
widget_id varchar(40) NOT NULL,
|
70 |
maintype varchar(20) NOT NULL,
|
71 |
`name` varchar(40) NOT NULL,
|
72 |
`value` smallint(1) NOT NULL default '1',
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
$wpdb->query($query);
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
85 |
|
86 |
function dynwid_uninstall() {
|
87 |
-
|
88 |
$dbtable = $wpdb->prefix . DW_DB_TABLE;
|
89 |
|
90 |
// Housekeeping
|
91 |
delete_option('dynwid_version');
|
92 |
-
$query = "DROP TABLE " . $dbtable;
|
93 |
$wpdb->query($query);
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
}
|
99 |
|
100 |
function dynwid_worker() {
|
101 |
-
|
|
|
102 |
}
|
103 |
|
104 |
// Hooks
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Dynamic Widgets
|
4 |
+
* Plugin URI: http://www.qurl.nl/dynamic-widgets/
|
5 |
+
* Description: Dynamic Widgets gives you more control over your widgets. It lets you dynamicly place widgets on pages by excluding or including rules by roles, for the homepage, single posts, pages, authors, categories, archives and the error page.
|
6 |
* Author: Jacco
|
7 |
+
* Version: 1.2
|
8 |
* Author URI: http://www.qurl.nl/
|
9 |
+
* Tags: widget, widgets, dynamic, sidebar, custom, rules, admin, conditional tags
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
*
|
16 |
* Released under the GPL v.2, http://www.gnu.org/copyleft/gpl.html
|
17 |
*
|
18 |
+
* @version $Id: dynamic-widgets.php 207231 2010-02-17 20:14:08Z qurl $
|
19 |
*/
|
20 |
|
21 |
// Constants
|
22 |
+
define('DW_DEBUG', FALSE);
|
23 |
define('DW_DB_TABLE', 'dynamic_widgets');
|
24 |
define('DW_LIST_LIMIT', 20);
|
25 |
define('DW_LIST_STYLE', 'style="overflow:auto;height:240px;"');
|
26 |
+
define('DW_VERSION', '1.2');
|
27 |
+
|
28 |
+
// Class version to use
|
29 |
+
if ( version_compare(PHP_VERSION, '5.0.0', '<') ) {
|
30 |
+
define('DW_CLASSFILE', 'dynwid_class_php4.php');
|
31 |
+
} else {
|
32 |
+
define('DW_CLASSFILE', 'dynwid_class.php');
|
33 |
+
}
|
34 |
+
require_once(dirname(__FILE__) . '/' . DW_CLASSFILE);
|
35 |
|
36 |
// Functions
|
37 |
function dynwid_add_admin_menu() {
|
38 |
+
$DW = &$GLOBALS['DW'];
|
39 |
+
|
40 |
+
$screen = add_submenu_page('themes.php', 'Dynamic Widgets', 'Dynamic Widgets', 'switch_themes', 'dynwid-config', 'dynwid_admin_page');
|
41 |
+
add_action('admin_print_scripts-' . $screen, 'dynwid_add_admin_scripts');
|
42 |
+
|
43 |
+
// Contextual help
|
44 |
+
if ( $_GET['action'] == 'edit' ) {
|
45 |
+
$help = 'Widgets are always displayed by default (The \'<em>Yes</em>\' selection).<br />';
|
46 |
+
$help .= 'Click on the <img src="' . $DW->plugin_url . 'img/info.gif" alt="info" /> next to the options for more info.';
|
47 |
+
} else {
|
48 |
+
$help = '<p><strong>Static / Dynamic</strong><br />';
|
49 |
+
$help .= 'When a widget is <em>Static</em>, the widget uses the WordPress default. In other words, it\'s shown everywhere.<br />';
|
50 |
+
$help .= 'A widget is <em>Dynamic</em> when there are options set, i.e. not showing on the front page.</p>';
|
51 |
+
$help .= '<p><strong>Reset</strong><br />';
|
52 |
+
$help .= 'Reset makes the widget return to <em>Static</em>.</p>';
|
53 |
+
}
|
54 |
+
add_contextual_help($screen, $help);
|
55 |
+
|
56 |
+
// Only show meta box in posts panel when there are widgets enabled.
|
57 |
+
$opt = $DW->getOptions('%','individual');
|
58 |
+
if ( count($opt) > 0 ) {
|
59 |
+
add_meta_box('dynwid', 'Dynamic Widgets', 'dynwid_add_post_control', 'post', 'side', 'low');
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
function dynwid_add_admin_scripts() {
|
64 |
+
wp_enqueue_script('jquery');
|
65 |
}
|
66 |
|
67 |
function dynwid_add_plugin_actions($all) {
|
71 |
return array_merge($links, $all);
|
72 |
}
|
73 |
|
74 |
+
function dynwid_add_post_control() {
|
75 |
+
$post = $GLOBALS['post'];
|
76 |
+
$DW = &$GLOBALS['DW'];
|
77 |
+
|
78 |
+
$opt = $DW->getOptions('%','individual');
|
79 |
+
echo '<strong>Apply exception rule to widgets:</strong><br /><br />';
|
80 |
+
foreach ( $opt as $widget ) {
|
81 |
+
$single_condition = '1';
|
82 |
+
$checked = '';
|
83 |
+
$opt_single = $DW->getOptions($widget['widget_id'], 'single');
|
84 |
+
|
85 |
+
// loop through the opts to see if we have a match
|
86 |
+
foreach ( $opt_single as $widget_opt ) {
|
87 |
+
if ( $widget_opt['maintype'] == 'single' ) {
|
88 |
+
$single_condition = $widget_opt['value'];
|
89 |
+
}
|
90 |
+
if ( $widget_opt['maintype'] == 'single-post' && $widget_opt['name'] == $post->ID ) {
|
91 |
+
$checked = ' checked="checked"';
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
$default = ( $single_condition == '0' ) ? 'Off' : 'On';
|
96 |
+
echo '<input type="checkbox" id="dw_' . $widget['widget_id'] . '" name="dw-single-post[]" value="' . $widget['widget_id'] . '"' . $checked . ' /> <label for="dw_' . $widget['widget_id'] . '">' . $DW->getName($widget['widget_id']) . ' (Default: ' . $default . ')</label><br />';
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
function dynwid_add_tag_page() {
|
101 |
+
$DW = &$GLOBALS['DW'];
|
102 |
+
|
103 |
+
// Only show dynwid row when there are widgets enabled
|
104 |
+
$opt = $DW->getOptions('%','individual');
|
105 |
+
if ( count($opt) > 0 ) {
|
106 |
+
|
107 |
+
echo '<tr class="form-field">';
|
108 |
+
echo '<th scope="row" valign="top"><label for="dynamic-widgets">Dynamic Widgets</label></th>';
|
109 |
+
echo '<td>';
|
110 |
+
foreach ( $opt as $widget ) {
|
111 |
+
$single_condition = '1';
|
112 |
+
$checked = '';
|
113 |
+
$opt_single = $DW->getOptions($widget['widget_id'], 'single');
|
114 |
+
|
115 |
+
// loop through the opts to see if we have a match
|
116 |
+
foreach ( $opt_single as $widget_opt ) {
|
117 |
+
if ( $widget_opt['maintype'] == 'single' ) {
|
118 |
+
$single_condition = $widget_opt['value'];
|
119 |
+
}
|
120 |
+
if ( $widget_opt['maintype'] == 'single-tag' && $widget_opt['name'] == $_GET['tag_ID'] ) {
|
121 |
+
$checked = ' checked="checked"';
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
$default = ( $single_condition == '0' ) ? 'Off' : 'On';
|
126 |
+
echo '<input type="checkbox" style="width:10pt;border:none;" id="dw_' . $widget['widget_id'] . '" name="dw-single-tag[]" value="' . $widget['widget_id'] . '"' . $checked . ' /> <label for="dw_' . $widget['widget_id'] . '">' . $DW->getName($widget['widget_id']) . ' (Default: ' . $default . ')</label><br />';
|
127 |
+
|
128 |
+
} // END foreach opt
|
129 |
+
echo '</td>';
|
130 |
+
echo '</tr>';
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
function dynwid_add_widget_control() {
|
135 |
+
$DW = &$GLOBALS['DW'];
|
136 |
+
|
137 |
+
/*
|
138 |
+
Hooking into the callback of the widgets by moving the existing callback to wp_callback
|
139 |
+
and setting callback with own callback function.
|
140 |
+
We need the widget_id registered in params also for calling own callback.
|
141 |
+
*/
|
142 |
+
foreach ( $DW->registered_widgets as $widget_id => $widget ) {
|
143 |
+
if ( array_key_exists($widget_id, $DW->registered_widget_controls) ) {
|
144 |
+
$DW->registered_widget_controls[$widget_id]['wp_callback'] = $DW->registered_widget_controls[$widget_id]['callback'];
|
145 |
+
$DW->registered_widget_controls[$widget_id]['callback'] = 'dynwid_widget_callback';
|
146 |
+
|
147 |
+
if ( count($DW->registered_widget_controls[$widget_id]['params']) == 0 ) {
|
148 |
+
$DW->registered_widget_controls[$widget_id]['params'][ ] = array('widget_id' => $widget_id);
|
149 |
+
} else {
|
150 |
+
$DW->registered_widget_controls[$widget_id]['params'][0]['widget_id'] = $widget_id;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
// Notifying user when options are saved and returned to ./wp-admin/widgets.php
|
156 |
+
if ( $_GET['dynwid_save'] == 'yes' ) {
|
157 |
+
add_action('sidebar_admin_page', 'dynwid_add_widget_page');
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
function dynwid_add_widget_page() {
|
162 |
+
$DW = &$GLOBALS['DW'];
|
163 |
+
|
164 |
+
$name = strip_tags($DW->getName($_GET['widget_id']));
|
165 |
+
|
166 |
+
echo '<div class="updated fade" id="message">';
|
167 |
+
echo '<p>';
|
168 |
+
echo '<strong>Dynamic Widgets Options saved</strong> for ' . $name;
|
169 |
+
echo '</p>';
|
170 |
+
echo '</div>';
|
171 |
+
}
|
172 |
+
|
173 |
+
function dynwid_admin_dump() {
|
174 |
+
$DW = &$GLOBALS['DW'];
|
175 |
+
|
176 |
+
header('Content-Description: File Transfer');
|
177 |
+
header('Content-Disposition: attachment; filename=dynwid_dump_' . date('Ymd') . '.txt' );
|
178 |
+
header('Content-Type: text/plain');
|
179 |
+
|
180 |
+
$DW->dump();
|
181 |
die();
|
182 |
}
|
183 |
|
184 |
function dynwid_admin_page() {
|
185 |
+
$DW = &$GLOBALS['DW'];
|
186 |
+
require_once(dirname(__FILE__) . '/dynwid_admin.php');
|
187 |
}
|
188 |
|
189 |
function dynwid_init() {
|
190 |
+
$GLOBALS['DW'] = new dynWid();
|
191 |
+
|
192 |
if ( is_admin() ) {
|
|
|
193 |
if ( $_POST['dynwid_save'] == 'yes' ) {
|
194 |
+
$DW = &$GLOBALS['DW'];
|
195 |
+
require_once(dirname(__FILE__) . '/dynwid_admin_save.php');
|
196 |
}
|
197 |
|
198 |
add_action('admin_menu', 'dynwid_add_admin_menu');
|
199 |
+
add_action('edit_tag_form_fields', 'dynwid_add_tag_page');
|
200 |
+
add_action('edited_term', 'dynwid_save_tagdata');
|
201 |
add_action('plugin_action_links_' . plugin_basename(__FILE__), 'dynwid_add_plugin_actions');
|
202 |
+
add_action('save_post', 'dynwid_save_postdata');
|
203 |
+
add_action('sidebar_admin_setup', 'dynwid_add_widget_control');
|
204 |
} else {
|
205 |
add_action('wp_head', 'dynwid_worker');
|
206 |
}
|
207 |
}
|
208 |
|
209 |
function dynwid_install() {
|
210 |
+
$wpdb = $GLOBALS['wpdb'];
|
211 |
+
$dbtable = $wpdb->prefix . DW_DB_TABLE;
|
212 |
|
213 |
+
$query = "CREATE TABLE IF NOT EXISTS " . $dbtable . " (
|
214 |
id int(11) NOT NULL auto_increment,
|
215 |
widget_id varchar(40) NOT NULL,
|
216 |
maintype varchar(20) NOT NULL,
|
217 |
`name` varchar(40) NOT NULL,
|
218 |
`value` smallint(1) NOT NULL default '1',
|
219 |
+
PRIMARY KEY (id),
|
220 |
+
KEY widget_id (widget_id,maintype)
|
221 |
+
);";
|
222 |
$wpdb->query($query);
|
223 |
|
224 |
+
// Version check
|
225 |
+
$version = get_option('dynwid_version');
|
226 |
+
if ( $version !== FALSE ) {
|
227 |
+
/* 1.2 > Added support for widget display setting options for Author Pages.
|
228 |
+
Need to apply archive rule to author also to keep same behavior. */
|
229 |
+
if ( version_compare($version, '1.2', '<') ) {
|
230 |
+
$query = "SELECT widget_id FROM " . $dbtable . " WHERE maintype = 'archive'";
|
231 |
+
$results = $wpdb->get_results($query);
|
232 |
+
foreach ( $results as $myrow ) {
|
233 |
+
$query = "INSERT INTO " .$dbtable . "(widget_id, maintype, value) VALUES ('" . $myrow->widget_id . "', 'author', '0')";
|
234 |
+
$wpdb->query($query);
|
235 |
+
}
|
236 |
+
}
|
237 |
+
}
|
238 |
+
update_option('dynwid_version', DW_VERSION);
|
239 |
+
}
|
240 |
+
|
241 |
+
function dynwid_save_postdata($post_id) {
|
242 |
+
$DW = &$GLOBALS['DW'];
|
243 |
|
244 |
+
// Using parent post_id to prevent cluttering up the database with revision numbers
|
245 |
+
if ( array_key_exists('post_ID', $_POST) ) {
|
246 |
+
$post_id = $_POST['post_ID'];
|
247 |
+
}
|
248 |
+
|
249 |
+
// Housekeeping
|
250 |
+
$opt = $DW->getOptions('%','individual');
|
251 |
+
foreach ( $opt as $widget ) {
|
252 |
+
$DW->deleteOption($widget['widget_id'], 'single-post', $post_id);
|
253 |
+
}
|
254 |
+
|
255 |
+
if ( array_key_exists('dw-single-post', $_POST) ) {
|
256 |
+
$opt = $_POST['dw-single-post'];
|
257 |
+
$default = 'yes';
|
258 |
+
$default_single = '1';
|
259 |
+
|
260 |
+
foreach ( $opt as $widget_id ) {
|
261 |
+
$opt_single = $DW->getOptions($widget_id, 'single');
|
262 |
+
if ( count($opt_single) > 0 ) {
|
263 |
+
foreach ( $opt_single as $widget ) {
|
264 |
+
if ( $widget['maintype'] == 'single' ) {
|
265 |
+
$default_single = $widget['value'];
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
if ( $default_single == '0' ) {
|
270 |
+
$default = 'no';
|
271 |
+
}
|
272 |
+
}
|
273 |
+
$DW->addMultiOption($widget_id, 'single-post', $default, array($post_id));
|
274 |
+
}
|
275 |
+
} // END if array_key_exists
|
276 |
+
}
|
277 |
+
|
278 |
+
function dynwid_save_tagdata($term_id) {
|
279 |
+
// Only act when tag is updated via 'edit', NOT via 'quick edit'
|
280 |
+
if ( $_POST['action'] == 'editedtag' ) {
|
281 |
+
$DW = &$GLOBALS['DW'];
|
282 |
+
|
283 |
+
if ( array_key_exists('tag_ID', $_POST) ) {
|
284 |
+
$term_id = $_POST['tag_ID'];
|
285 |
+
}
|
286 |
+
|
287 |
+
// Housekeeping
|
288 |
+
$opt = $DW->getOptions('%','individual');
|
289 |
+
foreach ( $opt as $widget ) {
|
290 |
+
$DW->deleteOption($widget['widget_id'], 'single-tag', $term_id);
|
291 |
+
}
|
292 |
+
|
293 |
+
if ( array_key_exists('dw-single-tag', $_POST) ) {
|
294 |
+
$opt = $_POST['dw-single-tag'];
|
295 |
+
$default = 'yes';
|
296 |
+
$default_single = '1';
|
297 |
+
|
298 |
+
foreach ( $opt as $widget_id ) {
|
299 |
+
$opt_single = $DW->getOptions($widget_id, 'single');
|
300 |
+
if ( count($opt_single) > 0 ) {
|
301 |
+
foreach ( $opt_single as $widget ) {
|
302 |
+
if ( $widget['maintype'] == 'single' ) {
|
303 |
+
$default_single = $widget['value'];
|
304 |
+
}
|
305 |
+
}
|
306 |
+
}
|
307 |
+
$DW->addMultiOption($widget_id, 'single-tag', $default, array($term_id));
|
308 |
+
}
|
309 |
+
} // END if array_key_exists
|
310 |
+
} // END if action
|
311 |
}
|
312 |
|
313 |
function dynwid_uninstall() {
|
314 |
+
$wpdb = $GLOBALS['wpdb'];
|
315 |
$dbtable = $wpdb->prefix . DW_DB_TABLE;
|
316 |
|
317 |
// Housekeeping
|
318 |
delete_option('dynwid_version');
|
319 |
+
$query = "DROP TABLE IF EXISTS " . $dbtable;
|
320 |
$wpdb->query($query);
|
321 |
|
322 |
+
$plugin = plugin_basename(__FILE__);
|
323 |
+
|
324 |
+
/* Shamelessly ripped from /wp-admin/plugins.php */
|
325 |
+
deactivate_plugins($plugin);
|
326 |
+
update_option('recently_activated', array($plugin => time()) + (array) get_option('recently_activated'));
|
327 |
+
wp_redirect('plugins.php?deactivate=true&plugin_status=' . $status . '&paged=' . $page);
|
328 |
+
|
329 |
+
die();
|
330 |
+
}
|
331 |
+
|
332 |
+
function dynwid_widget_callback() {
|
333 |
+
$DW = &$GLOBALS['DW'];
|
334 |
+
|
335 |
+
$args = func_get_args();
|
336 |
+
$widget_id = $args[0]['widget_id'];
|
337 |
+
$wp_callback = $DW->registered_widget_controls[$widget_id]['wp_callback'];
|
338 |
+
|
339 |
+
// Calling original callback first
|
340 |
+
call_user_func_array($wp_callback, $args);
|
341 |
+
|
342 |
+
// Now adding the dynwid text & link
|
343 |
+
echo '<p><b>Dynamic Widgets</b><br />';
|
344 |
+
echo 'This widget is <a title="Edit Dynamic Widgets Options" href="themes.php?page=dynwid-config&action=edit&id=' . $widget_id . '&returnurl=' . urlencode($_SERVER['REQUEST_URI']) . '">';
|
345 |
+
echo ( $DW->hasOptions($widget_id) ) ? 'dynamic' : 'static';
|
346 |
+
echo '</a>.';
|
347 |
+
if ( $DW->hasOptions($widget_id) ) {
|
348 |
+
$s = array();
|
349 |
+
$buffer = array(
|
350 |
+
'role' => 'Role',
|
351 |
+
'front-page' => 'Front Page',
|
352 |
+
'single' => 'Single Posts',
|
353 |
+
'page' => 'Pages',
|
354 |
+
'author' => 'Author Pages',
|
355 |
+
'category' => 'Category Pages',
|
356 |
+
'archive' => 'Archive Pages',
|
357 |
+
'e404' => 'Error Page',
|
358 |
+
);
|
359 |
+
$opt = $DW->getOptions($widget_id, NULL);
|
360 |
+
foreach ( $opt as $widget ) {
|
361 |
+
$type = $widget['maintype'];
|
362 |
+
if ( $type != 'individual' ) {
|
363 |
+
$single = array('single-author', 'single-category', 'single-tag', 'single-post');
|
364 |
+
if ( in_array($type, $single) ) {
|
365 |
+
$type = 'single';
|
366 |
+
}
|
367 |
+
if (! in_array($type, $s) ) {
|
368 |
+
$s[ ] = $type;
|
369 |
+
}
|
370 |
+
}
|
371 |
+
}
|
372 |
+
|
373 |
+
$last = count($s) - 1;
|
374 |
+
for ( $i = 0; $i < $last; $i++ ) {
|
375 |
+
$type = $s[$i];
|
376 |
+
$string .= $buffer[$type];
|
377 |
+
$string .= ( ($last - 1) == $i ) ? ' and ' : ', ';
|
378 |
+
}
|
379 |
+
$type = $s[$last];
|
380 |
+
$string .= $buffer[$type];
|
381 |
+
|
382 |
+
$output = '<br /><small>Option';
|
383 |
+
$output .= ( count($opt) > 1 ) ? 's' : '';
|
384 |
+
$output .= ' set for ' . $string . '.</small>';
|
385 |
+
echo $output;
|
386 |
+
}
|
387 |
+
echo '</p>';
|
388 |
}
|
389 |
|
390 |
function dynwid_worker() {
|
391 |
+
$DW = &$GLOBALS['DW'];
|
392 |
+
require_once(dirname(__FILE__) . '/dynwid_worker.php');
|
393 |
}
|
394 |
|
395 |
// Hooks
|
dynwid_admin.php
CHANGED
@@ -2,13 +2,8 @@
|
|
2 |
/**
|
3 |
* dynwid_admin.php - Startpage for admin
|
4 |
*
|
5 |
-
* @version $Id: dynwid_admin.php
|
6 |
*/
|
7 |
-
|
8 |
-
require_once('dynwid_class.php');
|
9 |
-
if (! isset($DW) ) {
|
10 |
-
$DW = new dynWid();
|
11 |
-
}
|
12 |
?>
|
13 |
|
14 |
<div class="wrap">
|
@@ -18,121 +13,18 @@
|
|
18 |
// Actions
|
19 |
switch ( $_GET['action'] ) {
|
20 |
case 'edit':
|
21 |
-
require_once('dynwid_admin_edit.php');
|
22 |
break;
|
23 |
|
24 |
-
default:
|
25 |
-
|
26 |
-
|
27 |
-
check_admin_referer('plugin-name-action_reset_' . $_GET['id']);
|
28 |
-
$DW->resetOptions($_GET['id']);
|
29 |
-
?>
|
30 |
-
<div class="updated fade" id="message">
|
31 |
-
<p>
|
32 |
-
<strong>Widget options have been reset to default.</strong><br />
|
33 |
-
</p>
|
34 |
-
</div>
|
35 |
-
<?php } ?>
|
36 |
-
<style type="text/css">
|
37 |
-
.helpbox {
|
38 |
-
-moz-border-radius-topleft : 6px;
|
39 |
-
-moz-border-radius-topright : 6px;
|
40 |
-
-moz-border-radius-bottomleft : 6px;
|
41 |
-
-moz-border-radius-bottomright : 6px;
|
42 |
-
border-style : solid;
|
43 |
-
border-width : 1px;
|
44 |
-
border-color : #E3E3E3;
|
45 |
-
padding : 5px;
|
46 |
-
background-color : white;
|
47 |
-
width : 98%;
|
48 |
-
}
|
49 |
-
</style>
|
50 |
-
|
51 |
-
<div class="helpbox">
|
52 |
-
<strong>Static / Dynamic</strong><br />
|
53 |
-
When a widget is <em>Static</em>, the widget uses the WordPress default. In other words, it's shown everywhere.<br />
|
54 |
-
A widget is <em>Dynamic</em> when there are options set, i.e. not showing on the front page.<br />
|
55 |
-
<br />
|
56 |
-
|
57 |
-
<strong>Reset</strong><br />
|
58 |
-
Reset makes the widget return to <em>Static</em>.<br />
|
59 |
-
</div>
|
60 |
-
|
61 |
-
<?php
|
62 |
-
foreach ( $DW->sidebars as $sidebar_id => $widgets ) {
|
63 |
-
if ( count($widgets) > 0 ) {
|
64 |
-
if ( $sidebar_id == 'wp_inactive_widgets' ) {
|
65 |
-
$name = 'Inactive Widgets';
|
66 |
-
} else {
|
67 |
-
$name = $DW->getName($sidebar_id, 'S');
|
68 |
-
}
|
69 |
-
?>
|
70 |
-
|
71 |
-
<div class="postbox-container" style="width:48%;margin-top:10px;margin-right:10px;">
|
72 |
-
<table cellspacing="0" class="widefat fixed">
|
73 |
-
<thead>
|
74 |
-
<tr>
|
75 |
-
<th class="managage-column" scope="col"><?php echo $name; ?></th>
|
76 |
-
<th style="width:70px"> </th>
|
77 |
-
</tr>
|
78 |
-
</thead>
|
79 |
-
|
80 |
-
<tbody class="list:link-cat" id="<?php echo str_replace('-', '_', $sidebar_id); ?>">
|
81 |
-
<?php foreach ( $widgets as $widget_id ) { ?>
|
82 |
-
<tr>
|
83 |
-
<td class="name">
|
84 |
-
<p class="row-title"><?php echo $DW->getName($widget_id); ?></p>
|
85 |
-
<div class="row-actions">
|
86 |
-
<span class="edit">
|
87 |
-
<a title="Edit this widget options" href="themes.php?page=dynwid-config&action=edit&id=<?php echo $widget_id; ?>">Edit</a>
|
88 |
-
</span>
|
89 |
-
<?php if ( $DW->hasOptions($widget_id) ) { ?>
|
90 |
-
<span class="delete">
|
91 |
-
<?php $href = wp_nonce_url('themes.php?page=dynwid-config&action=reset&id=' . $widget_id, 'plugin-name-action_reset_' . $widget_id); ?>
|
92 |
-
| <a class="submitdelete" title="Reset widget to Static" onclick="if ( confirm('You are about to reset this widget \'<?php echo strip_tags($DW->getName($widget_id)); ?>\'\n \'Cancel\' to stop, \'OK\' to reset.') ) { return true;}return false;" href="<?php echo $href; ?>">Reset</a>
|
93 |
-
</span>
|
94 |
-
<?php } ?>
|
95 |
-
</div>
|
96 |
-
</td>
|
97 |
-
<td>
|
98 |
-
<?php echo ( $DW->hasOptions($widget_id) ) ? 'Dynamic' : 'Static'; ?>
|
99 |
-
</td>
|
100 |
-
</tr>
|
101 |
-
<?php } // END foreach $widgets ?>
|
102 |
-
</tbody>
|
103 |
-
</table>
|
104 |
-
</div>
|
105 |
-
<?php
|
106 |
-
} // END count $widgets
|
107 |
-
} // END foreach $sidebars
|
108 |
?>
|
109 |
|
|
|
110 |
<div class="clear"><br /><br /></div>
|
111 |
-
|
112 |
-
<a href="
|
113 |
-
|
114 |
-
<br />
|
115 |
-
For debugging purposes it is possible you're asked to create a dump. Click the 'Create dump' button and save the text file.
|
116 |
-
<br /><br />
|
117 |
-
<div id="dump">
|
118 |
-
<form action="" method="get">
|
119 |
-
<input type="hidden" name="action" value="dynwid_dump" />
|
120 |
-
<input class="button-primary" type="submit" value="Create dump" />
|
121 |
-
</form>
|
122 |
-
</div>
|
123 |
-
|
124 |
-
<br /><br />
|
125 |
-
|
126 |
-
If you deceide not to use this plugin anymore (sorry to hear that!). You can cleanup all settings and data related to this plugin by clicking on the 'Uninstall' button. This process is irreversible! After the cleanup, you can deactivate the plugin.
|
127 |
-
<br /><br />
|
128 |
-
<div id="uninstall">
|
129 |
-
<form action="" method="get">
|
130 |
-
<input type="hidden" name="action" value="dynwid_uninstall" />
|
131 |
-
<input class="button-primary" type="submit" value="Uninstall" onclick="if ( confirm('Are you sure you want to uninstall Dynamic Widgets?') ) { return true; } return false;" />
|
132 |
-
</form>
|
133 |
-
</div>
|
134 |
-
</div>
|
135 |
-
|
136 |
-
<?php } // END switch ?>
|
137 |
|
138 |
</div> <!-- /wrap //-->
|
2 |
/**
|
3 |
* dynwid_admin.php - Startpage for admin
|
4 |
*
|
5 |
+
* @version $Id: dynwid_admin.php 207183 2010-02-17 17:54:48Z qurl $
|
6 |
*/
|
|
|
|
|
|
|
|
|
|
|
7 |
?>
|
8 |
|
9 |
<div class="wrap">
|
13 |
// Actions
|
14 |
switch ( $_GET['action'] ) {
|
15 |
case 'edit':
|
16 |
+
require_once(dirname(__FILE__) . '/dynwid_admin_edit.php');
|
17 |
break;
|
18 |
|
19 |
+
default:
|
20 |
+
require_once(dirname(__FILE__) . '/dynwid_admin_overview.php');
|
21 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
?>
|
23 |
|
24 |
+
<!-- Footer //-->
|
25 |
<div class="clear"><br /><br /></div>
|
26 |
+
<div><small>
|
27 |
+
<a href="http://www.qurl.nl/dynamic-widgets/" target="_blank">Dynamic Widgets</a> v<?php echo DW_VERSION; ?> (<?php echo DW_CLASSFILE; ?>)
|
28 |
+
</small></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
</div> <!-- /wrap //-->
|
dynwid_admin_dump.php
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* dynwid_admin_dump.php
|
4 |
-
*
|
5 |
-
* @version $Id: dynwid_admin_dump.php 194733 2010-01-17 12:29:21Z qurl $
|
6 |
-
*/
|
7 |
-
|
8 |
-
require_once('dynwid_class.php');
|
9 |
-
if (! isset($DW) ) {
|
10 |
-
$DW = new dynWid();
|
11 |
-
}
|
12 |
-
|
13 |
-
header('Content-Description: File Transfer');
|
14 |
-
header('Content-Disposition: attachment; filename=dynwid_dump_' . date('Ymd') . '.txt' );
|
15 |
-
header('Content-Type: text/plain');
|
16 |
-
|
17 |
-
$DW->dump();
|
18 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dynwid_admin_edit.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* dynwid_admin_edit.php - Options
|
4 |
*
|
5 |
-
* @version $Id: dynwid_admin_edit.php
|
6 |
*/
|
7 |
|
8 |
// Roles
|
9 |
-
|
10 |
$roles = array_merge($wp_roles->role_names, array('anonymous' => 'Anonymous|User role'));
|
11 |
$jsroles = array();
|
12 |
foreach ( $roles as $rid => $role ) {
|
@@ -17,7 +17,7 @@
|
|
17 |
$role_condition_select_style = DW_LIST_STYLE;
|
18 |
}
|
19 |
|
20 |
-
$role_yes_selected = 'checked="
|
21 |
$opt_role = $DW->getOptions($_GET['id'], 'role');
|
22 |
if ( count($opt_role) > 0 ) {
|
23 |
$role_act = array();
|
@@ -36,7 +36,7 @@
|
|
36 |
}
|
37 |
|
38 |
// Front Page
|
39 |
-
$frontpage_yes_selected = 'checked="
|
40 |
$opt_frontpage = $DW->getOptions($_GET['id'], 'front-page');
|
41 |
if ( count($opt_frontpage) > 0 ) {
|
42 |
$frontpage_condition = $opt_frontpage[0]['value'];
|
@@ -47,10 +47,15 @@
|
|
47 |
}
|
48 |
|
49 |
// Single Post
|
50 |
-
$single_yes_selected = 'checked="
|
|
|
51 |
$opt_single = $DW->getOptions($_GET['id'], 'single');
|
52 |
if ( count($opt_single) > 0 ) {
|
53 |
-
$
|
|
|
|
|
|
|
|
|
54 |
if ( $single_condition == '0' ) {
|
55 |
$single_no_selected = $single_yes_selected;
|
56 |
unset($single_yes_selected);
|
@@ -58,30 +63,63 @@
|
|
58 |
}
|
59 |
|
60 |
// -- Author
|
|
|
61 |
$opt_single_author = $DW->getOptions($_GET['id'], 'single-author');
|
|
|
62 |
if ( count($opt_single_author) > 0 ) {
|
|
|
63 |
$single_author_act = array();
|
64 |
foreach ( $opt_single_author as $single_author_condition ) {
|
65 |
$single_author_act[ ] = $single_author_condition['name'];
|
66 |
}
|
67 |
}
|
68 |
|
69 |
-
$authors = get_users_of_blog();
|
70 |
-
if ( count($authors) > DW_LIST_LIMIT ) {
|
71 |
-
$single_author_condition_select_style = DW_LIST_STYLE;
|
72 |
-
}
|
73 |
-
|
74 |
// -- Category
|
75 |
$opt_single_category = $DW->getOptions($_GET['id'], 'single-category');
|
|
|
76 |
if ( count($opt_single_category) > 0 ) {
|
|
|
77 |
$single_category_act = array();
|
78 |
foreach ( $opt_single_category as $single_category_condition ) {
|
79 |
$single_category_act[ ] = $single_category_condition['name'];
|
80 |
}
|
81 |
}
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
// Pages
|
84 |
-
$page_yes_selected = 'checked="
|
85 |
$opt_page = $DW->getOptions($_GET['id'], 'page');
|
86 |
if ( count($opt_page) > 0 ) {
|
87 |
$page_act = array();
|
@@ -104,8 +142,32 @@
|
|
104 |
$page_condition_select_style = DW_LIST_STYLE;
|
105 |
}
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
// Categories
|
108 |
-
$category_yes_selected = 'checked="
|
109 |
$opt_category = $DW->getOptions($_GET['id'], 'category');
|
110 |
if ( count($opt_category) > 0 ) {
|
111 |
$category_act = array();
|
@@ -129,7 +191,7 @@
|
|
129 |
}
|
130 |
|
131 |
// Archives
|
132 |
-
$archive_yes_selected = 'checked="
|
133 |
$opt_archive = $DW->getOptions($_GET['id'], 'archive');
|
134 |
if ( count($opt_archive) > 0 ) {
|
135 |
$archive_condition = $opt_archive[0]['value'];
|
@@ -140,7 +202,7 @@
|
|
140 |
}
|
141 |
|
142 |
// Error 404
|
143 |
-
$e404_yes_selected = 'checked="
|
144 |
$opt_e404 = $DW->getOptions($_GET['id'], 'e404');
|
145 |
if ( count($opt_e404) > 0 ) {
|
146 |
$e404_condition = $opt_e404[0]['value'];
|
@@ -149,11 +211,8 @@
|
|
149 |
unset($e404_yes_selected);
|
150 |
}
|
151 |
}
|
152 |
-
|
153 |
?>
|
154 |
|
155 |
-
<div id="adv"></div>
|
156 |
-
|
157 |
<style type="text/css">
|
158 |
label {
|
159 |
cursor : default;
|
@@ -174,6 +233,8 @@ label {
|
|
174 |
.infotext {
|
175 |
width : 98%;
|
176 |
display : none;
|
|
|
|
|
177 |
}
|
178 |
</style>
|
179 |
|
@@ -183,9 +244,7 @@ label {
|
|
183 |
<strong>Widget options saved.</strong> <a href="themes.php?page=dynwid-config">Return</a> to Dynamic Widgets overview.
|
184 |
</p>
|
185 |
</div>
|
186 |
-
<?php } ?>
|
187 |
-
|
188 |
-
<?php if ( $_GET['work'] == 'none' ) { ?>
|
189 |
<div class="error" id="message">
|
190 |
<p>Dynamic does not mean static hiding of a widget. Hint: <a href="widgets.php">Remove</a> the widget from the sidebar.</p>
|
191 |
</div>
|
@@ -197,20 +256,22 @@ label {
|
|
197 |
<?php wp_nonce_field('plugin-name-action_edit_' . $_GET['id']); ?>
|
198 |
<input type="hidden" name="dynwid_save" value="yes" />
|
199 |
<input type="hidden" name="widget_id" value="<?php echo $_GET['id']; ?>" />
|
|
|
200 |
|
201 |
-
<b>
|
202 |
Show widget to everybody?
|
203 |
-
|
|
|
204 |
<div id="role" class="infotext">
|
205 |
Setting options by role is very powerfull. It can override all other options!<br />
|
206 |
Users who are not logged in, get the <em>Anonymous</em> role.
|
207 |
</div>
|
208 |
</div>
|
209 |
-
<input type="radio" name="role" value="yes" id="role-yes" <?php echo $role_yes_selected; ?> onclick="
|
210 |
-
<input type="radio" name="role" value="no" id="role-no" <?php echo $role_no_selected; ?> onclick="
|
211 |
<div id="role-select" class="condition-select" <?php echo $role_condition_select_style; ?>>
|
212 |
<?php foreach ( $roles as $rid => $role ) { ?>
|
213 |
-
<input type="checkbox" id="role_act_<?php echo $rid; ?>" name="role_act[]" value="<?php echo $rid; ?>" <?php
|
214 |
<?php } ?>
|
215 |
</div>
|
216 |
|
@@ -218,37 +279,59 @@ Show widget to everybody?
|
|
218 |
|
219 |
<b>Front Page</b><br />
|
220 |
Show widget on the front page?<br />
|
|
|
221 |
<input type="radio" name="front-page" value="yes" id="front-page-yes" <?php echo $frontpage_yes_selected; ?> /> <label for="front-page-yes">Yes</label>
|
222 |
<input type="radio" name="front-page" value="no" id="front-page-no" <?php echo $frontpage_no_selected; ?> /> <label for="front-page-no">No</label>
|
223 |
|
224 |
<br /><br />
|
225 |
|
226 |
-
<b>Single Posts</b> <img src="<?php echo $DW->plugin_url; ?>img/info.gif" alt="info" title="Click to toggle info" onclick="
|
227 |
-
Show widget on single posts?<br />
|
228 |
-
|
|
|
229 |
<div id="single" class="infotext">
|
230 |
-
When you use an author <b>AND</b> a category exception, both rules in the condition must be met. Otherwise the exception won't
|
231 |
-
If you want to use the rules in
|
232 |
</div>
|
233 |
</div>
|
234 |
<input type="radio" name="single" value="yes" id="single-yes" <?php echo $single_yes_selected; ?> /> <label for="single-yes">Yes</label>
|
235 |
<input type="radio" name="single" value="no" id="single-no" <?php echo $single_no_selected; ?> /> <label for="single-no">No</label><br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
<table border="0" cellspacing="0" cellpadding="0">
|
237 |
<tr>
|
238 |
<td valign="top">
|
239 |
Except the posts by author:
|
240 |
-
|
|
|
241 |
<?php foreach ( $authors as $author ) { ?>
|
242 |
-
|
|
|
243 |
<?php } ?>
|
244 |
</div>
|
245 |
</td>
|
246 |
<td style="width:10px"></td>
|
247 |
<td valign="top">
|
248 |
Except the posts in category:
|
|
|
249 |
<div id="single-category-select" class="condition-select" <?php echo $category_condition_select_style; ?>>
|
250 |
<?php foreach ( $category as $cat ) { ?>
|
251 |
-
|
|
|
252 |
<?php } ?>
|
253 |
</div>
|
254 |
</td>
|
@@ -258,36 +341,52 @@ Show widget on single posts?<br />
|
|
258 |
<br /><br />
|
259 |
|
260 |
<b>Pages</b><br />
|
261 |
-
Show widget on pages?<br />
|
|
|
262 |
<input type="radio" name="page" value="yes" id="page-yes" <?php echo $page_yes_selected; ?> /> <label for="page-yes">Yes</label>
|
263 |
<input type="radio" name="page" value="no" id="page-no" <?php echo $page_no_selected; ?> /> <label for="page-no">No</label><br />
|
264 |
-
Except the
|
265 |
<div id="page-select" class="condition-select" <?php echo $page_condition_select_style; ?>>
|
266 |
<?php foreach ( $pages as $page ) { ?>
|
267 |
-
<input type="checkbox" id="page_act_<?php echo $page->ID; ?>" name="page_act[]" value="<?php echo $page->ID; ?>" <?php
|
268 |
<?php } ?>
|
269 |
</div>
|
270 |
|
271 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
<b>Category Pages</b><br />
|
274 |
-
Show widget on category pages?<br />
|
|
|
275 |
<input type="radio" name="category" value="yes" id="category-yes" <?php echo $category_yes_selected; ?> /> <label for="category-yes">Yes</label>
|
276 |
<input type="radio" name="category" value="no" id="category-no" <?php echo $category_no_selected; ?> /> <label for="category-no">No</label><br />
|
277 |
Except the categories:<br />
|
278 |
<div id="category-select" class="condition-select" <?php echo $category_condition_select_style; ?>>
|
279 |
<?php foreach ( $category as $cat ) { ?>
|
280 |
-
<input type="checkbox" id="cat_act_<?php echo $cat->cat_ID; ?>" name="category_act[]" value="<?php echo $cat->cat_ID; ?>" <?php
|
281 |
<?php } ?>
|
282 |
</div>
|
283 |
|
284 |
-
<br />
|
285 |
|
286 |
-
<b>Archive Pages</b> <img src="<?php echo $DW->plugin_url; ?>img/info.gif" alt="info" title="Click to toggle info" onclick="
|
287 |
Show widget on archive pages?<br />
|
288 |
-
|
|
|
289 |
<div id="archive" class="infotext">
|
290 |
-
This option does not include
|
291 |
</div>
|
292 |
</div>
|
293 |
<input type="radio" name="archive" value="yes" id="archive-yes" <?php echo $archive_yes_selected; ?> /> <label for="archive-yes">Yes</label>
|
@@ -295,8 +394,9 @@ Show widget on archive pages?<br />
|
|
295 |
|
296 |
<br /><br />
|
297 |
|
298 |
-
<b>
|
299 |
-
Show widget on error
|
|
|
300 |
<input type="radio" name="e404" value="yes" id="e404-yes" <?php echo $e404_yes_selected; ?> /> <label for="e404-yes">Yes</label>
|
301 |
<input type="radio" name="e404" value="no" id="e404-no" <?php echo $e404_no_selected; ?> /> <label for="e404-no">No</label>
|
302 |
|
@@ -305,45 +405,69 @@ Show widget on error 404 page?<br />
|
|
305 |
<input class="button-primary" type="submit" value="Save" />
|
306 |
</form>
|
307 |
|
308 |
-
|
309 |
-
<input
|
310 |
-
<input class="button-secondary" type="submit" value="Cancel" style="position:relative;top:-23px;left:80px;" />
|
311 |
-
</form>
|
312 |
|
313 |
<script type="text/javascript">
|
314 |
-
function
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
}
|
318 |
-
swRoles(true);
|
319 |
}
|
320 |
|
321 |
-
function
|
322 |
-
|
323 |
-
|
|
|
|
|
324 |
}
|
325 |
}
|
326 |
|
327 |
-
function
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
}
|
339 |
}
|
340 |
|
341 |
-
var
|
|
|
|
|
|
|
|
|
342 |
if ( document.getElementById('role-yes').checked ) {
|
343 |
-
|
|
|
|
|
|
|
|
|
344 |
}
|
345 |
-
|
346 |
-
var d_role = false;
|
347 |
-
var d_single = false;
|
348 |
-
var d_archive = false;
|
349 |
</script>
|
1 |
<?php
|
2 |
/**
|
3 |
+
* dynwid_admin_edit.php - Options settings
|
4 |
*
|
5 |
+
* @version $Id: dynwid_admin_edit.php 207183 2010-02-17 17:54:48Z qurl $
|
6 |
*/
|
7 |
|
8 |
// Roles
|
9 |
+
$wp_roles = $GLOBALS['wp_roles'];
|
10 |
$roles = array_merge($wp_roles->role_names, array('anonymous' => 'Anonymous|User role'));
|
11 |
$jsroles = array();
|
12 |
foreach ( $roles as $rid => $role ) {
|
17 |
$role_condition_select_style = DW_LIST_STYLE;
|
18 |
}
|
19 |
|
20 |
+
$role_yes_selected = 'checked="checked"';
|
21 |
$opt_role = $DW->getOptions($_GET['id'], 'role');
|
22 |
if ( count($opt_role) > 0 ) {
|
23 |
$role_act = array();
|
36 |
}
|
37 |
|
38 |
// Front Page
|
39 |
+
$frontpage_yes_selected = 'checked="checked"';
|
40 |
$opt_frontpage = $DW->getOptions($_GET['id'], 'front-page');
|
41 |
if ( count($opt_frontpage) > 0 ) {
|
42 |
$frontpage_condition = $opt_frontpage[0]['value'];
|
47 |
}
|
48 |
|
49 |
// Single Post
|
50 |
+
$single_yes_selected = 'checked="checked"';
|
51 |
+
$single_condition == '1';
|
52 |
$opt_single = $DW->getOptions($_GET['id'], 'single');
|
53 |
if ( count($opt_single) > 0 ) {
|
54 |
+
foreach ( $opt_single as $widget ) {
|
55 |
+
if ( $widget['maintype'] == 'single' ) {
|
56 |
+
$single_condition = $widget['value'];
|
57 |
+
}
|
58 |
+
}
|
59 |
if ( $single_condition == '0' ) {
|
60 |
$single_no_selected = $single_yes_selected;
|
61 |
unset($single_yes_selected);
|
63 |
}
|
64 |
|
65 |
// -- Author
|
66 |
+
$js_count = 0;
|
67 |
$opt_single_author = $DW->getOptions($_GET['id'], 'single-author');
|
68 |
+
$js_author_array = array();
|
69 |
if ( count($opt_single_author) > 0 ) {
|
70 |
+
$js_count = $js_count + count($opt_single_author) - 1;
|
71 |
$single_author_act = array();
|
72 |
foreach ( $opt_single_author as $single_author_condition ) {
|
73 |
$single_author_act[ ] = $single_author_condition['name'];
|
74 |
}
|
75 |
}
|
76 |
|
|
|
|
|
|
|
|
|
|
|
77 |
// -- Category
|
78 |
$opt_single_category = $DW->getOptions($_GET['id'], 'single-category');
|
79 |
+
$js_category_array = array();
|
80 |
if ( count($opt_single_category) > 0 ) {
|
81 |
+
$js_count = $js_count + count($opt_single_category) - 1;
|
82 |
$single_category_act = array();
|
83 |
foreach ( $opt_single_category as $single_category_condition ) {
|
84 |
$single_category_act[ ] = $single_category_condition['name'];
|
85 |
}
|
86 |
}
|
87 |
|
88 |
+
// -- Individual / Posts / Tags
|
89 |
+
$individual = FALSE;
|
90 |
+
$opt_individual = $DW->getOptions($_GET['id'], 'individual');
|
91 |
+
$single_post_act = array();
|
92 |
+
$single_tag_act = array();
|
93 |
+
|
94 |
+
if ( count($opt_individual) > 0 ) {
|
95 |
+
$individual_condition = $opt_individual[0]['value'];
|
96 |
+
if ( $individual_condition == 1 ) {
|
97 |
+
$individual = TRUE;
|
98 |
+
|
99 |
+
$opt_single_post = $DW->getOptions($_GET['id'], 'single-post');
|
100 |
+
if ( count($opt_single_post) > 0 ) {
|
101 |
+
foreach ( $opt_single_post as $single_post_condition ) {
|
102 |
+
if ( $single_post_condition['name'] != 'default' ) {
|
103 |
+
$single_post_act[ ] = $single_post_condition['name'];
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
$opt_single_tag = $DW->getOptions($_GET['id'], 'single-tag');
|
109 |
+
if ( count($opt_single_tag) > 0 ) {
|
110 |
+
foreach ( $opt_single_tag as $single_tag_condition ) {
|
111 |
+
if ( $single_tag_condition['name'] != 'default' ) {
|
112 |
+
$single_tag_act[ ] = $single_tag_condition['name'];
|
113 |
+
}
|
114 |
+
}
|
115 |
+
}
|
116 |
+
|
117 |
+
$count_individual = '(Posts: ' . count($single_post_act) . ', Tags: ' . count($single_tag_act) . ')';
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
// Pages
|
122 |
+
$page_yes_selected = 'checked="checked"';
|
123 |
$opt_page = $DW->getOptions($_GET['id'], 'page');
|
124 |
if ( count($opt_page) > 0 ) {
|
125 |
$page_act = array();
|
142 |
$page_condition_select_style = DW_LIST_STYLE;
|
143 |
}
|
144 |
|
145 |
+
// Author
|
146 |
+
$author_yes_selected = 'checked="checked"';
|
147 |
+
$opt_author = $DW->getOptions($_GET['id'], 'author');
|
148 |
+
if ( count($opt_author) > 0 ) {
|
149 |
+
$author_act = array();
|
150 |
+
foreach ( $opt_author as $author_condition ) {
|
151 |
+
if ( $author_condition['name'] == 'default' || empty($author_condition['name']) ) {
|
152 |
+
$author_default = $author_condition['value'];
|
153 |
+
} else {
|
154 |
+
$author_act[ ] = $author_condition['name'];
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
if ( $author_default == '0' ) {
|
159 |
+
$author_no_selected = $author_yes_selected;
|
160 |
+
unset($author_yes_selected);
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
$authors = get_users_of_blog();
|
165 |
+
if ( count($authors) > DW_LIST_LIMIT ) {
|
166 |
+
$author_condition_select_style = DW_LIST_STYLE;
|
167 |
+
}
|
168 |
+
|
169 |
// Categories
|
170 |
+
$category_yes_selected = 'checked="checked"';
|
171 |
$opt_category = $DW->getOptions($_GET['id'], 'category');
|
172 |
if ( count($opt_category) > 0 ) {
|
173 |
$category_act = array();
|
191 |
}
|
192 |
|
193 |
// Archives
|
194 |
+
$archive_yes_selected = 'checked="checked"';
|
195 |
$opt_archive = $DW->getOptions($_GET['id'], 'archive');
|
196 |
if ( count($opt_archive) > 0 ) {
|
197 |
$archive_condition = $opt_archive[0]['value'];
|
202 |
}
|
203 |
|
204 |
// Error 404
|
205 |
+
$e404_yes_selected = 'checked="checked"';
|
206 |
$opt_e404 = $DW->getOptions($_GET['id'], 'e404');
|
207 |
if ( count($opt_e404) > 0 ) {
|
208 |
$e404_condition = $opt_e404[0]['value'];
|
211 |
unset($e404_yes_selected);
|
212 |
}
|
213 |
}
|
|
|
214 |
?>
|
215 |
|
|
|
|
|
216 |
<style type="text/css">
|
217 |
label {
|
218 |
cursor : default;
|
233 |
.infotext {
|
234 |
width : 98%;
|
235 |
display : none;
|
236 |
+
color : #666666;
|
237 |
+
font-style : italic;
|
238 |
}
|
239 |
</style>
|
240 |
|
244 |
<strong>Widget options saved.</strong> <a href="themes.php?page=dynwid-config">Return</a> to Dynamic Widgets overview.
|
245 |
</p>
|
246 |
</div>
|
247 |
+
<?php } else if ( $_GET['work'] == 'none' ) { ?>
|
|
|
|
|
248 |
<div class="error" id="message">
|
249 |
<p>Dynamic does not mean static hiding of a widget. Hint: <a href="widgets.php">Remove</a> the widget from the sidebar.</p>
|
250 |
</div>
|
256 |
<?php wp_nonce_field('plugin-name-action_edit_' . $_GET['id']); ?>
|
257 |
<input type="hidden" name="dynwid_save" value="yes" />
|
258 |
<input type="hidden" name="widget_id" value="<?php echo $_GET['id']; ?>" />
|
259 |
+
<input type="hidden" name="returnurl" value="<?php echo urldecode($_GET['returnurl']); ?>" />
|
260 |
|
261 |
+
<b>Role</b> <img src="<?php echo $DW->plugin_url; ?>img/info.gif" alt="info" onclick="divToggle('role');" /><br />
|
262 |
Show widget to everybody?
|
263 |
+
<?php $DW->dumpOpt($opt_role); ?>
|
264 |
+
<div>
|
265 |
<div id="role" class="infotext">
|
266 |
Setting options by role is very powerfull. It can override all other options!<br />
|
267 |
Users who are not logged in, get the <em>Anonymous</em> role.
|
268 |
</div>
|
269 |
</div>
|
270 |
+
<input type="radio" name="role" value="yes" id="role-yes" <?php echo $role_yes_selected; ?> onclick="swChb(cRole, true);" /> <label for="role-yes">Yes</label>
|
271 |
+
<input type="radio" name="role" value="no" id="role-no" <?php echo $role_no_selected; ?> onclick="swChb(cRole, false)" /> <label for="role-no">No, only to:</label><br />
|
272 |
<div id="role-select" class="condition-select" <?php echo $role_condition_select_style; ?>>
|
273 |
<?php foreach ( $roles as $rid => $role ) { ?>
|
274 |
+
<input type="checkbox" id="role_act_<?php echo $rid; ?>" name="role_act[]" value="<?php echo $rid; ?>" <?php echo ( count($role_act) > 0 && in_array($rid,$role_act) ) ? 'checked="checked"' : ''; ?> /> <label for="role_act_<?php echo $rid; ?>"><?php echo $role; ?></label><br />
|
275 |
<?php } ?>
|
276 |
</div>
|
277 |
|
279 |
|
280 |
<b>Front Page</b><br />
|
281 |
Show widget on the front page?<br />
|
282 |
+
<?php $DW->dumpOpt($opt_frontpage); ?>
|
283 |
<input type="radio" name="front-page" value="yes" id="front-page-yes" <?php echo $frontpage_yes_selected; ?> /> <label for="front-page-yes">Yes</label>
|
284 |
<input type="radio" name="front-page" value="no" id="front-page-no" <?php echo $frontpage_no_selected; ?> /> <label for="front-page-no">No</label>
|
285 |
|
286 |
<br /><br />
|
287 |
|
288 |
+
<b>Single Posts</b> <img src="<?php echo $DW->plugin_url; ?>img/info.gif" alt="info" title="Click to toggle info" onclick="divToggle('single')" /><br />
|
289 |
+
Show widget default on single posts?<br />
|
290 |
+
<?php $DW->dumpOpt($opt_single); ?>
|
291 |
+
<div>
|
292 |
<div id="single" class="infotext">
|
293 |
+
When you use an author <b>AND</b> a category exception, both rules in the condition must be met. Otherwise the exception rule won't be applied.
|
294 |
+
If you want to use the rules in a logical OR condition. Add the same widget again and apply the other rule to that.
|
295 |
</div>
|
296 |
</div>
|
297 |
<input type="radio" name="single" value="yes" id="single-yes" <?php echo $single_yes_selected; ?> /> <label for="single-yes">Yes</label>
|
298 |
<input type="radio" name="single" value="no" id="single-no" <?php echo $single_no_selected; ?> /> <label for="single-no">No</label><br />
|
299 |
+
<?php $DW->dumpOpt($opt_individual); ?>
|
300 |
+
<input type="checkbox" id="individual" name="individual" value="1" <?php echo ( $individual ) ? 'checked="checked"' : ''; ?> onclick="chkInPosts()" />
|
301 |
+
<label for="individual">Make exception rule available to individual posts and tags. <?php echo $count_individual; ?></label>
|
302 |
+
<img src="<?php echo $DW->plugin_url; ?>img/info.gif" alt="info" title="Click to toggle info" onclick="divToggle('individual_post_tag')" />
|
303 |
+
<div>
|
304 |
+
<div id="individual_post_tag" class="infotext">
|
305 |
+
When you enable this option, you have the ability to apply the exception rule for <em>Single Posts</em> to tags and individual posts. You can set the exception rule for tags in the single Edit Tag Panel (go to <a href="edit-tags.php?taxonomy=post_tag">Post Tags</a>, click a tag), For individual posts in the <a href="post-new.php">New</a> or <a href="edit.php">Edit</a> Posts panel. Exception rules for tags and individual posts in any combination work independantly, but will always be counted as one exception.<br />
|
306 |
+
Please note when exception rules are set for Author and/or Category, these will be removed.
|
307 |
+
</div>
|
308 |
+
</div>
|
309 |
+
<?php foreach ( $single_post_act as $singlepost ) { ?>
|
310 |
+
<input type="hidden" name="single_post_act[]" value="<?php echo $singlepost; ?>" />
|
311 |
+
<?php } ?>
|
312 |
+
<?php foreach ( $single_tag_act as $tag ) { ?>
|
313 |
+
<input type="hidden" name="single_tag_act[]" value="<?php echo $tag; ?>" />
|
314 |
+
<?php } ?>
|
315 |
<table border="0" cellspacing="0" cellpadding="0">
|
316 |
<tr>
|
317 |
<td valign="top">
|
318 |
Except the posts by author:
|
319 |
+
<?php $DW->dumpOpt($opt_single_author); ?>
|
320 |
+
<div id="single-author-select" class="condition-select" <?php echo $author_condition_select_style; ?>>
|
321 |
<?php foreach ( $authors as $author ) { ?>
|
322 |
+
<?php $js_author_array[ ] = '\'single_author_act_' . $author->ID . '\''; ?>
|
323 |
+
<input type="checkbox" id="single_author_act_<?php echo $author->ID; ?>" name="single_author_act[]" value="<?php echo $author->ID; ?>" <?php echo ( count($single_author_act) > 0 && in_array($author->ID,$single_author_act) ) ? 'checked="checked"' : ''; ?> onclick="ci('single_author_act_<?php echo $author->ID; ?>')" /> <label for="single_author_act_<?php echo $author->ID; ?>"><?php echo $author->display_name; ?></label><br />
|
324 |
<?php } ?>
|
325 |
</div>
|
326 |
</td>
|
327 |
<td style="width:10px"></td>
|
328 |
<td valign="top">
|
329 |
Except the posts in category:
|
330 |
+
<?php $DW->dumpOpt($opt_single_category); ?>
|
331 |
<div id="single-category-select" class="condition-select" <?php echo $category_condition_select_style; ?>>
|
332 |
<?php foreach ( $category as $cat ) { ?>
|
333 |
+
<?php $js_category_array[ ] = '\'single_cat_act_' . $cat->cat_ID . '\''; ?>
|
334 |
+
<input type="checkbox" id="single_cat_act_<?php echo $cat->cat_ID; ?>" name="single_category_act[]" value="<?php echo $cat->cat_ID; ?>" <?php echo ( count($single_category_act) > 0 && in_array($cat->cat_ID,$single_category_act) ) ? 'checked="checked"' : ''; ?> onclick="ci('single_cat_act_<?php echo $cat->cat_ID; ?>')" /> <label for="single_cat_act_<?php echo $cat->cat_ID; ?>"><?php echo $cat->name; ?></label><br />
|
335 |
<?php } ?>
|
336 |
</div>
|
337 |
</td>
|
341 |
<br /><br />
|
342 |
|
343 |
<b>Pages</b><br />
|
344 |
+
Show widget default on pages?<br />
|
345 |
+
<?php $DW->dumpOpt($opt_page); ?>
|
346 |
<input type="radio" name="page" value="yes" id="page-yes" <?php echo $page_yes_selected; ?> /> <label for="page-yes">Yes</label>
|
347 |
<input type="radio" name="page" value="no" id="page-no" <?php echo $page_no_selected; ?> /> <label for="page-no">No</label><br />
|
348 |
+
Except the page(s):<br />
|
349 |
<div id="page-select" class="condition-select" <?php echo $page_condition_select_style; ?>>
|
350 |
<?php foreach ( $pages as $page ) { ?>
|
351 |
+
<input type="checkbox" id="page_act_<?php echo $page->ID; ?>" name="page_act[]" value="<?php echo $page->ID; ?>" <?php echo ( count($page_act) > 0 && in_array($page->ID,$page_act) ) ? 'checked="checked"' : ''; ?> /> <label for="page_act_<?php echo $page->ID; ?>"><?php echo $page->post_title; ?></label><br />
|
352 |
<?php } ?>
|
353 |
</div>
|
354 |
|
355 |
+
<br /><br />
|
356 |
+
|
357 |
+
<b>Author Pages</b><br />
|
358 |
+
Show widget default on author pages?<br />
|
359 |
+
<?php $DW->dumpOpt($opt_author); ?>
|
360 |
+
<input type="radio" name="author" value="yes" id="author-yes" <?php echo $author_yes_selected; ?> /> <label for="author-yes">Yes</label>
|
361 |
+
<input type="radio" name="author" value="no" id="author-no" <?php echo $author_no_selected; ?> /> <label for="author-no">No</label><br />
|
362 |
+
Except the author(s):<br />
|
363 |
+
<div id="author-select" class="condition-select" <?php echo $author_condition_select_style; ?>>
|
364 |
+
<?php foreach ( $authors as $author ) { ?>
|
365 |
+
<input type="checkbox" id="author_act_<?php echo $author->ID; ?>" name="author_act[]" value="<?php echo $author->ID; ?>" <?php echo ( count($author_act) > 0 && in_array($author->ID,$author_act) ) ? 'checked="checked"' : ''; ?> /> <label for="author_act_<?php echo $author->ID; ?>"><?php echo $author->display_name; ?></label><br />
|
366 |
+
<?php } ?></div>
|
367 |
+
|
368 |
+
<br /><br />
|
369 |
|
370 |
<b>Category Pages</b><br />
|
371 |
+
Show widget default on category pages?<br />
|
372 |
+
<?php $DW->dumpOpt($opt_category); ?>
|
373 |
<input type="radio" name="category" value="yes" id="category-yes" <?php echo $category_yes_selected; ?> /> <label for="category-yes">Yes</label>
|
374 |
<input type="radio" name="category" value="no" id="category-no" <?php echo $category_no_selected; ?> /> <label for="category-no">No</label><br />
|
375 |
Except the categories:<br />
|
376 |
<div id="category-select" class="condition-select" <?php echo $category_condition_select_style; ?>>
|
377 |
<?php foreach ( $category as $cat ) { ?>
|
378 |
+
<input type="checkbox" id="cat_act_<?php echo $cat->cat_ID; ?>" name="category_act[]" value="<?php echo $cat->cat_ID; ?>" <?php echo ( count($category_act) > 0 && in_array($cat->cat_ID,$category_act) ) ? 'checked="checked"' : ''; ?> /> <label for="cat_act_<?php echo $cat->cat_ID; ?>"><?php echo $cat->name; ?></label><br />
|
379 |
<?php } ?>
|
380 |
</div>
|
381 |
|
382 |
+
<br /><br />
|
383 |
|
384 |
+
<b>Archive Pages</b> <img src="<?php echo $DW->plugin_url; ?>img/info.gif" alt="info" title="Click to toggle info" onclick="divToggle('archive')" /><br />
|
385 |
Show widget on archive pages?<br />
|
386 |
+
<?php $DW->dumpOpt($opt_archive); ?>
|
387 |
+
<div>
|
388 |
<div id="archive" class="infotext">
|
389 |
+
This option does not include Author and Category Pages.
|
390 |
</div>
|
391 |
</div>
|
392 |
<input type="radio" name="archive" value="yes" id="archive-yes" <?php echo $archive_yes_selected; ?> /> <label for="archive-yes">Yes</label>
|
394 |
|
395 |
<br /><br />
|
396 |
|
397 |
+
<b>Error Page</b><br />
|
398 |
+
Show widget on the error page?<br />
|
399 |
+
<?php $DW->dumpOpt($opt_e404); ?>
|
400 |
<input type="radio" name="e404" value="yes" id="e404-yes" <?php echo $e404_yes_selected; ?> /> <label for="e404-yes">Yes</label>
|
401 |
<input type="radio" name="e404" value="no" id="e404-no" <?php echo $e404_no_selected; ?> /> <label for="e404-no">No</label>
|
402 |
|
405 |
<input class="button-primary" type="submit" value="Save" />
|
406 |
</form>
|
407 |
|
408 |
+
<?php $url = (! empty($_GET['returnurl']) ) ? $_GET['returnurl'] : 'themes.php?page=dynwid-config'; ?>
|
409 |
+
<input class="button-secondary" type="submit" value="Return" style="position:relative;top:-23px;left:80px;" onclick="location.href='<?php echo $url; ?>'" />
|
|
|
|
|
410 |
|
411 |
<script type="text/javascript">
|
412 |
+
function chkInPosts() {
|
413 |
+
var posts = <?php echo count($single_post_act); ?>;
|
414 |
+
var tags = <?php echo count($single_tag_act); ?>;
|
415 |
+
|
416 |
+
if ( (posts > 0 || tags > 0) && document.getElementById('individual').checked == false ) {
|
417 |
+
if ( confirm('Are you sure you want to disable the exception rule for individual posts and tags?\nThis will remove the options set to individual posts and/or tags for this widget.\nOk = Yes; No = Cancel') ) {
|
418 |
+
swChb(cAuthors, false);
|
419 |
+
swChb(cCat, false);
|
420 |
+
} else {
|
421 |
+
document.getElementById('individual').checked = true;
|
422 |
+
}
|
423 |
+
} else if ( icount > 0 && document.getElementById('individual').checked ) {
|
424 |
+
if ( confirm('Are you sure you want to enable the exception rule for individual posts and tags?\nThis will remove the exceptions set for Author and/or Category on single posts for this widget.\nOk = Yes; No = Cancel') ) {
|
425 |
+
swChb(cAuthors, true);
|
426 |
+
swChb(cCat, true);
|
427 |
+
} else {
|
428 |
+
document.getElementById('individual').checked = false;
|
429 |
+
}
|
430 |
+
} else if ( document.getElementById('individual').checked ) {
|
431 |
+
swChb(cAuthors, true);
|
432 |
+
swChb(cCat, true);
|
433 |
+
} else {
|
434 |
+
swChb(cAuthors, false);
|
435 |
+
swChb(cCat, false);
|
436 |
}
|
|
|
437 |
}
|
438 |
|
439 |
+
function ci(id) {
|
440 |
+
if ( document.getElementById(id).checked ) {
|
441 |
+
icount++;
|
442 |
+
} else {
|
443 |
+
icount--;
|
444 |
}
|
445 |
}
|
446 |
|
447 |
+
function divToggle(div) {
|
448 |
+
div = '#'+div;
|
449 |
+
jQuery(div).slideToggle(400);
|
450 |
+
}
|
451 |
|
452 |
+
function swChb(c, s) {
|
453 |
+
for ( i = 0; i < c.length; i++ ) {
|
454 |
+
if ( s == true ) {
|
455 |
+
document.getElementById(c[i]).checked = false;
|
456 |
+
}
|
457 |
+
document.getElementById(c[i]).disabled = s;
|
458 |
}
|
459 |
}
|
460 |
|
461 |
+
var cAuthors = new Array(<?php echo implode(', ', $js_author_array); ?>);
|
462 |
+
var cCat = new Array(<?php echo implode(', ', $js_category_array); ?>);
|
463 |
+
var cRole = new Array(<?php echo implode(', ' , $jsroles); ?>);
|
464 |
+
var icount = <?php echo $js_count; ?>;
|
465 |
+
|
466 |
if ( document.getElementById('role-yes').checked ) {
|
467 |
+
swChb(cRole, true);
|
468 |
+
}
|
469 |
+
if ( document.getElementById('individual').checked ) {
|
470 |
+
swChb(cAuthors, true);
|
471 |
+
swChb(cCat, true);
|
472 |
}
|
|
|
|
|
|
|
|
|
473 |
</script>
|
dynwid_admin_overview.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* dynwid_admin_overview.php - Overview page
|
4 |
+
*
|
5 |
+
* @version $Id: dynwid_admin_overview.php 207183 2010-02-17 17:54:48Z qurl $
|
6 |
+
*/
|
7 |
+
|
8 |
+
// Special case: Reset action needs to go back to overview.
|
9 |
+
if ( $_GET['action'] == 'reset' ) {
|
10 |
+
check_admin_referer('plugin-name-action_reset_' . $_GET['id']);
|
11 |
+
$DW->resetOptions($_GET['id']);
|
12 |
+
?>
|
13 |
+
<div class="updated fade" id="message">
|
14 |
+
<p>
|
15 |
+
<strong>Widget options have been reset to default.</strong><br />
|
16 |
+
</p>
|
17 |
+
</div>
|
18 |
+
<?php
|
19 |
+
}
|
20 |
+
|
21 |
+
foreach ( $DW->sidebars as $sidebar_id => $widgets ) {
|
22 |
+
if ( count($widgets) > 0 ) {
|
23 |
+
if ( $sidebar_id == 'wp_inactive_widgets' ) {
|
24 |
+
$name = 'Inactive Widgets';
|
25 |
+
} else {
|
26 |
+
$name = $DW->getName($sidebar_id, 'S');
|
27 |
+
}
|
28 |
+
?>
|
29 |
+
|
30 |
+
<div class="postbox-container" style="width:48%;margin-top:10px;margin-right:10px;">
|
31 |
+
<table cellspacing="0" class="widefat fixed">
|
32 |
+
<thead>
|
33 |
+
<tr>
|
34 |
+
<th class="managage-column" scope="col"><?php echo $name; ?></th>
|
35 |
+
<th style="width:70px"> </th>
|
36 |
+
</tr>
|
37 |
+
</thead>
|
38 |
+
|
39 |
+
<tbody class="list:link-cat" id="<?php echo str_replace('-', '_', $sidebar_id); ?>">
|
40 |
+
<?php foreach ( $widgets as $widget_id ) {
|
41 |
+
$name = $DW->getName($widget_id);
|
42 |
+
// When $name is empty, we have a widget which not belongs here
|
43 |
+
if (! empty($name) ) {
|
44 |
+
?>
|
45 |
+
<tr>
|
46 |
+
<td class="name">
|
47 |
+
<p class="row-title"><a title="Edit this widget options" href="themes.php?page=dynwid-config&action=edit&id=<?php echo $widget_id; ?>"><?php echo $name; ?></a></p>
|
48 |
+
<div class="row-actions">
|
49 |
+
<span class="edit">
|
50 |
+
<a title="Edit this widget options" href="themes.php?page=dynwid-config&action=edit&id=<?php echo $widget_id; ?>">Edit</a>
|
51 |
+
</span>
|
52 |
+
<?php if ( $DW->hasOptions($widget_id) ) { ?>
|
53 |
+
<span class="delete">
|
54 |
+
<?php $href = wp_nonce_url('themes.php?page=dynwid-config&action=reset&id=' . $widget_id, 'plugin-name-action_reset_' . $widget_id); ?>
|
55 |
+
| <a class="submitdelete" title="Reset widget to Static" onclick="if ( confirm('You are about to reset this widget \'<?php echo strip_tags($DW->getName($widget_id)); ?>\'\n \'Cancel\' to stop, \'OK\' to reset.') ) { return true;}return false;" href="<?php echo $href; ?>">Reset</a>
|
56 |
+
</span>
|
57 |
+
<?php } ?>
|
58 |
+
</div>
|
59 |
+
</td>
|
60 |
+
<td>
|
61 |
+
<?php echo ( $DW->hasOptions($widget_id) ) ? 'Dynamic' : 'Static'; ?>
|
62 |
+
</td>
|
63 |
+
</tr>
|
64 |
+
<?php } // END if (! empty($name) ) ?>
|
65 |
+
<?php } // END foreach ( $widgets as $widget_id ) ?>
|
66 |
+
</tbody>
|
67 |
+
</table>
|
68 |
+
</div>
|
69 |
+
<?php
|
70 |
+
} // END if ( count($widgets) > 0 )
|
71 |
+
} // END foreach ( $DW->sidebars as $sidebar_id => $widgets )
|
72 |
+
?>
|
73 |
+
|
74 |
+
<div class="clear"><br /><br /></div>
|
75 |
+
|
76 |
+
<a href="#" onclick="jQuery('#un').slideToggle('fast'); return false;">Advanced ></a>
|
77 |
+
<div id="un" style="display:none">
|
78 |
+
<br />
|
79 |
+
For debugging purposes it is possible you're asked to create a dump. Click the 'Create dump' button and save the text file.
|
80 |
+
<br /><br />
|
81 |
+
<div id="dump">
|
82 |
+
<form action="" method="get">
|
83 |
+
<input type="hidden" name="action" value="dynwid_dump" />
|
84 |
+
<input class="button-primary" type="submit" value="Create dump" />
|
85 |
+
</form>
|
86 |
+
</div>
|
87 |
+
|
88 |
+
<br /><br />
|
89 |
+
|
90 |
+
If you deceide not to use this plugin anymore (sorry to hear that!). You can cleanup all settings and data related to this plugin by clicking on the 'Uninstall' button. This process is irreversible! After the cleanup the plugin is deactivated automaticly.
|
91 |
+
<br /><br />
|
92 |
+
<div id="uninstall">
|
93 |
+
<form action="" method="get">
|
94 |
+
<input type="hidden" name="action" value="dynwid_uninstall" />
|
95 |
+
<input class="button-primary" type="submit" value="Uninstall" onclick="if ( confirm('Are you sure you want to uninstall Dynamic Widgets?') ) { return true; } return false;" />
|
96 |
+
</form>
|
97 |
+
</div>
|
98 |
+
</div>
|
dynwid_admin_save.php
CHANGED
@@ -2,19 +2,19 @@
|
|
2 |
/**
|
3 |
* dynwid_admin_save.php - Saving options to the database
|
4 |
*
|
5 |
-
* @version $Id: dynwid_admin_save.php
|
6 |
*/
|
7 |
|
8 |
// Security - nonce
|
9 |
check_admin_referer('plugin-name-action_edit_' . $_POST['widget_id']);
|
10 |
|
11 |
-
|
12 |
-
if (
|
13 |
-
$
|
|
|
14 |
}
|
15 |
|
16 |
-
|
17 |
-
$fields = array('role', 'front-page', 'single', 'page', 'category', 'archive', 'e404' );
|
18 |
$work = FALSE;
|
19 |
foreach ( $fields as $field ) {
|
20 |
if ( $_POST[$field] == 'yes' ) {
|
@@ -23,7 +23,14 @@
|
|
23 |
}
|
24 |
}
|
25 |
if (! $work ) {
|
26 |
-
$fields = array('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
foreach ( $fields as $field ) {
|
28 |
if ( count($_POST[$field]) > 0 ) {
|
29 |
$work = TRUE;
|
@@ -31,15 +38,18 @@
|
|
31 |
}
|
32 |
}
|
33 |
}
|
|
|
|
|
|
|
|
|
|
|
34 |
if (! $work ) {
|
35 |
wp_redirect( get_option('siteurl') . $_SERVER['REQUEST_URI'] . '&work=none' );
|
36 |
die();
|
37 |
}
|
38 |
|
39 |
-
//
|
40 |
-
|
41 |
-
$DW->resetOptions($_POST['widget_id']);
|
42 |
-
}
|
43 |
|
44 |
// Role
|
45 |
if ( $_POST['role'] == 'no' && count($_POST['role_act']) > 0 ) {
|
@@ -72,6 +82,17 @@
|
|
72 |
$DW->addMultiOption($_POST['widget_id'], 'single-category', $_POST['single'], $_POST['single_category_act']);
|
73 |
}
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
// Pages
|
76 |
if ( count($_POST['page_act']) > 0 ) {
|
77 |
$DW->addMultiOption($_POST['widget_id'], 'page', $_POST['page'], $_POST['page_act']);
|
@@ -79,6 +100,13 @@
|
|
79 |
$DW->addSingleOption($_POST['widget_id'], 'page');
|
80 |
}
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
// Categories
|
83 |
if ( count($_POST['category_act']) > 0 ) {
|
84 |
$DW->addMultiOption($_POST['widget_id'], 'category', $_POST['category'], $_POST['category_act']);
|
@@ -95,4 +123,31 @@
|
|
95 |
if ( $_POST['e404'] == 'no' ) {
|
96 |
$DW->addSingleOption($_POST['widget_id'], 'e404');
|
97 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
?>
|
2 |
/**
|
3 |
* dynwid_admin_save.php - Saving options to the database
|
4 |
*
|
5 |
+
* @version $Id: dynwid_admin_save.php 207183 2010-02-17 17:54:48Z qurl $
|
6 |
*/
|
7 |
|
8 |
// Security - nonce
|
9 |
check_admin_referer('plugin-name-action_edit_' . $_POST['widget_id']);
|
10 |
|
11 |
+
// Checking basic stuff
|
12 |
+
if ( $_POST['role'] == 'no' && count($_POST['role_act']) == 0 ) {
|
13 |
+
wp_redirect( get_option('siteurl') . $_SERVER['REQUEST_URI'] . '&work=none' );
|
14 |
+
die();
|
15 |
}
|
16 |
|
17 |
+
$fields = array('front-page', 'single', 'page', 'author', 'category', 'archive', 'e404');
|
|
|
18 |
$work = FALSE;
|
19 |
foreach ( $fields as $field ) {
|
20 |
if ( $_POST[$field] == 'yes' ) {
|
23 |
}
|
24 |
}
|
25 |
if (! $work ) {
|
26 |
+
$fields = array('single_author_act',
|
27 |
+
'single_category_act',
|
28 |
+
'single_post_act',
|
29 |
+
'single_tag_act',
|
30 |
+
'page_act',
|
31 |
+
'author_act',
|
32 |
+
'category_act'
|
33 |
+
);
|
34 |
foreach ( $fields as $field ) {
|
35 |
if ( count($_POST[$field]) > 0 ) {
|
36 |
$work = TRUE;
|
38 |
}
|
39 |
}
|
40 |
}
|
41 |
+
if (! $work) {
|
42 |
+
if ( $_POST['individual'] == '1' ) {
|
43 |
+
$work = TRUE;
|
44 |
+
}
|
45 |
+
}
|
46 |
if (! $work ) {
|
47 |
wp_redirect( get_option('siteurl') . $_SERVER['REQUEST_URI'] . '&work=none' );
|
48 |
die();
|
49 |
}
|
50 |
|
51 |
+
// Removing already set options
|
52 |
+
$DW->resetOptions($_POST['widget_id']);
|
|
|
|
|
53 |
|
54 |
// Role
|
55 |
if ( $_POST['role'] == 'no' && count($_POST['role_act']) > 0 ) {
|
82 |
$DW->addMultiOption($_POST['widget_id'], 'single-category', $_POST['single'], $_POST['single_category_act']);
|
83 |
}
|
84 |
|
85 |
+
// -- Individual / Posts / Tag
|
86 |
+
if ( $_POST['individual'] == '1' ) {
|
87 |
+
$DW->addSingleOption($_POST['widget_id'], 'individual', '1');
|
88 |
+
if ( count($_POST['single_post_act']) > 0 ) {
|
89 |
+
$DW->addMultiOption($_POST['widget_id'], 'single-post', $_POST['single'], $_POST['single_post_act']);
|
90 |
+
}
|
91 |
+
if ( count($_POST['single_tag_act']) > 0 ) {
|
92 |
+
$DW->addMultiOption($_POST['widget_id'], 'single-tag', $_POST['single'], $_POST['single_tag_act']);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
// Pages
|
97 |
if ( count($_POST['page_act']) > 0 ) {
|
98 |
$DW->addMultiOption($_POST['widget_id'], 'page', $_POST['page'], $_POST['page_act']);
|
100 |
$DW->addSingleOption($_POST['widget_id'], 'page');
|
101 |
}
|
102 |
|
103 |
+
// Author
|
104 |
+
if ( count($_POST['author_act']) > 0 ) {
|
105 |
+
$DW->addMultiOption($_POST['widget_id'], 'author', $_POST['author'], $_POST['author_act']);
|
106 |
+
} else if ( $_POST['author'] == 'no' ) {
|
107 |
+
$DW->addSingleOption($_POST['widget_id'], 'author');
|
108 |
+
}
|
109 |
+
|
110 |
// Categories
|
111 |
if ( count($_POST['category_act']) > 0 ) {
|
112 |
$DW->addMultiOption($_POST['widget_id'], 'category', $_POST['category'], $_POST['category_act']);
|
123 |
if ( $_POST['e404'] == 'no' ) {
|
124 |
$DW->addSingleOption($_POST['widget_id'], 'e404');
|
125 |
}
|
126 |
+
|
127 |
+
// Redirect to ReturnURL
|
128 |
+
if (! empty($_POST['returnurl']) ) {
|
129 |
+
$q = array();
|
130 |
+
|
131 |
+
// Checking if there are arguments set
|
132 |
+
$pos = strpos($_POST['returnurl'],'?');
|
133 |
+
if ( $pos !== FALSE ) {
|
134 |
+
// evaluate the args
|
135 |
+
$query_string = substr($_POST['returnurl'], ($pos+1));
|
136 |
+
$args = explode('&', $query_string);
|
137 |
+
foreach ( $args as $arg ) {
|
138 |
+
@list($name,$value) = explode('=', $arg);
|
139 |
+
if ( $name != 'dynwid_save' && $name != 'widget_id' ) {
|
140 |
+
$q[ ] = $name . '=' . $value;
|
141 |
+
}
|
142 |
+
}
|
143 |
+
$script_url = substr($_POST['returnurl'],0,$pos);
|
144 |
+
} else {
|
145 |
+
$script_url = $_POST['returnurl'];
|
146 |
+
}
|
147 |
+
$q[ ] = 'dynwid_save=yes';
|
148 |
+
$q[ ] = 'widget_id=' . $_POST['widget_id'];
|
149 |
+
|
150 |
+
wp_redirect( get_option('siteurl') . $script_url . '?' . implode('&', $q) );
|
151 |
+
die();
|
152 |
+
}
|
153 |
?>
|
dynwid_class.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
<?
|
2 |
/**
|
3 |
-
* dynwid_class.php - Dynamic Widgets Class
|
4 |
*
|
5 |
-
* @version $Id: dynwid_class.php
|
6 |
*/
|
7 |
|
8 |
class dynWid {
|
@@ -10,6 +10,7 @@
|
|
10 |
public $dynwid_list;
|
11 |
private $firstmessage;
|
12 |
private $registered_sidebars;
|
|
|
13 |
public $registered_widgets;
|
14 |
public $sidebars;
|
15 |
public $plugin_url;
|
@@ -17,23 +18,20 @@
|
|
17 |
private $wpdb;
|
18 |
|
19 |
public function __construct() {
|
20 |
-
global $current_user, $wp_registered_sidebars, $wp_registered_widgets, $wpdb;
|
21 |
-
// $wp_registered_widget_controls
|
22 |
-
|
23 |
if ( is_user_logged_in() ) {
|
24 |
-
|
25 |
-
$this->userrole = $current_user->roles[0];
|
26 |
} else {
|
27 |
$this->userrole = 'anonymous';
|
28 |
}
|
29 |
|
30 |
$this->firstmessage = TRUE;
|
31 |
-
$this->registered_sidebars = $wp_registered_sidebars;
|
32 |
-
$this->
|
|
|
33 |
$this->sidebars = wp_get_sidebars_widgets();
|
34 |
$this->plugin_url = WP_PLUGIN_URL . '/' . str_replace( basename(__FILE__), '', plugin_basename(__FILE__) );
|
35 |
|
36 |
-
$this->wpdb = $wpdb;
|
37 |
$this->dbtable = $this->wpdb->prefix . DW_DB_TABLE;
|
38 |
|
39 |
$this->createList();
|
@@ -49,13 +47,13 @@
|
|
49 |
}
|
50 |
|
51 |
$query = "INSERT INTO " . $this->dbtable . "
|
52 |
-
(widget_id,maintype,name,value)
|
53 |
VALUES
|
54 |
('" . $widget_id . "', '" . $maintype . "', 'default', '" . $opt_default . "')";
|
55 |
$this->wpdb->query($query);
|
56 |
foreach ( $act as $option ) {
|
57 |
$query = "INSERT INTO " . $this->dbtable . "
|
58 |
-
(widget_id,maintype,name,value)
|
59 |
VALUES
|
60 |
('" . $widget_id . "', '" . $maintype . "', '" . $option . "', '" . $opt_act . "')";
|
61 |
$this->wpdb->query($query);
|
@@ -64,7 +62,7 @@
|
|
64 |
|
65 |
public function addSingleOption($widget_id, $maintype, $value = '0') {
|
66 |
$query = "INSERT INTO " . $this->dbtable . "
|
67 |
-
(widget_id,maintype,value)
|
68 |
VALUES
|
69 |
('" . $widget_id . "', '" . $maintype . "', '" . $value . "')";
|
70 |
$this->wpdb->query($query);
|
@@ -79,9 +77,17 @@
|
|
79 |
if ( $this->hasOptions($widget_id) ) {
|
80 |
$this->dynwid_list[ ] = $widget_id;
|
81 |
}
|
82 |
-
}
|
83 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
|
|
85 |
}
|
86 |
|
87 |
public function detectPage() {
|
@@ -91,9 +97,11 @@
|
|
91 |
return 'single';
|
92 |
} else if ( is_page() ) {
|
93 |
return 'page';
|
|
|
|
|
94 |
} else if ( is_category() ) {
|
95 |
return 'category';
|
96 |
-
} else if ( is_archive() && ! is_category() ) {
|
97 |
return 'archive';
|
98 |
} else if ( is_404() ) {
|
99 |
return 'e404';
|
@@ -103,21 +111,34 @@
|
|
103 |
}
|
104 |
|
105 |
public function dump() {
|
106 |
-
|
107 |
-
|
108 |
-
echo "wp version: " . $wp_version . "\n";
|
109 |
echo "dw version: " . DW_VERSION . "\n";
|
110 |
-
echo "php version: " .
|
111 |
|
112 |
echo "\n";
|
113 |
echo "list: \n";
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
|
116 |
echo "wp_registered_widgets: \n";
|
117 |
print_r($this->registered_widgets);
|
118 |
|
119 |
echo "options: \n";
|
120 |
print_r( $this->getOptions('%', NULL) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
|
123 |
public function getName($id, $type = 'W') {
|
@@ -153,13 +174,13 @@
|
|
153 |
$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
|
154 |
WHERE widget_id LIKE '" . $widget_id . "'
|
155 |
AND maintype LIKE '" . $maintype . "%'
|
156 |
-
ORDER BY name";
|
157 |
|
158 |
} else {
|
159 |
$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
|
160 |
WHERE widget_id LIKE '" . $widget_id . "'
|
161 |
AND (maintype LIKE '" . $maintype . "%' OR maintype = 'role')
|
162 |
-
ORDER BY name";
|
163 |
}
|
164 |
$results = $this->wpdb->get_results($query);
|
165 |
|
@@ -175,7 +196,9 @@
|
|
175 |
}
|
176 |
|
177 |
public function hasOptions($widget_id) {
|
178 |
-
$query =
|
|
|
|
|
179 |
$count = $this->wpdb->get_var($this->wpdb->prepare($query));
|
180 |
|
181 |
if ( $count > 0 ) {
|
@@ -186,7 +209,7 @@
|
|
186 |
}
|
187 |
|
188 |
public function message($text) {
|
189 |
-
if (
|
190 |
if ( $this->firstmessage ) {
|
191 |
echo "\n";
|
192 |
$this->firstmessage = FALSE;
|
1 |
+
<?php
|
2 |
/**
|
3 |
+
* dynwid_class.php - Dynamic Widgets Class (PHP5)
|
4 |
*
|
5 |
+
* @version $Id: dynwid_class.php 207183 2010-02-17 17:54:48Z qurl $
|
6 |
*/
|
7 |
|
8 |
class dynWid {
|
10 |
public $dynwid_list;
|
11 |
private $firstmessage;
|
12 |
private $registered_sidebars;
|
13 |
+
public $registered_widget_controls;
|
14 |
public $registered_widgets;
|
15 |
public $sidebars;
|
16 |
public $plugin_url;
|
18 |
private $wpdb;
|
19 |
|
20 |
public function __construct() {
|
|
|
|
|
|
|
21 |
if ( is_user_logged_in() ) {
|
22 |
+
$this->userrole = $GLOBALS['current_user']->roles[0];
|
|
|
23 |
} else {
|
24 |
$this->userrole = 'anonymous';
|
25 |
}
|
26 |
|
27 |
$this->firstmessage = TRUE;
|
28 |
+
$this->registered_sidebars = $GLOBALS['wp_registered_sidebars'];
|
29 |
+
$this->registered_widget_controls = &$GLOBALS['wp_registered_widget_controls'];
|
30 |
+
$this->registered_widgets = &$GLOBALS['wp_registered_widgets'];
|
31 |
$this->sidebars = wp_get_sidebars_widgets();
|
32 |
$this->plugin_url = WP_PLUGIN_URL . '/' . str_replace( basename(__FILE__), '', plugin_basename(__FILE__) );
|
33 |
|
34 |
+
$this->wpdb = $GLOBALS['wpdb'];
|
35 |
$this->dbtable = $this->wpdb->prefix . DW_DB_TABLE;
|
36 |
|
37 |
$this->createList();
|
47 |
}
|
48 |
|
49 |
$query = "INSERT INTO " . $this->dbtable . "
|
50 |
+
(widget_id, maintype, name, value)
|
51 |
VALUES
|
52 |
('" . $widget_id . "', '" . $maintype . "', 'default', '" . $opt_default . "')";
|
53 |
$this->wpdb->query($query);
|
54 |
foreach ( $act as $option ) {
|
55 |
$query = "INSERT INTO " . $this->dbtable . "
|
56 |
+
(widget_id, maintype, name, value)
|
57 |
VALUES
|
58 |
('" . $widget_id . "', '" . $maintype . "', '" . $option . "', '" . $opt_act . "')";
|
59 |
$this->wpdb->query($query);
|
62 |
|
63 |
public function addSingleOption($widget_id, $maintype, $value = '0') {
|
64 |
$query = "INSERT INTO " . $this->dbtable . "
|
65 |
+
(widget_id, maintype, value)
|
66 |
VALUES
|
67 |
('" . $widget_id . "', '" . $maintype . "', '" . $value . "')";
|
68 |
$this->wpdb->query($query);
|
77 |
if ( $this->hasOptions($widget_id) ) {
|
78 |
$this->dynwid_list[ ] = $widget_id;
|
79 |
}
|
80 |
+
} // END foreach widgets
|
81 |
}
|
82 |
+
} // END foreach sidebars
|
83 |
+
}
|
84 |
+
|
85 |
+
public function deleteOption($widget_id, $maintype, $name = '') {
|
86 |
+
$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = '" .$widget_id . "' AND maintype = '" .$maintype ."'";
|
87 |
+
if (! empty($name) ) {
|
88 |
+
$query .= " AND (name = '" . $name . "' OR name = 'default')";
|
89 |
}
|
90 |
+
$this->wpdb->query($query);
|
91 |
}
|
92 |
|
93 |
public function detectPage() {
|
97 |
return 'single';
|
98 |
} else if ( is_page() ) {
|
99 |
return 'page';
|
100 |
+
} else if ( is_author() ) {
|
101 |
+
return 'author';
|
102 |
} else if ( is_category() ) {
|
103 |
return 'category';
|
104 |
+
} else if ( is_archive() && ! is_category() && ! is_author() ) {
|
105 |
return 'archive';
|
106 |
} else if ( is_404() ) {
|
107 |
return 'e404';
|
111 |
}
|
112 |
|
113 |
public function dump() {
|
114 |
+
echo "wp version: " . $GLOBALS['wp_version'] . "\n";
|
|
|
|
|
115 |
echo "dw version: " . DW_VERSION . "\n";
|
116 |
+
echo "php version: " . PHP_VERSION . "\n";
|
117 |
|
118 |
echo "\n";
|
119 |
echo "list: \n";
|
120 |
+
$list = array();
|
121 |
+
foreach ( $this->dynwid_list as $widget_id ) {
|
122 |
+
$list[$widget_id] = strip_tags($this->getName($widget_id));
|
123 |
+
}
|
124 |
+
print_r($list);
|
125 |
|
126 |
echo "wp_registered_widgets: \n";
|
127 |
print_r($this->registered_widgets);
|
128 |
|
129 |
echo "options: \n";
|
130 |
print_r( $this->getOptions('%', NULL) );
|
131 |
+
|
132 |
+
echo "\n";
|
133 |
+
echo serialize($this->getOptions('%', NULL));
|
134 |
+
}
|
135 |
+
|
136 |
+
public function dumpOpt($opt) {
|
137 |
+
if ( DW_DEBUG && count($opt) > 0 ) {
|
138 |
+
echo '<pre>';
|
139 |
+
print_r($opt);
|
140 |
+
echo '</pre>';
|
141 |
+
}
|
142 |
}
|
143 |
|
144 |
public function getName($id, $type = 'W') {
|
174 |
$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
|
175 |
WHERE widget_id LIKE '" . $widget_id . "'
|
176 |
AND maintype LIKE '" . $maintype . "%'
|
177 |
+
ORDER BY maintype, name";
|
178 |
|
179 |
} else {
|
180 |
$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
|
181 |
WHERE widget_id LIKE '" . $widget_id . "'
|
182 |
AND (maintype LIKE '" . $maintype . "%' OR maintype = 'role')
|
183 |
+
ORDER BY maintype, name";
|
184 |
}
|
185 |
$results = $this->wpdb->get_results($query);
|
186 |
|
196 |
}
|
197 |
|
198 |
public function hasOptions($widget_id) {
|
199 |
+
$query = "SELECT COUNT(1) AS total FROM " . $this->dbtable . "
|
200 |
+
WHERE widget_id = '" . $widget_id . "' AND
|
201 |
+
maintype != 'individual'";
|
202 |
$count = $this->wpdb->get_var($this->wpdb->prepare($query));
|
203 |
|
204 |
if ( $count > 0 ) {
|
209 |
}
|
210 |
|
211 |
public function message($text) {
|
212 |
+
if ( DW_DEBUG ) {
|
213 |
if ( $this->firstmessage ) {
|
214 |
echo "\n";
|
215 |
$this->firstmessage = FALSE;
|
dynwid_class_php4.php
ADDED
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* dynwid_class_php4.php - Dynamic Widgets Class for PHP4
|
4 |
+
* Needs at least PHP 4.1.0
|
5 |
+
*
|
6 |
+
* @version $Id: dynwid_class_php4.php 207183 2010-02-17 17:54:48Z qurl $
|
7 |
+
*/
|
8 |
+
|
9 |
+
class dynWid {
|
10 |
+
var $dbtable; /* private */
|
11 |
+
var $dynwid_list;
|
12 |
+
var $firstmessage; /* private */
|
13 |
+
var $registered_sidebars; /* private */
|
14 |
+
var $registered_widget_controls;
|
15 |
+
var $registered_widgets;
|
16 |
+
var $sidebars;
|
17 |
+
var $plugin_url;
|
18 |
+
var $userrole;
|
19 |
+
var $wpdb; /* private */
|
20 |
+
|
21 |
+
/* Old constructor redirect to new constructor */
|
22 |
+
function dynWid() {
|
23 |
+
$this->__construct();
|
24 |
+
}
|
25 |
+
|
26 |
+
function __construct() {
|
27 |
+
if ( is_user_logged_in() ) {
|
28 |
+
$this->userrole = $GLOBALS['current_user']->roles[0];
|
29 |
+
} else {
|
30 |
+
$this->userrole = 'anonymous';
|
31 |
+
}
|
32 |
+
|
33 |
+
$this->firstmessage = TRUE;
|
34 |
+
$this->registered_sidebars = $GLOBALS['wp_registered_sidebars'];
|
35 |
+
$this->registered_widget_controls = &$GLOBALS['wp_registered_widget_controls'];
|
36 |
+
$this->registered_widgets = &$GLOBALS['wp_registered_widgets'];
|
37 |
+
$this->sidebars = wp_get_sidebars_widgets();
|
38 |
+
$this->plugin_url = WP_PLUGIN_URL . '/' . str_replace( basename(__FILE__), '', plugin_basename(__FILE__) );
|
39 |
+
|
40 |
+
$this->wpdb = $GLOBALS['wpdb'];
|
41 |
+
$this->dbtable = $this->wpdb->prefix . DW_DB_TABLE;
|
42 |
+
|
43 |
+
$this->createList();
|
44 |
+
}
|
45 |
+
|
46 |
+
function addMultiOption($widget_id, $maintype, $default, $act) {
|
47 |
+
if ( $default == 'no' ) {
|
48 |
+
$opt_default = '0';
|
49 |
+
$opt_act = '1';
|
50 |
+
} else {
|
51 |
+
$opt_default = '1';
|
52 |
+
$opt_act = '0';
|
53 |
+
}
|
54 |
+
|
55 |
+
$query = "INSERT INTO " . $this->dbtable . "
|
56 |
+
(widget_id, maintype, name, value)
|
57 |
+
VALUES
|
58 |
+
('" . $widget_id . "', '" . $maintype . "', 'default', '" . $opt_default . "')";
|
59 |
+
$this->wpdb->query($query);
|
60 |
+
foreach ( $act as $option ) {
|
61 |
+
$query = "INSERT INTO " . $this->dbtable . "
|
62 |
+
(widget_id, maintype, name, value)
|
63 |
+
VALUES
|
64 |
+
('" . $widget_id . "', '" . $maintype . "', '" . $option . "', '" . $opt_act . "')";
|
65 |
+
$this->wpdb->query($query);
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
function addSingleOption($widget_id, $maintype, $value = '0') {
|
70 |
+
$query = "INSERT INTO " . $this->dbtable . "
|
71 |
+
(widget_id, maintype, value)
|
72 |
+
VALUES
|
73 |
+
('" . $widget_id . "', '" . $maintype . "', '" . $value . "')";
|
74 |
+
$this->wpdb->query($query);
|
75 |
+
}
|
76 |
+
|
77 |
+
/* private function */
|
78 |
+
function createList() {
|
79 |
+
$this->dynwid_list = array();
|
80 |
+
|
81 |
+
foreach ( $this->sidebars as $sidebar_id => $widgets ) {
|
82 |
+
if ( count($widgets) > 0 ) {
|
83 |
+
foreach ( $widgets as $widget_id ) {
|
84 |
+
if ( $this->hasOptions($widget_id) ) {
|
85 |
+
$this->dynwid_list[ ] = $widget_id;
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
function deleteOption($widget_id, $maintype, $name = '') {
|
93 |
+
$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = '" .$widget_id . "' AND maintype = '" .$maintype ."'";
|
94 |
+
if (! empty($name) ) {
|
95 |
+
$query .= " AND (name = '" . $name . "' OR name = 'default')";
|
96 |
+
}
|
97 |
+
$this->wpdb->query($query);
|
98 |
+
}
|
99 |
+
|
100 |
+
function detectPage() {
|
101 |
+
if ( is_front_page() ) {
|
102 |
+
return 'front-page';
|
103 |
+
} else if ( is_single() ) {
|
104 |
+
return 'single';
|
105 |
+
} else if ( is_page() ) {
|
106 |
+
return 'page';
|
107 |
+
} else if ( is_author() ) {
|
108 |
+
return 'author';
|
109 |
+
} else if ( is_category() ) {
|
110 |
+
return 'category';
|
111 |
+
} else if ( is_archive() && ! is_category() && ! is_author() ) {
|
112 |
+
return 'archive';
|
113 |
+
} else if ( is_404() ) {
|
114 |
+
return 'e404';
|
115 |
+
} else {
|
116 |
+
return 'undef';
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
function dump() {
|
121 |
+
echo "wp version: " . $GLOBALS['wp_version'] . "\n";
|
122 |
+
echo "dw version: " . DW_VERSION . "\n";
|
123 |
+
echo "php version: " . PHP_VERSION . "\n";
|
124 |
+
|
125 |
+
echo "\n";
|
126 |
+
echo "list: \n";
|
127 |
+
$list = array();
|
128 |
+
foreach ( $this->dynwid_list as $widget_id ) {
|
129 |
+
$list[$widget_id] = strip_tags($this->getName($widget_id));
|
130 |
+
}
|
131 |
+
print_r($list);
|
132 |
+
|
133 |
+
echo "wp_registered_widgets: \n";
|
134 |
+
print_r($this->registered_widgets);
|
135 |
+
|
136 |
+
echo "options: \n";
|
137 |
+
print_r( $this->getOptions('%', NULL) );
|
138 |
+
|
139 |
+
echo "\n";
|
140 |
+
echo serialize($this->getOptions('%', NULL));
|
141 |
+
}
|
142 |
+
|
143 |
+
function dumpOpt($opt) {
|
144 |
+
if ( DW_DEBUG && count($opt) > 0 ) {
|
145 |
+
echo '<pre>';
|
146 |
+
print_r($opt);
|
147 |
+
echo '</pre>';
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
function getName($id, $type = 'W') {
|
152 |
+
switch ( $type ) {
|
153 |
+
case 'S':
|
154 |
+
$lookup = $this->registered_sidebars;
|
155 |
+
break;
|
156 |
+
|
157 |
+
default:
|
158 |
+
$lookup = $this->registered_widgets;
|
159 |
+
// end default
|
160 |
+
}
|
161 |
+
|
162 |
+
$name = $lookup[$id]['name'];
|
163 |
+
|
164 |
+
if ( $type == 'W' ) {
|
165 |
+
// Retrieve optional set title
|
166 |
+
$number = $lookup[$id]['params'][0]['number'];
|
167 |
+
$option_name = $lookup[$id]['callback'][0]->option_name;
|
168 |
+
$option = get_option($option_name);
|
169 |
+
if (! empty($option[$number]['title']) ) {
|
170 |
+
$name .= ': <span class="in-widget-title">' . $option[$number]['title'] . '</span>';
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
return $name;
|
175 |
+
}
|
176 |
+
|
177 |
+
function getOptions($widget_id, $maintype, $admin = TRUE) {
|
178 |
+
$opt = array();
|
179 |
+
|
180 |
+
if ( $admin ) {
|
181 |
+
$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
|
182 |
+
WHERE widget_id LIKE '" . $widget_id . "'
|
183 |
+
AND maintype LIKE '" . $maintype . "%'
|
184 |
+
ORDER BY maintype, name";
|
185 |
+
|
186 |
+
} else {
|
187 |
+
$query = "SELECT widget_id, maintype, name, value FROM " . $this->dbtable . "
|
188 |
+
WHERE widget_id LIKE '" . $widget_id . "'
|
189 |
+
AND (maintype LIKE '" . $maintype . "%' OR maintype = 'role')
|
190 |
+
ORDER BY maintype, name";
|
191 |
+
}
|
192 |
+
$results = $this->wpdb->get_results($query);
|
193 |
+
|
194 |
+
foreach ( $results as $myrow ) {
|
195 |
+
$opt[ ] = array('widget_id' => $myrow->widget_id,
|
196 |
+
'maintype' => $myrow->maintype,
|
197 |
+
'name' => $myrow->name,
|
198 |
+
'value' => $myrow->value
|
199 |
+
);
|
200 |
+
}
|
201 |
+
|
202 |
+
return $opt;
|
203 |
+
}
|
204 |
+
|
205 |
+
function hasOptions($widget_id) {
|
206 |
+
$query = "SELECT COUNT(1) AS total FROM " . $this->dbtable . "
|
207 |
+
WHERE widget_id = '" . $widget_id . "' AND
|
208 |
+
maintype != 'individual'";
|
209 |
+
$count = $this->wpdb->get_var($this->wpdb->prepare($query));
|
210 |
+
|
211 |
+
if ( $count > 0 ) {
|
212 |
+
return TRUE;
|
213 |
+
} else {
|
214 |
+
return FALSE;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
function message($text) {
|
219 |
+
if ( DW_DEBUG ) {
|
220 |
+
if ( $this->firstmessage ) {
|
221 |
+
echo "\n";
|
222 |
+
$this->firstmessage = FALSE;
|
223 |
+
}
|
224 |
+
echo '<!-- ' . $text . ' //-->';
|
225 |
+
echo "\n";
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
function resetOptions($widget_id) {
|
230 |
+
$query = "DELETE FROM " . $this->dbtable . " WHERE widget_id = '" . $widget_id . "'";
|
231 |
+
$this->wpdb->query($query);
|
232 |
+
}
|
233 |
+
}
|
234 |
+
?>
|
dynwid_worker.php
CHANGED
@@ -2,26 +2,28 @@
|
|
2 |
/**
|
3 |
* dynwid_worker.php - The worker does the actual work.
|
4 |
*
|
5 |
-
* @version $Id: dynwid_worker.php
|
6 |
*/
|
7 |
|
8 |
-
require_once('dynwid_class.php');
|
9 |
-
if (! isset($DW) ) {
|
10 |
-
$DW = new dynWid();
|
11 |
-
}
|
12 |
$DW->message('Dynamic Widgets INIT');
|
13 |
$DW->message('User has role ' . $DW->userrole);
|
14 |
|
15 |
$whereami = $DW->detectPage();
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
foreach ( $DW->sidebars as $sidebar_id => $widgets ) {
|
18 |
// Only processing active sidebars with widgets
|
19 |
if ( $sidebar_id != 'wp_inactive_widgets' && count($widgets) > 0 ) {
|
20 |
foreach ( $widgets as $widget_id ) {
|
21 |
// Check if the widget has options set
|
22 |
-
if ( in_array($widget_id
|
23 |
$act = array();
|
24 |
$opt = $DW->getOptions($widget_id, $whereami, FALSE);
|
|
|
25 |
$display = TRUE;
|
26 |
$role = TRUE;
|
27 |
|
@@ -29,6 +31,7 @@
|
|
29 |
if ( empty($condition['name']) && $condition['value'] == '0' ) {
|
30 |
$DW->message('Default for ' . $widget_id . ' set to FALSE (rule D1)');
|
31 |
$display = FALSE;
|
|
|
32 |
break;
|
33 |
} else if ( $condition['maintype'] != 'role' ) {
|
34 |
// Get default value
|
@@ -54,21 +57,26 @@
|
|
54 |
|
55 |
// Act the condition(s) when there are options set
|
56 |
if ( count($opt) > 0 ) {
|
57 |
-
//
|
58 |
foreach ( $opt as $condition ) {
|
59 |
if ( $condition['maintype'] == 'role' && $condition['name'] == $DW->userrole ) {
|
60 |
-
$DW->message('Role
|
61 |
$role = TRUE;
|
62 |
}
|
63 |
}
|
64 |
|
|
|
|
|
|
|
|
|
65 |
switch ( $whereami ) {
|
66 |
case 'single':
|
67 |
-
global $post;
|
68 |
-
|
69 |
$act_author = array();
|
70 |
$act_category = array();
|
|
|
|
|
71 |
$post_category = array();
|
|
|
72 |
|
73 |
// Get the categories from the post
|
74 |
$categories = get_the_category();
|
@@ -76,64 +84,108 @@
|
|
76 |
$post_category[ ] = $category->cat_ID;
|
77 |
}
|
78 |
|
79 |
-
//
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
$act_category[ ] = $condition['name'];
|
85 |
}
|
|
|
|
|
86 |
}
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
|
|
|
94 |
if ( count($act_author) > 0 && count($act_category) > 0 ) {
|
95 |
// Use of array_intersect to be sure one value in both arrays returns true
|
96 |
if ( in_array($post->post_author,$act_author) && (bool) array_intersect($post_category, $act_category) ) {
|
97 |
$display = $other;
|
98 |
-
$DW->message('Exception triggered for ' . $widget_id . ' (rule ES1)');
|
99 |
}
|
|
|
100 |
} else if ( count($act_author) > 0 && count($act_category == 0) ) {
|
101 |
if ( in_array($post->post_author,$act_author) ) {
|
102 |
$display = $other;
|
103 |
-
$DW->message('Exception triggered for ' . $widget_id . ' (rule ES2)');
|
104 |
}
|
|
|
105 |
} else if ( count($act_author) == 0 && count($act_category) > 0 ) {
|
106 |
if ( (bool) array_intersect($post_category, $act_category) ) {
|
107 |
$display = $other;
|
108 |
-
$DW->message('Exception triggered for ' . $widget_id . ' (rule ES3)');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
}
|
111 |
break;
|
112 |
|
113 |
case 'page':
|
114 |
-
if ( is_page($act) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
$display = $other;
|
116 |
-
$DW->message('Exception triggered for ' . $widget_id . ' (rule
|
117 |
}
|
118 |
break;
|
119 |
|
120 |
case 'category':
|
121 |
-
if ( is_category($act) ) {
|
122 |
$display = $other;
|
123 |
-
$DW->message('Exception triggered for ' . $widget_id . ' (rule EC1)');
|
124 |
}
|
125 |
break;
|
126 |
-
}
|
127 |
-
}
|
128 |
|
129 |
if (! $display || ! $role ) {
|
130 |
$DW->message('Removed ' . $widget_id . ' from display');
|
131 |
unset($DW->registered_widgets[$widget_id]);
|
132 |
}
|
133 |
-
}
|
134 |
-
} // END foreach $widgets
|
135 |
-
}
|
136 |
-
} // END foreach $sidebars
|
137 |
|
138 |
$DW->message('Dynamic Widgets END');
|
139 |
?>
|
2 |
/**
|
3 |
* dynwid_worker.php - The worker does the actual work.
|
4 |
*
|
5 |
+
* @version $Id: dynwid_worker.php 207183 2010-02-17 17:54:48Z qurl $
|
6 |
*/
|
7 |
|
|
|
|
|
|
|
|
|
8 |
$DW->message('Dynamic Widgets INIT');
|
9 |
$DW->message('User has role ' . $DW->userrole);
|
10 |
|
11 |
$whereami = $DW->detectPage();
|
12 |
+
$DW->message('Page is ' . $whereami);
|
13 |
+
if ( $whereami == 'single' ) {
|
14 |
+
$post = $GLOBALS['post'];
|
15 |
+
$DW->message('post_id = ' .$post->ID);
|
16 |
+
}
|
17 |
|
18 |
foreach ( $DW->sidebars as $sidebar_id => $widgets ) {
|
19 |
// Only processing active sidebars with widgets
|
20 |
if ( $sidebar_id != 'wp_inactive_widgets' && count($widgets) > 0 ) {
|
21 |
foreach ( $widgets as $widget_id ) {
|
22 |
// Check if the widget has options set
|
23 |
+
if ( in_array($widget_id, $DW->dynwid_list) ) {
|
24 |
$act = array();
|
25 |
$opt = $DW->getOptions($widget_id, $whereami, FALSE);
|
26 |
+
$DW->message('Number of rules to check for widget ' .$widget_id . ': ' . count($opt));
|
27 |
$display = TRUE;
|
28 |
$role = TRUE;
|
29 |
|
31 |
if ( empty($condition['name']) && $condition['value'] == '0' ) {
|
32 |
$DW->message('Default for ' . $widget_id . ' set to FALSE (rule D1)');
|
33 |
$display = FALSE;
|
34 |
+
$other = TRUE;
|
35 |
break;
|
36 |
} else if ( $condition['maintype'] != 'role' ) {
|
37 |
// Get default value
|
57 |
|
58 |
// Act the condition(s) when there are options set
|
59 |
if ( count($opt) > 0 ) {
|
60 |
+
// Role exceptions
|
61 |
foreach ( $opt as $condition ) {
|
62 |
if ( $condition['maintype'] == 'role' && $condition['name'] == $DW->userrole ) {
|
63 |
+
$DW->message('Role set to TRUE (rule ER1)');
|
64 |
$role = TRUE;
|
65 |
}
|
66 |
}
|
67 |
|
68 |
+
// For debug messages
|
69 |
+
$e = ( $other ) ? 'TRUE' : 'FALSE';
|
70 |
+
|
71 |
+
// Display exceptions
|
72 |
switch ( $whereami ) {
|
73 |
case 'single':
|
|
|
|
|
74 |
$act_author = array();
|
75 |
$act_category = array();
|
76 |
+
$act_post = array();
|
77 |
+
$act_tag = array();
|
78 |
$post_category = array();
|
79 |
+
$post_tag = array();
|
80 |
|
81 |
// Get the categories from the post
|
82 |
$categories = get_the_category();
|
84 |
$post_category[ ] = $category->cat_ID;
|
85 |
}
|
86 |
|
87 |
+
// Get the tags form the post
|
88 |
+
if ( has_tag() ) {
|
89 |
+
$tags = get_the_tags();
|
90 |
+
foreach ( $tags as $tag ) {
|
91 |
+
$post_tag[ ] = $tag->term_id;
|
|
|
92 |
}
|
93 |
+
} else {
|
94 |
+
$tags = array();
|
95 |
}
|
96 |
|
97 |
+
// Split out the conditions
|
98 |
+
foreach ( $opt as $condition ) {
|
99 |
+
if ( $condition['name'] != 'default' ) {
|
100 |
+
switch ( $condition['maintype'] ) {
|
101 |
+
case 'single-author':
|
102 |
+
$act_author[ ] = $condition['name'];
|
103 |
+
break;
|
104 |
+
|
105 |
+
case 'single-category':
|
106 |
+
$act_category[ ] = $condition['name'];
|
107 |
+
break;
|
108 |
+
|
109 |
+
case 'single-tag':
|
110 |
+
$act_tag[ ] = $condition['name'];
|
111 |
+
break;
|
112 |
+
|
113 |
+
case 'single-post':
|
114 |
+
$act_post[ ] = $condition['name'];
|
115 |
+
break;
|
116 |
+
} // END switch
|
117 |
+
}
|
118 |
}
|
119 |
|
120 |
+
/* Author AND Category */
|
121 |
if ( count($act_author) > 0 && count($act_category) > 0 ) {
|
122 |
// Use of array_intersect to be sure one value in both arrays returns true
|
123 |
if ( in_array($post->post_author,$act_author) && (bool) array_intersect($post_category, $act_category) ) {
|
124 |
$display = $other;
|
125 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES1)');
|
126 |
}
|
127 |
+
/* Only Author */
|
128 |
} else if ( count($act_author) > 0 && count($act_category == 0) ) {
|
129 |
if ( in_array($post->post_author,$act_author) ) {
|
130 |
$display = $other;
|
131 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES2)');
|
132 |
}
|
133 |
+
/* Only Category */
|
134 |
} else if ( count($act_author) == 0 && count($act_category) > 0 ) {
|
135 |
if ( (bool) array_intersect($post_category, $act_category) ) {
|
136 |
$display = $other;
|
137 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES3)');
|
138 |
+
}
|
139 |
+
/* None or individual checked - individual is not included in the $opt */
|
140 |
+
} else {
|
141 |
+
/* Tags */
|
142 |
+
if ( count($act_tag) > 0 ) {
|
143 |
+
if ( (bool) array_intersect($post_tag, $act_tag) ) {
|
144 |
+
$display = $other;
|
145 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES4)');
|
146 |
+
}
|
147 |
+
}
|
148 |
+
/* Posts */
|
149 |
+
if ( count($act_post) > 0 ) {
|
150 |
+
if ( in_array($post->ID,$act_post) ) {
|
151 |
+
$display = $other;
|
152 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule ES5)');
|
153 |
+
}
|
154 |
}
|
155 |
}
|
156 |
break;
|
157 |
|
158 |
case 'page':
|
159 |
+
if ( count($act) > 0 && is_page($act) ) {
|
160 |
+
$display = $other;
|
161 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EP1)');
|
162 |
+
}
|
163 |
+
break;
|
164 |
+
|
165 |
+
case 'author':
|
166 |
+
if ( count($act) > 0 && is_author($act) ) {
|
167 |
$display = $other;
|
168 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EA1)');
|
169 |
}
|
170 |
break;
|
171 |
|
172 |
case 'category':
|
173 |
+
if ( count($act) > 0 && is_category($act) ) {
|
174 |
$display = $other;
|
175 |
+
$DW->message('Exception triggered for ' . $widget_id . ' sets display to ' . $e . ' (rule EC1)');
|
176 |
}
|
177 |
break;
|
178 |
+
} // END switch ( $whereami )
|
179 |
+
} /* END if ( count($opt) > 0 ) */
|
180 |
|
181 |
if (! $display || ! $role ) {
|
182 |
$DW->message('Removed ' . $widget_id . ' from display');
|
183 |
unset($DW->registered_widgets[$widget_id]);
|
184 |
}
|
185 |
+
} // END if ( in_array($widget_id, $DW->dynwid_list) )
|
186 |
+
} // END foreach ( $widgets as $widget_id )
|
187 |
+
} // END if ( $sidebar_id != 'wp_inactive_widgets' && count($widgets) > 0 )
|
188 |
+
} // END foreach ( $DW->sidebars as $sidebar_id => $widgets )
|
189 |
|
190 |
$DW->message('Dynamic Widgets END');
|
191 |
?>
|
readme.txt
CHANGED
@@ -1,30 +1,32 @@
|
|
1 |
=== Plugin Name ===
|
2 |
Contributors: Qurl
|
3 |
Donate link:
|
4 |
-
Tags: widget, widgets, dynamic, sidebar, custom, rules
|
5 |
Requires at least: 2.9.1
|
6 |
-
Tested up to: 2.9.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Dynamic Widgets gives you more control over your widgets. It lets you dynamicly place widgets on WordPress pages.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
-
Dynamic Widgets gives you more control over your widgets. It lets you dynamicly place widgets on WordPress pages by excluding or including rules by role, for the homepage, single posts, pages, categories, archives and the error
|
14 |
|
15 |
* Default widget display setting is supported for:
|
16 |
- User roles
|
17 |
- Front page
|
18 |
- Single post pages
|
19 |
- Pages
|
|
|
20 |
- Category pages
|
21 |
- Archive pages
|
22 |
-
-
|
23 |
* Exceptions can be created for:
|
24 |
- User roles on role, including not logged in (anonymous) users
|
25 |
-
- Single post pages on Author and/or
|
26 |
- Pages on Page Title
|
27 |
-
-
|
|
|
28 |
|
29 |
== Installation ==
|
30 |
|
@@ -40,6 +42,21 @@ Installation of this plugin is fairly easy:
|
|
40 |
|
41 |
For the latest FAQ, please visit the [online FAQ](http://www.qurl.nl/faq/).
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
= You asked me to create a dump. How do I do that? =
|
44 |
|
45 |
* Click at the bottom of the Widgets Overview page on the 'Advanced >' link.
|
@@ -57,19 +74,36 @@ Please file a [bugreport](http://www.qurl.nl/bugreport/). Please note the proced
|
|
57 |
* Click at the bottom of the Widgets Overview page on the 'Advanced >' link.
|
58 |
* Now a button 'Uninstall' appears a bit below.
|
59 |
* Click that button.
|
60 |
-
* Confirm you really want to uninstall the plugin. After the cleanup,
|
61 |
-
* Deactivate Dynamic Widgets.
|
62 |
* Remove the directory 'dynamic-widgets' underneath to the `/wp-content/plugins/` directory.
|
63 |
|
64 |
== Changelog ==
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
= Version 1.1.1 =
|
|
|
67 |
* Bugfix for unexpected default option values when using role options.
|
68 |
|
69 |
= Version 1.1 =
|
|
|
70 |
* Added support for widget display settings based on role, including not logged in (anonymous) users.
|
71 |
|
72 |
= Version 1.0.1 =
|
|
|
73 |
* Added default widget display setting option for 'Not Found' Error (404) Page.
|
74 |
|
75 |
== Upgrade Notice ==
|
@@ -78,30 +112,14 @@ Please file a [bugreport](http://www.qurl.nl/bugreport/). Please note the proced
|
|
78 |
|
79 |
== Release notes ==
|
80 |
|
81 |
-
= Version 1.
|
82 |
-
An unplanned release due to a bug in version 1.1. If you're using version 1.1 and using or planning to use role options, you should upgrade asap.
|
83 |
|
84 |
-
|
85 |
-
This is the next official stable release. If you upgrade from a previous version, please follow the upgrade notice.
|
86 |
|
87 |
-
|
88 |
-
No bugs found and/or reported since version 1.0.
|
89 |
-
If you do an upgrade from version 1.0, please follow the upgrade notice.
|
90 |
-
|
91 |
-
= Version 1.0 =
|
92 |
-
* This is the first stable release. However, the road ahead might be a bumpy. Fasten your seatbelt.
|
93 |
-
* Default widget display setting is supported for:
|
94 |
-
- Front page
|
95 |
-
- Single post pages
|
96 |
-
- Pages
|
97 |
-
- Category pages
|
98 |
-
- Archive pages
|
99 |
-
* Exceptions can be created for:
|
100 |
-
- Single post pages on Author and/or Category
|
101 |
-
- Pages on Page Title
|
102 |
-
- Category pages on Category
|
103 |
|
104 |
== Screenshots ==
|
105 |
|
106 |
1. Widgets overview page
|
107 |
-
2. Widget Options page
|
|
1 |
=== Plugin Name ===
|
2 |
Contributors: Qurl
|
3 |
Donate link:
|
4 |
+
Tags: widget, widgets, dynamic, sidebar, custom, rules, admin, conditional tags
|
5 |
Requires at least: 2.9.1
|
6 |
+
Tested up to: 2.9.2
|
7 |
+
Stable tag: 1.2
|
8 |
|
9 |
Dynamic Widgets gives you more control over your widgets. It lets you dynamicly place widgets on WordPress pages.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
Dynamic Widgets gives you more control over your widgets. It lets you dynamicly place widgets on WordPress pages by excluding or including rules by role, for the homepage, single posts, pages, authors, categories, archives and the error page.
|
14 |
|
15 |
* Default widget display setting is supported for:
|
16 |
- User roles
|
17 |
- Front page
|
18 |
- Single post pages
|
19 |
- Pages
|
20 |
+
- Author pages
|
21 |
- Category pages
|
22 |
- Archive pages
|
23 |
+
- Error Page
|
24 |
* Exceptions can be created for:
|
25 |
- User roles on role, including not logged in (anonymous) users
|
26 |
+
- Single post pages on Author, Categories, Tags and/or Individual posts
|
27 |
- Pages on Page Title
|
28 |
+
- Author pages on Author
|
29 |
+
- Category pages on Category name
|
30 |
|
31 |
== Installation ==
|
32 |
|
42 |
|
43 |
For the latest FAQ, please visit the [online FAQ](http://www.qurl.nl/faq/).
|
44 |
|
45 |
+
= What are the (system) requirements to use this plugin? =
|
46 |
+
|
47 |
+
1. A properly working WordPress site (doh!).
|
48 |
+
2. Your theme must have at least one dynamic sidebar.
|
49 |
+
3. Your theme must call `wp_head()`.
|
50 |
+
4. PHP5 is highly recommended. Read on if your host uses PHP4.
|
51 |
+
|
52 |
+
= My hoster is (still) using PHP4, so what? =
|
53 |
+
|
54 |
+
Start immediately looking for another hoster. YES, immediately! NOW! Pronto! PHP4 was introduced in the year 2000 and is [not supported](http://en.wikipedia.org/wiki/PHP#Release_history) anymore. As I don't have PHP4 anymore, I can only be sure for about 80% the plugin will work. Please let me know if it doesn't. I'll try to work out a solution.
|
55 |
+
|
56 |
+
= I checked the "Make exception rule available to individual posts and tags" option, but nothing happens. =
|
57 |
+
|
58 |
+
Did you save the options? If you did, you may try to hit the (i) icon a bit to the right and read the text which appears below.
|
59 |
+
|
60 |
= You asked me to create a dump. How do I do that? =
|
61 |
|
62 |
* Click at the bottom of the Widgets Overview page on the 'Advanced >' link.
|
74 |
* Click at the bottom of the Widgets Overview page on the 'Advanced >' link.
|
75 |
* Now a button 'Uninstall' appears a bit below.
|
76 |
* Click that button.
|
77 |
+
* Confirm you really want to uninstall the plugin. After the cleanup, the plugin is deactivated automaticly.
|
|
|
78 |
* Remove the directory 'dynamic-widgets' underneath to the `/wp-content/plugins/` directory.
|
79 |
|
80 |
== Changelog ==
|
81 |
|
82 |
+
= Version 1.2 =
|
83 |
+
|
84 |
+
* Added support for PHP4 (not fully tested).
|
85 |
+
* Added Dynamic Widgets info and edit link in the widgets admin itself.
|
86 |
+
* Added support for widget display setting options for Author Pages.
|
87 |
+
* Added support for Single Posts exception rules for tags.
|
88 |
+
* Added support for Single Posts exception rules for individual posts.
|
89 |
+
* Bugfix for rare cases not selecting the right default option for single posts.
|
90 |
+
* Bugfix for wrong exception rules were applied in rare cases when rules are set for a page or archive page.
|
91 |
+
* Bugfix for displaying confusing success and error message.
|
92 |
+
* Bugfix for not displaying checked checkboxes in MS Internet Explorer.
|
93 |
+
* Workaround to stop showing invalid (not clean unregistered) widgets without a name.
|
94 |
+
* Some small textual changes.
|
95 |
+
* Moved general helpinfo to standard WordPress contextual help screen.
|
96 |
+
|
97 |
= Version 1.1.1 =
|
98 |
+
|
99 |
* Bugfix for unexpected default option values when using role options.
|
100 |
|
101 |
= Version 1.1 =
|
102 |
+
|
103 |
* Added support for widget display settings based on role, including not logged in (anonymous) users.
|
104 |
|
105 |
= Version 1.0.1 =
|
106 |
+
|
107 |
* Added default widget display setting option for 'Not Found' Error (404) Page.
|
108 |
|
109 |
== Upgrade Notice ==
|
112 |
|
113 |
== Release notes ==
|
114 |
|
115 |
+
= Version 1.2 =
|
|
|
116 |
|
117 |
+
PHP4 support is now automatic. However, PHP4 support is not fully tested. If you encounter problems, please let me know. I'll try to work out a solution.
|
|
|
118 |
|
119 |
+
Due to the addition of the Author pages option, the behavior of the Archive pages option has slightly changed. The Archive pages option does not include the Author pages anymore. If you have widgets with the Archive option set to 'No' the upgrade process to version 1.2 will automaticly set 'No' to the Author pages also to keep the old behavior. An upgrade is only triggered when a proper deactivate and activate cycle is done.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
== Screenshots ==
|
122 |
|
123 |
1. Widgets overview page
|
124 |
+
2. Widget Options page
|
125 |
+
3. Widget with Dynamic Widgets info and link
|
screenshot-2.jpg
CHANGED
Binary file
|
screenshot-3.jpg
ADDED
Binary file
|