Commit e4d2a6dd authored by nirgendswo's avatar nirgendswo

adding comments

change naming for Post
adding json support for methods
bugfix css
parent eb4e51c6
......@@ -9,18 +9,21 @@ use App\PageService;
/**
* Abstract Controller for pages
*
*
* @author Björn Hase
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository
*/
abstract class PageAbstractController extends Controller
{
/** pageService, parse slug, index, page, action and tags */
/**
* pageService, parse slug, index, page, method and tags
* @var App\PageService
*/
protected $pageService;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
......
......@@ -11,11 +11,16 @@ use App\Models\PageModel as Page;
/**
* Handle Pages
*
*
* @author Björn Hase
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository
*/
class PageController extends PageAbstractController
{
/**
* default result
* @var array
*/
const RESULT = [];
/**
......@@ -57,7 +62,7 @@ class PageController extends PageAbstractController
]);
}
$result = $this->processAction($page, $request);
$result = $this->processMethod($page, $request);
return app()->make('view')->make($page->view(), [
'page' => $page,
......@@ -67,25 +72,35 @@ class PageController extends PageAbstractController
}
/**
* put single page with slug
* post single page with slug
* check for controller in current theme and call
*
* @param Request $request
* @return View
*/
public function putAction(Request $request)
public function postJsonAction(Request $request)
{
$page = $this->pageService->getPage();
$result = $this->processMethod($page, $request);
if (!$page) {
return redirect()->route('page.show', [
'slug' => '404'
]);
}
return response()->json([
'page' => $page,
'request' => $request,
'result' => $result
]);
}
$result = $this->processAction($page, $request);
/**
* show single page as json
*
* @param string $slug
* @return View
*/
public function jsonAction(Request $request)
{
$page = $this->pageService->getPage();
return app()->make('view')->make($page->view(), [
return response()->json([
'page' => $page,
'request' => $request,
'result' => $result
......@@ -93,37 +108,24 @@ class PageController extends PageAbstractController
}
/**
* process action if that was defined in the theme for a slug
* process method if that was defined in the theme for a slug
*
* @param Mixed $action
* @param PageModel $page
* @param Request $request
* @return array
*/
protected function processAction($page, $request)
protected function processMethod($page, $request)
{
$result = self::RESULT;
if (isset($request->action)) {
$action = $request->action;
$action = new $action($page, $request);
$action->process();
if (isset($request->methodClass)) {
$methodClass = $request->methodClass;
$methodClass = new $methodClass($page, $request);
$methodClass->process();
$result = $action->getResult();
$result = $methodClass->getResult();
}
return $result;
}
/**
* show single page as json
*
* @param string $slug
* @return View
*/
public function jsonAction()
{
$page = $this->getPage();
return response()->json($page);
}
}
......@@ -9,12 +9,16 @@ use App\Facades\PageRepositoryFacade as PageRepository;
/**
* Handle RSS-Feeds
*
*
* @author Björn Hase
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository
*/
class RssController extends Controller
{
/** rss */
/**
* rss
* @var string
*/
const RSS = 'rss';
/**
......
<?php
namespace App\Http\Actions;
namespace App\Http\Methods;
/**
* Interface to handle methods in Themes
......
<?php
namespace App\Http\Actions;
namespace App\Http\Methods;
use Illuminate\Http\Request;
use App\Models\PageModel as Page;
......
......@@ -60,24 +60,35 @@ class PageRepository
/** regex to get current filepath */
/**
* regex
* regex to filter files
* @var string
*/
const REGEX_FILEPATH = '/\..*+$/';
/**
*
* @var [type]
* request
* @var Request
*/
protected $request;
/** directory for md-files */
/**
* directory path for md-files
* @var string
*/
protected $repositoryPath;
/** default paramters */
/**
* parameters
* @var array
*/
protected $parameters = [];
/** default options */
/**
* default options
* @var array
*/
protected $options = [
'depth' => 3,
'offset' => 0,
......@@ -85,12 +96,15 @@ class PageRepository
'parent' => '/'
];
/** count of pages */
/**
* count of pages
* @var integer
*/
protected $count = 0;
/**
*
* @param array $config
* @param request
*/
public function __construct($request)
{
......@@ -287,9 +301,10 @@ class PageRepository
}
/**
* limit pages
*
* @param $limit [description]
* @param integer $offset [description]
* @param integer $limit
* @param integer $offset
* @return Array
*/
protected function limit($pages, $limit, $offset = 0)
......
......@@ -13,25 +13,57 @@ use App\Facades\PageRepositoryFacade as PageRepository;
* and also modifies slug and tries to get page with slug
*
* @author Björn Hase
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository
*/
class PageService {
/** getting /p/? from slug */
/**
* regex for page number in url
* /p/?
* @var string
*/
const REGEX_NUMBER = '/\/p\/[0-9]/';
/**
* regex for page in url
* /p/
* @var string
*/
const REGEX_NUMBER_STRING = '/\/p\//';
/** getting /tags/? from slug */
/**
* regex for tags in url
* /tags/?
* @var string
*/
const REGEX_TAGS = '/\/tags\/[a-zA-Z0-9,]*$/';
/**
* regex for tags in url
* /tags/
* @var string
*/
const REGEX_TAGS_STRING = '/\/tags\//';
/** default slug */
/**
* method namespace
* @var string
*/
const METHOD_NAMESPACE = 'Method';
/**
* default slug
* @var string
*/
private $slug = NULL;
/**
*
*
* @param Request $request
* @param Illuminate\Http\Request $request
*
*/
public function __construct(Request $request)
{
......@@ -49,8 +81,10 @@ class PageService {
$this->parseNumber($request);
$this->parseTags($request);
$this->page = $this->parsePage($request);
$this->parseAction($this->page, $request);
$this->parseMethod($this->page, $request);
}
/**
......@@ -81,7 +115,7 @@ class PageService {
/**
* getting tags in url
*
* @param string $slug
* @param Illuminate\Http\Request $request
*/
private function parseTags(Request $request)
{
......@@ -105,29 +139,41 @@ class PageService {
* get view of current page,
* if view is not set, use default const
*
* @param string $page
* @param mixed $page
* @param Illuminate\Http\Request $request
* @return string
*/
private function parseAction($page, Request $request)
private function parseMethod($page, Request $request)
{
if ($page && $request->getMethod()) {
$data = [
'methodClass' => NULL
];
$theme = env('APP_THEME');
// getting slug of page and write it as camelcase
$className = ucfirst(camel_case(str_replace('/', '', $page->slug)));
// getting method and change letters to CamelCase
$method = ucfirst(strtolower($request->getMethod()));
$classPath = '\\Themes\\'.$theme.'\\Actions\\'.$className.$method.'Action';
// create class path
$classPath = '\\Themes\\'.$theme.'\\Methods\\'.$className.$method.self::METHOD_NAMESPACE;
// check if class exists
if (class_exists($classPath)) {
$request->merge(['action' => $classPath]);
$data['methodClass'] = $classPath;
}
$request->merge($data);
}
}
/**
* find one page with slug
*
* @param Request $request
* @param Illuminate\Http\Request $request
* @return mixed
*/
private function parsePage(Request $request)
......
{
"name": "nirgendswo/fuzzy-cms",
"version": "0.1.0",
"version": "1.0.0",
"description": "Build with Fuzzy CMS simple fast Websites or get your Content as JSON",
"authors": [
{
"name": "Björn Hase",
"email": "me@nirgendswo.de"
"email": "me@herr-hase.wtf"
}
],
"keywords": ["app", "lumen", "cms", "json"],
......
<?php
namespace Themes\FuzzyCms\Actions;
namespace Themes\FuzzyCms\Methods;
use App\Http\Actions\PostActionAbstract;
use App\Http\Methods\PostMethodAbstract;
/**
* Only to show how it works
*
*
* @author Björn Hase
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository
*
*/
class GettingStartedPostAction extends PostActionAbstract
class GettingStartedPostMethod extends PostMethodAbstract
{
/**
* process request and adding values to result
*
*
* @inheritance
*
*/
public function process()
{
$this->result['value'] = $this->request->get('value');
$this->result['checkbox'] = $this->request->get('checkbox');
$this->result['value'] = htmlspecialchars($this->request->get('value'));
$this->result['checkbox'] = htmlspecialchars($this->request->get('checkbox'));
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -37,12 +37,17 @@ $table__background-color--odd: #f9f9f9;
margin: 0 0 10px;
dt {
clear: left;
float: left;
clear: left;
}
dd {
color: red;
&:after {
content: ' ';
display: inline-block;
}
}
}
}
......
......@@ -17,8 +17,8 @@
<div class="content">
{!! $page->html() !!}
<div class="code">
<div class="code__result clearfix">
<dl>
<div class="code__result">
<dl class="clearfix">
<dt>result['value']</dt><dd>{{ $viewHelper->text('value', $result) }}</dd>
<dt>result['checkbox']</dt><dd>{{ $viewHelper->text('checkbox', $result) }}</dd>
</dl>
......
......@@ -22,6 +22,10 @@ $app->get('rss/{type}', [
// get the hole url as slug
$app->group(['middleware' => 'page'], function() use ($app) {
$app->post('json/{slug:[0-9\/a-z,-]+}', [
'as' => 'page.json.post', 'uses' => 'PageController@postJsonAction'
]);
$app->get('json/{slug:[0-9\/a-z,-]+}', [
'as' => 'page.json', 'uses' => 'PageController@jsonAction'
]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment