Permalink
Browse files

r2375@opsdev009 (orig r115888): ntucker | 2008-08-13 14:46:53 -0700

 Added app that tests events APIs to public svn
  • Loading branch information...
1 parent 797b37a commit f04e31368e7a39a99006575871890ec39ecde250 (no author) committed Aug 13, 2008
Showing with 195 additions and 0 deletions.
  1. +30 −0 samples/events/cancel.php
  2. +102 −0 samples/events/common.php
  3. +17 −0 samples/events/create.php
  4. +25 −0 samples/events/edit.php
  5. +21 −0 samples/events/index.php
View
@@ -0,0 +1,30 @@
+<?php
+include_once 'common.php';
+
+if (!isset($_GET['eid'])) {
+ echo "Which event???";
+ return;
+}
+$eid=$_GET['eid'];
+if (isset($_POST['cancel_eid'])) {
+ try {
+ if ($facebook->api_client->events_cancel($_POST['cancel_eid'],$_POST['cancel_message'])) {
+ echo "Event successfully cancelled.";
+ } else {
+ echo "Event cancellation failed.";
+ }
+ } catch (Exception $e) {
+ handle_exception($e);
+ return;
+ }
+} else {
+?>
+<form method="post">
+<input type="hidden" name="cancel_eid" value="<?php echo $eid ?>" />
+<input type="hidden" value="cancel" name="cancel" /><input type="text" name="cancel_message" />
+<input type="submit" value="cancel" />
+</form>
+<?php
+}
+ ?>
+<a href="index.php">Manage events</a>
View
@@ -0,0 +1,102 @@
+<?php
+include_once './client/facebook.php';
+
+// Get these from http://developers.facebook.com
+$api_key = '';
+$secret = '';
+
+$facebook = new Facebook($api_key, $secret);
+$facebook->api_client->server_addr="http://api.new.facebook.com/restserver.php";
+//$facebook->require_frame();
+//$user = $facebook->require_login();
+
+foreach ($_POST as $key => $value) {
+ if (!strncmp($key,"fb_",3)) {
+ unset($_POST[$key]);
+ }
+}
+
+
+function handle_exception($e) {
+ if ($e->getCode()===FacebookAPIErrorCodes::API_EC_PERMISSION_EVENT) {
+ $facebook->redirect('http://www.new.facebook.com/authorize.php?api_key='.$api_key.'&v=1.0&ext_perm=create_event');
+ } else {
+ echo $e->getMessage();
+ }
+}
+
+function render_create() {
+ render_event_helper(0);
+}
+function render_edit($eid) {
+ render_event_helper($eid);
+}
+function render_event_helper($eid) {
+ global $facebook;
+ $dformat = 'm/d/Y h:i:a';
+ $format = '%m/%d/%Y %I:%M:%p';
+ $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "December");
+ if (!empty($eid)) {
+ echo "<h3>EID: ".$eid."</h3>";
+ try {
+ $event_info=$facebook->api_client->events_get($user,$eid);
+ if (empty($event_info)) {
+ echo $event_info."<br />";
+ } else {
+ $event_info=$event_info[0];
+ foreach($event_info as $key=>$value) {
+ echo '<div>'.$key.': '.$value.'</div>';
+ }
+ }
+ echo '<a href="cancel.php?eid=' . $eid . '">Cancel</a> | <a href="./">Manage Events</a>';
+ } catch (Exception $e) {
+ echo $e->getMessage();
+ return;
+ }
+ $event_info['city'] = $event_info['venue']['city'];
+ unset($event_info['venue']);
+ $event_info['category'] = 1;unset($event_info['event_type']);
+ $event_info['subcategory'] = 1;unset($event_info['event_subtype']);
+ $event_info['start_time'] = strptime(date($dformat, $event_info['start_time']), $format);
+ $event_info['end_time'] = strptime(date($dformat, $event_info['end_time']), $format);
+ unset($event_info['creator']);unset($event_info['update_time']);unset($event_info['eid']);
+ } else {
+ $event_info = array('name' => 'name',
+ 'category' => '1',
+ 'subcategory' => '1',
+ 'host' => 'host',
+ 'location' => 'location',
+ 'city' => 'Palo Alto',
+ 'start_time' => strptime(date($dformat), $format),
+ 'end_time' => strptime(date($dformat), $format));
+ }
+ echo '<style type="text/css">label { display:block; }</style><form method="post">';
+ if (!empty($eid)) echo '<input type="hidden" name="eid" value="'.$eid.'" />';
+ foreach ($event_info as $key => $value) {
+ if (is_array($value)) {
+ echo '<label>'.ucfirst($key);
+ echo '<select autocomplete="off" id="'.$key.'_month" name="'.$key.'_month">';
+ foreach ($months as $index => $month) {
+ echo '<option value="'.$index.'"'.($index===$value['tm_mon']?' selected="selected"':'').'>'.$month.'</option>';
+ }
+ echo '</select><select autocomplete="off" id="'.$key.'_day" name="'.$key.'_day">';
+ for ($i=1; $i<32; $i++) {
+ echo '<option value="'.$i.'"'.($i===$value['tm_mday']?' selected="selected"':'').'>'.$i.'</option>';
+ }
+ echo '</select><span> at </span> <select id="'.$key.'_hour" name="'.$key.'_hour">';
+ for ($i=0; $i<12; $i++) {
+ echo '<option value="'.$i.'"'.($i===($value['tm_hour']%12)?' selected="selected"':'').'>'.$i.'</option>';
+ }
+ echo '</select>: <select id="'.$key.'_min" name="'.$key.'_min">';
+ for ($i=0; $i<60; $i++) {
+ echo '<option value="'.$i.'"'.($i===$value['tm_min']?' selected="selected"':'').'>'.$i.'</option>';
+ }
+ echo '</select> <select id="'.$key.'_ampm" name="'.$key.'_ampm"><option value="am"'.(floor($value['tm_hour']/12)==0?' selected="selected"':'').'>am</option><option value="pm"'.(floor($value['tm_hour']/12)==1?' selected="selected"':'').'>pm</option></select></label>'."\n\n";
+ } else {
+ echo '<label>'.ucfirst($key).' <input type="text" name="'.$key.'" id="'.$key.'" value="'.$value.'" /></label>'."\n\n";
+ }
+ }
+ echo '<input type="submit" value="'.(empty($eid)?'Create Event':'Edit Event').'" /></form>';
+}
+
+?>
View
@@ -0,0 +1,17 @@
+<?php
+include_once 'common.php';
+
+if (isset($_POST['name'])) {
+ $_POST['start_time']=mktime($_POST['start_time_hour']+($_POST['start_time_ampm']==="pm"?12:0),$_POST['start_time_min'],0,$_POST['start_time_month'],$_POST['start_time_day']);
+ $_POST['end_time']=mktime($_POST['end_time_hour']+($_POST['end_time_ampm']==="pm"?12:0),$_POST['end_time_min'],0,$_POST['end_time_month'],$_POST['end_time_day']);
+ try {
+ $eid=$facebook->api_client->events_create(json_encode($_POST));
+ $facebook->redirect('edit.php?eid=' . $eid);
+ } catch (Exception $e) {
+ handle_exception($e);
+ return;
+ }
+}
+
+render_create();
+?>
View
@@ -0,0 +1,25 @@
+<?php
+include_once 'common.php';
+
+if (!isset($_GET['eid'])) {
+ echo "Which event???";
+ return;
+}
+$eid=$_GET['eid'];
+if (isset($_POST['name'])) {
+ $_POST['start_time']=mktime($_POST['start_time_hour']+($_POST['start_time_ampm']==="pm"?12:0),$_POST['start_time_min'],0,$_POST['start_time_month'],$_POST['start_time_day']);
+ $_POST['end_time']=mktime($_POST['end_time_hour']+($_POST['end_time_ampm']==="pm"?12:0),$_POST['end_time_min'],0,$_POST['end_time_month'],$_POST['end_time_day']);
+ try {
+ if ($facebook->api_client->events_edit($eid,json_encode($_POST))) {
+ echo "Event successfully edited.";
+ } else {
+ echo "Event edit failed.";
+ }
+ } catch (Exception $e) {
+ handle_exception($e);
+ return;
+ }
+}
+
+render_edit($eid);
+?>
View
@@ -0,0 +1,21 @@
+<?php
+include_once 'common.php';
+
+
+try {
+ $event_info=$facebook->api_client->events_get();
+
+ if (empty($event_info)) {
+ echo $event_info."<br />";
+ } else {
+ foreach ($event_info as $index=>$event) {
+ echo '<div><a href="edit.php?eid='.$event['eid'].'">'.$event['name'].'</a></div>';
+ }
+ }
+} catch (Exception $e) {
+ echo $e->getMessage();
+ return;
+}
+
+?>
+<a href="create.php">Create Event</a>

0 comments on commit f04e313

Please sign in to comment.