From d653412f86b269032158807f2d51523ad54952e4 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Sat, 17 Dec 2011 23:48:53 -0800 Subject: [PATCH] setup on local dev --- .htaccess | 1 + data.php | 56 ++++++++++++++++++------------------- get.php | 1 + index.php | 82 +++++++++++++++++++++++++++---------------------------- 4 files changed, 71 insertions(+), 69 deletions(-) diff --git a/.htaccess b/.htaccess index c8fdc6b..b0f633f 100644 --- a/.htaccess +++ b/.htaccess @@ -4,3 +4,4 @@ RewriteEngine On # redirect every other request to the index RewriteRule /*\.(css|php|js|gif|png|jpe?g)$ - [NC,L] RewriteRule ^(.*)$ index.php?_url=$1 [QSA,L] + diff --git a/data.php b/data.php index ee63c0d..f071328 100644 --- a/data.php +++ b/data.php @@ -1,40 +1,40 @@ getMessage(); - } +function get_db_connection() +{ + try { + return $dbh = new PDO(DB_DSN, DB_UNAME, DB_PW); } + catch(PDOException $e) { + return $e->getMessage(); + } +} - function get_user() - { - return isset($_SESSION['user']) ? $_SESSION['user'] : false; - } +function get_user() +{ + return isset($_SESSION['user']) ? $_SESSION['user'] : false; +} - function get_users(&$dbh, $args) - { - $user = isset($args['user']) ? $args['user'] : false; +function get_users(&$dbh, $args) +{ + $user = isset($args['user']) ? $args['user'] : false; - try { - if ($user) { - $sql = "SELECT * FROM users WHERE user = ?"; - $q = $dbh->prepare($sql); - $q->execute( array( $user )); - if ($q->rowCount() == 1) { - return $q->fetch(); - } + try { + if ($user) { + $sql = "SELECT * FROM users WHERE user = ?"; + $q = $dbh->prepare($sql); + $q->execute( array( $user )); + if ($q->rowCount() == 1) { + return $q->fetch(); } } - catch (PDOException $e) { - echo $e->getMessage(); - } + } + catch (PDOException $e) { + echo $e->getMessage(); + } - return false; - } \ No newline at end of file + return false; +} \ No newline at end of file diff --git a/get.php b/get.php index 4de5fce..269b7db 100644 --- a/get.php +++ b/get.php @@ -6,6 +6,7 @@ $params['user'] = isset($_GET['user']) ? $_GET['user'] : null; $dbh = get_db_connection(); + $dbh->beginTransaction(); try { diff --git a/index.php b/index.php index c48a293..dd3428f 100644 --- a/index.php +++ b/index.php @@ -1,47 +1,47 @@ source on github'; - echo '
© 2011 quilime'; - exit; - - default : - if ($endpoint != '') { - - $dbh = get_db_connection(); - $dbh->beginTransaction(); - $user = get_users($dbh, array( 'user' => $endpoint )); - $dbh = null; - if ( isset($user['user']) ) { - $get = function( $user ) { - $_GET['user'] = $user; - }; - $get( $user['user'] ); - } +require_once 'init.php'; + +$url = isset($_GET['_url']) ? trim($_GET['_url'], '/') : '/'; + +list($endpoint) = explode('/', $url); + +$pathinfo = pathinfo($_SERVER['REQUEST_URI']); +$format = isset($pathinfo['extension']) ? $pathinfo['extension'] : null; + +$endpoint = str_replace('.'.$format, '', $endpoint); + +switch($endpoint) +{ + case 'about' : + include 'head.html'; + echo "clmpr is a place to save hyperlinks"; + echo '
source on github'; + echo '
© 2011 quilime'; + exit; + + default : + if ($endpoint != '') { + + $dbh = get_db_connection(); + $dbh->beginTransaction(); + $user = get_users($dbh, array( 'user' => $endpoint )); + $dbh = null; + if ( isset($user['user']) ) { + $get = function( $user ) { + $_GET['user'] = $user; + }; + $get( $user['user'] ); } - } + } +} - switch ($format) { - case 'rss' : - case 'xml' : - include 'get.php'; - exit; - } +switch ($format) { + case 'rss' : + case 'xml' : + include 'get.php'; + exit; +} ?> @@ -61,7 +61,7 @@

bookmarklet: +

-- 2.34.1