Beispiel #1
0
 public function update($values)
 {
     if ($this->validate($values, self::NONCE_INSERT)) {
         $update = wp_insert_post(array("post_title" => $values["post_title"], "post_content" => "[wordtour_event id='{$values['post_event_id']}']", "post_status" => 'publish', 'post_type' => "post"), 0);
         if ($update) {
             $social = new WT_Social();
             $social->insert(wp_create_nonce(WT_SOCIAL::NONCE_INSERT), "post", $values["post_event_id"], $update);
             $result = $social->db_result["result"];
             $result["post_link"] = admin_url("post.php?action=edit&post={$update}");
             $this->db_result("success", null, array("msg" => "Post was added succefully", "result" => $result));
         } else {
             $this->db_result("error", null, array("msg" => "Error adding Post, please try again"));
         }
     }
     return false;
 }
 public function import($artist_id = 0)
 {
     $results = array();
     if (!$artist_id || empty($artist_id)) {
         $this->is_valid_response('{"error": {"error_type": "Artist Missing", "error_message": "Can\\"t import events without an artist"}}');
     } else {
         // get list of all venues
         $venues = wt_file_get_contents("http://www.eventbrite.com/json/user_list_venues?app_key={$this->app_key}&user_key={$this->user_key}");
         $venues_parents = array();
         if ($this->is_valid_response($venues)) {
             $social = new WT_Social();
             try {
                 if (!$this->response["venues"]) {
                     throw new Exception("Connection Error");
                 }
                 foreach ($this->response["venues"] as $v) {
                     $venue_id = 0;
                     $social_regist = $social->get_by_ref_id($v["venue"]["id"], "venue", "ebvenue");
                     if (!$social_regist) {
                         $venue_params = array("_nonce" => wp_create_nonce(WT_Venue::NONCE_INSERT), "venue_name" => $v["venue"]["name"], "venue_city" => $v["venue"]["city"], "venue_country" => get_country_by_code($v["venue"]["country_code"]), "venue_state" => get_state_by_code($v["venue"]["region"]), "venue_zip" => $v["venue"]["postal_code"], "venue_address" => $v["venue"]["address"], "venue_tour_status" => 1, "venue_gallery_status" => 1, "venue_video_status" => 1, "venue_flickr_status" => 1, "venue_post_status" => 1);
                         $venue = new WT_Venue();
                         $venue->insert($venue_params, 0);
                         if ($venue->data) {
                             $venue_id = $venue->data["venue_id"];
                             $social->insert(wp_create_nonce(WT_SOCIAL::NONCE_INSERT), "ebvenue", $venue->data["venue_id"], $v["venue"]["id"], "venue");
                         } else {
                             $results["venues"][] = array("venue" => $v["venue"], "msg" => $venue->db_response());
                         }
                     } else {
                         $venue_id = $social_regist["social_parent_id"];
                     }
                     if ($venue_id) {
                         $venues_parents[$v["venue"]["id"]] = $venue_id;
                     }
                 }
                 $events = wt_file_get_contents("http://www.eventbrite.com/json/user_list_events?app_key={$this->app_key}&user_key={$this->user_key}");
                 if ($this->is_valid_response($events)) {
                     if (!$this->response["events"]) {
                         throw new Exception("Connection Error");
                     }
                     foreach ($this->response["events"] as $e) {
                         if ($e["event"]["status"] != "Canceled") {
                             $social_regist = $social->get_by_ref_id($e["event"]["id"], "event", "ebevent");
                             if (!$social_regist) {
                                 $event_params = array("_nonce" => wp_create_nonce(WT_Event::NONCE_INSERT), "event_title" => $e["event"]["title"], "event_notes" => $e["event"]["description"], "event_start_date" => mysql2date("Y-m-d", $e["event"]["start_date"]), "event_start_time" => mysql2date("H:i:s", $e["event"]["start_date"]), "event_end_date" => mysql2date("Y-m-d", $e["event"]["end_date"]), "event_end_time" => mysql2date("H:i:s", $e["event"]["end_date"]), "event_venue_id" => $venues_parents[$e["event"]["venue"]["id"]], "event_artist_id" => $artist_id, "event_published" => 1, 'event_status' => $e["event"]["status"] == "Canceled" ? "cancelled" : "active", "tkts_url" => $e["event"]["url"], "tkts_price" => $e["ticket"]["price"] . $e["ticket"]["currency"], 'comment_status' => 1, 'rsvp_status' => 1, 'gallery_status' => 1, 'flickr_status' => 1, 'post_status' => 1, 'video_status' => 1);
                                 $event = new WT_Event();
                                 $event->insert($event_params, 0);
                                 if ($event->data) {
                                     $event_id = $event->data["event_id"];
                                     $social->insert(wp_create_nonce(WT_SOCIAL::NONCE_INSERT), "ebevent", $event->data["event_id"], $e["event"]["id"], "event");
                                 } else {
                                     $results["events"][] = array("event" => $e["event"], "msg" => $event->db_response());
                                 }
                             }
                         }
                     }
                     $this->response = array("type" => "success", "log" => $results);
                     return 1;
                 }
             } catch (Exception $e) {
                 $this->is_valid_response(0);
             }
         }
     }
     $this->response = array("type" => "error", "log" => $this->response);
 }