| 1 |
<?php |
| 2 |
/** |
| 3 |
* Simple Ticker |
| 4 |
* |
| 5 |
* @package SimpleTicker |
| 6 |
* @subpackage SimpleTicker Widget |
| 7 |
/* |
| 8 |
Copyright (c) 2016- Katsushi Kawamori (email : dodesyoswift312@gmail.com) |
| 9 |
This program is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; version 2 of the License. |
| 12 |
|
| 13 |
This program is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
GNU General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with this program; if not, write to the Free Software |
| 20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 |
*/ |
| 22 |
|
| 23 |
add_action( |
| 24 |
'widgets_init', |
| 25 |
function() { |
| 26 |
register_widget( 'SimpleTickerWidgetItem' ); |
| 27 |
} |
| 28 |
); |
| 29 |
|
| 30 |
/** ================================================== |
| 31 |
* Widget |
| 32 |
* |
| 33 |
* @since 1.00 |
| 34 |
*/ |
| 35 |
class SimpleTickerWidgetItem extends WP_Widget { |
| 36 |
|
| 37 |
/** ================================================== |
| 38 |
* Construct |
| 39 |
* |
| 40 |
* @since 1.00 |
| 41 |
*/ |
| 42 |
public function __construct() { |
| 43 |
parent::__construct( |
| 44 |
'SimpleTickerWidgetItem', /* Base ID */ |
| 45 |
__( 'Ticker', 'simple-ticker' ), /* Name */ |
| 46 |
array( 'description' => __( 'Ticker from SimpleTicker.', 'simple-ticker' ) ) /* Args */ |
| 47 |
); |
| 48 |
} |
| 49 |
|
| 50 |
/** ================================================== |
| 51 |
* Widget |
| 52 |
* |
| 53 |
* @param array $args args. |
| 54 |
* @param array $instance instance. |
| 55 |
* @since 1.00 |
| 56 |
*/ |
| 57 |
public function widget( $args, $instance ) { |
| 58 |
|
| 59 |
$before_widget = $args['before_widget']; |
| 60 |
$before_title = $args['before_title']; |
| 61 |
$after_title = $args['after_title']; |
| 62 |
$after_widget = $args['after_widget']; |
| 63 |
|
| 64 |
$title = apply_filters( 'widget_title', $instance['title'] ); |
| 65 |
|
| 66 |
if ( $title ) { |
| 67 |
echo wp_kses_post( $before_widget ); |
| 68 |
echo wp_kses_post( $before_title . esc_html( $title ) . $after_title ); |
| 69 |
include_once( dirname( __FILE__ ) . '/class-simpleticker.php' ); |
| 70 |
$simpleticker = new SimpleTicker(); |
| 71 |
echo wp_kses_post( $simpleticker->read_tickers( null, null, null, null, null, null, null, null, null, null, null ) ); |
| 72 |
unset( $simpleticker ); |
| 73 |
echo wp_kses_post( $after_widget ); |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
/** ================================================== |
| 79 |
* Update |
| 80 |
* |
| 81 |
* @param array $new_instance new_instance. |
| 82 |
* @param array $old_instance old_instance. |
| 83 |
* @since 1.00 |
| 84 |
*/ |
| 85 |
public function update( $new_instance, $old_instance ) { |
| 86 |
$instance = $old_instance; |
| 87 |
$instance['title'] = wp_strip_tags( $new_instance['title'] ); |
| 88 |
return $instance; |
| 89 |
} |
| 90 |
|
| 91 |
/** ================================================== |
| 92 |
* Form |
| 93 |
* |
| 94 |
* @param array $instance instance. |
| 95 |
* @since 1.00 |
| 96 |
*/ |
| 97 |
public function form( $instance ) { |
| 98 |
|
| 99 |
if ( isset( $instance['title'] ) ) { |
| 100 |
$title = $instance['title']; |
| 101 |
} else { |
| 102 |
$title = null; |
| 103 |
} |
| 104 |
|
| 105 |
?> |
| 106 |
<p> |
| 107 |
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title' ); ?>:</label> |
| 108 |
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> |
| 109 |
</p> |
| 110 |
<?php |
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|