Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Roy Toledo  >  Facebook Open Graph Search  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Usage Example
Class: Facebook Open Graph Search
Search for content in Facebook with Open Graph API
Author: By
Last change:
Date: 2012-08-17 20:35
Size: 2,699 bytes
 

Contents

Class file image Download
<?php 
require 'facebook_search.class.php';
$vars $_POST;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Facebook Search Example</title>
    <style>
        table, td{ border: solid thin grey; }
        form { margin: 10px; border: 2px dotted blue; width: 400px;}
    </style>
</head>
<body>

<h1>Facebook Search</h2>


<form action="" method="post">
    <input type="text" name="q" value="<?=$vars['q']?>"></input>
    <select name="type">
        <option value="post">Post</option>
        <option value="event">Event</option>
        <option value="place">place</option>
        <option value="page">page</option>
        <option value="group">group</option>
        <option value="checkin">checkin</option>
    </select>
    <input type="submit" value="search"></input>
</form>

<?

if(isset($_POST['q'])){
    
    
$searcher = new facebookSearcher();
    
$searcher->setQuery($vars['q'])
                ->
setType($vars['type'])
                ->
setLimit(15);
    
$graph_res $searcher->fetchResults();
    
    
/** Show Results **/
    
echo "<h2>Search {$vars['type']}s For : {$vars['q']}</h2>";
    if(
count($graph_res->data) == 0)  exit("No Results");
    if(
$vars['type'] == 'post'){
        
//post
        
foreach($graph_res->data as $post){
            
$row[] = "<img src='{$post->icon}' />".$post->type;
            
$row[] = $post->from->name;
            
$row[] = $post->message;
            
$row[] = "<a href='{$post->link}' target='_blank'>{$post->link}</a>";
            
$row[] = $post->likes->count." Likes";
            
$table[] = $row;
            unset(
$row);
        }
    }elseif(
$vars['type'] == 'event'){
        foreach(
$graph_res->data as $post){
            
$row[] = $post->name;
            
$row[] = "At ".$post->location;
            
$row[] = "From ".$post->start_time." To ".$post->end_time;
            
$table[] = $row;
            unset(
$row);
        }
    }elseif(
$vars['type'] == 'place'){
        foreach(
$graph_res->data as $post){
            
$row[] = $post->name;
            
$row[] = $post->category;
            
$row[] = $post->location->street.", ".$post->location->city.", ".$post->location->country;
            
$table[] = $row;
            unset(
$row);
        }
    }else{
        echo 
"New Type: <br /><pre>".print_r($graph_res,true)."</pre>";
    }
echo <<<HTML
    <table>
HTML;
        foreach (
$table as $row){
            echo 
"<tr>";
            foreach (
$row as $cell){
                echo 
"<td>{$cell}</td>";
            }
            echo 
"</tr>";
        }
        
?>
    </table>
<a href="<?=$searcher->getPreviousPage()?>">Preivous Search Results URL</a> | <a href="<?=$searcher->getNextPage()?>">Next Search Results URL</a>
<?}?>

</body>
</html>