Footer Putter - Version 1.15

Version Description

Added 6 new footer layouts to organize the copyright, contact and footer menu sections

For full version history please see https://www.diywebmastery.com/plugins/footer-putter/footer-putter-version-history/

=

Download this release

Release Info

Developer powerblogservice
Plugin Icon 128x128 Footer Putter
Version 1.15
Comparing to
See all releases

Code changes from version 1.14.1 to 1.15

classes/class-admin.php CHANGED
@@ -5,18 +5,41 @@ abstract class Footer_Putter_Admin {
5
protected $parent_slug;
6
protected $slug;
7
protected $screen_id;
8
- private $tooltips;
9
private $tips = array();
10
- private $messages = array();
11
-
12
- function __construct($version, $path, $parent_slug, $slug = '') {
13
- $this->version = $version;
14
- $this->path = $path;
15
- $this->parent_slug = $parent_slug;
16
- $this->slug = empty($slug) ? $this->parent_slug : ( $this->parent_slug.'-'.$slug );
17
- $this->tooltips = new Footer_Putter_Tooltip($this->tips);
18
$this->init();
19
}
20
21
abstract function init() ;
22
@@ -50,6 +73,10 @@ abstract class Footer_Putter_Admin {
50
return admin_url('admin.php?page='.$this->get_slug());
51
}
52
53
function get_code($code='') {
54
$format = empty($code) ? '%1$s' : '%1$s-%2$s';
55
return sprintf($format, $this->get_parent_slug(), $code);
@@ -82,8 +109,8 @@ abstract class Footer_Putter_Admin {
82
}
83
84
function set_tooltips($tips) {
85
- $this->tips = $tips;
86
- $this->tooltips = new Footer_Putter_Tooltip($this->tips);
87
$this->add_tooltip_support();
88
}
89
@@ -94,31 +121,40 @@ abstract class Footer_Putter_Admin {
94
}
95
96
function register_tooltip_styles() {
97
- Footer_Putter_Utils::register_tooltip_styles();
98
}
99
100
function enqueue_tooltip_styles() {
101
- Footer_Putter_Utils::enqueue_tooltip_styles();
102
}
103
104
function register_admin_styles() {
105
wp_register_style($this->get_code('admin'), plugins_url('styles/admin.css',dirname(__FILE__)), array(),$this->get_version());
106
}
107
108
- function enqueue_admin_styles() {
109
- wp_enqueue_style($this->get_code('admin'));
110
- }
111
112
function enqueue_color_picker_styles() {
113
wp_enqueue_style('wp-color-picker');
114
}
115
116
function enqueue_color_picker_scripts() {
117
wp_enqueue_script('wp-color-picker');
118
add_action('admin_print_footer_scripts', array($this, 'enable_color_picker'));
119
}
120
121
function enqueue_metabox_scripts() {
122
wp_enqueue_style($this->get_code('tabs'), plugins_url('styles/tabs.css',dirname(__FILE__)), array(),$this->get_version());
123
wp_enqueue_script($this->get_code('tabs'), plugins_url('scripts/jquery.tabs.js',dirname(__FILE__)), array(),$this->get_version());
124
}
@@ -130,6 +166,10 @@ abstract class Footer_Putter_Admin {
130
add_action('admin_footer-'.$this->get_screen_id(), array($this, 'toggle_postboxes'));
131
}
132
133
function add_meta_box($code, $title, $callback_func, $callback_params = null, $context = 'normal', $priority = 'core', $post_type = false ) {
134
if (empty($post_type)) $post_type = $this->get_screen_id();
135
add_meta_box($this->get_code($code), __($title), array($this, $callback_func), $post_type, $context, $priority, $callback_params);
@@ -138,7 +178,14 @@ abstract class Footer_Putter_Admin {
138
function form_field($id, $name, $label, $value, $type, $options = array(), $args = array(), $wrap = false) {
139
if (!$label) $label = $id;
140
$label_args = (is_array($args) && array_key_exists('label_args', $args)) ? $args['label_args'] : false;
141
- return Footer_Putter_Utils::form_field($id, $name, $this->tooltips->tip($label, $label_args), $value, $type, $options, $args, $wrap);
142
}
143
144
function meta_form_field($meta, $key, $type, $options=array(), $args=array()) {
@@ -150,46 +197,52 @@ abstract class Footer_Putter_Admin {
150
return $this->form_field($fld, $fld, false, $value, $type, $options, $args, $wrap);
151
}
152
153
- function print_form_field($fld, $value, $type, $options = array(), $args = array(), $wrap = false) {
154
- print $this->form_field($fld, $fld, false, $value, $type, $options, $args, $wrap);
155
- }
156
-
157
function fetch_text_field($fld, $value, $args = array()) {
158
return $this->fetch_form_field($fld, $value, 'text', array(), $args);
159
}
160
161
- function print_text_field($fld, $value, $args = array()) {
162
- $this->print_form_field($fld, $value, 'text', array(), $args);
163
- }
164
165
- function get_meta_form_data($metakey, $prefix, $values ) {
166
$content = array();
167
- if (($post_id = Footer_Putter_Utils::get_post_id())
168
- && ($meta = Footer_Putter_Utils::get_meta($post_id, $metakey)))
169
- $values = Footer_Putter_Utils::validate_options($values, $meta);
170
foreach ($values as $key => $val) {
171
$content[$key] = array();
172
$content[$key]['value'] = $val;
173
$content[$key]['id'] = $prefix.$key;
174
$content[$key]['name'] = $metakey. '[' . $key . ']';
175
}
176
- return $content;
177
}
178
-
179
- function get_newsfeeds() {
180
- return apply_filters('footer_putter_newsfeeds', array( FOOTER_PUTTER_NEWS));
181
}
182
-
183
- function news_panel($post,$metabox){
184
- Footer_Putter_Feed_Widget::display_feeds($this->get_newsfeeds());
185
- }
186
-
187
- function get_nonces($referer) {
188
- return wp_nonce_field($referer, '_wpnonce', true, false).
189
- wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false, false ).
190
- wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false, false);
191
}
192
193
function submit_button($button_text='Save Changes', $name = 'options_update') {
194
return sprintf('<p class="save"><input type="submit" name="%1$s" value="%2$s" class="button-primary" /></p>', $name, $button_text);
195
}
@@ -202,21 +255,54 @@ abstract class Footer_Putter_Admin {
202
$updates = false;
203
foreach ($page_options as $option) {
204
$option = trim($option);
205
- $val = array_key_exists($option, $_POST) ? trim(stripslashes($_POST[$option])) : '';
206
if ($trim_option_prefix) $option = substr($option,$trim_option_prefix); //remove prefix
207
$options[$option] = $val;
208
} //end for
209
$saved = call_user_func( array($options_class, 'save_options'), $options) ;
210
if ($saved)
211
- $this->add_admin_notice($settings_name, 'settings saved successfully.');
212
else
213
- $this->add_admin_notice($settings_name, 'settings have not been changed.', true);
214
} else {
215
$this->add_admin_notice($settings_name, 'settings not found', true);
216
}
217
return $saved;
218
}
219
220
function fetch_message() {
221
if (isset($_REQUEST['message']) && ! empty($_REQUEST['message'])) {
222
$message = urldecode($_REQUEST['message']);
@@ -237,14 +323,17 @@ abstract class Footer_Putter_Admin {
237
return $columns;
238
}
239
240
- function admin_heading($title = '', $icon_class = '') {
241
if (empty($title)) $title = sprintf('%1$s %2$s', ucwords(str_replace('-',' ',$this->slug)), $this->get_version());
242
- if (empty($icon_class)) $icon_class = FOOTER_PUTTER_ICON;
243
- $icon = sprintf('<i class="%1$s"></i>', 'dashicons-'==substr($icon_class,0,10) ? ('dashicons '.$icon_class) : $icon_class) ;
244
- return sprintf('<h2 class="title">%2$s%1$s</h2>', $title, $icon);
245
}
246
247
- function print_admin_form_start($title, $referer = false, $keys = false, $enctype = false, $with_sidebar = false, $preamble = false) {
248
$this_url = $_SERVER['REQUEST_URI'];
249
$enctype = $enctype ? 'enctype="multipart/form-data" ' : '';
250
$nonces = $referer ? $this->get_nonces($referer) : '';
@@ -253,9 +342,8 @@ abstract class Footer_Putter_Admin {
253
$keys = is_array($keys) ? implode(',', $keys) : $keys;
254
$page_options = sprintf('<input type="hidden" name="page_options" value="%1$s" />', $keys);
255
}
256
- $class = $with_sidebar ? ' columns-2' : '';
257
- printf('<div class="wrap">%1$s<form id="diy_options" method="post" %2$saction="%3$s"><p>%4$s%5$s</p><div id="poststuff"><div id="post-body" class="metabox-holder%6$s"><div id="post-body-content">%7$s',
258
- $title, $enctype, $this_url, $page_options, $nonces, $class, $preamble ? $preamble : '');
259
}
260
261
function print_admin_form_with_sidebar_middle() {
@@ -263,38 +351,77 @@ abstract class Footer_Putter_Admin {
263
}
264
265
function print_admin_form_end() {
266
- print '</div></div><br class="clear"/></div></form></div>';
267
}
268
269
function print_admin_form_with_sidebar($title, $referer = false, $keys = false, $enctype = false, $preamble = false) {
270
- $this->print_admin_form_start ($title, $referer, $keys, $enctype, true, $preamble);
271
do_meta_boxes($this->get_screen_id(), 'normal', null);
272
if ($keys) print $this->submit_button();
273
do_meta_boxes($this->get_screen_id(), 'advanced', null);
274
$this->print_admin_form_with_sidebar_middle();
275
do_meta_boxes($this->get_screen_id(), 'side', null);
276
- $this->print_admin_form_end();
277
}
278
279
function print_admin_form ($title, $referer = false, $keys = false, $enctype = false, $preamble = false) {
280
- $this->print_admin_form_start ($title, $referer, $keys, $enctype, false, $preamble);
281
do_meta_boxes($this->get_screen_id(), 'normal', null);
282
if ($keys) print $this->submit_button();
283
- do_meta_boxes($this->get_screen_id(), 'advanced', null);
284
$this->print_admin_form_end();
285
}
286
287
-
288
- function display_metabox($tabs) {
289
$labels = $contents = '';
290
- $t=0;
291
- $tab = isset($_REQUEST['tabselect']) ? $_REQUEST['tabselect'] : 'tab1';
292
foreach ($tabs as $label => $content) {
293
$t++;
294
$labels .= sprintf('<li class="tab tab%1$s"><a href="#">%2$s</a></li>', $t, $label);
295
$contents .= sprintf('<div class="tab%1$s"><div class="tab-content">%2$s</div></div>', $t, $content);
296
}
297
- printf('<div class="footer-putter-metabox"><ul class="footer-putter-metabox-tabs">%1$s</ul><div class="metabox-content">%2$s</div><input type="hidden" id="tabselect" name="tabselect" value="%3$s" /></div>', $labels, $contents, $tab);
298
}
299
300
function toggle_postboxes() {
@@ -312,13 +439,32 @@ SCRIPT;
312
}
313
314
function enable_color_picker() {
315
print <<< SCRIPT
316
- <script type="text/javascript">
317
- //<![CDATA[
318
- jQuery(document).ready( function($) {
319
- $('.color-picker').wpColorPicker();
320
- });
321
- //]]>
322
</script>
323
SCRIPT;
324
}
5
protected $parent_slug;
6
protected $slug;
7
protected $screen_id;
8
+ protected $plugin;
9
+ protected $utils;
10
+ protected $options;
11
+ protected $icon;
12
+ protected $tooltips;
13
private $tips = array();
14
+ private $messages = array();
15
+ private $is_metabox = false;
16
+ private $metabox_class;
17
+ private $metabox_tab;
18
+
19
+ function __construct($plugin, $slug = '') {
20
+ $this->plugin = $plugin;
21
+ $this->icon = $this->plugin->get_icon();
22
+ $this->options = $this->plugin->get_options();
23
+ $this->tooltips = $this->plugin->get_tooltips();
24
+ $this->utils = $this->plugin->get_utils();
25
+ $this->version = $this->plugin->get_version();
26
+ $this->path = $this->plugin->get_path();
27
+ $this->parent_slug = $this->plugin->get_slug();
28
+ $this->slug = empty($slug) ? $this->parent_slug : ( $this->parent_slug.'-'.$slug );
29
+ $this->metabox_class = $this->prefix_class('metabox');
30
+ $this->metabox_tab = $this->prefix_action('tab');
31
$this->init();
32
+ add_action('wp_ajax_'. $this->metabox_tab, array($this,'save_tab'));
33
}
34
+
35
+ function news_panel($post,$metabox){
36
+ $this->plugin->get_news()->display_feeds($this->plugin->get_newsfeeds());
37
+ }
38
+
39
+ function make_icon($icon) {
40
+ if (empty($icon)) $icon = $this->icon;
41
+ return sprintf('<i class="%1$s"></i>', 'dashicons-'==substr($icon,0,10) ? ('dashicons '.$icon) : $icon) ;
42
+ }
43
44
abstract function init() ;
45
73
return admin_url('admin.php?page='.$this->get_slug());
74
}
75
76
+ function get_name() {
77
+ return $this->plugin->get_name();
78
+ }
79
+
80
function get_code($code='') {
81
$format = empty($code) ? '%1$s' : '%1$s-%2$s';
82
return sprintf($format, $this->get_parent_slug(), $code);
109
}
110
111
function set_tooltips($tips) {
112
+ $this->tips = (array)$tips;
113
+ $this->tooltips->init($this->tips);
114
$this->add_tooltip_support();
115
}
116
121
}
122
123
function register_tooltip_styles() {
124
+ $this->utils->register_tooltip_styles();
125
}
126
127
function enqueue_tooltip_styles() {
128
+ $this->utils->enqueue_tooltip_styles();
129
}
130
131
function register_admin_styles() {
132
wp_register_style($this->get_code('admin'), plugins_url('styles/admin.css',dirname(__FILE__)), array(),$this->get_version());
133
}
134
135
+ function enqueue_admin() {
136
+ $this->enqueue_admin_styles();
137
+ $this->enqueue_metabox_scripts();
138
+ $this->enqueue_postbox_scripts();
139
+ $this->enqueue_news_scripts();
140
+ }
141
+
142
+ function enqueue_admin_styles() {
143
+ wp_enqueue_style($this->get_code('admin'));
144
+ }
145
146
function enqueue_color_picker_styles() {
147
wp_enqueue_style('wp-color-picker');
148
}
149
150
function enqueue_color_picker_scripts() {
151
+ wp_enqueue_script('underscore');
152
wp_enqueue_script('wp-color-picker');
153
add_action('admin_print_footer_scripts', array($this, 'enable_color_picker'));
154
}
155
156
function enqueue_metabox_scripts() {
157
+ $this->is_metabox = true;
158
wp_enqueue_style($this->get_code('tabs'), plugins_url('styles/tabs.css',dirname(__FILE__)), array(),$this->get_version());
159
wp_enqueue_script($this->get_code('tabs'), plugins_url('scripts/jquery.tabs.js',dirname(__FILE__)), array(),$this->get_version());
160
}
166
add_action('admin_footer-'.$this->get_screen_id(), array($this, 'toggle_postboxes'));
167
}
168
169
+ function enqueue_news_scripts() {
170
+ $this->plugin->get_news()->enqueue_scripts();
171
+ }
172
+
173
function add_meta_box($code, $title, $callback_func, $callback_params = null, $context = 'normal', $priority = 'core', $post_type = false ) {
174
if (empty($post_type)) $post_type = $this->get_screen_id();
175
add_meta_box($this->get_code($code), __($title), array($this, $callback_func), $post_type, $context, $priority, $callback_params);
178
function form_field($id, $name, $label, $value, $type, $options = array(), $args = array(), $wrap = false) {
179
if (!$label) $label = $id;
180
$label_args = (is_array($args) && array_key_exists('label_args', $args)) ? $args['label_args'] : false;
181
+ return $this->utils->form_field($id, $name, $this->tooltips->tip($label, $label_args), $value, $type, $options, $args, $wrap);
182
+ }
183
+
184
+ function grouped_form_field($data, $group, $fld, $type, $options = array(), $args = array(), $wrap='tr', $prefix='') {
185
+ $id = $group.'_'.$fld;
186
+ $name = $prefix.$group.'['.$fld.']';
187
+ $value = isset($data[$fld]) ? $data[$fld] : '';
188
+ return $this->form_field($id, $name, false, $value, $type, $options, $args, $wrap);
189
}
190
191
function meta_form_field($meta, $key, $type, $options=array(), $args=array()) {
197
return $this->form_field($fld, $fld, false, $value, $type, $options, $args, $wrap);
198
}
199
200
function fetch_text_field($fld, $value, $args = array()) {
201
return $this->fetch_form_field($fld, $value, 'text', array(), $args);
202
}
203
204
+ function get_meta_form_data($metakey, $prefix, $values = '' ) {
205
+ $content = false;
206
+ $meta = false;
207
+ if (($post_id = $this->utils->get_post_id())
208
+ && ($meta = $this->utils->get_post_meta($post_id, $metakey))
209
+ && is_array($values)
210
+ && is_array($meta))
211
+ $values = $this->options->validate_options($values, $meta);
212
213
+ if (is_array($values)) {
214
$content = array();
215
foreach ($values as $key => $val) {
216
$content[$key] = array();
217
$content[$key]['value'] = $val;
218
$content[$key]['id'] = $prefix.$key;
219
$content[$key]['name'] = $metakey. '[' . $key . ']';
220
}
221
+ } else {
222
+ if (is_string($values)) {
223
+ $key ='';
224
+ $content = array();
225
+ $content[$key] = array();
226
+ $content[$key]['value'] = $meta;
227
+ $content[$key]['id'] = $prefix;
228
+ $content[$key]['name'] = $metakey;
229
}
230
}
231
+ return $content;
232
}
233
234
+ function prefix_action($action, $prefix ='') {
235
+ if (empty($prefix)) $prefix = $this->utils->get_prefix();
236
+ if ('_' == substr($prefix,0,1)) $prefix = substr($prefix,1);
237
+ return strtolower( $prefix.$action);
238
+ }
239
+
240
+ function prefix_class($class, $prefix ='') {
241
+ if (empty($prefix)) $prefix = $this->utils->get_prefix();
242
+ if ('_' == substr($prefix,0,1)) $prefix = substr($prefix,1);
243
+ return strtolower( str_replace('_', '-', $prefix).$class);
244
+ }
245
+
246
function submit_button($button_text='Save Changes', $name = 'options_update') {
247
return sprintf('<p class="save"><input type="submit" name="%1$s" value="%2$s" class="button-primary" /></p>', $name, $button_text);
248
}
255
$updates = false;
256
foreach ($page_options as $option) {
257
$option = trim($option);
258
+ $val = array_key_exists($option, $_POST) ? (is_array($_POST[$option]) ? $_POST[$option] : trim(stripslashes($_POST[$option]))) : '';
259
if ($trim_option_prefix) $option = substr($option,$trim_option_prefix); //remove prefix
260
$options[$option] = $val;
261
} //end for
262
$saved = call_user_func( array($options_class, 'save_options'), $options) ;
263
if ($saved)
264
+ $this->add_admin_notice($settings_name, ' saved successfully.');
265
else
266
+ $this->add_admin_notice($settings_name, ' have not been changed.', true);
267
} else {
268
$this->add_admin_notice($settings_name, 'settings not found', true);
269
}
270
return $saved;
271
}
272
273
+ function save_postmeta($post_id, $enabler, $metakey, $defaults = array()) {
274
+ if (array_key_exists($enabler, $_POST)) {
275
+ if (isset($_POST[$metakey])) {
276
+ $val = $_POST[$metakey];
277
+ if (is_array($val)) {
278
+ foreach ($val as $k => $v) if (!is_array($v)) $val[$k] = stripslashes(trim($v));
279
+ $val = @serialize($this->options->validate_options($defaults, $val ));
280
+ } else {
281
+ $val = stripslashes(trim($val));
282
+ }
283
+ } else {
284
+ $val = false;
285
+ }
286
+ $this->utils->update_post_meta( $post_id, $metakey, $val );
287
+ }
288
+ }
289
+
290
+ function disable_checkbox($post_id, $action, $option, $label_format) {
291
+ $key = $this->utils->get_toggle_post_meta_key($action, $option);
292
+ return $this->toggle_checkbox($key, $this->utils->get_post_meta_value($post_id, $key), $action=='disable' ? 'Disable' : 'Enable', $option, $label_format);
293
+ }
294
+
295
+ function visibility_checkbox($post_id, $action, $option, $label_format) {
296
+ $key = $this->utils->get_toggle_post_meta_key($action, $option);
297
+ return $this->toggle_checkbox($key, $this->utils->get_post_meta_value($post_id, $key), $action=='hide' ? 'Do not show' : 'Show', $option, $label_format);
298
+ }
299
+
300
+ function toggle_checkbox($key, $value, $action, $option, $label_format) {
301
+ $checked = $value ?'checked="checked" ':'';
302
+ $label = __(sprintf($label_format, $action, ucwords(str_replace('_',' ', $option))));
303
+ return sprintf('<label><input class="valinp" type="checkbox" name="%1$s" id="%1$s" %2$svalue="1" />%3$s</label><br/>', $key, $checked, $label);
304
+ }
305
+
306
function fetch_message() {
307
if (isset($_REQUEST['message']) && ! empty($_REQUEST['message'])) {
308
$message = urldecode($_REQUEST['message']);
323
return $columns;
324
}
325
326
+ function admin_heading($title = '', $icon = '') {
327
if (empty($title)) $title = sprintf('%1$s %2$s', ucwords(str_replace('-',' ',$this->slug)), $this->get_version());
328
+ return sprintf('<h2 class="title">%2$s<span>%1$s</span></h2>', $title, $this->make_icon($icon));
329
}
330
331
+ function print_admin_page_start($title, $with_sidebar = false) {
332
+ $class = $with_sidebar ? ' columns-2' : '';
333
+ printf('<div class="wrap">%1$s<div id="poststuff"><div id="post-body" class="metabox-holder%2$s"><div id="post-body-content">', $title, $class);
334
+ }
335
+
336
+ function print_admin_form_start($referer = false, $keys = false, $enctype = false, $preamble = false) {
337
$this_url = $_SERVER['REQUEST_URI'];
338
$enctype = $enctype ? 'enctype="multipart/form-data" ' : '';
339
$nonces = $referer ? $this->get_nonces($referer) : '';
342
$keys = is_array($keys) ? implode(',', $keys) : $keys;
343
$page_options = sprintf('<input type="hidden" name="page_options" value="%1$s" />', $keys);
344
}
345
+ printf('%1$s<form id="diy_options" method="post" %2$saction="%3$s"><div>%4$s%5$s</div>',
346
+ $preamble ? $preamble : '', $enctype, $this_url, $page_options, $nonces);
347
}
348
349
function print_admin_form_with_sidebar_middle() {
351
}
352
353
function print_admin_form_end() {
354
+ print '</form>';
355
+ }
356
+
357
+ function print_admin_page_end() {
358
+ print '</div></div><br class="clear"/></div></div>';
359
}
360
361
function print_admin_form_with_sidebar($title, $referer = false, $keys = false, $enctype = false, $preamble = false) {
362
+ $this->print_admin_page_start ($title, true);
363
+ $this->print_admin_form_start ($referer, $keys, $enctype, $preamble);
364
do_meta_boxes($this->get_screen_id(), 'normal', null);
365
if ($keys) print $this->submit_button();
366
+ $this->print_admin_form_end();
367
do_meta_boxes($this->get_screen_id(), 'advanced', null);
368
$this->print_admin_form_with_sidebar_middle();
369
do_meta_boxes($this->get_screen_id(), 'side', null);
370
+ $this->print_admin_page_end();
371
}
372
373
function print_admin_form ($title, $referer = false, $keys = false, $enctype = false, $preamble = false) {
374
+ $this->print_admin_page_start ($title);
375
+ $this->print_admin_form_start ($referer, $keys, $enctype, $preamble);
376
do_meta_boxes($this->get_screen_id(), 'normal', null);
377
if ($keys) print $this->submit_button();
378
$this->print_admin_form_end();
379
+ do_meta_boxes($this->get_screen_id(), 'advanced', null);
380
+ $this->print_admin_page_end();
381
+ }
382
+
383
+ function is_metabox_active($post_type, $context) {
384
+ return ('advanced' === $context ) && $this->plugin->is_post_type_enabled($post_type) ;
385
}
386
387
+ function tabbed_metabox($container_id, $tabs, $n=0) {
388
+ if (!$tabs || (is_array($tabs) && (count($tabs) == 0))) return;
389
+ $tabselect = sprintf('tabselect%1$s', $n);
390
+ if (isset($_REQUEST[$tabselect]))
391
+ $tab = $_REQUEST[$tabselect];
392
+ else {
393
+ $tab = get_user_option($this->metabox_tab.'_'.$container_id ) ;
394
+ if (!$tab) $tab = 'tab1' ;
395
+ }
396
+ $t=0;
397
$labels = $contents = '';
398
foreach ($tabs as $label => $content) {
399
$t++;
400
$labels .= sprintf('<li class="tab tab%1$s"><a href="#">%2$s</a></li>', $t, $label);
401
$contents .= sprintf('<div class="tab%1$s"><div class="tab-content">%2$s</div></div>', $t, $content);
402
}
403
+ return sprintf('<div class="%1$s"><ul class="metabox-tabs">%2$s</ul><div class="metabox-content">%3$s</div><input type="hidden" class="tabselect" name="%4$s" value="%5$s" />%6$s</div>',
404
+ $this->metabox_class, $labels, $contents, $tabselect, $tab, $this->get_action_nonce($this->metabox_tab));
405
+ }
406
+
407
+ function get_action_nonce($action) {
408
+ return wp_nonce_field($action, $action.'nonce', false, false );
409
+ }
410
+
411
+ function get_nonces($referer) {
412
+ return wp_nonce_field($referer, '_wpnonce', true, false).
413
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false, false ).
414
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false, false);
415
+ }
416
+
417
+ function save_tab() {
418
+ check_ajax_referer( $this->metabox_tab, 'tabnonce');
419
+ $tabselect = isset( $_POST['tabselect'] ) ? $_POST['tabselect'] : 'tab0';
420
+ $box = isset( $_POST['box'] ) ? $_POST['box'] : '';
421
+ if ( $box != sanitize_key( $box ) ) wp_die( 0 );
422
+ if ( ! $user = wp_get_current_user() ) wp_die( -1 );
423
+ if ( $tabselect ) update_user_option($user->ID, $this->metabox_tab.'_'.$box, $tabselect, true);
424
+ wp_die( 1 );
425
}
426
427
function toggle_postboxes() {
439
}
440
441
function enable_color_picker() {
442
+ if ($this->is_metabox)
443
+ $this->enable_color_picker_metabox();
444
+ else
445
+ $this->enable_color_picker_widgets();
446
+ }
447
+
448
+ function enable_color_picker_metabox() {
449
+ $target = sprintf('.%1$s .color-picker', $this->metabox_class);
450
print <<< SCRIPT
451
+ <script>
452
+ ( function( $ ){
453
+ $( document ).ready( function() { $( '{$target}' ).wpColorPicker(); });
454
+ }( jQuery ) );
455
+ </script>
456
+ SCRIPT;
457
+ }
458
+
459
+ function enable_color_picker_widgets() {
460
+ print <<< SCRIPT
461
+ <script>
462
+ ( function( $ ){
463
+ function initColorPickerWidget( widget ) { widget.find( '.color-picker' ).wpColorPicker( { change: _.throttle( function() { $(this).trigger( 'change' );}, 3000 ) }); }
464
+ function colorPickerWidgetUpdate( event, widget ) { initColorPickerWidget( widget ); }
465
+ $( document ).on( 'widget-added widget-updated', colorPickerWidgetUpdate );
466
+ $( document ).ready( function() { $( '#widgets-right .widget:has(.color-picker)' ).each( function () { initColorPickerWidget( $( this ) );} ); } );
467
+ }( jQuery ) );
468
</script>
469
SCRIPT;
470
}
classes/class-credits-admin.php CHANGED
@@ -29,8 +29,10 @@ class Footer_Credits_Admin extends Footer_Putter_Admin{
29
'terms_contact' => array('heading' => 'Add Terms Contact?', 'tip' => 'Add a section to the end of the Terms page with contact and legal information'),
30
'hide_wordpress' => array('heading' => 'Hide WordPress link?', 'tip' => 'Hide link to WordPress.org'),
31
);
32
33
function init() {
34
add_action('admin_menu',array($this, 'admin_menu'));
35
}
36
@@ -41,30 +43,56 @@ class Footer_Credits_Admin extends Footer_Putter_Admin{
41
}
42
43
function page_content() {
44
- $title = $this->admin_heading('Footer Credits',FOOTER_PUTTER_ICON);
45
- $this->print_admin_form_with_sidebar($title, __CLASS__, $this->get_keys());
46
}
47
48
function load_page() {
49
if (isset($_POST['options_update'])) $this->save_credits();
50
$this->add_meta_box('introduction', 'Introduction' , 'intro_panel');
51
- $this->add_meta_box('credits', 'Footer Settings' , 'credits_panel', array ('options' => Footer_Credits_Options::get_options()));
52
$this->add_meta_box('example', 'Footer Preview', 'preview_panel', null, 'advanced');
53
$this->add_meta_box('news', 'DIY Webmastery News', 'news_panel', null, 'side');
54
- $this->set_tooltips($this->tips);
55
add_action('admin_enqueue_scripts', array($this, 'enqueue_credits_styles'));
56
- add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
57
- add_action('admin_enqueue_scripts',array($this, 'enqueue_metabox_scripts'));
58
- add_action('admin_enqueue_scripts',array($this, 'enqueue_postbox_scripts'));
59
}
60
61
function enqueue_credits_styles() {
62
wp_enqueue_style($this->get_code(), plugins_url('styles/footer-credits.css', dirname(__FILE__)), array(),$this->get_version());
63
}
64
65
function credits_panel($post,$metabox) {
66
$options = $metabox['args']['options'];
67
- $this->display_metabox( array(
68
'Owner' => $this->owner_panel($options['terms']),
69
'Contact' => $this->contact_panel($options['terms']),
70
'Legal' => $this->legal_panel($options['terms']),
@@ -73,20 +101,11 @@ class Footer_Credits_Admin extends Footer_Putter_Admin{
73
));
74
}
75
76
- function intro_panel() {
77
- printf('<p>%1$s</p>', __('The following information is used in the Footer Copyright Widget and optionally at the end of the Privacy Statement and Terms and Conditions pages.'));
78
- }
79
-
80
- function preview_panel() {
81
- printf('<p><i>%1$s</i></p><hr/>%2$s', __('Note: Preview is purely illustrative. Actual footer layout on the site will vary based on footer widget settings.'), Footer_Credits::footer(array('nav_menu' => 'Footer Menu')));
82
- }
83
-
84
-
85
function owner_panel($terms) {
86
$s = $this->fetch_text_field('owner', $terms['owner'], array('size' =>30)) .
87
$this->fetch_text_field('country', $terms['country'], array('size' => 30)) .
88
$this->fetch_form_field('address', $terms['address'], 'textarea', array(), array('cols' => 30, 'rows' => 5));
89
- if (Footer_Credits::is_html5()) {
90
return $s .
91
'<p>Leave the above address field blank and fill in the various parts of the organization address below if you want to be able to use HTML5 microdata.</p>'.
92
'<h4>Organization Address</h4>'.
@@ -125,7 +144,7 @@ class Footer_Credits_Admin extends Footer_Putter_Admin{
125
}
126
127
function advanced_panel($options) {
128
- $url = 'http://www.diywebmastery.com/footer-credits-compatible-themes-and-hooks';
129
$before = <<< ADVANCED_PANEL
130
<p>You can place the Copyright and Trademark widgets in any existing widget area. However, if your theme does not have a suitably located widget area in the footer then you can create one by specifying the hook
131
where the Widget Area will be located.</p>
@@ -133,44 +152,28 @@ where the Widget Area will be located.</p>
133
<i>twentyeleven_credits</i>, <i>twentytwelve_credits</i>,<i>twentythirteen_credits</i> or <i>twentyfourteen_credits</i>. If you using a Genesis child theme and the theme does not have a suitable widget area then use
134
the hook <i>genesis_footer</i> or maybe <i>genesis_after</i>. See what looks best. Click for <a href="{$url}">suggestions of which hook to use for common WordPress themes</a>.</p>
135
ADVANCED_PANEL;
136
- $f = $this->fetch_text_field('footer_hook', $options['footer_hook'], array('size' => 30)) .
137
$this->fetch_form_field('footer_remove', $options['footer_remove'], 'checkbox');
138
$after = <<< REMOVE_PANEL
139
<p>If your WordPress theme supplies a filter hook rather than an action hook where it generates the footer, and you want to suppress the theme footer,
140
then specify the hook below. For example, entering <i>genesis_footer_output</i> will suppress the standard Genesis child theme footer.</p>
141
REMOVE_PANEL;
142
- $hook = $this->fetch_text_field('footer_filter_hook', $options['footer_filter_hook'], array('size' => 30));
143
if (($theme = wp_get_theme()) && (strpos(strtolower($theme->get('Name')), 'twenty') !== FALSE))
144
$hook .= $this->fetch_form_field('hide_wordpress', $options['hide_wordpress'], 'checkbox');
145
return $before . $f . $after . $hook;
146
}
147
148
- function save_credits() {
149
- check_admin_referer(__CLASS__);
150
- $page_options = explode(',', stripslashes($_POST['page_options']));
151
- if ($page_options) {
152
- $options = Footer_Credits_Options::get_options();
153
- foreach ($page_options as $option) {
154
- $val = array_key_exists($option, $_POST) ? trim(stripslashes($_POST[$option])) : '';
155
- if (Footer_Credits_Options::is_terms_key($option))
156
- $options['terms'][$option] = $val;
157
- else switch($option) {
158
- case 'footer_remove' : $options[$option] = !empty($val); break;
159
- case 'footer_hook':
160
- case 'footer_filter_hook': $options[$option] = preg_replace('/\W/','',$val); break;
161
- default: $options[$option] = trim($val);
162
- }
163
- } //end for ;
164
- $saved = Footer_Credits_Options::save_options($options) ;
165
- $message = $saved ? 'updated successfully' : 'have not been updated';
166
- $is_error = false;
167
- } else {
168
- $message= 'not found!';
169
- $is_error = true;
170
- }
171
172
- $this->add_admin_notice('Footer Settings ', $message, $is_error);
173
- return $saved;
174
}
175
176
}
29
'terms_contact' => array('heading' => 'Add Terms Contact?', 'tip' => 'Add a section to the end of the Terms page with contact and legal information'),
30
'hide_wordpress' => array('heading' => 'Hide WordPress link?', 'tip' => 'Hide link to WordPress.org'),
31
);
32
+ private $credits;
33
34
function init() {
35
+ $this->credits = $this->plugin->get_credits();
36
add_action('admin_menu',array($this, 'admin_menu'));
37
}
38
43
}
44
45
function page_content() {
46
+ $title = $this->admin_heading('Footer Credits');
47
+ $this->print_admin_form($title, __CLASS__, $this->get_keys());
48
}
49
50
function load_page() {
51
if (isset($_POST['options_update'])) $this->save_credits();
52
+ $this->set_tooltips($this->tips);
53
$this->add_meta_box('introduction', 'Introduction' , 'intro_panel');
54
+ $this->add_meta_box('credits', 'Footer Settings' , 'credits_panel', array ('options' => $this->credits->get_options()));
55
$this->add_meta_box('example', 'Footer Preview', 'preview_panel', null, 'advanced');
56
$this->add_meta_box('news', 'DIY Webmastery News', 'news_panel', null, 'side');
57
add_action('admin_enqueue_scripts', array($this, 'enqueue_credits_styles'));
58
+ add_action('admin_enqueue_scripts', array($this, 'enqueue_admin'));
59
}
60
61
function enqueue_credits_styles() {
62
wp_enqueue_style($this->get_code(), plugins_url('styles/footer-credits.css', dirname(__FILE__)), array(),$this->get_version());
63
}
64
65
+
66
+ function save_credits() {
67
+ check_admin_referer(__CLASS__);
68
+ $page_options = explode(',', stripslashes($_POST['page_options']));
69
+ if ($page_options) {
70
+ $options = $this->credits->get_options();
71
+ foreach ($page_options as $option) {
72
+ $val = array_key_exists($option, $_POST) ? trim(stripslashes($_POST[$option])) : '';
73
+ if ($this->credits->is_terms_key($option))
74
+ $options['terms'][$option] = $val;
75
+ else switch($option) {
76
+ case 'footer_remove' : $options[$option] = !empty($val); break;
77
+ case 'footer_hook':
78
+ case 'footer_filter_hook': $options[$option] = preg_replace('/\W-\//','',$val); break;
79
+ default: $options[$option] = trim($val);
80
+ }
81
+ } //end for ;
82
+ $saved = $this->credits->save_options($options) ;
83
+ $message = $saved ? 'updated successfully' : 'have not been updated';
84
+ $is_error = false;
85
+ } else {
86
+ $is_error = true;
87
+ $message= 'not found!';
88
+ }
89
+ $this->add_admin_notice('Footer Settings ', $message, $is_error);
90
+ return $saved;
91
+ }
92
+
93
function credits_panel($post,$metabox) {
94
$options = $metabox['args']['options'];
95
+ print $this->tabbed_metabox($metabox['id'], array(
96
'Owner' => $this->owner_panel($options['terms']),
97
'Contact' => $this->contact_panel($options['terms']),
98
'Legal' => $this->legal_panel($options['terms']),
101
));
102
}
103
104
function owner_panel($terms) {
105
$s = $this->fetch_text_field('owner', $terms['owner'], array('size' =>30)) .
106
$this->fetch_text_field('country', $terms['country'], array('size' => 30)) .
107
$this->fetch_form_field('address', $terms['address'], 'textarea', array(), array('cols' => 30, 'rows' => 5));
108
+ if ($this->utils->is_html5()) {
109
return $s .
110
'<p>Leave the above address field blank and fill in the various parts of the organization address below if you want to be able to use HTML5 microdata.</p>'.
111
'<h4>Organization Address</h4>'.
144
}
145
146
function advanced_panel($options) {
147
+ $url = 'https://www.diywebmastery.com/footer-credits-compatible-themes-and-hooks';
148
$before = <<< ADVANCED_PANEL
149
<p>You can place the Copyright and Trademark widgets in any existing widget area. However, if your theme does not have a suitably located widget area in the footer then you can create one by specifying the hook
150
where the Widget Area will be located.</p>
152
<i>twentyeleven_credits</i>, <i>twentytwelve_credits</i>,<i>twentythirteen_credits</i> or <i>twentyfourteen_credits</i>. If you using a Genesis child theme and the theme does not have a suitable widget area then use
153
the hook <i>genesis_footer</i> or maybe <i>genesis_after</i>. See what looks best. Click for <a href="{$url}">suggestions of which hook to use for common WordPress themes</a>.</p>
154
ADVANCED_PANEL;
155
+ $f = $this->fetch_text_field('footer_hook', $options['footer_hook'], array('size' => 50)) .
156
$this->fetch_form_field('footer_remove', $options['footer_remove'], 'checkbox');
157
$after = <<< REMOVE_PANEL
158
<p>If your WordPress theme supplies a filter hook rather than an action hook where it generates the footer, and you want to suppress the theme footer,
159
then specify the hook below. For example, entering <i>genesis_footer_output</i> will suppress the standard Genesis child theme footer.</p>
160
REMOVE_PANEL;
161
+ $hook = $this->fetch_text_field('footer_filter_hook', $options['footer_filter_hook'], array('size' => 50));
162
if (($theme = wp_get_theme()) && (strpos(strtolower($theme->get('Name')), 'twenty') !== FALSE))
163
$hook .= $this->fetch_form_field('hide_wordpress', $options['hide_wordpress'], 'checkbox');
164
return $before . $f . $after . $hook;
165
}
166
167
168
+ function preview_panel() {
169
+ printf('<p><i>%1$s</i></p><hr/>%2$s', __('Note: Preview is purely illustrative. Actual footer layout on the site will vary based on footer widget settings.'),
170
+ $this->credits->footer(array('nav_menu' => 'Footer Menu')));
171
}
172
173
+ function intro_panel() {
174
+ printf('<p>%1$s</p>', __('The following information is used in the Footer Copyright Widget and optionally at the end of the Privacy Statement and Terms and Conditions pages.'));
175
+ }
176
+
177
+
178
+
179
}
classes/class-credits-options.php DELETED
@@ -1,161 +0,0 @@
1
- <?php
2
- class Footer_Credits_Options {
3
-
4
- const OPTIONS_NAME = 'footer_credits_options';
5
-
6
- protected static $options = null;
7
-
8
- protected static $defaults = array(
9
- 'terms' => array(
10
- 'site' => '',
11
- 'owner' => '',
12
- 'address' => '',
13
- 'street_address' => '',
14
- 'locality' => '',
15
- 'region' => '',
16
- 'postal_code' => '',
17
- 'country' => '',
18
- 'latitude' => '',
19
- 'longitude' => '',
20
- 'map' => '',
21
- 'email' => '',
22
- 'telephone' => '',
23
- 'copyright' => '',
24
- 'copyright_start_year' => '',
25
- 'copyright_preamble' => '',
26
- 'courts' => '',
27
- 'updated' => '',
28
- 'privacy_contact' => '',
29
- 'terms_contact' => ''),
30
- 'nav_menu' => 0,
31
- 'center' => true,
32
- 'two_lines' => true,
33
- 'separator' => '&nbsp;&middot;&nbsp;',
34
- 'item_separator' => '&nbsp;',
35
- 'section_separator' => '<br/>',
36
- 'show_copyright' => true,
37
- 'show_telephone' => true,
38
- 'show_email' => false,
39
- 'show_address' => true,
40
- 'show_return' => true,
41
- 'return_text' => 'Return To Top',
42
- 'return_class' => '',
43
- 'footer_class' => '',
44
- 'footer_hook' => '',
45
- 'footer_remove' => true,
46
- 'footer_filter_hook' => '',
47
- 'visibility' => '' ,
48
- 'use_microdata' => false,
49
- 'hide_wordpress' => false
50
- );
51
-
52
- public static function init() {
53
- self::theme_specific_defaults();
54
- self::$options = new Footer_Putter_DIY_Options(self::OPTIONS_NAME, self::$defaults);
55
- }
56
-
57
- public static function get_defaults() {
58
- return self::$defaults;
59
- }
60
-
61
- public static function is_terms_key($key) {
62
- return array_key_exists($key, self::$defaults['terms']);
63
- }
64
-
65
- public static function get_option($option_name) {
66
- $options = self::get_options();
67
- if ($option_name && $options && array_key_exists($option_name,$options))
68
- return $options[$option_name];
69
- else
70
- return false;
71
- }
72
-
73
- public static function get_options() {
74
- return self::$options->get_options();
75
- }
76
-
77
- public static function save_options($new_options) {
78
- $new_options['terms'] = self::sanitize_terms($new_options['terms']);
79
- return self::$options->save_options( $new_options) ;
80
- }
81
-
82
- private static function sanitize_terms($new_terms) {
83
- $new_terms = wp_parse_args($new_terms, self::$defaults['terms']); //ensure terms are complete
84
- $new_terms['site'] = self::get_default_site();
85
- $new_terms['copyright'] = self::get_copyright($new_terms['copyright_start_year']); //generate copyright
86
- return $new_terms;
87
- }
88
-
89
- private static function get_default_site() {
90
- $domain = strtolower(parse_url(site_url(),PHP_URL_HOST));
91
- $p = strpos($domain,'www.') ;
92
- if (($p !== FALSE) && ($p == 0)) $domain = substr($domain,4);
93
- return $domain;
94
- }
95
-
96
- public static function get_copyright($startyear='') {
97
- $thisyear = date("Y");
98
- $format = (empty( $startyear) || ($startyear==$thisyear)) ? '%1$s %3$s' : '%1$s %2$s-%3$s';
99
- return sprintf($format, self::get_term('copyright_preamble'), $startyear, $thisyear);
100
- }
101
-
102
- public static function get_terms() {
103
- return self::get_option('terms');
104
- }
105
-
106
- public static function get_term($term_name) {
107
- $options = self::get_options();
108
- $terms = is_array($options) && array_key_exists('terms',$options) ? $options['terms'] : false;
109
- if ($term_name && $terms && array_key_exists($term_name,$terms) && $terms[$term_name])
110
- return $terms[$term_name];
111
- else
112
- return self::get_default_term($term_name);
113
- }
114
-
115
- private static function get_default_term($key) {
116
- $default='';
117
- switch ($key) {
118
- case 'owner' : $default = self::get_term('site'); break;
119
- case 'copyright' : $default = self::get_copyright(self::get_term('copyright_start_year')); break;
120
- case 'copyright_start_year': $default = date('Y'); break;
121
- case 'copyright_preamble': $default = 'Copyright &copy;'; break;
122
- case 'country' : $default = 'The United States'; break;
123
- case 'courts' : $default = ucwords(sprintf('the courts of %1$s',self::get_term('country'))); break;
124
- case 'email' : $default = 'privacy@'.strtolower(self::get_term('site')); break;
125
- case 'site' : $default = self::get_default_site(); break;
126
- case 'updated' : $default = date('d M Y'); break;
127
- default: $default=''; //default is blank for others
128
- }
129
- return $default;
130
- }
131
-
132
- private static function theme_specific_defaults() {
133
- switch (basename( TEMPLATEPATH ) ) {
134
- case 'twentyten':
135
- self::$defaults['footer_hook'] = 'twentyten_credits'; break;
136
- case 'twentyeleven':
137
- self::$defaults['footer_hook'] = 'twentyeleven_credits'; break;
138
- case 'twentytwelve':
139
- self::$defaults['footer_hook'] = 'twentytwelve_credits'; break;
140
- case 'twentythirteen':
141
- self::$defaults['footer_hook'] = 'twentythirteen_credits'; break;
142
- case 'twentyfourteen':
143
- self::$defaults['footer_hook'] = 'twentyfourteen_credits'; break;
144
- case 'delicate':
145
- self::$defaults['footer_hook'] = 'get_footer'; break;
146
- case 'genesis':
147
- self::$defaults['footer_hook'] = 'genesis_footer';
148
- self::$defaults['footer_filter_hook'] = 'genesis_footer_output';
149
- break;
150
- case 'graphene':
151
- self::$defaults['footer_hook'] = 'graphene_footer'; break;
152
- case 'pagelines':
153
- self::$defaults['footer_hook'] = 'pagelines_leaf'; break;
154
- default:
155
- self::$defaults['footer_hook'] = 'wp_footer';
156
- self::$defaults['footer_remove'] = false;
157
- break;
158
- }
159
- }
160
-
161
- }
classes/class-credits-widgets.php CHANGED
@@ -1,8 +1,7 @@
1
<?php
2
- class Footer_Putter_Copyright_Widget extends WP_Widget {
3
4
- private $instance;
5
- private $tooltips;
6
private $defaults = array(
7
'nav_menu' => 0, 'center' => true, 'two_lines' => true,
8
'show_copyright' => true, 'show_address' => true, 'show_telephone' => true, 'show_email' => false,
@@ -11,7 +10,7 @@ class Footer_Putter_Copyright_Widget extends WP_Widget {
11
private $tips = array(
12
'nav_menu' => array('heading' => 'Footer Menu', 'tip' => 'Choose the menu to display in the footer'),
13
'center' => array('heading' => 'Center Menu', 'tip' => 'Center the footer horizontally'),
14
- 'two_lines' => array('heading' => 'Spread Over Two Lines', 'tip' => 'Place the menu and copyright on one line and the contact details on the other'),
15
'show_copyright' => array('heading' => 'Show Copyright', 'tip' => 'Show copyright holder an year range'),
16
'show_address' => array('heading' => 'Show Address', 'tip' => 'Show contact address'),
17
'show_telephone' => array('heading' => 'Show Telephone Number', 'tip' => 'Show telephone number(s)'),
@@ -34,14 +33,15 @@ class Footer_Putter_Copyright_Widget extends WP_Widget {
34
function __construct() {
35
$widget_ops = array( 'description' => __( "A widget displaying menu links, copyright and company details" ) );
36
parent::__construct('footer_copyright', __('Footer Copyright Widget'), $widget_ops);
37
}
38
39
function widget( $args, $instance ) {
40
extract( $args );
41
$instance = wp_parse_args( (array) $instance, $this->defaults );
42
- if (Footer_Putter_Utils::hide_widget($instance['visibility'])) return; //check visibility requirements
43
44
- if ($footer = Footer_Credits::footer($instance))
45
printf ('%1$s%2$s%3$s', $before_widget, $footer, $after_widget);
46
}
47
@@ -54,7 +54,7 @@ class Footer_Putter_Copyright_Widget extends WP_Widget {
54
$instance['show_address'] = !empty($new_instance['show_address']) ? 1 : 0;
55
$instance['use_microdata'] = !empty($new_instance['use_microdata']);
56
$instance['center'] = !empty($new_instance['center']) ? 1 : 0;
57
- $instance['two_lines'] = !empty($new_instance['two_lines']) ? 1 : 0;
58
$instance['show_return'] = !empty($new_instance['show_return']) ? 1 : 0;
59
$instance['return_class'] = trim($new_instance['return_class']);
60
$instance['footer_class'] = trim($new_instance['footer_class']);
@@ -63,6 +63,7 @@ class Footer_Putter_Copyright_Widget extends WP_Widget {
63
}
64
65
function form( $instance ) {
66
$menu_terms = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
67
if ( !$menu_terms ) {
68
echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.' ), admin_url('nav-menus.php') ) .'</p>';
@@ -71,22 +72,17 @@ class Footer_Putter_Copyright_Widget extends WP_Widget {
71
$menus = array();
72
$menus[0] = 'No menu';
73
foreach ( $menu_terms as $term ) $menus[ $term->term_id ] = $term->name;
74
-
75
- $this->instance = wp_parse_args( (array) $instance, $this->get_defaults() );
76
- $this->tooltips = new Footer_Putter_Tooltip($this->get_tips());
77
- print '<div class="diy-wrap">';
78
$this->print_form_field('nav_menu', 'select', $menus);
79
- print ('<hr/><h4>Options</h4>');
80
-
81
$this->print_form_field('center', 'checkbox');
82
- $this->print_form_field('two_lines', 'checkbox');
83
$this->print_form_field('show_copyright', 'checkbox');
84
$this->print_form_field('show_address', 'checkbox');
85
$this->print_form_field('show_telephone', 'checkbox');
86
$this->print_form_field('show_email', 'checkbox');
87
$this->print_form_field('show_return', 'checkbox');
88
- if (Footer_Putter_Utils::is_html5()) $this->print_form_field('use_microdata', 'checkbox');
89
-
90
print <<< CUSTOM_CLASSES
91
<hr/><h4>Custom Classes</h4>
92
<p>Add any custom CSS classes you want apply to the footer section content to change the font color and size.</p>
@@ -97,13 +93,8 @@ CUSTOM_CLASSES;
97
$this->print_form_field('return_class', 'text', array(), array('size' => 10));
98
$this->print_form_field('footer_class', 'text', array(), array('size' => 10));
99
print ('<hr/><h4>Widget Presence</h4>');
100
- $this->print_form_field('visibility', 'radio', Footer_Putter_Utils::get_visibility_options(), array('separator' => '<br />'));
101
print '</div>';
102
- }
103
-
104
- function print_form_field($fld, $type, $options = array(), $args = array()) {
105
- $value = array_key_exists($fld,$this->instance) ? $this->instance[$fld] : false;
106
- print Footer_Putter_Utils::form_field(
107
- $this->get_field_id($fld), $this->get_field_name($fld), $this->tooltips->tip($fld), $value, $type, $options, $args, 'br');
108
- }
109
}
1
<?php
2
+ class Footer_Putter_Copyright_Widget extends Footer_Putter_Widget {
3
4
+ private $credits;
5
private $defaults = array(
6
'nav_menu' => 0, 'center' => true, 'two_lines' => true,
7
'show_copyright' => true, 'show_address' => true, 'show_telephone' => true, 'show_email' => false,
10
private $tips = array(
11
'nav_menu' => array('heading' => 'Footer Menu', 'tip' => 'Choose the menu to display in the footer'),
12
'center' => array('heading' => 'Center Menu', 'tip' => 'Center the footer horizontally'),
13
+ 'layout' => array('heading' => 'Layout', 'tip' => 'Choose order and layout in which menu, copyright and contact are placed, + means same line, | means new line'),
14
'show_copyright' => array('heading' => 'Show Copyright', 'tip' => 'Show copyright holder an year range'),
15
'show_address' => array('heading' => 'Show Address', 'tip' => 'Show contact address'),
16
'show_telephone' => array('heading' => 'Show Telephone Number', 'tip' => 'Show telephone number(s)'),
33
function __construct() {
34
$widget_ops = array( 'description' => __( "A widget displaying menu links, copyright and company details" ) );
35
parent::__construct('footer_copyright', __('Footer Copyright Widget'), $widget_ops);
36
+ $this->credits = $this->plugin->get_credits();
37
}
38
39
function widget( $args, $instance ) {
40
extract( $args );
41
$instance = wp_parse_args( (array) $instance, $this->defaults );
42
+ if ($this->hide_widget($instance['visibility'])) return; //check visibility requirements
43
44
+ if ($footer = $this->credits->footer($instance))
45
printf ('%1$s%2$s%3$s', $before_widget, $footer, $after_widget);
46
}
47
54
$instance['show_address'] = !empty($new_instance['show_address']) ? 1 : 0;
55
$instance['use_microdata'] = !empty($new_instance['use_microdata']);
56
$instance['center'] = !empty($new_instance['center']) ? 1 : 0;
57
+ $instance['layout'] = $new_instance['layout'];
58
$instance['show_return'] = !empty($new_instance['show_return']) ? 1 : 0;
59
$instance['return_class'] = trim($new_instance['return_class']);
60
$instance['footer_class'] = trim($new_instance['footer_class']);
63
}
64
65
function form( $instance ) {
66
+ $this->form_init ($instance, $this->tips);
67
$menu_terms = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
68
if ( !$menu_terms ) {
69
echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.' ), admin_url('nav-menus.php') ) .'</p>';
72
$menus = array();
73
$menus[0] = 'No menu';
74
foreach ( $menu_terms as $term ) $menus[ $term->term_id ] = $term->name;
75
+ print '<div class="diy-wrap">';
76
$this->print_form_field('nav_menu', 'select', $menus);
77
+ print ('<hr/><h4>Options</h4>');
78
$this->print_form_field('center', 'checkbox');
79
$this->print_form_field('show_copyright', 'checkbox');
80
$this->print_form_field('show_address', 'checkbox');
81
$this->print_form_field('show_telephone', 'checkbox');
82
$this->print_form_field('show_email', 'checkbox');
83
$this->print_form_field('show_return', 'checkbox');
84
+ if ($this->utils->is_html5()) $this->print_form_field('use_microdata', 'checkbox');
85
+ $this->print_form_field('layout', 'select', $this->credits->get_layouts());
86
print <<< CUSTOM_CLASSES
87
<hr/><h4>Custom Classes</h4>
88
<p>Add any custom CSS classes you want apply to the footer section content to change the font color and size.</p>
93
$this->print_form_field('return_class', 'text', array(), array('size' => 10));
94
$this->print_form_field('footer_class', 'text', array(), array('size' => 10));
95
print ('<hr/><h4>Widget Presence</h4>');
96
+ $this->print_form_field('visibility', 'radio', $this->get_visibility_options(), array('separator' => '<br />'));
97
print '</div>';
98
+ }
99
+
100
}
classes/class-credits.php CHANGED
@@ -1,133 +1,263 @@
1
<?php
2
-
3
class Footer_Credits {
4
5
- const CODE = 'footer-credits'; //shortcode prefix
6
const SIDEBAR_ID = 'last-footer';
7
8
- public static function init() {
9
- add_action('widgets_init',array(__CLASS__,'register'),20);
10
- add_filter( 'wp_nav_menu_items', array(__CLASS__, 'fix_home_link'), 10, 2 );
11
- if (!is_admin()) add_action('wp',array(__CLASS__,'prepare'));
12
}
13
14
- public static function register() {
15
- self::register_sidebars();
16
- self::register_widgets();
17
}
18
19
- private static function register_sidebars() {
20
- if (Footer_Credits_Options::get_option('footer_hook')) {
21
- $tag = self::is_html5() ? 'section' : 'div';
22
register_sidebar( array(
23
'id' => self::SIDEBAR_ID,
24
- 'name' => __( 'Credibility Footer', __CLASS__ ),
25
- 'description' => __( 'Custom footer section for copyright, trademarks, etc', __CLASS__),
26
'before_widget' => '<'.$tag.' id="%1$s" class="widget %2$s"><div class="widget-wrap">',
27
'after_widget' => '</div></'.$tag.'>'
28
) );
29
}
30
}
31
32
- private static function register_widgets() {
33
if (class_exists('Footer_Putter_Copyright_Widget')) register_widget('Footer_Putter_Copyright_Widget');
34
if (class_exists('Footer_Putter_Trademark_Widget')) register_widget('Footer_Putter_Trademark_Widget');
35
}
36
-
37
- public static function is_html5() {
38
- return Footer_Putter_Utils::is_html5();
39
- }
40
41
- public static function prepare() {
42
- add_shortcode(self::CODE, array(__CLASS__, 'footer' ) );
43
- add_shortcode(self::CODE.'-contact', array(__CLASS__, 'contact' ) );
44
- add_shortcode(self::CODE.'-copyright', array(__CLASS__, 'copyright' ) );
45
- add_shortcode(self::CODE.'-menu', array(__CLASS__, 'footer_menu' ) );
46
add_filter('widget_text', 'do_shortcode', 11);
47
- add_action('wp_enqueue_scripts',array(__CLASS__, 'enqueue_styles' ));
48
49
- $options = Footer_Credits_Options::get_options();
50
51
//insert custom footer at specified hook
52
- if ($footer_hook = $options['footer_hook']) {
53
- if ($options['footer_remove']) {
54
- remove_all_actions( $footer_hook);
55
- if ($footer_hook =='wp_footer') {
56
- add_action( 'wp_footer', 'wp_print_footer_scripts', 20); //put back the footer scripts
57
- add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); //put back the admin bar
58
- }
59
- }
60
- add_action( $footer_hook, array(__CLASS__, 'custom_footer'));
61
}
62
63
//suppress footer output
64
- if ($ffs = $options['footer_filter_hook'])
65
- add_filter($ffs, array(__CLASS__, 'no_footer'),100);
66
67
- if (is_page('privacy') && Footer_Credits_Options::get_term('privacy_contact'))
68
- add_filter('the_content', array(__CLASS__, 'add_privacy_footer'),9 );
69
70
- if (is_page('terms') && Footer_Credits_Options::get_term('terms_contact'))
71
- add_filter('the_content', array(__CLASS__, 'add_terms_footer'),9 );
72
73
if (is_page('terms') || is_page('privacy') || is_page('affiliates') || is_page('disclaimer'))
74
- add_filter('the_content', array(__CLASS__, 'terms_filter') );
75
76
}
77
78
- public static function enqueue_styles() {
79
- wp_enqueue_style('footer-credits', plugins_url('styles/footer-credits.css',dirname(__FILE__)), array(), FOOTER_PUTTER_VERSION);
80
}
81
82
- public static function register_admin_styles() {
83
- wp_register_style('footer-credits-admin', plugins_url('styles/admin.css',dirname(__FILE__)), array(), FOOTER_PUTTER_VERSION);
84
}
85
86
- public static function enqueue_admin_styles() {
87
- wp_enqueue_style('footer-credits-admin');
88
}
89
90
- public static function return_to_top( $text, $class) {
91
- return sprintf( '<div id="footer-return" class="%1$s"><a rel="nofollow" href="#" onclick="window.scrollTo(0,0); return false;" >%2$s</a></div>', trim($class), $text);
92
}
93
94
- private static function contact_info($params) {
95
$org ='';
96
- if ($address = self::contact_address($params['show_address'], $params['use_microdata'], $params['separator'], $params['section_separator'])) $org .= $address;
97
- if ($telephone = self::contact_telephone($params['show_telephone'], $params['use_microdata'], $params['item_separator'])) $org .= $telephone;
98
- if ($email = self::contact_email($params['show_email'], $params['use_microdata'], $params['item_separator'])) $org .= $email;
99
- $format = '<span' . ($params['use_microdata'] ? ' itemscope="itemscope" itemtype="http://schema.org/Organization"' : '') . '>%1$s</span>';
100
- return sprintf($format, $org);
101
}
102
103
- private static function contact_telephone($show_telephone, $microdata, $prefix) {
104
- if ($show_telephone && ($telephone = Footer_Credits_Options::get_term('telephone')))
105
if ($microdata)
106
- return sprintf('%1$s<span itemprop="telephone" class="telephone">%2$s</span>', $prefix, $telephone) ;
107
else
108
- return sprintf('%1$s<span class="telephone">%2$s</span>', $prefix, $telephone) ;
109
else
110
return '';
111
}
112
113
- private static function contact_email($show_email, $microdata, $prefix) {
114
- if ($show_email && ($email = Footer_Credits_Options::get_term('email')))
115
- return apply_filters ( 'footer_putter_contact_email',
116
- sprintf('%1$s<a href="mailto:%2$s" class="email"%3$s>%2$s</a>', $prefix, $email, $microdata ? ' itemprop="email"' : '') );
117
else
118
return '';
119
}
120
121
- private static function contact_address($show_address, $microdata, $separator, $prefix) {
122
if ($show_address)
123
if ($microdata) {
124
- return self::org_location($separator, $prefix);
125
- } elseif ($address = Footer_Credits_Options::get_term('address'))
126
- return sprintf('%1$s<span class="address">%2$s%3$s</span>', $prefix, self::format_address($address, $separator), Footer_Credits_Options::get_term('country'));
127
return '';
128
}
129
130
- private static function format_address ($address, $separator) {
131
$s='';
132
$addlines = explode(',', trim($address));
133
foreach ($addlines as $a) {
@@ -137,28 +267,28 @@ class Footer_Credits {
137
return $s;
138
}
139
140
- private static function org_location($separator, $prefix) {
141
$location = '';
142
- if ($loc_address = self::location_address( $separator)) $location .= $loc_address;
143
- if ($loc_geo = self::location_geo()) $location .= $loc_geo;
144
- if ($loc_map = self::location_map()) $location .= $loc_map;
145
if ($location)
146
- return sprintf('%1$s<span itemprop="location" itemscope="itemscope" itemtype="http://schema.org/Place">%2$s</span>', $prefix, $location) ;
147
else
148
return '';
149
}
150
151
- private static function location_address($separator) {
152
$address = '';
153
- if ( $street_address = Footer_Credits_Options::get_term('street_address'))
154
- $address .= sprintf('<span itemprop="streetAddress">%1$s</span>', self::format_address($street_address, $separator)) ;
155
- if ( $locality = Footer_Credits_Options::get_term('locality'))
156
- $address .= sprintf('<span itemprop="addressLocality">%1$s</span>', self::format_address($locality, $separator)) ;
157
- if ( $region = Footer_Credits_Options::get_term('region'))
158
- $address .= sprintf('<span itemprop="addressRegion">%1$s</span>', self::format_address($region, $separator)) ;
159
- if ( $postal_code = Footer_Credits_Options::get_term('postal_code'))
160
- $address .= sprintf('<span itemprop="postalCode">%1$s</span>', self::format_address($postal_code, $separator)) ;
161
- if ( $country = Footer_Credits_Options::get_term('country'))
162
$address .= sprintf('<span itemprop="addressCountry">%1$s</span>', $country) ;
163
164
if ($address)
@@ -167,84 +297,93 @@ class Footer_Credits {
167
return '';
168
}
169
170
- private static function location_geo() {
171
$geo = '';
172
- if ( $latitude = Footer_Credits_Options::get_term('latitude')) $geo .= sprintf('<meta itemprop="latitude" content="%1$s" />', $latitude) ;
173
- if ( $longitude = Footer_Credits_Options::get_term('longitude')) $geo .= sprintf('<meta itemprop="longitude" content="%1$s" />', $longitude) ;
174
return $geo ? sprintf('<span itemprop="geo" itemscope="itemscope" itemtype="http://schema.org/GeoCoordinates">%1$s</span>', $geo) : '';
175
}
176
177
- private static function location_map() {
178
- if ( $map = Footer_Credits_Options::get_term('map'))
179
return sprintf('<a rel="nofollow external" target="_blank" class="map" itemprop="map" href="%1$s">%2$s</a>', $map, __('Map')) ;
180
else
181
return '';
182
}
183
184
- public static function copyright_owner($params){
185
return sprintf('<span class="copyright">%1$s %2$s</span>',
186
- Footer_Credits_Options::get_copyright($params['copyright_start_year']), $params['owner']);
187
}
188
189
- public static function contact($atts = array()) {
190
- $all_defaults = Footer_Credits_Options::get_defaults();
191
$defaults = array();
192
- $defaults['show_telephone'] = $all_defaults['show_telephone'];
193
- $defaults['show_email'] = $all_defaults['show_email'];
194
- $defaults['show_address'] = $all_defaults['show_address'];
195
- $defaults['use_microdata'] = $all_defaults['use_microdata'];
196
- $defaults['separator'] = $all_defaults['separator'];
197
- $defaults['item_separator'] = $all_defaults['item_separator'];
198
- $defaults['section_separator'] = $all_defaults['section_separator'];
199
- $defaults['footer_class'] = self::CODE;
200
$params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
201
- return sprintf ('<span class="%1$s">%2$s</span>', $params['footer_class'], self::contact_info($params));
202
}
203
204
- public static function copyright($atts = array()){
205
$defaults = array();
206
- $defaults['owner'] = Footer_Credits_Options::get_term('owner');
207
- $defaults['copyright_start_year'] = Footer_Credits_Options::get_term('copyright_start_year');
208
- $defaults['footer_class'] = self::CODE;
209
$params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
210
- return sprintf ('<span class="%1$s">%2$s</span>', $params['footer_class'], self::copyright_owner($params));
211
}
212
213
- public static function footer_menu($atts = array()) {
214
$defaults = array('menu' => 'Footer Menu', 'echo' => false, 'container' => false, 'footer_class' => self::CODE);
215
$params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
216
- return sprintf ('<span class="%1$s">%2$s</span>', $params['footer_class'], wp_nav_menu($params));
217
}
218
219
- public static function footer($atts = array()) {
220
- $params = shortcode_atts( Footer_Credits_Options::get_options(), $atts ); //apply plugin defaults
221
222
if ($params['center']) {
223
- if (! $params['two_lines']) $params['section_separator'] = $params['item_separator'];
224
- $params['return_class'] .= ' return-center';
225
- $params['footer_class'] .= ' footer-center';
226
$clear = '';
227
} else {
228
- if (! $params['two_lines']) $params['item_separator'] = $params['section_separator'] ;
229
- $params['return_class'] .= ' return-left';
230
- $params['footer_class'] .= ' footer-right';
231
$clear = '<div class="clear"></div>';
232
}
233
- $format = '<div id="%1$s" class="%2$s">%3$s%4$s%5$s</div>%6$s';
234
return (empty($params['show_return']) ? '' :
235
- self::return_to_top($params['return_text'], $params['return_class'])) .
236
sprintf($format,
237
self::CODE,
238
- $params['footer_class'],
239
- (empty($params['nav_menu']) ? '' : self::footer_menu(array('menu' => $params['nav_menu']))),
240
- (empty($params['show_copyright']) ? '' : sprintf('%1$s%2$s', $params['item_separator'], self::copyright_owner(Footer_Credits_Options::get_terms()))),
241
- self::contact_info($params),
242
$clear
243
);
244
}
245
246
- public static function terms_filter($content) {
247
- if ($terms = Footer_Credits_Options::get_terms()) {
248
$from = array();
249
$to = array();
250
foreach ($terms as $term => $value) {
@@ -256,10 +395,10 @@ class Footer_Credits {
256
return $content;
257
}
258
259
- public static function custom_footer() {
260
if ( is_active_sidebar( self::SIDEBAR_ID) ) {
261
- $class = 'custom-footer'. (Footer_Credits_Options::get_option('hide_wordpress') ? ' hide-wordpress' :'');
262
- if (self::is_html5()) {
263
printf('<footer class="%1$s" role="contentinfo" itemscope="itemscope" itemtype="http://schema.org/WPFooter">', $class);
264
dynamic_sidebar( self::SIDEBAR_ID );
265
echo '</footer><!-- end .custom-footer -->';
@@ -271,39 +410,48 @@ class Footer_Credits {
271
}
272
}
273
274
- public static function no_footer($content) { return ''; }
275
276
- public static function add_privacy_footer($content) {
277
- $terms = Footer_Credits_Options::get_terms();
278
- $email = $terms['email'];
279
$contact = <<< PRIVACY
280
<h2>How to Contact Us</h2>
281
- <p>Questions about this statement or about our handling of your information may be sent by email to <a href="mailto:{$email}">{$email}</a>, or by post to {$terms['owner']} Privacy Office, {$terms['address']} {$terms['country']}. </p>
282
PRIVACY;
283
return (strpos($content,'%%') == FALSE) ? ($content . $contact) : $content;
284
}
285
286
- public static function add_terms_footer($content) {
287
- $terms = Footer_Credits_Options::get_terms();
288
$disputes = <<< DISPUTES
289
<h2>Dispute Resolution</h2>
290
- <p>These terms, and any dispute arising from the use of this site, will be governed by {$terms['courts']} without regard to its conflicts of laws provisions.</p>
291
DISPUTES;
292
- $feedback = <<< FEEDBACK
293
<h2>Feedback And Information</h2>
294
- <p>Any feedback you provide at this site shall be deemed to be non-confidential. {$terms['owner']} shall be free to use such information on an unrestricted basis.</p>
295
<p>The terms and conditions for this web site are subject to change without notice.<p>
296
- <p>{$terms['copyright']} {$terms['owner']} All rights reserved.<br/> {$terms['owner']}, {$terms['address']} {$terms['country']}</p>
297
- <p>Updated by The {$terms['owner']} Legal Team on {$terms['updated']}</p>
298
- FEEDBACK;
299
if (strpos($content,'%%') == FALSE) {
300
- $content .= $terms['courts'] ? $disputes : '';
301
- $content .= $terms['address'] ? $feedback : '';
302
}
303
return $content ;
304
}
305
306
- public static function fix_home_link( $content, $args) {
307
$class = is_front_page()? ' class="current_page_item"' : '';
308
$home_linktexts = array('Home','<span>Home</span>');
309
foreach ($home_linktexts as $home_linktext) {
@@ -314,5 +462,47 @@ FEEDBACK;
314
return $content;
315
}
316
317
- }
318
1
<?php
2
class Footer_Credits {
3
4
+ const CODE = 'footer-credits'; //element prefix
5
+ const OPTIONS_NAME = 'footer_credits_options';
6
const SIDEBAR_ID = 'last-footer';
7
8
+ protected $defaults = array(
9
+ 'terms' => array(
10
+ 'site' => '',
11
+ 'owner' => '',
12
+ 'address' => '',
13
+ 'street_address' => '',
14
+ 'locality' => '',
15
+ 'region' => '',
16
+ 'postal_code' => '',
17
+ 'country' => '',
18
+ 'latitude' => '',
19
+ 'longitude' => '',
20
+ 'map' => '',
21
+ 'email' => '',
22
+ 'telephone' => '',
23
+ 'copyright' => '',
24
+ 'copyright_start_year' => '',
25
+ 'copyright_preamble' => '',
26
+ 'courts' => '',
27
+ 'updated' => '',
28
+ 'privacy_contact' => '',
29
+ 'terms_contact' => ''),
30
+ 'nav_menu' => 0,
31
+ 'center' => true,
32
+ 'layout' => false,
33
+ 'separator' => '&nbsp;&middot;&nbsp;',
34
+ 'show_copyright' => true,
35
+ 'show_telephone' => true,
36
+ 'show_email' => false,
37
+ 'show_address' => true,
38
+ 'show_return' => true,
39
+ 'return_text' => 'Return To Top',
40
+ 'return_class' => '',
41
+ 'footer_class' => '',
42
+ 'footer_hook' => '',
43
+ 'footer_remove' => true,
44
+ 'footer_filter_hook' => '',
45
+ 'visibility' => '' ,
46
+ 'use_microdata' => false,
47
+ 'hide_wordpress' => false
48
+ );
49
+
50
+ private $layouts = array(
51
+ 'single' => 'Single line: Menu + copyright + contact',
52
+ 'single-alt' => 'Single line: Menu + contact + copyright',
53
+ 'contact-below' => '2 lines: Menu + copyright | Contact',
54
+ 'copyright-below' => '2 lines: Menu + contact | Copyright',
55
+ 'menu-above' => '2 lines: Menu | Copyright + contact',
56
+ 'menu-above-alt' => '2 lines: Menu | Contact + copyright',
57
+ 'stacked' => '3 lines : Menu | Copyright | Contact',
58
+ 'stacked-alt' => '3 lines : Menu | Contact | Copyright');
59
+
60
+ protected $is_landing = false;
61
+ private $plugin;
62
+ private $utils;
63
+ private $options;
64
+
65
+ function __construct(){
66
+ $this->plugin = Footer_Putter_Plugin::get_instance();
67
+ $this->utils = $this->plugin->get_utils();
68
+ $this->init();
69
+ }
70
+
71
+ public function init() {
72
+ $defaults = $this->theme_specific_defaults($this->defaults);
73
+ $this->options = new Footer_Putter_Options(self::OPTIONS_NAME, $defaults);
74
+ add_action('widgets_init',array($this,'register'),20);
75
+ add_filter( 'wp_nav_menu_items', array($this, 'fix_home_link'), 10, 2 );
76
+ if (!is_admin()) add_action('wp',array($this,'prepare'));
77
}
78
79
+ function register() {
80
+ $this->register_sidebars();
81
+ $this->register_widgets();
82
}
83
84
+ private function register_sidebars() {
85
+ if ($this->get_option('footer_hook')) {
86
+ $tag = $this->is_html5() ? 'section' : 'div';
87
register_sidebar( array(
88
'id' => self::SIDEBAR_ID,
89
+ 'name' => __( 'Credibility Footer' ),
90
+ 'description' => __( 'Custom footer section for copyright, trademarks, etc.'),
91
'before_widget' => '<'.$tag.' id="%1$s" class="widget %2$s"><div class="widget-wrap">',
92
'after_widget' => '</div></'.$tag.'>'
93
) );
94
}
95
}
96
97
+ private function register_widgets() {
98
if (class_exists('Footer_Putter_Copyright_Widget')) register_widget('Footer_Putter_Copyright_Widget');
99
if (class_exists('Footer_Putter_Trademark_Widget')) register_widget('Footer_Putter_Trademark_Widget');
100
}
101
102
+ function prepare() {
103
+ add_shortcode(self::CODE, array($this, 'footer' ) );
104
+ add_shortcode(self::CODE.'-contact', array($this, 'contact' ) );
105
+ add_shortcode(self::CODE.'-copyright', array($this, 'copyright' ) );
106
+ add_shortcode(self::CODE.'-menu', array($this, 'footer_menu' ) );
107
+ add_shortcode(self::CODE.'-return', array($this, 'footer_return' ) );
108
add_filter('widget_text', 'do_shortcode', 11);
109
+ add_action('wp_enqueue_scripts',array($this, 'enqueue_styles' ));
110
111
+ $this->is_landing = $this->utils->is_landing_page();
112
113
//insert custom footer at specified hook
114
+ if ($footer_hook = $this->get_option('footer_hook')) {
115
+ if ($this->get_option('footer_remove')) {
116
+ remove_all_actions( $footer_hook);
117
+ if ($footer_hook =='wp_footer') {
118
+ add_action( 'wp_footer', 'wp_print_footer_scripts', 20); //put back the footer scripts
119
+ add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); //put back the admin bar
120
+ }
121
+ }
122
+ add_action( $footer_hook, array($this, 'custom_footer'));
123
}
124
125
//suppress footer output
126
+ if ($ffs = $this->get_option('footer_filter_hook'))
127
+ add_filter($ffs, array($this, 'no_footer'),100);
128
129
+ if (is_page('privacy') && $this->get_term('privacy_contact'))
130
+ add_filter('the_content', array($this, 'add_privacy_footer'),9 );
131
132
+ if (is_page('terms') && $this->get_term('terms_contact'))
133
+ add_filter('the_content', array($this, 'add_terms_footer'),9 );
134
135
if (is_page('terms') || is_page('privacy') || is_page('affiliates') || is_page('disclaimer'))
136
+ add_filter('the_content', array($this, 'terms_filter') );
137
138
}
139
140
+ function enqueue_styles() {
141
+ wp_enqueue_style('footer-credits', plugins_url('styles/footer-credits.css',dirname(__FILE__)), array(), $this->plugin->get_version());
142
+ }
143
+
144
+ function get_option($option_name) {
145
+ $options = $this->get_options();
146
+ if ($option_name && $options && array_key_exists($option_name,$options))
147
+ return $options[$option_name];
148
+ else
149
+ return false;
150
}
151
152
+ function get_options() {
153
+ return $this->options->get_options();
154
+ }
155
+
156
+ function save_options($new_options) {
157
+ $new_options['terms'] = $this->sanitize_terms($new_options['terms']);
158
+ return $this->options->save_options( $new_options) ;
159
+ }
160
+
161
+ function get_layouts() { return $this->layouts; }
162
+
163
+ function is_html5() {
164
+ return $this->utils->is_html5();
165
}
166
167
+ private function sanitize_terms($new_terms) {
168
+ $new_terms = wp_parse_args($new_terms, $this->defaults['terms']); //ensure terms are complete
169
+ $new_terms['site'] = $this->get_default_site();
170
+ $new_terms['copyright'] = $this->get_copyright($new_terms['copyright_start_year']); //generate copyright
171
+ return $new_terms;
172
+ }
173
+
174
+ public function is_terms_key($key) {
175
+ return array_key_exists($key, $this->defaults['terms']);
176
+ }
177
+
178
+ public function get_terms() {
179
+ return $this->get_option('terms');
180
+ }
181
+
182
+ public function get_term($term_name) {
183
+ $options = $this->get_options();
184
+ $terms = is_array($options) && array_key_exists('terms',$options) ? $options['terms'] : false;
185
+ if ($term_name && $terms && array_key_exists($term_name,$terms) && $terms[$term_name])
186
+ return $terms[$term_name];
187
+ else
188
+ return $this->get_default_term($term_name);
189
+ }
190
+
191
+ private function get_default_term($key) {
192
+ $default='';
193
+ switch ($key) {
194
+ case 'owner' : $default = $this->get_term('site'); break;
195
+ case 'copyright' : $default = $this->get_copyright($this->get_term('copyright_start_year')); break;
196
+ case 'copyright_start_year': $default = date('Y'); break;
197
+ case 'copyright_preamble': $default = 'Copyright &copy;'; break;
198
+ case 'country' : $default = 'The United States'; break;
199
+ case 'courts' : $default = ucwords(sprintf('the courts of %1$s',$this->get_term('country'))); break;
200
+ case 'email' : $default = 'privacy@'.strtolower($this->get_term('site')); break;
201
+ case 'site' : $default = $this->get_default_site(); break;
202
+ case 'updated' : $default = date('d M Y'); break;
203
+ default: $default=''; //default is blank for others
204
+ }
205
+ return $default;
206
+ }
207
+
208
+ private function get_default_site() {
209
+ $domain = strtolower(parse_url(site_url(),PHP_URL_HOST));
210
+ $p = strpos($domain,'www.') ;
211
+ if (($p !== FALSE) && ($p == 0)) $domain = substr($domain,4);
212
+ return $domain;
213
+ }
214
+
215
+ public function get_copyright($startyear=''){
216
+ $thisyear = date("Y");
217
+ $format = (empty( $startyear) || ($startyear==$thisyear)) ? '%1$s %3$s' : '%1$s %2$s-%3$s';
218
+ return sprintf($format, $this->get_term('copyright_preamble'), $startyear, $thisyear);
219
}
220
221
+ public function return_to_top( $text, $class) {
222
+ return sprintf( '<div class="footer-return %1$s"><a rel="nofollow" href="#" onclick="window.scrollTo(0,0); return false;" >%2$s</a></div>', trim($class), $text);
223
}
224
225
+ private function contact_info($params) {
226
$org ='';
227
+ if ($address = $this->contact_address($params['show_address'], $params['use_microdata'], $params['separator'])) $org .= $address;
228
+ if ($telephone = $this->contact_telephone($params['show_telephone'], $params['use_microdata'])) $org .= $telephone;
229
+ if ($email = $this->contact_email($params['show_email'], $params['use_microdata'])) $org .= $email;
230
+ $format = '<div class="footer-credits-contact %1$s" ' . ($params['use_microdata'] ? ' itemscope="itemscope" itemtype="http://schema.org/Organization"' : '') . '>%2$s</div>';
231
+ return sprintf($format, $params['footer_class'], $org);
232
}
233
234
+ private function contact_telephone($show_telephone, $microdata ) {
235
+ if ($show_telephone && ($telephone = $this->get_term('telephone')))
236
if ($microdata)
237
+ return sprintf('<span itemprop="telephone" class="telephone">%1$s</span>', $telephone) ;
238
else
239
+ return sprintf('<span class="telephone">%1$s</span>', $telephone) ;
240
else
241
return '';
242
}
243
244
+ private function contact_email($show_email, $microdata) {
245
+ if ($show_email && ($email = $this->get_term('email')))
246
+ return sprintf('<a href="mailto:%1$s" class="email"%2$s>%1$s</a>', $email, $microdata ? ' itemprop="email"' : '') ;
247
else
248
return '';
249
}
250
251
+ private function contact_address($show_address, $microdata, $separator) {
252
if ($show_address)
253
if ($microdata) {
254
+ return $this->org_location($separator);
255
+ } elseif ($address = $this->get_term('address'))
256
+ return sprintf('<span class="address">%1$s%2$s</span>', $this->format_address($address, $separator), $this->get_term('country'));
257
return '';
258
}
259
260
+ private function format_address ($address, $separator) {
261
$s='';
262
$addlines = explode(',', trim($address));
263
foreach ($addlines as $a) {
267
return $s;
268
}
269
270
+ private function org_location($separator) {
271
$location = '';
272
+ if ($loc_address = $this->location_address( $separator)) $location .= $loc_address;
273
+ if ($loc_geo = $this->location_geo()) $location .= $loc_geo;
274
+ if ($loc_map = $this->location_map()) $location .= $loc_map;
275
if ($location)
276
+ return sprintf('<span itemprop="location" itemscope="itemscope" itemtype="http://schema.org/Place">%1$s</span>', $location) ;
277
else
278
return '';
279
}
280
281
+ private function location_address($separator) {
282
$address = '';
283
+ if ( $street_address = $this->get_term('street_address'))
284
+ $address .= sprintf('<span itemprop="streetAddress">%1$s</span>', $this->format_address($street_address, $separator)) ;
285
+ if ( $locality = $this->get_term('locality'))
286
+ $address .= sprintf('<span itemprop="addressLocality">%1$s</span>', $this->format_address($locality, $separator)) ;
287
+ if ( $region = $this->get_term('region'))
288
+ $address .= sprintf('<span itemprop="addressRegion">%1$s</span>', $this->format_address($region, $separator)) ;
289
+ if ( $postal_code = $this->get_term('postal_code'))
290
+ $address .= sprintf('<span itemprop="postalCode">%1$s</span>', $this->format_address($postal_code, $separator)) ;
291
+ if ( $country = $this->get_term('country'))
292
$address .= sprintf('<span itemprop="addressCountry">%1$s</span>', $country) ;
293
294
if ($address)
297
return '';
298
}
299
300
+ private function location_geo() {
301
$geo = '';
302
+ if ( $latitude = $this->get_term('latitude')) $geo .= sprintf('<meta itemprop="latitude" content="%1$s" />', $latitude) ;
303
+ if ( $longitude = $this->get_term('longitude')) $geo .= sprintf('<meta itemprop="longitude" content="%1$s" />', $longitude) ;
304
return $geo ? sprintf('<span itemprop="geo" itemscope="itemscope" itemtype="http://schema.org/GeoCoordinates">%1$s</span>', $geo) : '';
305
}
306
307
+ private function location_map() {
308
+ if ( $map = $this->get_term('map'))
309
return sprintf('<a rel="nofollow external" target="_blank" class="map" itemprop="map" href="%1$s">%2$s</a>', $map, __('Map')) ;
310
else
311
return '';
312
}
313
314
+ public function copyright_owner($params){
315
return sprintf('<span class="copyright">%1$s %2$s</span>',
316
+ $this->get_copyright($params['copyright_start_year']), $params['owner']);
317
}
318
319
+ public function contact($atts = array()) {
320
$defaults = array();
321
+ $defaults['show_telephone'] = $this->defaults['show_telephone'];
322
+ $defaults['show_email'] = $this->defaults['show_email'];
323
+ $defaults['show_address'] = $this->defaults['show_address'];
324
+ $defaults['use_microdata'] = $this->defaults['use_microdata'];
325
+ $defaults['separator'] = $this->defaults['separator'];
326
+ $defaults['footer_class'] = '';
327
$params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
328
+ return $this->contact_info($params);
329
}
330
331
+ public function copyright($atts = array()){
332
$defaults = array();
333
+ $defaults['owner'] = $this->get_term('owner');
334
+ $defaults['copyright_start_year'] = $this->get_term('copyright_start_year');
335
+ $defaults['footer_class'] = '';
336
$params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
337
+ return sprintf('<div class="footer-credits-copyright %1$s">%2$s</div>', $params['footer_class'], $this->copyright_owner($params));
338
}
339
340
+ public function footer_menu($atts = array()) {
341
$defaults = array('menu' => 'Footer Menu', 'echo' => false, 'container' => false, 'footer_class' => self::CODE);
342
+ if (isset($atts['nav_menu'])) $atts['menu'] = $atts['nav_menu'];
343
$params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
344
+ return sprintf ('<div class="footer-credits-menu %1$s">%2$s</div>', $params['footer_class'], wp_nav_menu($params));
345
}
346
347
+ public function footer($atts = array()) {
348
+ $params = shortcode_atts( $this->get_options(), $atts ); //apply plugin defaults
349
350
if ($params['center']) {
351
+ $return_class = 'return-center';
352
+ $footer_class = 'footer-center';
353
$clear = '';
354
} else {
355
+ $return_class = ' return-left';
356
+ $footer_class = ' footer-right';
357
$clear = '<div class="clear"></div>';
358
}
359
+ $layout = isset($atts['layout']) ? $atts['layout'] : 'single';
360
+
361
+ $format = '<div class="%4$s %5$s %6$s">'.$this->get_footer_content_order($layout).'</div>%7$s';
362
return (empty($params['show_return']) ? '' :
363
+ $this->return_to_top($params['return_text'], $return_class. ' ' . $params['return_class'])) .
364
sprintf($format,
365
+ (empty($params['nav_menu']) ? '' : $this->footer_menu($params)),
366
+ (empty($params['show_copyright']) ? '' : $this->copyright($params)),
367
+ $this->contact_info($params),
368
self::CODE,
369
+ $footer_class,
370
+ $layout,
371
$clear
372
);
373
}
374
375
+ private function get_footer_content_order($layout) {
376
+ switch ($layout) {
377
+ case 'single-alt':
378
+ case 'copyright-below':
379
+ case 'menu-above-alt':
380
+ case 'stacked-alt': return '%1$s%3$s%2$s';
381
+ }
382
+ return '%1$s%2$s%3$s';
383
+ }
384
+
385
+ public function terms_filter($content) {
386
+ if ($terms = $this->get_terms()) {
387
$from = array();
388
$to = array();
389
foreach ($terms as $term => $value) {
395
return $content;
396
}
397
398
+ public function custom_footer() {
399
if ( is_active_sidebar( self::SIDEBAR_ID) ) {
400
+ $class = 'custom-footer'. ($this->get_option('hide_wordpress') ? ' hide-wordpress' :'');
401
+ if ($this->is_html5()) {
402
printf('<footer class="%1$s" role="contentinfo" itemscope="itemscope" itemtype="http://schema.org/WPFooter">', $class);
403
dynamic_sidebar( self::SIDEBAR_ID );
404
echo '</footer><!-- end .custom-footer -->';
410
}
411
}
412
413
+ public function no_footer($content) { return ''; }
414
415
+ public function add_privacy_footer($content) {
416
+ $email = $this->get_term('email');
417
+ $address = $this->get_term('address');
418
+ $country = $this->get_term('country');
419
+ $owner = $this->get_term('owner');
420
$contact = <<< PRIVACY
421
<h2>How to Contact Us</h2>
422
+ <p>Questions about this statement or about our handling of your information may be sent by email to <a href="mailto:{$email}">{$email}</a>, or by post to {$owner} Privacy Office, {$address} {$country}. </p>
423
PRIVACY;
424
return (strpos($content,'%%') == FALSE) ? ($content . $contact) : $content;
425
}
426
427
+ public function add_terms_footer($content) {
428
+ $email = $this->get_term('email');
429
+ $address = $this->get_term('address');
430
+ $country = $this->get_term('country');
431
+ $courts = $this->get_term('courts');
432
+ $owner = $this->get_term('owner');
433
+ $copyright = $this->get_term('copyright');
434
+ $updated = $this->get_term('updated');
435
+ $terms_contact = $this->get_term('terms_contact');
436
$disputes = <<< DISPUTES
437
<h2>Dispute Resolution</h2>
438
+ <p>These terms, and any dispute arising from the use of this site, will be governed by {$courts} without regard to its conflicts of laws provisions.</p>
439
DISPUTES;
440
+ $terms = <<< TERMS
441
<h2>Feedback And Information</h2>
442
+ <p>Any feedback you provide at this site shall be deemed to be non-confidential. {$owner} shall be free to use such information on an unrestricted basis.</p>
443
<p>The terms and conditions for this web site are subject to change without notice.<p>
444
+ <p>{$copyright} {$owner} All rights reserved.<br/> {$owner}, {$address} {$country}</p>
445
+ <p>Updated by The {$owner} Legal Team on {$updated}</p>
446
+ TERMS;
447
if (strpos($content,'%%') == FALSE) {
448
+ $content .= $courts ? $disputes : '';
449
+ $content .= $address ? $terms : '';
450
}
451
return $content ;
452
}
453
454
+ function fix_home_link( $content, $args) {
455
$class = is_front_page()? ' class="current_page_item"' : '';
456
$home_linktexts = array('Home','<span>Home</span>');
457
foreach ($home_linktexts as $home_linktext) {
462
return $content;
463
}
464
465
+ function footer_return($atts = array()) {
466
+ $defaults = array('return_text' => $this->defaults['return_text'], 'return_class' => $this->defaults['return_class']);
467
+ $params = shortcode_atts( $defaults, $atts ); //apply plugin defaults
468
+ return $this->return_to_top($params['return_text'], $params['return_class']);
469
+ }
470
471
+ function theme_specific_defaults($defaults) {
472
+ switch (basename( TEMPLATEPATH ) ) {
473
+ case 'twentyten':
474
+ $defaults['footer_hook'] = 'twentyten_credits'; break;
475
+ case 'twentyeleven':
476
+ $defaults['footer_hook'] = 'twentyeleven_credits'; break;
477
+ case 'twentytwelve':
478
+ $defaults['footer_hook'] = 'twentytwelve_credits'; break;
479
+ case 'twentythirteen':
480
+ $defaults['footer_hook'] = 'twentythirteen_credits'; break;
481
+ case 'twentyfourteen':
482
+ $defaults['footer_hook'] = 'twentyfourteen_credits'; break;
483
+ case 'twentyfifteen':
484
+ $defaults['footer_hook'] = 'twentyfifteen_credits'; break;
485
+ case 'twentysixteen':
486
+ $defaults['footer_hook'] = 'twentysixteen_credits'; break;
487
+ case 'twentyseventeen':
488
+ $defaults['footer_hook'] = 'get_template_part_template-parts/footer/site'; break;
489
+ case 'generatepress':
490
+ $defaults['footer_hook'] = 'generate_credits'; break;
491
+ case 'delicate':
492
+ $defaults['footer_hook'] = 'get_footer'; break;
493
+ case 'genesis':
494
+ $defaults['footer_hook'] = 'genesis_footer';
495
+ $defaults['footer_filter_hook'] = 'genesis_footer_output';
496
+ break;
497
+ case 'graphene':
498
+ $defaults['footer_hook'] = 'graphene_footer'; break;
499
+ case 'pagelines':
500
+ $defaults['footer_hook'] = 'pagelines_leaf'; break;
501
+ default:
502
+ $defaults['footer_hook'] = 'wp_footer';
503
+ $defaults['footer_remove'] = false;
504
+ break;
505
+ }
506
+ return $defaults;
507
+ }
508
+ }
classes/class-dashboard.php CHANGED
@@ -4,37 +4,36 @@ class Footer_Putter_Dashboard extends Footer_Putter_Admin {
4
function init() {
5
add_action('admin_menu', array($this, 'admin_menu'));
6
add_action('load-widgets.php', array($this, 'add_tooltip_support'));
7
- add_action('admin_enqueue_scripts', array($this ,'register_tooltip_styles'));
8
- add_action('admin_enqueue_scripts', array($this ,'register_admin_styles'));
9
add_filter('plugin_action_links',array($this, 'plugin_action_links'), 10, 2 );
10
}
11
12
function admin_menu() {
13
- $intro = sprintf('Intro (v%1$s)', $this->get_version());
14
- $this->screen_id = add_menu_page(FOOTER_PUTTER_FRIENDLY_NAME, FOOTER_PUTTER_FRIENDLY_NAME, 'manage_options',
15
- $this->get_slug(), array($this,'page_content'), FOOTER_PUTTER_ICON );
16
- add_submenu_page($this->get_slug(), FOOTER_PUTTER_FRIENDLY_NAME, $intro, 'manage_options', $this->get_slug(), array($this,'page_content') );
17
- add_action('load-'.$this->get_screen_id(), array($this, 'load_page'));
18
}
19
20
function page_content() {
21
- $title = $this->admin_heading('Footer Putter v'. $this->get_version(), FOOTER_PUTTER_ICON);
22
- $this->print_admin_form_with_sidebar($title, __CLASS__);
23
}
24
25
function load_page() {
26
$this->add_tooltip_support();
27
- add_action('admin_enqueue_scripts', array($this, 'register_admin_styles'));
28
- add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
29
- add_action('admin_enqueue_scripts', array($this, 'enqueue_metabox_scripts'));
30
- add_action('admin_enqueue_scripts', array($this, 'enqueue_postbox_scripts'));
31
$this->add_meta_box('intro', 'Introduction', 'intro_panel');
32
$this->add_meta_box('details','Details', 'footer_panel');
33
- $this->add_meta_box('news', 'DIY Webmastery News', 'news_panel', null, 'side');
34
}
35
36
- function footer_panel() {
37
- $this->display_metabox( array(
38
'Widgets' => $this->widgets_panel(),
39
'Instructions' => $this->instructions_panel(),
40
'Footer Hook' => $this->hooks_panel(),
@@ -43,8 +42,8 @@ class Footer_Putter_Dashboard extends Footer_Putter_Admin {
43
}
44
45
46
- function intro_panel() {
47
- $plugin = FOOTER_PUTTER_FRIENDLY_NAME;
48
print <<< INTRO_PANEL
49
<p>{$plugin} allows you to put a footer to your site that adds credibility to your site, with BOTH visitors and search engines.</p>
50
<p>Google is looking for some indicators that the site is about a real business.</p>
@@ -73,10 +72,10 @@ WIDGETS_PANEL;
73
}
74
75
function instructions_panel() {
76
- $plugin = FOOTER_PUTTER_FRIENDLY_NAME;
77
$widgets_url = admin_url('widgets.php');
78
- $credits_url = Footer_Putter_Plugin::get_link_url('credits');
79
- $trademarks_url = Footer_Putter_Plugin::get_link_url('trademarks');
80
return <<< INSTRUCTIONS_PANEL
81
<h4>Create Standard Pages And Footer Menu</h4>
82
<ol>
@@ -113,8 +112,8 @@ INSTRUCTIONS_PANEL;
113
}
114
115
function hooks_panel() {
116
- $home_url = FOOTER_PUTTER_HOME_URL;
117
- $plugin = FOOTER_PUTTER_FRIENDLY_NAME;
118
return <<< HOOKS_PANEL
119
<p>The footer hook is only required if your theme does not already have a footer widget area into which you can drag the two widgets.</p>
120
<p>For some themes, the footer hook is left blank, for others use a WordPress hook such as <i>get_footer</i> or <i>wp_footer</i>,
@@ -124,13 +123,13 @@ HOOKS_PANEL;
124
}
125
126
function links_panel() {
127
- $home = FOOTER_PUTTER_HOME_URL;
128
return <<< LINKS_PANEL
129
<ul>
130
- <li><a rel="external" href="{$home}">Footer Putter Plugin Home</a></li>
131
- <li><a rel="external" href="http://www.diywebmastery.com/footer-credits-compatible-themes-and-hooks/">Themes and Recommended Footer Hooks</a></li>
132
- <li><a rel="external" href="http://www.diywebmastery.com/4098/how-to-add-a-different-footer-on-landing-pages/">How To Use A Different Footer On Landing Pages</a></li>
133
- <li><a rel="external" href="http://www.diywebmastery.com/4109/using-html5-microdata-footer/">Using HTML5 Microdata for better SEO and Local Search</a></li>
134
</ul>
135
LINKS_PANEL;
136
}
4
function init() {
5
add_action('admin_menu', array($this, 'admin_menu'));
6
add_action('load-widgets.php', array($this, 'add_tooltip_support'));
7
+ add_action('admin_enqueue_scripts', array($this ,'register_tooltip_styles'));
8
+ add_action('admin_enqueue_scripts', array($this ,'register_admin_styles'));
9
add_filter('plugin_action_links',array($this, 'plugin_action_links'), 10, 2 );
10
}
11
12
function admin_menu() {
13
+ $intro = sprintf('Intro (v%1$s)', $this->get_version());
14
+ $this->screen_id = add_menu_page($this->get_name(), $this->get_name(), 'manage_options',
15
+ $this->get_slug(), array($this,'page_content'), $this->icon );
16
+ add_submenu_page($this->get_slug(), $this->get_name(), $intro, 'manage_options', $this->get_slug(), array($this,'page_content') );
17
+ add_action('admin_enqueue_scripts', array($this, 'register_admin_styles'));
18
+ add_action('admin_enqueue_scripts', array($this, 'register_tooltip_styles'));
19
+ add_action('load-'.$this->get_screen_id(), array($this, 'load_page'));
20
}
21
22
function page_content() {
23
+ $title = $this->admin_heading('Footer Putter v'. $this->get_version());
24
+ $this->print_admin_form($title, __CLASS__, $this->get_keys());
25
}
26
27
function load_page() {
28
$this->add_tooltip_support();
29
$this->add_meta_box('intro', 'Introduction', 'intro_panel');
30
$this->add_meta_box('details','Details', 'footer_panel');
31
+ $this->add_meta_box('news', $this->get_name().' '.__('News'), 'news_panel', null, 'advanced');
32
+ add_action('admin_enqueue_scripts', array($this, 'enqueue_admin'));
33
}
34
35
+ function footer_panel($post,$metabox) {
36
+ print $this->tabbed_metabox($metabox['id'], array(
37
'Widgets' => $this->widgets_panel(),
38
'Instructions' => $this->instructions_panel(),
39
'Footer Hook' => $this->hooks_panel(),
42
}
43
44
45
+ function intro_panel($post,$metabox) {
46
+ $plugin = $this->get_name();
47
print <<< INTRO_PANEL
48
<p>{$plugin} allows you to put a footer to your site that adds credibility to your site, with BOTH visitors and search engines.</p>
49
<p>Google is looking for some indicators that the site is about a real business.</p>
72
}
73
74
function instructions_panel() {
75
+ $plugin = $this->get_name();
76
$widgets_url = admin_url('widgets.php');
77
+ $credits_url = $this->plugin->get_link_url('credits');
78
+ $trademarks_url = $this->plugin->get_link_url('trademarks');
79
return <<< INSTRUCTIONS_PANEL
80
<h4>Create Standard Pages And Footer Menu</h4>
81
<ol>
112
}
113
114
function hooks_panel() {
115
+ $home_url = $this->plugin->get_home();
116
+ $plugin = $this->get_name();
117
return <<< HOOKS_PANEL
118
<p>The footer hook is only required if your theme does not already have a footer widget area into which you can drag the two widgets.</p>
119
<p>For some themes, the footer hook is left blank, for others use a WordPress hook such as <i>get_footer</i> or <i>wp_footer</i>,
123
}
124
125
function links_panel() {
126
+ $home = $this->plugin->get_home();
127
return <<< LINKS_PANEL
128
<ul>
129
+ <li><a rel="external" target="_blank" href="{$home}">Footer Putter Plugin Home</a></li>
130
+ <li><a rel="external" target="_blank" href="https://www.diywebmastery.com/footer-credits-compatible-themes-and-hooks/">Themes and Recommended Footer Hooks</a></li>
131
+ <li><a rel="external" target="_blank" href="https://www.diywebmastery.com/4098/how-to-add-a-different-footer-on-landing-pages/">How To Use A Different Footer On Landing Pages</a></li>
132
+ <li><a rel="external" target="_blank" href="https://www.diywebmastery.com/4109/using-html5-microdata-footer/">Using HTML5 Microdata for better SEO and Local Search</a></li>
133
</ul>
134
LINKS_PANEL;
135
}
classes/{class-feed-widget.php → class-news.php} RENAMED
@@ -1,37 +1,54 @@
1
<?php
2
- if (!class_exists('Footer_Putter_Feed_Widget')) {
3
- class Footer_Putter_Feed_Widget extends WP_Widget_RSS {
4
-
5
- function __construct() {
6
- $widget_ops = array( 'description' => __('Displays Featured image in place of title in any RSS or Atom feed.') );
7
- $control_ops = array( 'width' => 400, 'height' => 200 );
8
- parent::__construct( 'footer-putter-feed', __('Footer Putter Feed'), $widget_ops, $control_ops );
9
}
10
11
- function widget($args, $instance) {
12
-
13
- if ( isset($instance['error']) && $instance['error'] )
14
- return;
15
-
16
- $title = $instance['title'];
17
- $desc = '';
18
- $link = '';
19
-
20
- /** This filter is documented in wp-includes/default-widgets.php */
21
- $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
22
-
23
- echo $args['before_widget'];
24
-
25
- if ( $title ) {
26
- echo $args['before_title'] . $title . $args['after_title'];
27
}
28
29
- self::rss_output($instance );
30
-
31
- echo $args['after_widget'];
32
}
33
34
- static function rss_output( $instance ) {
35
36
$url = ! empty( $instance['url'] ) ? $instance['url'] : '';
37
@@ -52,7 +69,7 @@ if (!class_exists('Footer_Putter_Feed_Widget')) {
52
return;
53
}
54
55
- $default_args = array( 'show_featured' => 0, 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
56
57
if (($parsed_url = parse_url($url))
58
&& ($query = isset($parsed_url['query']) ? $parsed_url['query'] : '')) {
@@ -70,9 +87,9 @@ if (!class_exists('Footer_Putter_Feed_Widget')) {
70
$show_date = (int) $args['show_date'];
71
72
if ( !$rss->get_item_quantity() ) {
73
- echo '<div>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</div>';
74
- return;
75
}
76
77
foreach ( $rss->get_items( 0, $items ) as $item ) {
78
$link = $item->get_link();
@@ -126,32 +143,14 @@ if (!class_exists('Footer_Putter_Feed_Widget')) {
126
}
127
}
128
129
- if ( $link == '' )
130
- $format = '<span>%3$s</span>%4$s%6$s';
131
- elseif ( $show_summary )
132
- $format = '<span><a class="rsswidget" href="%1$s"%2$s>%3$s</a></span>%4$s%5$s%6$s';
133
- else
134
- $format = '<span><a class="rsswidget" href="%1$s"%2$s>%3$s</a></span>%4$s%6$s';
135
-
136
- printf('<span class="diy-image-feed-widget-item">'.$format.'</span>', $link, $link_title, $title, $date, $summary, $author );
137
}
138
139
if ( ! is_wp_error($rss) )
140
$rss->__destruct();
141
unset($rss);
142
}
143
144
- static function display_feeds($feeds = false) {
145
- if (false == $feeds) $feeds = array(FOOTER_PUTTER_NEWS);
146
- if (is_array($feeds) && (count($feeds) > 0)) {
147
- echo '<div class="diy-image-feed-widget">';
148
- foreach( $feeds as $url ) {
149
- $args = array('url' => $url, 'show_summary' => true, 'show_featured' => true);
150
- self::rss_output( $args );
151
- }
152
- echo "</div>";
153
- }
154
- }
155
-
156
- }
157
}
1
<?php
2
+ class Footer_Putter_News {
3
+
4
+ private $version;
5
+ private $script_var;
6
+ private $handle;
7
+ private $results;
8
+
9
+ function __construct($version) {
10
+ $this->version = $version;
11
+ $this->script_var = strtolower(__CLASS__);
12
+ $this->handle = str_replace('_', '-', $this->script_var);
13
+ $this->results = $this->handle . '-feed';
14
+ add_action( 'wp_ajax_'.$this->script_var, array($this, 'get_feeds_ajax') );
15
}
16
17
+ function enqueue_scripts() {
18
+ wp_enqueue_script($this->handle, plugins_url('scripts/jquery.news.js', dirname(__FILE__)), array('jquery'), $this->version, true);
19
+ wp_localize_script($this->handle, $this->script_var,
20
+ array(
21
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
22
+ 'ajaxnonce' => wp_create_nonce( $this->script_var.'_nonce' ),
23
+ 'ajaxaction' => $this->script_var,
24
+ 'ajaxresults' => '.'.$this->results
25
+ )
26
+ );
27
+ }
28
+
29
+ function display_feeds($feeds = array()) {
30
+ if (is_array($feeds) && (count($feeds) > 0)) {
31
+ printf ('<div class="%1$s"></div>', $this->results);
32
+ for($index=0; $index < count($feeds); $index++ ) {
33
+ wp_localize_script( $this->handle, $this->script_var.$index, array( 'feedurl' => $feeds[$index]) );
34
+ }
35
}
36
+ }
37
38
+ function get_feeds_ajax() {
39
+ check_ajax_referer( $this->script_var.'_nonce', 'security' );
40
+ $url = isset($_POST['url']) ? $_POST['url'] : '';
41
+ if (empty($url)) wp_send_json_error( array( 'error' => __( 'Feed URL not supplied.' ) ) );
42
+
43
+ $instance = array('url' => $url, 'show_summary' => false, 'show_featured' => true);
44
+ $feed = $this->get_rss_feed_instance($instance);
45
+ if( isset( $feed ) )
46
+ wp_send_json_success( $feed );
47
+ else
48
+ wp_send_json_error( array( 'error' => __( 'Could not retrieve feed '.$url ) ) );
49
}
50
51
+ function get_rss_feed_instance( $instance ) {
52
53
$url = ! empty( $instance['url'] ) ? $instance['url'] : '';
54
69
return;
70
}
71
72
+ $default_args = array( 'show_featured' => 0, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0, 'items' => 0 );
73
74
if (($parsed_url = parse_url($url))
75
&& ($query = isset($parsed_url['query']) ? $parsed_url['query'] : '')) {
87
$show_date = (int) $args['show_date'];
88
89
if ( !$rss->get_item_quantity() ) {
90
+ return '<div>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</div>';
91
}
92
+ $results = '';
93
94
foreach ( $rss->get_items( 0, $items ) as $item ) {
95
$link = $item->get_link();
143
}
144
}
145
146
+ if ($link) $title = sprintf('<a target="_blank" class="rsswidget" href="%1$s"%2$s>%3$s</a>', $link, $link_title, $title);
147
+ $results .= sprintf('<div class="%5$s-item"><div>%1$s</div>%2$s%3$s%4$s</div>', $title, $date, $summary, $author, $this->results );
148
}
149
150
if ( ! is_wp_error($rss) )
151
$rss->__destruct();
152
unset($rss);
153
+ return $results;
154
}
155
156
}
classes/{class-diy-options.php → class-options.php} RENAMED
@@ -1,5 +1,5 @@
1
<?php
2
- class Footer_Putter_DIY_Options {
3
4
protected $option_name;
5
protected $options = array();
@@ -13,9 +13,11 @@ class Footer_Putter_DIY_Options {
13
}
14
15
function add_defaults($more = array()) {
16
- $this->defaults = array_merge($this->defaults, (array)$more);
17
- $this->options = array(); //clear cache
18
- }
19
20
function get_defaults() {
21
return $this->defaults;
@@ -44,9 +46,12 @@ class Footer_Putter_DIY_Options {
44
function get_option($option_name, $cache = true) {
45
$options = $this->get_options($cache);
46
if ($option_name && $options && array_key_exists($option_name,$options))
47
return $options[$option_name];
48
else
49
- return false;
50
}
51
52
function save_options($new_options) {
@@ -59,29 +64,31 @@ class Footer_Putter_DIY_Options {
59
}
60
61
function validate_options($defaults, $options ) {
62
- if (is_array($options) && is_array($defaults) )
63
return shortcode_atts($defaults, $options);
64
else
65
return false;
66
}
67
68
function upgrade_options() {
69
$new_options = array();
70
$defaults = $this->get_defaults();
71
- $options = get_option($this->get_option_name());
72
73
- if (is_array($options)) {
74
- /* Remove old options and set defaults for new options */
75
foreach ($defaults as $key => $subdefaults)
76
- if (array_key_exists($key, $options))
77
- if (is_array($options[$key]) && is_array($subdefaults))
78
- $new_options[$key] = shortcode_atts($subdefaults, $options[$key]);
79
else
80
- $new_options[$key] = $options[$key];
81
} else {
82
$new_options = $defaults;
83
}
84
$this->save_options($new_options);
85
}
86
-
87
}
1
<?php
2
+ class Footer_Putter_Options {
3
4
protected $option_name;
5
protected $options = array();
13
}
14
15
function add_defaults($more = array()) {
16
+ if ($more) {
17
+ $this->defaults = array_merge($this->defaults, (array)$more);
18
+ $this->options = array(); //clear cache
19
+ }
20
+ }
21
22
function get_defaults() {
23
return $this->defaults;
46
function get_option($option_name, $cache = true) {
47
$options = $this->get_options($cache);
48
if ($option_name && $options && array_key_exists($option_name,$options))
49
+ if (($defaults = $this->get_default($option_name)) && is_array($defaults) && is_array($options[$option_name]))
50
+ return $this->validate_options($defaults, $options[$option_name]);
51
+ else
52
return $options[$option_name];
53
else
54
+ return $this->get_default($option_name);
55
}
56
57
function save_options($new_options) {
64
}
65
66
function validate_options($defaults, $options ) {
67
+ if (is_array($defaults) )
68
+ if (is_array($options))
69
return shortcode_atts($defaults, $options);
70
else
71
+ return $defaults;
72
+ else
73
return false;
74
}
75
76
function upgrade_options() {
77
+ /* Remove old options and set defaults for new options */
78
$new_options = array();
79
$defaults = $this->get_defaults();
80
+ $old_options = get_option($this->get_option_name());
81
82
+ if (is_array($old_options)) {
83
foreach ($defaults as $key => $subdefaults)
84
+ if (array_key_exists($key, $old_options))
85
+ if (is_array($old_options[$key]) && is_array($subdefaults))
86
+ $new_options[$key] = shortcode_atts($subdefaults, $old_options[$key]);
87
else
88
+ $new_options[$key] = $old_options[$key];
89
} else {
90
$new_options = $defaults;
91
}
92
$this->save_options($new_options);
93
}
94
}
classes/class-plugin.php CHANGED
@@ -1,41 +1,133 @@
1
<?php
2
class Footer_Putter_Plugin {
3
4
- protected static $links = array();
5
6
- public static function get_link_url($key) {
7
- if (array_key_exists($key, self::$links))
8
- return self::$links[$key];
9
- else
10
- return ('#');
11
}
12
13
- public static function init() {
14
$dir = dirname(__FILE__) . '/';
15
require_once($dir . 'class-utils.php');
16
- require_once($dir . 'class-diy-options.php');
17
- require_once($dir . 'class-credits-options.php');
18
require_once($dir . 'class-credits.php');
19
require_once($dir . 'class-credits-widgets.php');
20
require_once($dir . 'class-trademarks-widgets.php');
21
- Footer_Credits_Options::init();
22
- Footer_Credits::init();
23
}
24
25
- public static function admin_init() {
26
$dir = dirname(__FILE__) . '/';
27
require_once($dir . 'class-tooltip.php');
28
require_once($dir . 'class-admin.php');
29
- require_once($dir . 'class-feed-widget.php');
30
- require_once($dir . 'class-dashboard.php');
31
require_once($dir . 'class-credits-admin.php');
32
require_once($dir . 'class-trademarks-admin.php');
33
- $intro = new Footer_Putter_Dashboard(FOOTER_PUTTER_VERSION, FOOTER_PUTTER_PATH, FOOTER_PUTTER_PLUGIN_NAME);
34
- self::$links['intro'] = $intro->get_url();
35
- $credits = new Footer_Credits_Admin(FOOTER_PUTTER_VERSION, FOOTER_PUTTER_PATH, FOOTER_PUTTER_PLUGIN_NAME,'credits');
36
- self::$links['credits'] = $credits->get_url();
37
- $trademarks = new Footer_Trademarks_Admin(FOOTER_PUTTER_VERSION, FOOTER_PUTTER_PATH, FOOTER_PUTTER_PLUGIN_NAME,'trademarks');
38
- self::$links['trademarks'] = $trademarks->get_url();
39
}
40
41
}
1
<?php
2
class Footer_Putter_Plugin {
3
4
5
+ const OPTIONS_NAME = 'footer_putter_options';
6
+ private $help = FOOTER_PUTTER_HELP;
7
+ private $home = FOOTER_PUTTER_HOME;
8
+ private $icon = FOOTER_PUTTER_ICON;
9
+ private $name = FOOTER_PUTTER_NAME;
10
+ private $newsfeeds = array(DIYWEBMASTERY_NEWS);
11
+ private $path = FOOTER_PUTTER_PATH;
12
+ private $slug = FOOTER_PUTTER_SLUG;
13
+ private $version = FOOTER_PUTTER_VERSION;
14
+ private $news;
15
+ private $options;
16
+ private $tooltips;
17
+ private $utils;
18
+ private $defaults = array();
19
+ private $links = array();
20
+ private $credits;
21
+
22
+ static function get_instance() {
23
+ static $instance = null;
24
+ if (null === $instance) {
25
+ // $instance = new static(); //use self instead of static to support 5.2 - not the same but okay as the plugin class is not extended
26
+ $instance = new self();
27
+ register_activation_hook($instance->path, array($instance, 'activate'));
28
+ add_action('init', array($instance, 'init'),0);
29
+ if (is_admin()) add_action('init', array($instance, 'admin_init'),0);
30
+
31
+ }
32
+ return $instance;
33
}
34
+
35
+ protected function __construct() {}
36
+
37
+ private function __clone() {}
38
39
+ private function __wakeup() {}
40
+
41
+
42
+ function init() {
43
$dir = dirname(__FILE__) . '/';
44
require_once($dir . 'class-utils.php');
45
+ require_once($dir . 'class-tooltip.php');
46
+ require_once($dir . 'class-options.php');
47
+ require_once($dir . 'class-widget.php');
48
require_once($dir . 'class-credits.php');
49
require_once($dir . 'class-credits-widgets.php');
50
require_once($dir . 'class-trademarks-widgets.php');
51
+ $this->utils = new Footer_Putter_Utils();
52
+ $this->tooltips = new Footer_Putter_Tooltip();
53
+ $this->options = new Footer_Putter_Options( self::OPTIONS_NAME, $this->defaults);
54
+ $this->credits = new Footer_Credits();
55
}
56
57
+ function admin_init() {
58
$dir = dirname(__FILE__) . '/';
59
require_once($dir . 'class-tooltip.php');
60
require_once($dir . 'class-admin.php');
61
+ require_once($dir . 'class-news.php');
62
+ require_once($dir . 'class-dashboard.php');
63
require_once($dir . 'class-credits-admin.php');
64
require_once($dir . 'class-trademarks-admin.php');
65
+ $this->news = new Footer_Putter_News($this->version);
66
+ $intro = new Footer_Putter_Dashboard($this);
67
+ $this->links['intro'] = $intro->get_url();
68
+ $credits = new Footer_Credits_Admin($this, 'credits');
69
+ $this->links['credits'] = $credits->get_url();
70
+ $trademarks = new Footer_Trademarks_Admin($this, 'trademarks');
71
+ $this->links['trademarks'] = $trademarks->get_url();
72
}
73
74
+ public function get_help(){
75
+ return $this->help;
76
+ }
77
+
78
+ public function get_home(){
79
+ return $this->home;
80
+ }
81
+
82
+ public function get_icon(){
83
+ return $this->icon;
84
+ }
85
+
86
+ public function get_name(){