-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from svandragt/feature/reintegrate-blog
Feature/reintegrate blog
- Loading branch information
Showing
51 changed files
with
1,114 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ Desktop.ini | |
Thumbs.db | ||
_cache/ | ||
_logs/ | ||
src/content/ | ||
|
||
src/info.php | ||
vendor/ | ||
/content/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
)); | ||
} | ||
} |
Oops, something went wrong.