Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/reintegrate-blog
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	composer.lock
#	src/system/Environment.php
#	src/system/Router.php
#	src/system/Template.php
  • Loading branch information
svandragt committed Oct 1, 2020
2 parents e3acaa5 + b15940b commit d4397d4
Show file tree
Hide file tree
Showing 21 changed files with 564 additions and 18 deletions.
16 changes: 16 additions & 0 deletions decisionlog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ADR

An Architectural Decision (AD) is a software design choice that addresses a functional or non-functional requirement that is architecturally significant. An Architecturally Significant Requirement (ASR) is a requirement that has a measurable effect on a software system’s architecture and quality. An Architectural Decision Record (ADR) captures a single AD, such as often done when writing personal notes or meeting minutes; the collection of ADRs created and maintained in a project constitute its decision log. All these are within the topic of Architectural Knowledge Management (AKM).

## Overall goals

A) Strive to simplify.
B) Everyone contributes.


# Decision Record

Decision IDs are auto incremented. IDs not in the document no longer apply.

- 003 Cuttlefish only generates static websites.
- 004 A content project consists of content assets and a php configuration file. All other code is in this project.
109 changes: 109 additions & 0 deletions src/blog/ControllerAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace Cuttlefish\Blog;

use Cuttlefish\Controller;
use Cuttlefish\Html;
use Cuttlefish\App;

class ControllerAdmin extends Controller
{
public array $allowed_methods = array(
'index' => 'Overview',
'clearCache' => 'Clear cache',
'generateSite' => 'Generate static site',
'logout' => 'Logout',
);

// admin section does not use content files
protected string $contents;

protected function isAllowedMethod($action): bool
{
return array_key_exists($action, $this->allowed_methods);
}

protected function showTasks(): string
{
$output = '<ul>';
$am = $this->allowed_methods;
array_shift($am);
foreach ($am as $key => $value) :
$Url = new Cuttlefish\Url("/admin/$key");
$output .= sprintf('<li><a href="%s">%s</a></li>', $Url->url_absolute, $value);
endforeach;

$output .= '</ul>';

return $output;
}

protected function showLogin(): string
{
return App::getInstance()->Security->login();
}

protected function clearCache()
{
$App = App::getInstance();
$App->Security->maybeLoginRedirect();

return $App->Cache->clear();
}

protected function generateSite(): void
{
$App = App::getInstance();
$App->Security->maybeLoginRedirect();
echo $App->Cache->generateSite();
}


/**
* @return void
*/
public function init()
{
App::getInstance()->Cache->abort();

$action = ( isset($this->args[0]) ) ? $this->args[0] : 'index';
if ($this->isAllowedMethod($action)) {
$this->contents = $this->$action();
} else {
exit("Method $action is not allowed");
}

parent::init();
}

/**
* @return void
*/
public function view()
{
parent::view();

$this->View = new Html($this->contents, array(
'layout' => 'layout.php',
'controller' => 'admin',
'model' => 'page',
));
}

public function index(): string
{
if (App::getInstance()->Security->isLoggedIn()) {
return $this->showTasks();
}

return $this->showLogin();
}

public function logout()
{
$App = App::getInstance();
$App->Security->maybeLoginRedirect();

return $App->Security->logout();
}
}
42 changes: 42 additions & 0 deletions src/blog/ControllerArchive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Cuttlefish\Blog;

use Configuration;
use Cuttlefish\Controller;
use Cuttlefish\Files;
use Cuttlefish\Html;

class ControllerArchive extends Controller
{
/**
* @return void
*/
public function records()
{
$content_dir = Configuration::CONTENT_FOLDER . '/posts';
$Files = new Files(array( 'url' => $content_dir ), $this->ext);
$this->records = $Files->files();
}

/**
* @return void
*/
public function model()
{
$this->Model = new ModelPost($this->records);
}

/**
* @return void
*/
public function view()
{
parent::view();
$this->View = new Html($this->Model->contents, array(
'layout' => 'layout.php',
'controller' => 'archive',
'model' => 'post',
));
}
}
45 changes: 45 additions & 0 deletions src/blog/ControllerError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Cuttlefish\Blog;

