From a73791f16d10ea0e2c477f29d9049d75516aa774 Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Sun, 16 Sep 2012 01:17:46 -0400 Subject: Added OpenID Authentication --- src/openid/config.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/openid/wrapper.php | 27 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/openid/config.php create mode 100644 src/openid/wrapper.php (limited to 'src') diff --git a/src/openid/config.php b/src/openid/config.php new file mode 100644 index 0000000..fdec5e1 --- /dev/null +++ b/src/openid/config.php @@ -0,0 +1,55 @@ + + * @copyright 2009 Bill Shupp + * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD + * @link http://github.com/shupp/openid + */ + +set_include_path(dirname(__FILE__) . '/../../:' . get_include_path()); + +/** + * Required files + */ +require_once 'OpenID/RelyingParty.php'; +require_once 'OpenID/Discover.php'; +require_once 'OpenID/Store.php'; +require_once 'OpenID/Extension/SREG10.php'; +require_once 'OpenID/Extension/SREG11.php'; +require_once 'OpenID/Extension/AX.php'; +require_once 'OpenID/Extension/UI.php'; +require_once 'OpenID/Extension/OAuth.php'; +require_once 'OpenID/Message.php'; +require_once 'OpenID/Observer/Log.php'; +require_once 'Net/URL2.php'; + +// Determine realm and return_to +$base = 'http'; +if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { + $base .= 's'; +} +$base .= '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; + +$realm = $base . '/'; +$returnTo = $base . dirname($_SERVER['PHP_SELF']); +if ($returnTo[strlen($returnTo) - 1] != '/') { + $returnTo .= '/'; +} +$returnTo .= 'auth'; + +// SQL storage example +// $storeOptions = array( +// 'dsn' => 'mysql://user:pass@db.example.com/openid' +// ); +// OpenID::setStore(OpenID_Store::factory('MDB2', $storeOptions)); +// +// // The first time you run it, you'll also need to create the tables: +// OpenID::getStore()->createTables(); + +?> diff --git a/src/openid/wrapper.php b/src/openid/wrapper.php new file mode 100644 index 0000000..cb57f4e --- /dev/null +++ b/src/openid/wrapper.php @@ -0,0 +1,27 @@ + + * @copyright 2009 Bill Shupp + * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD + * @link http://github.com/shupp/openid + */ +?> + + + PEAR OpenID Debug + + + + + + -- cgit v1.2.3 From 5935a357efd7be14481b21560347f70116891e16 Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Sun, 16 Sep 2012 13:52:17 -0400 Subject: ADD: Commit as logged in user --- data/config.default.php | 1 + src/phorkie/Repository/Post.php | 14 ++++++++++---- www/edit.php | 2 +- www/new.php | 2 +- www/www-header.php | 6 ++++++ 5 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/data/config.default.php b/data/config.default.php index 7ecbda3..da16241 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -15,6 +15,7 @@ $GLOBALS['phorkie']['cfg'] = array( $GLOBALS['phorkie']['auth'] = array( 'secure' => 0, // 0 = public, no authentication, 1 = protect adds/edits/deletes, 2 = use authentication 'userlist' => false, // true = user must be explicitly defined, false = anyone allowed, but they must authenticate + 'anonymousName' => 'Anonymous', // Email for non-authenticated commits 'anonymousEmail' => 'anonymous@phorkie' // Email for non-authenticated commits ); $GLOBALS['phorkie']['tools'] = array( diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index de987e0..ed44cf1 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -15,7 +15,7 @@ class Repository_Post * * @return boolean True if the post was successful */ - public function process($postData) + public function process($postData, $sessionData) { if (!isset($postData['files'])) { return false; @@ -117,11 +117,17 @@ class Repository_Post } } + $commitmsg = "phorkie commit"; + if (isset($sessionData['identity'])) { + $commitmsg .= " from ".$sessionData['identity']; + } else { + $commitmsg .= " by ".$sessionData['ipaddr']; + } + if ($bCommit) { $vc->getCommand('commit') - ->setOption('message', '') - ->setOption('allow-empty-message') - ->setOption('author', 'Anonymous ') + ->setOption('message', $commitmsg) + ->setOption('author', $sessionData['name'].' <'.$sessionData['email'].'>') ->execute(); $bChanged = true; } diff --git a/www/edit.php b/www/edit.php index 226b774..db4428b 100644 --- a/www/edit.php +++ b/www/edit.php @@ -12,7 +12,7 @@ $repo = new Repository(); $repo->loadFromRequest(); $repopo = new Repository_Post($repo); -if ($repopo->process($_POST)) { +if ($repopo->process($_POST, $_SESSION)) { redirect($repo->getLink('display')); } diff --git a/www/new.php b/www/new.php index fc6d5f3..8d1a231 100644 --- a/www/new.php +++ b/www/new.php @@ -16,7 +16,7 @@ if ($GLOBALS['phorkie']['auth']['secure'] > 0) { } $repopo = new Repository_Post(); -if ($repopo->process($_POST)) { +if ($repopo->process($_POST, $_SESSION)) { redirect($repopo->repo->getLink('display')); } diff --git a/www/www-header.php b/www/www-header.php index 74863e1..5785a3e 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -47,6 +47,12 @@ if (file_exists(__DIR__ . '/../data/config.php')) { if ($GLOBALS['phorkie']['cfg']['setupcheck']) { SetupCheck::run(); } + +// Set/Get git commit session variables +$_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR']; +if (!isset($_SESSION['name'])) { $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName']; } +if (!isset($_SESSION['email'])) { $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail']; } + \Twig_Autoloader::register(); $loader = new \Twig_Loader_Filesystem($GLOBALS['phorkie']['cfg']['tpl']); -- cgit v1.2.3 From 0845bf175dc416cdf107209fc34f7b37bf42b6e6 Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Sun, 16 Sep 2012 15:17:28 -0400 Subject: data/templates/revision-head.htm - ADD: display commit message --- data/templates/revision-head.htm | 1 + src/phorkie/Repository.php | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/data/templates/revision-head.htm b/data/templates/revision-head.htm index 132a68f..a5f7e88 100644 --- a/data/templates/revision-head.htm +++ b/data/templates/revision-head.htm @@ -10,6 +10,7 @@ revision {{repo.hash}}

