Fixed pages plugin

This commit is contained in:
Diego Najar 2017-06-20 23:56:22 +02:00
parent dce4130ae6
commit 19d6ab347b
21 changed files with 206 additions and 317 deletions

View File

@ -39,42 +39,6 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'tip'=>$L->g('Order the content by date to create a Blog or order the content by position to create a Website') 'tip'=>$L->g('Order the content by date to create a Blog or order the content by position to create a Website')
)); ));
HTML::legend(array('value'=>$L->g('Special content')));
$options = array();
foreach($dbPages->db as $key=>$fields) {
$page = buildPage($key);
$options[$key] = $page->title();
}
HTML::formSelect(array(
'name'=>'pageError',
'label'=>$L->g('404 Page Not Found'),
'options'=>$options,
'selected'=>$Site->pageError(),
'class'=>'uk-width-1-3 uk-form-medium',
'tip'=>$L->g('This page is showed only when the page does not exist anymore')
));
HTML::formSelect(array(
'name'=>'pageAbout',
'label'=>$L->g('About page'),
'options'=>$options,
'addEmptySpace'=>true,
'selected'=>$Site->pageAbout(),
'class'=>'uk-width-1-3 uk-form-medium',
'tip'=>$L->g('This page is to define a history about you or the content of your site')
));
HTML::formSelect(array(
'name'=>'pageContact',
'label'=>$L->g('Contact page'),
'options'=>$options,
'addEmptySpace'=>true,
'selected'=>$Site->pageContact(),
'class'=>'uk-width-1-3 uk-form-medium',
'tip'=>$L->g('Page for contact information')
));
HTML::legend(array('value'=>$L->g('Email account settings'))); HTML::legend(array('value'=>$L->g('Email account settings')));
HTML::formInputText(array( HTML::formInputText(array(

View File

@ -239,6 +239,23 @@ class dbPages extends dbJSON
return true; return true;
} }
// Change a value of a page
public function setField($key, $field, $value)
{
if( $this->exists($key) ) {
settype($value, gettype($this->dbFields[$field]['value']));
$this->db[$key][$field] = $value;
return $this->save();
}
return false;
}
public function setStatus($key, $value)
{
return $this->setField($key, 'status', $value);
}
// Returns a database with published pages // Returns a database with published pages
public function getPublishedDB() public function getPublishedDB()
{ {
@ -386,16 +403,7 @@ class dbPages extends dbJSON
// ----- OLD // ----- OLD
// Set a field of the database
public function setField($key, $field, $value)
{
if( $this->exists($key) ) {
settype($value, gettype($this->dbFields[$key]['value']));
$this->db[$key][$field] = $value;
}
return false;
}

View File

@ -27,10 +27,7 @@ class dbSite extends dbJSON
'googlePlus'=> array('inFile'=>false, 'value'=>''), 'googlePlus'=> array('inFile'=>false, 'value'=>''),
'instagram'=> array('inFile'=>false, 'value'=>''), 'instagram'=> array('inFile'=>false, 'value'=>''),
'github'=> array('inFile'=>false, 'value'=>''), 'github'=> array('inFile'=>false, 'value'=>''),
'orderBy'=> array('inFile'=>false, 'value'=>'date'), // date or position 'orderBy'=> array('inFile'=>false, 'value'=>'date') // date or position
'pageError'=> array('inFile'=>false, 'value'=>'error'),
'pageAbout'=> array('inFile'=>false, 'value'=>'about'),
'pageContact'=> array('inFile'=>false, 'value'=>'contact')
); );
function __construct() function __construct()

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Fixed Pages",
"description": "Show a list of links."
}
}

View File

