PluginProbe
Simple Ticker / 1.05
Simple Ticker v1.05
trunk 1.0 1.01 1.02 1.03 1.04 1.05 1.06 1.07 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 2.11 3.00 3.01 3.02 3.03 All 33 releases
simple-ticker / req / SimpleTickerAdmin.php

SimpleTickerAdmin.php in Simple Ticker 1.05, at req/SimpleTickerAdmin.php

412 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Simple Ticker
4 *
5 * @package SimpleTicker
6 * @subpackage SimpleTicker Management screen
7 Copyright (c) 2016- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 class SimpleTickerAdmin {
23
24 /* ==================================================
25 * Add a "Settings" link to the plugins page
26 * @since 1.0
27 */
28 function settings_link( $links, $file ) {
29 static $this_plugin;
30 if ( empty($this_plugin) ) {
31 $this_plugin = SIMPLETICKER_PLUGIN_BASE_FILE;
32 }
33 if ( $file == $this_plugin ) {
34 $links[] = '<a href="'.admin_url('options-general.php?page=SimpleTicker').'">'.__( 'Settings').'</a>';
35 }
36 return $links;
37 }
38
39 /* ==================================================
40 * Settings page
41 * @since 1.0
42 */
43 function plugin_menu() {
44 add_options_page( 'Simple Ticker Options', 'Simple Ticker', 'manage_options', 'SimpleTicker', array($this, 'plugin_options') );
45 }
46
47 /* ==================================================
48 * Add Css and Script
49 * @since 1.0
50 */
51 function load_custom_wp_admin_style() {
52 if ($this->is_my_plugin_screen()) {
53 wp_enqueue_style( 'jquery-responsiveTabs', SIMPLETICKER_PLUGIN_URL.'/css/responsive-tabs.css' );
54 wp_enqueue_style( 'jquery-responsiveTabs-style', SIMPLETICKER_PLUGIN_URL.'/css/style.css' );
55 wp_enqueue_script('jquery');
56 wp_enqueue_script( 'jquery-responsiveTabs', SIMPLETICKER_PLUGIN_URL.'/js/jquery.responsiveTabs.min.js' );
57 wp_enqueue_script( 'jquery-jscolor', SIMPLETICKER_PLUGIN_URL.'/js/jscolor.min.js' );
58 wp_enqueue_script( 'simpleticker-js', SIMPLETICKER_PLUGIN_URL.'/js/jquery.simpleticker.js', array('jquery') );
59 }
60 }
61
62 /* ==================================================
63 * For only admin style
64 * @since 1.0
65 */
66 function is_my_plugin_screen() {
67 $screen = get_current_screen();
68 if (is_object($screen) && $screen->id == 'settings_page_SimpleTicker') {
69 return TRUE;
70 } else {
71 return FALSE;
72 }
73 }
74
75 /* ==================================================
76 * Settings page
77 * @since 1.0
78 */
79 function plugin_options() {
80
81 if ( !current_user_can( 'manage_options' ) ) {
82 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
83 }
84
85
86 if( !empty($_POST) ) {
87 $post_nonce_field = 'simpleticker_tabs';
88 if ( isset($_POST[$post_nonce_field]) && $_POST[$post_nonce_field] ) {
89 if ( check_admin_referer( 'simpleticker_settings', $post_nonce_field ) ) {
90 $this->options_updated(intval($_POST['simpleticker_admin_tabs']));
91 }
92 }
93 }
94
95 $scriptname = admin_url('options-general.php?page=SimpleTicker');
96
97 $simpleticker_option = get_option('simple_ticker');
98
99 ?>
100
101 <div class="wrap">
102 <h2>Simple Ticker</h2>
103
104 <div id="simpleticker-admin-tabs">
105 <ul>
106 <li><a href="#simpleticker-admin-tabs-1"><?php _e('How to use', 'simple-ticker'); ?></a></li>
107 <li><a href="#simpleticker-admin-tabs-2"><?php _e('Settings'); ?></a></li>
108 <li><a href="#simpleticker-admin-tabs-3"><?php _e('Donate to this plugin &#187;'); ?></a></li>
109 <!--
110 <li><a href="#simpleticker-admin-tabs-4">FAQ</a></li>
111 -->
112 </ul>
113 <div id="simpleticker-admin-tabs-1">
114 <div class="wrap">
115
116 <h2><?php _e('How to use', 'simple-ticker'); ?></h2>
117
118 <div style="width: 100%; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid;">
119 <h3><?php _e('Set the widget', 'simple-ticker'); ?></h3>
120 <?php
121 $widget_html = '<a href="'.admin_url('widgets.php').'" style="text-decoration: none; word-break: break-all;">'.__('Widgets').'['.__( 'Ticker', 'simple-ticker' ).']</a>';
122 ?>
123 <div style="padding: 5px 20px; font-weight: bold;"><?php echo sprintf(__('Please set the %1$s.', 'simple-ticker'), $widget_html); ?></div>
124 </div>
125
126 <div style="width: 100%; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid;">
127 <h3><?php _e('Set up a shortcode', 'simple-ticker'); ?></h3>
128
129 <div style="padding: 5px 20px; font-weight: bold;"><?php _e('Example', 'simple-ticker'); ?></div>
130 <div style="padding: 5px 25px;"><?php _e('to the post or pages', 'simple-ticker'); ?></div>
131 <div style="padding: 5px 35px;"><code>[simpleticker]</code></div>
132 <div style="padding: 5px 35px;"><code>[simpleticker ticker1_text="Ticker test!!" ticker1_color="#008000" sticky_posts_display=FALSE]</code></div>
133 <div style="padding: 5px 25px;"><?php _e('to the template of the theme', 'simple-ticker'); ?></div>
134 <div style="padding: 5px 35px;"><code>&lt;?php echo do_shortcode('[simpleticker]'); ?&gt</code></div>
135 <div style="padding: 5px 35px;"><code>&lt;?php echo do_shortcode('[simpleticker ticker1_text="Ticker test!!" ticker1_color="#008000" sticky_posts_display=FALSE]'); ?&gt</code></div>
136
137 <div style="padding: 5px 20px; font-weight: bold;"><?php _e('Description of each attribute', 'simple-ticker'); ?></div>
138
139 <div style="padding: 5px 35px;"><?php _e('Text of ticker', 'simple-ticker'); ?> : <code>ticker1_text</code> <code>ticker2_text</code> <code>ticker3_text</code></div>
140 <div style="padding: 5px 35px;"><?php _e('Color of ticker', 'simple-ticker'); ?> : <code>ticker1_color</code> <code>ticker2_color</code> <code>ticker3_color</code></div>
141 <div style="padding: 5px 35px;"><?php _e('Boolean value of sticky_posts', 'simple-ticker'); ?> : <code>sticky_posts_display</code></div>
142 <div style="padding: 5px 35px;"><?php _e('Title color of sticky_posts', 'simple-ticker'); ?> : <code>sticky_posts_title_color</code></div>
143 <div style="padding: 5px 35px;"><?php _e('Content color of sticky_posts', 'simple-ticker'); ?> : <code>sticky_posts_content_color</code></div>
144
145 <?php
146 $settings_html = '<a href="'.$scriptname.'#simpleticker-admin-tabs-2" style="text-decoration: none; word-break: break-all;">'.__('Settings', 'simple-ticker').'</a>';
147 ?>
148 <div style="padding: 5px 20px; font-weight: bold;"><?php echo sprintf(__('Attribute value of short codes can also be specified in the %1$s. Attribute value of the short code takes precedence.', 'simple-ticker'), $settings_html); ?></div>
149 </div>
150
151 </div>
152 </div>
153
154 <div id="simpleticker-admin-tabs-2">
155 <div class="wrap">
156
157 <h2><?php _e('Settings'); ?></h2>
158
159 <form method="post" action="<?php echo $scriptname.'#simpleticker-admin-tabs-2'; ?>">
160 <?php wp_nonce_field('simpleticker_settings', 'simpleticker_tabs'); ?>
161
162 <div class="submit">
163 <input type="submit" class="button" name="Submit" value="<?php _e('Save Changes') ?>" />
164 <input type="submit" class="button" name="Default" value="<?php _e('Default') ?>" />
165 </div>
166
167 <div style="width: 100%; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid;">
168
169 <div style="display: block; padding:5px 5px;">
170 <h3><?php _e('Own Ticker', 'simple-ticker'); ?></h3>
171 <div style="display: block; padding:5px 20px;">
172 <?php _e('Ticker1', 'simple-ticker'); ?> :
173 <div style="display: block; padding:5px 35px;">
174 <div>
175 <?php _e('Text', 'simple-ticker'); ?> :
176 <textarea name="simpleticker_ticker1_text" rows="4" cols="40" style="vertical-align: top"><?php echo $simpleticker_option['ticker1']['text']; ?></textarea>
177 </div>
178 <div>
179 <?php _e('Color', 'simple-ticker'); ?> :
180 <input type="text" class="jscolor" name="simpleticker_ticker1_color" value="<?php echo $simpleticker_option['ticker1']['color']; ?>" size="10" />
181 </div>
182 </div>
183 </div>
184 <div style="display: block; padding:5px 20px;">
185 <?php _e('Ticker2', 'simple-ticker'); ?> :
186 <div style="display: block; padding:5px 35px;">
187 <div>
188 <?php _e('Text', 'simple-ticker'); ?> :
189 <textarea name="simpleticker_ticker2_text" rows="4" cols="40" style="vertical-align: top"><?php echo $simpleticker_option['ticker2']['text']; ?></textarea>
190 </div>
191 <div>
192 <?php _e('Color', 'simple-ticker'); ?> :
193 <input type="text" class="jscolor" name="simpleticker_ticker2_color" value="<?php echo $simpleticker_option['ticker2']['color']; ?>" size="10" />
194 </div>
195 </div>
196 </div>
197 <div style="display: block; padding:5px 20px;">
198 <?php _e('Ticker3', 'simple-ticker'); ?> :
199 <div style="display: block; padding:5px 35px;">
200 <div>
201 <?php _e('Text', 'simple-ticker'); ?> :
202 <textarea name="simpleticker_ticker3_text" rows="4" cols="40" style="vertical-align: top"><?php echo $simpleticker_option['ticker3']['text']; ?></textarea>
203 </div>
204 <div>
205 <?php _e('Color', 'simple-ticker'); ?> :
206 <input type="text" class="jscolor" name="simpleticker_ticker3_color" value="<?php echo $simpleticker_option['ticker3']['color']; ?>" size="10" />
207 </div>
208 </div>
209 </div>
210 </div>
211 </div>
212 <div style="width: 100%; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid;">
213 <div style="display: block; padding:5px 5px;">
214 <h3><?php _e('Sticky Posts', 'simple-ticker'); ?></h3>
215 <div style="display: block; padding:5px 20px;">
216 <input type="checkbox" name="simpleticker_sticky_posts" value="1" <?php checked('1', $simpleticker_option['sticky_posts']['display']); ?> />
217 <?php _e('Include sticky_posts', 'simple-ticker'); ?>
218 </div>
219 <div style="display: block; padding:5px 35px;">
220 <?php _e('Title color', 'simple-ticker'); ?> :
221 <input type="text" class="jscolor" name="simpleticker_sticky_posts_titlecolor" value="<?php echo $simpleticker_option['sticky_posts']['title_color']; ?>" size="10" />
222 </div>
223 <div style="display: block; padding:5px 35px;">
224 <?php _e('Content color', 'simple-ticker'); ?> :
225 <input type="text" class="jscolor" name="simpleticker_sticky_posts_contentcolor" value="<?php echo $simpleticker_option['sticky_posts']['content_color']; ?>" size="10" />
226 </div>
227 </div>
228 </div>
229
230 <div class="submit">
231 <input type="hidden" name="simpleticker_admin_tabs" value="2" />
232 <input type="submit" class="button" name="Submit" value="<?php _e('Save Changes') ?>" />
233 </div>
234
235 </form>
236
237 </div>
238 </div>
239
240 <div id="simpleticker-admin-tabs-3">
241 <div class="wrap">
242 <?php $this->credit(); ?>
243 </div>
244 </div>
245
246 <!--
247 <div id="simpleticker-admin-tabs-4">
248 <div class="wrap">
249 <h2>FAQ</h2>
250
251 </div>
252 </div>
253 -->
254
255 </div>
256 </div>
257 <?php
258
259 }
260
261 /* ==================================================
262 * Credit
263 */
264 function credit() {
265
266 $plugin_name = NULL;
267 $plugin_ver_num = NULL;
268 $plugin_path = plugin_dir_path( __DIR__ );
269 $plugin_dir = untrailingslashit($plugin_path);
270 $slugs = explode('/', $plugin_dir);
271 $slug = end($slugs);
272 $files = scandir($plugin_dir);
273 foreach ($files as $file) {
274 if($file == '.' || $file == '..' || is_dir($plugin_path.$file)){
275 continue;
276 } else {
277 $exts = explode('.', $file);
278 $ext = strtolower(end($exts));
279 if ( $ext === 'php' ) {
280 $plugin_datas = get_file_data( $plugin_path.$file, array('name'=>'Plugin Name', 'version' => 'Version') );
281 if ( array_key_exists( "name", $plugin_datas ) && !empty($plugin_datas['name']) && array_key_exists( "version", $plugin_datas ) && !empty($plugin_datas['version']) ) {
282 $plugin_name = $plugin_datas['name'];
283 $plugin_ver_num = $plugin_datas['version'];
284 break;
285 }
286 }
287 }
288 }
289 $plugin_version = __('Version:').' '.$plugin_ver_num;
290 $faq = __('https://wordpress.org/plugins/'.$slug.'/faq', $slug);
291 $support = 'https://wordpress.org/support/plugin/'.$slug;
292 $review = 'https://wordpress.org/support/view/plugin-reviews/'.$slug;
293 $translate = 'https://translate.wordpress.org/projects/wp-plugins/'.$slug;
294 $facebook = 'https://www.facebook.com/katsushikawamori/';
295 $twitter = 'https://twitter.com/dodesyo312';
296 $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
297 $donate = __('https://riverforest-wp.info/donate/', $slug);
298
299 ?>
300 <span style="font-weight: bold;">
301 <div>
302 <?php echo $plugin_version; ?> |
303 <a style="text-decoration: none;" href="<?php echo $faq; ?>" target="_blank"><?php _e('FAQ'); ?></a> | <a style="text-decoration: none;" href="<?php echo $support; ?>" target="_blank"><?php _e('Support Forums'); ?></a> | <a style="text-decoration: none;" href="<?php echo $review; ?>" target="_blank"><?php _e('Reviews', 'media-from-ftp'); ?></a>
304 </div>
305 <div>
306 <a style="text-decoration: none;" href="<?php echo $translate; ?>" target="_blank"><?php echo sprintf(__('Translations for %s'), $plugin_name); ?></a> | <a style="text-decoration: none;" href="<?php echo $facebook; ?>" target="_blank"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo $twitter; ?>" target="_blank"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo $youtube; ?>" target="_blank"><span class="dashicons dashicons-video-alt3"></span></a>
307 </div>
308 </span>
309
310 <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
311 <h3><?php _e('Please make a donation if you like my work or would like to further the development of this plugin.', $slug); ?></h3>
312 <div style="text-align: right; margin: 5px; padding: 5px;"><span style="padding: 3px; color: #ffffff; background-color: #008000">Plugin Author</span> <span style="font-weight: bold;">Katsushi Kawamori</span></div>
313 <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo $donate; ?>')"><?php _e('Donate to this plugin &#187;'); ?></button>
314 </div>
315
316 <?php
317
318 }
319
320 /* ==================================================
321 * Update wp_options table.
322 * @param string $tabs
323 * @since 1.0
324 */
325 function options_updated($tabs){
326
327
328 include_once( SIMPLETICKER_PLUGIN_BASE_DIR . '/inc/SimpleTicker.php' );
329 $simpleticker = new SimpleTicker();
330
331 $simple_ticker_reset_tbl = array(
332 'ticker1' => array(
333 'text' => '',
334 'color' => '#ff0000'
335 ),
336 'ticker2' => array(
337 'text' => '',
338 'color' => '#ffff00'
339 ),
340 'ticker3' => array(
341 'text' => '',
342 'color' => '#008000'
343 ),
344 'sticky_posts' => array(
345 'display' => TRUE,
346 'title_color' => '#ff0000',
347 'content_color' => '#000000'
348 )
349 );
350
351 switch ($tabs) {
352 case 1:
353 break;
354 case 2:
355 if ( !empty($_POST['Default']) ) {
356 update_option( 'simple_ticker', $simple_ticker_reset_tbl );
357 echo '<div class="updated"><ul><li>'.__('Settings').' --> '.__('Default').' --> '.__('Changes saved.').'</li></ul></div>';
358 } else {
359 if ( !empty($_POST['simpleticker_ticker1_text']) ) {
360 $simpleticker_ticker1_text = sanitize_text_field($_POST['simpleticker_ticker1_text']);
361 } else {
362 $simpleticker_ticker1_text = NULL;
363 }
364 if ( !empty($_POST['simpleticker_ticker2_text']) ) {
365 $simpleticker_ticker2_text = sanitize_text_field($_POST['simpleticker_ticker2_text']);
366 } else {
367 $simpleticker_ticker2_text = NULL;
368 }
369 if ( !empty($_POST['simpleticker_ticker3_text']) ) {
370 $simpleticker_ticker3_text = sanitize_text_field($_POST['simpleticker_ticker3_text']);
371 } else {
372 $simpleticker_ticker3_text = NULL;
373 }
374 if ( !empty($_POST['simpleticker_sticky_posts']) ) {
375 $simpleticker_sticky_posts = intval($_POST['simpleticker_sticky_posts']);
376 } else {
377 $simpleticker_sticky_posts = FALSE;
378 }
379 $simple_ticker_tbl = array(
380 'ticker1' => array(
381 'text' => $simpleticker->html_text($simpleticker_ticker1_text),
382 'color' => sanitize_text_field($_POST['simpleticker_ticker1_color'])
383 ),
384 'ticker2' => array(
385 'text' => $simpleticker->html_text($simpleticker_ticker2_text),
386 'color' => sanitize_text_field($_POST['simpleticker_ticker2_color'])
387 ),
388 'ticker3' => array(
389 'text' => $simpleticker->html_text($simpleticker_ticker3_text),
390 'color' => sanitize_text_field($_POST['simpleticker_ticker3_color'])
391 ),
392 'sticky_posts' => array(
393 'display' => $simpleticker_sticky_posts,
394 'title_color' => sanitize_text_field($_POST['simpleticker_sticky_posts_titlecolor']),
395 'content_color' => sanitize_text_field($_POST['simpleticker_sticky_posts_contentcolor'])
396 )
397 );
398 update_option( 'simple_ticker', $simple_ticker_tbl );
399 echo '<div class="updated"><ul><li>'.__('Settings').' --> '.__('Changes saved.').'</li></ul></div>';
400 }
401 break;
402 }
403
404 unset($simpleticker);
405
406 return;
407
408 }
409
410 }
411
412 ?>