Version Description
Download this release
Release Info
Developer | MageNet |
Plugin | Website Monetization by MageNet |
Version | 1.0.1 |
Comparing to | |
See all releases |
Version 1.0.1
- FastJSON.class.php +368 -0
- css/admin-style.css +0 -0
- js/admin-scripts.js +0 -0
- monetization-by-magenet.php +207 -0
- view-settings.php +41 -0
FastJSON.class.php
ADDED
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**_______________________________________
|
3 |
+
*
|
4 |
+
* FastJSON (strict version for PHP 5.2 or greater),
|
5 |
+
* simple and fast Pear Service_JSON encoder/decoder alternative
|
6 |
+
* [http://pear.php.net/pepr/pepr-proposal-show.php?id=198]
|
7 |
+
* ---------------------------------------
|
8 |
+
* This class is about two time faster than Pear Service_JSON class.
|
9 |
+
* This class is probably not powerful as Service_JSON but it has
|
10 |
+
* no dependencies and converts correctly ASCII range 0x00 - 0x1F too.
|
11 |
+
* There's any string convertion, just regular RFC specific characters are converted
|
12 |
+
* into \u00XX string.
|
13 |
+
* To don't have problems with other chars try to use utf8_encode($json_encoded_string).
|
14 |
+
* To recieve correctly JSON strings from JavaScript use encodeURIComponent then
|
15 |
+
* use, if is necessary, utef8_decode before JS to PHP convertion.
|
16 |
+
* decode method doesn't returns a standard object class but You can
|
17 |
+
* create the corret class directly with FastJSON::convert method
|
18 |
+
* and with them You can manage JS Date objects too.
|
19 |
+
* ---------------------------------------
|
20 |
+
* Summary of static public methods
|
21 |
+
*
|
22 |
+
* convert
|
23 |
+
* extra, special method
|
24 |
+
*
|
25 |
+
* decode
|
26 |
+
* converts a valid JSON string
|
27 |
+
* into a native PHP variable
|
28 |
+
*
|
29 |
+
* encode
|
30 |
+
* converts a native php variable
|
31 |
+
* into a valid JSON string
|
32 |
+
* ---------------------------------------
|
33 |
+
*
|
34 |
+
* Special FastJSON::convert method Informations
|
35 |
+
* _______________________________________
|
36 |
+
* ---------------------------------------
|
37 |
+
* This method is used by FastJSON::encode method but should be used
|
38 |
+
* to do these convertions too:
|
39 |
+
*
|
40 |
+
* - JSON string to time() integer:
|
41 |
+
*
|
42 |
+
* FastJSON::convert(decodedDate:String):time()
|
43 |
+
*
|
44 |
+
* If You recieve a date string rappresentation You
|
45 |
+
* could convert into respective time() integer.
|
46 |
+
* Example:
|
47 |
+
* FastJSON::convert(FastJSON::decode($clienttime));
|
48 |
+
* // i.e. $clienttime = 2006-11-09T14:42:30
|
49 |
+
* // returned time will be an integer useful with gmdate or date
|
50 |
+
* // to create, for example, this string
|
51 |
+
* // Thu Nov 09 2006 14:42:30 GMT+0100 (Rome, Europe)
|
52 |
+
*
|
53 |
+
* - time() to JSON string:
|
54 |
+
*
|
55 |
+
* FastJSON::convert(time():Int32, true:Boolean):JSON Date String format
|
56 |
+
*
|
57 |
+
* You could send server time() informations and send them to clients.
|
58 |
+
* Example:
|
59 |
+
* FastJSON::convert(time(), true);
|
60 |
+
* // i.e. 2006-11-09T14:42:30
|
61 |
+
*
|
62 |
+
* - associative array to generic class:
|
63 |
+
*
|
64 |
+
* FastJSON::convert(array(params=>values), new GenericClass):new Instance of GenericClass
|
65 |
+
*
|
66 |
+
* With a decoded JSON object You could convert them
|
67 |
+
* into a new instance of your Generic Class.
|
68 |
+
* Example:
|
69 |
+
* class MyClass {
|
70 |
+
* var $param = "somevalue";
|
71 |
+
* function MyClass($somevar) {
|
72 |
+
* $this->somevar = $somevar;
|
73 |
+
* };
|
74 |
+
* function getVar = function(){
|
75 |
+
* return $this->somevar;
|
76 |
+
* };
|
77 |
+
* };
|
78 |
+
*
|
79 |
+
* $instance = new MyClass("example");
|
80 |
+
* $encoded = FastJSON::encode($instance);
|
81 |
+
* // {"param":"somevalue"}
|
82 |
+
*
|
83 |
+
* $decoded = FastJSON::decode($encoded);
|
84 |
+
* // $decoded instanceof Object => true
|
85 |
+
* // $decoded instanceof MyClass => false
|
86 |
+
*
|
87 |
+
* $decoded = FastJSON::convert($decoded, new MyClass("example"));
|
88 |
+
* // $decoded instanceof Object => true
|
89 |
+
* // $decoded instanceof MyClass => true
|
90 |
+
*
|
91 |
+
* $decoded->getVar(); // example
|
92 |
+
*
|
93 |
+
* ---------------------------------------
|
94 |
+
*
|
95 |
+
* @author Andrea Giammarchi
|
96 |
+
* @site http://www.devpro.it/
|
97 |
+
* @version 0.4 [fixed string convertion problems, add stdClass optional convertion instead of associative array (used by default)]
|
98 |
+
* @requires anything
|
99 |
+
* @compatibility PHP >= 5
|
100 |
+
* @license
|
101 |
+
* ---------------------------------------
|
102 |
+
*
|
103 |
+
* Copyright (c) 2006 - 2007 Andrea Giammarchi
|
104 |
+
*
|
105 |
+
* Permission is hereby granted, free of charge,
|
106 |
+
* to any person obtaining a copy of this software and associated
|
107 |
+
* documentation files (the "Software"),
|
108 |
+
* to deal in the Software without restriction,
|
109 |
+
* including without limitation the rights to use, copy, modify, merge,
|
110 |
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
111 |
+
* and to permit persons to whom the Software is furnished to do so,
|
112 |
+
* subject to the following conditions:
|
113 |
+
*
|
114 |
+
* The above copyright notice and this permission notice shall be included
|
115 |
+
* in all copies or substantial portions of the Software.
|
116 |
+
*
|
117 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
118 |
+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
119 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
120 |
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
121 |
+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
122 |
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
123 |
+
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
124 |
+
* _______________________________________
|
125 |
+
*/
|
126 |
+
class FastJSON {
|
127 |
+
|
128 |
+
// public methods
|
129 |
+
|
130 |
+
/**
|
131 |
+
* public static method
|
132 |
+
*
|
133 |
+
* FastJSON::convert(params:* [, result:Instance]):*
|
134 |
+
*
|
135 |
+
* @param * String or Object
|
136 |
+
* @param Instance optional new generic class instance if first
|
137 |
+
* parameter is an object.
|
138 |
+
* @return * time() value or new Instance with object parameters.
|
139 |
+
*
|
140 |
+
* @note please read Special FastJSON::convert method Informations
|
141 |
+
*/
|
142 |
+
static public function convert($params, $result = null){
|
143 |
+
switch(gettype($params)){
|
144 |
+
case 'array':
|
145 |
+
$tmp = array();
|
146 |
+
foreach($params as $key => $value) {
|
147 |
+
if(($value = FastJSON::encode($value)) !== '')
|
148 |
+
array_push($tmp, FastJSON::encode(strval($key)).':'.$value);
|
149 |
+
};
|
150 |
+
$result = '{'.implode(',', $tmp).'}';
|
151 |
+
break;
|
152 |
+
case 'boolean':
|
153 |
+
$result = $params ? 'true' : 'false';
|
154 |
+
break;
|
155 |
+
case 'double':
|
156 |
+
case 'float':
|
157 |
+
case 'integer':
|
158 |
+
$result = $result !== null ? strftime('%Y-%m-%dT%H:%M:%S', $params) : strval($params);
|
159 |
+
break;
|
160 |
+
case 'NULL':
|
161 |
+
$result = 'null';
|
162 |
+
break;
|
163 |
+
case 'string':
|
164 |
+
$i = create_function('&$e, $p, $l', 'return intval(substr($e, $p, $l));');
|
165 |
+
if(preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $params))
|
166 |
+
$result = mktime($i($params, 11, 2), $i($params, 14, 2), $i($params, 17, 2), $i($params, 5, 2), $i($params, 9, 2), $i($params, 0, 4));
|
167 |
+
break;
|
168 |
+
case 'object':
|
169 |
+
$tmp = array();
|
170 |
+
if(is_object($result)) {
|
171 |
+
foreach($params as $key => $value)
|
172 |
+
$result->$key = $value;
|
173 |
+
} else {
|
174 |
+
$result = get_object_vars($params);
|
175 |
+
foreach($result as $key => $value) {
|
176 |
+
if(($value = FastJSON::encode($value)) !== '')
|
177 |
+
array_push($tmp, FastJSON::encode($key).':'.$value);
|
178 |
+
};
|
179 |
+
$result = '{'.implode(',', $tmp).'}';
|
180 |
+
}
|
181 |
+
break;
|
182 |
+
}
|
183 |
+
return $result;
|
184 |
+
}
|
185 |
+
|
186 |
+
/**
|
187 |
+
* public method
|
188 |
+
*
|
189 |
+
* FastJSON::decode(params:String[, useStdClass:Boolean]):*
|
190 |
+
*
|
191 |
+
* @param String valid JSON encoded string
|
192 |
+
* @param Bolean uses stdClass instead of associative array if params contains objects (default false)
|
193 |
+
* @return * converted variable or null
|
194 |
+
* is params is not a JSON compatible string.
|
195 |
+
* @note This method works in an optimist way. If JSON string is not valid
|
196 |
+
* the code execution will die using exit.
|
197 |
+
* This is probably not so good but JSON is often used combined with
|
198 |
+
* XMLHttpRequest then I suppose that's better more protection than
|
199 |
+
* just some WARNING.
|
200 |
+
* With every kind of valid JSON string the old error_reporting level
|
201 |
+
* and the old error_handler will be restored.
|
202 |
+
*
|
203 |
+
* @example
|
204 |
+
* FastJSON::decode('{"param":"value"}'); // associative array
|
205 |
+
* FastJSON::decode('{"param":"value"}', true); // stdClass
|
206 |
+
* FastJSON::decode('["one",two,true,false,null,{},[1,2]]'); // array
|
207 |
+
*/
|
208 |
+
static public function decode($encode, $stdClass = false){
|
209 |
+
$pos = 0;
|
210 |
+
$slen = is_string($encode) ? strlen($encode) : null;
|
211 |
+
if($slen !== null) {
|
212 |
+
$error = error_reporting(0);
|
213 |
+
set_error_handler(array('FastJSON', '__exit'));
|
214 |
+
$result = FastJSON::__decode($encode, $pos, $slen, $stdClass);
|
215 |
+
error_reporting($error);
|
216 |
+
restore_error_handler();
|
217 |
+
}
|
218 |
+
else
|
219 |
+
$result = null;
|
220 |
+
return $result;
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* public method
|
225 |
+
*
|
226 |
+
* FastJSON::encode(params:*):String
|
227 |
+
*
|
228 |
+
* @param * Array, Boolean, Float, Int, Object, String or NULL variable.
|
229 |
+
* @return String JSON genric object rappresentation
|
230 |
+
* or empty string if param is not compatible.
|
231 |
+
*
|
232 |
+
* @example
|
233 |
+
* FastJSON::encode(array(1,"two")); // '[1,"two"]'
|
234 |
+
*
|
235 |
+
* $obj = new MyClass();
|
236 |
+
* obj->param = "value";
|
237 |
+
* obj->param2 = "value2";
|
238 |
+
* FastJSON::encode(obj); // '{"param":"value","param2":"value2"}'
|
239 |
+
*/
|
240 |
+
static public function encode($decode){
|
241 |
+
$result = '';
|
242 |
+
switch(gettype($decode)){
|
243 |
+
case 'array':
|
244 |
+
if(!count($decode) || array_keys($decode) === range(0, count($decode) - 1)) {
|
245 |
+
$keys = array();
|
246 |
+
foreach($decode as $value) {
|
247 |
+
if(($value = FastJSON::encode($value)) !== '')
|
248 |
+
array_push($keys, $value);
|
249 |
+
}
|
250 |
+
$result = '['.implode(',', $keys).']';
|
251 |
+
}
|
252 |
+
else
|
253 |
+
$result = FastJSON::convert($decode);
|
254 |
+
break;
|
255 |
+
case 'string':
|
256 |
+
$replacement = FastJSON::__getStaticReplacement();
|
257 |
+
$result = '"'.str_replace($replacement['find'], $replacement['replace'], $decode).'"';
|
258 |
+
break;
|
259 |
+
default:
|
260 |
+
if(!is_callable($decode))
|
261 |
+
$result = FastJSON::convert($decode);
|
262 |
+
break;
|
263 |
+
}
|
264 |
+
return $result;
|
265 |
+
}
|
266 |
+
|
267 |
+
// private methods, uncommented, sorry
|
268 |
+
static private function __getStaticReplacement(){
|
269 |
+
static $replacement = array('find'=>array(), 'replace'=>array());
|
270 |
+
if($replacement['find'] == array()) {
|
271 |
+
foreach(array_merge(range(0, 7), array(11), range(14, 31)) as $v) {
|
272 |
+
$replacement['find'][] = chr($v);
|
273 |
+
$replacement['replace'][] = "\\u00".sprintf("%02x", $v);
|
274 |
+
}
|
275 |
+
$replacement['find'] = array_merge(array(chr(0x5c), chr(0x2F), chr(0x22), chr(0x0d), chr(0x0c), chr(0x0a), chr(0x09), chr(0x08)), $replacement['find']);
|
276 |
+
$replacement['replace'] = array_merge(array('\\\\', '\\/', '\\"', '\r', '\f', '\n', '\t', '\b'), $replacement['replace']);
|
277 |
+
}
|
278 |
+
return $replacement;
|
279 |
+
}
|
280 |
+
static private function __decode(&$encode, &$pos, &$slen, &$stdClass){
|
281 |
+
switch($encode{$pos}) {
|
282 |
+
case 't':
|
283 |
+
$result = true;
|
284 |
+
$pos += 4;
|
285 |
+
break;
|
286 |
+
case 'f':
|
287 |
+
$result = false;
|
288 |
+
$pos += 5;
|
289 |
+
break;
|
290 |
+
case 'n':
|
291 |
+
$result = null;
|
292 |
+
$pos += 4;
|
293 |
+
break;
|
294 |
+
case '[':
|
295 |
+
$result = array();
|
296 |
+
++$pos;
|
297 |
+
while($encode{$pos} !== ']') {
|
298 |
+
array_push($result, FastJSON::__decode($encode, $pos, $slen, $stdClass));
|
299 |
+
if($encode{$pos} === ',')
|
300 |
+
++$pos;
|
301 |
+
}
|
302 |
+
++$pos;
|
303 |
+
break;
|
304 |
+
case '{':
|
305 |
+
$result = $stdClass ? new stdClass : array();
|
306 |
+
++$pos;
|
307 |
+
while($encode{$pos} !== '}') {
|
308 |
+
$tmp = FastJSON::__decodeString($encode, $pos);
|
309 |
+
++$pos;
|
310 |
+
if($stdClass)
|
311 |
+
$result->$tmp = FastJSON::__decode($encode, $pos, $slen, $stdClass);
|
312 |
+
else
|
313 |
+
$result[$tmp] = FastJSON::__decode($encode, $pos, $slen, $stdClass);
|
314 |
+
if($encode{$pos} === ',')
|
315 |
+
++$pos;
|
316 |
+
}
|
317 |
+
++$pos;
|
318 |
+
break;
|
319 |
+
case '"':
|
320 |
+
switch($encode{++$pos}) {
|
321 |
+
case '"':
|
322 |
+
$result = "";
|
323 |
+
break;
|
324 |
+
default:
|
325 |
+
$result = FastJSON::__decodeString($encode, $pos);
|
326 |
+
break;
|
327 |
+
}
|
328 |
+
++$pos;
|
329 |
+
break;
|
330 |
+
default:
|
331 |
+
$tmp = '';
|
332 |
+
preg_replace('/^(\-)?([0-9]+)(\.[0-9]+)?([eE]\+[0-9]+)?/e', '$tmp = "\\1\\2\\3\\4"', substr($encode, $pos));
|
333 |
+
if($tmp !== '') {
|
334 |
+
$pos += strlen($tmp);
|
335 |
+
$nint = intval($tmp);
|
336 |
+
$nfloat = floatval($tmp);
|
337 |
+
$result = $nfloat == $nint ? $nint : $nfloat;
|
338 |
+
}
|
339 |
+
break;
|
340 |
+
}
|
341 |
+
return $result;
|
342 |
+
}
|
343 |
+
static private function __decodeString(&$encode, &$pos) {
|
344 |
+
$replacement = FastJSON::__getStaticReplacement();
|
345 |
+
$endString = FastJSON::__endString($encode, $pos, $pos);
|
346 |
+
$result = str_replace($replacement['replace'], $replacement['find'], substr($encode, $pos, $endString));
|
347 |
+
$pos += $endString;
|
348 |
+
return $result;
|
349 |
+
}
|
350 |
+
static private function __endString(&$encode, $position, &$pos) {
|
351 |
+
do {
|
352 |
+
$position = strpos($encode, '"', $position + 1);
|
353 |
+
}while($position !== false && FastJSON::__slashedChar($encode, $position - 1));
|
354 |
+
if($position === false)
|
355 |
+
trigger_error('', E_USER_WARNING);
|
356 |
+
return $position - $pos;
|
357 |
+
}
|
358 |
+
static private function __exit($str, $a, $b) {
|
359 |
+
exit($a.'FATAL: FastJSON decode method failure [malicious or incorrect JSON string]');
|
360 |
+
}
|
361 |
+
static private function __slashedChar(&$encode, $position) {
|
362 |
+
$pos = 0;
|
363 |
+
while($encode{$position--} === '\\')
|
364 |
+
$pos++;
|
365 |
+
return $pos % 2;
|
366 |
+
}
|
367 |
+
}
|
368 |
+
?>
|
css/admin-style.css
ADDED
File without changes
|
js/admin-scripts.js
ADDED
File without changes
|
monetization-by-magenet.php
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
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.1
|
6 |
+
Author: MageNet.com
|
7 |
+
Author URI: http://magenet.com
|
8 |
+
*/
|
9 |
+
// Stop direct call
|
10 |
+
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
|
11 |
+
|
12 |
+
if (!function_exists('json_decode')) {
|
13 |
+
function json_decode($json, $assoc) {
|
14 |
+
include_once('FastJSON.class.php');
|
15 |
+
return FastJSON::decode($json, !$assoc);
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
if (!class_exists('MagenetLinkAutoinstall')) {
|
20 |
+
class MagenetLinkAutoinstall {
|
21 |
+
|
22 |
+
private $cache_time = 3;
|
23 |
+
private $api_host = "http://dev.api.magenet.com";
|
24 |
+
private $api_get = "/wordpress/get";
|
25 |
+
private $api_test = "/wordpress/test";
|
26 |
+
private $key = 0;
|
27 |
+
|
28 |
+
public function MagenetLinkAutoinstall() {
|
29 |
+
global $wpdb;
|
30 |
+
define('MagenetLinkAutoinstall', true);
|
31 |
+
$this->plugin_name = plugin_basename(__FILE__);
|
32 |
+
$this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
|
33 |
+
$this->tbl_magenet_links = $wpdb->prefix . 'magenet_links';
|
34 |
+
|
35 |
+
register_activation_hook($this->plugin_name, array(&$this, 'activate'));
|
36 |
+
register_deactivation_hook($this->plugin_name, array(&$this, 'deactivate'));
|
37 |
+
register_uninstall_hook($this->plugin_name, array(&$this, 'uninstall'));
|
38 |
+
|
39 |
+
if (is_admin()) {
|
40 |
+
add_action('wp_print_scripts', array(&$this, 'admin_load_scripts'));
|
41 |
+
add_action('wp_print_styles', array(&$this, 'admin_load_styles'));
|
42 |
+
add_action('admin_menu', array(&$this, 'admin_generate_menu'));
|
43 |
+
} else {
|
44 |
+
if (!has_filter('the_content', array(&$this, 'add_magenet_links')))
|
45 |
+
add_filter('the_content', array(&$this, 'add_magenet_links'));
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
public function getKey() {
|
50 |
+
if ($this->key == 0) {
|
51 |
+
$this->key = get_option("magenet_links_autoinstall_key");
|
52 |
+
}
|
53 |
+
return $this->key;
|
54 |
+
}
|
55 |
+
|
56 |
+
public function setKey($key) {
|
57 |
+
update_option("magenet_links_autoinstall_key", $key);
|
58 |
+
$this->key = $key;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function activate() {
|
62 |
+
global $wpdb;
|
63 |
+
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
|
64 |
+
|
65 |
+
$table = $this->tbl_magenet_links;
|
66 |
+
if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
|
67 |
+
if (!empty($wpdb->charset))
|
68 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
69 |
+
if (!empty($wpdb->collate))
|
70 |
+
$charset_collate .= " COLLATE $wpdb->collate";
|
71 |
+
}
|
72 |
+
|
73 |
+
$sql_table_magenet_links = "
|
74 |
+
CREATE TABLE `".$wpdb->prefix."magenet_links` (
|
75 |
+
`ID` INT(10) UNSIGNED NULL AUTO_INCREMENT,
|
76 |
+
`page_url` TEXT NOT NULL,
|
77 |
+
`link_html` TEXT NOT NULL,
|
78 |
+
PRIMARY KEY (`ID`)
|
79 |
+
)".$charset_collate.";";
|
80 |
+
$sql_add_index = "CREATE INDEX page_url ON `".$wpdb->prefix."magenet_links` (page_url(100));";
|
81 |
+
|
82 |
+
// Проверка на существование таблицы
|
83 |
+
if ( $wpdb->get_var("show tables like '".$table."'") != $table ) {
|
84 |
+
dbDelta($sql_table_magenet_links);
|
85 |
+
$wpdb->query($sql_add_index);
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
public function deactivate() {
|
90 |
+
return true;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function uninstall() {
|
94 |
+
global $wpdb;
|
95 |
+
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}magenet_links");
|
96 |
+
}
|
97 |
+
|
98 |
+
public function admin_load_scripts() {
|
99 |
+
wp_register_script('magenetLinkAutoinstallAdminJs', $this->plugin_url . 'js/admin-scripts.js' );
|
100 |
+
wp_enqueue_script('magenetLinkAutoinstallAdminJs');
|
101 |
+
}
|
102 |
+
|
103 |
+
public function admin_load_styles() {
|
104 |
+
wp_register_style('magenetLinkAutoinstallAdminCss', $this->plugin_url . 'css/admin-style.css' );
|
105 |
+
wp_enqueue_style('magenetLinkAutoinstallAdminCss');
|
106 |
+
}
|
107 |
+
|
108 |
+
public function admin_generate_menu() {
|
109 |
+
add_options_page('Website Monetization by MageNet', 'Website Monetization by MageNet', 'manage_options', 'magenet-links-settings', array(&$this, 'admin_magenet_settings'));
|
110 |
+
}
|
111 |
+
|
112 |
+
public function add_magenet_links($content) {
|
113 |
+
global $wpdb;
|
114 |
+
$link_data = $this->getLinks();
|
115 |
+
$content .= '<div class="mads-block">';
|
116 |
+
if (count($link_data) > 0) {
|
117 |
+
foreach($link_data as $link) {
|
118 |
+
$content .= "\n".$link['link_html'];
|
119 |
+
}
|
120 |
+
}
|
121 |
+
$content .='</div>';
|
122 |
+
return $content;
|
123 |
+
}
|
124 |
+
|
125 |
+
public function admin_magenet_settings() {
|
126 |
+
global $wpdb;
|
127 |
+
if (isset($_POST['key']) && !empty($_POST['key'])) {
|
128 |
+
$magenet_key = $_POST['key'];
|
129 |
+
$test_key = $this->testKey($magenet_key);
|
130 |
+
if ($test_key) {
|
131 |
+
$this->setKey($magenet_key);
|
132 |
+
$result_text = "<span style=\"color: #009900;\">Key confirmed</span>";
|
133 |
+
} else {
|
134 |
+
$result_text = "<span style=\"color: #ca2222;\">Incorrect Key. Please try again</span>";
|
135 |
+
}
|
136 |
+
} else {
|
137 |
+
$magenet_key = $this->getKey();
|
138 |
+
}
|
139 |
+
$link_data = $wpdb->get_results("SELECT * FROM `" . $this->tbl_magenet_links . "`", ARRAY_A);
|
140 |
+
include_once('view-settings.php');
|
141 |
+
}
|
142 |
+
|
143 |
+
public function testKey($key) {
|
144 |
+
$result = $this->sendRequest($this->api_host.$this->api_test, $key);
|
145 |
+
return $result === "1";
|
146 |
+
}
|
147 |
+
|
148 |
+
public function getLinks() {
|
149 |
+
global $wpdb;
|
150 |
+
$last_update_time = get_option("magenet_links_last_update");
|
151 |
+
if ($last_update_time + $this->cache_time < time()) {
|
152 |
+
$key = $this->getKey();
|
153 |
+
$result = $this->sendRequest($this->api_host.$this->api_get, $key);
|
154 |
+
if ($result) {
|
155 |
+
$wpdb->query("DELETE FROM {$this->tbl_magenet_links} WHERE 1");
|
156 |
+
$new_links = json_decode($result, TRUE);
|
157 |
+
foreach($new_links as $new_link) {
|
158 |
+
if (isset($new_link['page_url']) && isset($new_link['issue_html'])) {
|
159 |
+
$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']));
|
160 |
+
}
|
161 |
+
}
|
162 |
+
update_option("magenet_links_last_update", time());
|
163 |
+
}
|
164 |
+
}
|
165 |
+
$site_url = str_replace("'", "\'", get_option("siteurl"));
|
166 |
+
$page_url = str_replace("'", "\'", $_SERVER["REQUEST_URI"]);
|
167 |
+
$link_data = $wpdb->get_results("SELECT * FROM `" . $this->tbl_magenet_links . "` WHERE page_url='".$page_url."' OR page_url='".$site_url.$page_url."'", ARRAY_A);
|
168 |
+
return $link_data;
|
169 |
+
}
|
170 |
+
|
171 |
+
public function sendRequest($url, $key) {
|
172 |
+
$siteurl = get_option("siteurl");
|
173 |
+
$params = http_build_query(array(
|
174 |
+
'url' => $siteurl,
|
175 |
+
'key' => $key
|
176 |
+
));
|
177 |
+
if (function_exists('curl_init')) {
|
178 |
+
$ch = curl_init();
|
179 |
+
curl_setopt($ch, CURLOPT_URL, $url);
|
180 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
181 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
182 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
183 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
184 |
+
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
|
185 |
+
curl_setopt($ch, CURLOPT_POST, TRUE);
|
186 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
187 |
+
$curl_result = curl_exec($ch);
|
188 |
+
|
189 |
+
if (!curl_errno($ch)) {
|
190 |
+
$result = $curl_result;
|
191 |
+
} else {
|
192 |
+
$result = false;
|
193 |
+
}
|
194 |
+
curl_close($ch);
|
195 |
+
} else {
|
196 |
+
$url = $url."?".$params;
|
197 |
+
$data = file_get_contents($url, false);
|
198 |
+
$result = $data;
|
199 |
+
}
|
200 |
+
return $result;
|
201 |
+
}
|
202 |
+
}
|
203 |
+
}
|
204 |
+
|
205 |
+
global $magenetLinkAutoinstall;
|
206 |
+
$magenetLinkAutoinstall = new MagenetLinkAutoinstall();
|
207 |
+
?>
|
view-settings.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="wrap">
|
2 |
+
<h2>Website Monetization by MageNet</h2>
|
3 |
+
<p>By installing WordPress plugin, you allow MageNet to display paid contextual ads on pages where where you grant permission via Pages options.</p>
|
4 |
+
<div class="tool-box">
|
5 |
+
<h2 class="title">MageNet Key:</h2>
|
6 |
+
<form method="post" action="">
|
7 |
+
<input type="text" name="key" value="<?php echo $magenet_key;?>" />
|
8 |
+
<input type="submit" name="submit" value="Save" />
|
9 |
+
<?php echo $result_text; ?>
|
10 |
+
</form>
|
11 |
+
</div>
|
12 |
+
<div class="tool-box">
|
13 |
+
<h3 class="title">Active Ads:</h2>
|
14 |
+
<table class="widefat">
|
15 |
+
<thead>
|
16 |
+
<tr class="table-header">
|
17 |
+
<th>Page URL</th>
|
18 |
+
<th>Ads content</th>
|
19 |
+
</tr>
|
20 |
+
</thead>
|
21 |
+
<tbody>
|
22 |
+
<?php if (count($link_data) > 0): ?>
|
23 |
+
<?php foreach ($link_data as $key => $record): ?>
|
24 |
+
<tr>
|
25 |
+
<td class="url">
|
26 |
+
<?php echo $record['page_url'] ?>
|
27 |
+
</td>
|
28 |
+
<td class="link">
|
29 |
+
<?php echo $record['link_html'] ?>
|
30 |
+
</td>
|
31 |
+
</tr>
|
32 |
+
<?php endforeach; ?>
|
33 |
+
<?php else:?>
|
34 |
+
<tr>
|
35 |
+
<td colspan="2" style="text-align:center">No Ads</td>
|
36 |
+
</tr>
|
37 |
+
<?php endif;?>
|
38 |
+
</tbody>
|
39 |
+
</table>
|
40 |
+
</div>
|
41 |
+
</div>
|