예제 #1
1
파일: index.php 프로젝트: scarlettkuro/xii
<?php

require_once 'autoload.php';
//load app classes
require_once 'lib/limonade.php';
dispatch('/css/:css', 'AssetController::css');
dispatch('/js/:js', 'AssetController::js');
//ROUTES
dispatch_get('/', 'PostController::index');
dispatch_get('/new', 'PostController::neew');
//R
dispatch_get('/edit/:post', 'PostController::edit');
//R
dispatch_post('/:post', 'PostController::save');
//C, U
dispatch_get('/:post', 'PostController::post');
dispatch_post('/remove/:post', 'PostController::remove');
//D
run();
예제 #2
0
 /**
  * Define a GET route for AJAX GET with token validation
  * @param string $route
  * @param \Closure $closure
  */
 public static function get($route, \Closure $closure, $getNewStuff = true)
 {
     if (!\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
         $getNewStuff = false;
         //not available for guests
     }
     dispatch_get($route, function () use($closure, $getNewStuff) {
         Request::processReq($closure, $getNewStuff, func_get_args());
     });
 }
예제 #3
0
dispatch_get('uni_login/login/:name', function ($name) {
    // config and includes
    $config = SYSPATH . 'Ext/hybridauth/config.php';
    require_once SYSPATH . "Ext/hybridauth/Hybrid/Auth.php";
    try {
        // hybridauth EP
        $hybridauth = new Hybrid_Auth($config);
        // automatically try to login with Twitter
        $adapter = $hybridauth->authenticate($name);
        // get the user profile
        $user_profile = $adapter->getUserProfile();
        //        var_dump($user_profile);
        //oauth identifier
        $oauth_id = md5($name . $user_profile->identifier);
        $db = \DB::getPDO();
        $qry = 'SELECT id, username, avatar FROM ' . PREFIX . 'codo_users WHERE oauth_id=:oauth_id';
        $stmt = $db->prepare($qry);
        $stmt->execute(array(":oauth_id" => $oauth_id));
        $username = CODOF\Filter::clean_username($user_profile->displayName);
        $profile = $stmt->fetch();
        if (!empty($profile)) {
            if ($username != $profile['username'] || $user_profile->photoURL != $profile['avatar']) {
                //profile has been updated remotely
                $qry = 'UPDATE ' . PREFIX . 'codo_users SET username=:name,avatar=:avatar WHERE oauth_id=:id';
                $stmt = $db->prepare($qry);
                $stmt->execute(array(":name" => $username, ":avatar" => $user_profile->photoURL, ":id" => $oauth_id));
            }
            CODOF\User\User::login($profile['id']);
        } else {
            //no local copy of this profile yet
            $mail = $user_profile->email;
            $create_account = true;
            if ($mail == null) {
                $mail = '';
            } else {
                //we got an email, lets check if it exists
                $qry = "SELECT id FROM " . PREFIX . "codo_users WHERE mail=:mail";
                $stmt = $this->db->prepare($qry);
                $stmt->execute(array(":mail" => $mail));
                $res = $stmt->fetch();
                if (!empty($res)) {
                    //looks like this user has already registered
                    $create_account = false;
                    CODOF\User\User::login($res['id']);
                    //now this will work if you change authentication from
                    //fb to gmail etc
                }
            }
            if ($create_account) {
                $reg = new CODOF\User\Register($db);
                $reg->mail = $mail;
                $reg->name = $user_profile->firstName . ' ' . $user_profile->lastName;
                $reg->oauth_id = $oauth_id;
                $reg->username = $username;
                $reg->avatar = $user_profile->photoURL;
                $reg->user_status = 1;
                //approved user
                $reg->register_user();
                $reg->login();
            }
        }
        header('Location: ' . CODOF\User\User::getProfileUrl());
        //$adapter->logout();
    } catch (Exception $e) {
        // In case we have errors 6 or 7, then we have to use Hybrid_Provider_Adapter::logout() to
        // let hybridauth forget all about the user so we can try to authenticate again.
        // Display the recived error,
        // to know more please refer to Exceptions handling section on the userguide
        switch ($e->getCode()) {
            case 0:
                echo "Unspecified error.";
                break;
            case 1:
                echo "Hybridauth configuration error.";
                break;
            case 2:
                echo "Provider not properly configured.";
                break;
            case 3:
                echo "Unknown or disabled provider.";
                break;
            case 4:
                echo "Missing provider application credentials.";
                break;
            case 5:
                echo "Authentication failed. " . "The user has canceled the authentication or the provider refused the connection.";
                break;
            case 6:
                echo "User profile request failed. Most likely the user is not connected " . "to the provider and he should to authenticate again.";
                $adapter->logout();
                break;
            case 7:
                echo "User not connected to the provider.";
                $adapter->logout();
                break;
            case 8:
                echo "Provider does not support this feature.";
                break;
        }
    }
});
예제 #4
0
/**
 * An alias of {@link dispatch_get()}
 *
 * @return void
 */