+ message {{repo.message}}

diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 448982b..6ed3807 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -32,6 +32,12 @@ class Repository */ public $hash; + /** + * Commit message of the last (or current) revision + * + * @var string + */ + public $message; /** @@ -56,6 +62,7 @@ class Repository $this->id = (int)$_GET['id']; $this->loadDirs(); $this->loadHash(); + $this->loadMessage(); } protected function loadDirs() @@ -97,6 +104,23 @@ class Repository $this->hash = $output; } + public function loadMessage() + { + $rev = (isset($this->hash)) ? $this->hash : 'HEAD'; + $output = $this->getVc()->getCommand('log') + ->setOption('oneline') + ->addArgument('-1') + ->addArgument($rev) + ->execute(); + $output = trim($output); + if (strpos($output, ' ') > 0) { + $output = substr($output, strpos($output, ' '), strlen($output)); + $this->message = trim($output); + } else { + $this->message = "This commit message intentionally left blank."; + } + } + public function loadById($id) { if (!is_numeric($id)) { -- cgit v1.2.3 From 2935763e253c3616d951bc18c7d21a56349531fa Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Sun, 16 Sep 2012 15:37:49 -0400 Subject: Updated ChangeLog and README.rst --- ChangeLog | 4 ++++ README.rst | 14 ++++++++++++++ src/phorkie/Repository.php | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/ChangeLog b/ChangeLog index 7e45b7d..35e7456 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-09-16 Justin J. Novack + + * Add OpenID authentication + 2012-09-08 Christian Weiske * Fix bug #11: do not index edit, delete and tool pages diff --git a/README.rst b/README.rst index c94f29e..56bef95 100644 --- a/README.rst +++ b/README.rst @@ -190,6 +190,15 @@ URLs List all pastes, with optional page ``/new`` Shows form for new paste +``/login`` + Login page for protecting site +``/auth`` + Authentication callback url +``/forbidden`` + Access denied page +``/user`` + Edit logged-in user information + Internal directory layout ========================= @@ -227,4 +236,9 @@ If you use nginx, place the following lines into your ``server`` block: rewrite ^/search$ /search.php; rewrite ^/search/([0-9]+)$ /search.php?page=$1; + + rewrite ^/login$ /login.php; + rewrite ^/auth$ /auth.php; + rewrite ^/forbidden$ /forbidden.php; + rewrite ^/user$ /user.php; } diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 6ed3807..9f8f264 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -118,7 +118,7 @@ class Repository $this->message = trim($output); } else { $this->message = "This commit message intentionally left blank."; - } + } } public function loadById($id) -- cgit v1.2.3 From f9ade082ba49cf487af31339afa7aeeb0653af57 Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Mon, 17 Sep 2012 13:42:49 -0400 Subject: PEAR Coding Standards intermediate update for files changed --- src/phorkie/Repository.php | 5 +++++ www/auth.php | 11 ++++------- www/delete.php | 2 +- www/display.php | 2 +- www/edit.php | 2 +- www/forbidden.php | 2 +- www/fork.php | 4 ++-- www/list.php | 2 +- www/new.php | 2 +- www/raw.php | 2 +- www/user.php | 2 +- www/www-header.php | 8 ++++++-- 12 files changed, 25 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 995a16d..43f2b23 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -104,6 +104,11 @@ class Repository $this->hash = $output; } + /** + * Populates $this->message + * + * @return void + */ public function loadMessage() { $rev = (isset($this->hash)) ? $this->hash : 'HEAD'; diff --git a/www/auth.php b/www/auth.php index b8d08ff..1cafd59 100644 --- a/www/auth.php +++ b/www/auth.php @@ -27,7 +27,7 @@ if (isset($_REQUEST['logout'])) { session_destroy(); $redirect = 'http://' . $_SERVER['HTTP_HOST']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); - exit; + exit; } if (!count($_GET) && !count($_POST)) { @@ -59,9 +59,7 @@ try { exit; } -if (!empty($_POST['disable_associations']) - || !empty($_SESSION['disable_associations'])) { - +if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associations'])) { $o->disableAssociations(); $_SESSION['disable_associations'] = true; } @@ -159,8 +157,7 @@ if (isset($_POST['start'])) { $mode = $message->get('openid.mode'); try { - $result = $o->verify(new Net_URL2($returnTo . '?' . $queryString), - $message); + $result = $o->verify(new Net_URL2($returnTo . '?' . $queryString), $message); if ($result->success()) { $status = "Status:SUCCESS!"; @@ -202,7 +199,7 @@ if (isset($_POST['start'])) { $openid = $message->getArrayFormat(); - $email = (isset($openid['openid.ext1.value.email'])) ? $openid['openid.ext1.value.email'] : null; + $email = (isset($openid['openid.ext1.value.email'])) ? $openid['openid.ext1.value.email'] : null; $email = (isset($openid['openid.ext2.value.email']) && !isset($email)) ? $openid['openid.ext2.value.email'] : $email; $email = (isset($openid['openid.sreg.email']) && !isset($email)) ? $openid['openid.sreg.email'] : $email; $email = (isset($openid['openid.ax.value.email']) && !isset($email)) ? $openid['openid.ax.value.email'] : $email; diff --git a/www/delete.php b/www/delete.php index f332028..85f6258 100644 --- a/www/delete.php +++ b/www/delete.php @@ -5,7 +5,7 @@ namespace phorkie; */ require_once 'www-header.php'; if ($GLOBALS['phorkie']['auth']['secure'] > 0) { - require_once 'secure.php'; + include_once 'secure.php'; } $repo = new Repository(); diff --git a/www/display.php b/www/display.php index 2376d30..6f754d9 100644 --- a/www/display.php +++ b/www/display.php @@ -5,7 +5,7 @@ namespace phorkie; */ require_once 'www-header.php'; if ($GLOBALS['phorkie']['auth']['secure'] == 2) { - require_once 'secure.php'; + include_once 'secure.php'; } $repo = new Repository(); diff --git a/www/edit.php b/www/edit.php index db4428b..20e7793 100644 --- a/www/edit.php +++ b/www/edit.php @@ -5,7 +5,7 @@ namespace phorkie; */ require_once 'www-header.php'; if ($GLOBALS['phorkie']['auth']['secure'] > 0) { - require_once 'secure.php'; + include_once 'secure.php'; } $repo = new Repository(); diff --git a/www/forbidden.php b/www/forbidden.php index 1f587a2..3646b0a 100644 --- a/www/forbidden.php +++ b/www/forbidden.php @@ -1,6 +1,6 @@ 0) { - require_once 'secure.php'; + include_once 'secure.php'; } if ($_SERVER['REQUEST_METHOD'] !== 'POST') { @@ -33,4 +33,4 @@ foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) { //FIXME: where to put fork source link? redirect($new->getLink('display')); -?> \ No newline at end of file +?> diff --git a/www/list.php b/www/list.php index 17f46b1..5a394eb 100644 --- a/www/list.php +++ b/www/list.php @@ -5,7 +5,7 @@ namespace phorkie; require_once 'www-header.php'; if ($GLOBALS['phorkie']['auth']['secure'] == 2) { - require_once 'secure.php'; + include_once 'secure.php'; } $rs = new Repositories(); diff --git a/www/new.php b/www/new.php index 8d1a231..0675b4d 100644 --- a/www/new.php +++ b/www/new.php @@ -12,7 +12,7 @@ namespace phorkie; */ require_once 'www-header.php'; if ($GLOBALS['phorkie']['auth']['secure'] > 0) { - require_once 'secure.php'; + include_once 'secure.php'; } $repopo = new Repository_Post(); diff --git a/www/raw.php b/www/raw.php index 67a21ee..6b20633 100644 --- a/www/raw.php +++ b/www/raw.php @@ -5,7 +5,7 @@ namespace phorkie; require_once 'www-header.php'; if ($GLOBALS['phorkie']['auth']['secure'] == 2) { - require_once 'secure.php'; + include_once 'secure.php'; } $repo = new Repository(); $repo->loadFromRequest(); diff --git a/www/user.php b/www/user.php index 1cc8aeb..fd851c4 100644 --- a/www/user.php +++ b/www/user.php @@ -5,7 +5,7 @@ namespace phorkie; require_once 'www-header.php'; if (!isset($_SESSION['identity'])) { - require_once 'secure.php'; + include_once 'secure.php'; } if (isset($_POST['name'])) { diff --git a/www/www-header.php b/www/www-header.php index 5785a3e..64dca11 100644 --- a/www/www-header.php +++ b/www/www-header.php @@ -50,8 +50,12 @@ if ($GLOBALS['phorkie']['cfg']['setupcheck']) { // Set/Get git commit session variables $_SESSION['ipaddr'] = $_SERVER['REMOTE_ADDR']; -if (!isset($_SESSION['name'])) { $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName']; } -if (!isset($_SESSION['email'])) { $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail']; } +if (!isset($_SESSION['name'])) { + $_SESSION['name'] = $GLOBALS['phorkie']['auth']['anonymousName']; +} +if (!isset($_SESSION['email'])) { + $_SESSION['email'] = $GLOBALS['phorkie']['auth']['anonymousEmail']; +} \Twig_Autoloader::register(); -- cgit v1.2.3 From f5bdbfca6e34e35231ab7ae72241c152b047f86b Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Mon, 17 Sep 2012 15:50:56 -0400 Subject: FIX: Combine auth.php to login.php --- README.rst | 3 - data/templates/login.htm | 6 +- src/openid/config.php | 2 +- www/.htaccess | 1 - www/auth.php | 216 ---------------------------------------------- www/login.php | 217 +++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 216 insertions(+), 229 deletions(-) delete mode 100644 www/auth.php (limited to 'src') diff --git a/README.rst b/README.rst index 0b40b39..b92804a 100644 --- a/README.rst +++ b/README.rst @@ -192,8 +192,6 @@ URLs Shows form for new paste ``/login`` Login page for protecting site -``/auth`` - Authentication callback url ``/user`` Edit logged-in user information @@ -236,6 +234,5 @@ If you use nginx, place the following lines into your ``server`` block: rewrite ^/search/([0-9]+)$ /search.php?page=$1; rewrite ^/login$ /login.php; - rewrite ^/auth$ /auth.php; rewrite ^/user$ /user.php; } diff --git a/data/templates/login.htm b/data/templates/login.htm index 7e724b0..418432e 100644 --- a/data/templates/login.htm +++ b/data/templates/login.htm @@ -5,7 +5,7 @@ -
+ @@ -15,8 +15,8 @@

Please choose your account provider

- - + +

or enter your OpenID URL.

diff --git a/src/openid/config.php b/src/openid/config.php index fdec5e1..76ebc6a 100644 --- a/src/openid/config.php +++ b/src/openid/config.php @@ -41,7 +41,7 @@ $returnTo = $base . dirname($_SERVER['PHP_SELF']); if ($returnTo[strlen($returnTo) - 1] != '/') { $returnTo .= '/'; } -$returnTo .= 'auth'; +$returnTo .= 'login'; // SQL storage example // $storeOptions = array( diff --git a/www/.htaccess b/www/.htaccess index f6c3720..1f03fac 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -21,6 +21,5 @@ RewriteRule ^list/([0-9]+)$ /list.php?page=$1 RewriteRule ^search$ /search.php RewriteRule ^search/([0-9]+)$ /search.php?page=$1 -RewriteRule ^auth$ /auth.php RewriteRule ^login$ /login.php RewriteRule ^user$ /user.php diff --git a/www/auth.php b/www/auth.php deleted file mode 100644 index 29d7b37..0000000 --- a/www/auth.php +++ /dev/null @@ -1,216 +0,0 @@ - - * @copyright 2009 Bill Shupp - * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD - * @link http://github.com/shupp/openid - */ - -// A tool for testing Relying Party functionality -set_include_path( - __DIR__ . '/../../src/' - . PATH_SEPARATOR . get_include_path() -); - -require_once 'www-header.php'; -require_once 'openid/config.php'; - - -if (isset($_REQUEST['logout'])) { - unset($_SESSION); - session_destroy(); - $redirect = 'http://' . $_SERVER['HTTP_HOST']; - header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); - exit; -} - -if (!count($_GET) && !count($_POST)) { - $redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/login"; - header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); - exit; -} - -// Hackaround Non-Javascript Login Page -if (!count($_POST) && isset($_GET['start'])) { - $_POST = $_GET; -} - -if (isset($_POST['openid_url'])) { - $openid_url = $_POST['openid_url']; -} else if (isset($_SESSION['openid_url'])) { - $openid_url = $_SESSION['openid_url']; -} else { - $openid_url = null; -} - -try { - $o = new OpenID_RelyingParty($returnTo, $realm, $openid_url); -} catch (OpenID_Exception $e) { - $contents = "
\n"; - $contents .= "
" . $e->getMessage() . "
\n"; - $contents .= "
"; - include_once 'openid/wrapper.php'; - exit; -} - -if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associations'])) { - $o->disableAssociations(); - $_SESSION['disable_associations'] = true; -} - -$log = new OpenID_Observer_Log; -OpenID::attach($log); - -if (isset($_POST['start'])) { - - $_SESSION['openid_url'] = $openid_url; - try { - $authRequest = $o->prepare(); - } catch (OpenID_Exception $e) { - $contents = "
\n"; - $contents .= "
" . $e->getMessage() . "
\n"; - $contents .= "
"; - include_once 'openid/wrapper.php'; - exit; - } - - // checkid_immediate - if (!empty($_POST['checkid_immediate'])) { - $authRequest->setMode('checkid_immediate'); - } - - // SREG - $sreg = new OpenID_Extension_SREG11(OpenID_Extension::REQUEST); - $sreg->set('required', 'email,firstname,lastname,nickname'); - $sreg->set('optional', 'gender,dob'); - $authRequest->addExtension($sreg); - - // AX - $ax = new OpenID_Extension_AX(OpenID_Extension::REQUEST); - $ax->set('type.email', 'http://axschema.org/contact/email'); - $ax->set('type.firstname', 'http://axschema.org/namePerson/first'); - $ax->set('type.lastname', 'http://axschema.org/namePerson/last'); - $ax->set('mode', 'fetch_request'); - $ax->set('required', 'email,firstname,lastname'); - $authRequest->addExtension($ax); - - // UI - if (!empty($_POST['ui'])) { - $ui = new OpenID_Extension_UI(OpenID_Extension::REQUEST); - $ui->set('mode', 'popup'); - $ui->set('language', 'en-US'); - $authRequest->addExtension($ui); - } - - // OAuth - if (!empty($_POST['oauth'])) { - $oauth = new OpenID_Extension_OAuth(OpenID_Extension::REQUEST); - $oauth->set('consumer', $_POST['oauth_consumer_key']); - $_SESSION['OAuth_consumer_key'] = $_POST['oauth_consumer_key']; - $_SESSION['OAuth_consumer_secret'] = $_POST['oauth_consumer_secret']; - - $oauth->set('scope', $_POST['oauth_scope']); - $_SESSION['OAuth_scope'] = $_POST['oauth_scope']; - - $_SESSION['OAuth_access_token_url'] = $_POST['oauth_access_token_url']; - $_SESSION['OAuth_access_token_method'] = $_POST['oauth_access_token_method']; - - $authRequest->addExtension($oauth); - } - - $url = $authRequest->getAuthorizeURL(); - - if (empty($_POST['debug'])) { - header("Location: $url"); - exit; - } - -} else { - if (isset($_SESSION['openid_url'])) { - $usid = $_SESSION['openid_url']; - unset($_SESSION['openid_url']); - } else { - $usid = null; - } - - unset($_SESSION['disable_associations']); - - if (!count($_POST)) { - list(, $queryString) = explode('?', $_SERVER['REQUEST_URI']); - } else { - // I hate php sometimes - $queryString = file_get_contents('php://input'); - } - - $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP); - $id = $message->get('openid.claimed_id'); - $mode = $message->get('openid.mode'); - - try { - $result = $o->verify(new Net_URL2($returnTo . '?' . $queryString), $message); - - if ($result->success()) { - $status = "Status:SUCCESS!"; - $status .= " ({$result->getAssertionMethod()})"; - } else { - $status = "Status:FAIL!"; - $status .= " ({$result->getAssertionMethod()})"; - } - } catch (OpenID_Exception $e) { - $status = "Status:EXCEPTION!"; - $status .= " ({$e->getMessage()} : {$e->getCode()})"; - } - - // OAuth hyprid fetching access token - if (isset($_SESSION['OAuth_consumer_key'], - $_SESSION['OAuth_consumer_secret'], - $_SESSION['OAuth_access_token_url'], - $_SESSION['OAuth_access_token_method'])) { - - try { - $oauth = new OpenID_Extension_OAuth(OpenID_Extension::RESPONSE, - $message); - - // Fix line lengths. - $consumerKey = $_SESSION['OAuth_consumer_key']; - $consumerSecret = $_SESSION['OAuth_consumer_key']; - $tokenURL = $_SESSION['OAuth_access_token_url']; - $tokenMethod = $_SESSION['OAuth_access_token_method']; - - $oauthData = $oauth->getAccessToken($consumerKey, - $consumerSecret, - $tokenURL, - array(), - $tokenMethod); - - } catch (Exception $e) { - } - } - - $openid = $message->getArrayFormat(); - - $email = (isset($openid['openid.ext1.value.email'])) ? $openid['openid.ext1.value.email'] : null; - $email = (isset($openid['openid.ext2.value.email']) && !isset($email)) ? $openid['openid.ext2.value.email'] : $email; - $email = (isset($openid['openid.sreg.email']) && !isset($email)) ? $openid['openid.sreg.email'] : $email; - $email = (isset($openid['openid.ax.value.email']) && !isset($email)) ? $openid['openid.ax.value.email'] : $email; - $_SESSION['email'] = (isset($email)) ? $email : $GLOBALS['phorkie']['auth']['anonymousEmail']; - - $name = (isset($openid['openid.ext1.value.firstname']) && isset($openid['openid.ext1.value.lastname'])) ? $openid['openid.ext1.value.firstname']." ".$openid['openid.ext1.value.lastname'] : null; - $name = (isset($openid['openid.sreg.firstname']) && isset($openid['openid.sreg.lastname']) && !isset($name)) ? $openid['openid.sreg.firstname']." ".$openid['openid.sreg.lastname'] : $name; - $name = (isset($openid['openid.sreg.nickname']) && !isset($name)) ? $openid['openid.sreg.nickname'] : $name; - $_SESSION['name'] = (isset($name)) ? $name : $_SERVER['REMOTE_ADDR']; - - $_SESSION['identity'] = $openid['openid.identity']; - - $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SESSION['REQUEST_URI']; - header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); - exit; -} - -?> diff --git a/www/login.php b/www/login.php index 87c34f4..00d1877 100644 --- a/www/login.php +++ b/www/login.php @@ -1,11 +1,218 @@ + * @copyright 2009 Bill Shupp + * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD + * @link http://github.com/shupp/openid */ namespace phorkie; -require_once 'www-header.php'; -render( - 'login', - null +// A tool for testing Relying Party functionality +set_include_path( + __DIR__ . '/../../src/' + . PATH_SEPARATOR . get_include_path() ); + +require_once 'www-header.php'; +require_once 'openid/config.php'; + + +if (isset($_REQUEST['logout'])) { + unset($_SESSION); + session_destroy(); + $redirect = 'http://' . $_SERVER['HTTP_HOST']; + header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); + exit; +} + +if (!count($_GET) && !count($_POST)) { + render( + 'login', + null + ); + exit; +} + +// Hackaround Non-Javascript Login Page +if (!count($_POST) && isset($_GET['start'])) { + $_POST = $_GET; +} + +if (isset($_POST['openid_url'])) { + $openid_url = $_POST['openid_url']; +} else if (isset($_SESSION['openid_url'])) { + $openid_url = $_SESSION['openid_url']; +} else { + $openid_url = null; +} + +try { + $o = new OpenID_RelyingParty($returnTo, $realm, $openid_url); +} catch (OpenID_Exception $e) { + $contents = "
\n"; + $contents .= "
" . $e->getMessage() . "
\n"; + $contents .= "
"; + include_once 'openid/wrapper.php'; + exit; +} + +if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associations'])) { + $o->disableAssociations(); + $_SESSION['disable_associations'] = true; +} + +$log = new OpenID_Observer_Log; +OpenID::attach($log); + +if (isset($_POST['start'])) { + + $_SESSION['openid_url'] = $openid_url; + try { + $authRequest = $o->prepare(); + } catch (OpenID_Exception $e) { + $contents = "
\n"; + $contents .= "
" . $e->getMessage() . "
\n"; + $contents .= "
"; + include_once 'openid/wrapper.php'; + exit; + } + + // checkid_immediate + if (!empty($_POST['checkid_immediate'])) { + $authRequest->setMode('checkid_immediate'); + } + + // SREG + $sreg = new OpenID_Extension_SREG11(OpenID_Extension::REQUEST); + $sreg->set('required', 'email,firstname,lastname,nickname'); + $sreg->set('optional', 'gender,dob'); + $authRequest->addExtension($sreg); + + // AX + $ax = new OpenID_Extension_AX(OpenID_Extension::REQUEST); + $ax->set('type.email', 'http://axschema.org/contact/email'); + $ax->set('type.firstname', 'http://axschema.org/namePerson/first'); + $ax->set('type.lastname', 'http://axschema.org/namePerson/last'); + $ax->set('mode', 'fetch_request'); + $ax->set('required', 'email,firstname,lastname'); + $authRequest->addExtension($ax); + + // UI + if (!empty($_POST['ui'])) { + $ui = new OpenID_Extension_UI(OpenID_Extension::REQUEST); + $ui->set('mode', 'popup'); + $ui->set('language', 'en-US'); + $authRequest->addExtension($ui); + } + + // OAuth + if (!empty($_POST['oauth'])) { + $oauth = new OpenID_Extension_OAuth(OpenID_Extension::REQUEST); + $oauth->set('consumer', $_POST['oauth_consumer_key']); + $_SESSION['OAuth_consumer_key'] = $_POST['oauth_consumer_key']; + $_SESSION['OAuth_consumer_secret'] = $_POST['oauth_consumer_secret']; + + $oauth->set('scope', $_POST['oauth_scope']); + $_SESSION['OAuth_scope'] = $_POST['oauth_scope']; + + $_SESSION['OAuth_access_token_url'] = $_POST['oauth_access_token_url']; + $_SESSION['OAuth_access_token_method'] = $_POST['oauth_access_token_method']; + + $authRequest->addExtension($oauth); + } + + $url = $authRequest->getAuthorizeURL(); + + if (empty($_POST['debug'])) { + header("Location: $url"); + exit; + } + +} else { + if (isset($_SESSION['openid_url'])) { + $usid = $_SESSION['openid_url']; + unset($_SESSION['openid_url']); + } else { + $usid = null; + } + + unset($_SESSION['disable_associations']); + + if (!count($_POST)) { + list(, $queryString) = explode('?', $_SERVER['REQUEST_URI']); + } else { + // I hate php sometimes + $queryString = file_get_contents('php://input'); + } + + $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP); + $id = $message->get('openid.claimed_id'); + $mode = $message->get('openid.mode'); + + try { + $result = $o->verify(new Net_URL2($returnTo . '?' . $queryString), $message); + + if ($result->success()) { + $status = "Status:SUCCESS!"; + $status .= " ({$result->getAssertionMethod()})"; + } else { + $status = "Status:FAIL!"; + $status .= " ({$result->getAssertionMethod()})"; + } + } catch (OpenID_Exception $e) { + $status = "Status:EXCEPTION!"; + $status .= " ({$e->getMessage()} : {$e->getCode()})"; + } + + // OAuth hyprid fetching access token + if (isset($_SESSION['OAuth_consumer_key'], + $_SESSION['OAuth_consumer_secret'], + $_SESSION['OAuth_access_token_url'], + $_SESSION['OAuth_access_token_method'])) { + + try { + $oauth = new OpenID_Extension_OAuth(OpenID_Extension::RESPONSE, + $message); + + // Fix line lengths. + $consumerKey = $_SESSION['OAuth_consumer_key']; + $consumerSecret = $_SESSION['OAuth_consumer_key']; + $tokenURL = $_SESSION['OAuth_access_token_url']; + $tokenMethod = $_SESSION['OAuth_access_token_method']; + + $oauthData = $oauth->getAccessToken($consumerKey, + $consumerSecret, + $tokenURL, + array(), + $tokenMethod); + + } catch (Exception $e) { + } + } + + $openid = $message->getArrayFormat(); + + $email = (isset($openid['openid.ext1.value.email'])) ? $openid['openid.ext1.value.email'] : null; + $email = (isset($openid['openid.ext2.value.email']) && !isset($email)) ? $openid['openid.ext2.value.email'] : $email; + $email = (isset($openid['openid.sreg.email']) && !isset($email)) ? $openid['openid.sreg.email'] : $email; + $email = (isset($openid['openid.ax.value.email']) && !isset($email)) ? $openid['openid.ax.value.email'] : $email; + $_SESSION['email'] = (isset($email)) ? $email : $GLOBALS['phorkie']['auth']['anonymousEmail']; + + $name = (isset($openid['openid.ext1.value.firstname']) && isset($openid['openid.ext1.value.lastname'])) ? $openid['openid.ext1.value.firstname']." ".$openid['openid.ext1.value.lastname'] : null; + $name = (isset($openid['openid.sreg.firstname']) && isset($openid['openid.sreg.lastname']) && !isset($name)) ? $openid['openid.sreg.firstname']." ".$openid['openid.sreg.lastname'] : $name; + $name = (isset($openid['openid.sreg.nickname']) && !isset($name)) ? $openid['openid.sreg.nickname'] : $name; + $_SESSION['name'] = (isset($name)) ? $name : $_SERVER['REMOTE_ADDR']; + + $_SESSION['identity'] = $openid['openid.identity']; + + $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SESSION['REQUEST_URI']; + header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); + exit; +} + ?> -- cgit v1.2.3 From f662a50e02abe50321766c84a23b977a455d401c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 17 Sep 2012 23:38:47 +0200 Subject: get rid of openid config file --- src/openid/config.php | 55 --------------------------------------------------- www/login.php | 35 +++++++------------------------- 2 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 src/openid/config.php (limited to 'src') diff --git a/src/openid/config.php b/src/openid/config.php deleted file mode 100644 index 76ebc6a..0000000 --- a/src/openid/config.php +++ /dev/null @@ -1,55 +0,0 @@ - - * @copyright 2009 Bill Shupp - * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD - * @link http://github.com/shupp/openid - */ - -set_include_path(dirname(__FILE__) . '/../../:' . get_include_path()); - -/** - * Required files - */ -require_once 'OpenID/RelyingParty.php'; -require_once 'OpenID/Discover.php'; -require_once 'OpenID/Store.php'; -require_once 'OpenID/Extension/SREG10.php'; -require_once 'OpenID/Extension/SREG11.php'; -require_once 'OpenID/Extension/AX.php'; -require_once 'OpenID/Extension/UI.php'; -require_once 'OpenID/Extension/OAuth.php'; -require_once 'OpenID/Message.php'; -require_once 'OpenID/Observer/Log.php'; -require_once 'Net/URL2.php'; - -// Determine realm and return_to -$base = 'http'; -if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { - $base .= 's'; -} -$base .= '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']; - -$realm = $base . '/'; -$returnTo = $base . dirname($_SERVER['PHP_SELF']); -if ($returnTo[strlen($returnTo) - 1] != '/') { - $returnTo .= '/'; -} -$returnTo .= 'login'; - -// SQL storage example -// $storeOptions = array( -// 'dsn' => 'mysql://user:pass@db.example.com/openid' -// ); -// OpenID::setStore(OpenID_Store::factory('MDB2', $storeOptions)); -// -// // The first time you run it, you'll also need to create the tables: -// OpenID::getStore()->createTables(); - -?> diff --git a/www/login.php b/www/login.php index e3d165d..6a13fa2 100644 --- a/www/login.php +++ b/www/login.php @@ -1,42 +1,18 @@ - * @copyright 2009 Bill Shupp - * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD - * @link http://github.com/shupp/openid - */ namespace phorkie; -// A tool for testing Relying Party functionality -set_include_path( - __DIR__ . '/../../src/' - . PATH_SEPARATOR . get_include_path() -); - $pageRequiresLogin = false; require_once 'www-header.php'; -require_once 'openid/config.php'; - if (isset($_REQUEST['logout'])) { unset($_SESSION); session_destroy(); - $redirect = 'http://' . $_SERVER['HTTP_HOST']; - header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); - exit; + header('Location: ' . Tools::fullUrl('/')); + exit(); } if (!count($_GET) && !count($_POST)) { - render( - 'login', - null - ); - exit; + render('login'); + exit(); } // Hackaround Non-Javascript Login Page @@ -52,6 +28,9 @@ if (isset($_POST['openid_url'])) { $openid_url = null; } +$realm = Tools::fullUrl('/'); +$returnTo = Tools::fullUrl('/login'); + try { $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url); } catch (OpenID_Exception $e) { -- cgit v1.2.3 From 802794fcc585bbb6533c52b6a4c646829bd07b4d Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Mon, 17 Sep 2012 21:47:23 -0400 Subject: FIX: Files without eol --- data/templates/display-sidebar-history.htm | 2 +- data/templates/new.htm | 2 +- data/templates/pager.htm | 2 +- src/phorkie/File.php | 2 +- src/phorkie/GitCommandBinary.php | 2 +- src/phorkie/HtmlHelper.php | 2 +- src/phorkie/Repository/Commit.php | 2 +- src/phorkie/Tool/Manager.php | 2 +- src/phorkie/Tool/Result.php | 2 +- src/phorkie/Tool/Result/Line.php | 2 +- src/phorkie/Tools.php | 2 +- www/js/phorkie.js | 2 +- www/tool.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/data/templates/display-sidebar-history.htm b/data/templates/display-sidebar-history.htm index b3ef9df..bf38884 100644 --- a/data/templates/display-sidebar-history.htm +++ b/data/templates/display-sidebar-history.htm @@ -15,4 +15,4 @@ {% else %}

No commits yet

{% endfor %} - \ No newline at end of file + diff --git a/data/templates/new.htm b/data/templates/new.htm index 5b75bba..89c2fe0 100644 --- a/data/templates/new.htm +++ b/data/templates/new.htm @@ -37,4 +37,4 @@ $(document).ready(function() { {% endfor %} {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/data/templates/pager.htm b/data/templates/pager.htm index 085a281..9be2b9f 100644 --- a/data/templates/pager.htm +++ b/data/templates/pager.htm @@ -45,4 +45,4 @@ {% endif %}
-{% endif %} \ No newline at end of file +{% endif %} diff --git a/src/phorkie/File.php b/src/phorkie/File.php index 331f2e5..f378f60 100644 --- a/src/phorkie/File.php +++ b/src/phorkie/File.php @@ -165,4 +165,4 @@ class File } } -?> \ No newline at end of file +?> diff --git a/src/phorkie/GitCommandBinary.php b/src/phorkie/GitCommandBinary.php index 13a31db..a005349 100644 --- a/src/phorkie/GitCommandBinary.php +++ b/src/phorkie/GitCommandBinary.php @@ -12,4 +12,4 @@ class GitCommandBinary extends \VersionControl_Git_Util_Command } } -?> \ No newline at end of file +?> diff --git a/src/phorkie/HtmlHelper.php b/src/phorkie/HtmlHelper.php index af046cf..ea21ab5 100644 --- a/src/phorkie/HtmlHelper.php +++ b/src/phorkie/HtmlHelper.php @@ -25,4 +25,4 @@ class HtmlHelper } } -?> \ No newline at end of file +?> diff --git a/src/phorkie/Repository/Commit.php b/src/phorkie/Repository/Commit.php index 05c988b..62f1d40 100644 --- a/src/phorkie/Repository/Commit.php +++ b/src/phorkie/Repository/Commit.php @@ -70,4 +70,4 @@ class Repository_Commit } } -?> \ No newline at end of file +?> diff --git a/src/phorkie/Tool/Manager.php b/src/phorkie/Tool/Manager.php index 8e18199..ca93b4a 100644 --- a/src/phorkie/Tool/Manager.php +++ b/src/phorkie/Tool/Manager.php @@ -43,4 +43,4 @@ class Tool_Manager } } -?> \ No newline at end of file +?> diff --git a/src/phorkie/Tool/Result.php b/src/phorkie/Tool/Result.php index 22ea273..94dfe5e 100644 --- a/src/phorkie/Tool/Result.php +++ b/src/phorkie/Tool/Result.php @@ -6,4 +6,4 @@ class Tool_Result public $annotations; } -?> \ No newline at end of file +?> diff --git a/src/phorkie/Tool/Result/Line.php b/src/phorkie/Tool/Result/Line.php index a788db6..1fa8bcb 100644 --- a/src/phorkie/Tool/Result/Line.php +++ b/src/phorkie/Tool/Result/Line.php @@ -31,4 +31,4 @@ class Tool_Result_Line } } -?> \ No newline at end of file +?> diff --git a/src/phorkie/Tools.php b/src/phorkie/Tools.php index 843b2df..e4aab63 100644 --- a/src/phorkie/Tools.php +++ b/src/phorkie/Tools.php @@ -62,4 +62,4 @@ class Tools } -?> \ No newline at end of file +?> diff --git a/www/js/phorkie.js b/www/js/phorkie.js index 1171b1a..7078e8f 100644 --- a/www/js/phorkie.js +++ b/www/js/phorkie.js @@ -50,4 +50,4 @@ function toggleAdditional(elem, time) jt.children('i').toggleClass('icon-chevron-down') .toggleClass('icon-chevron-up'); jt.parents('.row-fluid').children('.additional').toggle(time); -} \ No newline at end of file +} diff --git a/www/tool.php b/www/tool.php index d42954c..647d6a7 100644 --- a/www/tool.php +++ b/www/tool.php @@ -30,4 +30,4 @@ render( ) ); -?> \ No newline at end of file +?> -- cgit v1.2.3 From 4293cbe275bec99763c9fd4bd5df347bd359599f Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Tue, 18 Sep 2012 08:09:00 -0400 Subject: FIX: Add identity to notes rather than commit --- src/phorkie/Repository/Post.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index ed44cf1..9119e06 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -118,10 +118,11 @@ class Repository_Post } $commitmsg = "phorkie commit"; + if (isset($sessionData['identity'])) { - $commitmsg .= " from ".$sessionData['identity']; + $notes = $sessionData['identity']; } else { - $commitmsg .= " by ".$sessionData['ipaddr']; + $notes = $sessionData['ipaddr']; } if ($bCommit) { @@ -129,6 +130,11 @@ class Repository_Post ->setOption('message', $commitmsg) ->setOption('author', $sessionData['name'].' <'.$sessionData['email'].'>') ->execute(); + //FIXME: git needs ref BEFORE add. ideally VersionControl_Git needs to be updated + $vc->getCommand('notes --ref=identity add') + ->setOption('force') + ->setOption('message', "$notes") + ->execute(); $bChanged = true; } -- cgit v1.2.3 From b81d2ab65f8fafce3b818eeb96c1cdcecd3e675f Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Tue, 18 Sep 2012 13:53:14 -0400 Subject: CLEAN: Removed openid debugging information --- src/openid/wrapper.php | 27 ---------------- www/css/debug.css | 85 -------------------------------------------------- www/login.php | 12 ++----- 3 files changed, 2 insertions(+), 122 deletions(-) delete mode 100644 src/openid/wrapper.php delete mode 100644 www/css/debug.css (limited to 'src') diff --git a/src/openid/wrapper.php b/src/openid/wrapper.php deleted file mode 100644 index cb57f4e..0000000 --- a/src/openid/wrapper.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @copyright 2009 Bill Shupp - * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD - * @link http://github.com/shupp/openid - */ -?> - - - PEAR OpenID Debug - - - - - - diff --git a/www/css/debug.css b/www/css/debug.css deleted file mode 100644 index 634243a..0000000 --- a/www/css/debug.css +++ /dev/null @@ -1,85 +0,0 @@ -html, body { - background: #ededed; - font: 82.5% Helvetica Neue, HelveticaNeue, Helvetica, sans-serif; - margin: 30px 0 0; padding: 0px; } - -h3 { - color: #aaa; - margin: 0; padding: 0; - font-size: 1.3em; - - position: absolute; - top: 30px; - width: 100%; - text-align: center; - left: 0; -} - -h3 a { - color: #111; - text-decoration: none; -} - -h3 a:hover { - text-decoration: underline; - -} - -form { - padding: 30px; - background: #fff; - -moz-border-radius: 6px; - -webkit-border-radius: 6px; - width: 400px; - margin: 50px auto 0; - } - -table { - font-size: 1.1em !important; - font-weight: bold; -} - -td { - width: 200px; -} -.discover_results { - margin: 60px 0 ; - padding: 30px; - background: #111; - text-align: center; -} - - -.discover_results b { - color: #fff; - font-size: 2.4em; -} - -.relyingparty_results { - width: 100%; -} - -.relyingparty_results table b { - display: block; - width: 300px; - font-size: 1.7em; - color: #fff; -} - - -pre, .relyingparty_results p table { - font-size: 1.2em; - width: 900px !important; - text-align: left; - margin: 0 auto; - - color: #ddd; - padding: 30px; - -} - -.relyingparty_results { - background: #111; - padding: 30px; - margin: 60px 0; -} diff --git a/www/login.php b/www/login.php index 9c1b136..a97246f 100644 --- a/www/login.php +++ b/www/login.php @@ -34,11 +34,7 @@ $returnTo = Tools::fullUrl('/login'); try { $o = new \OpenID_RelyingParty($returnTo, $realm, $openid_url); } catch (OpenID_Exception $e) { - $contents = "
\n"; - $contents .= "
" . $e->getMessage() . "
\n"; - $contents .= "
"; - include_once 'openid/wrapper.php'; - exit; + throw new Exception($e->getMessage()); } if (!empty($_POST['disable_associations']) || !empty($_SESSION['disable_associations'])) { @@ -55,11 +51,7 @@ if (isset($_POST['openid_url'])) { try { $authRequest = $o->prepare(); } catch (OpenID_Exception $e) { - $contents = "
\n"; - $contents .= "
" . $e->getMessage() . "
\n"; - $contents .= "
"; - include_once 'openid/wrapper.php'; - exit; + throw new Exception($e->getMessage()); } // SREG -- cgit v1.2.3 From d316adab970b993504ba38736a0f8753ef4bb052 Mon Sep 17 00:00:00 2001 From: "Justin J. Novack" Date: Tue, 18 Sep 2012 15:25:47 -0400 Subject: Feature: Add Markdown parsing --- ChangeLog | 4 ++++ README.rst | 3 +++ data/config.default.php | 5 +++++ src/phorkie/Renderer/Markdown.php | 27 +++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 src/phorkie/Renderer/Markdown.php (limited to 'src') diff --git a/ChangeLog b/ChangeLog index afefa9a..8557be7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2012-09-18 Justin J. Novack + + * Add Markdown as a known file-type. + 2012-09-16 Christian Weiske * Implement request #12: DOAP documents for all pastes diff --git a/README.rst b/README.rst index d1c6491..4a157bf 100644 --- a/README.rst +++ b/README.rst @@ -84,6 +84,9 @@ phorkie stands on the shoulders of giants. $ pear channel-discover zustellzentrum.cweiske.de $ pear install zz/mime_type_plaindetect-alpha + $ pear channel-discover pear.michelf.ca + $ pear install michelf/Markdown + Note that this version of GeSHi is a bit outdated, but it's the fastest way to install it. diff --git a/data/config.default.php b/data/config.default.php index 88c9ae5..3fc48f6 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -57,6 +57,11 @@ $GLOBALS['phorkie']['languages'] = array( 'mime' => 'application/javascript', 'geshi' => 'javascript' ), + 'md' => array( + 'title' => 'Markdown', + 'mime' => 'text/x-markdown', + 'renderer' => '\\phorkie\\Renderer_Markdown' + ), 'pl' => array( 'title' => 'Perl', 'mime' => 'application/x-perl', diff --git a/src/phorkie/Renderer/Markdown.php b/src/phorkie/Renderer/Markdown.php new file mode 100644 index 0000000..628d87f --- /dev/null +++ b/src/phorkie/Renderer/Markdown.php @@ -0,0 +1,27 @@ +getContent()); + + return '
' + . $markdown + . '
'; + } +} + +?> -- cgit v1.2.3