pnbp

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 12e4fe73a1ebc0d1e24d85cfd32cb6f5ece7eca3
parent 68c284b5f27d6b92abee160bbd88857e48f5aa90
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Thu May 22 17:10:38 2014

Archive is working, added /admin

Diffstat:
 compile.py                      |  17 +-
 data/admin/HTML_To_Markdown.php | 580 ++++++++++++++++++++++++-
 data/admin/auth.php             |  31 +-
 data/admin/config.json          |   8 +-
 data/admin/index.php            |  85 ++++-
 data/admin/markdown.php         | 991 +++++++++++++++++++++++++++++++++++++++++-
 data/admin/post.php             |  16 +-
 data/admin/scripts/md5.js       | 271 +++++++++++-
 data/index.json                 |   2 +-
 data/styles/style.css           |  20 +-
 data/test.json                  |   2 +-
 mod/blog.py                     |  26 +-
 templates/std.html              |   4 +-
 13 files changed, 2029 insertions(+), 24 deletions(-)

diff --git a/compile.py b/compile.py @@ -107,21 +107,10 @@ def buildSite(site): open(currentDir+"/"+subdir+"/"+page+"/index.html","w").write(content) else: open(currentDir+"/"+subdir+"/index.html", "w").write(data['default']) - copytree("data/styles","site/styles") - copytree("data/images","site/images") + shutil.copytree("data/admin","site/admin") + shutil.copytree("data/styles","site/styles") + shutil.copytree("data/images","site/images") -def copytree(src, dst, symlinks=False, ignore=None): - if not os.path.exists(dst): - os.makedirs(dst) - for item in os.listdir(src): - s = os.path.join(src, item) - d = os.path.join(dst, item) - if os.path.isdir(s): - copytree(s, d, symlinks, ignore) - else: - if not os.path.exists(d) or os.stat(src).st_mtime - os.stat(dst).st_mtime > 1: - shutil.copy2(s, d) - if __name__ == "__main__": print("Going through pages...") try: diff --git a/data/admin/HTML_To_Markdown.php b/data/admin/HTML_To_Markdown.php @@ -0,0 +1,580 @@ +<?php +/** + * Class HTML_To_Markdown + * + * A helper class to convert HTML to Markdown. + * + * @version 2.1.1 + * @author Nick Cernis <nick@cern.is> + * @link https://github.com/nickcernis/html2markdown/ Latest version on GitHub. + * @link http://twitter.com/nickcernis Nick on twitter. + * @license http://www.opensource.org/licenses/mit-license.php MIT + */ +class HTML_To_Markdown +{ + /** + * @var DOMDocument The root of the document tree that holds our HTML. + */ + private $document; + + /** + * @var string|boolean The Markdown version of the original HTML, or false if conversion failed + */ + private $output; + + /** + * @var array Class-wide options users can override. + */ + private $options = array( + 'header_style' => 'setext', // Set to "atx" to output H1 and H2 headers as # Header1 and ## Header2 + 'suppress_errors' => true, // Set to false to show warnings when loading malformed HTML + 'strip_tags' => false, // Set to true to strip tags that don't have markdown equivalents. N.B. Strips tags, not their content. Useful to clean MS Word HTML output. + 'bold_style' => '**', // Set to '__' if you prefer the underlined style + 'italic_style' => '*', // Set to '_' if you prefer the underlined style + ); + + + /** + * Constructor + * + * Set up a new DOMDocument from the supplied HTML, convert it to Markdown, and store it in $this->$output. + * + * @param string $html The HTML to convert to Markdown. + * @param array $overrides [optional] List of style and error display overrides. + */ + public function __construct($html = null, $overrides = null) + { + if ($overrides) + $this->options = array_merge($this->options, $overrides); + + if ($html) + $this->convert($html); + } + + + /** + * Setter for conversion options + * + * @param $name + * @param $value + */ + public function set_option($name, $value) + { + $this->options[$name] = $value; + } + + + /** + * Convert + * + * Loads HTML and passes to get_markdown() + * + * @param $html + * @return string The Markdown version of the html + */ + public function convert($html) + { + $html = preg_replace('~>\s+<~', '><', $html); // Strip white space between tags to prevent creation of empty #text nodes + + $this->document = new DOMDocument(); + + if ($this->options['suppress_errors']) + libxml_use_internal_errors(true); // Suppress conversion errors (from http://bit.ly/pCCRSX ) + + $this->document->loadHTML('<?xml encoding="UTF-8">' . $html); // Hack to load utf-8 HTML (from http://bit.ly/pVDyCt ) + $this->document->encoding = 'UTF-8'; + + if ($this->options['suppress_errors']) + libxml_clear_errors(); + + return $this->get_markdown($html); + } + + + /** + * Is Child Of? + * + * Is the node a child of the given parent tag? + * + * @param $parent_name string The name of the parent node to search for (e.g. 'code') + * @param $node + * @return bool + */ + private static function is_child_of($parent_name, $node) + { + for ($p = $node->parentNode; $p != false; $p = $p->parentNode) { + if (is_null($p)) + return false; + + if ($p->nodeName == $parent_name) + return true; + } + return false; + } + + + /** + * Convert Children + * + * Recursive function to drill into the DOM and convert each node into Markdown from the inside out. + * + * Finds children of each node and convert those to #text nodes containing their Markdown equivalent, + * starting with the innermost element and working up to the outermost element. + * + * @param $node + */ + private function convert_children($node) + { + // Don't convert HTML code inside <code> blocks to Markdown - that should stay as HTML + if (self::is_child_of('code', $node)) + return; + + // If the node has children, convert those to Markdown first + if ($node->hasChildNodes()) { + $length = $node->childNodes->length; + + for ($i = 0; $i < $length; $i++) { + $child = $node->childNodes->item($i); + $this->convert_children($child); + } + } + + // Now that child nodes have been converted, convert the original node + $this->convert_to_markdown($node); + } + + + /** + * Get Markdown + * + * Sends the body node to convert_children() to change inner nodes to Markdown #text nodes, then saves and + * returns the resulting converted document as a string in Markdown format. + * + * @return string|boolean The converted HTML as Markdown, or false if conversion failed + */ + private function get_markdown() + { + // Use the body tag as our root element + $body = $this->document->getElementsByTagName("body")->item(0); + + // Try the head tag if there's no body tag (e.g. the user's passed a single <script> tag for conversion) + if (!$body) + $body = $this->document->getElementsByTagName("head")->item(0); + + if (!$body) + return false; + + // Convert all children of the body element. The DOMDocument stored in $this->doc will + // then consist of #text nodes, each containing a Markdown version of the original node + // that it replaced. + $this->convert_children($body); + + // Sanitize and return the body contents as a string. + $markdown = $this->document->saveHTML(); // stores the DOMDocument as a string + $markdown = html_entity_decode($markdown, ENT_QUOTES, 'UTF-8'); + $markdown = html_entity_decode($markdown, ENT_QUOTES, 'UTF-8'); // Double decode to cover cases like &amp;nbsp; http://www.php.net/manual/en/function.htmlentities.php#99984 + $markdown = preg_replace("/<!DOCTYPE [^>]+>/", "", $markdown); // Strip doctype declaration + $unwanted = array('<html>', '</html>', '<body>', '</body>', '<head>', '</head>', '<?xml encoding="UTF-8">', '&#xD;'); + $markdown = str_replace($unwanted, '', $markdown); // Strip unwanted tags + $markdown = trim($markdown, "\n\r\0\x0B"); + + $this->output = $markdown; + + return $markdown; + } + + + /** + * Convert to Markdown + * + * Converts an individual node into a #text node containing a string of its Markdown equivalent. + * + * Example: An <h3> node with text content of "Title" becomes a text node with content of "### Title" + * + * @param $node + */ + private function convert_to_markdown($node) + { + $tag = $node->nodeName; // the type of element, e.g. h1 + $value = $node->nodeValue; // the value of that element, e.g. The Title + + switch ($tag) { + case "p": + case "pre": + $markdown = (trim($value)) ? rtrim($value) . PHP_EOL . PHP_EOL : ''; + break; + case "h1": + case "h2": + $markdown = $this->convert_header($tag, $node); + break; + case "h3": + $markdown = "### " . $value . PHP_EOL . PHP_EOL; + break; + case "h4": + $markdown = "#### " . $value . PHP_EOL . PHP_EOL; + break; + case "h5": + $markdown = "##### " . $value . PHP_EOL . PHP_EOL; + break; + case "h6": + $markdown = "###### " . $value . PHP_EOL . PHP_EOL; + break; + case "em": + case "i": + case "strong": + case "b": + $markdown = $this->convert_emphasis($tag, $value); + break; + case "hr": + $markdown = "- - - - - -" . PHP_EOL . PHP_EOL; + break; + case "br": + $markdown = " " . PHP_EOL; + break; + case "blockquote": + $markdown = $this->convert_blockquote($node); + break; + case "code": + $markdown = $this->convert_code($node); + break; + case "ol": + case "ul": + $markdown = $value . PHP_EOL; + break; + case "li": + $markdown = $this->convert_list($node); + break; + case "img": + $markdown = $this->convert_image($node); + break; + case "a": + $markdown = $this->convert_anchor($node); + break; + case "#text": + $markdown = preg_replace('~\s+~', ' ', $value); + break; + case "#comment": + $markdown = ''; + break; + default: + // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents, + // such as <span> and #text nodes on their own. C14N() canonicalizes the node to a string. + // See: http://www.php.net/manual/en/domnode.c14n.php + $markdown = ($this->options['strip_tags']) ? $value : html_entity_decode($node->C14N()); + } + + // Create a DOM text node containing the Markdown equivalent of the original node + $markdown_node = $this->document->createTextNode($markdown); + + // Replace the old $node e.g. "<h3>Title</h3>" with the new $markdown_node e.g. "### Title" + $node->parentNode->replaceChild($markdown_node, $node); + } + + + /** + * Convert Header + * + * Converts h1 and h2 headers to Markdown-style headers in setext style, + * matching the number of underscores with the length of the title. + * + * e.g. Header 1 Header Two + * ======== ---------- + * + * Returns atx headers instead if $this->options['header_style'] is "atx" + * + * e.g. # Header 1 ## Header Two + * + * @param string $level The header level, including the "h". e.g. h1 + * @param string $node The node to convert. + * @return string The Markdown version of the header. + */ + private function convert_header($level, $node) + { + $content = $node->nodeValue; + + if (!$this->is_child_of('blockquote', $node) && $this->options['header_style'] == "setext") { + $length = (function_exists('mb_strlen')) ? mb_strlen($content, 'utf-8') : strlen($content); + $underline = ($level == "h1") ? "=" : "-"; + $markdown = $content . PHP_EOL . str_repeat($underline, $length) . PHP_EOL . PHP_EOL; // setext style + } else { + $prefix = ($level == "h1") ? "# " : "## "; + $markdown = $prefix . $content . PHP_EOL . PHP_EOL; // atx style + } + + return $markdown; + } + + + /** + * Converts inline styles + * This function is used to render strong and em tags + * + * eg <strong>bold text</strong> becomes **bold text** or __bold text__ + * + * @param string $tag + * @param string $value + * @return string + */ + private function convert_emphasis($tag, $value) + { + if ($tag == 'i' || $tag == 'em') { + $markdown = $this->options['italic_style'] . $value . $this->options['italic_style']; + } else { + $markdown = $this->options['bold_style'] . $value . $this->options['bold_style']; + } + + return $markdown; + } + + + /** + * Convert Image + * + * Converts <img /> tags to Markdown. + * + * e.g. <img src="/path/img.jpg" alt="alt text" title="Title" /> + * becomes ![alt text](/path/img.jpg "Title") + * + * @param $node + * @return string + */ + private function convert_image($node) + { + $src = $node->getAttribute('src'); + $alt = $node->getAttribute('alt'); + $title = $node->getAttribute('title'); + + if ($title != "") { + $markdown = '![' . $alt . '](' . $src . ' "' . $title . '")'; // No newlines added. <img> should be in a block-level element. + } else { + $markdown = '![' . $alt . '](' . $src . ')'; + } + + return $markdown; + } + + + /** + * Convert Anchor + * + * Converts <a> tags to Markdown. + * + * e.g. <a href="http://modernnerd.net" title="Title">Modern Nerd</a> + * becomes [Modern Nerd](http://modernnerd.net "Title") + * + * @param $node + * @return string + */ + private function convert_anchor($node) + { + $href = $node->getAttribute('href'); + $title = $node->getAttribute('title'); + $text = $node->nodeValue; + + if ($title != "") { + $markdown = '[' . $text . '](' . $href . ' "' . $title . '")'; + } else { + $markdown = '[' . $text . '](' . $href . ')'; + } + + // Append a space if the node after this one is also an anchor + $next_node_name = $this->get_next_node_name($node); + + if ($next_node_name == 'a') + $markdown = $markdown . ' '; + + return $markdown; + } + + + /** + * Convert List + * + * Converts <ul> and <ol> lists to Markdown. + * + * @param $node + * @return string + */ + private function convert_list($node) + { + // If parent is an ol, use numbers, otherwise, use dashes + $list_type = $node->parentNode->nodeName; + $value = $node->nodeValue; + + if ($list_type == "ul") { + $markdown = "- " . trim($value) . PHP_EOL; + } else { + $number = $this->get_position($node); + $markdown = $number . ". " . trim($value) . PHP_EOL; + } + + return $markdown; + } + + + /** + * Convert Code + * + * Convert code tags by indenting blocks of code and wrapping single lines in backticks. + * + * @param $node + * @return string + */ + private function convert_code($node) + { + // Store the content of the code block in an array, one entry for each line + + $markdown = ''; + + $code_content = html_entity_decode($node->C14N()); + $code_content = str_replace(array("<code>", "</code>"), "", $code_content); + + $lines = preg_split('/\r\n|\r|\n/', $code_content); + $total = count($lines); + + // If there's more than one line of code, prepend each line with four spaces and no backticks. + if ($total > 1) { + + // Remove the first and last line if they're empty + $first_line = trim($lines[0]); + $last_line = trim($lines[$total - 1]); + $first_line = trim($first_line, "&#xD;"); //trim XML style carriage returns too + $last_line = trim($last_line, "&#xD;"); + + if (empty($first_line)) + array_shift($lines); + + if (empty($last_line)) + array_pop($lines); + + $count = 1; + foreach ($lines as $line) { + $line = str_replace('&#xD;', '', $line); + $markdown .= " " . $line; + // Add newlines, except final line of the code + if ($count != $total) + $markdown .= PHP_EOL; + $count++; + } + $markdown .= PHP_EOL; + + } else { // There's only one line of code. It's a code span, not a block. Just wrap it with backticks. + + $markdown .= "`" . $lines[0] . "`"; + + } + + return $markdown; + } + + + /** + * Convert blockquote + * + * Prepend blockquotes with > chars. + * + * @param $node + * @return string + */ + private function convert_blockquote($node) + { + // Contents should have already been converted to Markdown by this point, + // so we just need to add ">" symbols to each line. + + $markdown = ''; + + $quote_content = trim($node->nodeValue); + + $lines = preg_split('/\r\n|\r|\n/', $quote_content); + + $total_lines = count($lines); + + foreach ($lines as $i => $line) { + $markdown .= "> " . $line . PHP_EOL; + if ($i + 1 == $total_lines) + $markdown .= PHP_EOL; + } + + return $markdown; + } + + + /** + * Get Position + * + * Returns the numbered position of a node inside its parent + * + * @param $node + * @return int The numbered position of the node, starting at 1. + */ + private function get_position($node) + { + // Get all of the nodes inside the parent + $list_nodes = $node->parentNode->childNodes; + $total_nodes = $list_nodes->length; + + $position = 1; + + // Loop through all nodes and find the given $node + for ($a = 0; $a < $total_nodes; $a++) { + $current_node = $list_nodes->item($a); + + if ($current_node->isSameNode($node)) + $position = $a + 1; + } + + return $position; + } + + + /** + * Get Next Node Name + * + * Return the name of the node immediately after the passed one. + * + * @param $node + * @return string|null The node name (e.g. 'h1') or null. + */ + private function get_next_node_name($node) + { + $next_node_name = null; + + $current_position = $this->get_position($node); + $next_node = $node->parentNode->childNodes->item($current_position); + + if ($next_node) + $next_node_name = $next_node->nodeName; + + return $next_node_name; + } + + + /** + * To String + * + * Magic method to return Markdown output when HTML_To_Markdown instance is treated as a string. + * + * @return string + */ + public function __toString() + { + return $this->output(); + } + + + /** + * Output + * + * Getter for the converted Markdown contents stored in $this->output + * + * @return string + */ + public function output() + { + if (!$this->output) { + return ''; + } else { + return $this->output; + } + } +} diff --git a/data/admin/auth.php b/data/admin/auth.php @@ -0,0 +1,31 @@ +<?php +$config = json_decode(file_get_contents("./config.json"),TRUE); +$user = "root"; +$pass = ""; +$con = mysqli_connect($config['db_hostname'],$config['db_username'],$config['db_password'],$config['db_name']); +var_dump($_POST); +if (isset($_POST['u']) && isset($_POST['p'])) { + if (!isset($_POST['new'])) { + $guser = mysql_real_escape_string($_POST['u']); + echo 'SELECT hash, username FROM usr WHERE username = "'.$guser.'"'; + $user = mysqli_query($con,'SELECT hash, username FROM usr WHERE `username` = "$guser"'); + $user = mysqli_fetch_array($user); + if ( crypt($_POST['p'], $user['hash']) == $user['hash'] ) { + echo "Yes!"; + } else { + + } + } else { + $sth = $dbh->prepare(' + INSERT INTO usr (username, hash) + VALUES (:user, :hash) + '); + $username = $_POST['u']; + $hash = crypt($_POST['p']); + $sth->bindParam(':user',$username); + $sth->bindParam(':hash',$hash); + $sth->execute(); + echo "$hash, $username"; + } +} +?>+ \ No newline at end of file diff --git a/data/admin/config.json b/data/admin/config.json @@ -0,0 +1,8 @@ +{ + "db_hostname": "localhost", + "db_username": "root", + "db_password": "", + "db_name": "usr", + "maintemplate": "./default.page", + "pastetemplate": "./paste.page" +}+ \ No newline at end of file diff --git a/data/admin/index.php b/data/admin/index.php @@ -0,0 +1,85 @@ +<?php session_start(); ?> +<!DOCTYPE html> +<html> +<head> + <title>Admin</title> + <script type="text/javascript" src="./scripts/md5.js"></script> + <style> +html { + background-color:#EFEFEF; + border-top:5px solid #FF9311; +} +#wrapper { + width:800px; + margin:0 auto; +} +#wrapper label { + font-family:Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, monospace, serif; +} +#post { + width:100%; + height:1000px; + +} +#submit { + background-color:#EFEFEF; +} +#submit:hover { + box-shadow:0px 0px 3px black inset; +} +#submit:active { + background-color:#AAEEFF; +} +.input { + outline:none; + padding:5px; + border:1px solid #DEDEDE; + border-radius:5px; + box-shadow:0px 0px 3px #DEDEDE inset; +} + </style> +</head> +<body> + <div id="wrapper"> +<?php + +if (isset($_GET['location']) && isset($_GET['post'])) { + require_once( dirname( __FILE__) . '/HTML_To_Markdown.php' ); + $data = json_decode(file_get_contents($_GET['location']), TRUE); + $out = ""; + foreach ($data[$_GET['post']] as $key => $val) { + if ($key !== "content") { + $out = $out . $key . "=" . $val . ", "; + } + } + $_SESSION['vars'] = $out; + $_SESSION['post'] = new HTML_To_Markdown($data[$_GET['post']]['content']); +} +?> + <form id="update" action="./post.php" method="post" onsubmit="return validate();"> + <label>Password :</label><input id="password" name="password" type="password" class="input"/><input type="submit" id="submit" class="input"/><br /> + <label>Variables:</label><input id="vars" name="vars" type="text" class="input" value="<?php echo $_SESSION['vars']; ?>"/><br /> + <label>Location :</label><input id="loc" name="loc" type="text" class="input" value="<?php echo $_GET['location']; ?>"/><br /> + <textarea id="post" name="post" form="update" class="input"><?php echo $_SESSION['post']; ?></textarea> + </form> + </div> + <script type="text/javascript"> +function validate() { + document.getElementById("password").value = md5(document.getElementById("password").value + <?php + function generateRandomString($length = 10) { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, strlen($characters) - 1)]; + } + return $randomString; + } + $_SESSION['salt'] = generateRandomString(10); + $salt = $_SESSION['salt']; + echo "'$salt'"; + ?>); + return true; +} + </script> +</body> +</html> diff --git a/data/admin/markdown.php b/data/admin/markdown.php @@ -0,0 +1,991 @@ +<?php + +# +# +# Parsedown +# http://parsedown.org +# +# (c) Emanuil Rusev +# http://erusev.com +# +# For the full license information, please view the LICENSE file that was +# distributed with this source code. +# +# + +class Parsedown +{ + # + # Multiton (http://en.wikipedia.org/wiki/Multiton_pattern) + # + + static function instance($name = 'default') + { + if (isset(self::$instances[$name])) + return self::$instances[$name]; + + $instance = new Parsedown(); + + self::$instances[$name] = $instance; + + return $instance; + } + + private static $instances = array(); + + # + # Setters + # + + private $break_marker = " \n"; + + function set_breaks_enabled($breaks_enabled) + { + $this->break_marker = $breaks_enabled ? "\n" : " \n"; + + return $this; + } + + # + # Fields + # + + private $reference_map = array(); + private $escape_sequence_map = array(); + + # + # Public Methods + # + + function parse($text) + { + # removes UTF-8 BOM and marker characters + $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); + + # removes \r characters + $text = str_replace("\r\n", "\n", $text); + $text = str_replace("\r", "\n", $text); + + # replaces tabs with spaces + $text = str_replace("\t", ' ', $text); + + # encodes escape sequences + + if (strpos($text, '\\') !== FALSE) + { + $escape_sequences = array('\\\\', '\`', '\*', '\_', '\{', '\}', '\[', '\]', '\(', '\)', '\>', '\#', '\+', '\-', '\.', '\!'); + + foreach ($escape_sequences as $index => $escape_sequence) + { + if (strpos($text, $escape_sequence) !== FALSE) + { + $code = "\x1A".'\\'.$index.';'; + + $text = str_replace($escape_sequence, $code, $text); + + $this->escape_sequence_map[$code] = $escape_sequence; + } + } + } + + # ~ + + $text = preg_replace('/\n\s*\n/', "\n\n", $text); + $text = trim($text, "\n"); + + $lines = explode("\n", $text); + + $text = $this->parse_block_elements($lines); + + # decodes escape sequences + + foreach ($this->escape_sequence_map as $code => $escape_sequence) + { + $text = str_replace($code, $escape_sequence[1], $text); + } + + # ~ + + $text = rtrim($text, "\n"); + + return $text; + } + + # + # Private Methods + # + + private function parse_block_elements(array $lines, $context = '') + { + $elements = array(); + + $element = array( + 'type' => '', + ); + + foreach ($lines as $line) + { + # fenced elements + + switch ($element['type']) + { + case 'fenced_code_block': + + if ( ! isset($element['closed'])) + { + if (preg_match('/^[ ]*'.$element['fence'][0].'{3,}[ ]*$/', $line)) + { + $element['closed'] = true; + } + else + { + $element['text'] !== '' and $element['text'] .= "\n"; + + $element['text'] .= $line; + } + + continue 2; + } + + break; + + case 'markup': + + if ( ! isset($element['closed'])) + { + if (preg_match('{<'.$element['subtype'].'>$}', $line)) # opening tag + { + $element['depth']++; + } + + if (preg_match('{</'.$element['subtype'].'>$}', $line)) # closing tag + { + $element['depth'] > 0 + ? $element['depth']-- + : $element['closed'] = true; + } + + $element['text'] .= "\n".$line; + + continue 2; + } + + break; + } + + # * + + if ($line === '') + { + $element['interrupted'] = true; + + continue; + } + + # composite elements + + switch ($element['type']) + { + case 'blockquote': + + if ( ! isset($element['interrupted'])) + { + $line = preg_replace('/^[ ]*>[ ]?/', '', $line); + + $element['lines'] []= $line; + + continue 2; + } + + break; + + case 'li': + + if (preg_match('/^([ ]{0,3})(\d+[.]|[*+-])[ ](.*)/', $line, $matches)) + { + if ($element['indentation'] !== $matches[1]) + { + $element['lines'] []= $line; + } + else + { + unset($element['last']); + + $elements []= $element; + + $element = array( + 'type' => 'li', + 'indentation' => $matches[1], + 'last' => true, + 'lines' => array( + preg_replace('/^[ ]{0,4}/', '', $matches[3]), + ), + ); + } + + continue 2; + } + + if (isset($element['interrupted'])) + { + if ($line[0] === ' ') + { + $element['lines'] []= ''; + + $line = preg_replace('/^[ ]{0,4}/', '', $line); + + $element['lines'] []= $line; + + unset($element['interrupted']); + + continue 2; + } + } + else + { + $line = preg_replace('/^[ ]{0,4}/', '', $line); + + $element['lines'] []= $line; + + continue 2; + } + + break; + } + + # indentation sensitive types + + $deindented_line = $line; + + switch ($line[0]) + { + case ' ': + + # ~ + + $deindented_line = ltrim($line); + + if ($deindented_line === '') + { + continue 2; + } + + # code block + + if (preg_match('/^[ ]{4}(.*)/', $line, $matches)) + { + if ($element['type'] === 'code_block') + { + if (isset($element['interrupted'])) + { + $element['text'] .= "\n"; + + unset ($element['interrupted']); + } + + $element['text'] .= "\n".$matches[1]; + } + else + { + $elements []= $element; + + $element = array( + 'type' => 'code_block', + 'text' => $matches[1], + ); + } + + continue 2; + } + + break; + + case '#': + + # atx heading (#) + + if (preg_match('/^(#{1,6})[ ]*(.+?)[ ]*#*$/', $line, $matches)) + { + $elements []= $element; + + $level = strlen($matches[1]); + + $element = array( + 'type' => 'h.', + 'text' => $matches[2], + 'level' => $level, + ); + + continue 2; + } + + break; + + case '-': + + # setext heading (---) + + if ($line[0] === '-' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[-]+[ ]*$/', $line)) + { + $element['type'] = 'h.'; + $element['level'] = 2; + + continue 2; + } + + break; + + case '=': + + # setext heading (===) + + if ($line[0] === '=' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[=]+[ ]*$/', $line)) + { + $element['type'] = 'h.'; + $element['level'] = 1; + + continue 2; + } + + break; + } + + # indentation insensitive types + + switch ($deindented_line[0]) + { + case '<': + + # self-closing tag + + if (preg_match('{^<.+?/>$}', $deindented_line)) + { + $elements []= $element; + + $element = array( + 'type' => '', + 'text' => $deindented_line, + ); + + continue 2; + } + + # opening tag + + if (preg_match('{^<(\w+)(?:[ ].*?)?>}', $deindented_line, $matches)) + { + $elements []= $element; + + $element = array( + 'type' => 'markup', + 'subtype' => strtolower($matches[1]), + 'text' => $deindented_line, + 'depth' => 0, + ); + + preg_match('{</'.$matches[1].'>\s*$}', $deindented_line) and $element['closed'] = true; + + continue 2; + } + + break; + + case '>': + + # quote + + if (preg_match('/^>[ ]?(.*)/', $deindented_line, $matches)) + { + $elements []= $element; + + $element = array( + 'type' => 'blockquote', + 'lines' => array( + $matches[1], + ), + ); + + continue 2; + } + + break; + + case '[': + + # reference + + if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $deindented_line, $matches)) + { + $label = strtolower($matches[1]); + + $this->reference_map[$label] = array( + '»' => trim($matches[2], '<>'), + ); + + if (isset($matches[3])) + { + $this->reference_map[$label]['#'] = $matches[3]; + } + + continue 2; + } + + break; + + case '`': + case '~': + + # fenced code block + + if (preg_match('/^([`]{3,}|[~]{3,})[ ]*(\S+)?[ ]*$/', $deindented_line, $matches)) + { + $elements []= $element; + + $element = array( + 'type' => 'fenced_code_block', + 'text' => '', + 'fence' => $matches[1], + ); + + isset($matches[2]) and $element['language'] = $matches[2]; + + continue 2; + } + + break; + + case '*': + case '+': + case '-': + case '_': + + # hr + + if (preg_match('/^([-*_])([ ]{0,2}\1){2,}[ ]*$/', $deindented_line)) + { + $elements []= $element; + + $element = array( + 'type' => 'hr', + ); + + continue 2; + } + + # li + + if (preg_match('/^([ ]*)[*+-][ ](.*)/', $line, $matches)) + { + $elements []= $element; + + $element = array( + 'type' => 'li', + 'ordered' => false, + 'indentation' => $matches[1], + 'last' => true, + 'lines' => array( + preg_replace('/^[ ]{0,4}/', '', $matches[2]), + ), + ); + + continue 2; + } + } + + # li + + if ($deindented_line[0] <= '9' and $deindented_line >= '0' and preg_match('/^([ ]*)\d+[.][ ](.*)/', $line, $matches)) + { + $elements []= $element; + + $element = array( + 'type' => 'li', + 'ordered' => true, + 'indentation' => $matches[1], + 'last' => true, + 'lines' => array( + preg_replace('/^[ ]{0,4}/', '', $matches[2]), + ), + ); + + continue; + } + + # paragraph + + if ($element['type'] === 'p') + { + if (isset($element['interrupted'])) + { + $elements []= $element; + + $element['text'] = $line; + + unset($element['interrupted']); + } + else + { + $element['text'] .= "\n".$line; + } + } + else + { + $elements []= $element; + + $element = array( + 'type' => 'p', + 'text' => $line, + ); + } + } + + $elements []= $element; + + unset($elements[0]); + + # + # ~ + # + + $markup = ''; + + foreach ($elements as $element) + { + switch ($element['type']) + { + case 'p': + + $text = $this->parse_span_elements($element['text']); + + if ($context === 'li' and $markup === '') + { + if (isset($element['interrupted'])) + { + $markup .= "\n".'<p>'.$text.'</p>'."\n"; + } + else + { + $markup .= $text; + } + } + else + { + $markup .= '<p>'.$text.'</p>'."\n"; + } + + break; + + case 'blockquote': + + $text = $this->parse_block_elements($element['lines']); + + $markup .= '<blockquote>'."\n".$text.'</blockquote>'."\n"; + + break; + + case 'code_block': + case 'fenced_code_block': + + $text = htmlspecialchars($element['text'], ENT_NOQUOTES, 'UTF-8'); + + strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $this->escape_sequence_map); + + $markup .= isset($element['language']) + ? '<pre><code class="language-'.$element['language'].'">'.$text.'</code></pre>' + : '<pre><code>'.$text.'</code></pre>'; + + $markup .= "\n"; + + break; + + case 'h.': + + $text = $this->parse_span_elements($element['text']); + + $markup .= '<h'.$element['level'].'>'.$text.'</h'.$element['level'].'>'."\n"; + + break; + + case 'hr': + + $markup .= '<hr />'."\n"; + + break; + + case 'li': + + if (isset($element['ordered'])) # first + { + $list_type = $element['ordered'] ? 'ol' : 'ul'; + + $markup .= '<'.$list_type.'>'."\n"; + } + + if (isset($element['interrupted']) and ! isset($element['last'])) + { + $element['lines'] []= ''; + } + + $text = $this->parse_block_elements($element['lines'], 'li'); + + $markup .= '<li>'.$text.'</li>'."\n"; + + isset($element['last']) and $markup .= '</'.$list_type.'>'."\n"; + + break; + + case 'markup': + + $markup .= $this->parse_span_elements($element['text'])."\n"; + + break; + + default: + + $markup .= $element['text']."\n"; + } + } + + return $markup; + } + + # ~ + + private $strong_regex = array( + '*' => '/^[*]{2}([^*]+?)[*]{2}(?![*])/s', + '_' => '/^__([^_]+?)__(?!_)/s', + ); + + private $em_regex = array( + '*' => '/^[*]([^*]+?)[*](?![*])/s', + '_' => '/^_([^_]+?)[_](?![_])\b/s', + ); + + private $strong_em_regex = array( + '*' => '/^[*]{2}(.*?)[*](.+?)[*](.*?)[*]{2}/s', + '_' => '/^__(.*?)_(.+?)_(.*?)__/s', + ); + + private $em_strong_regex = array( + '*' => '/^[*](.*?)[*]{2}(.+?)[*]{2}(.*?)[*]/s', + '_' => '/^_(.*?)__(.+?)__(.*?)_/s', + ); + + private function parse_span_elements($text, $markers = array('![', '&', '*', '<', '[', '_', '`', 'http', '~~')) + { + if (isset($text[2]) === false or $markers === array()) + { + return $text; + } + + # ~ + + $markup = ''; + + while ($markers) + { + $closest_marker = null; + $closest_marker_index = 0; + $closest_marker_position = null; + + foreach ($markers as $index => $marker) + { + $marker_position = strpos($text, $marker); + + if ($marker_position === false) + { + unset($markers[$index]); + + continue; + } + + if ($closest_marker === null or $marker_position < $closest_marker_position) + { + $closest_marker = $marker; + $closest_marker_index = $index; + $closest_marker_position = $marker_position; + } + } + + # ~ + + if ($closest_marker === null or isset($text[$closest_marker_position + 2]) === false) + { + $markup .= $text; + + break; + } + else + { + $markup .= substr($text, 0, $closest_marker_position); + } + + $text = substr($text, $closest_marker_position); + + # ~ + + unset($markers[$closest_marker_index]); + + # ~ + + switch ($closest_marker) + { + case '![': + case '[': + + if (strpos($text, ']') and preg_match('/\[((?:[^][]|(?R))*)\]/', $text, $matches)) + { + $element = array( + '!' => $text[0] === '!', + 'a' => $matches[1], + ); + + $offset = strlen($matches[0]); + + $element['!'] and $offset++; + + $remaining_text = substr($text, $offset); + + if ($remaining_text[0] === '(' and preg_match('/\([ ]*(.*?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*\)/', $remaining_text, $matches)) + { + $element['»'] = $matches[1]; + + if (isset($matches[2])) + { + $element['#'] = $matches[2]; + } + + $offset += strlen($matches[0]); + } + elseif ($this->reference_map) + { + $reference = $element['a']; + + if (preg_match('/^\s*\[(.*?)\]/', $remaining_text, $matches)) + { + $reference = $matches[1] ? $matches[1] : $element['a']; + + $offset += strlen($matches[0]); + } + + $reference = strtolower($reference); + + if (isset($this->reference_map[$reference])) + { + $element['»'] = $this->reference_map[$reference]['»']; + + if (isset($this->reference_map[$reference]['#'])) + { + $element['#'] = $this->reference_map[$reference]['#']; + } + } + else + { + unset($element); + } + } + else + { + unset($element); + } + } + + if (isset($element)) + { + $element['»'] = str_replace('&', '&amp;', $element['»']); + $element['»'] = str_replace('<', '&lt;', $element['»']); + + if ($element['!']) + { + $markup .= '<img alt="'.$element['a'].'" src="'.$element['»'].'" />'; + } + else + { + $element['a'] = $this->parse_span_elements($element['a'], $markers); + + $markup .= isset($element['#']) + ? '<a href="'.$element['»'].'" title="'.$element['#'].'">'.$element['a'].'</a>' + : '<a href="'.$element['»'].'">'.$element['a'].'</a>'; + } + + unset($element); + } + else + { + $markup .= $closest_marker; + + $offset = $closest_marker === '![' ? 2 : 1; + } + + break; + + case '&': + + $markup .= '&amp;'; + + $offset = substr($text, 0, 5) === '&amp;' ? 5 : 1; + + break; + + case '*': + case '_': + + if ($text[1] === $closest_marker and preg_match($this->strong_regex[$closest_marker], $text, $matches)) + { + $matches[1] = $this->parse_span_elements($matches[1], $markers); + + $markup .= '<strong>'.$matches[1].'</strong>'; + } + elseif (preg_match($this->em_regex[$closest_marker], $text, $matches)) + { + $matches[1] = $this->parse_span_elements($matches[1], $markers); + + $markup .= '<em>'.$matches[1].'</em>'; + } + elseif ($text[1] === $closest_marker and preg_match($this->strong_em_regex[$closest_marker], $text, $matches)) + { + $matches[2] = $this->parse_span_elements($matches[2], $markers); + + $matches[1] and $matches[1] = $this->parse_span_elements($matches[1], $markers); + $matches[3] and $matches[3] = $this->parse_span_elements($matches[3], $markers); + + $markup .= '<strong>'.$matches[1].'<em>'.$matches[2].'</em>'.$matches[3].'</strong>'; + } + elseif (preg_match($this->em_strong_regex[$closest_marker], $text, $matches)) + { + $matches[2] = $this->parse_span_elements($matches[2], $markers); + + $matches[1] and $matches[1] = $this->parse_span_elements($matches[1], $markers); + $matches[3] and $matches[3] = $this->parse_span_elements($matches[3], $markers); + + $markup .= '<em>'.$matches[1].'<strong>'.$matches[2].'</strong>'.$matches[3].'</em>'; + } + + if (isset($matches) and $matches) + { + $offset = strlen($matches[0]); + } + else + { + $markup .= $closest_marker; + + $offset = 1; + } + + break; + + case '<': + + if (strpos($text, '>') !== false) + { + if ($text[1] === 'h' and preg_match('/^<(https?:[\/]{2}[^\s]+?)>/i', $text, $matches)) + { + $element_url = $matches[1]; + $element_url = str_replace('&', '&amp;', $element_url); + $element_url = str_replace('<', '&lt;', $element_url); + + $markup .= '<a href="'.$element_url.'">'.$element_url.'</a>'; + + $offset = strlen($matches[0]); + } + elseif (preg_match('/^<\/?\w.*?>/', $text, $matches)) + { + $markup .= $matches[0]; + + $offset = strlen($matches[0]); + } + else + { + $markup .= '&lt;'; + + $offset = 1; + } + } + else + { + $markup .= '&lt;'; + + $offset = 1; + } + + break; + + case '`': + + if (preg_match('/^`(.+?)`/', $text, $matches)) + { + $element_text = $matches[1]; + $element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8'); + + if ($this->escape_sequence_map and strpos($element_text, "\x1A") !== false) + { + $element_text = strtr($element_text, $this->escape_sequence_map); + } + + $markup .= '<code>'.$element_text.'</code>'; + + $offset = strlen($matches[0]); + } + else + { + $markup .= '`'; + + $offset = 1; + } + + break; + + case 'http': + + if (preg_match('/^https?:[\/]{2}[^\s]+\b/i', $text, $matches)) + { + $element_url = $matches[0]; + $element_url = str_replace('&', '&amp;', $element_url); + $element_url = str_replace('<', '&lt;', $element_url); + + $markup .= '<a href="'.$element_url.'">'.$element_url.'</a>'; + + $offset = strlen($matches[0]); + } + else + { + $markup .= 'http'; + + $offset = 4; + } + + break; + + case '~~': + + if (preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) + { + $matches[1] = $this->parse_span_elements($matches[1], $markers); + + $markup .= '<del>'.$matches[1].'</del>'; + + $offset = strlen($matches[0]); + } + else + { + $markup .= '~~'; + + $offset = 2; + } + + break; + } + + if (isset($offset)) + { + $text = substr($text, $offset); + } + + $markers[$closest_marker_index] = $closest_marker; + } + + $markup = str_replace($this->break_marker, '<br />'."\n", $markup); + + return $markup; + } +} diff --git a/data/admin/post.php b/data/admin/post.php @@ -0,0 +1,16 @@ +<?php +$PASSWD = "notapassword"; +require_once 'markdown.php'; +session_start(); +if ($_POST['password'] == md5($PASSWD . $_SESSION['salt'])) { + $posts = json_decode(file_get_contents($_POST['loc']),TRUE); + parse_str(str_replace(",", "&", $_POST['vars']), $data); + echo "SUCESS <br />"; + $posts[$data["post"]] = array_merge($data,array("content" => Parsedown::instance()->parse($_POST["post"]))); + $fp = fopen($_POST['loc'], 'w'); + fwrite($fp, json_encode($posts)); + fclose($fp); + $output = json_decode(file_get_contents($_POST['loc']),TRUE); + echo $output[$data["post"]]["content"]; +} +?> diff --git a/data/admin/scripts/md5.js b/data/admin/scripts/md5.js @@ -0,0 +1,271 @@ +function md5 (str) { + var xl; + + var rotateLeft = function (lValue, iShiftBits) { + return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); + }; + + var addUnsigned = function (lX, lY) { + var lX4, lY4, lX8, lY8, lResult; + lX8 = (lX & 0x80000000); + lY8 = (lY & 0x80000000); + lX4 = (lX & 0x40000000); + lY4 = (lY & 0x40000000); + lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); + if (lX4 & lY4) { + return (lResult ^ 0x80000000 ^ lX8 ^ lY8); + } + if (lX4 | lY4) { + if (lResult & 0x40000000) { + return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); + } else { + return (lResult ^ 0x40000000 ^ lX8 ^ lY8); + } + } else { + return (lResult ^ lX8 ^ lY8); + } + }; + + var _F = function (x, y, z) { + return (x & y) | ((~x) & z); + }; + var _G = function (x, y, z) { + return (x & z) | (y & (~z)); + }; + var _H = function (x, y, z) { + return (x ^ y ^ z); + }; + var _I = function (x, y, z) { + return (y ^ (x | (~z))); + }; + + var _FF = function (a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + }; + + var _GG = function (a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + }; + + var _HH = function (a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + }; + + var _II = function (a, b, c, d, x, s, ac) { + a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac)); + return addUnsigned(rotateLeft(a, s), b); + }; + + var convertToWordArray = function (str) { + var lWordCount; + var lMessageLength = str.length; + var lNumberOfWords_temp1 = lMessageLength + 8; + var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64; + var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; + var lWordArray = new Array(lNumberOfWords - 1); + var lBytePosition = 0; + var lByteCount = 0; + while (lByteCount < lMessageLength) { + lWordCount = (lByteCount - (lByteCount % 4)) / 4; + lBytePosition = (lByteCount % 4) * 8; + lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount) << lBytePosition)); + lByteCount++; + } + lWordCount = (lByteCount - (lByteCount % 4)) / 4; + lBytePosition = (lByteCount % 4) * 8; + lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); + lWordArray[lNumberOfWords - 2] = lMessageLength << 3; + lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; + return lWordArray; + }; + + var wordToHex = function (lValue) { + var wordToHexValue = "", + wordToHexValue_temp = "", + lByte, lCount; + for (lCount = 0; lCount <= 3; lCount++) { + lByte = (lValue >>> (lCount * 8)) & 255; + wordToHexValue_temp = "0" + lByte.toString(16); + wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); + } + return wordToHexValue; + }; + + var x = [], + k, AA, BB, CC, DD, a, b, c, d, S11 = 7, + S12 = 12, + S13 = 17, + S14 = 22, + S21 = 5, + S22 = 9, + S23 = 14, + S24 = 20, + S31 = 4, + S32 = 11, + S33 = 16, + S34 = 23, + S41 = 6, + S42 = 10, + S43 = 15, + S44 = 21; + + str = this.utf8_encode(str); + x = convertToWordArray(str); + a = 0x67452301; + b = 0xEFCDAB89; + c = 0x98BADCFE; + d = 0x10325476; + + xl = x.length; + for (k = 0; k < xl; k += 16) { + AA = a; + BB = b; + CC = c; + DD = d; + a = _FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); + d = _FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); + c = _FF(c, d, a, b, x[k + 2], S13, 0x242070DB); + b = _FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); + a = _FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); + d = _FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); + c = _FF(c, d, a, b, x[k + 6], S13, 0xA8304613); + b = _FF(b, c, d, a, x[k + 7], S14, 0xFD469501); + a = _FF(a, b, c, d, x[k + 8], S11, 0x698098D8); + d = _FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); + c = _FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); + b = _FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); + a = _FF(a, b, c, d, x[k + 12], S11, 0x6B901122); + d = _FF(d, a, b, c, x[k + 13], S12, 0xFD987193); + c = _FF(c, d, a, b, x[k + 14], S13, 0xA679438E); + b = _FF(b, c, d, a, x[k + 15], S14, 0x49B40821); + a = _GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); + d = _GG(d, a, b, c, x[k + 6], S22, 0xC040B340); + c = _GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); + b = _GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); + a = _GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); + d = _GG(d, a, b, c, x[k + 10], S22, 0x2441453); + c = _GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); + b = _GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); + a = _GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); + d = _GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); + c = _GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); + b = _GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); + a = _GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); + d = _GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); + c = _GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); + b = _GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); + a = _HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); + d = _HH(d, a, b, c, x[k + 8], S32, 0x8771F681); + c = _HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); + b = _HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); + a = _HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); + d = _HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); + c = _HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); + b = _HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); + a = _HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); + d = _HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); + c = _HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); + b = _HH(b, c, d, a, x[k + 6], S34, 0x4881D05); + a = _HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); + d = _HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); + c = _HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); + b = _HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); + a = _II(a, b, c, d, x[k + 0], S41, 0xF4292244); + d = _II(d, a, b, c, x[k + 7], S42, 0x432AFF97); + c = _II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); + b = _II(b, c, d, a, x[k + 5], S44, 0xFC93A039); + a = _II(a, b, c, d, x[k + 12], S41, 0x655B59C3); + d = _II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); + c = _II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); + b = _II(b, c, d, a, x[k + 1], S44, 0x85845DD1); + a = _II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); + d = _II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); + c = _II(c, d, a, b, x[k + 6], S43, 0xA3014314); + b = _II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); + a = _II(a, b, c, d, x[k + 4], S41, 0xF7537E82); + d = _II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); + c = _II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); + b = _II(b, c, d, a, x[k + 9], S44, 0xEB86D391); + a = addUnsigned(a, AA); + b = addUnsigned(b, BB); + c = addUnsigned(c, CC); + d = addUnsigned(d, DD); + } + + var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); + + return temp.toLowerCase(); +} +function utf8_encode (argString) { + // From: http://phpjs.org/functions + // + original by: Webtoolkit.info (http://www.webtoolkit.info/) + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) + // + improved by: sowberry + // + tweaked by: Jack + // + bugfixed by: Onno Marsman + // + improved by: Yves Sucaet + // + bugfixed by: Onno Marsman + // + bugfixed by: Ulrich + // + bugfixed by: Rafal Kukawski + // + improved by: kirilloid + // + bugfixed by: kirilloid + // * example 1: utf8_encode('Kevin van Zonneveld'); + // * returns 1: 'Kevin van Zonneveld' + + if (argString === null || typeof argString === "undefined") { + return ""; + } + + var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n"); + var utftext = '', + start, end, stringl = 0; + + start = end = 0; + stringl = string.length; + for (var n = 0; n < stringl; n++) { + var c1 = string.charCodeAt(n); + var enc = null; + + if (c1 < 128) { + end++; + } else if (c1 > 127 && c1 < 2048) { + enc = String.fromCharCode( + (c1 >> 6) | 192, + ( c1 & 63) | 128 + ); + } else if (c1 & 0xF800 != 0xD800) { + enc = String.fromCharCode( + (c1 >> 12) | 224, + ((c1 >> 6) & 63) | 128, + ( c1 & 63) | 128 + ); + } else { // surrogate pairs + if (c1 & 0xFC00 != 0xD800) { throw new RangeError("Unmatched trail surrogate at " + n); } + var c2 = string.charCodeAt(++n); + if (c2 & 0xFC00 != 0xDC00) { throw new RangeError("Unmatched lead surrogate at " + (n-1)); } + c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000; + enc = String.fromCharCode( + (c1 >> 18) | 240, + ((c1 >> 12) & 63) | 128, + ((c1 >> 6) & 63) | 128, + ( c1 & 63) | 128 + ); + } + if (enc !== null) { + if (end > start) { + utftext += string.slice(start, end); + } + utftext += enc; + start = end = n + 1; + } + } + + if (end > start) { + utftext += string.slice(start, stringl); + } + + return utftext; +}+ \ No newline at end of file diff --git a/data/index.json b/data/index.json @@ -1 +1 @@ -[{"post":"0","date":"1997-10-3","title":"I don't know what I'm doing","content":"Hello! How're you tuhday?"},{"post":"1","date":"1998-9-13","title":"I might have an idea of what I'm doing.","content":"Uh. hi."}]- \ No newline at end of file +[{"post":"0","date":"1997-10-3","title":"I don't know what I'm doing","content":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras blandit, orci eu consectetur eleifend, ante purus luctus leo, id gravida nulla ante ut odio. Nunc non turpis sapien. Pellentesque nec condimentum metus. Mauris vel lorem tincidunt mi tincidunt malesuada. Mauris eu luctus odio. Morbi vel ligula a eros condimentum facilisis sit amet ut ligula. Vivamus quis ultricies elit, sit amet sollicitudin justo. Etiam ac urna condimentum, tempus ipsum vitae, dapibus massa. Maecenas augue nunc, vehicula ultricies tincidunt nec, lacinia vel velit. Donec et leo venenatis, elementum felis elementum, facilisis justo. Ut egestas commodo diam eu adipiscing. Proin vestibulum velit sit amet congue semper. Cras convallis urna nec nibh consectetur bibendum. Vivamus scelerisque velit sit amet congue consequat. In posuere consectetur nisl.<\/p>\n<p>In fringilla nisl et ipsum suscipit, et interdum sem adipiscing. Aenean id turpis porttitor, imperdiet libero sit amet, ultrices augue. Donec id ultricies erat. Nam bibendum pulvinar enim. Sed egestas aliquet nunc ut rhoncus. Ut tristique at leo id condimentum. In hac habitasse platea dictumst. Phasellus eu orci blandit, ultricies dolor quis, ultricies nunc. Fusce elementum mattis nulla, vel tincidunt libero iaculis in. Donec posuere volutpat tortor sit amet auctor.<\/p>\n<p>Quisque fringilla venenatis velit, sed venenatis erat lobortis nec. Etiam fermentum ullamcorper euismod. Suspendisse vulputate lectus a turpis iaculis, nec interdum odio vestibulum. Duis fringilla porttitor dignissim. Sed at risus ac tellus gravida tincidunt. Nulla ornare dui quis nulla vehicula ornare. Etiam bibendum justo risus, et tristique quam bibendum eu. Mauris posuere orci ac enim pharetra, quis tincidunt elit tristique. Ut luctus dolor nulla, ut luctus ligula lacinia quis. Sed interdum interdum ante vel porttitor. Ut a odio ligula. Donec posuere, risus non tincidunt laoreet, nisi massa aliquet lacus, sed blandit diam ligula et lorem.<\/p>\n<p>Cras eu ullamcorper mauris. Maecenas malesuada diam in felis bibendum aliquam et laoreet dui. Pellentesque auctor accumsan diam, eu varius dui iaculis ac. Phasellus iaculis massa a nunc sollicitudin mollis. Curabitur pulvinar libero et ante ullamcorper accumsan. Maecenas non magna a elit blandit congue. Suspendisse mattis ultrices odio eu rutrum. Sed iaculis nulla eu orci ultricies, quis dapibus felis sodales. Nulla in porttitor purus. Morbi porta dictum felis, nec tristique magna posuere in. Cras arcu enim, viverra sed metus in, semper viverra nibh. Morbi rutrum at tellus nec sagittis. In purus turpis, tincidunt id posuere eget, tincidunt ac nulla. Curabitur convallis magna sed nisl congue vestibulum. Duis ut adipiscing lacus, in pharetra neque.<\/p>\n<p>Donec justo nibh, consectetur id massa id, iaculis euismod nunc. Proin pretium risus sem, sagittis luctus massa varius nec. Phasellus mollis posuere lorem, eget malesuada velit varius quis. Praesent quis quam tortor. Vivamus et sagittis odio. Morbi at sollicitudin libero, ac rutrum eros. Duis vitae pretium lorem, vehicula posuere elit. Integer faucibus tristique est nec luctus. Curabitur commodo pellentesque lacus vel feugiat. Vivamus id tellus id metus mollis vestibulum a ac dolor. <\/p>"},{"post":"1","date":"1998-9-13","title":"I might have an idea of what I'm doing.","content":"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras blandit, orci eu consectetur eleifend, ante purus luctus leo, id gravida nulla ante ut odio. Nunc non turpis sapien. Pellentesque nec condimentum metus. Mauris vel lorem tincidunt mi tincidunt malesuada. Mauris eu luctus odio. Morbi vel ligula a eros condimentum facilisis sit amet ut ligula. Vivamus quis ultricies elit, sit amet sollicitudin justo. Etiam ac urna condimentum, tempus ipsum vitae, dapibus massa. Maecenas augue nunc, vehicula ultricies tincidunt nec, lacinia vel velit. Donec et leo venenatis, elementum felis elementum, facilisis justo. Ut egestas commodo diam eu adipiscing. Proin vestibulum velit sit amet congue semper. Cras convallis urna nec nibh consectetur bibendum. Vivamus scelerisque velit sit amet congue consequat. In posuere consectetur nisl.<\/p>\n<p>In fringilla nisl et ipsum suscipit, et interdum sem adipiscing. Aenean id turpis porttitor, imperdiet libero sit amet, ultrices augue. Donec id ultricies erat. Nam bibendum pulvinar enim. Sed egestas aliquet nunc ut rhoncus. Ut tristique at leo id condimentum. In hac habitasse platea dictumst. Phasellus eu orci blandit, ultricies dolor quis, ultricies nunc. Fusce elementum mattis nulla, vel tincidunt libero iaculis in. Donec posuere volutpat tortor sit amet auctor.<\/p>\n<p>Quisque fringilla venenatis velit, sed venenatis erat lobortis nec. Etiam fermentum ullamcorper euismod. Suspendisse vulputate lectus a turpis iaculis, nec interdum odio vestibulum. Duis fringilla porttitor dignissim. Sed at risus ac tellus gravida tincidunt. Nulla ornare dui quis nulla vehicula ornare. Etiam bibendum justo risus, et tristique quam bibendum eu. Mauris posuere orci ac enim pharetra, quis tincidunt elit tristique. Ut luctus dolor nulla, ut luctus ligula lacinia quis. Sed interdum interdum ante vel porttitor. Ut a odio ligula. Donec posuere, risus non tincidunt laoreet, nisi massa aliquet lacus, sed blandit diam ligula et lorem.<\/p>\n<p>Cras eu ullamcorper mauris. Maecenas malesuada diam in felis bibendum aliquam et laoreet dui. Pellentesque auctor accumsan diam, eu varius dui iaculis ac. Phasellus iaculis massa a nunc sollicitudin mollis. Curabitur pulvinar libero et ante ullamcorper accumsan. Maecenas non magna a elit blandit congue. Suspendisse mattis ultrices odio eu rutrum. Sed iaculis nulla eu orci ultricies, quis dapibus felis sodales. Nulla in porttitor purus. Morbi porta dictum felis, nec tristique magna posuere in. Cras arcu enim, viverra sed metus in, semper viverra nibh. Morbi rutrum at tellus nec sagittis. In purus turpis, tincidunt id posuere eget, tincidunt ac nulla. Curabitur convallis magna sed nisl congue vestibulum. Duis ut adipiscing lacus, in pharetra neque.<\/p>\n<p>Donec justo nibh, consectetur id massa id, iaculis euismod nunc. Proin pretium risus sem, sagittis luctus massa varius nec. Phasellus mollis posuere lorem, eget malesuada velit varius quis. Praesent quis quam tortor. Vivamus et sagittis odio. Morbi at sollicitudin libero, ac rutrum eros. Duis vitae pretium lorem, vehicula posuere elit. Integer faucibus tristique est nec luctus. Curabitur commodo pellentesque lacus vel feugiat. Vivamus id tellus id metus mollis vestibulum a ac dolor. <\/p>"}]+ \ No newline at end of file diff --git a/data/styles/style.css b/data/styles/style.css @@ -1,8 +1,26 @@ body, div { width:900px; margin:0 auto; + font-family:sans-serif; } -.current { +a { + text-decoration:none; + color:#0000BB; +} + +a:hover { + color:#9900FF; +} + +a h1:hover { + color:#9900FF; +} + +a:visited { + color:#0000BB; +} + +a.current { border:2px solid black; } \ No newline at end of file diff --git a/data/test.json b/data/test.json @@ -1 +1 @@ -[{"post":"0","date":"1997-10-3","title":"I don't know what I'm doing","content":"Hello! How're you tuhday?"},{"post":"1","date":"1998-9-13","title":"I might have an idea of what I'm doing.","content":"Uh. hi."}]- \ No newline at end of file +[{"post":"0","date":"1997-10-3","title":"This is a test for tesing purposes","content":"<p>Blaugh.<\/p>"},{"post":"1","date":"2010-11-20","title":"No clue. Not one.","content":"<p>Uh. hi...<\/p>\n<p>Still...<\/p>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras blandit, orci eu consectetur eleifend, ante purus luctus leo, id gravida nulla ante ut odio. Nunc non turpis sapien. Pellentesque nec condimentum metus. Mauris vel lorem tincidunt mi tincidunt malesuada. Mauris eu luctus odio. Morbi vel ligula a eros condimentum facilisis sit amet ut ligula. Vivamus quis ultricies elit, sit amet sollicitudin justo. Etiam ac urna condimentum, tempus ipsum vitae, dapibus massa. Maecenas augue nunc, vehicula ultricies tincidunt nec, lacinia vel velit. Donec et leo venenatis, elementum felis elementum, facilisis justo. Ut egestas commodo diam eu adipiscing. Proin vestibulum velit sit amet congue semper. Cras convallis urna nec nibh consectetur bibendum. Vivamus scelerisque velit sit amet congue consequat. In posuere consectetur nisl. <\/p>"}]+ \ No newline at end of file diff --git a/mod/blog.py b/mod/blog.py @@ -32,14 +32,30 @@ def getPages(template,settings,name,page): pages['post'][slug(i['title'])] = template.replace("%"+name+"%",post) # Generates archive based off of dates. - pages['archive'] = {} a = "" dates = {} for i in data: - datedata = i['date'].split["-"] - - pages['archive']['default'] = template.replace("%content%",a) - + datedata = i['date'].split("-") + if datedata[0] in dates: + if datedata[1] in dates[datedata[0]]: + dates[datedata[0]][datedata[1]][datedata[2]] = i['title'] + else: + dates[datedata[0]][datedata[1]] = {} + dates[datedata[0]][datedata[1]][datedata[2]] = i['title'] + else: + dates[datedata[0]] = {} + dates[datedata[0]][datedata[1]] = {} + dates[datedata[0]][datedata[1]][datedata[2]] = i['title'] + a = "<ul>" + for year,months in sorted(dates.items(),reverse=True): + a = a + "<li>{}</li><li><ul>".format(year) + for month,days in sorted(months.items(),reverse=True): + a = a + "<li>{}</li><li><ul>".format(month) + for day,title in sorted(days.items(),reverse=True): + a = a + "<li>{} - <a href=\"{}\">{}</a></li>".format(day,slug(title),title) + a = a + "</ul></li>" + a = a + "</ul></li>" + pages['post']['default'] = template.replace("%content%", a) return pages diff --git a/templates/std.html b/templates/std.html @@ -7,7 +7,7 @@ <body> %:header% {: -for i,x in pagedata.items(): +for i,x in sorted(pagedata.items(),reverse=True): l = i if page == "":page = "index" if str(i) == page: c = "current" @@ -21,7 +21,7 @@ if page != "index": page = page + "/" else: page = "" -returns = returns + "<a href=\"/{}all\">All posts</a>".format(page) +returns = returns + "<a href=\"/{}all\">All posts</a>&nbsp<a href=\"/{}post\">Archive</a>".format(page,page) :} <div> %content%