@ -0,0 +1,174 @@
<?php
class pluginFixedPages extends Plugin {
public function init()
{
// JSON database
$jsondb = json_encode(array(
'about'=>'About'
));
// Fields and default values for the database of this plugin
$this->dbFields = array(
'label'=>'Fixed Pages',
'jsondb'=>$jsondb
);
// Disable default Save and Cancel button
$this->formButtons = false;
}
// Method called when a POST request is sent
public function post()
{
global $dbPages;
// Get current jsondb value from database
// All data stored in the database is html encoded
$jsondb = $this->db['jsondb'];
$jsondb = Sanitize::htmlDecode($jsondb);
// Convert JSON to Array
$pagesFixed = json_decode($jsondb, true);
// Check if the user click on the button delete or add
if( isset($_POST['delete']) ) {
// Values from $_POST
$pageKey = $_POST['delete'];
// Change the status of the page from fixed to published
$dbPages->setStatus($pageKey, 'published');
// Delete the link from the array
unset($pagesFixed[$pageKey]);
}
elseif( isset($_POST['add']) ) {
// Values from $_POST
$pageTitle = $_POST['newPageTitle'];
$pageKey = $_POST['newPageKey'];
// Change the status of the page from fixed to published
$dbPages->setStatus($pageKey, 'fixed');
// Add the link
$pagesFixed[$pageKey] = $pageTitle;
}
// Encode html to store the values on the database
$this->db['label'] = Sanitize::html($_POST['label']);
$this->db['jsondb'] = Sanitize::html(json_encode($pagesFixed));
// Save the database
return $this->save();
}
// Method called on plugin settings on the admin area
public function form()
{
global $Language;
global $dbPages;
$options = array();
foreach($dbPages->db as $key=>$fields) {
$page = buildPage($key);
if($page->published()) {
$options[$key] = $page->title();
}
}
$html = '<div>';
$html .= '<label>'.$Language->get('Label').'</label>';
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">';
$html .= '<span class="tip">'.$Language->get('Title of the plugin for the sidebar').'</span>';
$html .= '</div>';
$html .= '<div>';
$html .= '<button name="save" class="blue" type="submit">Save</button>';
$html .= '</div>';
// NEW PAGE
$html .= '<legend>'.$Language->get('New fixed page').'</legend>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Title').'</label>';
$html .= '<input name="newPageTitle" type="text" value="">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Page').'</label>';
$html .= '<select name="newPageKey">';
foreach($options as $key=>$title) {
$html .= '<option value="'.$key.'">'.$title.'</option>';
}
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<button name="add" class="blue" type="submit">Add</button>';
$html .= '</div>';
// LIST OF PAGES
$html .= '<legend>'.$Language->get('Fixed pages').'</legend>';
$jsondb = $this->getValue('jsondb', $unsanitized=false);
$pagesFixed = json_decode($jsondb, true);
foreach($pagesFixed as $pageKey=>$pageTitle) {
$html .= '<div>';
$html .= '<label>'.$Language->get('Title').'</label>';
$html .= '<input type="text" value="'.$pageTitle.'" disabled>';
$html .= '</div>';
$page = buildPage($pageKey);
if($page) {
$title = $page->title();
} else {
$title = $Language->get('Error page deleted');
}
$html .= '<div>';
$html .= '<label>'.$Language->get('Page linked').'</label>';
$html .= '<input type="text" value="'.$title.'" disabled>';
$html .= '</div>';
$html .= '<div>';
$html .= '<button name="delete" type="submit" value="'.$pageKey.'">Delete</button>';
$html .= '</div>';
$html .= '</br>';
}
return $html;
}
// Method called on the sidebar of the website
public function siteSidebar()
{
global $Language;
// HTML for sidebar
$html = '<div class="plugin plugin-pages">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>';
$html .= '<div class="plugin-content">';
$html .= '<ul>';
// Get the JSON DB, getValue() with the option unsanitized HTML code
$jsondb = $this->getValue('jsondb', false);
$pagesFixed = json_decode($jsondb);
// By default the database of categories are alphanumeric sorted
foreach($pagesFixed as $key=>$title) {
$html .= '<li>';
$html .= '<a href="'.DOMAIN_PAGES.$key.'">';
$html .= $title;
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}

View File

@ -16,6 +16,7 @@ class pluginLinks extends Plugin {
'jsondb'=>$jsondb 'jsondb'=>$jsondb
); );
// Disable default Save and Cancel button
$this->formButtons = false; $this->formButtons = false;
} }
@ -23,16 +24,19 @@ class pluginLinks extends Plugin {
public function post() public function post()
{ {
// Get current jsondb value from database // Get current jsondb value from database
$jsondb = $this->getValue('jsondb', $unsanitized=false); // All data stored in the database is html encoded
$jsondb = $this->db['jsondb'];
$jsondb = Sanitize::htmlDecode($jsondb);
// Convert JSON to Array // Convert JSON to Array
$links = json_decode($jsondb, true); $links = json_decode($jsondb, true);
// Check if the user click on the button delete or add
if( isset($_POST['deleteLink']) ) { if( isset($_POST['deleteLink']) ) {
// Values from $_POST // Values from $_POST
$name = $_POST['deleteLink']; $name = $_POST['deleteLink'];
// Delete the link // Delete the link from the array
unset($links[$name]); unset($links[$name]);
} }
elseif( isset($_POST['addLink']) ) { elseif( isset($_POST['addLink']) ) {
@ -47,7 +51,7 @@ class pluginLinks extends Plugin {
$links[$name] = $url; $links[$name] = $url;
} }
// Sanitize the new values and replace the current values of the database // Encode html to store the values on the database
$this->db['label'] = Sanitize::html($_POST['label']); $this->db['label'] = Sanitize::html($_POST['label']);
$this->db['jsondb'] = Sanitize::html(json_encode($links)); $this->db['jsondb'] = Sanitize::html(json_encode($links));

View File

@ -1,11 +0,0 @@
{
"plugin-data":
{
"name": "Страници",
"description": "Показва списък на страниците."
},
"home": "Начало",
"show-home-link": "Покажи връзка към начало",
"show-children": "Покажи подменю"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Menü aller Seiten",
"description": "Anzeige eines Menüs aller Seiten in der Seitenleiste (bei Themes mit Seitenleiste)."
},
"home": "Hauptseite",
"show-home-link": "Hauptseite zeigen"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Menü aller Seiten",
"description": "Anzeige eines Menüs aller Seiten in der Seitenleiste (bei Themes mit Seitenleiste)."
},
"home": "Hauptseite",
"show-home-link": "Hauptseite zeigen"
}

View File

@ -1,7 +0,0 @@
{
"plugin-data":
{
"name": "Special pages",
"description": "Shows a list of pages, you can define the amount of items and the order depends of settings."
}
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Listado de páginas",
"description": "Muestra las paginas en orden según la posición."
},
"home": "Página de inicio",
"show-home-link": "Mostrar página de inicio"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Page navigation",
"description": "Constitue un menu avec les liens des pages dans la colonne du thème."
},
"home": "Accueil",
"show-home-link": "Afficher le lien de la page daccueil"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Page list",
"description": "ページをリストにして表示します。"
},
"home": "ホーム",
"show-home-link": "ホーム・リンクを表示"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Pagina lijst",
"description": "Laat een lijst met alle pagina's op volgorde zien."
},
"home": "Home",
"show-home-link": "Laat de homepage link zien"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Lista stron",
"description": "Wyświetla listę stron znajdujących się w witrynie."
},
"home": "Strona główna",
"show-home-link": "Pokaż odnośnik do strony głównek"
}

