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

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

256 lines 9.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 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 = 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 $woo_sales_datas['interval_day'] = intval( $interval_day_ux / (60 * 60 * 24) ).__('Days', 'simple-ticker');
175 $woo_sales_datas['interval_time'] = gmdate( 'H:i:s' , $interval_day_ux % (60 * 60 * 24) );
176 $ticker_html .= $sale_html;
177 $ticker_html .= '<span style="color: '.$woo_sales_color.'; font-weight: bold;"> : ';
178 $woo_sales_text = NULL;
179 if ( $woo_sales_datas ) {
180 $woo_sales_text = $woo_sales_text_tag;
181 foreach($woo_sales_datas as $item => $woo_sale) {
182 $woo_sales_text = str_replace('%'.$item.'%', $woo_sale, $woo_sales_text);
183 }
184 preg_match_all('/%(.*?)%/', $woo_sales_text, $woo_sales_text_per_match);
185 foreach($woo_sales_text_per_match as $key1) {
186 foreach($key1 as $key2) {
187 $woo_sales_text = str_replace('%'.$key2.'%', '', $woo_sales_text);
188 }
189 }
190 }
191 $ticker_html .= $woo_sales_text;
192 $ticker_html .= '</span> ';
193 }
194 }
195 }
196 $ticker_html .= '</div></div>';
197
198 }
199
200 return $ticker_html;
201
202 }
203
204 /* ==================================================
205 * short code
206 * @param array $atts
207 * @return string $this->read_tickers()
208 */
209 public function simpleticker_func( $atts ) {
210
211 extract(shortcode_atts(array(
212 'ticker1_color' => '',
213 'ticker1_text' => '',
214 'ticker2_color' => '',
215 'ticker2_text' => '',
216 'ticker3_color' => '',
217 'ticker3_text' => '',
218 'sticky_posts_display' => '',
219 'sticky_posts_title_color' => '',
220 'sticky_posts_content_color' => '',
221 'woo_sales_display' => '',
222 'woo_sales_color' => ''
223 ), $atts));
224
225 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);
226
227 }
228
229 /*
230 * @param string $html
231 * @return string $text
232 * @since 1.0
233 */
234 public function html_text($html) {
235
236 $text = strip_tags($html);
237 $text = str_replace(array("\r", "\n"), '', $text);
238
239 return $text;
240
241 }
242
243 /* ==================================================
244 * Load Marquee Style
245 * @since 2.00
246 */
247 public function load_styles() {
248 $speed = $this->simpleticker_option['speed'];
249 wp_enqueue_style( 'simpleticker', plugin_dir_url( __DIR__ ).'css/marquee.css' );
250 $css = '.marquee > .marquee-inner { animation-duration: '.$speed.'s; }';
251 wp_add_inline_style( 'simpleticker', $css );
252 }
253
254 }
255
256 ?>