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

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

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