<?php
- function get_db_connection()
- {
- try {
- return $dbh = new PDO(DB_DSN, DB_UNAME, DB_PW);
- }
- catch(PDOException $e) {
- return $e->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
<?php
- require_once 'init.php';
-
- $url = trim($_GET['_url'], '/');
-
- list($endpoint) = explode('/', $url);
-
- $pathinfo = pathinfo($_SERVER['SCRIPT_URL']);
- $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 '<br /><a href="https://github.com/quilime/clmpr">source on github</a>';
- echo '<br />© 2011 <a href="http://quilime.com">quilime</a>';
- 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 '<br /><a href="https://github.com/quilime/clmpr">source on github</a>';
+ echo '<br />© 2011 <a href="http://quilime.com">quilime</a>';
+ 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;
+}
?><!DOCTYPE html>
<p>
bookmarklet:
<?php
-$js = file_get_contents('bookmarklet.js');
+ $js = file_get_contents('bookmarklet.js');
?>
<a href="javascript:<?=$js?>">+</a>
</p>