diff --git a/composer.json b/composer.json index 70bd80d..9d59cb0 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "name": "svandragt/cuttlefish", "description": "Hackable web framework.", - "type": "project", + "type": "library", + "version": "0.4.2", "license": "MIT", "authors": [ { @@ -19,8 +20,7 @@ }, "autoload": { "psr-4": { - "": "src/application/", - "Cuttlefish\\": "src/system/" + "Cuttlefish\\": "src" } }, "config": { @@ -45,4 +45,4 @@ "phpcs" ] } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 55f1140..6ba9079 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b9892f199f8c22d4091142b17994fc43", + "content-hash": "c6cc4bd465abda8869a07d4c1307414e", "packages": [ { "name": "michelf/php-markdown", diff --git a/src/system/App.php b/src/App.php similarity index 81% rename from src/system/App.php rename to src/App.php index 5201414..6461eee 100644 --- a/src/system/App.php +++ b/src/App.php @@ -7,9 +7,11 @@ class App public $Security; public $Cache; public $Environment; + public $app_namespace; - public function __construct() + public function __construct($app_namespace = '') { + $this->app_namespace = $app_namespace; $this->Cache = new Cache(); if ($this->Cache->hasExistingCachefile()) { $bytes = readfile($this->Cache->convertUrlpathToFilepath()); @@ -32,7 +34,7 @@ public function run() // Process request if not statically cached. $this->Cache->start(); - new Request(); + new Request($this->app_namespace); $this->Cache->end(); } } diff --git a/src/system/Cache.php b/src/Cache.php similarity index 100% rename from src/system/Cache.php rename to src/Cache.php diff --git a/src/Configuration.php.dist b/src/Configuration.php.dist deleted file mode 100644 index e8fc864..0000000 --- a/src/Configuration.php.dist +++ /dev/null @@ -1,18 +0,0 @@ -Cuttlefish, the hackable web framework.'; - const CACHE_ENABLED = FALSE; - - // const INDEX_PAGE = '/index.php'; - - // support port forwarding where local HTTP_HOST is different from developer (eg vagrant) - // const SERVER_HTTP_HOST = 'localhost'; -} \ No newline at end of file diff --git a/src/system/Controller.php b/src/Controller.php similarity index 100% rename from src/system/Controller.php rename to src/Controller.php diff --git a/src/system/Curl.php b/src/Curl.php similarity index 100% rename from src/system/Curl.php rename to src/Curl.php diff --git a/src/system/Defaults.php b/src/Defaults.php similarity index 92% rename from src/system/Defaults.php rename to src/Defaults.php index dd9d995..8a581ee 100644 --- a/src/system/Defaults.php +++ b/src/Defaults.php @@ -18,7 +18,7 @@ class Defaults public const HOME_PAGE = '/home'; public const APPLICATION_FOLDER = 'application'; public const CACHE_FOLDER = '../_cache'; - public const CONTENT_FOLDER = 'content'; + public const CONTENT_FOLDER = '../content'; public const LOGS_FOLDER = '../_logs'; public const THEMES_FOLDER = 'themes'; } diff --git a/src/system/Environment.php b/src/Environment.php similarity index 100% rename from src/system/Environment.php rename to src/Environment.php diff --git a/src/system/Feed.php b/src/Feed.php similarity index 100% rename from src/system/Feed.php rename to src/Feed.php diff --git a/src/system/File.php b/src/File.php similarity index 100% rename from src/system/File.php rename to src/File.php diff --git a/src/system/Files.php b/src/Files.php similarity index 100% rename from src/system/Files.php rename to src/Files.php diff --git a/src/system/Filesystem.php b/src/Filesystem.php similarity index 100% rename from src/system/Filesystem.php rename to src/Filesystem.php diff --git a/src/system/Html.php b/src/Html.php similarity index 100% rename from src/system/Html.php rename to src/Html.php diff --git a/src/system/Http.php b/src/Http.php similarity index 100% rename from src/system/Http.php rename to src/Http.php diff --git a/src/system/Log.php b/src/Log.php similarity index 100% rename from src/system/Log.php rename to src/Log.php diff --git a/src/system/MetadataReader.php b/src/MetadataReader.php similarity index 100% rename from src/system/MetadataReader.php rename to src/MetadataReader.php diff --git a/src/system/Model.php b/src/Model.php similarity index 100% rename from src/system/Model.php rename to src/Model.php diff --git a/src/system/Request.php b/src/Request.php similarity index 92% rename from src/system/Request.php rename to src/Request.php index d3c5ed7..20bf3d3 100644 --- a/src/system/Request.php +++ b/src/Request.php @@ -15,12 +15,15 @@ class Request { protected $Controller; - public function __construct() + public function __construct($app_namespace) { // Route to controller $args = explode("/", $this->pathInfo()); $controller_class = 'Controller' . ucfirst($args[1]); + if (!empty($app_namespace)) { + $controller_class = $app_namespace . '\\' . $controller_class; + } $controller_arguments = array_slice($args, 2); if (class_exists($controller_class, true)) { $this->Controller = new $controller_class($this, $controller_arguments); diff --git a/src/system/Security.php b/src/Security.php similarity index 100% rename from src/system/Security.php rename to src/Security.php diff --git a/src/system/Template.php b/src/Template.php similarity index 100% rename from src/system/Template.php rename to src/Template.php diff --git a/src/system/Url.php b/src/Url.php similarity index 100% rename from src/system/Url.php rename to src/Url.php diff --git a/src/application/ControllerAdmin.php b/src/application/ControllerAdmin.php deleted file mode 100644 index 32f0be4..0000000 --- a/src/application/ControllerAdmin.php +++ /dev/null @@ -1,109 +0,0 @@ - 'Overview', - 'clearCache' => 'Clear cache', - 'generateSite' => 'Generate static site', - 'logout' => 'Logout', - ); - - // admin section does not use content files - protected $contents; - - protected function isAllowedMethod($action): bool - { - return array_key_exists($action, $this->allowed_methods); - } - - protected function showTasks(): string - { - $output = ''; - - return $output; - } - - protected function showLogin() - { - 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 Cuttlefish\Html($this->contents, array( - 'layout' => 'layout.php', - 'controller' => 'admin', - 'model' => 'page', - )); - } - - public function index() - { - global $App; - if ($App->Security->isLoggedIn()) { - return $this->showTasks(); - } - - return $this->showLogin(); - } - - public function logout() - { - global $App; - - $App->Security->maybeLoginRedirect(); - - return $App->Security->logout(); - } -} diff --git a/src/application/ControllerArchive.php b/src/application/ControllerArchive.php deleted file mode 100644 index dc6cde2..0000000 --- a/src/application/ControllerArchive.php +++ /dev/null @@ -1,35 +0,0 @@ - '/content/posts' ), $this->ext); - $this->records = $Files->files(); - } - - /** - * @return void - */ - public function model() - { - $Model = new ModelPost($this->records); - $this->Model = $Model; - } - - /** - * @return void - */ - public function view() - { - parent::view(); - $this->View = new Cuttlefish\Html($this->Model->contents, array( - 'layout' => 'layout.php', - 'controller' => 'archive', - 'model' => 'post', - )); - } -} diff --git a/src/application/ControllerErrors.php b/src/application/ControllerErrors.php deleted file mode 100644 index 24a9a3e..0000000 --- a/src/application/ControllerErrors.php +++ /dev/null @@ -1,37 +0,0 @@ -args) . '.' . $this->ext; - $this->records = [ Cuttlefish\Filesystem::convertUrlToPath($url) ]; - } - - /** - * @return void - */ - public function model() - { - $this->Model = new ModelPage($this->records); - } - - /** - * @return void - */ - public function view() - { - parent::view(); - - $this->View = new Cuttlefish\Html($this->Model->contents, array( - 'layout' => 'layout.php', - 'controller' => 'errors', - 'model' => 'page', - )); - } -} diff --git a/src/application/ControllerFeeds.php b/src/application/ControllerFeeds.php deleted file mode 100644 index e9c080e..0000000 --- a/src/application/ControllerFeeds.php +++ /dev/null @@ -1,33 +0,0 @@ - '/content/posts' ), $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 Cuttlefish\Feed($this->Model->contents); - } -} diff --git a/src/application/ControllerHome.php b/src/application/ControllerHome.php deleted file mode 100644 index c144988..0000000 --- a/src/application/ControllerHome.php +++ /dev/null @@ -1,38 +0,0 @@ - '/content/posts' ), $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 Cuttlefish\Html($this->Model->contents, array( - 'layout' => 'layout.php', - 'controller' => 'home', - 'model' => 'post', - )); - } -} diff --git a/src/application/ControllerImages.php b/src/application/ControllerImages.php deleted file mode 100644 index d8de430..0000000 --- a/src/application/ControllerImages.php +++ /dev/null @@ -1,32 +0,0 @@ -records = [ Cuttlefish\Filesystem::convertUrlToPath('/content/images/' . implode('/', $this->args)) ]; - } - - /** - * @return void - */ - public function model() - { - $this->Model = new ModelFile($this->records); - } - - /** - * @return void - */ - public function view() - { - parent::view(); - - $this->View = new Cuttlefish\File($this->Model->contents); - $this->View->render(); - } -} diff --git a/src/application/ControllerPages.php b/src/application/ControllerPages.php deleted file mode 100644 index 6ca213d..0000000 --- a/src/application/ControllerPages.php +++ /dev/null @@ -1,36 +0,0 @@ -args) . '.' . $this->ext; - $this->records = [ Cuttlefish\Filesystem::convertUrlToPath($url) ]; - } - - /** - * @return void - */ - public function model() - { - $this->Model = new ModelPage($this->records); - } - - /** - * @return void - */ - public function view() - { - parent::view(); - - $this->View = new Cuttlefish\Html($this->Model->contents, array( - 'layout' => 'layout.php', - 'controller' => 'pages', - 'model' => 'page', - )); - } -} diff --git a/src/application/ControllerPosts.php b/src/application/ControllerPosts.php deleted file mode 100644 index f7e4070..0000000 --- a/src/application/ControllerPosts.php +++ /dev/null @@ -1,36 +0,0 @@ -args) . '.' . $this->ext; - $this->records = [ Cuttlefish\Filesystem::convertUrlToPath($url) ]; - } - - /** - * @return void - */ - public function model() - { - $this->Model = new ModelPost($this->records); - } - - /** - * @return void - */ - public function view() - { - parent::view(); - - $this->View = new Cuttlefish\Html($this->Model->contents, array( - 'layout' => 'layout.php', - 'controller' => 'posts', - 'model' => 'post', - )); - } -} diff --git a/src/application/ModelFile.php b/src/application/ModelFile.php deleted file mode 100644 index 186975e..0000000 --- a/src/application/ModelFile.php +++ /dev/null @@ -1,17 +0,0 @@ -contents = $records; - } -} diff --git a/src/application/ModelPage.php b/src/application/ModelPage.php deleted file mode 100644 index 2cd1942..0000000 --- a/src/application/ModelPage.php +++ /dev/null @@ -1,26 +0,0 @@ - 'content', - ); - - /** - * @return void - */ - public function contents($records) - { - $loaded_classes = array( - 'mdep' => new MarkdownExtra(), - ); - - foreach ($records as $record) { - $this->contents[] = $this->listContents($record, $loaded_classes); - } - } -} diff --git a/src/application/ModelPost.php b/src/application/ModelPost.php deleted file mode 100644 index 806d98d..0000000 --- a/src/application/ModelPost.php +++ /dev/null @@ -1,31 +0,0 @@ - 'metadata', - 'markdown|html' => 'content', - ); - - /** - * @return int - */ - public function sortByPublished($a, $b) - { - return strcmp($b->metadata->Published, $a->metadata->Published); - } - - /** - * @return self - */ - public function contents($records) - { - foreach ($records as $record) { - $this->contents[] = $this->listContents($record); - } - usort($this->contents, array( $this, 'sortByPublished' )); - - return $this; - } -} diff --git a/src/application/functions.php b/src/application/functions.php deleted file mode 100644 index 2c14677..0000000 --- a/src/application/functions.php +++ /dev/null @@ -1,8 +0,0 @@ - Create post template__ to download a _post_ template and save it in `/content/posts/2012/09/first-post.md`. -* Create a 404: `/content/errors/404.md`. Now non-existing links will point here. Error pages follow the _page_ data model. - -### Pretty Urls - -By default Cuttlefish uses Apache's mod_rewrite and the provided Nginx configuration to keep urls nice. You can disable this behaviour by opening `public/Configuration.php`: set `const INDEX_PAGE = '/index.php';`. This adds `/index.php` to all urls (eg: [/index.php/admin/new](http://localhost/index.php/admin/new) instead of [/admin/new](http://localhost/admin/new)); - - -### Caching - -To enable caching: open `public/Configuration.php` and set `const CACHE_ENABLED = true;`. Pages remain cached until its cache-file is deleted, manually or through __Admin > Clear Cache__. Caching must be enabled to use static site generation. - - -### Full static site generation - -Navigate to __Admin > Generate static site__. The `cache` folder now contains a full static site. - - - -### Externals - -Cuttlefish will support third-party plugins (externals). Simply drop a [spl_autoload_register](http://www.php.net/manual/en/function.spl-autoload-register.php) compatible class into the `system/Ext` folder and call the class in the code. See the php manual page for more info on autoloading classes. Feel free to organise classes using custom folders. - -Cuttlefish will register any externals and autoload them. It comes with markdown and yaml support courtesy of [PHP Markdown Extra](http://michelf.ca/projects/php-markdown/) and [Spyc](https://github.com/mustangostang/spyc/). - - -### Use of images within templates - -Put the image in the _/content/images_ folder, and then call the `/images` controller: - -![project logo](/images/cuttlefish/logo.png) - -An image is shown above this paragraph. diff --git a/src/favicon.ico b/src/favicon.ico deleted file mode 100644 index f1bc8a9..0000000 Binary files a/src/favicon.ico and /dev/null differ diff --git a/src/index.php b/src/index.php deleted file mode 100644 index 52a79f4..0000000 --- a/src/index.php +++ /dev/null @@ -1,14 +0,0 @@ -run(); diff --git a/src/themes/basic/styles/styles.css b/src/themes/basic/styles/styles.css deleted file mode 100644 index ce6e157..0000000 --- a/src/themes/basic/styles/styles.css +++ /dev/null @@ -1,187 +0,0 @@ -article { - margin-bottom: 4em; - max-width: 41em; -} - -code { - background: #eee; - display: inline-block; - padding: 0 .25em; - margin: 0 0.25em; - border-radius: 1px; - border: 1px solid #ddd; - font-family: Consolas, monospace; - max-width: 100%; -} - -pre, code { - white-space: pre-wrap; -} - -body { - max-width: 65em; - margin: 0 auto; - line-height: 1.6; - font-size: .95em; - padding: 0 20px; - font-family: Georgia, serif; - border-left: 1px solid #ccc; - box-shadow: -40px 0 1px rgba(0, 0, 0, 0.06); - min-height: 100%; - background: #fff; -} - -html { - height: 100%; - - background: #fff repeat left fixed; - -webkit-background-size: contain; - -moz-background-size: contain; - -o-background-size: contain; - background-size: contain; - /* background-image: url(../images/bg.jpg); */ - padding-left: 40px; -} - -h1, h2, h3, h4, h5, h6 { - font-size: 117.6%; - margin: 1em 0; -} - -h3, h4, h5, h6 { - font-size: 100%; -} - -h2 a { - display: block; -} - -blockquote { - font-style: italic; - border: 1px solid #eee; - border-width: 1px 0; -} - -#blank { - position: fixed; - background: #fff; - bottom: 0; - left: 50%; - right: 0; - top: 0; - z-index: -10; -} - -#content, #sidebar { - padding-top: 90px; -} - -#header a, h2 a { - text-decoration: none; - -webkit-transition: opacity 0.25s ease-in-out; - -moz-transition: opacity 0.25s ease-in-out; - -o-transition: opacity 0.25s ease-in-out; - transition: opacity 0.25s ease-in-out; - color: #000; - -} - -#sidebar a, #footer a { - text-decoration: none; -} - -#sidebar a { - display: block; -} - -#sidebar ul { - list-style: none; - padding-left: 0; -} - -#header a:hover, h2 a:hover { - opacity: 0.5; -} - -#footer { - margin: 2em -20px 0; - padding-left: 20px; - padding-bottom: 3em; - border-top: 1px solid #eee; - clear: both; -} - -#footer ul { - padding-left: 0; - list-style: none; -} - -#footer li { - float: left; -} - -#footer li a { - margin-right: 1em; -} - -#footer li[class="credits"] a { - margin-right: 0; -} - -#footer li.credits { - opacity: 0.7; - float: right; - margin-right: 20px; - -} - -#header { - box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset; - background: rgba(255, 255, 255, 0.9275); - position: fixed; - left: 0; - right: 0; - top: 0; - line-height: 1.2; - padding: 10px; - -} - -#header * { - margin: inherit; -} - -a { - color: #008; -} - -a:hover { - color: #04b; -} - -.float-left { - float: left; -} - -.float-right { - float: right; -} - -.one-third { - width: 33%; -} - -.two-thirds { - width: 63%; -} - -.archive dt { - clear: both; - margin-right: 1em; - width: 25%; - float: left; - color: #888; -} - - - diff --git a/src/themes/basic/views/admin.php b/src/themes/basic/views/admin.php deleted file mode 100644 index 448be03..0000000 --- a/src/themes/basic/views/admin.php +++ /dev/null @@ -1,8 +0,0 @@ -Admin'; -echo $this->contents; diff --git a/src/themes/basic/views/archive.php b/src/themes/basic/views/archive.php deleted file mode 100644 index b5cbca2..0000000 --- a/src/themes/basic/views/archive.php +++ /dev/null @@ -1,21 +0,0 @@ - - -

