PluginProbe
Taboola / 1.0.14
Taboola v1.0.14
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 | taboola_widget.php +64 -34 1.0.41.0.14 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2 /**
3 3 * Plugin Name: Taboola
4 - * Plugin URI: http://taboola.com
4 + * Plugin URI: https://developers.taboola.com/web-integrations/discuss
5 5 * Description: Taboola
6 - * Version: 1.0.4
6 + * Version: 1.0.14
7 7 * Author: Taboola
8 8 */
9 9
10 10 define ("XPATH_MARKER","/");
@@ -12,11 +12,13 @@
12 12 define ("JS_MARKER","{");
13 13 define ("TABOOLA_CONTENT_FORMAT_STRING",'string');
14 14 define ("TABOOLA_CONTENT_FORMAT_SCRIPT",'script');
15 15 define ("TABOOLA_CONTENT_FORMAT_HTML",'html');
16 +define ("TABOOLA_PLUGIN_VERSION","1.0.14");
16 17
17 18
18 19 include_once('widget.php');
20 +require_once('JavaScriptWrapper.php');
19 21
20 22 if (!class_exists('TaboolaWP')) {
21 23 class TaboolaWP
22 24 {
@@ -24,9 +26,10 @@
24 26 public $data = array();
25 27 public $_is_widget_on_page;
26 28 public $_is_head_script_loaded = false;
27 29
28 - function TaboolaWP()
30 +
31 + function __construct()
29 32 {
30 33 global $wpdb;
31 34
32 35 //initialize plugin constant
@@ -48,12 +51,16 @@
48 51 // Enable sidebar widgets
49 52 if($this->settings != NULL && !empty($this->settings->publisher_id)){
50 53 //register Taboola widget
51 54 add_action('widgets_init',
52 - create_function('', 'return register_widget("WP_Widget_Taboola");')
55 + function(){
56 + return register_widget("WP_Widget_Taboola");
57 + }
53 58 );
54 59 }
55 60
61 + //$this->should_place_tag_outside_of_content = $this->settings->out_of_content_enabled;
62 +
56 63 if (is_admin()) {
57 64 //add menu for plugin
58 65 add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
59 66 add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
@@ -113,15 +120,21 @@
113 120 // return the head loader script
114 121 function taboola_header_loader_js() {
115 122 $head_string = "";
116 123
117 - // Only adding Script1 if a widget is going to be placed on the page.
124 + // Only adding the loader if a widget is going to be placed on the page.
118 125 if ($this->is_widget_on_page()){
119 126
120 - $script1_content = str_replace('{{PUBLISHER_ID}}', $this->settings->publisher_id, file_get_contents($this->plugin_directory.'js/script1.js'));
121 - $script1_content = str_replace('{{PAGE_TYPE}}',$this->get_page_type(),$script1_content);
127 + $stringParams = array(
128 + '{{PUBLISHER_ID}}' => $this->settings->publisher_id,
129 + '{{PAGE_TYPE}}' => $this->get_page_type(),
130 + '{{WORDPRESS_VERSION}}' => get_bloginfo('version'),
131 + '{{PLUGIN_VERSION}}' => TABOOLA_PLUGIN_VERSION,
132 + '{{LOCATION}}' => $this->settings->location_string
133 + );
122 134
123 - $head_string = '<script type="text/javascript">'.$script1_content.'</script>';
135 + $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams);
136 + $head_string = $scriptWrapper->getScripMarkupString();
124 137 }
125 138
126 139 return $head_string;
127 140 }
@@ -135,12 +148,12 @@
135 148
136 149
137 150 function taboola_footer_loader_js() {
138 151
139 - // Only adding Script1 if a widget is going to be placed on the page.
152 + // Only adding flush script if a widget is going to be placed on the page.
140 153 if ( $this->is_widget_on_page() ){
141 - $script3_content = file_get_contents($this->plugin_directory.'js/script3.js');
142 - echo '<script type="text/javascript">'.$script3_content.'</script>';
154 + $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array());
155 + echo $flushInjectionScript->getScripMarkupString();
143 156 }
144 157 }
145 158
146 159 function load_taboola_content($content)
@@ -147,23 +160,26 @@
147 160 {
148 161 $taboola_content = array();
149 162 if ($this->should_show_content_widget()){
150 163
151 - $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->first_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
152 - $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article', $script2_content);
153 - $script2_content = str_replace('{{PLACEMENT}}', 'below-article', $script2_content);
164 + $firstWidgetParams = array('{{WIDGET_ID}}' => $this->settings->first_bc_widget_id,
165 + '{{CONTAINER}}' => 'taboola-below-article',
166 + '{{PLACEMENT}}' => 'below-article');
154 167
155 - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = '<div id="taboola-below-article"></div>';
156 - $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $script2_content;
168 + $firstWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$firstWidgetParams);
169 + $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article'></div>";
170 + $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $firstWidgetScript;
157 171
158 172 // Adding the 2nd widget if needed
159 173 if($this->settings->second_bc_enabled && trim($this->settings->second_bc_widget_id) != ''){
160 - $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->second_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
161 - $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article-second', $script2_content);
162 - $script2_content = str_replace('{{PLACEMENT}}', 'below-article-2nd', $script2_content);
163 174
164 - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = '<div id="taboola-below-article-second"></div>';
165 - $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $script2_content;
175 + $secondWidgetParams = array('{{WIDGET_ID}}' => $this->settings->second_bc_widget_id,
176 + '{{CONTAINER}}' => 'taboola-below-article-second',
177 + '{{PLACEMENT}}' => 'below-article-2nd');
178 + $secondWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$secondWidgetParams);
179 +
180 + $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article-second'></div>";
181 + $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $secondWidgetScript;
166 182 }
167 183
168 184 $content = $this->embed_taboola_content_location($content,$taboola_content,trim($this->settings->location_string));
169 185 }
@@ -208,18 +224,19 @@
208 224
209 225 if ($full_indicator == JS_INDICATOR){
210 226
211 227 $xpath = substr($location,strlen(JS_INDICATOR));
212 - $js_inject_script = file_get_contents($this->plugin_directory.'js/js_inject.min.js');
213 - $js_inject_script = str_replace("{{XPATH}}",$xpath,$js_inject_script);
214 - $js_inject_script = str_replace("{{HTML}}",$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML),$js_inject_script);
215 - $js_inject_script = str_replace("{{SCRIPT}}",$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT),$js_inject_script);
228 + $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
229 + "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML),
230 + "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT))
231 + );
232 + $scriptWrapper->appendScript("injectWidgetByXpath('".$xpath."');");
233 + $content = $content."<span id='tbdefault'></span><script type='text/javascript'>".$scriptWrapper."</script>";
216 234
217 - $content = $content."<span id='tbdefault'></span><script type='text/javascript'>".$js_inject_script."</script>";
218 235 $do_default = false;
219 236 }
220 237
221 - // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm)
238 + // server side selector provided (see simple_html_dom selectors https://simplehtmldom.sourceforge.net/manual.htm)
222 239 // basically it's CSS selectors like in jQuery
223 240 } else{
224 241
225 242 require_once('simple_html_dom.php');
@@ -235,8 +252,19 @@
235 252 $content = $html_doc;
236 253 $do_default = false;
237 254 }
238 255 }
256 +
257 + // tag is placed outside of content in order to allow "read more" functionality.
258 + }elseif ($this->settings->out_of_content_enabled){
259 +
260 + $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array(
261 + "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML),
262 + "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT))
263 + );
264 + $scriptWrapper->appendScript("injectWidgetByMarker('tbmarker');");
265 + $content = $content."<span id='tbmarker'></span><script type='text/javascript'>".$scriptWrapper."</script>";
266 + $do_default = false;
239 267 }
240 268
241 269 // Default - add to the end of the content
242 270 if ($do_default){
@@ -260,10 +288,10 @@
260 288
261 289 if(trim($_POST['publisher_id']) == ''){
262 290 $taboola_errors[] = "Please add a 'Publisher ID' in order to apply changes to your widgets";
263 291 }
264 - if(($_POST['first_bc_enabled'] == 'on' && trim($_POST['first_bc_widget_id']) == '') ||
265 - ($_POST['second_bc_enabled'] == 'on' && trim($_POST['second_bc_widget_id']) == '')
292 + if((isset($_POST['first_bc_enabled']) && trim($_POST['first_bc_widget_id']) == '') ||
293 + (isset($_POST['second_bc_enabled']) && trim($_POST['second_bc_widget_id']) == '')
266 294 ){
267 295 $taboola_errors[] = "Please add a 'Widget ID' in order to apply changes to your widgets";
268 296 }
269 297 if (trim($_POST['location_string']) != '' && !$this->is_location_string_valid($_POST['location_string'])){
@@ -272,13 +300,14 @@
272 300 if(count($taboola_errors) == 0){
273 301
274 302 $data = array(
275 303 "publisher_id" => trim($_POST['publisher_id']),
276 - "first_bc_enabled" => $_POST['first_bc_enabled'] == 'on' ? true : false,
304 + "first_bc_enabled" => isset($_POST['first_bc_enabled']) ? true : false,
277 305 "first_bc_widget_id" => trim($_POST['first_bc_widget_id']),
278 - "second_bc_enabled" => $_POST['second_bc_enabled'] == 'on' ? true : false,
306 + "second_bc_enabled" => isset($_POST['second_bc_enabled']) ? true : false,
279 307 "second_bc_widget_id" => trim($_POST['second_bc_widget_id']),
280 - "location_string" => trim($_POST['location_string'])
308 + "location_string" => trim($_POST['location_string']),
309 + "out_of_content_enabled" => isset($_POST['out_of_content_enabled']) ? true : false
281 310 );
282 311
283 312 //var_dump($settings);
284 313 if($settings == NULL){
@@ -305,9 +334,9 @@
305 334
306 335 $settings_table = $this->tbl_taboola_settings;
307 336
308 337 //check mysql version
309 - if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
338 + if (function_exists('mysql_get_server_info') && version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
310 339 if (!empty($wpdb->charset))
311 340 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
312 341 if (!empty($wpdb->collate))
313 342 $charset_collate .= " COLLATE $wpdb->collate";
@@ -324,12 +353,13 @@
324 353 `second_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
325 354 `second_bc_widget_id` VARCHAR(255) DEFAULT NULL,
326 355 `second_bc_custom_css` TEXT DEFAULT NULL,
327 356 `location_string` TEXT DEFAULT NULL,
357 + `out_of_content_enabled` TINYINT(1) NOT NULL DEFAULT TRUE,
328 358 PRIMARY KEY (`id`)
329 359 )" . $charset_collate . ";";
330 360
331 - // creat/update the table
361 + // create/update the table
332 362 dbDelta($sql_table_settings);
333 363 }
334 364 }
335 365 }