Advertisement
thelonelyghost

embed-facebook.php

Sep 6th, 2012
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.41 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Embed Facebook
  4. Plugin URI: http://sohailabid.com/projects/embed-facebook/
  5. Description: Embed various facebook objects (album, photo, event, video, page, group, or note) by just pasting the URL anywhere in a WordPress page or post
  6. Author: Sohail Abid
  7. Version: 1.4
  8. Author URI: http://www.sohailabid.com
  9. */
  10.  
  11. include_once('json.php');
  12. add_action('wp_head', 'sohail_embed_facebook_head');
  13.  
  14. define('SOHAIL_EMBED_FACEBOOK_URL', get_option( 'siteurl' ). '/wp-content/plugins/embed-facebook');
  15. $sohail_embed_facebook_url = get_option('siteurl') . '/wp-content/plugins/embed-facebook';
  16.  
  17. function sohail_embed_facebook_head() {
  18.     echo '<script type="text/javascript" src="'.SOHAIL_EMBED_FACEBOOK_URL.'/slidewindow/slidewindow_min.js"></script>' . "\n";
  19.     echo '<script type="text/javascript">currPath = "'.SOHAIL_EMBED_FACEBOOK_URL.'/slidewindow/"; strImgOf="";</script>' . "\n";
  20.     echo "<style>
  21.     .sohailerror { border:1px solid #eee; background:#f9f9f9; padding:10px; margin-bottom:15px;}
  22.     .sohailfbbox { margin:0 0 25px 0; padding:0; font-family: 'lucida grande', tahoma, verdana; font-size: 12px; line-height:18px; border: 1px solid #C6CEDD; border-top-color:#315C99; }
  23.     #content .sohailfbbox a, .sohailfbbox a { color:#3B5998;text-decoration:none; }
  24.     #content .sohailfbbox a:hover, .sohailfbbox a:hover { color:#3B5998;text-decoration:underline; }
  25.     .sohailfbboxhead { margin: 0; padding: 10px; font-size: 17px; border-bottom: 1px solid #D8DFEA; background: #EDEFF4; height:40px; }
  26.     .sohailfbboxhead span { margin: 0; padding: 0px; font-size: 12px; }
  27.     .sohailfbboxbody { margin: 0; padding: 12px 10px 8px 10px; }
  28.     .sohailfbboxinfo { margin: 0 0 0 10px; padding: 10px; float:right; width:250px; border:1px solid #D8DFEA; background:#EDEFF4; tex-align:right; font-size:11px; }
  29.     #content .sohailfbthumb, .fbalbumpics .sohailfbthumb { border:1px solid #ccc; padding:4px; margin-right:6px; width:130px; height:98px; }
  30. </style>\n";
  31. }
  32.  
  33.  
  34. add_filter('the_content', 'sohail_embed_facebook');
  35.  
  36. function sohail_embed_facebook($the_content) {
  37.     preg_match_all("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", $the_content, $matches, PREG_SET_ORDER);
  38.     foreach($matches as $match) {
  39.         $the_content = preg_replace("/<p>(http|https):\/\/www\.facebook\.com\/([^<\s]*)<\/p>/", sohail_do_embed($match), $the_content, 1);
  40.     }
  41.     return $the_content;
  42. }
  43.  
  44.  
  45. function sohail_do_embed($url) {
  46.     $raw_query_string = explode('?', $url[2]);
  47.     $query_string = str_replace(array('#038;', '&amp;'), array('&', '&'), $raw_query_string[1]);
  48.     parse_str($query_string, $query_vars);
  49.     if(!$query_vars) {
  50.         return sohail_do_embed_profile($raw_query_string[0], $url[2]);
  51.     } else {
  52.         if(strpos($raw_query_string[0], 'media/set/') !== false)
  53.             return sohail_do_embed_new_album($query_vars, $url[2]);
  54.         elseif(strpos($raw_query_string[0], 'media/set/fbx/') !== false)
  55.             return sohail_do_embed_new_album($query_vars, $url[2]);
  56.         elseif(strpos($raw_query_string[0], 'album.php') !== false)
  57.             return sohail_do_embed_album($query_vars, $url[2]);
  58.         elseif(strpos($raw_query_string[0], 'video.php') !== false)
  59.             return sohail_do_embed_video($query_vars, $url[2]);
  60.         elseif(strpos($raw_query_string[0], 'photo.php') !== false)
  61.             return sohail_do_embed_photo($query_vars, $url[2]);
  62.         elseif(strpos($raw_query_string[0], 'event.php') !== false)
  63.             return sohail_do_embed_event($query_vars, $url[2]);
  64.         elseif(strpos($raw_query_string[0], 'group.php') !== false)
  65.             return sohail_do_embed_group($query_vars, $url[2]);
  66.         elseif(strpos($raw_query_string[0], 'note.php') !== false)
  67.             return sohail_do_embed_note($query_vars, $url[2]);
  68.         else
  69.             return "<p><a href='".strip_tags($url[0])."' target='_blank'>".strip_tags($url[0])."</a></p>";
  70.     }
  71. }
  72.  
  73. function sohail_do_embed_profile($query_vars, $url) {
  74.     if(strpos($query_vars, 'pages/') == 0)
  75.         $fb_profile = "http://graph.facebook.com/". end(explode('/', $query_vars));
  76.     else
  77.         $fb_profile = "http://graph.facebook.com/{$query_vars}";
  78.     if (function_exists("curl_init"))
  79.         $fb_profile = @curl_get_content($fb_profile);
  80.     else
  81.         $fb_profile = @file_get_contents($fb_profile);
  82.     if(function_exists("json_decode"))
  83.         $fb_profile = json_decode($fb_profile);
  84.     else
  85.         $fb_profile = sohail_json_decode($fb_profile);
  86.     if(!isset($fb_profile->name)) {
  87.         $return = "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  88.         if(is_user_logged_in())
  89.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the profile.<br />(this message is visible to logged in users only)</div>';
  90.     } else {
  91.         if($fb_profile->category == 'Television') {
  92.  
  93.  
  94.             $return .= <<<HEREDOC
  95. <div class="sohailfbbox">
  96.     <div class="sohailfbboxhead">
  97.         <img src="http://graph.facebook.com/{$fb_profile->id}/picture" align="left" style="margin-right:10px; width:40px; height:40px;" />
  98.         <img src="{$sohail_embed_facebook_url}/images/page.png" style="vertical-align:text-top" />
  99.         $fb_profile->name<br />
  100.         <span>$fb_profile->category ($fb_profile->genre) &nbsp;|&nbsp; $fb_profile->fan_count fans &nbsp;|&nbsp; <a href="http://www.facebook.com/profile.php?id={$fb_profile->id}" target="_blank">View on Facebook</a></span>
  101.     </div>
  102.     <div class='sohailfbboxbody'>
  103.         <p>
  104. HEREDOC;
  105.  
  106.             if($fb_profile->network) $return .= "Network: {$fb_profile->network} / ";
  107.             if($fb_profile->directed_by) $return .= "Directed by: {$fb_profile->directed_by} / ";
  108.             if($fb_profile->starring) $return .= "Starring: {$fb_profile->starring}";
  109.            
  110.             $return .= <<<HEREDOC
  111.         </p>
  112.         $fb_profile->plot_outline
  113.     </div>
  114. </div>
  115. HEREDOC;
  116.  
  117.  
  118.         } elseif($fb_profile->category == 'Public_figures_other') {
  119.             $return .= "<div class='sohailfbbox'>\n";
  120.             $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$fb_profile->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/page.png' style='vertical-align:text-top' /> {$fb_profile->name}<br /><span>Public Figure &nbsp;|&nbsp; {$fb_profile->fan_count} fans &nbsp;|&nbsp; <a href='http://www.facebook.com/profile.php?id={$fb_profile->id}' target='_blank'>View on Facebook</a></span></div>\n";
  121.             $return .= "<div class='sohailfbboxbody'>\n";
  122.             $return .= "{$fb_profile->personal_info}";
  123.             $return .= "</div>\n";
  124.             $return .= "</div>\n";
  125.         } else {
  126.             $return .= "<div class='sohailfbbox'>\n";
  127.             $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$fb_profile->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/page.png' style='vertical-align:text-top' /> {$fb_profile->name}<br /><span>{$fb_profile->category} {$fb_profile->genre} &nbsp;|&nbsp; {$fb_profile->fan_count} fans &nbsp;|&nbsp; <a href='http://www.facebook.com/profile.php?id={$fb_profile->id}' target='_blank'>View on Facebook</a></span></div>\n";
  128.             $return .= "<div class='sohailfbboxbody'>\n";
  129.         if(strlen($fb_profile->company_overview) < 500)
  130.             $return .= nl2br($fb_profile->company_overview);
  131.         else
  132.             $return .= nl2br(substr($fb_profile->company_overview, 0, 500)) . '<span id="'.$fb_profile->id.'" style="display:none">' . nl2br(substr($fb_profile->company_overview, 500)) . '</span><span id="sohailmorelink'.$fb_profile->id.'">... <a href="javascript:void(0)" onclick="javascript:sohail_expand_content(\''.$fb_profile->id.'\')">See full description</a></span>';
  133.             $return .= "</div>\n";
  134.             $return .= "</div>\n";
  135.         }
  136.     }
  137.     return $return;
  138. }
  139.  
  140. function sohail_do_embed_album($query_vars, $url) {
  141.     $fb_albums = "http://graph.facebook.com/{$query_vars[id]}/albums?limit=400";
  142.     if (function_exists("curl_init"))
  143.         $fb_albums = @curl_get_content($fb_albums);
  144.     else
  145.         $fb_albums = @file_get_contents($fb_albums);
  146.     if(function_exists("json_decode"))
  147.         $fb_albums = json_decode($fb_albums);
  148.     else
  149.         $fb_albums = sohail_json_decode($fb_albums);
  150.     if(!isset($fb_albums->data)) {
  151.         $return .= "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  152.         if(is_user_logged_in())
  153.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the album, are you sure it belongs to a facebook page?<br />(this message is visible to logged in users only)</div>';
  154.     } else {
  155.         foreach($fb_albums->data as $album) {
  156.             if (!is_singular() && $fb_albums->foo ) echo "";
  157.             if (strpos($album->link, $query_vars['aid'])) {
  158.                 $return  = "<div class='sohailfbbox'>\n";
  159.                 $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$album->from->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/photos.png' style='vertical-align:text-top' /> ".substr($album->name, 0, 60)."<br /><span>By <a href='http://www.facebook.com/profile.php?id={$album->from->id}' target='_blank'>{$album->from->name}</a> &nbsp;|&nbsp; <a href='{$album->link}' target='_blank'>View on Facebook</a></span></div>\n";
  160.                 $return .= "<div class='sohailfbboxbody'>\n";
  161.                 if(!is_singular())
  162.                     $fb_photos = "http://graph.facebook.com/{$album->id}/photos?limit=12";
  163.                 elseif($query_vars[limit])
  164.                     $fb_photos = "http://graph.facebook.com/{$album->id}/photos?limit={$query_vars[limit]}";
  165.                 else
  166.                     $fb_photos = "http://graph.facebook.com/{$album->id}/photos?limit=400";
  167.                 if (function_exists("curl_init"))
  168.                     $fb_photos = @curl_get_content($fb_photos);
  169.                 else
  170.                     $fb_photos = @file_get_contents($fb_photos);
  171.                 if(function_exists("json_decode"))
  172.                     $fb_photos = json_decode($fb_photos);
  173.                 else
  174.                     $fb_photos = sohail_json_decode($fb_photos);
  175.                 /*
  176.                 if(is_user_logged_in()) {
  177.                     print '<pre>';
  178.                     print_r($fb_photos);
  179.                     print '</pre>';
  180.                 }
  181.                 */
  182.                 if(!isset($fb_photos->data)) {
  183.                     $return .= "<p><a href='http://www.facebook.com/$url'>www.facebook.com/$url</a></p>";
  184.                     if(is_user_logged_in())
  185.                         $return .= '<div class="sohailerror">Error: Couldn\'t access the photos inside the album. Please check privacy settings or contact me with album URL: <a href="http://sohailabid.com/">sohailabid.com</a><br />(this message is visible to logged in users only)</div>';
  186.                 } else {
  187.                     foreach($fb_photos->data as $photo) {
  188.                         $return .= "<a href='{$photo->source}' title='{$photo->name}' onclick='return showSlideWindow(this, 600, 400);' class='viewable'><img src='{$photo->picture}' class='sohailfbthumb' style='border:1px solid #ccc; padding:4px; margin-right:6px; width:130px; height:98px;' /></a>";
  189.                     }
  190.                 }
  191.                 $return .= "</div>\n";
  192.                 $return .= "</div>\n";
  193.             }
  194.         }
  195.     }
  196.     return $return;
  197. }
  198.  
  199. function sohail_do_embed_new_album($query_vars, $url) {
  200.     $query_vars = explode('.', $query_vars['set']);
  201.     $fb_albums = "http://graph.facebook.com/{$query_vars[3]}/albums?limit=400";
  202.     if (function_exists("curl_init"))
  203.         $fb_albums = @curl_get_content($fb_albums);
  204.     else
  205.         $fb_albums = @file_get_contents($fb_albums);
  206.     if(function_exists("json_decode"))
  207.         $fb_albums = json_decode($fb_albums);
  208.     else
  209.         $fb_albums = sohail_json_decode($fb_albums);
  210.     if(!isset($fb_albums->data)) {
  211.         $return .= "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  212.         if(is_user_logged_in())
  213.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the album, are you sure it belongs to a facebook page?<br />(this message is visible to logged in users only)</div>';
  214.     } else {
  215.         foreach($fb_albums->data as $album) {
  216.             if (strpos($album->link, $query_vars[2])) {
  217.                 $return  = "<div class='sohailfbbox'>\n";
  218.                 $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$album->from->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/photos.png' style='vertical-align:text-top' /> ".substr($album->name, 0, 60)."<br /><span>By <a href='http://www.facebook.com/profile.php?id={$album->from->id}' target='_blank'>{$album->from->name}</a> &nbsp;|&nbsp; <a href='{$album->link}' target='_blank'>View on Facebook</a></span></div>\n";
  219.                 $return .= "<div class='sohailfbboxbody'>\n";
  220.                 if(!is_singular())
  221.                     $fb_photos = "http://graph.facebook.com/{$album->id}/photos?limit=12";
  222.                 elseif($query_vars[limit])
  223.                     $fb_photos = "http://graph.facebook.com/{$album->id}/photos?limit={$query_vars[limit]}";
  224.                 else
  225.                     $fb_photos = "http://graph.facebook.com/{$album->id}/photos?limit=400";
  226.                 if (function_exists("curl_init"))
  227.                     $fb_photos = @curl_get_content($fb_photos);
  228.                 else
  229.                     $fb_photos = @file_get_contents($fb_photos);
  230.                 if(function_exists("json_decode"))
  231.                     $fb_photos = json_decode($fb_photos);
  232.                 else
  233.                     $fb_photos = sohail_json_decode($fb_photos);
  234.                 /*
  235.                 if(is_user_logged_in()) {
  236.                     print '<pre>';
  237.                     print_r($fb_photos);
  238.                     print '</pre>';
  239.                 }
  240.                 */
  241.                 if(!isset($fb_photos->data)) {
  242.                     $return .= "<p><a href='http://www.facebook.com/$url'>www.facebook.com/$url</a></p>";
  243.                     if(is_user_logged_in())
  244.                         $return .= '<div class="sohailerror">Error: Couldn\'t access the photos inside the album. Please check privacy settings or contact me with album URL: <a href="http://sohailabid.com/">sohailabid.com</a><br />(this message is visible to logged in users only)</div>';
  245.                 } else {
  246.                     foreach($fb_photos->data as $photo) {
  247.                         $return .= "<a href='{$photo->source}' title='{$photo->name}' onclick='return showSlideWindow(this, 600, 400);' class='viewable'><img src='{$photo->picture}' class='sohailfbthumb' style='border:1px solid #ccc; padding:4px; margin-right:6px; width:130px; height:98px;' /></a>";
  248.                     }
  249.                 }
  250.                 $return .= "</div>\n";
  251.                 $return .= "</div>\n";
  252.             }
  253.         }
  254.     }
  255.     return $return;
  256. }
  257.  
  258. function sohail_do_embed_video($query_vars, $url) {
  259.     $fb_video = 'http://www.facebook.com/video/video.php?v='.$query_vars[v];
  260.     if (function_exists("curl_init"))
  261.         $fb_video = @curl_get_content($fb_video);
  262.     else
  263.         $fb_video = @file_get_contents($fb_video);
  264.     preg_match_all('/<h3 class="video_title datawrap">(.*?)<\/h3>/', $fb_video, $title, PREG_SET_ORDER);
  265.     preg_match_all('/<a class="video_owner_link" href="(.*?)">(.*?)<\/a>/', $fb_video, $owner, PREG_SET_ORDER);
  266.     if(!isset($title[0][1])) {
  267.         $return = "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  268.         if(is_user_logged_in())
  269.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the video.<br />(this message is visible to logged in users only)</div>';
  270.     } else {
  271.         $return  = "<div class='sohailfbbox'>\n";
  272.         $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/".end(explode('/', $owner[0][1]))."/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/video.png' style='vertical-align:text-top' /> ".substr($title[0][1], 0, 70)."<br /><span>By {$owner[0][0]} &nbsp;|&nbsp; <a href='http://www.facebook.com/video/video.php?v={$query_vars[v]}' target='_blank'>View on Facebook</a></span></div>\n";
  273.         $return .= "<div class='sohailfbboxbody'>\n";
  274.         $return .= "<object width=\"100%\" height=\"40%\" ><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://www.facebook.com/v/{$query_vars[v]}\" /><embed src=\"http://www.facebook.com/v/{$query_vars[v]}\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"100%\" height=\"40%\"></embed></object>";
  275.         $return .= "</div>\n";
  276.         $return .= "</div>\n";
  277.     }
  278.     return $return;
  279. }
  280.  
  281. function sohail_do_embed_photo($query_vars, $url) {
  282.     $fb_photo = "http://graph.facebook.com/{$query_vars[fbid]}";
  283.     if (function_exists("curl_init"))
  284.         $fb_photo = @curl_get_content($fb_photo);
  285.     else
  286.         $fb_photo = @file_get_contents($fb_photo);
  287.     if(function_exists("json_decode"))
  288.         $fb_photo = json_decode($fb_photo);
  289.     else
  290.         $fb_photo = sohail_json_decode($fb_photo);
  291.     if(!isset($fb_photo->source)) {
  292.         $return = "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  293.         if(is_user_logged_in())
  294.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the photo, are you sure it belongs to a facebook Page?<br />(this message is visible to logged in users only)</div>';
  295.     } else {
  296.         $return  = "<div class='sohailfbbox'>\n";
  297.         $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$fb_photo->from->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/photos.png' style='vertical-align:text-top' /> ".substr($fb_photo->name, 0, 60)."<br /><span>By <a href='http://www.facebook.com/profile.php?id={$fb_photo->from->id}' target='_blank'>{$fb_photo->from->name}</a> &nbsp;|&nbsp; <a href='{$fb_photo->link}' target='_blank'>View on Facebook</a></span></div>\n";
  298.         $return .= "<div class='sohailfbboxbody'>\n";
  299.         $return .= "<a href='{$fb_photo->source}' title='{$fb_photo->name}' onclick='return showSlideWindow(this, 600, 400);' class='viewable'><img src='". str_replace('_s.jpg', '_a.jpg', $fb_photo->source) ."' style='max-width:100%' /></a>";
  300.         $return .= "</div>\n";
  301.         $return .= "</div>\n";
  302.     }
  303.     return $return;
  304. }
  305.  
  306. function sohail_do_embed_event($query_vars, $url) {
  307.     $fb_event = "http://graph.facebook.com/{$query_vars[eid]}";
  308.     if (function_exists("curl_init"))
  309.         $fb_event = @curl_get_content($fb_event);
  310.     else
  311.         $fb_event = @file_get_contents($fb_event);
  312.     if(function_exists("json_decode"))
  313.         $fb_event = json_decode($fb_event);
  314.     else
  315.         $fb_event = sohail_json_decode($fb_event);
  316.     if(!isset($fb_event->name)) {
  317.         $return = "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  318.         if(is_user_logged_in())
  319.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the event, are you sure it belongs to a facebook Page?<br />(this message is visible to logged in users only)</div>';
  320.     } else {
  321.         $start_time = sohail_iso8601($fb_event->start_time);
  322.         $end_time = sohail_iso8601($fb_event->end_time);
  323.         if($fb_event->location)
  324.             $location = $fb_event->location . '<br />';
  325.         if($fb_event->venue->street)
  326.             $address = $fb_event->venue->street;
  327.         if($fb_event->venue->city)
  328.             $address .= ', ' . $fb_event->venue->city;
  329.         if($fb_event->venue->state)
  330.             $address .= ', ' . $fb_event->venue->state;
  331.         if($fb_event->venue->country)
  332.             $address .= ', ' . $fb_event->venue->country;
  333.         $return  = "<div class='sohailfbbox'>\n";
  334.         $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$fb_event->owner->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/event.png' style='vertical-align:text-top' /> ".substr($fb_event->name, 0, 60)."<br /><span>By <a href='http://www.facebook.com/profile.php?id={$fb_event->owner->id}' target='_blank'>{$fb_event->owner->name}</a> &nbsp;|&nbsp; <a href='http://www.facebook.com/event.php?eid={$fb_event->id}' target='_blank'>View on Facebook</a></span></div>\n";
  335.         $return .= "<div class='sohailfbboxbody'>\n";
  336.         $return .= "<div class='sohailfbboxinfo'><b>When:</b> ";
  337.             if( date('M j Y', $start_time) == date('M j Y', $end_time) )
  338.                 $return .= date('M j, Y', $start_time) . ' (' . date('g:ia', $start_time) . ' - ' . date('g:ia', $end_time) . ')';
  339.             else
  340.                 $return .= date('M j', $start_time) . ' '. date('g:ia', $start_time) . ' - ' . date('M j', $end_time) . ' ' . date('g:ia', $end_time);
  341.         $return .= "<br /><br /><b>Where:</b> {$location}{$address}<br /><br />&raquo; <a target='_blank' href='http://maps.google.com/maps?q={$address}'>View map</a></div>";
  342.         if(strlen($fb_event->description) < 500)
  343.             $return .= nl2br($fb_event->description);
  344.         else
  345.             $return .= nl2br(substr($fb_event->description, 0, 500)) . '<span id="'.$fb_event->id.'" style="display:none">' . nl2br(substr($fb_event->description, 500)) . '</span><span id="sohailmorelink'.$fb_event->id.'">... <a href="javascript:void(0)" onclick="javascript:sohail_expand_content(\''.$fb_event->id.'\')">See full description</a></span>';
  346.         $return .= "</div>\n";
  347.         $return .= "</div>\n";
  348.     }
  349.     return $return;
  350. }
  351.  
  352. function sohail_do_embed_group($query_vars, $url) {
  353.     $fb_group = "http://graph.facebook.com/{$query_vars[gid]}";
  354.     if (function_exists("curl_init"))
  355.         $fb_group = @curl_get_content($fb_group);
  356.     else
  357.         $fb_group = @file_get_contents($fb_group);
  358.     if(function_exists("json_decode"))
  359.         $fb_group = json_decode($fb_group);
  360.     else
  361.         $fb_group = sohail_json_decode($fb_group);
  362.     if(!isset($fb_group->name)) {
  363.         $return = "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  364.         if(is_user_logged_in())
  365.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the group, are you sure it is public and not private?<br />(this message is visible to logged in users only)</div>';
  366.     } else {
  367.         $return  = "<div class='sohailfbbox'>\n";
  368.         $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/{$fb_group->owner->id}/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/group.png' style='vertical-align:text-top' /> ".substr($fb_group->name, 0, 60)."<br /><span>By <a href='http://www.facebook.com/profile.php?id={$fb_group->owner->id}' target='_blank'>{$fb_group->owner->name}</a> &nbsp;|&nbsp; <a href='http://www.facebook.com/group.php?gid={$fb_group->id}' target='_blank'>View on Facebook</a></span></div>\n";
  369.         $return .= "<div class='sohailfbboxbody'>\n";
  370.         if(strlen($fb_group->description) < 500)
  371.             $return .= nl2br($fb_group->description);
  372.         else
  373.             $return .= nl2br(substr($fb_group->description, 0, 500)) . '<span id="'.$fb_group->id.'" style="display:none">' . nl2br(substr($fb_group->description, 500)) . '</span><span id="sohailmorelink'.$fb_group->id.'">... <a href="javascript:void(0)" onclick="javascript:sohail_expand_content(\''.$fb_group->id.'\')">See full description</a></span>';
  374.         $return .= "</div>\n";
  375.         $return .= "</div>\n";
  376.     }
  377.     return $return;
  378. }
  379.  
  380. function sohail_do_embed_note($query_vars, $url) {
  381.     $fb_note = 'http://www.facebook.com/note.php?note_id='.$query_vars[note_id];
  382.     if (function_exists("curl_init"))
  383.         $fb_note = @curl_get_content($fb_note);
  384.     else
  385.         $fb_note = @file_get_contents($fb_note);
  386.     preg_match_all('/<h2 class="uiHeaderTitle">(.*?)<\/h2>/', $fb_note, $title, PREG_SET_ORDER);
  387.     preg_match_all('/<div class="mbs mbs uiHeaderSubTitle lfloat fsm fwn fcg">by <a href="(.*?)">(.*?)<\/a>/', $fb_note, $owner, PREG_SET_ORDER);
  388.     preg_match_all('/<div class="mbl notesBlogText clearfix"><div>(.*?)<\/div><\/div>/s', $fb_note, $note, PREG_SET_ORDER);
  389.     //print '<pre>';
  390.     //print_r($title);
  391.     //print_r($owner);
  392.     //print_r($note);
  393.     //print '</pre>';
  394.     if(!isset($title[0][1])) {
  395.         $return = "<p><a href='http://www.facebook.com/$url'>http://www.facebook.com/$url</a></p>";
  396.         if(is_user_logged_in())
  397.             $return .= '<div class="sohailerror">Error: Couldn\'t embed the note, are you sure it is public and not private?<br />(this message is visible to logged in users only)</div>';
  398.     } else {
  399.         $return  = "<div class='sohailfbbox'>\n";
  400.         $return .= "<div class='sohailfbboxhead'><img src='http://graph.facebook.com/".end(explode('/', $owner[0][1]))."/picture' align='left' style='margin-right:10px; width:40px; height:40px;' /><img src='".SOHAIL_EMBED_FACEBOOK_URL."/images/note.png' style='vertical-align:text-top' /> ".substr($title[0][1], 0, 70)."<br /><span>By ".str_replace('<div class="mbs mbs uiHeaderSubTitle lfloat fsm fwn fcg">by ', '', $owner[0][0]) . " &nbsp;|&nbsp; <a href='http://www.facebook.com/note.php?note_id={$query_vars[note_id]}' target='_blank'>View on Facebook</a></span></div>\n";
  401.         $return .= "<div class='sohailfbboxbody'>\n";
  402.         $return .= strip_tags($note[0][1], '<p><a><br><br /><img>');
  403.         $return .= "</div>\n";
  404.         $return .= "</div>\n";
  405.     }
  406.     return $return;
  407. }
  408.  
  409. function curl_get_content($url) {
  410.     $ch = curl_init();
  411.     curl_setopt($ch, CURLOPT_USERAGENT, "Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
  412.     curl_setopt ($ch, CURLOPT_URL, $url);
  413.     curl_setopt ($ch, CURLOPT_HEADER, 0);
  414.     ob_start();
  415.     curl_exec ($ch);
  416.     curl_close ($ch);
  417.     $return = ob_get_contents();
  418.     ob_end_clean();
  419.     return $return;
  420. }
  421.  
  422. function sohail_json_encode($value) {
  423.     $json = new Services_JSON();
  424.     return $json->encode($value);
  425. }
  426.  
  427. function sohail_json_decode($value) {
  428.     $json = new Services_JSON();
  429.     return $json->decode($value);
  430. }
  431.  
  432. function sohail_iso8601($tstamp) {
  433.     sscanf($tstamp,"%u-%u-%uT%u:%u:%uZ",$year,$month,$day,
  434.     $hour,$min,$sec);
  435.     $newtstamp=mktime($hour,$min,$sec,$month,$day,$year);
  436.     return $newtstamp;
  437. }
  438. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement