| @@ -2,23 +2,13 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Taboola |
| 4 | 4 | * Plugin URI: http://taboola.com |
| 5 | 5 | * Description: Taboola |
| 6 | - * Version: 1.0.7 | |
| 6 | + * Version: 1.0.2 | |
| 7 | 7 | * Author: Taboola |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -define ("XPATH_MARKER","/"); | |
| 11 | -define ("JS_INDICATOR","{JS}"); | |
| 12 | -define ("JS_MARKER","{"); | |
| 13 | -define ("TABOOLA_CONTENT_FORMAT_STRING",'string'); | |
| 14 | -define ("TABOOLA_CONTENT_FORMAT_SCRIPT",'script'); | |
| 15 | -define ("TABOOLA_CONTENT_FORMAT_HTML",'html'); | |
| 16 | -define ("TABOOLA_PLUGIN_VERSION","1.0.8"); | |
| 17 | - | |
| 18 | - | |
| 19 | 10 | include_once('widget.php'); |
| 20 | -require_once('JavaScriptWrapper.php'); | |
| 21 | 11 | |
| 22 | 12 | if (!class_exists('TaboolaWP')) { |
| 23 | 13 | class TaboolaWP |
| 24 | 14 | { |
| @@ -26,9 +16,8 @@ | ||
| 26 | 16 | public $data = array(); |
| 27 | 17 | public $_is_widget_on_page; |
| 28 | 18 | public $_is_head_script_loaded = false; |
| 29 | 19 | |
| 30 | - | |
| 31 | 20 | function TaboolaWP() |
| 32 | 21 | { |
| 33 | 22 | global $wpdb; |
| 34 | 23 | |
| @@ -55,10 +44,8 @@ | ||
| 55 | 44 | create_function('', 'return register_widget("WP_Widget_Taboola");') |
| 56 | 45 | ); |
| 57 | 46 | } |
| 58 | 47 | |
| 59 | - $this->should_place_tag_outside_of_content = $this->settings->out_of_content_enabled; | |
| 60 | - | |
| 61 | 48 | if (is_admin()) { |
| 62 | 49 | //add menu for plugin |
| 63 | 50 | add_action( 'admin_menu', array(&$this, 'admin_generate_menu') ); |
| 64 | 51 | add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 ); |
| @@ -118,20 +105,15 @@ | ||
| 118 | 105 | // return the head loader script |
| 119 | 106 | function taboola_header_loader_js() { |
| 120 | 107 | $head_string = ""; |
| 121 | 108 | |
| 122 | - // Only adding the loader if a widget is going to be placed on the page. | |
| 109 | + // Only adding Script1 if a widget is going to be placed on the page. | |
| 123 | 110 | if ($this->is_widget_on_page()){ |
| 124 | 111 | |
| 125 | - $stringParams = array( | |
| 126 | - '{{PUBLISHER_ID}}' => $this->settings->publisher_id, | |
| 127 | - '{{PAGE_TYPE}}' => $this->get_page_type(), | |
| 128 | - '{{WORDPRESS_VERSION}}' => get_bloginfo('version'), | |
| 129 | - '{{PLUGIN_VERSION}}' => TABOOLA_PLUGIN_VERSION | |
| 130 | - ); | |
| 112 | + $script1_content = str_replace('{{PUBLISHER_ID}}', $this->settings->publisher_id, file_get_contents($this->plugin_directory.'js/script1.js')); | |
| 113 | + $script1_content = str_replace('{{PAGE_TYPE}}',$this->get_page_type(),$script1_content); | |
| 131 | 114 | |
| 132 | - $scriptWrapper = new JavaScriptWrapper("loaderInjectionScript.js",$stringParams); | |
| 133 | - $head_string = $scriptWrapper->getScripMarkupString(); | |
| 115 | + $head_string = '<script type="text/javascript">'.$script1_content.'</script>'; | |
| 134 | 116 | } |
| 135 | 117 | |
| 136 | 118 | return $head_string; |
| 137 | 119 | } |
| @@ -145,134 +127,43 @@ | ||
| 145 | 127 | |
| 146 | 128 | |
| 147 | 129 | function taboola_footer_loader_js() { |
| 148 | 130 | |
| 149 | - // Only adding flush script if a widget is going to be placed on the page. | |
| 131 | + // Only adding Script1 if a widget is going to be placed on the page. | |
| 150 | 132 | if ( $this->is_widget_on_page() ){ |
| 151 | - $flushInjectionScript = new JavaScriptWrapper('flushInjectionScript.js',array()); | |
| 152 | - echo $flushInjectionScript->getScripMarkupString(); | |
| 133 | + $script3_content = file_get_contents($this->plugin_directory.'js/script3.js'); | |
| 134 | + echo '<script type="text/javascript">'.$script3_content.'</script>'; | |
| 153 | 135 | } |
| 154 | 136 | } |
| 155 | 137 | |
| 156 | 138 | function load_taboola_content($content) |
| 157 | 139 | { |
| 158 | - $taboola_content = array(); | |
| 140 | + | |
| 159 | 141 | if ($this->should_show_content_widget()){ |
| 160 | 142 | |
| 161 | - $firstWidgetParams = array('{{WIDGET_ID}}' => $this->settings->first_bc_widget_id, | |
| 162 | - '{{CONTAINER}}' => 'taboola-below-article', | |
| 163 | - '{{PLACEMENT}}' => 'below-article'); | |
| 143 | + $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->first_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); | |
| 144 | + $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article', $script2_content); | |
| 145 | + $script2_content = str_replace('{{PLACEMENT}}', 'below-article', $script2_content); | |
| 164 | 146 | |
| 165 | - $firstWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$firstWidgetParams); | |
| 166 | - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article'></div>"; | |
| 167 | - $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $firstWidgetScript; | |
| 147 | + $content = $content . | |
| 148 | + '<div id="taboola-below-article"></div>' . | |
| 149 | + '<script type="text/javascript">'.$script2_content.'</script>'; | |
| 168 | 150 | |
| 169 | 151 | // Adding the 2nd widget if needed |
| 170 | 152 | if($this->settings->second_bc_enabled && trim($this->settings->second_bc_widget_id) != ''){ |
| 153 | + $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->second_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); | |
| 154 | + $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article-second', $script2_content); | |
| 155 | + $script2_content = str_replace('{{PLACEMENT}}', 'below-article-2nd', $script2_content); | |
| 171 | 156 | |
| 172 | - $secondWidgetParams = array('{{WIDGET_ID}}' => $this->settings->second_bc_widget_id, | |
| 173 | - '{{CONTAINER}}' => 'taboola-below-article-second', | |
| 174 | - '{{PLACEMENT}}' => 'below-article-2nd'); | |
| 175 | - $secondWidgetScript = new JavaScriptWrapper("widgetInjectionScript.js",$secondWidgetParams); | |
| 176 | - | |
| 177 | - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = "<div id='taboola-below-article-second'></div>"; | |
| 178 | - $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $secondWidgetScript; | |
| 157 | + $content = $content . | |
| 158 | + '<div id="taboola-below-article-second"></div>' . | |
| 159 | + '<script type="text/javascript">'.$script2_content.'</script>'; | |
| 179 | 160 | } |
| 180 | - | |
| 181 | - $content = $this->embed_taboola_content_location($content,$taboola_content,trim($this->settings->location_string)); | |
| 182 | 161 | } |
| 183 | 162 | |
| 184 | 163 | return $content; |
| 185 | 164 | } |
| 186 | 165 | |
| 187 | - | |
| 188 | - // Extract the taboola content in the required format: | |
| 189 | - // String - for injecting on the servr side | |
| 190 | - // Script or HTML - for injecting on the client side | |
| 191 | - function format_taboola_content($taboola_content,$format){ | |
| 192 | - $ret_val = null; | |
| 193 | - | |
| 194 | - switch($format){ | |
| 195 | - case TABOOLA_CONTENT_FORMAT_STRING: | |
| 196 | - $result_string = join("",$taboola_content[TABOOLA_CONTENT_FORMAT_HTML]). | |
| 197 | - "<script type='text/javascript'>".join("\n",$taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT])."</script>"; | |
| 198 | - $ret_val = $result_string; | |
| 199 | - break; | |
| 200 | - | |
| 201 | - // script or html | |
| 202 | - default: | |
| 203 | - $ret_val = str_replace("\n","",join("",$taboola_content[$format])); | |
| 204 | - break; | |
| 205 | - } | |
| 206 | - | |
| 207 | - return $ret_val; | |
| 208 | - } | |
| 209 | - | |
| 210 | - | |
| 211 | - // Do the actual logic of choosing where to place the taboola content based on the "location" attribute | |
| 212 | - function embed_taboola_content_location($content, $taboola_content, $location){ | |
| 213 | - $do_default = true; | |
| 214 | - | |
| 215 | - if (isset($location) && $location != ''){ | |
| 216 | - $first_char = substr($location,0,1); | |
| 217 | - | |
| 218 | - // DIV/XPATH provided for JS handling | |
| 219 | - if ($first_char == JS_MARKER){ | |
| 220 | - $full_indicator = substr($location,0,strlen(JS_INDICATOR)); | |
| 221 | - | |
| 222 | - if ($full_indicator == JS_INDICATOR){ | |
| 223 | - | |
| 224 | - $xpath = substr($location,strlen(JS_INDICATOR)); | |
| 225 | - $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array( | |
| 226 | - "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML), | |
| 227 | - "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT)) | |
| 228 | - ); | |
| 229 | - $scriptWrapper->appendScript("injectWidgetByXpath('".$xpath."');"); | |
| 230 | - $content = $content."<span id='tbdefault'></span><script type='text/javascript'>".$scriptWrapper."</script>"; | |
| 231 | - | |
| 232 | - $do_default = false; | |
| 233 | - } | |
| 234 | - | |
| 235 | - // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm) | |
| 236 | - // basically it's CSS selectors like in jQuery | |
| 237 | - } else{ | |
| 238 | - | |
| 239 | - require_once('simple_html_dom.php'); | |
| 240 | - | |
| 241 | - $html_doc = str_get_html($content); | |
| 242 | - $target_location = $html_doc->find($location,0); | |
| 243 | - | |
| 244 | - // if the location was found within the html content | |
| 245 | - if (isset($target_location) && is_object($target_location)){ | |
| 246 | - | |
| 247 | - // adding taboola content AFTER the target location | |
| 248 | - $target_location->outertext = $target_location->outertext.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING); | |
| 249 | - $content = $html_doc; | |
| 250 | - $do_default = false; | |
| 251 | - } | |
| 252 | - } | |
| 253 | - | |
| 254 | - // tag is placed outside of content in order to allow "read more" functionality. | |
| 255 | - }elseif ($this->should_place_tag_outside_of_content){ | |
| 256 | - | |
| 257 | - $scriptWrapper = new JavaScriptWrapper("js_inject.min.js",array( | |
| 258 | - "{{HTML}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_HTML), | |
| 259 | - "{{SCRIPT}}" => $this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_SCRIPT)) | |
| 260 | - ); | |
| 261 | - $scriptWrapper->appendScript("injectWidgetByMarker('tbmarker');"); | |
| 262 | - $content = $content."<span id='tbmarker'></span><script type='text/javascript'>".$scriptWrapper."</script>"; | |
| 263 | - $do_default = false; | |
| 264 | - } | |
| 265 | - | |
| 266 | - // Default - add to the end of the content | |
| 267 | - if ($do_default){ | |
| 268 | - $content = $content.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING); | |
| 269 | - } | |
| 270 | - | |
| 271 | - return $content; | |
| 272 | - } | |
| 273 | - | |
| 274 | - | |
| 275 | 166 | function admin_generate_menu(){ |
| 276 | 167 | global $current_user; |
| 277 | 168 | add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110); |
| 278 | 169 | } |
| @@ -290,11 +181,8 @@ | ||
| 290 | 181 | ($_POST['second_bc_enabled'] == 'on' && trim($_POST['second_bc_widget_id']) == '') |
| 291 | 182 | ){ |
| 292 | 183 | $taboola_errors[] = "Please add a 'Widget ID' in order to apply changes to your widgets"; |
| 293 | 184 | } |
| 294 | - if (trim($_POST['location_string']) != '' && !$this->is_location_string_valid($_POST['location_string'])){ | |
| 295 | - $taboola_errors[] = "Location string not valid, please contact your Taboola account manager to get a valid location string"; | |
| 296 | - } | |
| 297 | 185 | if(count($taboola_errors) == 0){ |
| 298 | 186 | |
| 299 | 187 | $data = array( |
| 300 | 188 | "publisher_id" => trim($_POST['publisher_id']), |
| @@ -301,12 +189,9 @@ | ||
| 301 | 189 | "first_bc_enabled" => $_POST['first_bc_enabled'] == 'on' ? true : false, |
| 302 | 190 | "first_bc_widget_id" => trim($_POST['first_bc_widget_id']), |
| 303 | 191 | "second_bc_enabled" => $_POST['second_bc_enabled'] == 'on' ? true : false, |
| 304 | 192 | "second_bc_widget_id" => trim($_POST['second_bc_widget_id']), |
| 305 | - "location_string" => trim($_POST['location_string']), | |
| 306 | - "out_of_content_enabled" => $_POST['out_of_content_enabled'] == 'on' ? true : false | |
| 307 | 193 | ); |
| 308 | - | |
| 309 | 194 | //var_dump($settings); |
| 310 | 195 | if($settings == NULL){ |
| 311 | 196 | $wpdb->insert($this->tbl_taboola_settings, $data, null, null); |
| 312 | 197 | } else { |
| @@ -318,13 +203,8 @@ | ||
| 318 | 203 | |
| 319 | 204 | |
| 320 | 205 | include_once('settings.php'); |
| 321 | 206 | } |
| 322 | - | |
| 323 | - function is_location_string_valid($location_string){ | |
| 324 | - // TODO:: validate the location string | |
| 325 | - return true; | |
| 326 | - } | |
| 327 | 207 | function activate(){ |
| 328 | 208 | global $wpdb; |
| 329 | 209 | |
| 330 | 210 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| @@ -331,9 +211,9 @@ | ||
| 331 | 211 | |
| 332 | 212 | $settings_table = $this->tbl_taboola_settings; |
| 333 | 213 | |
| 334 | 214 | //check mysql version |
| 335 | - if (function_exists('mysql_get_server_info') && version_compare(mysql_get_server_info(), '4.1.0', '>=')) { | |
| 215 | + if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) { | |
| 336 | 216 | if (!empty($wpdb->charset)) |
| 337 | 217 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
| 338 | 218 | if (!empty($wpdb->collate)) |
| 339 | 219 | $charset_collate .= " COLLATE $wpdb->collate"; |
| @@ -349,19 +229,17 @@ | ||
| 349 | 229 | `first_bc_custom_css` TEXT DEFAULT NULL, |
| 350 | 230 | `second_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE, |
| 351 | 231 | `second_bc_widget_id` VARCHAR(255) DEFAULT NULL, |
| 352 | 232 | `second_bc_custom_css` TEXT DEFAULT NULL, |
| 353 | - `location_string` TEXT DEFAULT NULL, | |
| 354 | - `out_of_content_enabled` TINYINT(1) NOT NULL DEFAULT TRUE, | |
| 355 | 233 | PRIMARY KEY (`id`) |
| 356 | 234 | )" . $charset_collate . ";"; |
| 357 | 235 | |
| 358 | - // create/update the table | |
| 236 | + //check if table exists | |
| 237 | + if ($wpdb->get_var("show tables like '" . $settings_table . "'") != $settings_table) { | |
| 359 | 238 | dbDelta($sql_table_settings); |
| 239 | + } | |
| 360 | 240 | } |
| 361 | 241 | } |
| 362 | 242 | } |
| 363 | 243 | |
| 364 | 244 | global $taboolaWP; |
| 365 | -$taboolaWP = new TaboolaWP(); | |
| 366 | - | |
| 367 | -// | |
| 245 | +$taboolaWP = new TaboolaWP(); | |