forked from projects/fipamo
hot fix for open graph image rendering
This commit is contained in:
commit
6f2a8cfb4b
6 changed files with 148 additions and 139 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
# Fipamo means to save
|
||||
|
||||
The Fipamo project was born from a need for a simple, easy to use no data blog platform that doesn't require much effort to set up and maintain. Fipamo uses Markdown to handle posts and renders them to flat html so you can serve them from anywhere. No complicated set ups. No long list of dependencies. Just write and publish.
|
||||
The Fipamo project was born from a need for a simple, easy to use no data blog platform that doesn't require much effort to set up and maintain. Fipamo uses Markdown to handle posts and renders them to flat html so you can serve them from anywhere. No complicated set ups. No long list of dependencies. Just set up and go.
|
||||
|
||||
Because nobody has time for all that.
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@ class MailerAPI
|
|||
|
||||
public static function handleMail($request, $body, $response)
|
||||
{
|
||||
//if testing, verify session is active
|
||||
if ($body["mail_task"] == "TESTING") {
|
||||
// if testing, verify session is active
|
||||
// add clean method for sending programmtic emails
|
||||
if ($body['mail_task'] == 'TESTING') {
|
||||
if (Session::active()) {
|
||||
$result = Mailer::sendmail($body);
|
||||
} else {
|
||||
$result = [
|
||||
"message" => "You need to be logged in for this, champ.",
|
||||
"type" => "MAILER_ERROR",
|
||||
'message' => 'You need to be logged in for this, champ.',
|
||||
'type' => 'MAILER_ERROR',
|
||||
];
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
|
||||
namespace brain\init;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use brain\utility\HandleCors;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Slim\Views\Twig;
|
||||
use Slim\Views\TwigMiddleware;
|
||||
// Fipamo Core Classes
|
||||
use brain\utility\HandleCors;
|
||||
use Slim\Views\TwigMiddleware;
|
||||
|
||||
class App
|
||||
{
|
||||
|
@ -18,18 +16,18 @@ class App
|
|||
// set up cors
|
||||
new HandleCors();
|
||||
$app = AppFactory::create();
|
||||
$twig = Twig::create("../brain/views/");
|
||||
$twig = Twig::create('../brain/views/');
|
||||
$app->add(TwigMiddleware::create($app, $twig));
|
||||
//set up routing
|
||||
// set up routing
|
||||
$app->get(
|
||||
"/[{first}[/{second}[/{third}[/{fourth}[/{fifth}]]]]]",
|
||||
'/[{first}[/{second}[/{third}[/{fourth}[/{fifth}]]]]]',
|
||||
"brain\controller\RouteControl:get"
|
||||
);
|
||||
$app->post(
|
||||
"/[{first}[/{second}[/{third}[/{fourth}]]]]",
|
||||
'/[{first}[/{second}[/{third}[/{fourth}]]]]',
|
||||
"brain\controller\RouteControl:post"
|
||||
);
|
||||
//start the app
|
||||
// start the app
|
||||
|
||||
$app->run();
|
||||
}
|
||||
|
|
|
@ -2,34 +2,34 @@
|
|||
|
||||
namespace brain\utility;
|
||||
|
||||
use Mni\FrontYAML\Parser;
|
||||
use function _\filter;
|
||||
use function _\find;
|
||||
use brain\data\Book;
|
||||
use brain\data\Settings;
|
||||
|
||||
use function _\find;
|
||||
use function _\filter;
|
||||
use Mni\FrontYAML\Parser;
|
||||
|
||||
class Sorting
|
||||
{
|
||||
private static $_tags = [];
|
||||
private static $_archive = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function tags()
|
||||
{
|
||||
$pages = (new Book("../content/pages"))->getContents();
|
||||
$pages = (new Book('../content/pages'))->getContents();
|
||||
foreach ($pages as $page) {
|
||||
$temp = [];
|
||||
$temp = explode(",", $page["tags"]);
|
||||
$temp = explode(',', $page['tags']);
|
||||
foreach ($temp as $tag) {
|
||||
$label = trim($tag);
|
||||
if (!find(self::$_tags, ["tag_name" => $label])) {
|
||||
if (!find(self::$_tags, ['tag_name' => $label])) {
|
||||
array_push(self::$_tags, [
|
||||
"tag_name" => $label,
|
||||
"slug" => StringTools::safeString($label),
|
||||
"pages" => self::tagPages($label, $pages),
|
||||
'tag_name' => $label,
|
||||
'slug' => StringTools::safeString($label),
|
||||
'pages' => self::tagPages($label, $pages),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -42,12 +42,12 @@ class Sorting
|
|||
{
|
||||
$tagged = [];
|
||||
foreach ($pages as $page) {
|
||||
if (strpos($page["tags"], $tag) !== false) {
|
||||
if (strpos($page['tags'], $tag) !== false) {
|
||||
array_push($tagged, [
|
||||
"title" => $page["title"],
|
||||
"slug" => $page["slug"],
|
||||
"path" => $page["path"],
|
||||
"feature" => $page["feature"],
|
||||
'title' => $page['title'],
|
||||
'slug' => $page['slug'],
|
||||
'path' => $page['path'],
|
||||
'feature' => $page['feature'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -57,48 +57,49 @@ class Sorting
|
|||
|
||||
public static function archive()
|
||||
{
|
||||
$pages = (new Book("../content/pages"))->getContents();
|
||||
$pages = (new Book('../content/pages'))->getContents();
|
||||
$years = [];
|
||||
$archive = [];
|
||||
foreach ($pages as $page) {
|
||||
//$year = date("Y", date($page["rawCreated"]));
|
||||
$date = explode("/", $page["path"]);
|
||||
//echo $page["title"] . " : " . $year . "\n";
|
||||
if (!find($years, ["year" => trim($date[0])])) {
|
||||
$findPages = filter($pages, ["createdYear" => trim($date[0])]);
|
||||
//var_dump($findPages);
|
||||
// $year = date("Y", date($page["rawCreated"]));
|
||||
$date = explode('/', $page['path']);
|
||||
// echo $page["title"] . " : " . $year . "\n";
|
||||
if (!find($years, ['year' => trim($date[0])])) {
|
||||
$findPages = filter($pages, ['createdYear' => trim($date[0])]);
|
||||
// var_dump($findPages);
|
||||
array_push($years, [
|
||||
"year" => trim($date[0]),
|
||||
"count" => count($findPages),
|
||||
'year' => trim($date[0]),
|
||||
'count' => count($findPages),
|
||||
]);
|
||||
}
|
||||
}
|
||||
foreach ($years as $year) {
|
||||
$sorted = [];
|
||||
$filtered = filter($pages, ["createdYear" => $year["year"]]);
|
||||
$filtered = filter($pages, ['createdYear' => $year['year']]);
|
||||
|
||||
foreach ($filtered as $obj) {
|
||||
$month = date("m", date($obj["rawCreated"]));
|
||||
if (!find($sorted, ["month" => $month])) {
|
||||
$month = date('m', date($obj['rawCreated']));
|
||||
if (!find($sorted, ['month' => $month])) {
|
||||
$perMonth = filter($pages, [
|
||||
"path" => $year["year"] . "/" . $month,
|
||||
"deleted" => false,
|
||||
"published" => true,
|
||||
"layout" => "page",
|
||||
'path' => $year['year'].'/'.$month,
|
||||
'deleted' => false,
|
||||
'published' => true,
|
||||
'layout' => 'page',
|
||||
]);
|
||||
array_push($sorted, [
|
||||
"month" => $month,
|
||||
"full_month" => date("F", date($obj["rawCreated"])),
|
||||
"count" => count($perMonth),
|
||||
"pages" => $perMonth,
|
||||
'month' => $month,
|
||||
'full_month' => date('F', date($obj['rawCreated'])),
|
||||
'count' => count($perMonth),
|
||||
'pages' => $perMonth,
|
||||
]);
|
||||
}
|
||||
}
|
||||
array_push(self::$_archive, [
|
||||
"year" => $year["year"],
|
||||
"year_data" => $sorted,
|
||||
'year' => $year['year'],
|
||||
'year_data' => $sorted,
|
||||
]);
|
||||
}
|
||||
|
||||
return self::$_archive;
|
||||
}
|
||||
|
||||
|
@ -109,78 +110,86 @@ class Sorting
|
|||
$pageOption = [];
|
||||
|
||||
$pageInfo = [
|
||||
"keywords" => isset($settings["global"]["keywords"])
|
||||
? $settings["global"]["keywords"]
|
||||
: "fipamo, blog, jamstack, php, markdown, js",
|
||||
"description" => $settings["global"]["descriptions"],
|
||||
"image" =>
|
||||
$settings["global"]["base_url"] . $settings["global"]["background"],
|
||||
"baseURL" => $settings["global"]["base_url"],
|
||||
'keywords' => isset($settings['global']['keywords'])
|
||||
? $settings['global']['keywords']
|
||||
: 'fipamo, blog, jamstack, php, markdown, js',
|
||||
'description' => $settings['global']['descriptions'],
|
||||
'image' => $settings['global']['base_url'].$settings['global']['background'],
|
||||
'baseURL' => $settings['global']['base_url'],
|
||||
];
|
||||
|
||||
$taglist = explode(",", $page["tags"]);
|
||||
$taglist = explode(',', $page['tags']);
|
||||
$tags = [];
|
||||
foreach ($taglist as $tag) {
|
||||
$label = trim($tag);
|
||||
array_push($tags, [
|
||||
"label" => $label . " ",
|
||||
"slug" => StringTools::safeString($label),
|
||||
'label' => $label.' ',
|
||||
'slug' => StringTools::safeString($label),
|
||||
]);
|
||||
}
|
||||
|
||||
$meta = [
|
||||
"who" => $page["author"],
|
||||
"when" => $page["created"],
|
||||
"tags" => $tags,
|
||||
'who' => $page['author'],
|
||||
'when' => $page['created'],
|
||||
'tags' => $tags,
|
||||
];
|
||||
|
||||
//render markdown content and clean it
|
||||
// render markdown content and clean it
|
||||
$parser = new Parser();
|
||||
$rendered = $parser->parse($page["content"]);
|
||||
$rendered = $parser->parse($page['content']);
|
||||
$sanitizer = \HtmlSanitizer\Sanitizer::create([
|
||||
"extensions" => ["basic", "image", "list", "code"],
|
||||
"tags" => [
|
||||
"img" => [
|
||||
"allowed_attributes" => ["src", "alt", "title", "class"],
|
||||
"allowed_hosts" => null,
|
||||
'extensions' => ['basic', 'image', 'list', 'code'],
|
||||
'tags' => [
|
||||
'img' => [
|
||||
'allowed_attributes' => ['src', 'alt', 'title', 'class'],
|
||||
'allowed_hosts' => null,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$preclean = $sanitizer->sanitize($rendered->getContent());
|
||||
|
||||
//just clean renderd string for now, Sanitize doesn't like relative img urls
|
||||
//so another option is needed
|
||||
// just clean renderd string for now, Sanitize doesn't like relative img urls
|
||||
// so another option is needed
|
||||
$cleaned = strip_tags($rendered->getContent(), [
|
||||
"a",
|
||||
"br",
|
||||
"p",
|
||||
"strong",
|
||||
"br",
|
||||
"img",
|
||||
"iframe",
|
||||
"ul",
|
||||
"li",
|
||||
"i",
|
||||
"em",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"pre",
|
||||
"code",
|
||||
'a',
|
||||
'br',
|
||||
'p',
|
||||
'strong',
|
||||
'br',
|
||||
'img',
|
||||
'iframe',
|
||||
'ul',
|
||||
'li',
|
||||
'i',
|
||||
'em',
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
'pre',
|
||||
'code',
|
||||
]);
|
||||
//$cleaned = preg_replace('/(?:\r\n|[\r\n]){2,}/', "\n\n", $cleaned);
|
||||
//$cleaned = html_entity_decode($cleaned, ENT_QUOTES, "UTF-8");
|
||||
|
||||
//if page feature isn't empty, replace page info meta image
|
||||
if ($page["feature"] != "" || $page["feature"] != null) {
|
||||
$pageInfo["image"] = $pageInfo["baseURL"] . $page["feature"];
|
||||
// if page feature isn't empty, find image from list and set it as background image
|
||||
// if it is empty, just use global background
|
||||
if ($page['feature'] != '' || $page['feature'] != null) {
|
||||
$media = explode(',', $page['feature']);
|
||||
$set = false;
|
||||
foreach ($media as $file) {
|
||||
$item = trim($file);
|
||||
$ext = pathinfo($item, PATHINFO_EXTENSION);
|
||||
|
||||
if ($ext != 'mp4' && !$set) {
|
||||
$pageInfo['image'] = $pageInfo['baseURL'].$item;
|
||||
$set = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($page["layout"] == "index") {
|
||||
//$template = $this->theme . "/index.twig";
|
||||
//$location = "../public/index.html";
|
||||
//$dir = null;
|
||||
if ($page['layout'] == 'index') {
|
||||
// $template = $this->theme . "/index.twig";
|
||||
// $location = "../public/index.html";
|
||||
// $dir = null;
|
||||
|
||||
$recent = [];
|
||||
$featured = [];
|
||||
|
@ -188,26 +197,26 @@ class Sorting
|
|||
$pages = (new Book())->getContents();
|
||||
foreach ($pages as $item) {
|
||||
if (
|
||||
!$item["deleted"] &&
|
||||
$item["published"] &&
|
||||
$item["menu"] != "true"
|
||||
!$item['deleted'] &&
|
||||
$item['published'] &&
|
||||
$item['menu'] != 'true'
|
||||
) {
|
||||
if (count($recent) < $limit) {
|
||||
array_push($recent, [
|
||||
"path" => $item["path"],
|
||||
"slug" => $item["slug"],
|
||||
"title" => $item["title"],
|
||||
"feature" => $item["feature"],
|
||||
'path' => $item['path'],
|
||||
'slug' => $item['slug'],
|
||||
'title' => $item['title'],
|
||||
'feature' => $item['feature'],
|
||||
]);
|
||||
}
|
||||
|
||||
if ($item["featured"] == true) {
|
||||
if ($item['featured'] == true) {
|
||||
if (count($featured) < $limit) {
|
||||
array_push($featured, [
|
||||
"path" => $item["path"],
|
||||
"slug" => $item["slug"],
|
||||
"title" => $item["title"],
|
||||
"feature" => $item["feature"],
|
||||
'path' => $item['path'],
|
||||
'slug' => $item['slug'],
|
||||
'title' => $item['title'],
|
||||
'feature' => $item['feature'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -215,34 +224,35 @@ class Sorting
|
|||
}
|
||||
|
||||
$pageOptions = [
|
||||
"title" => $page["title"],
|
||||
"background" => $page["feature"],
|
||||
"content" => $page["html"], //$cleaned,
|
||||
"meta" => $meta,
|
||||
"recent" => $recent,
|
||||
"featured" => $featured,
|
||||
"info" => $pageInfo,
|
||||
"menu" => $settings["menu"],
|
||||
"dynamicRender" => $settings["global"]["dynamicRender"],
|
||||
"media" => $page["media"],
|
||||
"files" => $page["docs"],
|
||||
'title' => $page['title'],
|
||||
'background' => $page['feature'],
|
||||
'content' => $page['html'], // $cleaned,
|
||||
'meta' => $meta,
|
||||
'recent' => $recent,
|
||||
'featured' => $featured,
|
||||
'info' => $pageInfo,
|
||||
'menu' => $settings['menu'],
|
||||
'dynamicRender' => $settings['global']['dynamicRender'],
|
||||
'media' => $page['media'],
|
||||
'files' => $page['docs'],
|
||||
];
|
||||
} else {
|
||||
//$template = $this->theme . "/page.twig";
|
||||
//$location = "../public/" . $page["path"] . "/" . $page["slug"] . ".html";
|
||||
//$dir = "../public/" . $page["path"];
|
||||
// $template = $this->theme . "/page.twig";
|
||||
// $location = "../public/" . $page["path"] . "/" . $page["slug"] . ".html";
|
||||
// $dir = "../public/" . $page["path"];
|
||||
$pageOptions = [
|
||||
"title" => $page["title"],
|
||||
"background" => $page["feature"],
|
||||
"content" => $page["html"], //$cleaned,
|
||||
"meta" => $meta,
|
||||
"info" => $pageInfo,
|
||||
"menu" => $settings["menu"],
|
||||
"dynamicRender" => $settings["global"]["dynamicRender"],
|
||||
"media" => $page["media"],
|
||||
"files" => $page["docs"],
|
||||
'title' => $page['title'],
|
||||
'background' => $page['feature'],
|
||||
'content' => $page['html'], // $cleaned,
|
||||
'meta' => $meta,
|
||||
'info' => $pageInfo,
|
||||
'menu' => $settings['menu'],
|
||||
'dynamicRender' => $settings['global']['dynamicRender'],
|
||||
'media' => $page['media'],
|
||||
'files' => $page['docs'],
|
||||
];
|
||||
}
|
||||
|
||||
return $pageOptions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"brain\\":"brain"
|
||||
"brain\\": "brain"
|
||||
}
|
||||
},
|
||||
"support": {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
require "../vendor/autoload.php";
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
use brain\init\App as App;
|
||||
use brain\init\App;
|
||||
|
||||
new App();
|
||||
|
|
Loading…
Reference in a new issue