mailin
Last commit date
css
13 years ago
js
13 years ago
lang
13 years ago
api_form.php
13 years ago
compatibility.php
13 years ago
cron.php
13 years ago
listings.php
13 years ago
mailin.php
13 years ago
mailin_widget.php
13 years ago
mailinapi.class.php
13 years ago
readme.txt
13 years ago
cron.php
141 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Dummy CLI script that loads the WordPress environment |
| 4 | * Author: Thorsten Ott |
| 5 | * Author URI: http://hitchhackerguide.com |
| 6 | */ |
| 7 | set_time_limit( 0 ); |
| 8 | ini_set( "memory_limit", "64M" ); |
| 9 | $_SERVER['HTTP_HOST'] = 'wp_trunk'; // set this to the apache vhost name of your WordPress install |
| 10 | |
| 11 | ob_start(); |
| 12 | $wp_load = '../../../wp-load.php'; |
| 13 | |
| 14 | //STOP CRON EXECUTION WHEN WORDPRESS IS NOT LOADED ON THIS FILE |
| 15 | if(!is_file($wp_load)){ |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | require_once($wp_load); // you need to adjust this to your path |
| 20 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
| 21 | ob_end_clean(); |
| 22 | |
| 23 | |
| 24 | function curl_request($data) { |
| 25 | |
| 26 | $url = 'http://ws.mailin.fr/'; //WS URL |
| 27 | $ch = curl_init(); |
| 28 | |
| 29 | $ndata=''; |
| 30 | |
| 31 | if(is_array($data)){ |
| 32 | |
| 33 | foreach($data AS $key=>$value){ |
| 34 | $ndata .=$key.'='.urlencode($value).'&'; |
| 35 | } |
| 36 | |
| 37 | }else{ |
| 38 | |
| 39 | $ndata=$data; |
| 40 | |
| 41 | } |
| 42 | |
| 43 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); |
| 44 | curl_setopt($ch, CURLOPT_POST ,1); |
| 45 | curl_setopt ($ch, CURLOPT_POSTFIELDS,$ndata); |
| 46 | curl_setopt($ch, CURLOPT_HEADER, 0); |
| 47 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. |
| 48 | curl_setopt($ch, CURLOPT_URL, $url); |
| 49 | $data = curl_exec($ch); |
| 50 | curl_close($ch); |
| 51 | return $data; |
| 52 | } |
| 53 | |
| 54 | $api_key = get_option('mailin_apikey'); |
| 55 | |
| 56 | if($api_key == ''){ |
| 57 | exit; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | function call_server($email, $api_key){ |
| 62 | |
| 63 | $data = array(); |
| 64 | $data['webaction']='DISPLAYUSERDETAIL'; |
| 65 | $data['key']= $api_key; |
| 66 | $data['email'] = $email; |
| 67 | |
| 68 | $return = json_encode(curl_request($data)); |
| 69 | $return = json_decode($return); |
| 70 | return $return; |
| 71 | |
| 72 | } |
| 73 | |
| 74 | function getListUsers($api_key, $list_ids){ |
| 75 | |
| 76 | if($api_key == '') { |
| 77 | return ; |
| 78 | } |
| 79 | |
| 80 | $data = array(); |
| 81 | $data['webaction']='DISPLAYLISTDATABLACK'; |
| 82 | $data['key']=$api_key; |
| 83 | |
| 84 | $data['listids']= $list_ids; |
| 85 | |
| 86 | $return = curl_request($data); |
| 87 | $return = json_decode($return); |
| 88 | |
| 89 | return $return; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | |
| 94 | global $wpdb; |
| 95 | $table = $wpdb->prefix."mailin_subscribers "; |
| 96 | |
| 97 | |
| 98 | $api_key = get_option('mailin_apikey'); |
| 99 | |
| 100 | $lists = get_option('mailin_lists'); |
| 101 | $lists = unserialize($lists); |
| 102 | |
| 103 | $final_data = array(); |
| 104 | foreach($lists as $data){ |
| 105 | $final_data[] = $data->id; |
| 106 | } |
| 107 | |
| 108 | $list_ids = ''; |
| 109 | if(!empty($final_data)){ |
| 110 | $list_ids = implode('|' , $final_data); |
| 111 | } |
| 112 | |
| 113 | if($list_ids == ''){ |
| 114 | return ; |
| 115 | } |
| 116 | |
| 117 | $list_users = getListUsers($api_key , $list_ids); |
| 118 | |
| 119 | |
| 120 | if(!empty($list_users->result)){ |
| 121 | |
| 122 | foreach($list_users->result as $key=>$lists){ |
| 123 | |
| 124 | if(!empty($lists)){ |
| 125 | |
| 126 | foreach($lists as $users){ |
| 127 | |
| 128 | if(isset($users->blacklisted)){ |
| 129 | |
| 130 | if($users->blacklisted == '1'){ |
| 131 | $sql = "UPDATE ".$table." SET subscribed = '0' WHERE email = '".strtolower(trim($users->email))."' " ; |
| 132 | }else{ |
| 133 | $sql = "UPDATE ".$table." SET subscribed = '1' WHERE email = '".strtolower(trim($users->email))."' " ; |
| 134 | } |
| 135 | $myrows = $wpdb->query($sql); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 |