· 6 years ago · Dec 10, 2019, 02:56 AM
1<?php
2/*
3Plugin Name: HotPay for WordPress
4Plugin URI: https://hotpay.pl/
5Description: Wtyczka pozwalająca na integrację systemu WordPress z płatnościami HotPay.
6Version: 2.1.2
7Author: ePłatności sp. z o.o. sp. k.
8Author URI: https://hotpay.pl/
9License: GPL2
10*/
11
12//instalacja
13
14register_activation_hook( __FILE__, 'hotpay_create_db' );
15add_action("admin_menu", "hotpay_dodaj_do_menu");
16
17
18add_action( 'register_form', 'hotpay__rejestracja' );
19add_filter( 'registration_errors', 'hotpay__rejestracja_walidacja', 10, 3 );
20add_action( 'user_register', 'hotpay__zapis_sms' );
21
22function hotpay__rejestracja() {
23
24
25if(!empty(get_option( "hotpay-register-sms" ))){
26echo'
27 <p>
28 <label for="kod_sms">Wyślij SMS o treści '.get_option( "hotpay-register-sms" ).' pod numer '.get_option( "hotpay-register-numer" ).'<br />
29 <input type="text" name="kod_sms" id="kod_sms" class="input" size="25" required /></label>
30 </p>
31 ';
32}
33
34 }
35
36
37
38 function hotpay__rejestracja_walidacja( $errors, $sanitized_user_login, $user_email ) {
39 if(!empty(get_option( "hotpay-register-sms" ))){
40 if ( empty( $_POST['kod_sms'] ) || ! empty( $_POST['kod_sms'] ) && trim( $_POST['kod_sms'] ) == '' ) {
41 $errors->add( 'first_name_error', __( '<strong>ERROR</strong>: Wprowadz kod SMS.', 'mydomain' ) );
42 }else{
43
44
45
46
47$ch = curl_init();
48curl_setopt($ch, CURLOPT_URL, "https://api.hotpay.pl/check_sms.php?sekret=".get_option( "hotpay-register-sekret" )."&kod_sms=".urlencode($_POST['kod_sms']));
49curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
50$wynik = curl_exec($ch);
51curl_close($ch);
52
53$codeInfo = json_decode($wynik);
54
55if($codeInfo->status=="ERROR"){
56 $errors->add( 'first_name_error', __( '<strong>ERROR</strong>: Podany kod jest niepoprawny.', 'mydomain' ) );
57}else if($codeInfo->status=="SUKCESS")
58{
59if($codeInfo->aktywacja==1)
60{
61// kod poprawny
62}else
63{
64$errors->add( 'first_name_error', __( '<strong>ERROR</strong>: Podany kod został już aktywowany.', 'mydomain' ) );
65}
66}
67 }
68
69 return $errors;
70 } return $errors;
71 }
72
73
74 function hotpay__zapis_sms( $user_id ) {
75 if ( ! empty( $_POST['hotpay_sms'] ) ) {
76 update_user_meta( $user_id, 'hotpay_sms', trim( $_POST['hotpay_sms'] ) );
77 }
78 }
79
80
81function hotpay_create_db() {
82
83
84 add_option( "hotpay_klucz", "" );
85
86 add_option( "hotpay-register-sms", "" );
87 add_option( "hotpay-register-numer", "" );
88 add_option( "hotpay-register-sekret", "" );
89
90
91
92 global $wpdb;
93 $charset_collate = $wpdb->get_charset_collate();
94 $table_name = $wpdb->prefix . 'hotpay';
95
96 $sql = "CREATE TABLE $table_name (
97 id mediumint(9) NOT NULL AUTO_INCREMENT,
98 numer varchar(10) NOT NULL,
99 usluga varchar(160) NOT NULL,
100 sekret TEXT NOT NULL,
101 UNIQUE KEY id (id)
102 ) $charset_collate;";
103
104 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
105 dbDelta( $sql );
106}
107
108
109
110//panel
111function hotpay_dodaj_do_menu()
112{
113 add_menu_page("HotPay", "HotPay", "manage_options", "hotpay-ustawienia", "hotpay_ustawienia_func", plugins_url( '/hotpay-wordpress-2-1/hpico.png' ), null, 99);
114}
115
116
117
118
119function hotpay_ustawienia_func()
120{
121 global $wpdb;
122
123if(!empty($_POST["api_key"])){
124update_option( "hotpay_klucz", trim($_POST["api_key"]) );
125}
126
127$HOTPAY_KEY=get_option( "hotpay_klucz" );
128
129$t_menu='<ul class="subsubsub">
130 <li><a href="?page=hotpay-ustawienia" class="current">Content Locker</a> |</li>
131 <li><a href="?page=hotpay-ustawienia®ister=1">Blokowanie rejestracji</a></li>
132
133</ul>';
134
135if(!empty($_GET["register"])){
136$t_menu='<ul class="subsubsub">
137 <li><a href="?page=hotpay-ustawienia" >Content locker</a> |</li>
138 <li><a href="?page=hotpay-ustawienia®ister=1" class="current">Blokowanie rejestracji</a></li>
139</ul>';
140}
141
142
143 echo '
144 <form style="margin-top: 30px;" method="post">
145 <p><span style="font-size: 28px; font-weight: 600;">Klucz API:</span></p>
146 <p style="margin-top: -20px;">(<a target="_BLANK" href="https://hotpay.pl/profil/">Pobierz klucz API</a>)</p>
147 <input type="text" name="api_key" placeholder="API KEY" value="'.$HOTPAY_KEY.'" required/>
148
149 <button type="submit" value="1" name="aktualizuj_key" class="button button-primary">Aktualizuj</button>
150 </form><br>
151'.$t_menu.'
152
153
154<BR><BR>
155';
156
157if(!empty($_GET["register"])){
158
159
160
161
162if(!empty($HOTPAY_KEY)){
163
164
165
166$DANE_HP = file_get_contents('https://api.hotpay.pl/KONTO/lista_uslug.php?api_key='.$HOTPAY_KEY);
167$DANE_HP_JSON =json_decode($DANE_HP,true);
168
169if(!empty($DANE_HP_JSON["uslugi"])){
170
171if(isset($_POST["rejestracja_usluga"]) && isset($_POST["usluga"])){
172
173if(empty($_POST["usluga"])){
174update_option( "hotpay-register-sms", "" );
175update_option( "hotpay-register-numer", "");
176update_option( "hotpay-register-sekret", "" );
177}else{
178
179
180foreach ($DANE_HP_JSON["uslugi"] as &$value) {
181
182if($value["sekret"]==$_POST["usluga"]){
183update_option( "hotpay-register-sms", trim($value["usluga"]) );
184update_option( "hotpay-register-numer", trim($value["numer"]) );
185update_option( "hotpay-register-sekret", trim($value["sekret"]) );
186}
187}
188}
189
190}
191
192
193
194
195$opcje='<option value="0">Wyłącz</option>';
196foreach ($DANE_HP_JSON["uslugi"] as &$value) {
197 if(get_option( "hotpay-register-sekret" )==$value["sekret"]){
198 $opcje.='<option selected value="'.$value["sekret"].'">'.$value["numer"].':'.$value["usluga"].'</option>';
199}else{
200 $opcje.='<option value="'.$value["sekret"].'">'.$value["numer"].':'.$value["usluga"].'</option>';
201}
202
203}
204
205
206echo ' <h1 style="font-weight: 400;">Blokowanie rejestracji</h1>
207 <p style="margin-top: -10px;">Możesz zablokować rejestrację nowych kont na swoim blogu warunkując ją koniecznością wysłania SMSa.</p>
208 <form method="post">
209<select name="usluga">
210'.$opcje.'
211</select>
212<button type="submit" value="1" name="rejestracja_usluga" class="button button-primary">Aktualizuj</button>
213 </form>
214';
215
216}else{
217echo '
218<div class="update-nag">Błędny API KEY lub nie posiadasz jescze żadnych usług</div>
219';
220}
221
222}else{
223echo '
224<div class="update-nag">Błędny API KEY lub nie posiadasz jescze żadnych usług</div>
225';
226}
227
228
229
230
231}else{
232
233
234
235if(!empty($HOTPAY_KEY)){
236
237
238
239$DANE_HP = file_get_contents('https://api.hotpay.pl/KONTO/lista_uslug.php?api_key='.$HOTPAY_KEY);
240$DANE_HP_JSON =json_decode($DANE_HP,true);
241
242if(!empty($DANE_HP_JSON["uslugi"])){
243
244$opcje='';
245foreach ($DANE_HP_JSON["uslugi"] as &$value) {
246 $opcje.='<option value="'.$value["sekret"].'">'.$value["numer"].':'.$value["usluga"].'</option>';
247}
248
249
250if(!empty($_POST["nowa_usluga"]))
251 {
252if(!empty($_POST["usluga"])){
253foreach ($DANE_HP_JSON["uslugi"] as &$value) {
254if($value["sekret"]==$_POST["usluga"]){
255
256$wpdb->insert($wpdb->prefix."hotpay", array(
257 'numer' => $value["numer"],
258 'usluga' => $value["usluga"],
259 'sekret' => $value["sekret"]
260 ));
261}
262
263}
264}
265
266
267 }
268
269
270
271 $querystr = "SELECT * FROM ".$wpdb->prefix."hotpay";
272 $uslugi = $wpdb->get_results($querystr, OBJECT);
273 ?>
274 <div class="wrap">
275 <h1>Content Locker</h1>
276 <p style="margin-top: -5px;">Content Locker to narzędzie pozwalające blokować treść w ramach wpisów i stron. Wszystko co znajdzie się pomiędzy wygenerowanymi poniżej tagami będzie wyświetlone przez system dopiero po wpisaniu prawidłowego kodu wysyłanego przez HotPay SMSem.<br></p>
277
278 <table class="wp-list-table widefat striped">
279 <tr>
280 <td>Usługa</td>
281 <td>Sekret</td>
282 <td>Kod</td>
283 <td>Akcja</td>
284 </tr>
285 <?php
286
287foreach ($uslugi as &$value) {
288 echo '
289<tr>
290<td>'.$value->numer.':'.$value->usluga.'</td>
291<td>'.$value->sekret.'</td>
292<td><textarea style="width: 100%;"> [hidden_content_'.$value->id.']Odblokowana zawartość[/hidden_content_'.$value->id.']</textarea></td>
293<td><form method="post"><button type="submit" value="'.$value->id.'" class="button button-primary">Usuń</button></form></td>
294</tr>
295 ';
296 }
297 ?>
298 </table>
299 <BR><BR>
300 <h1>Nowy Content Locker</h1><BR>
301 <form method="post">
302<select name="usluga">
303<?php echo $opcje;?>
304</select>
305<button type="submit" value="1" name="nowa_usluga" class="button button-primary">Dodaj</button>
306 </form>
307
308
309
310 </div>
311 <?php
312
313}
314
315}else{
316echo '
317<div class="update-nag">Błędny API KEY lub nie posiadasz jescze żadnych usług</div>
318';
319}
320
321
322}
323
324
325
326}
327
328
329
330
331
332
333
334
335
336
337add_filter('the_content', 'podmien_zawartosc');
338
339function podmien_zawartosc($content){
340
341if(is_front_page()){
342 global $wpdb;
343 $querystr = "SELECT * FROM ".$wpdb->prefix."hotpay";
344 $uslugi = $wpdb->get_results($querystr, OBJECT);
345
346
347 foreach ($uslugi as &$value) {
348 $content = preg_replace("%\[hidden_content_".$value->id."\](.*?)\[/hidden_content_".$value->id."\]%s","<B>Płatność dostępna wewnątrz wpisu</B>",$content);
349 }
350 return $content;
351}
352 if ( ! in_the_loop() ) {
353 return $content;
354 }
355
356 if ( ! is_singular() ) {
357
358
359
360 return $content;
361 }
362
363 if ( ! is_main_query() ) {
364
365 return $content;
366 }
367
368
369 if(strpos($content, '[hidden_content')>0){
370
371
372
373 global $wpdb;
374 $querystr = "SELECT * FROM ".$wpdb->prefix."hotpay";
375 $uslugi = $wpdb->get_results($querystr, OBJECT);
376
377
378 foreach ($uslugi as &$value) {
379 $kod_poprawny=false;
380$alert="";
381
382 if(!empty($_POST["hotpay_sprawdz"]) && !empty($_POST["hotpay_kodsms"]))
383 {
384 if($_POST["hotpay_sprawdz"]==$value->id)
385 {
386
387$ch = curl_init();
388curl_setopt($ch, CURLOPT_URL, "https://api.hotpay.pl/check_sms.php?sekret=".$value->sekret."&kod_sms=".$_POST["hotpay_kodsms"]);
389curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
390$wynik = curl_exec($ch);
391curl_close($ch);
392
393$codeInfo = json_decode($wynik);
394
395if($codeInfo->status=="ERROR"){
396
397 $alert='<BR><center style="color:red"><b>Wystąpił problem podczas sprawdzania sms: '.$codeInfo->tresc.'</b></center><BR>';
398}else if($codeInfo->status=="SUKCESS")
399{
400if($codeInfo->aktywacja==1)
401{
402$kod_poprawny=true;
403}
404}
405
406 }
407 }
408 $forma='
409 <div class="col-md-12">'.$alert.'
410 <form method="POST">
411 <center
412 <hr>
413 <h4>Wyślij SMS o treści <span class="label label-primary">'.$value->usluga.'</span> na numer <span class="label label-primary">'.$value->numer.'</span></h4>
414 <hr>
415 <h5>Wpisz kod usługi:</h5>
416
417 <div class="col-md-12">
418 <input value="" placeholder="Kod usługi otrzymany SMSem..." maxlength="100" cols="25" size="100" class="form-control" name="hotpay_kodsms"
419 required="" type="text"><BR><BR>
420 <input required type="checkbox"> Akceptuję <a href="https://hotpay.pl/dokumentacja/regulamin-dla-klientow.pdf">regulamin usługi</a> SMS
421 </div>
422 <BR>
423 <button style="margin-top: 40px;" type="submit" value="'.$value->id.'" name="hotpay_sprawdz" class="btn btn-primary btn-lg">Zweryfikuj kod</button>
424</center>
425 </form>
426 </div>
427 ';
428 if(!$kod_poprawny)
429 {
430 $content = preg_replace("%\[hidden_content_".$value->id."\](.*?)\[/hidden_content_".$value->id."\]%s",$forma,$content);
431 }else{
432 $content = str_replace('[hidden_content_'.$value->id.']', "", $content);
433 $content = str_replace('[/hidden_content_'.$value->id.']', "", $content);
434 }
435
436 }
437
438
439
440
441 }
442 remove_filter( 'the_content', 'se225721_the_content' );
443 return $content;
444}
445
446?>