function dispatch($path_or_array, $function, $options = array())
{
    dispatch_get($path_or_array, $function, $options);
}
예제 #5
0
{
    (int) $id;
    return $id;
}
dispatch('/route8c/:id', 'test_route8c', array('params' => array('divider' => 2)));
function test_route8c($divider, $id)
{
    (int) $id;
    return $id / $divider;
}
dispatch('/route9/*', 'MyController::staticMethod');
dispatch('/route9b/*', 'MyController::staticMethod', array('params' => array(10)));
dispatch(array('/route10/*', array('id')), 'MyController::staticMethod');
dispatch(array('/route10b/*', array('id')), 'MyController::staticMethod', array('params' => array('id' => 10)));
/* http methods dispatching */
dispatch_get('/route11', 'test_route11');
function test_route11()
{
    header('X-LIM-CTL: route11');
    return "GET";
}
dispatch_post('/route11', 'test_route11post');
function test_route11post()
{
    //header('Content-length: 4');
    return "POST";
}
dispatch_put('/route11', 'test_route11put');
function test_route11put()
{
    return "PUT";
예제 #6
0
/**
 * an alias of dispatch_get
 *
 * @return void
 */
function dispatch($path_or_array, $function, $agent_regexp = null)
{
    dispatch_get($path_or_array, $function, $agent_regexp);
}
예제 #7
0
dispatch_get('/new_topic', function () {
    $forum = new \Controller\forum();
    $forum->manage_topic();
    CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);
});
dispatch_get('/tags/:tag/:page', function ($tag, $page = 1) {
    if (!isset($tag)) {
        return \CODOF\Smarty\Layout::not_found();
    }
    CODOF\Store::set('meta:robots', 'noindex, follow');
    $clean_tag = strip_tags($tag);
    $forum = new Controller\forum();
    $forum->listTaggedTopics($clean_tag, $page);
    CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);
});
//-------------INDEX------------------------------------------------------------
dispatch_get('/', function () {
    global $installed;
    if (!$installed) {
        $url = str_replace("index.php?u=/", "", RURI);
        header("Location: " . $url . "install/index.php");
    }
    $forum = new \Controller\forum();
    $forum->topics(1);
    CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);
});
function not_found($errno, $errstr, $errfile = null, $errline = null)
{
    CODOF\Smarty\Layout::not_found();
}
Request::start();
예제 #8
0
/**
 * an alias of dispatch_get
 *
 * @return void
 */
