Пример #1
0
 /**
  * process the mailchimp signup
  *
  * @return Norcrossv4
  */
 public function music_signup()
 {
     $MC_KEY = akm_get_key('MC_KEY');
     $MC_LIST = akm_get_key('MC_LIST');
     $apikey = $MC_KEY;
     $list_id = $MC_LIST;
     $method = 'listSubscribe';
     $email = $_POST['email'];
     $request = new WP_Http();
     $url = 'http://us1.api.mailchimp.com/1.3/?method=' . $method . '&apikey=' . $apikey . '&id=' . $list_id . '&email_address=' . $email . '&double_optin=false&output=json';
     $response = wp_remote_get($url);
     $ret = array();
     check_ajax_referer('rkv_nonce', 'nonce');
     if (is_wp_error($response)) {
         $ret['success'] = false;
         $ret['message'] = 'There was an error with your request. Please try again.';
         echo json_encode($ret);
         die;
     } else {
         $return = $response['body'];
         $data = json_decode($return);
     }
     // now process the actual return
     if (isset($data->error)) {
         $ret['success'] = false;
         $ret['message'] = $data->error;
     }
     if (isset($data->code) && $data->code === 214) {
         $ret['success'] = false;
         $ret['errcode'] = 'EMAIL_EXISTS';
         $ret['message'] = $data->error;
         $ret['display'] = $this->back_issues();
     }
     if ($data === true) {
         $ret['success'] = true;
         $ret['message'] = 'Success! Welcome to the club. Care to peruse the back issues?';
         $ret['display'] = $this->back_issues();
     }
     echo json_encode($ret);
     die;
 }
Пример #2
0
 /**
  * run cron for instagram
  *
  * @return Norcrossv4
  */
 public function run_insta_cron()
 {
     $args = array('sslverify' => false);
     // grab username and total photos to grab
     $user = akm_get_key('IG_USER');
     $token = akm_get_key('IG_TOKEN');
     $count = 60;
     // set number of items to return
     if (!empty($number)) {
         $max = $number;
     } else {
         $max = 60;
     }
     // 60 is the max return in the Instagram API
     $request = new WP_Http();
     $url = 'https://api.instagram.com/v1/users/self/media/recent?access_token=' . $token . '&count=' . $count . '';
     $response = wp_remote_get($url, $args);
     $data_array = json_decode($response['body']);
     $photos = $data_array->data;
     // loop through each gist and create a post
     foreach ($photos as $photo) {
         $photo_id = $photo->created_time;
         $photo_check = $this->insta_check();
         if (!in_array($photo_id, $photo_check)) {
             $stamp = $photo_id - 18000;
             $pubdt = date('Y-m-d H:i:s', $stamp);
             // make caption with fallback
             $caption_base = $photo->caption;
             $image_caption = empty($caption_base->text) ? '' : $caption_base->text;
             $image_caption = str_replace('@', '', $image_caption);
             // build new photo array
             $snapshot = array('post_type' => 'photos', 'post_title' => $photo_id, 'post_name' => $photo_id, 'post_content' => $image_caption, 'post_excerpt' => '', 'post_status' => 'publish', 'post_author' => 1, 'post_date' => $pubdt);
             // add the post to the database
             $new_photo = wp_insert_post($snapshot, true);
             // add some postmeta
             if (!is_wp_error($new_photo)) {
                 // build thumbnail  150px
                 $thumb_base = $photo->images->thumbnail;
                 $thumb_url = $thumb_base->url;
                 // build standard  306px
                 $standard_base = $photo->images->low_resolution;
                 $standard_url = $standard_base->url;
                 // build fullsize  612px
                 $fullsize_base = $photo->images->standard_resolution;
                 $fullsize_url = $fullsize_base->url;
                 // now make some meta
                 add_post_meta($new_photo, '_rkv_photo_id', $photo_id);
                 add_post_meta($new_photo, '_rkv_photo_thumb', $thumb_url);
                 add_post_meta($new_photo, '_rkv_photo_stand', $standard_url);
                 add_post_meta($new_photo, '_rkv_photo_full', $fullsize_url);
                 $this->insta_helper($new_photo);
             }
         }
         // end the array comparison
     }
     // end the foreach
 }