pnbp

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

commit 53cece7e92272f5e5e3893063744285cb9e8f08c
parent 1e17a462193555725d6ed4c5d82c0832c49cef2c
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Sat Jun 27 19:50:53 2015

Made the admin module a tad more pretty

Diffstat:
 .gitignore                                    |   2 +-
 src/core/__init__.py                          |  14 +--
 src/core/builder.py                           |   2 +-
 src/core/modules/admin.py                     | 199 +---------------------------
 src/core/modules/data/admin/edit.template     |  80 +++++++++++-
 src/core/modules/data/admin/htaccess.template |   5 +-
 src/core/modules/data/admin/index.template    |  55 +++++++-
 src/core/modules/data/admin/post.template     |  46 ++++++-
 src/init.py                                   |   8 +-
 9 files changed, 204 insertions(+), 207 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -18,5 +18,3 @@ emacs-config.el #Don't want to upload the site, do we? site/ -#Or the admin page... -admin/ diff --git a/src/core/__init__.py b/src/core/__init__.py @@ -12,14 +12,12 @@ import core.builder def init(arg): if arg.init: core.helper.cmd.init() - if arg.dir != "": - i = os.getcwd() + + if os.path.exists(arg.dir): + os.chdir(arg.dir) else: - if os.path.exists(arg.dir): - i = arg.dir - else: - print("'{}' does not exist".format(arg.dir)) - sys.exit(1) + print("'{}' does not exist".format(arg.dir)) + sys.exit(1) #Try to get the config try: @@ -31,5 +29,5 @@ def init(arg): pagedata = yaml.load(pages) - core.builder.build(pagedata,arg.dir) + core.builder.build(pagedata,arg.out) diff --git a/src/core/builder.py b/src/core/builder.py @@ -15,7 +15,7 @@ def makeSite(site,loc): shutil.move(loc, loc+".bak") except: - print("No directory '{}', ignoring".format(loc)) + print("Creating directory '{}'".format(loc)) os.mkdir(loc) for page, subpages in site.items(): diff --git a/src/core/modules/admin.py b/src/core/modules/admin.py @@ -1,202 +1,15 @@ -import yaml +import os, yaml def getPages(template,settings,name,page): blogdb = getBlogDB(settings) if settings['root'][-1] != "/": settings['root'] = settings['root'] + "/" settings['pass'] = settings.get("pass",settings['root'] + "data/.htpasswd") - index = """ -<!DOCTYPE html> -<html> - <head> - <title>Admin Page</title> - <style> -html { - font-family:sans-serif; - 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>".$name[$index]."</h1>"; - echo "<div class='container'>"; - $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> -<html> -<head> - <title>Admin</title> - <style> -html { - font-family:sans-serif; - 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:700px; - 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"> - <a href="/admin" class="nav">Home</a> -<?php - -if (isset($_GET['location']) && isset($_GET['post'])) { - $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'] = $data[$_GET['post']]['content']; -} else { - $_SESSION['post'] = ""; - $_SESSION['vars'] = ""; - 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();"> - <label>Variables:</label><input id="vars" name="vars" type="text" class="input" value="<?php echo $_SESSION['vars']; ?>"/><input type="submit" id="submit" class="input"/><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> -</body> -</html> -""" - - post = """ -<!DOCTYPE html> -<html> - <head> - <title>Admin</title> - <style> -html { - font-family:sans-serif; - 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; -} - </style> - </head> - <body> - <div id="container"> - <a href="/admin" class="nav">Home</a> - <plaintext> -<?php -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 shell_exec("build %destination% -d %root%"); -?> -""" - htaccess = """ -AuthUserFile %pass% -AuthName "Please Log In" -AuthType Basic -Require user %user% -""" + d = os.path.dirname(__file__) + index = file(os.path.join(d, "data/admin/index.template")).read() + edit = file(os.path.join(d, "data/admin/edit.template")).read() + post = file(os.path.join(d, "data/admin/post.template")).read() + htaccess = file(os.path.join(d, "data/admin/htaccess.template")).read() return { "index.php":index.replace("%db%",blogdb[0][:-1]).replace("%dbn%",blogdb[1][:-1]), diff --git a/src/core/modules/data/admin/edit.template b/src/core/modules/data/admin/edit.template @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html> +<head> + <title>Admin</title> + <style> +html { + font-family:sans-serif; + 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:700px; + 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"> + <a href="/admin" class="nav">Home</a> +<?php + +if (isset($_GET['location']) && isset($_GET['post'])) { + $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'] = $data[$_GET['post']]['content']; +} else { + $_SESSION['post'] = ""; + $_SESSION['vars'] = ""; + 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();"> + <label>Variables:</label><input id="vars" name="vars" type="text" class="input" value="<?php echo $_SESSION['vars']; ?>"/><input type="submit" id="submit" class="input"/><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> +</body> +</html> +" diff --git a/src/core/modules/data/admin/htaccess.template b/src/core/modules/data/admin/htaccess.template @@ -0,0 +1,5 @@ +AuthUserFile %pass% +AuthName "Please Log In" +AuthType Basic +Require user %user% + diff --git a/src/core/modules/data/admin/index.template b/src/core/modules/data/admin/index.template @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<html> + <head> + <title>Admin Page</title> + <style> +html { + font-family:sans-serif; + 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>".$name[$index]."</h1>"; + echo "<div class='container'>"; + $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> + diff --git a/src/core/modules/data/admin/post.template b/src/core/modules/data/admin/post.template @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> + <head> + <title>Admin</title> + <style> +html { + font-family:sans-serif; + 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; +} + </style> + </head> + <body> + <div id="container"> + <a href="/admin" class="nav">Home</a> + <plaintext> +<?php +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 shell_exec("build %destination% -d %root%"); +?> + diff --git a/src/init.py b/src/init.py @@ -15,10 +15,12 @@ from optparse import OptionParser def parsearg(): parser = OptionParser() - parser.add_option("-d", "--directory", dest="dir", default="site", - help="Set site project root directory", metavar="<dir>") + parser.add_option("-d", dest="dir", default=".", + help="set site project root directory", metavar="<dir>") + parser.add_option("-o", dest="out", default="site", + help="where to output", metavar="<out>") parser.add_option("-i", "--init", dest="init", action="store_true", default=False, - help="Initalize basic project directory") + help="initalize basic project directory") return parser.parse_args() if __name__ == "__main__":