function dispatch($path_or_array, $function)
{
    dispatch_get($path_or_array, $function);
}
예제 #9
0
    option('env', $env);
    option('dsn', $dsn);
    option('db_conn', $db);
    option('debug', true);
}
function after($output)
{
    $time = number_format((double) substr(microtime(), 0, 10) - LIM_START_MICROTIME, 6);
    $output .= "<!-- page rendered in {$time} sec., on " . date(DATE_RFC822) . "-->";
    return $output;
}
layout('layout/default.html.php');
// main controller
dispatch('/', 'main_page');
// books controller
dispatch_get('books', 'books_index');
dispatch_post('books', 'books_create');
dispatch_get('books/new', 'books_new');
dispatch_get('books/:id/edit', 'books_edit');
dispatch_get('books/:id', 'books_show');
dispatch_put('books/:id', 'books_update');
dispatch_delete('books/:id', 'books_destroy');
// authors controller
dispatch_get('authors', 'authors_index');
dispatch_post('authors', 'authors_create');
dispatch_get('authors/new', 'authors_new');
dispatch_get('authors/:id/edit', 'authors_edit');
dispatch_get('authors/:id', 'authors_show');
dispatch_put('authors/:id', 'authors_update');
dispatch_delete('authors/:id', 'authors_destroy');
run();
예제 #10
0
파일: index.php 프로젝트: kentana20/isucon3
dispatch_get('/memo/:id', function () {
    $db = option('db_conn');
    $user = get('user');
    $stmt = $db->prepare('SELECT id, user, content, is_private, created_at, updated_at FROM memos WHERE id = :id');
    $stmt->bindValue(':id', params('id'));
    $stmt->execute();
    $memo = $stmt->fetch(PDO::FETCH_ASSOC);
    if (!$memo) {
        return halt(404);
    }
    if ($memo['is_private'] != 0) {
        if (!$user || $user['id'] != $memo['user']) {
            return halt(404);
        }
    }
    $memo['content_html'] = markdown($memo['content']);
    $stmt = $db->prepare('SELECT username FROM users WHERE id = :id');
    $stmt->bindValue(':id', $memo['user']);
    $stmt->execute();
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $memo['username'] = $row['username'];
    if ($user && $user['id'] == $memo['user']) {
        $cond = "";
    } else {
        $cond = "AND is_private=0";
    }
    $stmt = $db->prepare("SELECT * FROM memos WHERE user = :user " . $cond . " ORDER BY created_at");
    $stmt->bindValue(':user', $memo['user']);
    $stmt->execute();
    $memos = $stmt->fetchAll(PDO::FETCH_ASSOC);
    $older = null;
    $newer = null;
    for ($i = 0; $i < count($memos); $i++) {
        if ($memos[$i]['id'] == $memo['id']) {
            if ($i > 0) {
                $older = $memos[$i - 1];
            }
            if ($i < count($memos) - 1) {
                $newer = $memos[$i + 1];
            }
        }
    }
    set('memo', $memo);
    set('older', $older);
    set('newer', $newer);
    return html('memo.html.php');
});
예제 #11
0
dispatch_get("/promos/get/:promo", "getPromo");
//get a promo
dispatch_post("/promos/add/:promo/:label", "addPromo");
//add a promo
dispatch_post("/promos/del/:promo", "delPromo");
//delete a promo
dispatch_post("/promos/upd/:promo/:newLabel", "updPromo");
//update promo
dispatch_get("/files/get/:id", "getFile");
//get file
dispatch_get("/files/get/promo/:promo", "getFile");
//get files associated with promo
dispatch_post("/files/add/:promo/:rang/:libelle", "addFile");
//add a file
dispatch_post("/files/del/:id", "delFile");
//delete a file
dispatch_post("/files/upd/:id/:promo/:rang/:libelle", "updFile");
//upd file
dispatch_get("/datas/get/all", "getData");
//gat all data
dispatch_get("/datas/get/:id", "getData");
//get a data
dispatch_get("/datas/xtr", "xtrData");
//export datas
dispatch_post("/datas/upd/:id/:identifiant/:nom_fils/:prenom_fils/:ddn_fils/:tel_mobile/:courriel", "updData");
//update data
dispatch_post("/datas/del/all", "delData");
//delete all datas
dispatch_post("/datas/del/:id", "delData");
//delete one data
run();
예제 #12
0
파일: index.php 프로젝트: kentana20/isucon3
dispatch_get('/timeline', function () {
    $db = option('db_conn');
    $user = get('user');
    $latest_entry = $_GET['latest_entry'];
    if ($latest_entry) {
        $stmt = $db->prepare('SELECT * FROM (SELECT * FROM entries WHERE (user = :user OR publish_level = 2 OR (publish_level = 1 AND user IN (SELECT target FROM follow_map WHERE user = :user))) AND id > :id ORDER BY id LIMIT 30) AS e ORDER BY e.id DESC');
        $stmt->bindValue(':user', $user['id']);
        $stmt->bindValue(':id', $latest_entry);
    } else {
        $stmt = $db->prepare('SELECT * FROM entries WHERE (user = :user OR publish_level = 2 OR (publish_level = 1 AND user IN (SELECT target FROM follow_map WHERE user = :user))) ORDER BY id DESC LIMIT 30');
        $stmt->bindValue(':user', $user['id']);
    }
    $start = time();
    while (time() - $start < constant('TIMEOUT')) {
        $stmt->execute();
        $entries = $stmt->fetchAll(PDO::FETCH_ASSOC);
        if (count($entries) == 0) {
            sleep(constant('INTERVAL'));
            continue;
        } else {
            $latest_entry = $entries[0]['id'];
            break;
        }
    }
    $entries_arranged = array();
    foreach ($entries as $entry) {
        $stmt = $db->prepare('SELECT * FROM users WHERE id = :id');
        $stmt->bindValue(':id', $entry['user']);
        $stmt->execute();
        $user = $stmt->fetch(PDO::FETCH_ASSOC);
        $entries_arranged[] = array('id' => $entry['id'], 'image' => uri_for('/image/' . $entry['image']), 'publish_level' => $entry['publish_level'], 'user' => array('id' => $user['id'], 'name' => $user['name'], 'icon' => uri_for('/icon/' . $user['icon'])));
    }
    return json(array('latest_entry' => $latest_entry, 'entries' => $entries_arranged));
});
예제 #13
0
<?php

