Ejemplo n.º 1
0
 public function doImport()
 {
     global $bp, $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     $itemCounter = 0;
     $user_metas = $wpdb->get_results("SELECT user_id\n                        FROM {$wpdb->usermeta} WHERE\n                        meta_key='bs_flickr_username'\n                        ORDER BY meta_value;");
     if ($user_metas) {
         foreach ($user_metas as $user_meta) {
             //check for daylimit
             $limitReached = $buddyStreamFilters->limitReached('flickr', $user_meta->user_id);
             if (!$limitReached && get_user_meta($user_meta->user_id, 'bs_flickr_username', 1)) {
                 $items = null;
                 //get the user id
                 $url = 'http://api.flickr.com/services/rest/?method=flickr.urls.lookupuser&api_key=' . get_site_option("bs_flickr_api_key") . '&url=' . urlencode('http://www.flickr.com/photos/' . get_user_meta($user_meta->user_id, 'bs_flickr_username', 1));
                 $buddystreamCurl = new BuddyStreamCurl();
                 $curlContent = $buddystreamCurl->getContentFromUrl($url);
                 $response = simplexml_load_string($curlContent);
                 //get the photos
                 $photosUrl = 'http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=' . get_site_option("bs_flickr_api_key") . '&user_id=' . $response->user['id'] . "&extras=date_upload,url_m,url_t,description";
                 $curlContent = $buddystreamCurl->getContentFromUrl($photosUrl);
                 $items = simplexml_load_string($curlContent);
                 if ($items->photos->photo) {
                     foreach ($items->photos->photo as $item) {
                         //check daylimit
                         $limitReached = $buddyStreamFilters->limitReached('flickr', $user_meta->user_id);
                         if (!$limitReached) {
                             if (!$item['title'] or empty($item['title'])) {
                                 $item['title'] = "";
                             }
                             if (!$item['description'] or empty($item['description'])) {
                                 $item['description'] = "";
                             }
                             $content = '<a href="' . $item["url_m"] . '" class="bs_lightbox" id="' . $item['id'] . '" title="' . $item['title'] . '"><img src="' . $item["url_t"] . '" title="' . $item["title"] . '"></a> ' . $item["title"] . " " . $item["description"];
                             $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'flickr', 'type' => 'Flickr photo', 'content' => $content, 'item_id' => $item['id'], 'raw_date' => gmdate('Y-m-d H:i:s', (int) $item["dateupload"]), 'actionlink' => 'http://www.flickr.com/photos/' . $item["owner"]));
                             if ($returnCreate) {
                                 $itemCounter++;
                             }
                         }
                     }
                 } else {
                     if ($items->err) {
                         delete_user_meta($user_meta->user_id, 'bs_flickr_username');
                     }
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("Flickr imported " . $itemCounter . " photo's for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
Ejemplo n.º 2
0
 public function doImport()
 {
     global $bp, $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     $itemCounter = 0;
     $user_metas = $wpdb->get_results("SELECT user_id\n                        FROM {$wpdb->usermeta} WHERE\n                        meta_key='buddystream_vimeo_username'\n                        ORDER BY meta_value;");
     if ($user_metas) {
         foreach ($user_metas as $user_meta) {
             //check for daylimit
             $limitReached = $buddyStreamFilters->limitReached('vimeo', $user_meta->user_id);
             if (!$limitReached && get_user_meta($user_meta->user_id, 'buddystream_vimeo_username', 1)) {
                 $url = 'http://vimeo.com/api/v2/' . get_user_meta($user_meta->user_id, 'buddystream_vimeo_username', 1) . '/videos.xml';
                 $buddystreamCurl = new BuddyStreamCurl();
                 $curlContent = $buddystreamCurl->getContentFromUrl($url);
                 $sxml = simplexml_load_string($curlContent);
                 if ($sxml) {
                     foreach ($sxml as $item) {
                         $max = $buddyStreamFilters->limitReached('vimeo', $user_meta->user_id);
                         if (!$max) {
                             $description = "";
                             $description = strip_tags($item->description);
                             if (strlen($description) > 400) {
                                 $description = substr($description, 0, 400) . "... <a href='" . $item->url . "'>read more</a>";
                             }
                             $content = '<a href="http://player.vimeo.com/video/' . $item->id . '" class="bs_lightbox" title="' . $item->title . '"><img src="' . $item->thumbnail_small . '"></a><b>' . $item->title . '</b> ' . $description;
                             //pre convert date
                             $ts = strtotime($item->upload_date);
                             $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'vimeo', 'type' => 'Vimeo video', 'content' => $content, 'item_id' => 'vimeo_' . $item->id, 'raw_date' => date("Y-m-d H:i:s", $ts), 'actionlink' => 'http://www.vimeo.com/' . get_user_meta($user_meta->user_id, 'buddystream_vimeo_username', 1)));
                             if ($returnCreate) {
                                 $itemCounter++;
                             }
                         }
                     }
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("Vimeo imported " . $itemCounter . " video's for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
Ejemplo n.º 3
0
 public function doImport()
 {
     global $bp, $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     $itemCounter = 0;
     $user_metas = $wpdb->get_results("SELECT user_id\n                        FROM {$wpdb->usermeta} WHERE\n                        meta_key='bs_lastfm_username'\n                        ORDER BY meta_value;");
     if ($user_metas) {
         foreach ($user_metas as $user_meta) {
             //always start with import = true
             $import = true;
             //check daylimit
             $max = $buddyStreamFilters->limitReached('lastfm', $user_meta->user_id);
             if (!$max && $import && get_user_meta($user_meta->user_id, 'bs_lastfm_username', 1)) {
                 $url = 'http://ws.audioscrobbler.com/2.0/user/' . get_user_meta($user_meta->user_id, 'bs_lastfm_username', 1) . '/recenttracks.xml';
                 $buddystreamCurl = new BuddyStreamCurl();
                 $curlContent = $buddystreamCurl->getContentFromUrl($url);
                 $items = null;
                 if (strpos($curlContent, "ERROR:") > 0) {
                     $items = simplexml_load_string($curlContent);
                 }
                 if ($items) {
                     foreach ($items as $song) {
                         //only import song that are older than 10 minutes!!!
                         $exist = 0;
                         if (date("d-m-Y", strtotime($song->date)) == date('d-m-Y')) {
                             $arrDate = explode(",", $song->date);
                             $time = trim($arrDate[1]);
                             $time = str_replace(":", "", $time);
                             if (date('Hi') - $time <= 10) {
                                 $exist = 1;
                             }
                         }
                         $sid = str_replace(" ", "", $song->date);
                         $sid = str_replace(":", "", $sid);
                         $sid = str_replace(",", "", $sid);
                         $sid = str_replace("-", "", $sid);
                         $sid = strtoupper($sid);
                         $sid = str_replace("JAN", "01", $sid);
                         $sid = str_replace("FEB", "02", $sid);
                         $sid = str_replace("MAR", "03", $sid);
                         $sid = str_replace("APR", "04", $sid);
                         $sid = str_replace("MAY", "05", $sid);
                         $sid = str_replace("JUN", "06", $sid);
                         $sid = str_replace("JUL", "07", $sid);
                         $sid = str_replace("AUG", "08", $sid);
                         $sid = str_replace("SEP", "09", $sid);
                         $sid = str_replace("OCT", "10", $sid);
                         $sid = str_replace("NOV", "11", $sid);
                         $sid = str_replace("DEC", "12", $sid);
                         if (!$max) {
                             $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'lastfm', 'type' => 'last.fm track', 'content' => 'Just listened to: <a href="' . $song->url . '" target="_new">' . $song->artist . " - " . $song->name . "</a>", 'item_id' => $sid, 'raw_date' => gmdate('Y-m-d H:i:s', strtotime($song->date)), 'actionlink' => 'http://www.lastfm.com/user/' . get_user_meta($user_meta->user_id, 'bs_lastfm_username', 1)));
                             if ($returnCreate) {
                                 $itemCounter++;
                             }
                         }
                     }
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("Last.fm imported " . $itemCounter . " songs        for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
Ejemplo n.º 4
0
 /**
  * Return decoded json content form url
  * @param string $url
  * @return string 
  */
 public function getJsonDecodedContent($url)
 {
     return json_decode(BuddyStreamCurl::getContentFromUrl($url));
 }