예제 #1
0
 $usersCount = !empty($_POST['usersCount']) ? $_POST['usersCount'] : 10;
 $selfComments = isset($_POST['selfComments']) ? $_POST['selfComments'] : 0;
 $ignoreLinks = isset($_POST['ignoreLinks']) ? $_POST['ignoreLinks'] : 0;
 $ignorePhotos = isset($_POST['ignorePhotos']) ? $_POST['ignorePhotos'] : 0;
 $minLines = isset($_POST['minLines']) && !empty($_POST['minLines']) ? $_POST['minLines'] : 0;
 $minWords = isset($_POST['minWords']) && !empty($_POST['minWords']) ? $_POST['minWords'] : 0;
 $copy_result = isset($_POST['copy_result']) ? $_POST['copy_result'] : "";
 $extra_params = array('since' => $since, 'until' => $until, 'selfComments' => $selfComments, 'minLines' => $minLines, 'minWords' => $minWords, 'ignoreLinks' => $ignoreLinks, 'ignorePhotos' => $ignorePhotos, 'copy_result' => $copy_result);
 $feedParams = array('sourceId' => $_POST['group'], 'limit' => 500, 'since' => urlencode($since), 'until' => urlencode($until));
 //get Group Feed
 try {
     $groupFeed = $fb->getFeed($feedParams);
 } catch (Exception $e) {
     echo '<div class="alert-message error">' . $e->getMessage() . '</div>';
 }
 $results = $fb->getTopUsers($groupFeed, $stat, $usersCount, $extra_params);
 list($title, $auto_message) = createMsgForWallPost($results, $messages, $units, $extra_params, $stat);
 if ($copy_result) {
     echo '<textarea name="statResult" id="statResult" rows="18" class="extra_long">' . $title . $auto_message . '</textarea>';
 } else {
     echo "<strong>Title : </strong>" . $title;
     echo '<label>Replace it by this title</label><br/>';
     echo '<input type="text" name="title" id="title" value="" class="long" />';
     echo "<br/><strong>Auto Message : </strong><br/>";
     echo nl2br(strip_tags($auto_message, '<br>'));
     echo '<label>Additional Message</label><br/>';
     echo '<textarea name="additional_message" id="additional_message" rows="8" class="long"></textarea>';
     echo '<input type="hidden" id="auto_title" value="' . $title . '" />';
     echo '<input type="hidden" id="auto_message" value="' . $auto_message . '" />';
     echo '<br/><br/><input type="submit" name="publish_result" id="publish_result" value="Publish Result" class="btn primary" />';
 }
                    <h1>Facebook Group Analytics Example</h1>
                </div>
                <div class="row">
                    <div class="span10">
                        <div class="row">
<?php 
//get Group Feed
try {
    $groupFeed = $fb->getFeed($feedParams);
} catch (Exception $e) {
    echo '<div class="alert-message error">' . $e->getMessage() . '</div>';
}
// totalStatusChars - counts total characters of status updates
foreach ($stats as $stat) {
    //var_dump($stat);
    $users = $fb->getTopUsers($groupFeed, $stat, 5);
    displayUsersTable($users, $stat);
}
?>
                        </div>
                    </div>
                    <div class="span4">
                        <h3>Project Links</h3>
                        <ul>
                            <li><a href="https://github.com/rakeshtembhurne/Facebook-Groups-Analytics">Facebook Groups Analytics on Github</a></li>
                            <li><a href="https://www.facebook.com/groups/nagpurpug/">Nagpur PHP Users Group</a></li>
                        </ul>
                    </div>
                </div>
            </div>
$until = 'now';
$stat = $_POST['stat'];
$usersCount = $_POST['usersCount'];
$dateRange = array('since' => strtotime($since), 'until' => strtotime($until));
try {
    // Create Facebook Instance
    $fb = new FbStats($config);
    $feedParams = array('sourceId' => $_POST['group'], 'limit' => 500, 'since' => urlencode($since), 'until' => urlencode($until));
    //get Group Feed
    $groupFeed = $fb->getFeed($feedParams);
} catch (Exception $e) {
    $response['error'] = $e->getMessage();
}
if (!isset($response['error'])) {
    try {
        $users = $fb->getTopUsers($groupFeed, $stat, $usersCount);
        $response['success']['usersTable'] = getUsersTable($users, $stat);
        if ($users) {
            $response['success']['plainText'] = $messages[$stat] . ' since ' . $period[$since] . "\n --------------------------------------- \n";
            $i = 1;
            foreach ($users as $user) {
                if ($user[$stat]) {
                    $response['success']['plainText'] .= " \n" . $i++ . " " . $user['name'] . " with " . $user[$stat] . " " . $units[$stat];
                    //.= " \n". $i++ .". @[".$user['id'].":0:".$user['name']."] ".$user['name']." with ". $user[$stat]. " " . $units[$stat];
                }
            }
        }
    } catch (Exception $e) {
        $response['error'] = $e->getMessage();
    }
}