Archive

-
- - contents as $post) : - printf( - "
%s
%s
", - $post->metadata->Published, - $post->link, - $post->content->title - ); - endforeach; - ?> - -
\ No newline at end of file diff --git a/src/themes/basic/views/content.php b/src/themes/basic/views/content.php deleted file mode 100644 index bc7c042..0000000 --- a/src/themes/basic/views/content.php +++ /dev/null @@ -1,25 +0,0 @@ -", $this->controller, $this->model); - -switch (count((array)$this->contents)) { - case 0: - // no content - new installation - printf( - "

Please add content to /%s/%s.

", - href('/admin/new'), - Configuration::CONTENT_FOLDER, - $this->model - ); - break; - - default: - $include = __DIR__ . DIRECTORY_SEPARATOR . $this->controller . ".php"; - include $include; - break; -} - -print( "" ); diff --git a/src/themes/basic/views/errors.php b/src/themes/basic/views/errors.php deleted file mode 100644 index f8e0ee3..0000000 --- a/src/themes/basic/views/errors.php +++ /dev/null @@ -1,4 +0,0 @@ -contents as $post) : - printf("
-

%s

- %s -
", $post->link, $post->content->title, $post->content->main); -endforeach; diff --git a/src/themes/basic/views/layout.php b/src/themes/basic/views/layout.php deleted file mode 100644 index b313c93..0000000 --- a/src/themes/basic/views/layout.php +++ /dev/null @@ -1,46 +0,0 @@ - - - - - <?= Configuration::SITE_TITLE ?> - - - - - - - - - -
- -
content->render() ?>
- - - - - - - \ No newline at end of file diff --git a/src/themes/basic/views/pages.php b/src/themes/basic/views/pages.php deleted file mode 100644 index 2421534..0000000 --- a/src/themes/basic/views/pages.php +++ /dev/null @@ -1,12 +0,0 @@ -contents[0]->content; - -printf("
-

%s

- %s -
", $post->title, $post->main); diff --git a/src/themes/basic/views/posts.php b/src/themes/basic/views/posts.php deleted file mode 100644 index 9357ef7..0000000 --- a/src/themes/basic/views/posts.php +++ /dev/null @@ -1,17 +0,0 @@ -contents[0]; -printf( - "
-

%s

- %s - %s -
", - $post->content->title, - $post->metadata->Published, - $post->content->main -); diff --git a/src/system/view_functions.php b/src/view_functions.php similarity index 100% rename from src/system/view_functions.php rename to src/view_functions.php