· 4 years ago · May 26, 2021, 07:30 AM
1<?php
2
3// PopCash Anti AdBlock PHP Script
4// Release Date: 10 March 2021
5// Version: 1.0.1
6
7$UID = "254831"; // Your publisherID
8$WID = "525290"; // Your domainID
9$TOKEN = "70b8e20084470febb97e-1622013388-13002791d8c3fd6aa247254831"; // Token used in PopCash API
10$OPTIONS = [
11 "pop_fback" => "under", // values: 'under' or 'up'
12 "pop_fcap" => "1", // How many ads we should show in a 24 hours time frame.
13 "pop_delay" => "0", // popunder delay from the user click (in seconds) - Default is 0
14];
15
16
17class PopcashPublisherScript
18{
19
20 /**
21 * cache
22 *
23 * @var array
24 */
25 protected $cache = [
26 'enabled' => true,
27 'host' => 'localhost',
28 'port' => '11211',
29 'key' => 'ppch-h6IzF4iRLEdZV-QX82hhpzmvxX--',
30 ];
31
32 /**
33 * endpoint
34 *
35 * @var string
36 */
37 public $endpoint = 'https://api-js.popcash.net/getCode?';
38
39 /**
40 * timeout
41 *
42 * @var int
43 */
44 public $timeout = 2;
45
46 /**
47 * expiration
48 *
49 * @var int
50 */
51 public $expiration = 10 * 60;
52
53 /**
54 * Constructor
55 *
56 * @param mixed $uid
57 * @param mixed $wid
58 * @param mixed $token
59 * @param array $options
60 */
61 public function __construct($uid, $wid, $token, $options=[])
62 {
63
64 $this->uid = $uid;
65 $this->wid = $wid;
66 $this->token = $token;
67 $this->options = $options;
68 $this->cache['key'] .= "$uid-$wid";
69 }
70
71 /**
72 * getCode
73 *
74 * @access public
75 */
76 public function getCode()
77 {
78
79 $code = $this->getCache()->get($this->cache['key']);
80
81 if($this->cache['enabled'] && $code = $this->getCache()->get($this->cache['key'])) {
82 return (object) ['response' =>$code, 'cacheStatus' => 1];
83 }
84
85 $userAgent = (isset($_SERVER['HTTP_USER_AGENT']) && !empty($_SERVER['HTTP_USER_AGENT']))
86 ? $_SERVER['HTTP_USER_AGENT']
87 : '';
88
89 $curl = curl_init();
90
91 curl_setopt_array($curl, [
92 CURLOPT_URL => $this->endpoint . "uid={$this->uid}&wid={$this->wid}&apikey={$this->token}&" . http_build_query($this->options),
93 CURLOPT_RETURNTRANSFER => true,
94 CURLOPT_TIMEOUT => $this->timeout,
95 CURLOPT_USERAGENT => $userAgent,
96 CURLOPT_REFERER => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "novel-tt.blogspot.com",
97 ]);
98
99 $response = curl_exec($curl);
100
101 $cacheStatus = $this->cache['enabled'];
102
103 if ($this->cache['enabled'] && curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
104 $cacheStatus = $this->getCache()->set($this->cache['key'], $response, $this->expiration);
105 }
106
107 return (object) [
108 'response' => $response,
109 'cacheStatus' => $cacheStatus,
110 ];
111 }
112
113 /**
114 * fromCache
115 *
116 * @access public
117 */
118 public function getCache()
119 {
120
121 if (class_exists('Memcached')) {
122 $memcached = new \Memcached();
123 $memcached->addServer($this->cache['host'], $this->cache['port']);
124
125 $index = $this->cache['host'] . ':' . $this->cache['port'];
126 $st = $memcached->getStats();
127 if (isset($st[$index]['pid']) && $st[$index]['pid'] > 0) {
128 return $memcached;
129 }
130 }
131
132 if (class_exists('Memcache')) {
133 $memcache = new XMemcache();
134 if (@$memcache->connect($this->cache['host'], $this->cache['port'])) {
135 return $memcache;
136 }
137 }
138
139 return new SimpleFile($this->expiration);
140 }
141
142 /**
143 * getCacheKey
144 *
145 * @access public
146 */
147 public function getCacheKey()
148 {
149
150 return $this->cache['key'];
151 }
152}
153
154if (class_exists('\Memcache')) {
155 class XMemcache extends \Memcache
156 {
157
158 /**
159 * set
160 *
161 * @param mixed $key
162 * @param mixed $var
163 * @param mixed $expire
164 */
165 public function set ($key, $var, $expire)
166 {
167 return parent::set($key, $var, 0, $expire);
168 }
169
170 }
171}
172
173class SimpleFile
174{
175
176 /**
177 * expiration
178 *
179 * @var int
180 */
181 protected $expiration;
182
183 /**
184 * Constructor
185 *
186 * @param mixed $expiration
187 */
188 public function __construct($expiration)
189 {
190 $this->expiration = $expiration;
191 }
192
193 /**
194 * set
195 *
196 * @param mixed $filename
197 * @param mixed $content
198 * @access public
199 * @return void
200 */
201 function set($filename, $content)
202 {
203
204 try {
205 $file = @fopen(sys_get_temp_dir() . "/$filename", 'w');
206 if (!$file) {
207 return false;
208 }
209 fwrite($file, $content);
210 return fclose($file);
211 } catch (\Exception $e) {
212
213 return false;
214 }
215 }
216
217 function get($filename)
218 {
219 try {
220 if (!file_exists(sys_get_temp_dir() . "/$filename")) {
221 return false;
222 }
223 $content = file_get_contents(sys_get_temp_dir() . "/$filename");
224 if (!$content) {
225 return false;
226 }
227 if (time() - filemtime(sys_get_temp_dir() . "/$filename") > $this->expiration) {
228 unlink(sys_get_temp_dir() . "/$filename");
229 return false;
230 }
231 return $content;
232 } catch (\Exception $e) {
233 return false;
234 }
235 }
236}
237
238$ps = new PopcashPublisherScript($UID , $WID, $TOKEN, $OPTIONS);
239
240echo "<script type='text/javascript'>";
241echo $ps->getCode()->cacheStatus == 1 ? "// Cache Key: {$ps->getCacheKey()}\n\n" : "// no cache\n\n";
242echo $ps->getCode()->response;
243echo "</script>";
244
245?>