View File

@ -1,11 +0,0 @@
{
"plugin-data":
{
"name": "Список страниц",
"description": "Показывает упорядоченый список страниц."
},
"home": "Главная",
"show-home-link": "Показывать ссылку на главную",
"show-children": "Показывать подменю"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "Sayfa listesi",
"description": "Sayfaları listeler."
},
"home": "Anasayfa",
"show-home-link": "Anasayfa linkini göster"
}

View File

@ -1,11 +0,0 @@
{
"plugin-data":
{
"name": "Список сторінок",
"description": "Показує список сторінок по порядку."
},
"home": "Головна",
"show-home-link": "Показувати лінк на головну сторінку",
"show-children": "Показувати вкладені лінки"
}

View File

@ -1,10 +0,0 @@
{
"plugin-data":
{
"name": "頁面列表",
"description": "顯示所有頁面的列表"
},
"home": "首頁",
"show-home-link": "顯示首頁連結"
}

View File

@ -1,135 +0,0 @@
<?php
class pluginSpecialPages extends Plugin {
public function init()
{
// Fields and default values for the database of this plugin
$this->dbFields = array(
'label'=>'Pages',
'homeLink'=>true,
'pageAboutLabel'=>'About',
'pageAbout'=>''
);
}
public function post()
{
}
// Method called on the settings of the plugin on the admin area
public function form()
{
global $Language;
global $dbPages;
$html = '<div>';
$html .= '<label>'.$Language->get('Label').'</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
$html .= '</div>';
$html .= '<div>';
$html .= '<input type="hidden" name="homeLink" value="false">';
$html .= '<input id="jshomeLink" name="homeLink" type="checkbox" value="true" '.($this->getValue('homeLink')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jshomeLink">'.$Language->get('Show home link').'</label>';
$html .= '</div>';
$options = array();
foreach($dbPages->db as $key=>$fields) {
$page = buildPage($key);
$options[$key] = $page->title();
}
HTML::formOpen(array('class'=>'uk-form-horizontal'));
HTML::legend(array('value'=>$Language->g('About page')));
HTML::formInputText(array(
'name'=>'title',
'label'=>$Language->g('Site title'),
'value'=>'test',
'class'=>'uk-width-1-2 uk-form-medium',
'tip'=>$Language->g('use-this-field-to-name-your-site')
));
HTML::formClose();
$html .= '<legend>About page</legend>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Label').'</label>';
$html .= '<input id="jspageAboutLabel" name="pageAboutLabel" type="text" value="'.$this->getValue('pageAboutLabel').'">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Select a page').'</label>';
$html .= '<select id="jspageAbout" name="pageAbout">';
$html .= '<option value=""></option>';
foreach($options as $key=>$title) {
$html .= '<option value="'.$key.'" '.($this->getValue('pageAbout')==$key?'selected':'').'>'.$title.'</option>';
}
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<input type="hidden" name="pageAboutHide" value="false">';
$html .= '<input id="jshomeLink" name="homeLink" type="checkbox" value="true" '.($this->getValue('homeLink')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jshomeLink">'.$Language->get('Show the page on the main').'</label>';
$html .= '</div>';
$html .= '<legend>Contact page</legend>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Label').'</label>';
$html .= '<input id="jspageContactLabel" name="pageContactLabel" type="text" value="'.$this->getValue('pageContactLabel').'">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Select a page').'</label>';
$html .= '<select id="jspageContact" name="pageContact">';
$html .= '<option value=""></option>';
foreach($options as $key=>$title) {
$html .= '<option value="'.$key.'" '.($this->getValue('pageContact')==$key?'selected':'').'>'.$title.'</option>';
}
$html .= '</select>';
$html .= '</div>';
return $html;
}
// Method called on the sidebar of the website
public function siteSidebar()
{
global $Language;
// HTML for sidebar
$html = '<div class="plugin plugin-special-pages">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>';
$html .= '<div class="plugin-content">';
$html .= '<ul>';
// Show Home page link
if( $this->getValue('homeLink') ) {
$html .= '<li>';
$html .= '<a href="'.$Site->url().'">';
$html .= $Language->get('Home page');
$html .= '</a>';
$html .= '</li>';
}
if( $this->getValue('pageAboutLabel') ) {
$html .= '<li>';
$html .= '<a href="'.$this->getValue('pageAbout').'">';
$html .= $this->getValue('pageAboutLabel');
$html .= '</a>';
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}