This repository was archived by the owner on Jan 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcat-signal.php
301 lines (276 loc) · 11.5 KB
/
cat-signal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
/*
Plugin Name: Cat Signal
Plugin URI: http://jazzsequence.github.io/Cat-Signal
Description: A WordPress plugin to easily display a banner or a modal alert when the Cat Signal (from the Internet Defense League) is active. For more information visit: http://internetdefenseleague.org/
Version: 1.1.2
Author: Chris Reynolds
Author URI: http://chrisreynolds.io
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html
*/
define( 'CAT_SIGNAL_PATH', plugin_dir_path(__FILE__) );
define( 'CAT_SIGNAL_PLUGIN_URL', plugin_dir_url(__FILE__) );
$cat_signal_options = get_option( 'cat_signal' );
function idl_cats_in_yr_wp() {
global $cat_signal_options;
// do html stuff
?>
<div class="wrap">
<?php screen_icon('cat-signal'); ?>
<h2><?php _e( 'Internet Defense League — Cat Signal', 'cat-signal' ); ?></h2>
<form method="POST" action="options.php">
<?php
settings_fields( 'cat_signal_options' );
?>
<table class="form-table">
<tbody>
<?php idl_do_signal_type_selection(); ?>
</tbody>
</table>
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
<input type="hidden" name="ap-core-settings-submit" value="Y" />
</form>
<div style="width: 100%; text-align: center; margin-top: 20px;">
<a href="http://internetdefenseleague.org/" target="_blank"><img src="<?php echo CAT_SIGNAL_PLUGIN_URL; ?>/img/IDL_type_logo.png" alt="<?php _e('The Internet Defense League', 'cat-signal'); ?>" /></a>
</div>
</div>
<?php
}
function idl_cats_in_yr_menus() {
add_submenu_page( 'options-general.php', __('Cat Signal', 'cat-signal'), __('Cat Signal', 'cat-signal'), 'administrator', 'cat_signal', 'idl_cats_in_yr_wp' );
}
add_action( 'admin_menu', 'idl_cats_in_yr_menus' );
function idl_initialize_cats() {
register_setting( 'cat_signal_options', 'cat_signal', 'idl_validate_teh_cats' );
}
add_action( 'admin_init', 'idl_initialize_cats' );
function idl_do_signal_type_selection() {
global $cat_signal_options;
ob_start();
?>
<tr valign="top"><th scope="row"><?php _e( 'Type of signal', 'cat-signal' ); ?></th>
<td>
<select id="cat-breed" name="cat_signal[type]">
<?php
$selected = $cat_signal_options['type'];
foreach ( idl_all_the_cats() as $option ) {
$label = $option['label'];
$value = $option['value'];
echo '<option value="' . $value . '" ' . selected( $selected, $value ) . '>' . esc_attr($label) . '</option>';
}
?>
</select>
<!-- <p>
<label type="description" for="cat_signal[type]"><small>
<?php _e( 'If Stop the Secrecy option is selected, the modal Cat Signal will be selected for any other campaigns and a Stop the Secrecy widget will appear on your <a href="widgets.php">Widgets</a> page. <strong>Important Note:</strong> The dimensions of this widget/petition cannot be changed. This means that the widget might not look good on all themes. If this is the case for you, you can <a href="https://openmedia.org/stopthesecrecy/resources">get the code</a> and add it somewhere else on your site.', 'cat-signal' ); ?>
</small></label>
</p>-->
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e( 'Where should the Cat Signal display?', 'cat-signal' ); ?></th>
<td>
<select id="cat-location" name="cat_signal[location]">
<?php
if ( $cat_signal_options['location-other'] ) {
$cat_signal_options['location-other'] = wp_kses($cat_signal_options['location-other']);
} else {
$cat_signal_options['location-other'] = '';
}
$selected = $cat_signal_options['location'];
foreach ( idl_whar_is_cats() as $option ) {
$label = $option['label'];
$value = $option['value'];
echo '<option value="' . $value . '" ' . selected( $selected, $value ) . '>' . esc_attr($label) . '</option>';
}
?>
</select>
<p><?php _e( 'Other', 'cat-signal' ); ?>: <input type="text" id="cat-other-location" name="cat_signal[location-other]" width="15" value="<?php echo $cat_signal_options['location-other']; ?>" /><br />
<label class="description" for="cat_signal[location]"><small><?php _e( 'This controls where the alert (banner or modal) will display on your site. If you want to display it on all pages, use the "All pages" option. If you only want to display it on the home page (whether that\'s a static page or your main blog page), select Home/Front Page. If you\'d rather set a specific page, enter either the page ID or the page slug into the "Other" box and select "Other" from the dropdown.', 'cat-signal' ); ?></small></label></p>
</td>
<tr valign="top"><th scope="row"><?php _e( 'Screenshots', 'cat-signal' ); ?></th>
<td>
<!--<div class="alignleft" style="margin-right: 20px;">
<img src="<?php echo CAT_SIGNAL_PLUGIN_URL; ?>img/banner.png" alt="<?php _e( 'Banner', 'cat-signal' ); ?>" />
<p><?php _e( 'Banner', 'cat-signal' ); ?></p>
</div>-->
<div class="alignleft" style="margin-right: 20px;">
<img src="<?php echo CAT_SIGNAL_PLUGIN_URL; ?>img/modal.png" alt="<?php _e( 'Modal', 'cat-signal' ); ?>" />
<p><?php _e( 'Modal', 'cat-signal' ); ?></p>
</div>
<!--<div class="alignleft">
<img src="<?php echo CAT_SIGNAL_PLUGIN_URL; ?>img/StopSecrecy.png" alt="<?php _e( 'Stop the Secrecy petition' ); ?>" />
<p><?php _e( 'Stop the Secrecy petition' ); ?></p>
</div>-->
</td>
</tr>
<!-- <tr valign="top"><th scope="row"><?php _e('Test it!', 'cat-signal'); ?></th>
<td>
<?php
$message = '';
if ( $cat_signal_options['location'] == 'all' || $cat_signal_options['location'] == 'front' || ( $cat_signal_options['location'] == 'other' && !$cat_signal_options['location-other'] ) ) {
$url = home_url() . '?_idl_test=1';
} elseif ( $cat_signal_options['location'] == 'other' && $cat_signal_options['location-other'] ) {
if ( is_numeric( $cat_signal_options['location-other'] ) ) {
$url = home_url() . '?p=' . $cat_signal_options['location-other'] . '&_idl_test=1';
} else {
$url = home_url() . '/' . $cat_signal_options['location-other'] . '?_idl_test=1';
}
} else {
$url = null;
$message = __( 'Woah there! I couldn\'t figure out what page you are loading your script on. Try saving your options again.', 'cat-signal' );
}
if ( $url ) {
echo sprintf( __( '%sRun the test on your site.%s', 'cat-signal' ), '<a href="' . $url . '" target="_blank">', '</a>' );
} else {
echo $message;
}
?>
<br />
<label class="description" for="cat_signal[test]"><small><?php _e( 'This will add a test parameter at the end of the URL to the page (or pages) that you have set to display the alert to make sure it\'s working correctly. If, for some reason, this link doesn\'t work, you can run the test manually by adding <code>?_idl_test=1</code> to the end of your url.', 'cat-signal' ); ?></small></label>
</td> -->
<?php
$cat_settings = ob_get_contents();
ob_end_clean();
echo $cat_settings;
}
function idl_all_the_cats() {
$cat_breeds = array(
/*'special' => array(
'value' => 'special',
'label' => __( 'Stop the Secrecy', 'cat-signal' )
),
'banner' => array(
'value' => 'banner',
'label' => __( 'Banner', 'cat-signal' )
),*/
'modal' => array(
'value' => 'modal',
'label' => __( 'Modal', 'cat-signal' ),
),
);
return $cat_breeds;
}
function idl_whar_is_cats() {
$cat_locations = array(
'all' => array(
'value' => 'all',
'label' => __( 'All pages', 'cat-signal' )
),
'front' => array(
'value' => 'front',
'label' => __( 'Home/Front Page', 'cat-signal' )
),
'other' => array(
'value' => 'other',
'label' => __( 'Other page', 'cat-signal' )
)
);
return $cat_locations;
}
function idl_signal_all_the_cats() {
global $cat_signal_options;
switch( $cat_signal_options['location'] ) {
case 'all':
idl_all_the_cats_all_lined_up();
break;
case 'front':
if ( is_front_page() || is_home() ) {
idl_all_the_cats_all_lined_up();
}
break;
case 'other':
if ( $cat_signal_options['location-other'] ) {
if ( is_page( $cat_signal_options['location-other'] ) ) {
idl_all_the_cats_all_lined_up();
}
} else {
idl_all_the_cats_all_lined_up();
}
break;
default:
idl_all_the_cats_all_lined_up();
}
}
add_action( 'wp_head', 'idl_signal_all_the_cats' );
function idl_all_the_cats_all_lined_up() {
global $cat_signal_options;
if ( ! is_admin() ) {
wp_enqueue_script( 'idf-modal', CAT_SIGNAL_PLUGIN_URL . 'js/modal.js', array(), '1.0', false );
/*
* Other Cat Signal types have been deprecated. Keeping here for historic purposes or
* if they come back (which they won't).
if ( $cat_signal_options['type'] == 'banner' ) {
wp_enqueue_script( 'idf-banner', CAT_SIGNAL_PLUGIN_URL . 'js/banner.js', array(), '1.0', false );
} elseif ( $cat_signal_options['type'] == 'special' ) { // used for special, one-time campaigns
$code = '';
printf( $code );
} else {
// if nothing has been set, default to modal.
wp_enqueue_script( 'idf-modal', CAT_SIGNAL_PLUGIN_URL . 'js/modal.js', array(), '1.0', false );
}
*/
}
}
function idl_cat_icon() {
?>
<style type="text/css" media="screen">
#icon-cat-signal {
background: url(<?php echo CAT_SIGNAL_PLUGIN_URL; ?>img/icon32.png) no-repeat!important;
}
</style>
<?php
}
add_action( 'admin_head', 'idl_cat_icon' );
function idl_validate_teh_cats($input) {
if ( !array_key_exists( $input['type'], idl_all_the_cats() ) )
$input['type'] = null;
if ( !array_key_exists( $input['location'], idl_whar_is_cats() ) )
$input['location'] = null;
$input['location-other'] = wp_filter_nohtml_kses( $input['location-other'] );
return $input;
}
// added for stop the secrecy campaign widget
if ( $cat_signal_options['type'] == 'special' ) {
add_action( 'widgets_init', 'idl_widgetize_teh_cats');
}
function idl_widgetize_teh_cats() {
register_widget( 'Cat_Signal_Widget' );
}
class Cat_Signal_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'cat_signal_widget',
__( 'Stop the Secrecy Widget', 'cat-signal' ),
array( 'description' => __( 'Displays the Stop the Secrecy petition in a widget.', 'cat-signal' ) )
);
}
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
$code = '<script type="text/javascript"> widgetContext = {"url":"https:\u002F\u002Fopenmedia.org\u002Fwidgets\u002Fstop-secrecy?width=260\u0026height=460\u0026src=aux", "width":"260", "height":"705", "widgetid":"web_widget_iframe_9c82eae7a4902042e4b47b5c826fa5e6", "scrolling":"auto"}; </script><script id="web_widget_iframe_9c82eae7a4902042e4b47b5c826fa5e6" src="https://openmedia.org/sites/all/modules/contrib/web_widgets/iframe/web_widgets_iframe.js"></script>';
echo $args['before_widget'];
if ( !empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
echo $code;
echo $args['after_widget'];
}
public function form( $instance ) {
if ( isset( $instance['title'] ) ) {
$title = $instance['title'];
} else {
$title = '';
}
// form is here
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}