class-facebook.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Facebook
  4. *
  5. * with help of the API this class delivers album images from Facebook
  6. *
  7. * @package socialstreams
  8. * @subpackage socialstreams/facebook
  9. * @author ThemePunch <info@themepunch.com>
  10. */
  11. class TP_facebook {
  12. /**
  13. * Get User ID from its URL
  14. *
  15. * @since 1.0.0
  16. * @param string $user_url URL of the Page
  17. */
  18. public function get_user_from_url($user_url){
  19. $theid = str_replace("https", "", $user_url);
  20. $theid = str_replace("http", "", $theid);
  21. $theid = str_replace("://", "", $theid);
  22. $theid = str_replace("www.", "", $theid);
  23. $theid = str_replace("facebook", "", $theid);
  24. $theid = str_replace(".com", "", $theid);
  25. $theid = str_replace("/", "", $theid);
  26. $theid = explode("?", $theid);
  27. return $theid[0];
  28. }
  29. /**
  30. * Get Photosets List from User
  31. *
  32. * @since 1.0.0
  33. * @param string $user_id Facebook User id (not name)
  34. * @param int $item_count number of photos to pull
  35. */
  36. public function get_photo_sets($user_id,$item_count=10){
  37. //photoset params
  38. $url = "https://graph.facebook.com/$user_id/albums";
  39. $photo_sets_list = json_decode(file_get_contents($url));
  40. return $photo_sets_list->data;
  41. }
  42. /**
  43. * Get Photoset Photos
  44. *
  45. * @since 1.0.0
  46. * @param string $photo_set_id Photoset ID
  47. * @param int $item_count number of photos to pull
  48. */
  49. public function get_photo_set_photos($photo_set_id,$item_count=10){
  50. $url = "https://graph.facebook.com/v2.0/$photo_set_id?fields=photos";
  51. $photo_set_photos = json_decode(file_get_contents($url));
  52. return $photo_set_photos->photos->data;
  53. }
  54. /**
  55. * Get Feed
  56. *
  57. * @since 1.0.0
  58. * @param string $user User ID
  59. * @param int $item_count number of itmes to pull
  60. */
  61. public function get_post_feed($user,$app_id,$app_secret,$item_count=10){
  62. $oauth = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
  63. $url = "https://graph.facebook.com/$user/feed?".$oauth."&fields=id,from,message,picture,link,name,icon,privacy,type,status_type,object_id,application,created_time,updated_time,is_hidden,is_expired,likes,comments";
  64. $feed = json_decode(file_get_contents($url));
  65. return $feed->data;
  66. }
  67. /**
  68. * Decode URL from feed
  69. *
  70. * @since 1.0.0
  71. * @param string $url facebook Output Data
  72. */
  73. public static function decode_facebook_url($url) {
  74. $url = str_replace('u00253A',':',$url);
  75. $url = str_replace('\u00255C\u00252F','/',$url);
  76. $url = str_replace('u00252F','/',$url);
  77. $url = str_replace('u00253F','?',$url);
  78. $url = str_replace('u00253D','=',$url);
  79. $url = str_replace('u002526','&',$url);
  80. return $url;
  81. }
  82. }
  83. ?>