PluginProbe
Simple Ticker / 1.07
Simple Ticker v1.07
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 / lib / SimpleTickerAdmin.php

SimpleTickerAdmin.php in Simple Ticker 1.07, at lib/SimpleTickerAdmin.php

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