Skip to content

Instantly share code, notes, and snippets.

@sadasant
Created June 22, 2012 22:21
Show Gist options
  • Save sadasant/2975535 to your computer and use it in GitHub Desktop.
Save sadasant/2975535 to your computer and use it in GitHub Desktop.
b
<?PHP
// b
// Copyright (C) 2012 Daniel Rodríguez (sadasant.com)
// License: GNU General Public License 3.0
// Settings
$s = array(
'rw_menu_on' => 6 // Number of updates before rewriting the menu session
, 'articles_per_page' => 6 // Number of articles per page
, 'blog_location' => 'http://sadasant.com/b/'
, 'menu_location' => 'md/menu.md' // Any local or remote location of the menu markdown file
, 'markdown_location' => '../d/scripts/Markdown.php' // http://michelf.com/projects/php-markdown/
, 'previous_url' => 'http://sadasant.com/#/writes' // Click *here* to go back
, 'who_am_i' => 'Daniel R. (sadasant.com)'
, 'twitter_account' => 'sadasant'
, 'disquss_shortname' => 'sadasant'
, 'keywords' => 'sadasant daniel rodriguez music writes digital art pixel code programming'
);
session_start();
// The article title obtained from the url b/$1
$article = ($article = explode('.php/', strtolower($_SERVER[PHP_SELF]))) ? $article[1] : '';
// The session storing the countdown of updates, used for reloading the menu session
$_SESSION['updates'] = ($updates = $_SESSION['updates']) && $updates < $s[rw_menu_on] ? ++$_SESSION['updates'] : 1;
// The menu session, used to avoid the download of the menu each time the user loads an article
$menu = $_SESSION['menu'] = $_SESSION['menu'] && $updates < $s[rw_menu_on] ? $_SESSION['menu'] : json_decode(file_get_contents($s[menu_location]));
// The page number obtained from the URL parammeters b/?page=
$page = $_SESSION['page'] = ($_GET['page'] || $_GET['page'] === '0' ? $_GET['page'] : ($article ? $_SESSION['page'] : 0)) * 1;
// The variable holding the data that will fill the view
$b = array('url' => "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"], 'back' => $s[blog_location].($page ? '?page='.$page : ''));
if ($article && include_once $s[markdown_location]) { // Show article
foreach($menu as $k => $v) {
if (!stristr($v->url, $article)) continue;
$b['description'] = $v->description;
$b['title'] = "&ldquo;".$v->title."&rdquo; by ".$s[who_am_i];
$b['tweet'] = "&ldquo;".$v->title."&rdquo;: ".substr($v->description,0,128-strlen($v->title)-strlen($s[twitter_account])-strlen($b['url'])).", by @".$s[twitter_account]." ".$b['url'];
$b['content'] = '<div style="text-align:justify;"><small>'.$v->date.'</small><br/>'.Markdown(file_get_contents($v->markdown)).'</div>';
$b['disquss'] = '<div id="content"><div id="disqus_thread"></div><script type="text/javascript"> var disqus_shortname = \''.$s[disquss_shortname].'\'; (function() { var dsq = document.createElement(\'script\'); dsq.type = \'text/javascript\'; dsq.async = true; dsq.src = \'http://\' + disqus_shortname + \'.disqus.com/embed.js\'; (document.getElementsByTagName(\'head\')[0] || document.getElementsByTagName(\'body\')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a></div>';
break;
}
} elseif ($articles = count($menu)) { // Show menu
if ($url = explode('?',$b[url].(strstr($b[url], '.php') ? '/' : ''))) $url = $url[0];
$b['back'] = $page ? $url.($page > 1 ? "?page=".($page-1) : '') : $s[previous_url];
$b['description'] = $s[who_am_i];
$b['title'] = "Ideas of ".$s[who_am_i];
$b['tweet'] = "Check out @".$s[twitter_account]." 's blog: ".$b['url'];
$page_last = ($i = $page * $s[articles_per_page]) + $s[articles_per_page];
while($i < $page_last && $v = $menu[$i++]) {
$b['content'] .= "<li><a href='$url$v->url'>$v->title</a></br><small>".str_replace('\n','<br/>',$v->description)."<br/>$v->date</small></li><br/>";
if ($i == $page_last || $i == $articles) $b['content'] .= ($page ? "<a href='".$b['back']."'><div class='img_back' title='Previous Page'></div></a>" : '').($page_last > $articles ? '' : "<a href='$url?page=".($page+1)."'><div class='img_forw' title='Next Page'></div></a>");
}
$b['content'] = '<ul>'.$b['content'].'</ul></br>';
}
?>
<!DOCTYPE html>
<!-- Copyright (C) 2012 <?=$s[who_am_i]?> -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta charset=utf-8 />
<title><?=$b['title']?></title>
<meta property="og:title" content="<?=$b['title']?>"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?=$b['url']?>"/>
<meta property="og:image" content="http://sadasant.com/tweet/img/tweetskull.png"/>
<meta property="og:site_name" content="sadasant"/>
<meta property="og:description" content="<?=$b['description']?>" />
<meta name="description" content="<?=$b['description']?>" />
<meta name="keywords" content="<?=$s[keywords]?>" />
<link rel="shortcut icon" href="http://sadasant.com/sadasant.ico">
<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
<link rel="stylesheet" type="text/css" media="screen" href="http://sadasant.com/css/sdsnt.css">
</head>
<body>
<div class="share">
<a href="https://github.com/sadasant/b"><div class="img_gh" title="Fork me on GitHub" ></div></a><br/>
<a href="http://twitter.com/home?status=<?=$b['tweet']?>"><div class="img_tw" title="Tweet this article" ></div></a><br/>
<a href="http://www.facebook.com/sharer.php?u=<?=$b['url']?>&t=<?=$b['title']?>"><div class="img_fb" title="Share it on Facebook" ></div></a><br/>
</div>
<header>
<a href="http://sadasant.com/" title="sadasant.com"><div id="skull"></div></a><h1><b>My blog</b></h1>
</header>
<menu>
Click <a id="back" href="<?=$b['back']?>" title="Go back">here</a> to go back.
</menu>
<div id="content">
<?=$b['content']?>
</div>
<footer>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Licencia de Creative Commons" style="border-width:0" src="http://sadasant.com/img/cc.png" title="CC BY-NC-SA 3.0" /></a>
</footer>
<?=$b['disquss']?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment