Exemplo n.º 1
0
 /**
  * catch all methods for the autocomplete and pass them to this controller
  *
  * @param string $method 
  * @param array $params 
  * @return void
  * @author Craig Ulliott
  */
 public function catch_all($method, array $params)
 {
     $query = array_val($params, 'q');
     $results = WIB::getClient()->call_method('autocomplete.' . $method, array('q' => $query));
     // normalize to minute
     $data = array();
     foreach ($results['results'] as $result) {
         $data[] = array($result['type'] . ':' . $result['id'] => $result['name']);
     }
     v('json/data', $data);
 }
Exemplo n.º 2
0
/**
 * call the WIB API and convert urls into trackable urls
 *
 * @param mixed $urls 
 * @return void
 * @author Craig Ulliott
 */
function track_urls($urls, $additional_params = null)
{
    // to make the code easier, and accept one or an array of urls
    if (!is_array($urls)) {
        $urls = array($urls);
        $return_single = true;
    } else {
        $return_single = false;
    }
    // save on bandwidth
    $unique_urls = array_unique($urls);
    // here we add any new params we want to the url
    if ($additional_params) {
        foreach ($unique_urls as $k => $url) {
            // we cant add params to some urls
            if (!stristr($url, 'ad.doubleclick.net')) {
                $unique_urls[$k] = http_add_params($url, $additional_params);
            }
        }
    }
    // build an assoc array to return the new urls
    $new_urls = array();
    // build cache keys
    $cache_keys = array();
    foreach ($unique_urls as $url) {
        $cache_keys[] = 'track_urls_' . $url;
    }
    // try the cache first
    foreach (Cache::get($cache_keys) as $cache_key => $lilurl) {
        $url = substr($cache_key, 11);
        // add to the new url list
        $new_urls[$url] = $lilurl;
        // remove from the $unique_urls queue
        $k = array_search($url, $unique_urls);
        if ($k !== false) {
            unset($unique_urls[$k]);
        }
    }
    // we want to get all the remaining lilurls in one call
    WIB::getClient()->start_batch();
    // loop through each
    foreach ($unique_urls as $url) {
        // if we didnt get it from the cache
        if (!array_key_exists($url, $new_urls)) {
            $response = WIB::getClient()->call_method('lilurl.create', array('url' => $url));
        }
    }
    // get the results
    $results = WIB::getClient()->run_batch();
    // get only the parts we want from each URL
    foreach ($results as $result) {
        //the url we passed to the wib api
        $tracked_url = array_val($result, array('results', 0, 'url'));
        // we now go back to the very original $urls array, as we dont want to pass back the "additional params"
        $k = array_search($tracked_url, $unique_urls);
        $original_url = $urls[$k];
        $tracking_url = array_val($result, array('results', 0, 'lilurl'));
        if ($original_url && $tracking_url) {
            // add it to the result
            $new_urls[$original_url] = $tracking_url;
            // cache it for next time
            $from_cache = Cache::add('track_urls_' . $original_url, $tracking_url);
        }
    }
    if ($return_single) {
        return reset($new_urls);
    }
    return $new_urls;
}
Exemplo n.º 3
0
 /**
  * Internally store the uid for the active user
  *
  * @param User $user 
  * @return void
  * @author Craig Ulliott
  */
 public static function setSessionUser(UserModel $user)
 {
     // we use the facebookID for the wib library
     self::$uid = $user->getID();
 }
Exemplo n.º 4
0
if ($facebookID = array_val($_SESSION, 'facebookID')) {
    // will throw an exception if invalid
    $user = m('user', $facebookID);
}
// a user called from the wib NAL, will throw an exception if invalid
if ($wib_session_user_id = array_val($_REQUEST, 'wib_session_user')) {
    $user = m($wib_session_user_id);
}
// if we are logged in then set some useful defines and setup some other classes
if ($user) {
    define('CURRENT_UID', $user->getID());
    define('CURRENT_SESSION_KEY', $user->get_facebook_token());
    // were going to call facebook using this users session
    FB::setSessionUser($user);
    // tell wib client who the active user is
    WIB::setSessionUser($user);
} else {
    define('CURRENT_UID', NULL);
    define('CURRENT_SESSION_KEY', NULL);
}
/**
 * the HTTP/HTML Template Handler & Presentation Layer (the view in mvc)
 */
require 'view.php';
// we are serving templates out of this folder
Template::setTemplatePath(CORE_PATH . 'view/');
// we are serving templates out of this folder
Template::setLayoutPath(SITE_ROOT . 'htdoc/layout/');
// the uri to target the controller
$controller = array_val($_REQUEST, 'controller');
// lots of people are going to hate this but i want to enforce denying access to global variables
Exemplo n.º 5
0
<?php

// test root directory
define('TEST_ROOT', realpath(dirname(__FILE__) . '/../') . '/');
// include the core for the framework
require TEST_ROOT . 'core/header.php';
// http://www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html
require_once 'PHPUnit/Framework.php';
// include our wrapper "test" for the PHPUnit_Framework_TestCase
require 'test.php';
// the MVC requires a view class, this view captures the changes so we can write unit tests
require 'view.php';
// craig's user
$test_user = m('user', 507521266);
// for tests that require a users is logged in
Test::setUser($test_user);
// were going to call facebook using this users session
FB::setSessionUser($test_user);
// tell wib client who the active user is
WIB::setSessionUser($test_user);