Skip to content

Commit

Permalink
Merge pull request #99 from svandragt/feature/reintegrate-blog
Browse files Browse the repository at this point in the history
Feature/reintegrate blog
  • Loading branch information
svandragt authored Oct 1, 2020
2 parents b15940b + d4397d4 commit f1cf53f
Show file tree
Hide file tree
Showing 51 changed files with 1,114 additions and 153 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Desktop.ini
Thumbs.db
_cache/
_logs/
src/content/

src/info.php
vendor/
/content/
12 changes: 12 additions & 0 deletions Configuration.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
if (!defined('BASE_FILEPATH'))
{
exit('No direct script access allowed');
}

class Configuration extends Cuttlefish\Defaults
{
const SITE_TITLE = 'Your site';
const SITE_MOTTO = 'Example theme of <a href="https://vandragt.com/tag/cuttlefish/">Cuttlefish</a>, the hackable web framework.';
const CACHE_ENABLED = FALSE;
}
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"autoload": {
"psr-4": {
"Cuttlefish\\": "src",
"Cuttlefish\\Blog\\": "src/blog"
"Cuttlefish\\": "src/system",
"Cuttlefish\\Blog\\": "src/application"
}
},
"config": {
Expand All @@ -30,19 +30,26 @@
}
},
"scripts": {
"post-create-project-cmd": [
"@setup"
],
"setup": [
"composer install --ansi",
"phive install"
"phive install",
"php -r \"copy('src/Configuration.php.dist', 'src/Configuration.php');\""
],
"prep": [
"phpcbf",
"psalm --alter",
"psalm --alter --issues=all",
"@lint"
],
"lint": [
"find . -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v 'No syntax errors detected' )",
"psalm --show-info=true; exit 0",
"phpcs"
],
"serve": [
"export $(cat .env | xargs) && php -S localhost:8080 -t src/"
]
}
}
}
29 changes: 19 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<phive xmlns="https://phar.io/phive">
<phar name="phpcs" version="^3.5.4" installed="3.5.5" location="./vendor/bin/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.5.4" installed="3.5.5" location="./vendor/bin/phpcbf" copy="false"/>
<phar name="vimeo/psalm" version="^3.9.3" installed="3.12.2" location="./vendor/bin/psalm" copy="false"/>
<phar name="vimeo/psalm" version="^3.9.3" installed="3.9.3" location="./vendor/bin/psalm" copy="false"/>
</phive>
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Cuttlefish
Cuttlefish is a PHP based hackable blog framework.
Cuttlefish is a PHP based opinionated blog framework.

_It should be considered work in progress._

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/svandragt/cuttlefish/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/svandragt/cuttlefish/?branch=master)

## Aims

* Fast.
* Easy to adopt.
* Hackable.
* Easily understood.
* Accommodating defaults.
* Adaptable to your needs.
* Code over Configuration

![Cuttlefish screenshot](https://vandragt.com/file/d97a82559947ebc1f195213a751c52f0/Screenshot+from+2020-03-03+08-34-26.png)

Expand Down
13 changes: 0 additions & 13 deletions src/Security.php

This file was deleted.

115 changes: 115 additions & 0 deletions src/application/ControllerAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Cuttlefish\Blog;

use Cuttlefish\Controller;
use Cuttlefish\Html;
use Cuttlefish\Url;

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 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
{
global $App;

return $App->Security->login();
}

protected function clearCache()
{
global $App;
$App->Security->maybeLoginRedirect();

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

protected function generateSite(): void
{
global $App;

$App->Security->maybeLoginRedirect();
echo $App->Cache->generateSite();
}


/**
* @return void
*/
public function init()
{
global $App;
$App->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
{
global $App;
if ($App->Security->isLoggedIn()) {
return $this->showTasks();
}

return $this->showLogin();
}

public function logout()
{
global $App;

$App->Security->maybeLoginRedirect();

return $App->Security->logout();
}
}
42 changes: 42 additions & 0 deletions src/application/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 . '/post';
$Files = new Files($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',
));
}
}
Loading

0 comments on commit f1cf53f

Please sign in to comment.