require_once 'autoload.php';
//load app classes
require_once 'lib/limonade.php';
dispatch('/css/:css', 'AssetController::css');
dispatch('/js/:js', 'AssetController::js');
//REST API
dispatch_get('/api/users', 'UserController::index');
dispatch_get('/api/users/:id', 'UserController::get');
dispatch_post('/api/users', 'UserController::post');
dispatch_put('/api/users/:id', 'UserController::put');
dispatch_delete('/api/users/:id', 'UserController::remove');
dispatch_get('/api/users/search/:name', 'UserController::search');
//pages
dispatch('/', 'MainController::index');
run();
예제 #14
0
require dirname(__DIR__) . '/lib/limonade.php';
//
// configuration
//
function configure()
{
    option('root_dir', dirname(__DIR__));
    option('views_dir', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'views');
    option('controllers_dir', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'controllers');
    option('lib_dir', dirname(__DIR__) . DIRECTORY_SEPARATOR . 'lib');
    option('public_dir', __DIR__);
}
function before()
{
    layout('layouts/layout.phtml');
}
//
// application
//
dispatch_get('/', function () {
    return html('index.phtml');
});
dispatch_get('/shopsavvy/:id', function ($id) {
    if (empty($id)) {
        halt(NOT_FOUND);
    }
    $json = file_get_contents("http://api.developer.shopsavvy.mobi/products/{$id}.json?apikey=91f7ccdc3a32b5ba899e64fd191942c8");
    return $json;
});
run();
예제 #15
0
    option('env', ENV_DEVELOPMENT);
    option('debug', true);
    option('session', 'Yummy_Plus3_Session_Cookie');
    // true, false or the name of your session
    option('encoding', 'utf-8');
}
// END function configure()
# the index request
dispatch('/', function () {
    return 'hello world';
});
dispatch('/phpinfo', function () {
    phpinfo();
    return;
});
$echo = function () {
    setcookie('example', 'test');
    $response = array();
    foreach ($GLOBALS as $key => $data) {
        if ($key != 'GLOBALS') {
            $response[$key] = $data;
        }
    }
    $response['_HEADERS'] = http_get_request_headers();
    return json($response);
};
dispatch_get('/echo', $echo);
dispatch_post('/echo', $echo);
dispatch_put('/echo', $echo);
dispatch_delete('/echo', $echo);
run();
예제 #16
0
파일: limonade.php 프로젝트: soitun/CRMx
/**
 * An alias of {@link dispatch_get()}
 *
 * @return void
 */
