Beispiel #1
0
     } else {
         $link = $r["entry"];
     }
 } elseif ($r["table"] == "bigtree_users") {
     if (!isset($user_cache[$r["entry"]])) {
         $user_cache[$r["entry"]] = $admin->getUser($r["entry"]);
     }
     $user = $user_cache[$r["entry"]];
     if ($user) {
         $link = '<a target="_blank" href="' . ADMIN_ROOT . 'users/edit/' . $user["id"] . '/">' . $user["name"] . '</a>';
     } else {
         $link = 'Deleted User: '******'<a target="_blank" href="' . $form_link . $r["entry"] . '/">View Entry (id: ' . $r["entry"] . ')</a>';
     } else {
         $link = $r["entry"] . " (Unknown Form)";
     }
 }
 static function sync($id = false)
 {
     if ($id) {
         $q = sqlquery("SELECT * FROM btx_social_feed_queries WHERE id = '" . sqlescape($id) . "' ORDER BY service");
     } else {
         $q = sqlquery("SELECT * FROM btx_social_feed_queries ORDER BY service");
     }
     while ($f = sqlfetch($q)) {
         // Twitter
         if ($f["service"] == "Twitter") {
             $twitter = isset($twitter) ? $twitter : new BigTreeTwitterAPI();
             $params = array();
             if (self::$IgnoreRetweets) {
                 $params["include_rts"] = false;
             }
             if (self::$IgnoreReplies) {
                 $params["exclude_replies"] = true;
             }
             if ($f["type"] == "Person") {
                 self::syncData($f, "Twitter", $twitter->getUserTimeline($f["query"], self::$SyncCount, $params));
             } elseif ($f["type"] == "Hashtag") {
                 self::syncData($f, "Twitter", $twitter->searchTweets("#" . ltrim(trim($f["query"]), "#"), self::$SyncCount, "recent", false, false, false, $params));
             } elseif ($f["type"] == "Search") {
                 self::syncData($f, "Twitter", $twitter->searchTweets(trim($f["query"]), self::$SyncCount, "recent", false, false, false, $params));
             }
             // Instagram
         } elseif ($f["service"] == "Instagram") {
             $instagram = isset($instagram) ? $instagram : new BigTreeInstagramAPI();
             if ($f["type"] == "Person") {
                 self::syncData($f, "Instagram", $instagram->getUserMedia($f["query"], self::$SyncCount));
             } elseif ($f["type"] == "Hashtag") {
                 self::syncData($f, "Instagram", $instagram->getTaggedMedia(trim($f["query"])));
             } elseif ($f["type"] == "Location") {
                 $query = json_decode($f["query"], true);
                 // Instagram uses meters, so we convert the default miles to meters
                 $radius = is_numeric($query["radius"]) ? $query["radius"] : floor(self::$DefaultLocationRadius * 1609.34);
                 self::syncData($f, "Instagram", $instagram->searchMedia($query["latitude"], $query["longitude"], $radius));
             }
             // Google+
         } elseif ($f["service"] == "Google+") {
             $gplus = isset($gplus) ? $gplus : new BigTreeGooglePlusAPI();
             if ($f["type"] == "Person") {
                 self::syncData($f, "Google+", $gplus->getActivities($f["query"], self::$SyncCount));
             } elseif ($f["type"] == "Search") {
                 self::syncData($f, "Google+", $gplus->searchActivities($f["query"], self::$SyncCount, "recent"));
             }
             // YouTube
         } elseif ($f["service"] == "YouTube") {
             $youtube = isset($youtube) ? $youtube : new BigTreeYouTubeAPI();
             if ($f["type"] == "Person") {
                 self::syncData($f, "YouTube", $youtube->getChannelVideos($f["query"], self::$SyncCount));
             } elseif ($f["type"] == "Search") {
                 self::syncData($f, "YouTube", $youtube->searchVideos($f["query"], self::$SyncCount, "date"));
             }
             // Flickr
         } elseif ($f["service"] == "Flickr") {
             $flickr = isset($flickr) ? $flickr : new BigTreeFlickrAPI();
             if ($f["type"] == "Person") {
                 self::syncData($f, "Flickr", $flickr->getPhotosForPerson($f["query"], self::$SyncCount));
             } elseif ($f["type"] == "Search") {
                 self::syncData($f, "Flickr", $flickr->searchPhotos($f["query"], self::$SyncCount));
             } elseif ($f["type"] == "Location") {
                 $query = json_decode($f["query"], true);
                 $radius = is_numeric($query["radius"]) ? $query["radius"] : self::$DefaultLocationRadius;
                 self::syncData($f, "Flickr", $flickr->getPhotosByLocation($query["latitude"], $query["longitude"], $radius, "mi", self::$SyncCount));
             }
         } elseif ($f["service"] == "Facebook") {
             $facebook = isset($facebook) ? $facebook : new BigTreeFacebookAPI();
             if ($f["type"] == "Page") {
                 // Look up info on the page first to get username
                 $user_response = $facebook->callUncached($f["query"] . "?fields=username,link");
                 // Get posts
                 $response = $facebook->callUncached($f["query"] . "/posts?fields=id,message,type,picture,link,actions,created_time,updated_time&limit=" . self::$SyncCount);
                 // We're going to emulate the response from the more mature APIs
                 $data = new stdClass();
                 $data->Results = array();
                 foreach ($response->data as $item) {
                     $result = new stdClass();
                     $result->ID = $item->id;
                     $result->Link = $item->link;
                     $result->Message = $item->message;
                     $result->PageLink = $user_response->link;
                     $result->PageUsername = $user_response->username;
                     $result->Picture = $item->picture;
                     $result->Type = $item->type;
                     $result->URL = $item->actions[0]->link;
                     $result->CreatedAt = date("Y-m-d H:i:s", strtotime($item->created_time));
                     $result->UpdatedAt = date("Y-m-d H:i:s", strtotime($item->updated_time));
                     $data->Results[] = $result;
                 }
                 self::syncData($f, "Facebook", $data);
             }
         }
     }
     // Get view information for manually caching the records
     $view = BigTreeAutoModule::getViewForTable("btx_social_feed_stream");
     $parsers = array();
     foreach ($view["fields"] as $key => $field) {
         if ($field["parser"]) {
             $parsers[$key] = $field["parser"];
         }
     }
     foreach (self::$ItemsToCache as $i) {
         BigTreeAutoModule::cacheRecord($i, $view, $parsers, array(), $i);
     }
 }