PluginProbe
Taboola / 1.0
Taboola v1.0
1.0.4 1.0.5 1.0.6 1.0.8 2.0.1 2.0.2 2.1.0 2.1.1 2.2.2 2.2.3 3.0.0 3.0.1 3.0.2 3.1.0 trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.2 1.0.3
← All changes | widget.php +12 -51 1.0.51.0 View file →
@@ -1,41 +1,15 @@
1 1 <?php
2 -define ("TABOOLA_WIDGET_BASE_ID","taboola");
3 -define ("TABOOLA_CONTAINER_PREFIX","inner-");
2 +
4 3 class WP_Widget_Taboola extends WP_Widget {
5 4
6 - private static $counter;
7 5 function __construct() {
8 -
9 -
10 6 $widget_ops = array('classname' => 'widget_taboola', 'description' => __( "A taboola widget for your site.") );
11 - parent::__construct( TABOOLA_WIDGET_BASE_ID, _x( 'Taboola Widget', 'Taboola Widget' ), $widget_ops );
7 + parent::__construct( 'taboola', _x( 'Taboola Widget', 'Taboola Widget' ), $widget_ops );
12 8 $this->plugin_directory = plugin_dir_path(__FILE__);
13 9 }
14 10
15 - function get_id($tag){
16 -
17 - $start_pos = strpos($tag,"id=");
18 -
19 - $container_id = null;
20 - if ($start_pos !== false){
21 -
22 - $end_pos = strpos($tag," ",$start_pos);
23 - $extracted_id = str_replace(array('"',"'"),"",substr($tag,$start_pos+3,$end_pos-$start_pos-3));
24 - if ($extracted_id != ""){
25 - $container_id = $extracted_id;
26 - }
27 - }
28 - return $container_id;
29 - }
30 -
31 11 function widget( $args, $instance ) {
32 - if (!isset(WP_Widget_Taboola::$counter)){
33 - WP_Widget_Taboola::$counter = 1;
34 - }
35 - else{
36 - WP_Widget_Taboola::$counter = WP_Widget_Taboola::$counter + 1;
37 - }
38 12 if (trim($instance['widget_id']) == ''){
39 13 return;
40 14 }
41 15 extract($args);
@@ -42,33 +16,19 @@
42 16
43 17 /** This filter is documented in wp-includes/default-widgets.php */
44 18 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
45 19
46 - $tmp_id = explode("-",$args["widget_id"]);
47 - $widget_num = $tmp_id[1];
48 -
49 20 $widget_id = ! empty( $instance['widget_id'] ) ? $instance['widget_id'] : '';
21 + $placement = ! empty( $instance['placement'] ) ? $instance['placement'] : '';
50 22
51 - // use the widget container name as the placement, suffix the widget_num to make it unique
52 - $placement=$args["id"]."-".$widget_num;
53 -
54 23 echo $before_widget;
55 24
56 - if ( $title ){
25 + if ( $title )
57 26 echo $before_title . $title . $after_title;
58 - }
59 27
60 - $container = $this->get_id($before_widget);
61 -
62 - if ($container == null){
63 - // widget container (adding a div)
64 - $container = TABOOLA_CONTAINER_PREFIX.$this->id;
65 - echo '<div id="'.$container.'"></div>';
66 - }
67 -
68 28 //widget content
69 29 $script2_content = str_replace('{{WIDGET_ID}}', $widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
70 - $script2_content = str_replace('{{CONTAINER}}', $container, $script2_content);
30 + $script2_content = str_replace('{{CONTAINER}}', $this->id, $script2_content);
71 31 $script2_content = str_replace('{{PLACEMENT}}', $placement, $script2_content);
72 32 echo '<script type="text/javascript">'.$script2_content.'</script>';
73 33
74 34 echo $after_widget;
@@ -76,8 +36,9 @@
76 36
77 37 function form( $instance ) {
78 38 $instance = wp_parse_args( (array) $instance );
79 39 $widget_id = esc_attr( $instance['widget_id'] );
40 + $placement = esc_attr( $instance['placement'] );
80 41 ?>
81 42 <p>
82 43 <label for="<?php echo $this->get_field_id('widget_id'); ?>"><?php _e('Widget ID:'); ?>
83 44 <input class="widefat" id="<?php echo $this->get_field_id('widget_id'); ?>" name="<?php echo $this->get_field_name('widget_id'); ?>" type="text" value="<?php echo esc_attr($widget_id); ?>" />
@@ -82,20 +43,20 @@
82 43 <label for="<?php echo $this->get_field_id('widget_id'); ?>"><?php _e('Widget ID:'); ?>
83 44 <input class="widefat" id="<?php echo $this->get_field_id('widget_id'); ?>" name="<?php echo $this->get_field_name('widget_id'); ?>" type="text" value="<?php echo esc_attr($widget_id); ?>" />
84 45 </label>
85 46 </p>
47 + <p>
48 + <label for="<?php echo $this->get_field_id('placement'); ?>"><?php _e('Placement:'); ?>
49 + <input class="widefat" id="<?php echo $this->get_field_id('placement'); ?>" name="<?php echo $this->get_field_name('placement'); ?>" type="text" value="<?php echo esc_attr($placement); ?>" />
50 + </label>
51 + </p>
86 52 <?php
87 53 }
88 54
89 55 function update( $new_instance, $old_instance ) {
90 -
91 - // canceling save if the field is empty
92 - if (strip_tags($new_instance['widget_id']) == ""){
93 - return false;
94 - }
95 -
96 56 $instance = $old_instance;
97 57 $instance['widget_id'] = strip_tags($new_instance['widget_id']);
58 + $instance['placement'] = strip_tags($new_instance['placement']);
98 59
99 60 return $instance;
100 61 }
101 62