PluginProbe
Simple Ticker / 2.02
Simple Ticker v2.02
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 / SimpleTicker.php

SimpleTicker.php in Simple Ticker 2.02, at lib/SimpleTicker.php

228 lines 8.8 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 Simple Ticker
6 * @subpackage SimpleTicker
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 $simpleticker = new SimpleTicker();
23
24 class SimpleTicker {
25
26 /* ==================================================
27 * Construct
28 * @since 1.06
29 */
30 public function __construct() {
31
32 add_action( 'wp_print_styles', array($this, 'load_styles') );
33 add_shortcode( 'simpleticker', array($this, 'simpleticker_func') );
34
35 }
36
37 /*
38 * Main
39 * @param string $ticker1_color
40 * @param string $ticker1_text
41 * @param string $ticker2_color
42 * @param string $ticker2_text
43 * @param string $ticker3_color
44 * @param string $ticker3_text
45 * @param bool $sticky_posts_display
46 * @param string $sticky_posts_title_color
47 * @param string $sticky_posts_content_color
48 * @param bool $woo_sales_display
49 * @param string $woo_sales_color
50 * @return string $ticker_html
51 * @since 1.0
52 */
53 public function read_tickers($ticker1_color, $ticker1_text, $ticker2_color, $ticker2_text, $ticker3_color, $ticker3_text, $sticky_posts_display, $sticky_posts_title_color, $sticky_posts_content_color, $woo_sales_display, $woo_sales_color) {
54
55 $simpleticker_option = get_option('simple_ticker');
56
57 if ( empty($ticker1_color) ) { $ticker1_color = $simpleticker_option['ticker1']['color']; }
58 if ( empty($ticker1_text) ) { $ticker1_text = $simpleticker_option['ticker1']['text']; }
59 if ( empty($ticker2_color) ) { $ticker2_color = $simpleticker_option['ticker2']['color']; }
60 if ( empty($ticker2_text) ) { $ticker2_text = $simpleticker_option['ticker2']['text']; }
61 if ( empty($ticker3_color) ) { $ticker3_color = $simpleticker_option['ticker3']['color']; }
62 if ( empty($ticker3_text) ) { $ticker3_text = $simpleticker_option['ticker3']['text']; }
63
64 if ( empty($sticky_posts_display) ) { $sticky_posts_display = $simpleticker_option['sticky_posts']['display']; }
65 if ( empty($sticky_posts_title_color) ) { $sticky_posts_title_color = $simpleticker_option['sticky_posts']['title_color']; }
66 if ( empty($sticky_posts_content_color) ) { $sticky_posts_content_color = $simpleticker_option['sticky_posts']['content_color']; }
67
68 if ( empty($woo_sales_display) ) { $woo_sales_display = $simpleticker_option['woo_sales']['display']; }
69 if ( empty($woo_sales_color) ) { $woo_sales_color = $simpleticker_option['woo_sales']['color']; }
70
71 $ticker_html = NULL;
72
73 if ( !empty($ticker1_text) ) {
74 $ticker_html .= '<div class="marquee"><div class="marquee-inner"><font color="'.$ticker1_color.'"><b>';
75 $ticker_html .= ' '.$ticker1_text;
76 $ticker_html .= '</b></font></div></div>';
77 }
78 if ( !empty($ticker2_text) ) {
79 $ticker_html .= '<div class="marquee"><div class="marquee-inner"><font color="'.$ticker2_color.'"><b>';
80 $ticker_html .= ' '.$ticker2_text;
81 $ticker_html .= '</b></font></div></div>';
82 }
83 if ( !empty($ticker3_text) ) {
84 $ticker_html .= '<div class="marquee"><div class="marquee-inner"><font color="'.$ticker3_color.'"><b>';
85 $ticker_html .= ' '.$ticker3_text;
86 $ticker_html .= '</b></font></div></div>';
87 }
88
89 if ( $sticky_posts_display == 1 ) {
90 $stickies = get_option( 'sticky_posts' );
91 if ( !empty($stickies) ) {
92 rsort( $stickies );
93 foreach ( $stickies as $sticky ) {
94 $post = NULL;
95 $title = NULL;
96 $content = NULL;
97 $post = get_post($sticky);
98 $title = $post->post_title;
99 $content = $this->html_text($post->post_content);
100 $ticker_html .= '<div class="marquee"><div class="marquee-inner"><font color="'.$sticky_posts_title_color.'"><b>';
101 $ticker_html .= ' '.$title.':';
102 $ticker_html .= '</b></font>';
103 $ticker_html .= '<font color="'.$sticky_posts_content_color.'"><b>';
104 $ticker_html .= $content;
105 $ticker_html .= '</b></font></div></div>';
106 }
107 }
108 }
109
110 if ( $woo_sales_display == 1 && class_exists( 'WooCommerce' ) ) {
111 global $wpdb;
112 $sales = $wpdb->get_results("
113 SELECT post_id, meta_key, meta_value
114 FROM $wpdb->postmeta
115 WHERE meta_key LIKE '%%_sale_price%%'
116 ");
117 $ticker_html .= '<div class="marquee"><div class="marquee-inner">';
118 $woo_sales_text_tag = $simpleticker_option['woo_sales']['text'];
119 $currency = get_option('woocommerce_currency');
120 $currency_symbol = get_woocommerce_currency_symbol( $currency );
121 foreach ( $sales as $sale ){
122 if ( $sale->meta_key === '_sale_price' ) {
123 if ( !empty( $sale->meta_value ) ) {
124 $woo_sales_datas = array();
125 $sale_product = get_the_title( $sale->post_id );
126 $sale_link = get_permalink( $sale->post_id );
127 $sale_html = '<a href="'.$sale_link.'">'.$sale_product.'</a>';
128
129 $regular_price = get_post_meta( $sale->post_id, '_regular_price', TRUE );
130 $sale_price = get_post_meta( $sale->post_id, '_sale_price', TRUE );
131 $to_date_ux = get_post_meta( $sale->post_id, '_sale_price_dates_to', TRUE );
132 $current_date_ux = time();
133
134 $woo_sales_datas['regular_price'] = sprintf( get_woocommerce_price_format(), $currency_symbol, $regular_price );
135 $woo_sales_datas['sale_price'] = sprintf( get_woocommerce_price_format(), $currency_symbol, $sale_price );
136
137 $dis_amount = sprintf( get_woocommerce_price_format(), $currency_symbol, intval($regular_price - $sale_price) );
138 $dis_rate = intval((($regular_price - $sale_price) / $regular_price) * 100);
139 $woo_sales_datas['dis_rate_price'] = sprintf(__('%1$s %2$s', 'simple-ticker'), $dis_amount, __('OFF', 'countdown-woocommerce-sale'));
140 $woo_sales_datas['dis_rate_percent'] = sprintf(__('%1$d&#37; %2$s', 'simple-ticker'), $dis_rate, __('OFF', 'countdown-woocommerce-sale'));
141
142 $woo_sales_datas['to_date'] = date_i18n( "Y-m-d H:i:s", $to_date_ux, FALSE );
143 $interval_day_ux = $to_date_ux - $current_date_ux;
144 $woo_sales_datas['interval_day'] = intval( $interval_day_ux / (60 * 60 * 24) ).__('Days', 'simple-ticker');
145 $woo_sales_datas['interval_time'] = gmdate( 'H:i:s' , $interval_day_ux % (60 * 60 * 24) );
146 $ticker_html .= $sale_html;
147 $ticker_html .= '<font color="'.$woo_sales_color.'"><b> : ';
148 $woo_sales_text = NULL;
149 if ( $woo_sales_datas ) {
150 $woo_sales_text = $woo_sales_text_tag;
151 foreach($woo_sales_datas as $item => $woo_sale) {
152 $woo_sales_text = str_replace('%'.$item.'%', $woo_sale, $woo_sales_text);
153 }
154 preg_match_all('/%(.*?)%/', $woo_sales_text, $woo_sales_text_per_match);
155 foreach($woo_sales_text_per_match as $key1) {
156 foreach($key1 as $key2) {
157 $woo_sales_text = str_replace('%'.$key2.'%', '', $woo_sales_text);
158 }
159 }
160 }
161 $ticker_html .= $woo_sales_text;
162 $ticker_html .= '</b></font> ';
163 }
164 }
165 }
166 $ticker_html .= '</div></div>';
167
168 }
169
170 return $ticker_html;
171
172 }
173
174 /* ==================================================
175 * short code
176 * @param array $atts
177 * @return string $this->read_tickers()
178 */
179 public function simpleticker_func( $atts ) {
180
181 extract(shortcode_atts(array(
182 'ticker1_color' => '',
183 'ticker1_text' => '',
184 'ticker2_color' => '',
185 'ticker2_text' => '',
186 'ticker3_color' => '',
187 'ticker3_text' => '',
188 'sticky_posts_display' => '',
189 'sticky_posts_title_color' => '',
190 'sticky_posts_content_color' => '',
191 'woo_sales_display' => '',
192 'woo_sales_color' => ''
193 ), $atts));
194
195 return $this->read_tickers($ticker1_color, $this->html_text($ticker1_text), $ticker2_color, $this->html_text($ticker2_text), $ticker3_color, $this->html_text($ticker3_text), $sticky_posts_display, $sticky_posts_title_color, $sticky_posts_content_color, $woo_sales_display, $woo_sales_color);
196
197 }
198
199 /*
200 * @param string $html
201 * @return string $text
202 * @since 1.0
203 */
204 public function html_text($html) {
205
206 $text = strip_tags($html);
207 $text = str_replace(array("\r", "\n"), '', $text);
208
209 return $text;
210
211 }
212
213 /* ==================================================
214 * Load Marquee Style
215 * @since 2.00
216 */
217 public function load_styles() {
218 $simpleticker_option = get_option('simple_ticker');
219 $speed = $simpleticker_option['speed'];
220 $woo_sales_color = $simpleticker_option['woo_sales']['color'];
221 wp_enqueue_style( 'simpleticker', plugin_dir_url( __DIR__ ).'css/marquee.css' );
222 $css = '.marquee > .marquee-inner { animation-duration: '.$speed.'s; }';
223 wp_add_inline_style( 'simpleticker', $css );
224 }
225
226 }
227
228 ?>