PluginProbe
Taboola / 1.0
Taboola v1.0
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 +31 -86 1.0.21.0 View file →
@@ -2,9 +2,9 @@
2 2 /**
3 3 * Plugin Name: Taboola
4 4 * Plugin URI: http://taboola.com
5 5 * Description: Taboola
6 - * Version: 1.0.2
6 + * Version: 1.0
7 7 * Author: Taboola
8 8 */
9 9
10 10 include_once('widget.php');
@@ -11,23 +11,18 @@
11 11
12 12 if (!class_exists('TaboolaWP')) {
13 13 class TaboolaWP
14 14 {
15 +
15 16 //save internal data
16 17 public $data = array();
17 - public $_is_widget_on_page;
18 - public $_is_head_script_loaded = false;
19 18
20 19 function TaboolaWP()
21 20 {
22 21 global $wpdb;
23 -
24 22 //initialize plugin constant
25 23 DEFINE('TaboolaWP', true);
26 24
27 - $this->_is_widget_on_page = false;
28 - $this->_is_head_script_loaded = false;
29 -
30 25 $this->plugin_name = plugin_basename(__FILE__);
31 26 $this->plugin_directory = plugin_dir_path(__FILE__);
32 27 $this->plugin_url = trailingslashit(WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__)));
33 28 $this->settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
@@ -36,15 +31,16 @@
36 31
37 32 //activation function
38 33 register_activation_hook($this->plugin_name, array(&$this, 'activate'));
39 34
40 - // Enable sidebar widgets
41 - if($this->settings != NULL && !empty($this->settings->publisher_id)){
35 +
36 + // disable sidebar widget
37 + /*if($this->settings != NULL && !empty($this->settings->publisher_id)){
42 38 //register Taboola widget
43 39 add_action('widgets_init',
44 40 create_function('', 'return register_widget("WP_Widget_Taboola");')
45 41 );
46 - }
42 + }*/
47 43
48 44 if (is_admin()) {
49 45 //add menu for plugin
50 46 add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
@@ -50,18 +46,14 @@
50 46 add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
51 47 add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
52 48 } else {
53 49 if($this->settings != NULL){
54 - add_action('wp_head', array(&$this, 'taboola_header_loader_inject'));
50 + add_action('wp_head', array(&$this, 'taboola_header_loader_js'));
55 51 add_action('wp_footer', array(&$this, 'taboola_footer_loader_js'));
56 52 add_filter('the_content', array(&$this, 'load_taboola_content'));
57 53 }
58 54 }
59 55 }
60 -
61 -
62 -
63 -
64 56 function plugin_action_links($links, $file) {
65 57 static $this_plugin;
66 58
67 59 if (!$this_plugin) {
@@ -74,90 +66,41 @@
74 66 }
75 67
76 68 return $links;
77 69 }
78 -
79 - private function should_show_content_widget(){
80 - $retVal = ((trim($this->settings->publisher_id) != '') && is_single() && $this->settings->first_bc_enabled && trim($this->settings->first_bc_widget_id) != '');
81 - return $retVal;
82 - }
83 -
84 - private function should_show_sidebar_widget(){
85 - $retVal = ((trim($this->settings->publisher_id) != '') && is_active_widget( false, false, TABOOLA_WIDGET_BASE_ID, true ));
86 - return $retVal;
87 - }
88 -
89 - // Determine if a taboola widget should be added somewhere on the current page (content or sidebar)
90 - function is_widget_on_page(){
91 - return $this->should_show_content_widget() || $this->should_show_sidebar_widget();
92 - }
93 -
94 - function get_page_type(){
95 -
96 - $page_type='article';
97 - if (is_front_page()){
98 - $page_type='home';
99 - }else if (is_category() || is_archive() || is_search()){
100 - $page_type='category';
101 - }
102 - return $page_type;
103 - }
104 -
105 - // return the head loader script
106 70 function taboola_header_loader_js() {
107 - $head_string = "";
108 -
109 - // Only adding Script1 if a widget is going to be placed on the page.
110 - if ($this->is_widget_on_page()){
111 -
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);
114 -
115 - $head_string = '<script type="text/javascript">'.$script1_content.'</script>';
116 - }
117 -
118 - return $head_string;
71 + $script1_content = str_replace('{{PUBLISHER_ID}}', $this->settings->publisher_id, file_get_contents($this->plugin_directory.'js/script1.js'));
72 + echo '<script type="text/javascript">'.$script1_content.'</script>';
119 73 }
120 -
121 -
122 - // This function is used for the hook action, injects the header content to the <head> tag.
123 - function taboola_header_loader_inject(){
124 -
125 - echo $this->taboola_header_loader_js();
126 - }
127 -
128 -
129 74 function taboola_footer_loader_js() {
130 -
131 - // Only adding Script1 if a widget is going to be placed on the page.
132 - if ( $this->is_widget_on_page() ){
133 - $script3_content = file_get_contents($this->plugin_directory.'js/script3.js');
134 - echo '<script type="text/javascript">'.$script3_content.'</script>';
135 - }
75 + $script3_content = file_get_contents($this->plugin_directory.'js/script3.js');
76 + echo '<script type="text/javascript">'.$script3_content.'</script>';
136 77 }
137 78
138 79 function load_taboola_content($content)
139 80 {
81 + if (trim($this->settings->publisher_id) == ''){
82 + return $content;
83 + }
84 + if (is_single()) {
140 85
141 - if ($this->should_show_content_widget()){
86 + if($this->settings->first_bc_enabled && trim($this->settings->first_bc_widget_id) != ''){
87 + $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->first_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
88 + $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article', $script2_content);
89 + $script2_content = str_replace('{{PLACEMENT}}', 'below-article', $script2_content);
142 90
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);
146 -
147 - $content = $content .
148 - '<div id="taboola-below-article"></div>' .
149 - '<script type="text/javascript">'.$script2_content.'</script>';
150 -
151 - // Adding the 2nd widget if needed
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);
156 -
157 91 $content = $content .
158 - '<div id="taboola-below-article-second"></div>' .
92 + '<div id="taboola-below-article" style="'.$this->settings->first_bc_custom_css.'"></div>' .
159 93 '<script type="text/javascript">'.$script2_content.'</script>';
94 + if($this->settings->second_bc_enabled && trim($this->settings->second_bc_widget_id) != ''){
95 + $script2_content = str_replace('{{WIDGET_ID}}', $this->settings->second_bc_widget_id, file_get_contents($this->plugin_directory.'js/script2.js'));
96 + $script2_content = str_replace('{{CONTAINER}}', 'taboola-below-article-second', $script2_content);
97 + $script2_content = str_replace('{{PLACEMENT}}', 'below-article-2nd', $script2_content);
98 +
99 + $content = $content .
100 + '<div id="taboola-below-article-second" style="'.$this->settings->second_bc_custom_css.'"></div>' .
101 + '<script type="text/javascript">'.$script2_content.'</script>';
102 + }
160 103 }
161 104 }
162 105
163 106 return $content;
@@ -187,10 +130,12 @@
187 130 $data = array(
188 131 "publisher_id" => trim($_POST['publisher_id']),
189 132 "first_bc_enabled" => $_POST['first_bc_enabled'] == 'on' ? true : false,
190 133 "first_bc_widget_id" => trim($_POST['first_bc_widget_id']),
134 + "first_bc_custom_css" => trim($_POST['first_bc_custom_css']),
191 135 "second_bc_enabled" => $_POST['second_bc_enabled'] == 'on' ? true : false,
192 136 "second_bc_widget_id" => trim($_POST['second_bc_widget_id']),
137 + "second_bc_custom_css" => trim($_POST['second_bc_custom_css'])
193 138 );
194 139 //var_dump($settings);
195 140 if($settings == NULL){
196 141 $wpdb->insert($this->tbl_taboola_settings, $data, null, null);