Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |