From: Gabriel Dunne Date: Sun, 2 Oct 2011 09:09:49 +0000 (+0530) Subject: Clean URLs X-Git-Url: https://git.quilime.com/?a=commitdiff_plain;h=00a9665b761c3a3ae4bc60f02c8069f20185bc27;p=plog.git Clean URLs --- diff --git a/.htaccess b/.htaccess deleted file mode 100644 index a57877b..0000000 --- a/.htaccess +++ /dev/null @@ -1,9 +0,0 @@ - - - -RewriteEngine On -RewriteBase / -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule . index.php [L] - diff --git a/index.php b/index.php index ab1a99c..181841a 100644 --- a/index.php +++ b/index.php @@ -1,58 +1,55 @@ response_format = $response_format; - $t->assign('view', isset($_GET['v']) ? $_GET['v'] : null); - - $content_request = LOCAL_ROOT . CONTENT_DIR . $url['dirname'] . '/' . $url['filename']; - $page_request = LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url['filename']; - $total = 0; - - # content exists, and is a folder - - if ($url['filename'] == '') - { - $template = 'index.html.tpl'; - } - else if (is_dir($content_request)) { - # get config in folder, if exists - if (is_file($content_request . '/' . CONFIG_FILE )) { - $config = parse_entry(new SplFileInfo($content_request . '/' . CONFIG_FILE)); - $template = $config['config']['template'] . '.' . $response_format . '.tpl' ; - } - list($data, $total) = get_entries($url['dirname'] . '/' . $url['filename']); - $t->assign('data', $data); - $t->assign('page_title', preg_replace('{^/|/$}', '', $url['url'])); - } - - # content exists, and is a single entry - else if (is_file($content_request)) { - $t->assign('data', parse_entry(new SplFileInfo($content_request))); - $t->assign('single', true); - $template = 'single.'.$response_format.'.tpl'; - } - - # content exists, and is a page - else if (is_file($page_request)) { - $page = parse_entry(new SplFileInfo($page_request), 1); - $t->assign('data', $page); - $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; +require_once 'lib/init.php'; + +$url = get_url(); +list($response_format, $response_mime_type) = parse_format($url['extension'], 'html'); + +# setup template +$t = get_template_instance(); +$t->response_format = $response_format; +$t->assign('view', isset($_GET['v']) ? $_GET['v'] : null); + +$content_request = LOCAL_ROOT. '/' . CONTENT_DIR . '/' . $url['dirname'] . '/' . $url['filename']; +$page_request = LOCAL_ROOT . '/' . PAGE_DIR . '/' . $url['filename']; +$total = 0; + + +if ($url['filename'] == 'index') +{ + $template = 'index.html.tpl'; +} +else if (is_dir($content_request)) { + # get config in folder, if exists + if (is_file($content_request . '/' . CONFIG_FILE )) { + $config = parse_entry(new SplFileInfo($content_request . '/' . CONFIG_FILE)); + $template = $config['config']['template'] . '.' . $response_format . '.tpl' ; } - - # 404 - else { - $template = '404.html.tpl'; - } - - # render - $t->assign('total', $total); - header("Content-Type: {$response_mime_type}; charset=UTF-8"); - $t->render($template); - -?> + list($data, $total) = get_entries($url['dirname'] . '/' . $url['filename']); + $t->assign('data', $data); + $t->assign('page_title', preg_replace('{^/|/$}', '', $url['url'])); +} + +# content exists, and is a single entry +else if (is_file($content_request)) { + $t->assign('data', parse_entry(new SplFileInfo($content_request))); + $t->assign('single', true); + $template = 'single.'.$response_format.'.tpl'; +} + +# content exists, and is a page +else if (is_file($page_request)) { + $page = parse_entry(new SplFileInfo($page_request), 1); + $t->assign('data', $page); + $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; +} + +# 404 +else { + $template = '404.html.tpl'; +} + +# render +$t->assign('total', $total); +header("Content-Type: {$response_mime_type}; charset=UTF-8"); +$t->render($template); diff --git a/js/aggregate.js b/js/aggregate.js deleted file mode 100644 index 2e58cce..0000000 --- a/js/aggregate.js +++ /dev/null @@ -1,248 +0,0 @@ -(function () { - - var token = 'IeFqDeIAsZp8yMdxWXSbcfaH8ep/uLuA3Mkmf62IqGBnHt2LgW6edQXxpRpwLfEQqrhnXWsLCYNPyHYM/XUqMrOzK9t8jSB7wJyUGbSeRgw='; - var regex_found = /^https?:\/\/.*?\.?ffffound\.com\//; - - if (location.href.match(regex_found)) { - window.alert('This bookmarklet cannot use in ffffound.com domain.'); - return; - } - - var res_endpoint = 'http://ffffound.com/add_asset'; - - var res_popupimg_src = 'http://ffffound.com/assets/bookmarklet_01.r2509.gif'; - var res_popupimg_w = 149; - var res_popupimg_h = 44; - - var res_popupimg2_src = 'http://ffffound.com/assets/bookmarklet_02.r2509.gif'; - var res_popupimg2_w = 149; - var res_popupimg2_h = 44; - - var min_size = 200; - - var style_em_size = 10; - var style_em_color = '#0000ff'; - var style_om_color = '#0000ff'; - var style_om_color_ff = 'rgb(0, 0, 255)'; - - var isie = 0 <= navigator.appName.indexOf('Internet Explorer'); - var isff = 0 <= navigator.userAgent.indexOf('Firefox'); - var iswk = 0 <= navigator.userAgent.indexOf('Safari'); - - var frames = document.getElementsByTagName('frame'); - var d; - if (0 < frames.length) { - d = window[0].document; - } - else { - d = document; - } - - var selectedimg = null; - - var ele_popup = d.createElement('div'); - ele_popup.id = '__found-popup'; - ele_popup.style.display = 'none'; - ele_popup.style.zIndex = 10000; - ele_popup.style.position = 'absolute'; - ele_popup.style.margin = '0px'; - ele_popup.style.padding = '0px'; - ele_popup.style.borderWidth = '0px'; - ele_popup.onmouseout = function () { - selectedimg = null; - setTimeout(function () { - resetAll(); - }, 50); - }; - d.body.appendChild(ele_popup); - - var imgs = d.getElementsByTagName('img'); - var found = false; - for (var i = 0; i < imgs.length; i++) { - var img = imgs[i]; - if (img.src.match(regex_found)) { - continue; - } - // else if (img.src.match(/\.(jpg|gif|png)/i)) { - else { - if (img.width < min_size && img.height < min_size) { - continue; - } - - if (img.src.match(/\.(tif|tiff|bmp)$/i)) { - continue; - } - - found = true; - img.style.border = style_em_size + 'px solid ' + style_em_color; - img.style.cursor = 'pointer'; - - img.onclick = function () { - addToFound(); - return false; - }; - - img.onmouseover = function () { - selectedimg = this; - - var ele_a = d.createElement('a'); - ele_a.href = 'javascript:void(0);'; - ele_a.onclick = function () { - addToFound(); - return false; - }; - - var ele_img = d.createElement('img'); - ele_img.src = res_popupimg_src; - ele_img.width = res_popupimg_w; - ele_img.height = res_popupimg_h; - ele_img.alt = 'ADD TO MY FOUND'; - ele_img.border = 0; - - ele_a.appendChild(ele_img); - - if (ele_popup.firstChild) { - ele_popup.removeChild(ele_popup.firstChild); - } - ele_popup.appendChild(ele_a); - - var offset = getElementOffset(this); - ele_popup.style.left = offset[0] + ((this.width + (style_em_size * 2)) / 2) - (res_popupimg_w / 2) + 'px'; - ele_popup.style.top = offset[1] + ((this.height + (style_em_size * 2)) / 2) - (res_popupimg_h / 2) + 'px'; - ele_popup.style.display = ''; - - var img = this; - ele_popup.onmouseover = function () { - selectedimg = img; - }; - - this.style.border = style_em_size + 'px solid ' + style_om_color; - }; - - img.onmouseout = function () { - selectedimg = null; - setTimeout(function () { - resetAll(); - }, 50); - }; - } - } - - if (!found) { - window.alert('Image not found.'); - } - - function addToFound() { - var img = selectedimg; - - if (img == null) { - return; - } - - var params = { - 'token': token, - 'url': img.src, - 'referer': (img.src == location.href ? document.referrer : location.href), - 'title': d.title, - 'alt': img.alt - }; - - var urlb = []; - urlb.push(res_endpoint); - urlb.push('?'); - for (var n in params) { - urlb.push(encodeURIComponent(n)); - urlb.push('='); - urlb.push(encodeURIComponent(params[n])); - urlb.push('&'); - } - - if (true) { - window.open(urlb.join(''), - 'found' + new Date().getTime(), - 'status=no,resizable=no,scrollbars=no,personalbar=no,directories=no,location=no,toolbar=no,menubar=no,' + - 'width=300,height=50,left=0,top=0'); - } - - disableImage(img); - resetAll(); - - return false; - } - - function disableImage(img) { - img.onclick = null; - img.onmouseover = null; - img.onmouseout = null; - img.style.border = style_em_size + 'px solid #000000'; - - var w = img.width + (style_em_size * 2); - var h = img.height + (style_em_size * 2); - - var e = d.createElement('div'); - e.style.zIndex = 10010; - e.style.position = 'absolute'; - e.style.margin = '0px'; - e.style.padding = '0px'; - e.style.borderWidth = '0px'; - e.style.backgroundColor = '#000000'; - e.style.width = w; - e.style.height = h; - - var offset = getElementOffset(img); - e.style.left = offset[0] + 'px'; - e.style.top = offset[1] + 'px'; - - d.body.appendChild(e); - - e.innerHTML = '
'; - } - - function resetAll() { - for (var i = 0; i < imgs.length; i++) { - var img = imgs[i]; - if (hide(img)) { - img.style.border = style_em_size + 'px solid ' + style_em_color; - if (selectedimg == null) { - ele_popup.style.display = 'none'; - } - } - } - - function hide(img) { - if (img == selectedimg) { - return; - } - - if (iswk) { - return img.style.borderTopWidth == style_em_size + 'px' && - img.style.borderTopStyle == 'solid' && - img.style.borderTopColor == style_om_color_ff; - } - else if (isff) { - return img.style.border == style_em_size + 'px solid ' + style_om_color_ff; - } - else { - return img.style.border == style_om_color + ' ' + style_em_size + 'px solid'; - } - } - } - - // import from prototype.js. - // (c) 2005 Sam Stephenson - // http://prototype.conio.net - function getElementOffset(element) { - var valueT = 0, valueL = 0; - do { - valueT += element.offsetTop || 0; - valueL += element.offsetLeft || 0; - element = element.offsetParent; - if (element) { - p = element.style.position; - if (p == 'relative' || p == 'absolute') break; - } - } while (element); - return [valueL, valueT]; - } -})(); - diff --git a/js/js.js b/js/js.js deleted file mode 100644 index e69de29..0000000 diff --git a/lib/data.php b/lib/data.php index 43110a2..1fb49ab 100644 --- a/lib/data.php +++ b/lib/data.php @@ -63,9 +63,10 @@ function get_pages() */ function get_dirs( $path = "", $args = array()) { - $recursive = isset($args['recursive']) ? $args['recursive'] : 1; - $path = LOCAL_ROOT . CONTENT_DIR . $path; + + $local_content = LOCAL_ROOT . CONTENT_DIR; + $path = $local_content . $path; if ($recursive) { $iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME); @@ -78,8 +79,13 @@ function get_dirs( $path = "", $args = array()) foreach ($dir_iterator as $dir => $info) { if ($info->isDir() && $info->getFilename() != '.' && $info->getFilename() != '..') { $d = array(); - $d['url'] = str_replace($path, "", $info->getRealPath()) . '/'; - $d['name'] = substr(str_replace($path, "", $info->getRealPath()),1); + $d['url'] = str_replace($path, "", $info->getRealPath()); + + if (!CLEAN_URLS) { + $d['url'] = WEB_ROOT . '?c=' . $d['url']; + } + + $d['name'] = str_replace($path, "", $info->getRealPath()); $dirs[] = $d; } } @@ -117,22 +123,23 @@ function parse_entry($fileInfo, $page = 0) $content .= $line; } - $file = array(); - $file['config'] = parse_ini_string($config); - $file['title'] = $file['config']['title']; - $file['config']['date'] = isset($file['config']['date']) ? $file['config']['date'] : null; - $file['timestamp'] = $file['config']['date'] ? date('U', strtotime( $file['config']['date'])) : $fileInfo->getCTime(); - $file['tags'] = isset($file['config']['tags']) ? explode(" ", $file['config']['tags']) : null; - $file['content'] = Markdown($content); + $f = array(); + $f['config'] = parse_ini_string($config); + $f['title'] = $f['config']['title']; + $f['config']['date'] = isset($f['config']['date']) ? $f['config']['date'] : null; + $f['timestamp'] = $f['config']['date'] ? date('U', strtotime( $f['config']['date'])) : $fileInfo->getCTime(); + $f['tags'] = isset($f['config']['tags']) ? explode(" ", $f['config']['tags']) : null; + $f['content'] = Markdown($content); if ($passed_more) - $file['content_short'] = Markdown($content_short); + $f['content_short'] = Markdown($content_short); $cat = clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath())); - $file['cat'] = $page ? null : array('name' => substr($cat,1), 'url' => $cat.'/' ); - $file['path'] = $fileInfo->getRealPath(); - $file['url'] = WEB_ROOT . ($page ? '' : substr($file['cat']['url'],1)) . $fileInfo->getFilename() . '/'; - - return $file; -} + $f['cat'] = $page ? null : array('name' => substr($cat,1), 'url' => $cat ); + $f['path'] = $fileInfo->getRealPath(); + $f['url'] = ($page ? '' : substr($file['cat']['url'],1)) . $fileInfo->getFilename(); + if (!CLEAN_URLS) { + $f['url'] = WEB_ROOT . '?p=' . $f['url']; + } -?> + return $f; +} diff --git a/lib/init.php b/lib/init.php index 1ebcec8..6f0205a 100644 --- a/lib/init.php +++ b/lib/init.php @@ -1,26 +1,35 @@ '); - define ('TITLE_DELIMITER', ': '); - define ('CONFIG_FILE', 'config'); - - require_once 'data.php'; - require_once 'output.php'; - require_once 'markdown.php'; - require_once 'template.php'; - - - //error_reporting(E_ALL); - //ini_set("display_errors", 1); - \ No newline at end of file +// NOTE +// short tags must be enabled + +# error reporting +error_reporting(E_ALL); +ini_set("display_errors", 1); + +# timezone +putenv("TZ=America/Los_Angeles"); + +# include path +ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(realpath(__FILE__))); + +# settings +define ('CLEAN_URLS', false); +define ('SITE_TITLE', 'plog'); +define ('LOCAL_ROOT', '/Users/gdunne/Sites/india/'); +define ('WEB_ROOT', 'http://localhost/~gdunne/india/'); +define ('CONTENT_DIR', 'content/'); +define ('TEMPLATE_DIR', 'templates/'); +define ('PAGE_DIR', 'pages/'); +define ('CONFIG_DELIMITER', '--'); +define ('MORE_DELIM', ''); +define ('TITLE_DELIMITER', ': '); +define ('CONFIG_FILE', 'config'); + + + +# includes +require_once 'data.php'; +require_once 'output.php'; +require_once 'markdown.php'; +require_once 'template.php'; diff --git a/lib/output.php b/lib/output.php index cbe9609..9046fb8 100644 --- a/lib/output.php +++ b/lib/output.php @@ -20,8 +20,9 @@ function get_template_instance() function parse_format($format, $default) { $types = array('html' => 'text/html', + 'php' => 'text/html', 'text' => 'text/plain', - 'rss' => 'application/rss+xml', + 'rss' => 'application/rss+xml', 'atom' => 'application/atom+xml', 'json' => 'text/json', 'js' => 'application/x-javascript', @@ -163,17 +164,17 @@ function get_base_href() function get_url_parts() { - $parts = explode('/', substr($_SERVER['SCRIPT_URL'], strlen(get_base_dir() . '/'))); + $parts = explode('/', substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/'))); return $parts[0] ? $parts : 0; } function get_url() { - $path_info = pathinfo($_SERVER['SCRIPT_URL']); - $path_info['url'] = preg_match("/\.\.\//", $_SERVER['SCRIPT_URL']) ? '/' : $_SERVER['SCRIPT_URL']; - $path_info['extension'] = null; - return $path_info; //substr($_SERVER['SCRIPT_URL'], strlen(get_base_dir() . '/')); + $path_info = pathinfo( $_SERVER['SCRIPT_NAME'] ); + $path_info['url'] = preg_match("/\.\.\//", $_SERVER['SCRIPT_NAME']) ? '/' : $_SERVER['SCRIPT_NAME']; + //$path_info['extension'] = null; + return $path_info; //substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/')); }