Version Description
- Fixed bug with not showing links on some pages
- Increasing the Plugin security
- Fixed the issue with errors on site after Plugin installation
Download this release
Release Info
Developer | MageNet |
Plugin | Website Monetization by MageNet |
Version | 1.0.16 |
Comparing to | |
See all releases |
Code changes from version 1.0.15 to 1.0.16
- MagenetLinkAutoinstall.php +260 -0
- monetization-by-magenet.php +4 -257
- readme.txt +5 -0
- uninstall.php +10 -0
MagenetLinkAutoinstall.php
ADDED
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if(!function_exists('get_plugin_data'))
|
3 |
+
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
4 |
+
$plugin_data = get_plugin_data(plugin_file);
|
5 |
+
|
6 |
+
define("magenet_plugin_version", $plugin_data['Version']);
|
7 |
+
if (!class_exists('MagenetLinkAutoinstall')) {
|
8 |
+
class MagenetLinkAutoinstall {
|
9 |
+
|
10 |
+
private $cache_time = 3600;
|
11 |
+
private $api_host = "http://api.magenet.com";
|
12 |
+
private $api_get = "/wordpress/get";
|
13 |
+
private $api_test = "/wordpress/test";
|
14 |
+
private $api_activate = "/wordpress/activate";
|
15 |
+
private $api_deactivate = "/wordpress/deactivate";
|
16 |
+
private $api_uninstall = "/wordpress/uninstall";
|
17 |
+
private $is_active_seo_plugin = false;
|
18 |
+
private $key = false;
|
19 |
+
private $link_shown = 0;
|
20 |
+
private $lastError = 0;
|
21 |
+
|
22 |
+
public function MagenetLinkAutoinstall() {
|
23 |
+
global $wpdb;
|
24 |
+
define('MagenetLinkAutoinstall', true);
|
25 |
+
$this->plugin_name = plugin_basename(plugin_file);
|
26 |
+
$this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(plugin_file)));
|
27 |
+
$this->tbl_magenet_links = $wpdb->prefix . 'magenet_links';
|
28 |
+
|
29 |
+
register_activation_hook($this->plugin_name, array(&$this, 'activate'));
|
30 |
+
register_deactivation_hook($this->plugin_name, array(&$this, 'deactivate'));
|
31 |
+
//register_uninstall_hook($this->plugin_name, array(&$this, 'uninstall'));
|
32 |
+
|
33 |
+
if (is_admin()) {
|
34 |
+
add_action('wp_print_scripts', array(&$this, 'admin_load_scripts'));
|
35 |
+
add_action('wp_print_styles', array(&$this, 'admin_load_styles'));
|
36 |
+
add_action('admin_menu', array(&$this, 'admin_generate_menu'));
|
37 |
+
} else {
|
38 |
+
if (!has_filter('the_content', array(&$this, 'add_magenet_links'))) {
|
39 |
+
add_filter('the_content', array(&$this, 'add_magenet_links'));
|
40 |
+
}
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
public function getSeoPluginParam() {
|
45 |
+
if (!$this->is_active_seo_plugin) {
|
46 |
+
$this->is_active_seo_plugin = get_option("magenet_is_active_seo_plugin");
|
47 |
+
}
|
48 |
+
return $this->is_active_seo_plugin;
|
49 |
+
}
|
50 |
+
public function setSeoPluginParam($seoparam) {
|
51 |
+
update_option("magenet_is_active_seo_plugin", $seoparam);
|
52 |
+
$this->is_active_seo_plugin = $seoparam;
|
53 |
+
}
|
54 |
+
|
55 |
+
public function getKey() {
|
56 |
+
if (!$this->key) {
|
57 |
+
$this->key = get_option("magenet_links_autoinstall_key");
|
58 |
+
}
|
59 |
+
return $this->key;
|
60 |
+
}
|
61 |
+
public function setKey($key) {
|
62 |
+
update_option("magenet_links_autoinstall_key", $key);
|
63 |
+
$this->key = $key;
|
64 |
+
}
|
65 |
+
|
66 |
+
public function activate() {
|
67 |
+
global $wpdb;
|
68 |
+
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
|
69 |
+
|
70 |
+
$table = $this->tbl_magenet_links;
|
71 |
+
if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
|
72 |
+
if (!empty($wpdb->charset))
|
73 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
74 |
+
if (!empty($wpdb->collate))
|
75 |
+
$charset_collate .= " COLLATE $wpdb->collate";
|
76 |
+
}
|
77 |
+
|
78 |
+
$sql_table_magenet_links = "
|
79 |
+
CREATE TABLE `".$wpdb->prefix."magenet_links` (
|
80 |
+
`ID` INT(10) UNSIGNED NULL AUTO_INCREMENT,
|
81 |
+
`page_url` TEXT NOT NULL,
|
82 |
+
`link_html` TEXT NOT NULL,
|
83 |
+
PRIMARY KEY (`ID`)
|
84 |
+
)".$charset_collate.";";
|
85 |
+
$sql_add_index = "CREATE INDEX page_url ON `".$wpdb->prefix."magenet_links` (page_url(100));";
|
86 |
+
|
87 |
+
if ( $wpdb->get_var("show tables like '".$table."'") != $table ) {
|
88 |
+
dbDelta($sql_table_magenet_links);
|
89 |
+
$wpdb->query($sql_add_index);
|
90 |
+
}
|
91 |
+
$result = $this->sendRequest($this->api_host.$this->api_activate, $this->getKey());
|
92 |
+
}
|
93 |
+
|
94 |
+
public function deactivate() {
|
95 |
+
$result = $this->sendRequest($this->api_host.$this->api_deactivate, $this->getKey());
|
96 |
+
return true;
|
97 |
+
}
|
98 |
+
|
99 |
+
public function uninstall() {
|
100 |
+
global $wpdb;
|
101 |
+
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}magenet_links");
|
102 |
+
$result = $this->sendRequest($this->api_host.$this->api_uninstall, $this->getKey());
|
103 |
+
}
|
104 |
+
|
105 |
+
public function admin_load_scripts() {
|
106 |
+
wp_register_script('magenetLinkAutoinstallAdminJs', $this->plugin_url . 'js/admin-scripts.js' );
|
107 |
+
wp_enqueue_script('magenetLinkAutoinstallAdminJs');
|
108 |
+
}
|
109 |
+
|
110 |
+
public function admin_load_styles() {
|
111 |
+
wp_register_style('magenetLinkAutoinstallAdminCss', $this->plugin_url . 'css/admin-style.css' );
|
112 |
+
wp_enqueue_style('magenetLinkAutoinstallAdminCss');
|
113 |
+
}
|
114 |
+
|
115 |
+
public function admin_generate_menu() {
|
116 |
+
add_options_page('Website Monetization by MageNet', 'Website Monetization by MageNet', 'manage_options', 'magenet-links-settings', array(&$this, 'admin_magenet_settings'));
|
117 |
+
}
|
118 |
+
|
119 |
+
public function add_magenet_links($content) {
|
120 |
+
global $post;
|
121 |
+
$link_count = 1;
|
122 |
+
$is_active_plugin = $this->getSeoPluginParam();
|
123 |
+
if($is_active_plugin=='on' && ($post->post_type == 'page' OR $post->post_type == 'post')) $link_count = 2;
|
124 |
+
|
125 |
+
$this->link_shown++;
|
126 |
+
if($this->link_shown <= $link_count) {
|
127 |
+
global $wpdb;
|
128 |
+
$link_data = $this->getLinks();
|
129 |
+
$content .= '<div class="mads-block">';
|
130 |
+
if (is_array($link_data) && count($link_data) > 0) {
|
131 |
+
foreach($link_data as $link) {
|
132 |
+
$content .= "\n".$link['link_html'];
|
133 |
+
}
|
134 |
+
}
|
135 |
+
$content .='</div>';
|
136 |
+
}
|
137 |
+
|
138 |
+
return $content;
|
139 |
+
}
|
140 |
+
|
141 |
+
public function admin_magenet_settings() {
|
142 |
+
global $wpdb;
|
143 |
+
$magenet_key = $this->getKey();
|
144 |
+
$is_active_seo_plugin = $this->getSeoPluginParam();
|
145 |
+
$plugin_result_text = '';
|
146 |
+
if(isset($_POST['seoplugin']) && !empty($_POST['seoplugin'])) {
|
147 |
+
if (isset($_POST['seoparam']) && !empty($_POST['seoparam'])) {
|
148 |
+
$this->setSeoPluginParam($_POST['seoparam']);
|
149 |
+
} else {
|
150 |
+
$this->setSeoPluginParam('off');
|
151 |
+
}
|
152 |
+
$is_active_seo_plugin = $this->getSeoPluginParam();
|
153 |
+
$plugin_result_text = "<span style=\"color: #009900;\">Saved</span>";
|
154 |
+
}
|
155 |
+
if (isset($_POST['key']) && !empty($_POST['key'])) {
|
156 |
+
$magenet_key = $_POST['key'];
|
157 |
+
$test_key = $this->testKey($magenet_key);
|
158 |
+
if ($test_key) {
|
159 |
+
$this->setKey($magenet_key);
|
160 |
+
$result_text = "<span style=\"color: #009900;\">Key confirmed</span>";
|
161 |
+
} else {
|
162 |
+
if($this -> lastError == 0) {
|
163 |
+
$result_text = "<span style=\"color: #ca2222;\">Incorrect Key. Please try again</span>";
|
164 |
+
} else {
|
165 |
+
$result_text = "<span style=\"color: #ca2222;\">Temporary Error (".$this -> lastError."). Please try again later. If you continue to see this error over an extended period of time, <a href=\"http://www.magenet.com/contact-us/\" target=\"_blank\">please let us know</a> so we can look into the issue.</span>";
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
if (isset($_POST['update_data']) && $_POST['update_data'] == 1) {
|
170 |
+
$result = $this->sendRequest($this->api_host.$this->api_get, $magenet_key);
|
171 |
+
if ($result) {
|
172 |
+
$wpdb->query("DELETE FROM {$this->tbl_magenet_links} WHERE 1");
|
173 |
+
$new_links = json_decode($result, TRUE);
|
174 |
+
if (count($new_links)>0)
|
175 |
+
foreach($new_links as $new_link) {
|
176 |
+
if (isset($new_link['page_url']) && isset($new_link['issue_html'])) {
|
177 |
+
$wpdb->query($wpdb->prepare("INSERT INTO {$this->tbl_magenet_links}(page_url, link_html) VALUES (%s, %s)", $new_link['page_url'], $new_link['issue_html']));
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
update_option("magenet_links_last_update", time());
|
182 |
+
$result_update_text = "<span style=\"color: #009900;\">Ads have been updated.</span>";
|
183 |
+
}
|
184 |
+
$link_data = $wpdb->get_results("SELECT * FROM `" . $this->tbl_magenet_links . "`", ARRAY_A);
|
185 |
+
include_once('view-settings.php');
|
186 |
+
}
|
187 |
+
|
188 |
+
public function testKey($key) {
|
189 |
+
$result = $this->sendRequest($this->api_host.$this->api_test, $key);
|
190 |
+
return $result === "1";
|
191 |
+
}
|
192 |
+
|
193 |
+
public function getLinks() {
|
194 |
+
global $wpdb;
|
195 |
+
$key = $this->getKey();
|
196 |
+
if ($key) {
|
197 |
+
$last_update_time = get_option("magenet_links_last_update");
|
198 |
+
if ($last_update_time + $this->cache_time < time()) {
|
199 |
+
$result = $this->sendRequest($this->api_host.$this->api_get, $key);
|
200 |
+
if ($result) {
|
201 |
+
$wpdb->query("DELETE FROM {$this->tbl_magenet_links} WHERE 1");
|
202 |
+
$new_links = json_decode($result, TRUE);
|
203 |
+
if (count($new_links)>0)
|
204 |
+
foreach($new_links as $new_link) {
|
205 |
+
if (isset($new_link['page_url']) && isset($new_link['issue_html'])) {
|
206 |
+
$wpdb->query($wpdb->prepare("INSERT INTO {$this->tbl_magenet_links}(page_url, link_html) VALUES (%s, %s)", $new_link['page_url'], $new_link['issue_html']));
|
207 |
+
}
|
208 |
+
}
|
209 |
+
}
|
210 |
+
update_option("magenet_links_last_update", time());
|
211 |
+
}
|
212 |
+
$page_url = get_permalink();
|
213 |
+
|
214 |
+
$check_page_without_last_slash_query = "";
|
215 |
+
if($page_url[strlen($page_url)-1] == "/") {
|
216 |
+
$check_page_without_last_slash_query = " OR page_url='" . substr($page_url, 0, -1) . "'";
|
217 |
+
}
|
218 |
+
$link_data = $wpdb->get_results("SELECT * FROM `" . $this->tbl_magenet_links . "` WHERE page_url='". $page_url ."'" . $check_page_without_last_slash_query, ARRAY_A);
|
219 |
+
return $link_data;
|
220 |
+
}
|
221 |
+
return false;
|
222 |
+
}
|
223 |
+
|
224 |
+
public function sendRequest($url, $key) {
|
225 |
+
$siteurl = get_option("siteurl");
|
226 |
+
$params = http_build_query(array(
|
227 |
+
'url' => $siteurl,
|
228 |
+
'key' => $key,
|
229 |
+
'version' => magenet_plugin_version
|
230 |
+
));
|
231 |
+
if (function_exists('curl_init') && function_exists('curl_exec')) {
|
232 |
+
$ch = curl_init();
|
233 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
234 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
235 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
236 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
237 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
238 |
+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
239 |
+
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
|
240 |
+
curl_setopt($ch, CURLOPT_POST, TRUE);
|
241 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
242 |
+
$curl_result = curl_exec($ch);
|
243 |
+
|
244 |
+
$this -> lastError = curl_errno($ch);
|
245 |
+
if (!$this -> lastError) {
|
246 |
+
$result = $curl_result;
|
247 |
+
} else {
|
248 |
+
$result = false;
|
249 |
+
}
|
250 |
+
curl_close($ch);
|
251 |
+
} else {
|
252 |
+
$url = $url."?".$params;
|
253 |
+
$data = file_get_contents($url, false);
|
254 |
+
$result = $data;
|
255 |
+
}
|
256 |
+
return $result;
|
257 |
+
}
|
258 |
+
}
|
259 |
+
}
|
260 |
+
?>
|
monetization-by-magenet.php
CHANGED
@@ -2,18 +2,13 @@
|
|
2 |
/*
|
3 |
Plugin Name: Website Monetization by MageNet
|
4 |
Description: Website Monetization by MageNet allows you to sell contextual ads from your pages automatically and receive payments with PayPal. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://magenet.com" target="_blank">Sign up for a MageNet Key</a>, and 3) Go to Settings > "Website Monetization by MageNet" configuration page, and save your MageNet Key.
|
5 |
-
Version: 1.0.
|
6 |
Author: MageNet.com
|
7 |
Author URI: http://magenet.com
|
8 |
*/
|
9 |
-
|
10 |
-
if(!function_exists('get_plugin_data'))
|
11 |
-
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
12 |
-
$plugin_data = get_plugin_data(__FILE__);
|
13 |
-
|
14 |
-
define("plugin_version", $plugin_data['Version']);
|
15 |
// Stop direct call
|
16 |
-
if(preg_match('#' . basename(
|
17 |
|
18 |
if (!function_exists('json_decode')) {
|
19 |
function json_decode($json, $assoc) {
|
@@ -23,256 +18,8 @@ if (!function_exists('json_decode')) {
|
|
23 |
return $jsonO->decode($json);
|
24 |
}
|
25 |
}
|
26 |
-
|
27 |
-
if (!class_exists('MagenetLinkAutoinstall')) {
|
28 |
-
class MagenetLinkAutoinstall {
|
29 |
-
|
30 |
-
private $cache_time = 3600;
|
31 |
-
private $api_host = "http://api.magenet.com";
|
32 |
-
private $api_get = "/wordpress/get";
|
33 |
-
private $api_test = "/wordpress/test";
|
34 |
-
private $is_active_seo_plugin = false;
|
35 |
-
private $key = false;
|
36 |
-
private $link_shown = 0;
|
37 |
-
private $lastError = 0;
|
38 |
-
|
39 |
-
public function MagenetLinkAutoinstall() {
|
40 |
-
global $wpdb;
|
41 |
-
define('MagenetLinkAutoinstall', true);
|
42 |
-
$this->plugin_name = plugin_basename(__FILE__);
|
43 |
-
$this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
|
44 |
-
$this->tbl_magenet_links = $wpdb->prefix . 'magenet_links';
|
45 |
-
|
46 |
-
register_activation_hook($this->plugin_name, array(&$this, 'activate'));
|
47 |
-
register_deactivation_hook($this->plugin_name, array(&$this, 'deactivate'));
|
48 |
-
register_uninstall_hook($this->plugin_name, array(&$this, 'uninstall'));
|
49 |
-
|
50 |
-
if (is_admin()) {
|
51 |
-
add_action('wp_print_scripts', array(&$this, 'admin_load_scripts'));
|
52 |
-
add_action('wp_print_styles', array(&$this, 'admin_load_styles'));
|
53 |
-
add_action('admin_menu', array(&$this, 'admin_generate_menu'));
|
54 |
-
} else {
|
55 |
-
if (!has_filter('the_content', array(&$this, 'add_magenet_links'))) {
|
56 |
-
add_filter('the_content', array(&$this, 'add_magenet_links'));
|
57 |
-
}
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
-
public function getSeoPluginParam() {
|
62 |
-
if (!$this->is_active_seo_plugin) {
|
63 |
-
$this->is_active_seo_plugin = get_option("magenet_is_active_seo_plugin");
|
64 |
-
}
|
65 |
-
return $this->is_active_seo_plugin;
|
66 |
-
}
|
67 |
-
public function setSeoPluginParam($seoparam) {
|
68 |
-
update_option("magenet_is_active_seo_plugin", $seoparam);
|
69 |
-
$this->is_active_seo_plugin = $seoparam;
|
70 |
-
}
|
71 |
-
|
72 |
-
public function getKey() {
|
73 |
-
if (!$this->key) {
|
74 |
-
$this->key = get_option("magenet_links_autoinstall_key");
|
75 |
-
}
|
76 |
-
return $this->key;
|
77 |
-
}
|
78 |
-
public function setKey($key) {
|
79 |
-
update_option("magenet_links_autoinstall_key", $key);
|
80 |
-
$this->key = $key;
|
81 |
-
}
|
82 |
-
|
83 |
-
public function activate() {
|
84 |
-
global $wpdb;
|
85 |
-
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
|
86 |
-
|
87 |
-
$table = $this->tbl_magenet_links;
|
88 |
-
if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
|
89 |
-
if (!empty($wpdb->charset))
|
90 |
-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
91 |
-
if (!empty($wpdb->collate))
|
92 |
-
$charset_collate .= " COLLATE $wpdb->collate";
|
93 |
-
}
|
94 |
-
|
95 |
-
$sql_table_magenet_links = "
|
96 |
-
CREATE TABLE `".$wpdb->prefix."magenet_links` (
|
97 |
-
`ID` INT(10) UNSIGNED NULL AUTO_INCREMENT,
|
98 |
-
`page_url` TEXT NOT NULL,
|
99 |
-
`link_html` TEXT NOT NULL,
|
100 |
-
PRIMARY KEY (`ID`)
|
101 |
-
)".$charset_collate.";";
|
102 |
-
$sql_add_index = "CREATE INDEX page_url ON `".$wpdb->prefix."magenet_links` (page_url(100));";
|
103 |
-
|
104 |
-
if ( $wpdb->get_var("show tables like '".$table."'") != $table ) {
|
105 |
-
dbDelta($sql_table_magenet_links);
|
106 |
-
$wpdb->query($sql_add_index);
|
107 |
-
}
|
108 |
-
}
|
109 |
-
|
110 |
-
public function deactivate() {
|
111 |
-
return true;
|
112 |
-
}
|
113 |
-
|
114 |
-
public function uninstall() {
|
115 |
-
global $wpdb;
|
116 |
-
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}magenet_links");
|
117 |
-
}
|
118 |
-
|
119 |
-
public function admin_load_scripts() {
|
120 |
-
wp_register_script('magenetLinkAutoinstallAdminJs', $this->plugin_url . 'js/admin-scripts.js' );
|
121 |
-
wp_enqueue_script('magenetLinkAutoinstallAdminJs');
|
122 |
-
}
|
123 |
-
|
124 |
-
public function admin_load_styles() {
|
125 |
-
wp_register_style('magenetLinkAutoinstallAdminCss', $this->plugin_url . 'css/admin-style.css' );
|
126 |
-
wp_enqueue_style('magenetLinkAutoinstallAdminCss');
|
127 |
-
}
|
128 |
-
|
129 |
-
public function admin_generate_menu() {
|
130 |
-
add_options_page('Website Monetization by MageNet', 'Website Monetization by MageNet', 'manage_options', 'magenet-links-settings', array(&$this, 'admin_magenet_settings'));
|
131 |
-
}
|
132 |
-
|
133 |
-
public function add_magenet_links($content) {
|
134 |
-
global $post;
|
135 |
-
$link_count = 1;
|
136 |
-
$is_active_plugin = $this->getSeoPluginParam();
|
137 |
-
if($is_active_plugin=='on' && ($post->post_type == 'page' OR $post->post_type == 'post')) $link_count = 2;
|
138 |
-
|
139 |
-
$this->link_shown++;
|
140 |
-
if($this->link_shown <= $link_count) {
|
141 |
-
global $wpdb;
|
142 |
-
$link_data = $this->getLinks();
|
143 |
-
$content .= '<div class="mads-block">';
|
144 |
-
if (is_array($link_data) && count($link_data) > 0) {
|
145 |
-
foreach($link_data as $link) {
|
146 |
-
$content .= "\n".$link['link_html'];
|
147 |
-
}
|
148 |
-
}
|
149 |
-
$content .='</div>';
|
150 |
-
}
|
151 |
-
|
152 |
-
return $content;
|
153 |
-
}
|
154 |
-
|
155 |
-
public function admin_magenet_settings() {
|
156 |
-
global $wpdb;
|
157 |
-
$magenet_key = $this->getKey();
|
158 |
-
$is_active_seo_plugin = $this->getSeoPluginParam();
|
159 |
-
$plugin_result_text = '';
|
160 |
-
if(isset($_POST['seoplugin']) && !empty($_POST['seoplugin'])) {
|
161 |
-
if (isset($_POST['seoparam']) && !empty($_POST['seoparam'])) {
|
162 |
-
$this->setSeoPluginParam($_POST['seoparam']);
|
163 |
-
} else {
|
164 |
-
$this->setSeoPluginParam('off');
|
165 |
-
}
|
166 |
-
$is_active_seo_plugin = $this->getSeoPluginParam();
|
167 |
-
$plugin_result_text = "<span style=\"color: #009900;\">Saved</span>";
|
168 |
-
}
|
169 |
-
if (isset($_POST['key']) && !empty($_POST['key'])) {
|
170 |
-
$magenet_key = $_POST['key'];
|
171 |
-
$test_key = $this->testKey($magenet_key);
|
172 |
-
if ($test_key) {
|
173 |
-
$this->setKey($magenet_key);
|
174 |
-
$result_text = "<span style=\"color: #009900;\">Key confirmed</span>";
|
175 |
-
} else {
|
176 |
-
if($this -> lastError == 0) {
|
177 |
-
$result_text = "<span style=\"color: #ca2222;\">Incorrect Key. Please try again</span>";
|
178 |
-
} else {
|
179 |
-
$result_text = "<span style=\"color: #ca2222;\">Temporary Error (".$this -> lastError."). Please try again later. If you continue to see this error over an extended period of time, <a href=\"http://www.magenet.com/contact-us/\" target=\"_blank\">please let us know</a> so we can look into the issue.</span>";
|
180 |
-
}
|
181 |
-
}
|
182 |
-
}
|
183 |
-
if (isset($_POST['update_data']) && $_POST['update_data'] == 1) {
|
184 |
-
$result = $this->sendRequest($this->api_host.$this->api_get, $magenet_key);
|
185 |
-
if ($result) {
|
186 |
-
$wpdb->query("DELETE FROM {$this->tbl_magenet_links} WHERE 1");
|
187 |
-
$new_links = json_decode($result, TRUE);
|
188 |
-
if (count($new_links)>0)
|
189 |
-
foreach($new_links as $new_link) {
|
190 |
-
if (isset($new_link['page_url']) && isset($new_link['issue_html'])) {
|
191 |
-
$wpdb->query($wpdb->prepare("INSERT INTO {$this->tbl_magenet_links}(page_url, link_html) VALUES (%s, %s)", $new_link['page_url'], $new_link['issue_html']));
|
192 |
-
}
|
193 |
-
}
|
194 |
-
}
|
195 |
-
update_option("magenet_links_last_update", time());
|
196 |
-
$result_update_text = "<span style=\"color: #009900;\">Ads have been updated.</span>";
|
197 |
-
}
|
198 |
-
$link_data = $wpdb->get_results("SELECT * FROM `" . $this->tbl_magenet_links . "`", ARRAY_A);
|
199 |
-
include_once('view-settings.php');
|
200 |
-
}
|
201 |
-
|
202 |
-
public function testKey($key) {
|
203 |
-
$result = $this->sendRequest($this->api_host.$this->api_test, $key);
|
204 |
-
return $result === "1";
|
205 |
-
}
|
206 |
-
|
207 |
-
public function getLinks() {
|
208 |
-
global $wpdb;
|
209 |
-
$key = $this->getKey();
|
210 |
-
if ($key) {
|
211 |
-
$last_update_time = get_option("magenet_links_last_update");
|
212 |
-
if ($last_update_time + $this->cache_time < time()) {
|
213 |
-
$result = $this->sendRequest($this->api_host.$this->api_get, $key);
|
214 |
-
if ($result) {
|
215 |
-
$wpdb->query("DELETE FROM {$this->tbl_magenet_links} WHERE 1");
|
216 |
-
$new_links = json_decode($result, TRUE);
|
217 |
-
if (count($new_links)>0)
|
218 |
-
foreach($new_links as $new_link) {
|
219 |
-
if (isset($new_link['page_url']) && isset($new_link['issue_html'])) {
|
220 |
-
$wpdb->query($wpdb->prepare("INSERT INTO {$this->tbl_magenet_links}(page_url, link_html) VALUES (%s, %s)", $new_link['page_url'], $new_link['issue_html']));
|
221 |
-
}
|
222 |
-
}
|
223 |
-
}
|
224 |
-
update_option("magenet_links_last_update", time());
|
225 |
-
}
|
226 |
-
$site_url = str_replace("'", "\'", get_option("siteurl"));
|
227 |
-
$page_url = str_replace("'", "\'", $_SERVER["REQUEST_URI"]);
|
228 |
-
|
229 |
-
$check_page_without_last_slash_query = "";
|
230 |
-
if($page_url[strlen($page_url)-1] == "/") {
|
231 |
-
$check_page_without_last_slash_query = " OR page_url='" . $site_url . substr($page_url, 0, -1) . "'";
|
232 |
-
}
|
233 |
-
$link_data = $wpdb->get_results("SELECT * FROM `" . $this->tbl_magenet_links . "` WHERE page_url='". $site_url . $page_url ."'" . $check_page_without_last_slash_query, ARRAY_A);
|
234 |
-
return $link_data;
|
235 |
-
}
|
236 |
-
return false;
|
237 |
-
}
|
238 |
-
|
239 |
-
public function sendRequest($url, $key) {
|
240 |
-
$siteurl = get_option("siteurl");
|
241 |
-
$params = http_build_query(array(
|
242 |
-
'url' => $siteurl,
|
243 |
-
'key' => $key,
|
244 |
-
'version' => plugin_version
|
245 |
-
));
|
246 |
-
if (function_exists('curl_init') && function_exists('curl_exec')) {
|
247 |
-
$ch = curl_init();
|
248 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
249 |
-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
250 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
251 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
252 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
253 |
-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
254 |
-
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
|
255 |
-
curl_setopt($ch, CURLOPT_POST, TRUE);
|
256 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
257 |
-
$curl_result = curl_exec($ch);
|
258 |
-
|
259 |
-
$this -> lastError = curl_errno($ch);
|
260 |
-
if (!$this -> lastError) {
|
261 |
-
$result = $curl_result;
|
262 |
-
} else {
|
263 |
-
$result = false;
|
264 |
-
}
|
265 |
-
curl_close($ch);
|
266 |
-
} else {
|
267 |
-
$url = $url."?".$params;
|
268 |
-
$data = file_get_contents($url, false);
|
269 |
-
$result = $data;
|
270 |
-
}
|
271 |
-
return $result;
|
272 |
-
}
|
273 |
-
}
|
274 |
-
}
|
275 |
|
|
|
276 |
global $magenetLinkAutoinstall;
|
277 |
$magenetLinkAutoinstall = new MagenetLinkAutoinstall();
|
278 |
?>
|
2 |
/*
|
3 |
Plugin Name: Website Monetization by MageNet
|
4 |
Description: Website Monetization by MageNet allows you to sell contextual ads from your pages automatically and receive payments with PayPal. To get started: 1) Click the "Activate" link to the left of this description, 2) <a href="http://magenet.com" target="_blank">Sign up for a MageNet Key</a>, and 3) Go to Settings > "Website Monetization by MageNet" configuration page, and save your MageNet Key.
|
5 |
+
Version: 1.0.16
|
6 |
Author: MageNet.com
|
7 |
Author URI: http://magenet.com
|
8 |
*/
|
9 |
+
define("plugin_file",__FILE__);
|
|
|
|
|
|
|
|
|
|
|
10 |
// Stop direct call
|
11 |
+
if(preg_match('#' . basename(plugin_file) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
|
12 |
|
13 |
if (!function_exists('json_decode')) {
|
14 |
function json_decode($json, $assoc) {
|
18 |
return $jsonO->decode($json);
|
19 |
}
|
20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
require_once( plugin_dir_path( plugin_file ).'MagenetLinkAutoinstall.php' );
|
23 |
global $magenetLinkAutoinstall;
|
24 |
$magenetLinkAutoinstall = new MagenetLinkAutoinstall();
|
25 |
?>
|
readme.txt
CHANGED
@@ -84,6 +84,11 @@ MageNet crawler will index your sites the same way Google does. It will “read
|
|
84 |
3. "Pages options" menu
|
85 |
|
86 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
87 |
= 1.0.15 =
|
88 |
* Fixed the issue with errors on site after Plugin installation
|
89 |
|
84 |
3. "Pages options" menu
|
85 |
|
86 |
== Changelog ==
|
87 |
+
= 1.0.16 =
|
88 |
+
* Fixed bug with not showing links on some pages
|
89 |
+
* Increasing the Plugin security
|
90 |
+
* Fixed the issue with errors on site after Plugin installation
|
91 |
+
|
92 |
= 1.0.15 =
|
93 |
* Fixed the issue with errors on site after Plugin installation
|
94 |
|
uninstall.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
//if uninstall not called from WordPress exit
|
3 |
+
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
|
4 |
+
exit ();
|
5 |
+
define("plugin_file",__FILE__);
|
6 |
+
require_once( plugin_dir_path( plugin_file ).'MagenetLinkAutoinstall.php' );
|
7 |
+
global $magenetLinkAutoinstall;
|
8 |
+
$magenetLinkAutoinstall = new MagenetLinkAutoinstall();
|
9 |
+
$magenetLinkAutoinstall->uninstall();
|
10 |
+
?>
|