added Sorting class to handle organizing tags and archives organizing for page rendering. added empty Render class for rendering
parent
39809a60ec
commit
c78772e2c0
@ -1,74 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
include "../brain/data/Settings.inc.php";
|
|
||||||
use function _\find;
|
use function _\find;
|
||||||
use ReallySimpleJWT\Token;
|
use ReallySimpleJWT\Token;
|
||||||
|
|
||||||
class Auth
|
class Auth
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function sessionStatus()
|
public static function sessionStatus()
|
||||||
{
|
{
|
||||||
if (isset($_SESSION["member"])) {
|
if (isset($_SESSION["member"])) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
//return $this->secret;
|
||||||
}
|
}
|
||||||
//return $this->secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function status()
|
public static function status()
|
||||||
{
|
{
|
||||||
$result = "";
|
$result = "";
|
||||||
if (Session::active()) {
|
if (Session::active()) {
|
||||||
$result = true;
|
$result = true;
|
||||||
} else {
|
} else {
|
||||||
$result = false;
|
$result = false;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function login($who)
|
public static function login($who)
|
||||||
{
|
{
|
||||||
//grab member list
|
//grab member list
|
||||||
$folks = (new Settings())->getFolks();
|
$folks = (new Settings())->getFolks();
|
||||||
$found = find($folks, ["handle" => $who["handle"]]);
|
$found = find($folks, ["handle" => $who["handle"]]);
|
||||||
|
|
||||||
if ($found) {
|
if ($found) {
|
||||||
//name is found, verify password
|
//name is found, verify password
|
||||||
if (password_verify($who["password"], $found["password"])) {
|
if (password_verify($who["password"], $found["password"])) {
|
||||||
$member = [
|
$member = [
|
||||||
"handle" => $found["handle"],
|
"handle" => $found["handle"],
|
||||||
"email" => $found["email"],
|
"email" => $found["email"],
|
||||||
"role" => $found["role"],
|
"role" => $found["role"],
|
||||||
"avatar" => $found["avi"],
|
"avatar" => $found["avi"],
|
||||||
];
|
];
|
||||||
|
|
||||||
$token = Token::create(
|
$token = Token::create(
|
||||||
$found["id"],
|
$found["id"],
|
||||||
$found["secret"],
|
$found["secret"],
|
||||||
time() + 3600,
|
time() + 3600,
|
||||||
"localhost"
|
"localhost"
|
||||||
); //expires in an hour
|
); //expires in an hour
|
||||||
Session::start();
|
Session::start();
|
||||||
Session::set("member", $member);
|
Session::set("member", $member);
|
||||||
Session::set("token", $token);
|
Session::set("token", $token);
|
||||||
|
|
||||||
$result = "good_login";
|
$result = "good_login";
|
||||||
} else {
|
} else {
|
||||||
$result = "bad_pass";
|
$result = "bad_pass";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//if name is not found
|
//if name is not found
|
||||||
$result = "no_name";
|
$result = "no_name";
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function logout()
|
public static function logout()
|
||||||
{
|
{
|
||||||
Session::kill();
|
Session::kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Render
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
use function _\find;
|
||||||
|
use function _\filter;
|
||||||
|
|
||||||
|
class Sorting
|
||||||
|
{
|
||||||
|
private static $_tags = [];
|
||||||
|
private static $_archive = [];
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tags()
|
||||||
|
{
|
||||||
|
$pages = (new Book("../content/pages"))->getContents();
|
||||||
|
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$temp = [];
|
||||||
|
$temp = explode(",", $page["tags"]);
|
||||||
|
foreach ($temp as $tag) {
|
||||||
|
$label = trim($tag);
|
||||||
|
if (!find(self::$_tags, ["tag_name" => $label])) {
|
||||||
|
array_push(self::$_tags, [
|
||||||
|
"tag_name" => $label,
|
||||||
|
"slug" => StringTools::safeString($label),
|
||||||
|
"count" => 1,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$item = find(self::$_tags, ["tag_name" => $label]);
|
||||||
|
//echo "TAG: " . $item["tag_name"] . "\n";
|
||||||
|
$count = $item["count"];
|
||||||
|
self::$_tags[$label]["count"] = $count + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$_tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function archive()
|
||||||
|
{
|
||||||
|
$pages = (new Book("../content/pages"))->getContents();
|
||||||
|
$years = [];
|
||||||
|
$archive = [];
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$year = date("Y", date($page["rawCreated"]));
|
||||||
|
//echo $page["title"] . " : " . $year . "\n";
|
||||||
|
if (!find($years, ["year" => $year])) {
|
||||||
|
$findPages = filter($pages, ["createdYear" => $year]);
|
||||||
|
//var_dump($findPages);
|
||||||
|
array_push($years, ["year" => $year, "count" => count($findPages)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($years as $year) {
|
||||||
|
$sorted = [];
|
||||||
|
$filtered = filter($pages, ["createdYear" => $year["year"]]);
|
||||||
|
|
||||||
|
foreach ($filtered as $obj) {
|
||||||
|
$month = date("m", date($obj["rawCreated"]));
|
||||||
|
if (!find($sorted, ["month" => $month])) {
|
||||||
|
$perMonth = filter($pages, [
|
||||||
|
"createdYear" => $year["year"],
|
||||||
|
"createdMonth" => $month,
|
||||||
|
"deleted" => false,
|
||||||
|
"published" => true,
|
||||||
|
"layout" => "page",
|
||||||
|
]);
|
||||||
|
array_push($sorted, [
|
||||||
|
"month" => $month,
|
||||||
|
"full_month" => date("F", date($obj["rawCreated"])),
|
||||||
|
"count" => count($perMonth),
|
||||||
|
"pages" => $perMonth,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
array_push(self::$_archive, [
|
||||||
|
"year" => $year["year"],
|
||||||
|
"year_data" => $sorted,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return self::$_archive;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue