PluginProbe
Taboola / 1.0.15
Taboola v1.0.15
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 +33 -5 1.0.11.0.15 View file →
@@ -1,6 +1,7 @@
1 1 <?php
2 2 define ("TABOOLA_WIDGET_BASE_ID","taboola");
3 +define ("TABOOLA_CONTAINER_PREFIX","inner-");
3 4 class WP_Widget_Taboola extends WP_Widget {
4 5
5 6 private static $counter;
6 7 function __construct() {
@@ -10,8 +11,24 @@
10 11 parent::__construct( TABOOLA_WIDGET_BASE_ID, _x( 'Taboola Widget', 'Taboola Widget' ), $widget_ops );
11 12 $this->plugin_directory = plugin_dir_path(__FILE__);
12 13 }
13 14
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 +
14 31 function widget( $args, $instance ) {
15 32 if (!isset(WP_Widget_Taboola::$counter)){
16 33 WP_Widget_Taboola::$counter = 1;
17 34 }
@@ -30,9 +47,9 @@
30 47 $widget_num = $tmp_id[1];
31 48
32 49 $widget_id = ! empty( $instance['widget_id'] ) ? $instance['widget_id'] : '';
33 50
34 - // use the widget container name as the placement, suffix the widget_id to make it unique
51 + // use the widget container name as the placement, suffix the widget_num to make it unique
35 52 $placement=$args["id"]."-".$widget_num;
36 53
37 54 echo $before_widget;
38 55
@@ -39,13 +56,24 @@
39 56 if ( $title ){
40 57 echo $before_title . $title . $after_title;
41 58 }
42 59
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 +
43 68 //widget content
44 - $script2_content = str_replace('{{WIDGET_ID}}', $widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
45 - $script2_content = str_replace('{{CONTAINER}}', $this->id, $script2_content);
46 - $script2_content = str_replace('{{PLACEMENT}}', $placement, $script2_content);
47 - echo '<script type="text/javascript">'.$script2_content.'</script>';
69 + $stringParams = array(
70 + "{{WIDGET_ID}}" => $widget_id,
71 + "{{CONTAINER}}" => $container,
72 + "{{PLACEMENT}}" => $placement
73 + );
74 + $widgetInjectionScript_content = str_replace(array_keys($stringParams), array_values($stringParams), file_get_contents($this->plugin_directory.'js/widgetInjectionScript.js'));
75 + echo '<script type="text/javascript">'.$widgetInjectionScript_content.'</script>';
48 76
49 77 echo $after_widget;
50 78 }
51 79