Permalink
Browse files

basic SocialNoise\Facebook

Trust me, this hurts me more than it does you.
  • Loading branch information...
1 parent a53b1f7 commit c4ca8c291beffb84430edb3d0d92260c53ad0049 Brennen Bearnes committed Oct 15, 2012
Showing with 64 additions and 0 deletions.
  1. +64 −0 SocialNoise/Facebook.php
View
@@ -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.