pnbp

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

commit c66ec384ec0f4fd999c0e13e03a4ee6831eafe4c
parent 83cc682c40674c57cc6827d039b45c5a6ff0f29d
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Sun Aug 31 17:18:20 2014

more admin

Diffstat:
 src/functions.py         |  14 +++---
 src/module/.admin.py.swp | Bin 20480 -> 0 bytes
 src/module/admin.py      | 113 ++++++++++++++++++++++++++++++++++++------------
 src/module/blog.py       |  18 +++++++-
 4 files changed, 108 insertions(+), 37 deletions(-)

diff --git a/src/functions.py b/src/functions.py @@ -11,14 +11,14 @@ import time #Return the current date in the format sepecified in config def now(config): - return time.strftime(config) + return time.strftime(config) #Return an HTML list. example format: {'root':"<ul class=\"special\">%li%</ul>",'li':"<li class=\"list\">%content%</li>"} def list(things,formats={}): - formats['root'] = formats.get("root","<ul>%li%</ul>") - formats['li'] = formats.get("li","<li>%content%</li>") - li = "" - for thing in things: - li = li + formats['li'].replace("%content%",thing) + formats['root'] = formats.get("root","<ul>%li%</ul>") + formats['li'] = formats.get("li","<li>%content%</li>") + li = "" + for thing in things: + li = li + formats['li'].replace("%content%",thing) - return formats['root'].replace("%li%",li) + return formats['root'].replace("%li%",li) diff --git a/src/module/.admin.py.swp b/src/module/.admin.py.swp Binary files differ diff --git a/src/module/admin.py b/src/module/admin.py @@ -1,7 +1,8 @@ import yaml def getPages(template,settings,name,page): - blogdb = getBlogDB() + blogdb = getBlogDB(settings) + print blogdb[0] index = """ <!DOCTYPE html> <html> @@ -12,31 +13,51 @@ html { background-color:#EFEFEF; border-top:5px solid #FF9311; } +a { + text-decoration:none; + color:#4183c4; +} +a:hover { + text-decoration:underline; +} +a:visited { + color:#4183c4; +} +#container { + width:700px; + margin:0 auto; +} .container { margin-left:50px; } </style> </head> <body> + <div id="container"> <a href="/admin" class="nav">Home</a> + <a href="/admin/post.php">Update</a> <?php - $databases = [%db%]; - +$name = [%dbn%]; +$index = 0; foreach ($databases as $db) { $data = json_decode(file_get_contents($db),TRUE); - echo "<h1>".$db."</h1>"; + echo "<h1>".$name[$index]."</h1>"; echo "<div class='container'>"; - echo "<a href=\\"edit.php?location=".$db."\\">New Post</a><br/>"; + $new = 0; foreach ($data as $val) { echo "<a href=\\"edit.php?location=".$db."&post=".$val["post"]."\\">".$val["title"]."</a><br/>"; + $new = $new + 1; } + echo "<br /><a href=\\"edit.php?location=".$db."&newpost=".$new."\\">New Post</a><br/>"; echo "</div>"; + $index = $index + 1; } ?> + </div> </body> </html> - """ +""" edit = """ <!DOCTYPE html> @@ -48,8 +69,18 @@ html { background-color:#EFEFEF; border-top:5px solid #FF9311; } +a { + text-decoration:none; + color:#4183c4; +} +a:hover { + text-decoration:underline; +} +a:visited { + color:#4183c4; +} #wrapper { - width:800px; + width:700px; margin:0 auto; } #wrapper label { @@ -95,7 +126,8 @@ if (isset($_GET['location']) && isset($_GET['post'])) { } else { $_SESSION['post'] = ""; $_SESSION['vars'] = ""; - $_GET['location'] = ""; + if (isset($_GET['location']) == false) { $_GET['location'] = ""; } + if (isset($_GET['newpost'])) { $_SESSION['vars'] = "post=".$_GET['newpost'].", "; } } ?> <form id="update" action="./post.php" method="post" onsubmit="return validate();"> @@ -118,43 +150,68 @@ html { background-color:#EFEFEF; border-top:5px solid #FF9311; } -.example { +a { + text-decoration:none; + color:#4183c4; +} +a:hover { + text-decoration:underline; +} +a:visited { + color:#4183c4; +} + +#container { width:700px; margin:0 auto; } </style> </head> <body> - <a href="/admin" class="nav">Home</a> + <div id="container"> + <a href="/admin" class="nav">Home</a> + <plaintext> <?php -$posts = json_decode(file_get_contents($_POST['loc']),TRUE); -parse_str(str_replace(",", "&", $_POST['vars']), $data); - -echo "<div class=\\"example\\">"; +if (isset($_POST['loc'])) { + $posts = json_decode(file_get_contents($_POST['loc']),TRUE); + parse_str(str_replace(",", "&", $_POST['vars']), $data); -$posts[$data["post"]] = array_merge($data,array("content" => $_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"]; -echo "</div>"; -echo "<hr/>"; -echo "<plaintext>". shell_exec("build %destination% -d %root%"); + $posts[$data["post"]] = array_merge($data,array("content" => $_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"]; + echo "</div>"; +} +echo shell_exec("build %destination% -d %root%"); ?> """ - return {"php:index":index.replace("%db%",blogdb[:-1]),"php:edit":edit,"php:post":post.replace("%root%",settings['root']).replace("%destination%",settings['dest'])} + return { + "php:index":index.replace("%db%",blogdb[0][:-1]).replace("%dbn%",blogdb[1][:-1]), + "php:edit":edit, + "php:post":post.replace("%root%",settings['root']).replace("%destination%",settings['dest']), + } -def getBlogDB(): +def getBlogDB(s): dbs = "" - + dbn = "" data = yaml.load(file("pages.yml").read()) for k,v in data.items(): for m,md in v['pagemod'].items(): if md['mod'] == "blog": - dbs = dbs + "\""+md['settings']['data']+"\"," + if md['settings']['data'][0:2] == "./" or md['settings']['data'][0] != "/": + if s['root'][-1] != "/": + s['root'] = s['root'] + "/" + + dbs = dbs + "\""+s['root']+md['settings']['data'][2:]+"\"," + + else: + dbs = dbs + "\""+md['settings']['data']+"\"," + + dbn = dbn + "\""+k+"\"," - return dbs + return [dbs,dbn] diff --git a/src/module/blog.py b/src/module/blog.py @@ -1,11 +1,15 @@ -import json,time +import markdown,json,time def getPages(template,settings,name,page): pages = {} settings['postTemplate'] = settings.get("postTemplate","./templates/post.html") settings['defaultPostCount'] = settings.get("defaultPostCount","0") settings['description'] = settings.get("description","0") - data = json.load(file(settings['data'])) + settings['database'] = settings.get("database","markdown") + settings['backend'] = settings.get("backend","json") + + data = getDB(settings['data'],settings['backend'],settings['database']) + temp = file(settings['postTemplate']).read() # Generates all posts on page (/all) @@ -99,3 +103,13 @@ def getConfig(index,data): retVal = retVal + data[pointer] pointer += 1 return retVal + +def getDB(db, backend, content): + dbdata = {} + if backend == "json": + dbdata = json.load(file(db)) + if content == "markdown": + for post in dbdata: + post['content'] = markdown.markdown(post['content']) + + return dbdata