use Configuration;
use Cuttlefish\Controller;
use Cuttlefish\Filesystem;
use Cuttlefish\Html;

class ControllerError extends Controller
{
// single errors page

/**
* @return void
*/
public function records()
{
$content_dir = Configuration::CONTENT_FOLDER . '/errors/';
$url = $content_dir . implode("/", $this->args) . '.' . $this->ext;
$this->records = [ Filesystem::convertUrlToPath($url) ];
}

/**
* @return void
*/
public function model()
{
$this->Model = new ModelPage($this->records);
}

/**
* @return void
*/
public function view()
{
parent::view();

$this->View = new Html($this->Model->contents, array(
'layout' => 'layout.php',
'controller' => 'errors',
'model' => 'page',
));
}
}
41 changes: 41 additions & 0 deletions src/blog/ControllerFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Cuttlefish\Blog;

use Configuration;
use Cuttlefish\Controller;
use Cuttlefish\Feed;
use Cuttlefish\Files;

class ControllerFeed extends Controller
{
// single feed
/**
* @return void
*/
public function records()
{
$limit = Configuration::POSTS_HOMEPAGE;
$content_dir = Configuration::CONTENT_FOLDER . '/posts';
$Records = new Files(array( 'url' => $content_dir ), $this->ext);
$this->records = $Records->limit($limit + 5);
}

/**
* @return void
*/
public function model()
{
$Model = new ModelPost($this->records);
$this->Model = $Model->limit(10);
}

/**
* @return void
*/
public function view()
{
parent::view();
$this->View = new Feed($this->Model->contents);
}
}
45 changes: 45 additions & 0 deletions src/blog/ControllerHome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Cuttlefish\Blog;

use Configuration;
use Cuttlefish\Controller;
use Cuttlefish\Files;
use Cuttlefish\Html;

class ControllerHome extends Controller
{
// list of recent posts
/**
* @return void
*/
public function records()
{
$limit = Configuration::POSTS_HOMEPAGE;
$content_dir = Configuration::CONTENT_FOLDER . '/posts';
$Files = new Files(array( 'url' => $content_dir ), $this->ext);
$this->records = $Files->limit($limit + 5);
}

/**
* @return void
*/
public function model()
{
$Model = new ModelPost($this->records);
$this->Model = $Model->limit(Configuration::POSTS_HOMEPAGE);
}

/**
* @return void
*/
public function view()
{
parent::view();
$this->View = new Html($this->Model->contents, array(
'layout' => 'layout.php',
'controller' => 'home',
'model' => 'post',
));
}
}
39 changes: 39 additions & 0 deletions src/blog/ControllerImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Cuttlefish\Blog;

use Configuration;
use Cuttlefish\Controller;
use Cuttlefish\File;
use Cuttlefish\Filesystem;

// single image
class ControllerImage extends Controller
{
/**
* @return void
*/
public function records()
{
$content_dir = Configuration::CONTENT_FOLDER . '/images/';
$this->records = [ Filesystem::convertUrlToPath($content_dir . implode('/', $this->args)) ];
}

/**
* @return void
*/
public function model()
{
$this->Model = new ModelFile($this->records);
}

/**
* @return void
*/
public function view()
{
parent::view();
$this->View = new File($this->Model->contents[0]);
$this->View->render();
}
}
44 changes: 44 additions & 0 deletions src/blog/ControllerPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Cuttlefish\Blog;

use Configuration;
use Cuttlefish\Controller;
use Cuttlefish\Filesystem;
use Cuttlefish\Html;

// single page
class ControllerPage extends Controller
{
/**
* @return void
*/
public function records()
{
$content_dir = Configuration::CONTENT_FOLDER . '/pages/';
$url = $content_dir . implode('/', $this->args) . '.' . $this->ext;
$this->records = [ Filesystem::convertUrlToPath($url) ];
}

/**
* @return void
*/
public function model()
{
$this->Model = new ModelPage($this->records);
}

/**
* @return void
*/
public function view()
{
parent::view();

$this->View = new Html($this->Model->contents, array(
'layout' => 'layout.php',
'controller' => 'pages',
'model' => 'page',
));
}
}
Loading

0 comments on commit d4397d4

Please sign in to comment.