function dispatch($path_or_array, $callback, $options = array())
{
    dispatch_get($path_or_array, $callback, $options);
}
예제 #17
0
<?php

require_once "lib/limonade.php";
dispatch_get("/", "redirect_data");
dispatch_get("/data", "data");
dispatch_get("/data/extract", "data_extract");
dispatch_get("/document", "document");
dispatch_get("/promo", "promo");
dispatch_post("/document", "add_document");
dispatch_post("/promo", "add_promo");
dispatch_put("/data/:dataid", "alter_data");
dispatch_put("/document/:documentid", "alter_document");
dispatch_put("/promo/:promoid", "alter_promo");
dispatch_delete("/document/:fileid", "delete_document");
dispatch_delete("/promo/:promoid", "delete_promo");
try {
    run();
} catch (Exception $e) {
    error_log($e);
}
예제 #18
0
dispatch_get('/me/final_report', function () {
    $advertiser_id = advertiser_id();
    if (empty($advertiser_id)) {
        halt(401);
    }
    $reports = [];
    $redis = option('redis');
    $ad_keys = $redis->smembers(advertiser_key($advertiser_id));
    foreach ($ad_keys as $ad_key) {
        $ad = $redis->hgetall($ad_key);
        if (empty($ad)) {
            continue;
        }
        $imp = intval(fetch($ad, 'impressions', 0));
        $ad['impressions'] = $imp;
        $reports[$ad['id']] = ['ad' => $ad, 'clicks' => 0, 'impressions' => $imp];
    }
    $logs = get_log($advertiser_id);
    foreach ($reports as $ad_id => $report) {
        $log = fetch($logs, $ad_id, []);
        $report['clicks'] = count($log);
        $breakdown = array('gender' => (object) [], 'agents' => (object) [], 'generations' => (object) []);
        foreach ($log as $click) {
            incr_hash($breakdown['gender'], $click['gender']);
            incr_hash($breakdown['agents'], $click['agent']);
            if (isset($click['age']) && !empty($click['age'])) {
                $generation = intval($click['age'] / 10);
            } else {
                $generation = 'unknown';
            }
            incr_hash($breakdown['generations'], $generation);
        }
        $report['breakdown'] = $breakdown;
        $reports[$ad_id] = $report;
    }
    return json((object) $reports);
});
예제 #19
0
function fz_dispatch_get($path_or_array, $controller, $action)
{
    return dispatch_get($path_or_array, 'fz_dispatcher', array('params' => array('controller' => $controller, 'action' => $action)));
}
예제 #20
0
        return redirect_to('/mypage');
    } else {
        switch ($result['error']) {
            case 'locked':
                flash('notice', 'This account is locked.');
                break;
            case 'banned':
                flash('notice', "You're banned.");
                break;
            default:
                flash('notice', 'Wrong username or password');
                break;
        }
        return redirect_to('/');
    }
});
dispatch_get('/mypage', function () {
    $user = current_user();
    if (empty($user)) {
        flash('notice', 'You must be logged in');
        return redirect_to('/');
    } else {
        set('user', $user);
        set('last_login', last_login());
        return html('mypage.html.php');
    }
});
dispatch_get('/report', function () {
    return json_encode(['banned_ips' => banned_ips(), 'locked_users' => locked_users()]);
});
run();