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
taboola / taboola_widget.php

taboola_widget.php in Taboola 1.0, at taboola_widget.php

190 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Taboola
4 * Plugin URI: http://taboola.com
5 * Description: Taboola
6 * Version: 1.0
7 * Author: Taboola
8 */
9
10 include_once('widget.php');
11
12 if (!class_exists('TaboolaWP')) {
13 class TaboolaWP
14 {
15
16 //save internal data
17 public $data = array();
18
19 function TaboolaWP()
20 {
21 global $wpdb;
22 //initialize plugin constant
23 DEFINE('TaboolaWP', true);
24
25 $this->plugin_name = plugin_basename(__FILE__);
26 $this->plugin_directory = plugin_dir_path(__FILE__);
27 $this->plugin_url = trailingslashit(WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__)));
28 $this->settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
29
30 $this->tbl_taboola_settings = $wpdb->prefix . '_taboola_settings';
31
32 //activation function
33 register_activation_hook($this->plugin_name, array(&$this, 'activate'));
34
35
36 // disable sidebar widget
37 /*if($this->settings != NULL && !empty($this->settings->publisher_id)){
38 //register Taboola widget
39 add_action('widgets_init',
40 create_function('', 'return register_widget("WP_Widget_Taboola");')
41 );
42 }*/
43
44 if (is_admin()) {
45 //add menu for plugin
46 add_action( 'admin_menu', array(&$this, 'admin_generate_menu') );
47 add_filter('plugin_action_links', array(&$this, 'plugin_action_links'), 10, 2 );
48 } else {
49 if($this->settings != NULL){
50 add_action('wp_head', array(&$this, 'taboola_header_loader_js'));
51 add_action('wp_footer', array(&$this, 'taboola_footer_loader_js'));
52 add_filter('the_content', array(&$this, 'load_taboola_content'));
53 }
54 }
55 }
56 function plugin_action_links($links, $file) {
57 static $this_plugin;
58
59 if (!$this_plugin) {
60 $this_plugin = plugin_basename(__FILE__);
61 }
62
63 if ($file == $this_plugin) {
64 $settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=taboola_widget">Settings</a>';
65 array_unshift($links, $settings_link);
66 }
67
68 return $links;
69 }
70 function taboola_header_loader_js() {
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>';
73 }
74 function taboola_footer_loader_js() {
75 $script3_content = file_get_contents($this->plugin_directory.'js/script3.js');
76 echo '<script type="text/javascript">'.$script3_content.'</script>';
77 }
78
79 function load_taboola_content($content)
80 {
81 if (trim($this->settings->publisher_id) == ''){
82 return $content;
83 }
84 if (is_single()) {
85
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);
90
91 $content = $content .
92 '<div id="taboola-below-article" style="'.$this->settings->first_bc_custom_css.'"></div>' .
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 }
103 }
104 }
105
106 return $content;
107 }
108
109 function admin_generate_menu(){
110 global $current_user;
111 add_menu_page('Taboola', 'Taboola', 'manage_options', 'taboola_widget', array(&$this, 'admin_taboola_settings'), $this->plugin_url.'img/taboola_icon.png', 110);
112 }
113
114 function admin_taboola_settings(){
115 global $wpdb;
116 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
117 $taboola_errors = array();
118 if($_SERVER['REQUEST_METHOD'] == 'POST'){
119
120 if(trim($_POST['publisher_id']) == ''){
121 $taboola_errors[] = "Please add a 'Publisher ID' in order to apply changes to your widgets";
122 }
123 if(($_POST['first_bc_enabled'] == 'on' && trim($_POST['first_bc_widget_id']) == '') ||
124 ($_POST['second_bc_enabled'] == 'on' && trim($_POST['second_bc_widget_id']) == '')
125 ){
126 $taboola_errors[] = "Please add a 'Widget ID' in order to apply changes to your widgets";
127 }
128 if(count($taboola_errors) == 0){
129
130 $data = array(
131 "publisher_id" => trim($_POST['publisher_id']),
132 "first_bc_enabled" => $_POST['first_bc_enabled'] == 'on' ? true : false,
133 "first_bc_widget_id" => trim($_POST['first_bc_widget_id']),
134 "first_bc_custom_css" => trim($_POST['first_bc_custom_css']),
135 "second_bc_enabled" => $_POST['second_bc_enabled'] == 'on' ? true : false,
136 "second_bc_widget_id" => trim($_POST['second_bc_widget_id']),
137 "second_bc_custom_css" => trim($_POST['second_bc_custom_css'])
138 );
139 //var_dump($settings);
140 if($settings == NULL){
141 $wpdb->insert($this->tbl_taboola_settings, $data, null, null);
142 } else {
143 $wpdb->update($this->tbl_taboola_settings, $data, array('id' => $settings->id));
144 }
145 }
146 $settings = $wpdb->get_row("select * from ".$wpdb->prefix."_taboola_settings limit 1");
147 }
148
149
150 include_once('settings.php');
151 }
152 function activate(){
153 global $wpdb;
154
155 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
156
157 $settings_table = $this->tbl_taboola_settings;
158
159 //check mysql version
160 if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
161 if (!empty($wpdb->charset))
162 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
163 if (!empty($wpdb->collate))
164 $charset_collate .= " COLLATE $wpdb->collate";
165 }
166
167 //settings table structure
168 $sql_table_settings = "
169 CREATE TABLE `" . $wpdb->prefix . "_taboola_settings` (
170 `id` INT NOT NULL AUTO_INCREMENT ,
171 `publisher_id` VARCHAR(255) DEFAULT NULL,
172 `first_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
173 `first_bc_widget_id` VARCHAR(255) DEFAULT NULL,
174 `first_bc_custom_css` TEXT DEFAULT NULL,
175 `second_bc_enabled` TINYINT(1) NOT NULL DEFAULT FALSE,
176 `second_bc_widget_id` VARCHAR(255) DEFAULT NULL,
177 `second_bc_custom_css` TEXT DEFAULT NULL,
178 PRIMARY KEY (`id`)
179 )" . $charset_collate . ";";
180
181 //check if table exists
182 if ($wpdb->get_var("show tables like '" . $settings_table . "'") != $settings_table) {
183 dbDelta($sql_table_settings);
184 }
185 }
186 }
187 }
188
189 global $taboolaWP;
190 $taboolaWP = new TaboolaWP();