Bug fixes on URL router

This commit is contained in:
Diego Najar 2017-09-21 20:42:03 +02:00
parent 7ab8303c7e
commit 429ccadd2d
11 changed files with 123 additions and 114 deletions

View File

@ -26,6 +26,10 @@ class dbList extends dbJSON
public function getList($key, $pageNumber, $amountOfItems)
{
if (empty($key)) {
return false;
}
if (!isset($this->db[$key])) {
Log::set(__METHOD__.LOG_SEP.'Error key does not exist '.$key);
return false;

View File

@ -39,4 +39,4 @@ $scheduled = $dbPages->getScheduledDB();
$static = $dbPages->getStaticDB();
// Title of the page
$layout['title'] .= ' - '.$Language->g('Manage Content');
$layout['title'] .= ' - '.$Language->g('Manage Pages');

View File

@ -196,7 +196,7 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
'value'=>$externalCoverImage,
'class'=>'uk-width-1-1 uk-form-medium',
'label'=>$L->g('External Cover Image'),
'tip'=>$L->g('Image URL')
'tip'=>$L->g('Full image URL')
));
// Slug input

View File

@ -122,7 +122,8 @@ elseif ($Url->whereAmI()==='home') {
// Set page 404 not found
if ($Url->notFound()) {
$page = buildPage( $Site->pageNotFound() );
$pageNotFoundKey = $Site->pageNotFound();
$page = buildPage( $pageNotFoundKey );
if ($page===false) {
$page = buildErrorPage();
}

View File

@ -8,6 +8,10 @@ function buildPage($key) {
global $Parsedown;
global $Site;
if (empty($key)) {
return false;
}
// Page object, content from index.txt file
$page = new Page($key);
if (!$page->isValid()) {
@ -70,10 +74,12 @@ function reindexTags() {
function buildErrorPage() {
global $dbPages;
global $Language;
global $dbUsers;
$page = new Page(false);
$page->setField('title', $Language->get('page-not-found'));
$page->setField('content', $Language->get('page-not-found-content'));
$page->setField('user', $dbUsers->getUser('admin'));
return $page;
}

View File

@ -359,12 +359,6 @@ class Page {
return ($this->getValue('status')=='sticky');
}
// (boolean) Returns TRUE if the page is static, FALSE otherwise
public function static()
{
return ($this->getValue('status')=='static');
}
// (string) Returns status of the page
public function status()
{

View File

@ -69,16 +69,18 @@ class Url
// Check coincidence with complete filterURI
if ($subString==$filterURI) {
$this->slug = mb_substr($this->uri, $filterFullLenght);
$this->whereAmI = $filterName;
$this->setWhereAmI($filterName);
$this->activeFilter = $filterURI;
if (empty($this->slug) && (($filterName=='blog') || ($filterURI=='/')) ) {
$this->whereAmI = 'home';
} elseif (!empty($this->slug) && ($filterURI=='/')) {
$this->whereAmI = 'page';
if (empty($this->slug) && ($filterName=='blog')) {
$this->setWhereAmI('home');
} elseif (!empty($this->slug) && ($filterName=='blog')) {
$this->setNotFound();
return false;
} elseif (empty($this->slug) && ($filterURI=='/')) {
$this->setWhereAmI('home');
} elseif (!empty($this->slug) && ($filterURI=='/')) {
$this->setWhereAmI('page');
} elseif ($filterName=='admin') {
$this->slug = ltrim($this->slug, '/');
}
@ -87,8 +89,8 @@ class Url
}
}
return false;
$this->setNotFound();
return false;
}
public function slug()
@ -155,7 +157,7 @@ class Url
public function setNotFound()
{
$this->whereAmI = 'page';
$this->setWhereAmI('page');
$this->notFound = true;
$this->httpCode = 404;
$this->httpMessage = 'Not Found';

View File

@ -211,5 +211,6 @@
"create-a-new-category-to-organize-your-pages": "Create a new category to organize your pages",
"edit-or-delete-pages-from-your-site": "Edit or delete pages from your site",
"add-new-page": "Add new page",
"this-field-is-used-when-you-order-the-pages-by-position": "This field is used when you order the pages by position."
"this-field-is-used-when-you-order-the-pages-by-position": "This field is used when you order the pages by position.",
"about-your-site-or-yourself": "About your site or yourself"
}

View File

@ -43,6 +43,7 @@ class pluginAPI extends Plugin {
global $Url;
global $dbPages;
global $dbUsers;
global $Login;
// CHECK URL
// ------------------------------------------------------------
@ -95,6 +96,8 @@ class pluginAPI extends Plugin {
if ($username!==false) {
// Enable write permissions
$writePermissions = true;
// Loggin the user to create the session
$Login->setLogin($username, 'admin');
}
}
@ -107,11 +110,22 @@ class pluginAPI extends Plugin {
}
// (GET) /api/pages/<key>
elseif ( ($method==='GET') && ($parameters[0]==='pages') && !empty($parameters[1]) ) {
$data = $this->getPage($parameters[1]);
$pageKey = $parameters[1];
$data = $this->getPage($pageKey);
}
// (PUT) /api/pages/<key>
elseif ( ($method==='PUT') && ($parameters[0]==='pages') && !empty($parameters[1]) && $writePermissions ) {
$pageKey = $parameters[1];
$data = $this->editPage($pageKey, $inputs);
}
// (DELETE) /api/pages/<key>
elseif ( ($method==='DELETE') && ($parameters[0]==='pages') && !empty($parameters[1]) && $writePermissions ) {
$pageKey = $parameters[1];
$data = $this->deletePage($pageKey);
}
// (POST) /api/pages
elseif ( ($method==='POST') && ($parameters[0]==='pages') && empty($parameters[1]) && $writePermissions ) {
$data = $this->newPage($inputs);
$data = $this->createPage($inputs);
}
else {
$this->response(401, 'Unauthorized', array('message'=>'Access denied or invalid endpoint.'));
@ -201,26 +215,6 @@ class pluginAPI extends Plugin {
exit($json);
}
private function getPage($key)
{
// Generate the object Page
$Page = buildPage($key);
if (!$Page) {
return array(
'status'=>'1',
'message'=>'Page not found.'
);
}
$data = array();
$data['status'] = '0';
$data['message'] = 'Page filtered by key: '.$key;
$data['data'] = $Page->json( $returnsArray=true );
return $data;
}
private function getPages()
{
global $dbPages;
@ -247,10 +241,76 @@ class pluginAPI extends Plugin {
return $tmp;
}
private function getPage($key)
{
// Generate the object Page
$Page = buildPage($key);
if (!$Page) {
return array(
'status'=>'1',
'message'=>'Page not found.'
);
}
return array(
'status'=>'0',
'message'=>'Page filtered by key: '.$key,
'data'=>$Page->json( $returnsArray=true )
);
}
private function createPage($args)
{
// This function is defined on functions.php
return createPage($args);
$key = createPage($args);
if ($key===false) {
return array(
'status'=>'1',
'message'=>'Error trying to create the new page.'
);
}
return array(
'status'=>'0',
'message'=>'Page created.',
'data'=>array('key'=>$key)
);
}
private function editPage($key, $args)
{
$args['key'] = $key;
$newKey = editPage($args);
if ($newKey===false) {
return array(
'status'=>'1',
'message'=>'Error trying to edit the page.'
);
}
return array(
'status'=>'0',
'message'=>'Page edited.',
'data'=>array('key'=>$newKey)
);
}
private function deletePage($key)
{
if (deletePage($key)) {
return array(
'status'=>'0',
'message'=>'Page deleted.'
);
}
return array(
'status'=>'1',
'message'=>'Error trying to delete the page.'
);
}
}

View File

@ -15,11 +15,11 @@
<nav class="links">
<ul>
<?php
$fixedPages = $dbPages->getFixedDB();
$keys = array_keys($fixedPages);
foreach($keys as $pageKey) {
$pageParent = buildPage($pageKey);
echo '<li><a href="'.$pageParent->permalink().'">'.$pageParent->title().'</a></li>';
$staticPages = $dbPages->getStaticDB();
$staticPagesKeyList = array_keys($staticPages);
foreach ($staticPagesKeyList as $pageKey) {
$staticPage = buildPage($pageKey);
echo '<li><a href="'.$staticPage->permalink().'">'.$staticPage->title().'</a></li>';
}
?>
</ul>
@ -39,21 +39,19 @@
<ul class="links">
<?php
echo '<li>';
echo '<a href="'.$Site->url().'">
<h3>'.$Language->get('Home page').'</h3>
<p>'.$Site->description().'</p>
</a>';
echo '<a href="'.$Site->url().'">';
echo '<h3>'.$Language->get('Home page').'</h3>';
echo '<p>'.$Site->description().'</p>';
echo '</a>';
echo '</li>';
$fixedPages = $dbPages->getFixedDB();
$keys = array_keys($fixedPages);
foreach($keys as $pageKey) {
$pageParent = buildPage($pageKey);
foreach ($staticPagesKeyList as $pageKey) {
$staticPage = buildPage($pageKey);
echo '<li>';
echo '<a href="'.$pageParent->permalink().'">
<h3>'.$pageParent->title().'</h3>
<p>'.$pageParent->description().'</p>
</a>';
echo '<a href="'.$staticPage->permalink().'">';
echo '<h3>'.$staticPage->title().'</h3>';
echo '<p>'.$staticPage->description().'</p>';
echo '</a>';
echo '</li>';
}
?>

View File

@ -1,57 +0,0 @@
<article class="post">
<!-- Show plugins, Hook: Post Begin -->
<?php Theme::plugins('postBegin') ?>
<!-- Post's header -->
<header>
<div class="title">
<h1><a href="<?php echo $Post->permalink() ?>"><?php echo $Post->title() ?></a></h1>
</div>
<div class="meta">
<?php
// Get the user who created the post.
$User = $Post->user();
// Default author is the username.
$author = $User->username();
// If the user complete the first name or last name this will be the author.
if( Text::isNotEmpty($User->firstName()) || Text::isNotEmpty($User->lastName()) ) {
$author = $User->firstName().' '.$User->lastName();
}
?>
<time class="published" datetime="2015-11-01"><?php echo $Post->date() ?></time>
<div class="author"><span class="name"><?php echo $author ?></span><img src="<?php echo $User->profilePicture() ?>" alt=""></div>
</div>
</header>
<!-- Cover Image -->
<?php
if($Post->coverImage()) {
echo '<a href="'.$Post->permalink().'" class="image featured"><img src="'.$Post->coverImage().'" alt="Cover Image"></a>';
}
?>
<!-- Post's content, the first part if has pagebrake -->
<?php echo $Post->content() ?>
<!-- Post's footer -->
<footer>
<!-- Post's tags -->
<ul class="stats">
<?php
$tags = $Post->tags(true);
foreach($tags as $tagKey=>$tagName) {
echo '<li><a href="'.HTML_PATH_ROOT.$Url->filters('tag').'/'.$tagKey.'">'.$tagName.'</a></li>';
}
?>
</ul>
</footer>
<!-- Show plugins, Hook: Post End -->
<?php Theme::plugins('postEnd') ?>
</article>