| @@ -2,20 +2,12 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Taboola |
| 4 | 4 | * Plugin URI: http://taboola.com |
| 5 | 5 | * Description: Taboola |
| 6 | - * Version: 1.0.5 | |
| 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 | - | |
| 17 | - | |
| 18 | 10 | include_once('widget.php'); |
| 19 | 11 | |
| 20 | 12 | if (!class_exists('TaboolaWP')) { |
| 21 | 13 | class TaboolaWP |
| @@ -144,9 +136,9 @@ | ||
| 144 | 136 | } |
| 145 | 137 | |
| 146 | 138 | function load_taboola_content($content) |
| 147 | 139 | { |
| 148 | - $taboola_content = array(); | |
| 140 | + | |
| 149 | 141 | if ($this->should_show_content_widget()){ |
| 150 | 142 | |
| 151 | 143 | $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->first_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); |
| 152 | 144 | $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article', $script2_content); |
| @@ -151,10 +143,11 @@ | ||
| 151 | 143 | $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->first_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); |
| 152 | 144 | $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article', $script2_content); |
| 153 | 145 | $script2_content = str_replace('{{PLACEMENT}}', 'below-article', $script2_content); |
| 154 | 146 | |
| 155 | - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = '<div id="taboola-below-article"></div>'; | |
| 156 | - $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $script2_content; | |
| 147 | + $content = $content . | |
| 148 | + '<div id="taboola-below-article"></div>' . | |
| 149 | + '<script type="text/javascript">'.$script2_content.'</script>'; | |
| 157 | 150 | |
| 158 | 151 | // Adding the 2nd widget if needed |
| 159 | 152 | if($this->settings->second_bc_enabled && trim($this->settings->second_bc_widget_id) != ''){ |
| 160 | 153 | $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->second_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); |
| @@ -160,94 +153,17 @@ | ||
| 160 | 153 | $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->second_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js')); |
| 161 | 154 | $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article-second', $script2_content); |
| 162 | 155 | $script2_content = str_replace('{{PLACEMENT}}', 'below-article-2nd', $script2_content); |
| 163 | 156 | |
| 164 | - $taboola_content[TABOOLA_CONTENT_FORMAT_HTML][] = '<div id="taboola-below-article-second"></div>'; | |
| 165 | - $taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT][] = $script2_content; | |
| 157 | + $content = $content . | |
| 158 | + '<div id="taboola-below-article-second"></div>' . | |
| 159 | + '<script type="text/javascript">'.$script2_content.'</script>'; | |
| 166 | 160 | } |
| 167 | - | |
| 168 | - $content = $this->embed_taboola_content_location($content,$taboola_content,trim($this->settings->location_string)); | |
| 169 | 161 | } |
| 170 | 162 | |
| 171 | 163 | return $content; |
| 172 | 164 | } |
| 173 | 165 | |
| 174 | - | |
| 175 | - // Extract the taboola content in the required format: | |
| 176 | - // String - for injecting on the servr side | |
| 177 | - // Script or HTML - for injecting on the client side | |
| 178 | - function format_taboola_content($taboola_content,$format){ | |
| 179 | - $ret_val = null; | |
| 180 | - | |
| 181 | - switch($format){ | |
| 182 | - case TABOOLA_CONTENT_FORMAT_STRING: | |
| 183 | - $result_string = join("",$taboola_content[TABOOLA_CONTENT_FORMAT_HTML]). | |
| 184 | - "<script type='text/javascript'>".join("\n",$taboola_content[TABOOLA_CONTENT_FORMAT_SCRIPT])."</script>"; | |
| 185 | - $ret_val = $result_string; | |
| 186 | - break; | |
| 187 | - | |
| 188 | - // script or html | |
| 189 | - default: | |
| 190 | - $ret_val = str_replace("\n","",join("",$taboola_content[$format])); | |
| 191 | - break; | |
| 192 | - } | |
| 193 | - | |
| 194 | - return $ret_val; | |
| 195 | - } | |
| 196 | - | |
| 197 | - | |
| 198 | - // Do the actual logic of choosing where to place the taboola content based on the "location" attribute | |
| 199 | - function embed_taboola_content_location($content, $taboola_content, $location){ | |
| 200 | - $do_default = true; | |
| 201 | - | |
| 202 | - if (isset($location) && $location != ''){ | |
| 203 | - $first_char = substr($location,0,1); | |
| 204 | - | |
| 205 | - // DIV/XPATH provided for JS handling | |
| 206 | - if ($first_char == JS_MARKER){ | |
| 207 | - $full_indicator = substr($location,0,strlen(JS_INDICATOR)); | |
| 208 | - | |
| 209 | - if ($full_indicator == JS_INDICATOR){ | |
| 210 | - | |
| 211 | - $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); | |
| 216 | - | |
| 217 | - $content = $content."<span id='tbdefault'></span><script type='text/javascript'>".$js_inject_script."</script>"; | |
| 218 | - $do_default = false; | |
| 219 | - } | |
| 220 | - | |
| 221 | - // server side selector provided (see simple_html_dom selectors http://simplehtmldom.sourceforge.net/manual.htm) | |
| 222 | - // basically it's CSS selectors like in jQuery | |
| 223 | - } else{ | |
| 224 | - | |
| 225 | - require_once('simple_html_dom.php'); | |
| 226 | - | |
| 227 | - $html_doc = str_get_html($content); | |
| 228 | - $target_location = $html_doc->find($location,0); | |
| 229 | - | |
| 230 | - // if the location was found within the html content | |
| 231 | - if (isset($target_location) && is_object($target_location)){ | |
| 232 | - | |
| 233 | - // adding taboola content AFTER the target location | |
| 234 | - $target_location->outertext = $target_location->outertext.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING); | |
| 235 | - $content = $html_doc; | |
| 236 | - $do_default = false; | |
| 237 | - } | |
| 238 | - } | |
| 239 | - } | |
| 240 | - | |
| 241 | - // Default - add to the end of the content | |
| 242 | - if ($do_default){ | |
| 243 | - $content = $content.$this->format_taboola_content($taboola_content,TABOOLA_CONTENT_FORMAT_STRING); | |
| 244 | - } | |
| 245 | - | |
| 246 | - return $content; | |
| 247 | - } | |
| 248 | - | |
| 249 | - | |
| 250 | 166 | function admin_generate_menu(){ |
| 251 | 167 | global $current_user; |
| 252 | 168 | add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110); |
| 253 | 169 | } |
| @@ -265,11 +181,8 @@ | ||
| 265 | 181 | ($_POST['second_bc_enabled'] == 'on' && trim($_POST['second_bc_widget_id']) == '') |
| 266 | 182 | ){ |
| 267 | 183 | $taboola_errors[] = "Please add a 'Widget ID' in order to apply changes to your widgets"; |
| 268 | 184 | } |
| 269 | - if (trim($_POST['location_string']) != '' && !$this->is_location_string_valid($_POST['location_string'])){ | |
| 270 | - $taboola_errors[] = "Location string not valid, please contact your Taboola account manager to get a valid location string"; | |
| 271 | - } | |
| 272 | 185 | if(count($taboola_errors) == 0){ |
| 273 | 186 | |
| 274 | 187 | $data = array( |
| 275 | 188 | "publisher_id" => trim($_POST['publisher_id']), |
| @@ -276,11 +189,9 @@ | ||
| 276 | 189 | "first_bc_enabled" => $_POST['first_bc_enabled'] == 'on' ? true : false, |
| 277 | 190 | "first_bc_widget_id" => trim($_POST['first_bc_widget_id']), |
| 278 | 191 | "second_bc_enabled" => $_POST['second_bc_enabled'] == 'on' ? true : false, |
| 279 | 192 | "second_bc_widget_id" => trim($_POST['second_bc_widget_id']), |
| 280 | - "location_string" => trim($_POST['location_string']) | |
| 281 | 193 | ); |
| 282 | - | |
| 283 | 194 | //var_dump($settings); |
| 284 | 195 | if($settings == NULL){ |
| 285 | 196 | $wpdb->insert($this->tbl_taboola_settings, $data, null, null); |
| 286 | 197 | } else { |
| @@ -292,13 +203,8 @@ | ||
| 292 | 203 | |
| 293 | 204 | |
| 294 | 205 | include_once('settings.php'); |
| 295 | 206 | } |
| 296 | - | |
| 297 | - function is_location_string_valid($location_string){ | |
| 298 | - // TODO:: validate the location string | |
| 299 | - return true; | |
| 300 | - } | |
| 301 | 207 | function activate(){ |
| 302 | 208 | global $wpdb; |
| 303 | 209 | |
| 304 | 210 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| @@ -305,9 +211,9 @@ | ||
| 305 | 211 | |
| 306 | 212 | $settings_table = $this->tbl_taboola_settings; |
| 307 | 213 | |
| 308 | 214 | //check mysql version |
| 309 | - 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', '>=')) { | |
| 310 | 216 | if (!empty($wpdb->charset)) |
| 311 | 217 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
| 312 | 218 | if (!empty($wpdb->collate)) |
| 313 | 219 | $charset_collate .= " COLLATE $wpdb->collate"; |
| @@ -323,18 +229,17 @@ | ||
| 323 | 229 | `first_bc_custom_css` TEXT DEFAULT NULL, |
| 324 | 230 | `second_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE, |
| 325 | 231 | `second_bc_widget_id` VARCHAR(255) DEFAULT NULL, |
| 326 | 232 | `second_bc_custom_css` TEXT DEFAULT NULL, |
| 327 | - `location_string` TEXT DEFAULT NULL, | |
| 328 | 233 | PRIMARY KEY (`id`) |
| 329 | 234 | )" . $charset_collate . ";"; |
| 330 | 235 | |
| 331 | - // creat/update the table | |
| 236 | + //check if table exists | |
| 237 | + if ($wpdb->get_var("show tables like '" . $settings_table . "'") != $settings_table) { | |
| 332 | 238 | dbDelta($sql_table_settings); |
| 239 | + } | |
| 333 | 240 | } |
| 334 | 241 | } |
| 335 | 242 | } |
| 336 | 243 | |
| 337 | 244 | global $taboolaWP; |
| 338 | -$taboolaWP = new TaboolaWP(); | |
| 339 | - | |
| 340 | -// | |
| 245 | +$taboolaWP = new TaboolaWP(); | |