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