예제 #1
0
<?php

/**
 * TODO handle mysqli prepare errors
 * @file
 * Get tweets for a specific channel ID
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/config/main.conf.php';
require $_SERVER['DOCUMENT_ROOT'] . '/lib/helpers.php';
if ($_GET['cid'] == 0) {
    $cache_time_secs = 120;
} else {
    $cache_time_secs = 30;
}
check_required_get_params(array('cid' => 'numeric'));
if (isset($_GET['rpp']) && is_numeric($_GET['rpp'])) {
    $limit = $_GET['rpp'];
    $do_cache = FALSE;
} else {
    $limit = 100;
    $do_cache = TRUE;
}
if ($do_cache) {
    $root = $_SERVER['DOCUMENT_ROOT'];
    $cachefile = $root . '/cache/' . basename($_SERVER['PHP_SELF'], '.php');
    $cachefile .= ".chan-{$_GET['cid']}.cache";
    clearstatcache();
    if (file_exists($cachefile) && filemtime($cachefile) > time() - $cache_time_secs) {
        // good to serve!
        include $cachefile;
        exit;
예제 #2
0
<?php

/**
 * @file
 * For any attendees without uid's, use their screen_name to get their UID from twitter
 */
require_once '../config/main.conf.php';
require '../lib/helpers.php';
require '../lib/twitrest/twitterrest.php';
check_required_get_params(array('screen_name' => 'string'));
$screen_name = $_GET['screen_name'];
$mysqli = new mysqli(DBHOST, DBUSER, DBPASS, DB);
if (mysqli_connect_error()) {
    $message = 'database error ' . mysqli_connect_errno() . ': ' . mysqli_connect_error();
    die(to_json(array('success' => FALSE, 'code' => 10, 'message' => $message)));
}
$twitterRest = new TwitterRest();
$twitterRest->decode_json = TRUE;
$i = 0;
if ($stmt = $mysqli->prepare("INSERT into attendee (screen_name, uid) values(?, ?) ON DUPLICATE KEY UPDATE uid=?")) {
    $user = $twitterRest->get('users/show', array('screen_name' => $screen_name));
    if ($user->error) {
        die(to_json(array('success' => FALSE, 'code' => 10, 'message' => $user->error)));
    } else {
        $stmt->bind_param('sdd', $screen_name, $user->id, $user->id);
        if (!$stmt->execute()) {
            error_log("Failed to update or add attendee: " . $mysqli->error);
        }
        $stmt->close();
    }
}