| 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 |
class SimpleTicker { |
| 23 |
|
| 24 |
/* |
| 25 |
* Main |
| 26 |
* @param string $ticker1_color |
| 27 |
* @param string $ticker1_text |
| 28 |
* @param string $ticker2_color |
| 29 |
* @param string $ticker2_text |
| 30 |
* @param string $ticker3_color |
| 31 |
* @param string $ticker3_text |
| 32 |
* @param bool $sticky_posts_display |
| 33 |
* @param string $sticky_posts_title_color |
| 34 |
* @param string $sticky_posts_content_color |
| 35 |
* @return string $ticker_html |
| 36 |
* @since 1.0 |
| 37 |
*/ |
| 38 |
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) { |
| 39 |
|
| 40 |
$simpleticker_option = get_option('simple_ticker'); |
| 41 |
|
| 42 |
if ( empty($ticker1_color) ) { $ticker1_color = $simpleticker_option['ticker1']['color']; } |
| 43 |
if ( empty($ticker1_text) ) { $ticker1_text = $simpleticker_option['ticker1']['text']; } |
| 44 |
if ( empty($ticker2_color) ) { $ticker2_color = $simpleticker_option['ticker2']['color']; } |
| 45 |
if ( empty($ticker2_text) ) { $ticker2_text = $simpleticker_option['ticker2']['text']; } |
| 46 |
if ( empty($ticker3_color) ) { $ticker3_color = $simpleticker_option['ticker3']['color']; } |
| 47 |
if ( empty($ticker3_text) ) { $ticker3_text = $simpleticker_option['ticker3']['text']; } |
| 48 |
|
| 49 |
if ( empty($sticky_posts_display) ) { $sticky_posts_display = $simpleticker_option['sticky_posts']['display']; } |
| 50 |
if ( empty($sticky_posts_title_color) ) { $sticky_posts_title_color = $simpleticker_option['sticky_posts']['title_color']; } |
| 51 |
if ( empty($sticky_posts_content_color) ) { $sticky_posts_content_color = $simpleticker_option['sticky_posts']['content_color']; } |
| 52 |
|
| 53 |
|
| 54 |
$ticker_html = NULL; |
| 55 |
|
| 56 |
if ( !empty($ticker1_text) ) { |
| 57 |
$ticker_html .= '<div><marquee><font color='.$ticker1_color.'><b>'; |
| 58 |
$ticker_html .= ' '.$ticker1_text; |
| 59 |
$ticker_html .= '</b></font></marquee></div>'; |
| 60 |
} |
| 61 |
if ( !empty($ticker2_text) ) { |
| 62 |
$ticker_html .= '<div><marquee><font color='.$ticker2_color.'><b>'; |
| 63 |
$ticker_html .= ' '.$ticker2_text; |
| 64 |
$ticker_html .= '</b></font></marquee></div>'; |
| 65 |
} |
| 66 |
if ( !empty($ticker3_text) ) { |
| 67 |
$ticker_html .= '<div><marquee><font color='.$ticker3_color.'><b>'; |
| 68 |
$ticker_html .= ' '.$ticker3_text; |
| 69 |
$ticker_html .= '</b></font></marquee></div>'; |
| 70 |
} |
| 71 |
|
| 72 |
if ( $sticky_posts_display == 1 ) { |
| 73 |
$stickies = get_option( 'sticky_posts' ); |
| 74 |
if ( !empty($stickies) ) { |
| 75 |
rsort( $stickies ); |
| 76 |
foreach ( $stickies as $sticky ) { |
| 77 |
$post = NULL; |
| 78 |
$title = NULL; |
| 79 |
$content = NULL; |
| 80 |
$post = get_post($sticky); |
| 81 |
$title = $post->post_title; |
| 82 |
$content = $this->html_text($post->post_content); |
| 83 |
$ticker_html .= '<div><marquee><font color='.$sticky_posts_title_color.'><b>'; |
| 84 |
$ticker_html .= ' '.$title.':'; |
| 85 |
$ticker_html .= '</b></font>'; |
| 86 |
$ticker_html .= '<font color='.$sticky_posts_content_color.'><b>'; |
| 87 |
$ticker_html .= $content; |
| 88 |
$ticker_html .= '</b></font></marquee></div>'; |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
return $ticker_html; |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
/* ================================================== |
| 98 |
* short code |
| 99 |
* @param array $atts |
| 100 |
* @return string $this->read_tickers() |
| 101 |
*/ |
| 102 |
function simpleticker_func( $atts ) { |
| 103 |
|
| 104 |
extract(shortcode_atts(array( |
| 105 |
'ticker1_color' => '', |
| 106 |
'ticker1_text' => '', |
| 107 |
'ticker2_color' => '', |
| 108 |
'ticker2_text' => '', |
| 109 |
'ticker3_color' => '', |
| 110 |
'ticker3_text' => '', |
| 111 |
'sticky_posts_display' => '', |
| 112 |
'sticky_posts_title_color' => '', |
| 113 |
'sticky_posts_content_color' => '' |
| 114 |
), $atts)); |
| 115 |
|
| 116 |
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); |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
/* |
| 121 |
* @param string $html |
| 122 |
* @return string $text |
| 123 |
* @since 1.0 |
| 124 |
*/ |
| 125 |
function html_text($html) { |
| 126 |
|
| 127 |
$text = strip_tags($html); |
| 128 |
$text = str_replace(array("\r", "\n"), '', $text); |
| 129 |
|
| 130 |
return $text; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
?> |