Skip to content
Newer
Older
100644 139 lines (99 sloc) 2.8 KB
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
1 <?php
2
3 include("include/init.php");
4
5 if (! $GLOBALS['cfg']['enable_feature_flickr_push']){
6 error_disabled();
7 }
8
9 loadlib("flickr_push_subscriptions");
53d8d0b start writing to FlickrSubscriptionsPhotos
straup authored Dec 4, 2011
10 loadlib("flickr_push_photos");
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
11 loadlib("syndication_atom");
12
13 $secret_url = get_str("secret_url");
14
15 if (! $secret_url){
16 error_404();
17 }
18
49bbe22 start recording update types; add update type map
straup authored Dec 21, 2011
19 # error_log("[PARALLEL] updates for {$secret_url}");
20
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
21 $subscription = flickr_push_subscriptions_get_by_secret_url($secret_url);
22
23 if (! $subscription){
49bbe22 start recording update types; add update type map
straup authored Dec 21, 2011
24 # error_log("[PARALLEL] no subscription for {$secret_url}");
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
25 error_404();
26 }
27
28 if ($verify_token = get_str("verify_token")){
29
30 if ($subscription['verify_token'] != $verify_token){
31 error_404();
32 }
33
34 $mode = get_str('mode');
35
36 if ($mode == 'subscribe'){
37
38 $update = array(
39 'verified' => time(),
40 );
41
42 $rsp = flickr_push_subscriptions_update($subscription, $update);
43 }
44
45 else if ($mode == 'unsubscribe'){
46
47 $rsp = flickr_push_subscriptions_delete($subscription);
48
49 if (! $rsp['ok']){
50 error_404();
51 }
52 }
53
54 else {
55 error_404();
56 }
57
58 echo get_str("challenge");
59 exit();
60 }
61
07114e6 comments
straup authored Dec 4, 2011
62 # TO DO: check $subscription['topic_id'] here against
63 # the 'flickr_push_enable_*' flags (20111203/straup)
64
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
65 $xml = file_get_contents('php://input');
66 $atom = syndication_atom_parse_str($xml);
67
53d8d0b start writing to FlickrSubscriptionsPhotos
straup authored Dec 4, 2011
68 $user = users_get_by_id($subscription['user_id']);
69
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
70 $new = 0;
71
72 foreach ($atom->items as $e){
73
8445a14 store faved by information if feed is contacts faves
straup authored Dec 4, 2011
74 # for debugging...
75 # $fh = fopen("/tmp/wtf.json", "w");
76 # fwrite($fh, json_encode($e));
77 # fclose($fh);
78
07114e6 comments
straup authored Dec 4, 2011
79 # TO DO: check $subscription['topic_id'] here because
80 # at some point if we start to use the push stuff to
81 # track things we're backing we'll need to store the
82 # data in another table (20111203/straup)
83
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
84 if (! preg_match("!.*/(\d+)$!", $e['id'], $m)){
85 continue;
86 }
87
88 $photo_id = $m[1];
49bbe22 start recording update types; add update type map
straup authored Dec 21, 2011
89 $update_type = (isset($e['flickr']['update@type'])) ? $e['flickr']['update@type'] : '';
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
90
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
91 $photo = array(
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
92 'photo_id' => $photo_id,
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
93 'owner' => $e['flickr']['author_nsid'],
94 'ownername' => $e['author'],
95 'title' => $e['title'],
96 'updated' => $e['updated'],
97 'photo_url' => $e['media']['atom_content@url'],
98 'thumb_url' => $e['media']['thumbnail@url'],
49bbe22 start recording update types; add update type map
straup authored Dec 21, 2011
99 'update_type' => $update_type,
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
100 );
101
8445a14 store faved by information if feed is contacts faves
straup authored Dec 4, 2011
102 if ($subscription['topic_id'] == 2){
8c03b9c record faved_by username correctly; start polishing foofy CWF display
straup authored Dec 12, 2011
103 $photo['faved_by'] = $e['contributor_name'];
8445a14 store faved by information if feed is contacts faves
straup authored Dec 4, 2011
104 $photo['faved_by_nsid'] = $e['flickr']['contributor_nsid'];
105 }
813f0e0 notes about storing faved by information
straup authored Dec 4, 2011
106
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
107 $enc_photo = json_encode($photo);
53d8d0b start writing to FlickrSubscriptionsPhotos
straup authored Dec 4, 2011
108
109 $photo_data = array(
110 'user_id' => $user['id'],
111 'subscription_id' => $subscription['id'],
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
112 'photo_id' => $photo_id,
53d8d0b start writing to FlickrSubscriptionsPhotos
straup authored Dec 4, 2011
113 'photo_data' => $enc_photo,
114 );
115
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
116 $rsp = flickr_push_photos_record($user, $photo_data);
53d8d0b start writing to FlickrSubscriptionsPhotos
straup authored Dec 4, 2011
117
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
118 if ($rsp['ok']){
119 $new ++;
120 }
49bbe22 start recording update types; add update type map
straup authored Dec 21, 2011
121
122 else {
123 error_log("[PARALLEL] " . var_export($rsp, 1));
124 }
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
125 }
126
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
127 if ($new){
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
128
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
129 $update = array(
130 'last_update' => time(),
131 );
91e3539 actually start to receive subscriptions
straup authored Dec 4, 2011
132
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
133 $rsp = flickr_push_subscriptions_update($subscription, $update);
134 }
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
135
fe525a6 dump recent photos from contacts
straup authored Dec 4, 2011
136 flickr_push_photos_purge();
2a001e0 initial import of flickr_push code; untested and experimental
straup authored Nov 26, 2011
137 exit();
138 ?>
Something went wrong with that request. Please try again.