Skip to content

Commit

Permalink
basic SocialNoise\Facebook
Browse files Browse the repository at this point in the history
Trust me, this hurts me more than it does you.
  • Loading branch information
Brennen Bearnes committed Oct 15, 2012
1 parent a53b1f7 commit c4ca8c2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions SocialNoise/Facebook.php
@@ -0,0 +1,64 @@
<?php
namespace SparkLib\SocialNoise;

use \SparkLib\Util\Text;

class Facebook extends \SparkLib\SocialNoise {

public $tableClass = '';

public function __construct () { }

public function search ($text, $qty)
{
$url = "https://graph.facebook.com/search?type=post&q={$text}";
return static::getSearchFromJson($url);
}

/**
* Format a particular search response as HTML.
*/
public function searchHTML ($text, $qty)
{
$result = $this->search($text, $qty);

$html = '<table class="' . htmlspecialchars($this->tableClass) . '">';

$count = 0;
foreach ($result->data as $activity) {

if ($count++ > $qty)
break;

$html .= '<tr>';

if (isset($activity->picture))
$html .= '<td><img src="' . htmlspecialchars($activity->picture) . '" height=50 width=50></td>';
elseif (isset($activity->icon))
$html .= '<td><img src="' . htmlspecialchars($activity->icon) . '"></td>';
else
$html .= "<td></td>";

$html .= '<td>[' . htmlspecialchars($activity->from->name) . '] ';

if (isset($activity->message))
$html .= (Text::truncate(htmlspecialchars($activity->message), 50));
elseif (isset($activity->story))
$html .= (Text::truncate(htmlspecialchars($activity->story), 50));

$html .= '<br>';
$time = '<small><i>' . htmlspecialchars($activity->created_time) . "</i></small>";
if (isset($activity->link))
$html .= '<a href="' . htmlspecialchars($activity->link) . '">' . $time . '</a>';
else
$html .= $time;

$html .= "</td></tr>";
}

$html .= '</table>';

return $html;
}

}

0 comments on commit c4ca8c2

Please sign in to comment.