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 retrieve() { global $wpdb, $_wt_options; $id = $this->id; $data = null; if ($id) { $data = $wpdb->get_results($wpdb->prepare("SELECT \n\t\t\t\t* \n\t\t\t\tFROM " . WORDTOUR_EVENTS . " AS e \n\t\t\t\tLEFT JOIN " . WORDTOUR_VENUES . " AS v \n\t\t\t\tON e.event_venue_id = v.venue_id \n\t\t\t\tLEFT JOIN " . WORDTOUR_ARTISTS . " AS a\n\t\t\t\tON e.event_artist_id = a.artist_id \n\t\t\t\tLEFT JOIN " . WORDTOUR_TOUR . " AS t\n\t\t\t\tON e.event_tour_id = t.tour_id \n\t\t\t\tLEFT JOIN " . WORDTOUR_EVENTS_META . " AS m ON e.event_meta_id = m.meta_id\n\t\t\t\tWHERE e.event_id = {$id} ORDER BY id ASC"), "ARRAY_A"); if (is_array($data)) { $event = $data[0]; $event["event_more_artists"] = array(); foreach ($data as $e) { if (!$e["event_is_headline"]) { $event["event_more_artists"][] = array("id" => $e["artist_id"], "name" => $e["artist_name"]); } } $event_wpdb = clone $wpdb; $this->meta_id = $event["event_meta_id"]; $social = new WT_Social(); $fbstatus = $social->get_by_event($this->id, "fbstatus"); $ebstatus = $social->get_by_event($this->id, "ebevent"); $fbevent = $social->get_by_event($this->id, "fbevent"); $twitter = $social->get_by_event($this->id, "twitter"); $post = $social->get_by_event($this->id, "post"); $data = array_merge($data, array("post_ref_id" => $post ? admin_url("post.php?action=edit&post={$post['social_ref_id']}") : 0, "facebook_event_id" => $fbevent ? $fbevent["social_ref_id"] : 0, "twitter_status_date" => $twitter ? $twitter["social_publish_time"] : 0, "facebook_status_date" => $fbstatus ? $fbstatus["social_publish_time"] : 0, "eventbrite_status_date" => $ebstatus ? $ebstatus["social_publish_time"] : 0, "eventbrite_event_id" => $ebstatus ? $ebstatus["social_ref_id"] : 0)); $event["event_thumbnail"] = get_attachment_data($this->get_thumbnail("event")); $event["event_videos"] = $this->get_videos("event"); $event["event_gallery"] = $this->get_gallery("event"); $event["event_category"] = $this->get_category("event"); $event["event_genre"] = $this->get_genre("event"); } } //$this->db_result("error",$event_wpdb,array("msg"=>"Can't retrieve event(<i>Missing event id</i>)")); return parent::retrieve($event); }
<textarea name="twitter_status" id="twitter_status"><?php echo $status; ?> </textarea> </div> </div> <?php wt_static_panel_end(); ?> <?php wt_dynamic_panel_start(array("title" => "History"), "", 1); ?> <div> <?php $social = new WT_Social(); $social_status_history = $social->query("social_parent_id={$event_id}&social_parent_type=event&social_type=twitter&order=social_publish_time&limit=5", WORDTOUR_SOCIAL); if ($social_status_history) { foreach ($social_status_history as $h) { $h = $social->db_out($h); echo "<div style='border-bottom: 1px solid #EEEEEE;padding:5px;'>Status was updated on " . $h["social_publish_time"] . "</div>"; } } else { echo "No History"; } ?> </div> <?php wt_dynamic_panel_end(); ?>
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); }
$eventbrite = new WT_Eventbrite(); $eb_id = $eventbrite->save_event($_POST); try { $r = $eventbrite->response; if ($r["error"]) { if ($r["error"]["error_type"] == "Region error") { $r["error"]["error_message"] = $r["error"]["error_message"] . "<br/>Refer to the venue administration page, could be because venue is missing a state value"; } if ($r["error"]["error_type"] == "Not Found") { $r["error"]["error_message"] = $r["error"]["error_message"] . "<br/>Event dosn't exist in Eventbrite, Please try again"; } echo json_encode(array("type" => "error", "msg" => "Error publishing event to eventbrite:<p>" . $r["error"]["error_message"] . " (" . $r["error"]["error_type"] . ")</p>")); exit; } else { if ($r["process"]) { $social = new WT_Social(); $social_row = $social->get_by_event($_POST["eventbrite_event_id"], "ebevent"); echo json_encode(array("type" => "success", "url" => "http://www.eventbrite.com/myevent?eid={$eb_id}", "tickets" => "http://www.eventbrite.com/event/{$eb_id}", "publish_date" => WT_DBPrepere::datetime_short_out($social_row["social_publish_time"]), "eventbrite" => $r)); exit; } } } catch (Exception $e) { } echo json_encode(array("type" => "error", "msg" => "Error connecting to Eventbrite, Please try again later")); break; case "import-eventbrite-events": $eventbrite = new WT_Eventbrite(); $eventbrite->import($_POST["artist_id"]); echo json_encode($eventbrite->response); break; // GENERAL