/var/www/technexus/views/blog/post.twig
{% extends "blog/layouts/design.twig" %}
{% block title %}{{BlogPost.Title}} | {{ parent() }}{% endblock %}
{% block description %}{{ BlogPost.MainContent | replace({'\n':" ",'\t':" "}) | striptags | trim | slice(0,255) }}{% endblock %}
{% block meta %}
<meta property="og:title" content="{{ BlogPost.Title }}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="{{ BlogPost.ExternalPermaLink }}" />
<meta property="og:image" content="{{ BlogPost.ShareImage}}" />
<meta content='article' property='og:type'/>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@0xAkuKun">
<meta name="twitter:creator" content="@0xAkuKun">
<meta name="twitter:title" content="{{ BlogPost.Title }}">
<meta name="twitter:description" content="{{ BlogPost.MainContent | replace({'\n':" ",'\t':" "}) | striptags | trim | slice(0,255) }}">
<meta name="twitter:image" content="{{ BlogPost.ShareImage}} ">
{% endblock %}
{% block content %}
{% include 'blog/templates/post.twig' %}
{% endblock %}
Arguments
"An exception has been thrown during the rendering of a template ("Undefined array key 1")."
/var/www/technexus/src/Models/BlogPost.php
{
return $this->getPermaLink();
}
public function getExternalPermaLink()
{
return $this->getPermaLink(true);
}
/**
* Quick and dirty
* TODO: Change admin to let you select this image
*
* @return string|false
*/
public function getShareImage()
{
preg_match("/\/media\/([0-9]*)/", $this->getValue('MainContent'), $images);
if (ctype_digit($images[1])) {
return 'https://'.$_SERVER['SERVER_NAME'].'/media/thumbnail/'.$images[1].'/500x500/cropped/';
} else {
return false;
}
}
public function saveTags($tags)
{
$SeenTags = [];
foreach ($tags as $tag) {
if (!$Tag = Tag::getByField('Tag', $tag)) {
$Tag = Tag::create([
'Tag' => $tag,
'Slug' => strtolower($tag),
], true);
}
$SeenTags[] = $Tag->getPrimaryKeyValue();
Arguments
/var/www/technexus/src/Models/BlogPost.php
{
return $this->getPermaLink();
}
public function getExternalPermaLink()
{
return $this->getPermaLink(true);
}
/**
* Quick and dirty
* TODO: Change admin to let you select this image
*
* @return string|false
*/
public function getShareImage()
{
preg_match("/\/media\/([0-9]*)/", $this->getValue('MainContent'), $images);
if (ctype_digit($images[1])) {
return 'https://'.$_SERVER['SERVER_NAME'].'/media/thumbnail/'.$images[1].'/500x500/cropped/';
} else {
return false;
}
}
public function saveTags($tags)
{
$SeenTags = [];
foreach ($tags as $tag) {
if (!$Tag = Tag::getByField('Tag', $tag)) {
$Tag = Tag::create([
'Tag' => $tag,
'Slug' => strtolower($tag),
], true);
}
$SeenTags[] = $Tag->getPrimaryKeyValue();
/var/www/technexus/vendor/twig/twig/src/Extension/CoreExtension.php
if ($ignoreStrictCheck || !$env->isStrictVariables()) {
return;
}
throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()"/"has%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), $lineno, $source);
}
if ($isDefinedTest) {
return true;
}
if ($sandboxed) {
$env->getExtension(SandboxExtension::class)->checkMethodAllowed($object, $method, $lineno, $source);
}
// Some objects throw exceptions when they have __call, and the method we try
// to call is not supported. If ignoreStrictCheck is true, we should return null.
try {
$ret = $object->$method(...$arguments);
} catch (\BadMethodCallException $e) {
if ($call && ($ignoreStrictCheck || !$env->isStrictVariables())) {
return;
}
throw $e;
}
return $ret;
}
/**
* Returns the values from a single column in the input array.
*
* <pre>
* {% set items = [{ 'fruit' : 'apple'}, {'fruit' : 'orange' }] %}
*
* {% set fruits = items|column('fruit') %}
*
* {# fruits now contains ['apple', 'orange'] #}
* </pre>
/var/www/technexus/vendor/twig/twig/src/Environment.php
$key = $this->cache->generateKey($name, $mainCls);
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
$this->cache->load($key);
}
$source = null;
if (!class_exists($cls, false)) {
$source = $this->getLoader()->getSourceContext($name);
$content = $this->compileSource($source);
$this->cache->write($key, $content);
$this->cache->load($key);
if (!class_exists($mainCls, false)) {
/* Last line of defense if either $this->bcWriteCacheFile was used,
* $this->cache is implemented as a no-op or we have a race condition
* where the cache was cleared between the above calls to write to and load from
* the cache.
*/
eval('?>'.$content);
}
if (!class_exists($cls, false)) {
throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source);
}
}
}
$this->extensionSet->initRuntime();
return $this->loadedTemplates[$cls] = new $cls($this);
}
/**
* Creates a template from source.
*
* This method should not be used as a generic way to load templates.
*
* @param string $template The template source
* @param string $name An optional name of the template to be used in error messages
/var/www/technexus/vendor/twig/twig/src/Template.php
{
if ($useBlocks && isset($blocks[$name])) {
$template = $blocks[$name][0];
$block = $blocks[$name][1];
} elseif (isset($this->blocks[$name])) {
$template = $this->blocks[$name][0];
$block = $this->blocks[$name][1];
} else {
$template = null;
$block = null;
}
// avoid RCEs when sandbox is enabled
if (null !== $template && !$template instanceof self) {
throw new \LogicException('A block must be a method on a \Twig\Template instance.');
}
if (null !== $template) {
try {
$template->$block($context, $blocks);
} catch (Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($template->getSourceContext());
}
// this is mostly useful for \Twig\Error\LoaderError exceptions
// see \Twig\Error\LoaderError
if (-1 === $e->getTemplateLine()) {
$e->guess();
}
throw $e;
} catch (\Exception $e) {
$e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e);
$e->guess();
throw $e;
}
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this);
/var/www/technexus/vendor/twig/twig/src/Environment.php
$key = $this->cache->generateKey($name, $mainCls);
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
$this->cache->load($key);
}
$source = null;
if (!class_exists($cls, false)) {
$source = $this->getLoader()->getSourceContext($name);
$content = $this->compileSource($source);
$this->cache->write($key, $content);
$this->cache->load($key);
if (!class_exists($mainCls, false)) {
/* Last line of defense if either $this->bcWriteCacheFile was used,
* $this->cache is implemented as a no-op or we have a race condition
* where the cache was cleared between the above calls to write to and load from
* the cache.
*/
eval('?>'.$content);
}
if (!class_exists($cls, false)) {
throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source);
}
}
}
$this->extensionSet->initRuntime();
return $this->loadedTemplates[$cls] = new $cls($this);
}
/**
* Creates a template from source.
*
* This method should not be used as a generic way to load templates.
*
* @param string $template The template source
* @param string $name An optional name of the template to be used in error messages
/var/www/technexus/vendor/twig/twig/src/Template.php
} else {
ob_start(function () { return ''; });
}
try {
$this->display($context);
} catch (\Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = [])
{
try {
$this->doDisplay($context, $blocks);
} catch (Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
// this is mostly useful for \Twig\Error\LoaderError exceptions
// see \Twig\Error\LoaderError
if (-1 === $e->getTemplateLine()) {
$e->guess();
}
throw $e;
} catch (\Exception $e) {
$e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
$e->guess();
throw $e;
}
}
/var/www/technexus/vendor/twig/twig/src/Template.php
{
return $this;
}
/**
* Returns all blocks.
*
* This method is for internal use only and should never be called
* directly.
*
* @return array An array of blocks
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = [])
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
if ($this->env->isDebug()) {
ob_start();
} else {
ob_start(function () { return ''; });
}
try {
$this->display($context);
} catch (\Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
/var/www/technexus/vendor/twig/twig/src/Environment.php
$key = $this->cache->generateKey($name, $mainCls);
if (!$this->isAutoReload() || $this->isTemplateFresh($name, $this->cache->getTimestamp($key))) {
$this->cache->load($key);
}
$source = null;
if (!class_exists($cls, false)) {
$source = $this->getLoader()->getSourceContext($name);
$content = $this->compileSource($source);
$this->cache->write($key, $content);
$this->cache->load($key);
if (!class_exists($mainCls, false)) {
/* Last line of defense if either $this->bcWriteCacheFile was used,
* $this->cache is implemented as a no-op or we have a race condition
* where the cache was cleared between the above calls to write to and load from
* the cache.
*/
eval('?>'.$content);
}
if (!class_exists($cls, false)) {
throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache might be corrupted.', $name, $index), -1, $source);
}
}
}
$this->extensionSet->initRuntime();
return $this->loadedTemplates[$cls] = new $cls($this);
}
/**
* Creates a template from source.
*
* This method should not be used as a generic way to load templates.
*
* @param string $template The template source
* @param string $name An optional name of the template to be used in error messages
/var/www/technexus/vendor/twig/twig/src/Template.php
} else {
ob_start(function () { return ''; });
}
try {
$this->display($context);
} catch (\Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = [])
{
try {
$this->doDisplay($context, $blocks);
} catch (Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
// this is mostly useful for \Twig\Error\LoaderError exceptions
// see \Twig\Error\LoaderError
if (-1 === $e->getTemplateLine()) {
$e->guess();
}
throw $e;
} catch (\Exception $e) {
$e = new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e);
$e->guess();
throw $e;
}
}
/var/www/technexus/vendor/twig/twig/src/Template.php
{
return $this;
}
/**
* Returns all blocks.
*
* This method is for internal use only and should never be called
* directly.
*
* @return array An array of blocks
*/
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = [])
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
if ($this->env->isDebug()) {
ob_start();
} else {
ob_start(function () { return ''; });
}
try {
$this->display($context);
} catch (\Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
/var/www/technexus/vendor/twig/twig/src/Template.php
public function getBlocks()
{
return $this->blocks;
}
public function display(array $context, array $blocks = [])
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
public function render(array $context)
{
$level = ob_get_level();
if ($this->env->isDebug()) {
ob_start();
} else {
ob_start(function () { return ''; });
}
try {
$this->display($context);
} catch (\Throwable $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return ob_get_clean();
}
protected function displayWithErrorHandling(array $context, array $blocks = [])
{
try {
$this->doDisplay($context, $blocks);
} catch (Error $e) {
if (!$e->getSourceContext()) {
$e->setSourceContext($this->getSourceContext());
}
/var/www/technexus/vendor/twig/twig/src/TemplateWrapper.php
private $env;
private $template;
/**
* This method is for internal use only and should never be called
* directly (use Twig\Environment::load() instead).
*
* @internal
*/
public function __construct(Environment $env, Template $template)
{
$this->env = $env;
$this->template = $template;
}
public function render(array $context = []): string
{
// using func_get_args() allows to not expose the blocks argument
// as it should only be used by internal code
return $this->template->render($context, \func_get_args()[1] ?? []);
}
public function display(array $context = [])
{
// using func_get_args() allows to not expose the blocks argument
// as it should only be used by internal code
$this->template->display($context, \func_get_args()[1] ?? []);
}
public function hasBlock(string $name, array $context = []): bool
{
return $this->template->hasBlock($name, $context);
}
/**
* @return string[] An array of defined template block names
*/
public function getBlockNames(array $context = []): array
{
return $this->template->getBlockNames($context);
/var/www/technexus/vendor/twig/twig/src/Environment.php
*/
public function getTemplateClass(string $name, int $index = null): string
{
$key = $this->getLoader()->getCacheKey($name).$this->optionsHash;
return $this->templateClassPrefix.hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $key).(null === $index ? '' : '___'.$index);
}
/**
* Renders a template.
*
* @param string|TemplateWrapper $name The template name
*
* @throws LoaderError When the template cannot be found
* @throws SyntaxError When an error occurred during compilation
* @throws RuntimeError When an error occurred during rendering
*/
public function render($name, array $context = []): string
{
return $this->load($name)->render($context);
}
/**
* Displays a template.
*
* @param string|TemplateWrapper $name The template name
*
* @throws LoaderError When the template cannot be found
* @throws SyntaxError When an error occurred during compilation
* @throws RuntimeError When an error occurred during rendering
*/
public function display($name, array $context = []): void
{
$this->load($name)->display($context);
}
/**
* Loads a template.
*
* @param string|TemplateWrapper $name The template name
/var/www/technexus/vendor/divergence/divergence/src/Responders/TwigBuilder.php
namespace Divergence\Responders;
use Divergence\App;
use Twig\Environment;
use GuzzleHttp\Psr7\Utils;
use Twig\Loader\FilesystemLoader;
use Psr\Http\Message\StreamInterface;
use Twig\Extension\StringLoaderExtension;
class TwigBuilder extends ResponseBuilder
{
protected string $contentType = 'text/html; charset=utf-8';
public function getBody(): StreamInterface
{
$loader = new FilesystemLoader([App::$App->ApplicationPath.'/views']);
$env = new Environment($loader, ['strict_variables' => true]);
$env->addExtension(new StringLoaderExtension());
$output = $env->render($this->template, $this->data);
return Utils::streamFor($output);
}
}
/var/www/technexus/vendor/divergence/divergence/src/Responders/Response.php
505 => 'HTTP Version not supported',
506 => 'Variant Also Negotiates',
507 => 'Insufficient Storage',
508 => 'Loop Detected',
510 => 'Not Extended',
511 => 'Network Authentication Required',
];
/** @var string */
private $reasonPhrase;
/** @var int */
private $statusCode;
public function __construct(ResponseBuilder $responseBuilder)
{
$this
->withDefaults(200, [
'Content-Type' => $responseBuilder->getContentType(),
], $responseBuilder->getBody());
}
/**
* @param int $status Status code
* @param array<string, string|string[]> $headers Response headers
* @param string|resource|StreamInterface|null $body Response body
* @param string $version Protocol version
* @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
* @return static
*/
public function withDefaults(
int $status = 200,
array $headers = [],
$body = null,
string $version = '1.1',
string $reason = null
) {
$this->assertStatusCodeRange($status);
$this->statusCode = $status;
/var/www/technexus/src/Controllers/Blog.php
/**
* Displays a blog post
*
* @param string $year
* @param string $month
* @param string $permalink
* @link project://views/blog/post.twig
* @link project://views/templates/post.twig
* @return Response
*/
public function post($year, $month, $permalink): Response
{
$BlogPost = BlogPost::getByWhere(array_merge($this->conditions(), [
sprintf('YEAR(`Created`)=%d', $year),
sprintf('MONTH(`Created`)=%d', $month),
"`permalink`='".DB::escape($permalink)."'",
]));
if (!empty($BlogPost)) {
return new Response(new TwigBuilder('blog/post.twig', [
'BlogPost' => $BlogPost,
'isLoggedIn' => App::$App->is_loggedin(),
'Sidebar' => $this->getSidebarData(),
'Limit' => static::LIMIT,
'Total' => DB::foundRows(),
]));
} else {
return $this->notFound();
}
}
/**
* Shows 404 page
*
* @return Response
*/
public function notFound(): Response
{
/var/www/technexus/src/Controllers/Blog.php
}
// month of posts
if (ctype_digit($this->peekPath()) && strlen($this->peekPath()) == 2) {
$month = $this->shiftPath();
}
// single post
$permalink = $this->peekPath()?$this->shiftPath():null;
// yearly digest
if (empty($permalink) && empty($month)) {
return $this->year($year);
}
// monthly digest
if (empty($permalink)) {
return $this->month($year, $month);
}
// specific single post
return $this->post($year, $month, $permalink??null);
default:
return $this->notfound();
}
}
/**
* Gets stuff that goes into the sidebar. All Months with blog posts and tags ordered by the amount of times that tag was used.
*
* @link project://views/blog/sidebar.twig
* @return array
*/
public function getSidebarData()
{
return [
'Months' => DB::AllRecords(sprintf('SELECT DISTINCT MONTHNAME(`Created`) as `MonthName`,MONTH(`Created`) as `Month`, YEAR(`Created`) as `Year` FROM `%s` ORDER BY `Created` DESC', BlogPost::$tableName)),
'Tags' => PostTags::getAllbyQuery('SELECT *,COUNT(*) as `Count` FROM `'.PostTags::$tableName.'` GROUP BY `TagID` ORDER BY `Count` DESC'),
];
}
/var/www/technexus/src/Controllers/Main.php
* @uses Blog::handleRequest()
* @return void
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/site.LOCK')) {
echo file_get_contents($_SERVER['DOCUMENT_ROOT'].'/down.html');
exit;
}
/*
* This is to make sure any page that loads
* through Apache's ErrorDocument returns 200
* instead of 404.
*/
header('HTTP/1.0 200 OK');
//header('X-Powered-By: PHP/' . phpversion() . ' Div Framework (http://emr.ge) Henry\'s Revision');
$blog = new Blog();
return $blog->handle($request);
}
}
/var/www/technexus/src/App.php
return true;
}
}
return false;
}
/**
* Gets difference between process start and now in microseconds.
*
* @return void
*/
public function getLoadTime()
{
return (microtime(true)-DIVERGENCE_START);
}
public function handleRequest()
{
$main = new Main();
$response = $main->handle(ServerRequest::fromGlobals());
(new Emitter($response))->emit();
}
}
/var/www/technexus/bootstrap/router.php
<?php
/**
* This file is part of the Divergence package.
*
* (c) Henry Paradiz <henry.paradiz@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
$app->handleRequest();
/var/www/technexus/public/index.php
<?php
require(__DIR__.'/../bootstrap/autoload.php');
require(__DIR__.'/../bootstrap/app.php');
require(__DIR__.'/../bootstrap/router.php');
Arguments
"/var/www/technexus/bootstrap/router.php"