diff --git a/post.php b/p/index.php similarity index 55% rename from post.php rename to p/index.php index 0240dd4..f28cd53 100644 --- a/post.php +++ b/p/index.php @@ -8,30 +8,39 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. */ -$depth = ""; +$depth = "../"; $title = ""; -$mark = "post"; -include "res/lib/load.php"; +$mark = "p_index"; +include "../res/lib/load.php"; // ------------------------------------- -$id = $_GET['id'] ?? post_name_to_id($_GET['name']); + +$id = $_GET['id'] ?? post_title_to_id($_GET['name']); $name = post_title($id); +// ------------------------------------- + +if (empty($_GET['id']) && empty($_GET['name'])) { + root_redirect('p/list/'); +} else if (!is_post_id($_GET['id']) && !is_post_title($_GET['name'])) { + general_error("We can't find that post! :("); +} + // -------------------------------------- -$text = markdown(post_text($id)); -$date = post_date($id); -$data = post_data($id); +$post_text = markdown(post_text($id)); +$post_date = post_date($id); +$post_data = post_data($id); $user_id = post_author($id); $username = user_name($user_id); $full_name = user_full_name($user_id); -$local_exports = array('id' => $id, 'text' => $text, 'username' => $username, - 'user_id' => $user_id, 'full_name' => $full_name, - 'data' => $data, 'title' => $name, - 'date' => $date); +$local_exports = array('post_id' => $id, 'post_text' => $post_text, + 'post_author' => $user_id, + 'post_data' => $post_data, 'post_title' => $name, + 'post_date' => $date); // ------------------------------------- diff --git a/p/list/index.php b/p/list/index.php new file mode 100644 index 0000000..183d309 --- /dev/null +++ b/p/list/index.php @@ -0,0 +1,20 @@ + diff --git a/new/post/index.php b/p/new/index.php similarity index 95% rename from new/post/index.php rename to p/new/index.php index 5eddb3a..ddd3083 100644 --- a/new/post/index.php +++ b/p/new/index.php @@ -9,7 +9,7 @@ GNU Affero General Public License for more details. */ $title = "New Post"; -$mark = "new_post_index"; +$mark = "p_new_index"; $depth = "../../"; include "../../res/lib/load.php"; diff --git a/new/post/private/post_create.php b/p/new/private/post_create.php similarity index 100% rename from new/post/private/post_create.php rename to p/new/private/post_create.php diff --git a/res/lib/blagoblag.php b/res/lib/blagoblag.php index 4a4a550..2c68f87 100644 --- a/res/lib/blagoblag.php +++ b/res/lib/blagoblag.php @@ -16,6 +16,9 @@ function display_page($mark, $depth, $title, $local_exports=array()) { echo $GLOBALS['twig']->render("head.twig.html", make_exports($depth, $title, $mark, $local_exports)); + echo $GLOBALS['twig']->render("navbar.twig.html", + make_exports($depth, $title, $mark, + $local_exports)); echo $GLOBALS['twig']->render($mark . ".twig.html", make_exports($depth, $title, $mark, $local_exports)); diff --git a/res/lib/load.php b/res/lib/load.php index 471469a..d4f9531 100644 --- a/res/lib/load.php +++ b/res/lib/load.php @@ -41,6 +41,8 @@ $twig = new Twig_Environment($loader, ['cache' => // global variable declaration global $users; $users = user_ids(); global $user; $user = array(); +global $posts; $posts = post_ids_recent(); +global $post; $post = array(); $push_user_data = function($user_id) { $user_name = user_name($user_id); @@ -48,11 +50,14 @@ $push_user_data = function($user_id) { $GLOBALS['user'][$user_name] = user_data($user_id); }; -array_map($push_user_data, $users); +$push_post_data = function($post_id) { + $post_title = post_title($post_id); + $GLOBALS['post'][$post_id] = post_data($post_id); + $GLOBALS['post'][$post_title] = post_data($post_id); + }; -global $posts; $posts = post_ids_recent(); -global $post; $post = array(); -$post = array_map("post_data", $posts); +array_map($push_user_data, $users); +array_map($push_post_data, $posts); // ----------------- @@ -61,6 +66,7 @@ $twig_exports = array('theme' => $GLOBALS['theme'], 'users' => $GLOBALS['users'], 'user' => $GLOBALS['user'], 'posts' => $GLOBALS['posts'], - 'post' => $GLOBALS['post']); + 'post' => $GLOBALS['post'], + 'instance_title' => $GLOBALS['instance_title']); ?> diff --git a/res/lib/post.php b/res/lib/post.php index 0ad9e5d..0ac0ad7 100644 --- a/res/lib/post.php +++ b/res/lib/post.php @@ -47,8 +47,7 @@ function post_delete($id) { // ------------------------------------- - -function post_name_to_id($name) { +function post_title_to_id($name) { return db_get_cell("posts", "title", string_wrap($name), "id"); } diff --git a/res/lib/sterilize.php b/res/lib/sterilize.php index aba197e..fbc4587 100644 --- a/res/lib/sterilize.php +++ b/res/lib/sterilize.php @@ -140,6 +140,26 @@ function is_user_id($id) { } } +// NUMBER --> BOOLEAN +// Return whether or not a number is a post ID +function is_post_id($id) { + if (post_title($id)) { + return true; + } else { + return false; + } +} + +// NUMBER --> BOOLEAN +// Return whether or not a string is a post name +function is_post_title($title) { + if (post_title_to_id($title)) { + return true; + } else { + return false; + } +} + // ------------------------------------- // STRING --> BOOLEAN @@ -156,6 +176,21 @@ function is_free_user_id($id) { return true; } else { return false; } } +// STRING --> BOOLEAN +// Return whether or not a given string is a valid (unused) post title +function is_free_post_title($title) { + if (!is_post_title($title) && is_ne_string($title)) { + return true; } else { return false; } +} + +// STRING --> BOOLEAN +// Return whether or not a given number is a valid (unused) psot ID +function is_free_post_id($id) { + if (!is_post_id($id) && is_int($id)) { + return true; } else { return false; } +} + +// ------------------------------------- function bleep_word($word, $replacement) { $word = str_replace("a", $replacement, $word); diff --git a/res/lib/user.php b/res/lib/user.php index eb72f5f..ab3b6ed 100644 --- a/res/lib/user.php +++ b/res/lib/user.php @@ -142,6 +142,49 @@ function user_data($id) { // ------------------------------------- +// NUMBER --> NUMBER +// Generate a new login-token and associate it with the user's account. +// Returns the token number. +function user_token_create($id) { + $token = rand(0, 5000000); + db_set_cell("lusers", "id", $id, "token", rand(0, 5000000)); + return $token; +} + +// NUMBER NUMBER --> BOOLEAN +// Return whether or not a token is valid for a certain user account +function user_token_validate($id, $token) { + $valid_token = db_get_cell("lusers", "id", $id, "token"); + + if ($token == $valid_token) { + return true; + + } else { + return false; + } +} + + +// ------------------------------------- + + +// NUMBER --> NIL +// Log a user in-- create a token, then make a cookie with said token. +function user_log_in($id) { + $token = user_token_create($id); + setcookie("token", $token, 2628000); + setcookie("id", $id, 2628000); +} + +function logged() { + if (user_token_validate($id, $_COOKIE['token'])) { + return $id; + } else { + return "no"; + } +} + +// ------------------------------------- // NUMBER STRING --> BOOLEAN // Return whether or not a given password is valid. function user_valid_password($id, $password) { diff --git a/res/themes/default/css/global.css b/res/themes/default/css/global.css index 85c73fe..05eaefa 100644 --- a/res/themes/default/css/global.css +++ b/res/themes/default/css/global.css @@ -1,213 +1,74 @@ -/*PEN STYLES*/ - -* { - box-sizing: border-box; -} - -.postbox { - height: 500px; -} - - +/* The color-combo we're using: + * https://www.colorcombos.com/color-schemes/116/ColorCombo116.html */ body { - background: #f1f1f1; - margin: 2rem; + background-color: #CECFCE; + font-family: sans-serif; + font-size: 17px; + color: #073642; + width: 100%; } -$color_white: #fff; -$color_prime: #5ad67d; -$color_grey: #e2e2e2; -$color_grey_dark: #a2a2a2; - -.blog-card { - display: flex; - flex-direction: column; - margin: 1rem auto; - box-shadow: 0 3px 7px -1px rgba(#000, .1); - margin-bottom: 1.6%; - background: $color_white; - line-height: 1.4; - font-family: sans-serif; - border-radius: 5px; - overflow: hidden; - z-index: 0; - a { - color: inherit; - &:hover { - color: $color_prime; - } - } - &:hover { - .photo { - transform: scale(1.3) rotate(3deg); - } - } - .meta { - position: relative; - z-index: 0; - height: 200px; - } - .photo { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - background-size: cover; - background-position: center; - transition: transform .2s; - } - .details, - .details ul { - margin: auto; - padding: 0; - list-style: none; - } - - .details { - position: absolute; - top: 0; - bottom: 0; - left: -100%; - margin: auto; - transition: left .2s; - background: rgba(#000, .6); - color: $color_white; - padding: 10px; - width: 100%; - font-size: .9rem; - a { - text-decoration: dotted underline - } - ul li { - display: inline-block; - } - .author:before { - font-family: FontAwesome; - margin-right: 10px; - content: "\f007"; - } - - .date:before { - font-family: FontAwesome; - margin-right: 10px; - content: "\f133"; - } - - .tags { - ul:before { - font-family: FontAwesome; - content: "\f02b"; - margin-right: 10px; - } - li { - margin-right: 2px; - &:first-child { - margin-left: -4px; - } - } - } - } - .description { - padding: 1rem; - background: $color_white; - position: relative; - z-index: 1; - h1, - h2 { - font-family: Poppins, sans-serif; - } - h1 { - line-height: 1; - margin: 0; - font-size: 1.7rem; - } - h2 { - font-size: 1rem; - font-weight: 300; - text-transform: uppercase; - color: $color_grey_dark; - margin-top: 5px; - } - .read-more { - text-align: right; - a { - color: $color_prime; - display: inline-block; - position: relative; - &:after { - content: "\f061"; - font-family: FontAwesome; - margin-left: -10px; - opacity: 0; - vertical-align: middle; - transition: margin .3s, opacity .3s; - } - - &:hover:after { - margin-left: 5px; - opacity: 1; - } - } - } - } - p { - position: relative; - margin: 1rem 0 0; - &:first-of-type { - margin-top: 1.25rem; - &:before { - content: ""; - position: absolute; - height: 5px; - background: $color_prime; - width: 35px; - top: -0.75rem; - border-radius: 3px; - } - } - } - &:hover { - .details { - left: 0%; - } - } - - - @media (min-width: 640px) { - flex-direction: row; - max-width: 700px; - .meta { - flex-basis: 40%; - height: auto; - } - .description { - flex-basis: 60%; - &:before { - transform: skewX(-3deg); - content: ""; - background: #fff; - width: 30px; - position: absolute; - left: -10px; - top: 0; - bottom: 0; - z-index: -1; - } - } - &.alt { - flex-direction: row-reverse; - .description { - &:before { - left: inherit; - right: -10px; - transform: skew(3deg) - } - } - .details { - padding-left: 25px; - } - } - } +nav { + background-color: #84596B; + width: 100%; + margin: 0; + padding: 0; } +nav ul { + background-color: #84596B; + overflow: hidden; + color: #FFFFFF; +} + +nav li { + display: block; + margin-left: 20px; + margin-right: 20px; + background-color: #84596B; + float: left; + padding: 10px; +} + +#star { + margin-left: 1px; + margin-right: 1px; + padding-left: 0px; + padding-right: 0px; + font-weight: bold; + color: #D86969; +} + +#star:hover { + background-color: inherit; +} + +nav li:hover { + background-color: #AFB170; +} + +nav li a { + text-decoration: none; + color: #FFFFFF; +} + +.right { + float: right; +} + +p { + max-width: 700px; + padding-left: 10%; +} + + +.post_card { + height: 200px; + display: inline-block; + overflow: hidden; + max-width: 200px; + border-style: solid; + border-width: 2px; + border-color: #B58AA5; + border-radius: 5px; +} diff --git a/res/themes/default/html/index.twig.html b/res/themes/default/html/index.twig.html index dc3c88a..18e6be9 100644 --- a/res/themes/default/html/index.twig.html +++ b/res/themes/default/html/index.twig.html @@ -1,12 +1,5 @@ {% for post_id in posts %} - {% set post_author = post[post_id]['author'] %} - {% set post_username = user[post_author]['name'] %} - {% set post_full_name = user[post_author]['full_name'] %} - - {% set post_title = post[post_id]['title'] %} - {% set post_date = post[post_id]['date'] %} - {% set post_desc = post[post_id]['desc'] %} - - {{ include('meta_post_card.html') }} + {% set post_id = post_id %} + {{ include('meta_post_card.twig.html') }} {% endfor %} diff --git a/res/themes/default/html/meta_post_card.twig.html b/res/themes/default/html/meta_post_card.twig.html new file mode 100644 index 0000000..28474f2 --- /dev/null +++ b/res/themes/default/html/meta_post_card.twig.html @@ -0,0 +1,15 @@ +
{{ post[post_id]['desc'] }}
{{ post_text }}
diff --git a/res/themes/default/html/p_list_index.twig.html b/res/themes/default/html/p_list_index.twig.html new file mode 100644 index 0000000..c4a29d7 --- /dev/null +++ b/res/themes/default/html/p_list_index.twig.html @@ -0,0 +1,19 @@ ++ + {{ post[id]['title'] }} + + | ++ + {{ user[post[id]['author']]['full_name'] }} + + | ++ {{ post[id]['date'] }} + | +
{{ user_bio }}
+ +{% for post_id in user_posts %} + {% set post_id = post_id %} + + {{ include ('meta_post_card.twig.html') }} +{% endfor %} + diff --git a/res/themes/default/html/u_list_index.twig.html b/res/themes/default/html/u_list_index.twig.html new file mode 100644 index 0000000..4e2544e --- /dev/null +++ b/res/themes/default/html/u_list_index.twig.html @@ -0,0 +1,7 @@ +