Improvements on tags
This commit is contained in:
parent
1635937225
commit
63d11a755b
@ -33,4 +33,4 @@ foreach($pages as $Page)
|
||||
if(!$Page->published()) {
|
||||
array_push($_draftPages, $Page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ function editPage($args)
|
||||
{
|
||||
$dbPages->regenerate();
|
||||
|
||||
//$dbTags->reindexPages( $dbPages->db );
|
||||
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
Redirect::page('admin', 'edit-page/'.$args['key']);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
function editPost($args)
|
||||
{
|
||||
global $dbPosts;
|
||||
global $dbTags;
|
||||
global $Language;
|
||||
|
||||
// Post status, published or draft.
|
||||
@ -20,6 +21,9 @@ function editPost($args)
|
||||
// Edit the post.
|
||||
if( $dbPosts->edit($args) )
|
||||
{
|
||||
// Regenerate the database tags
|
||||
$dbTags->reindexPosts( $dbPosts->db );
|
||||
|
||||
Alert::set($Language->g('The changes have been saved'));
|
||||
Redirect::page('admin', 'edit-post/'.$args['key']);
|
||||
}
|
||||
@ -32,10 +36,14 @@ function editPost($args)
|
||||
function deletePost($key)
|
||||
{
|
||||
global $dbPosts;
|
||||
global $dbTags;
|
||||
global $Language;
|
||||
|
||||
if( $dbPosts->delete($key) )
|
||||
{
|
||||
// Regenerate the database tags
|
||||
$dbTags->reindexPosts( $dbPosts->db );
|
||||
|
||||
Alert::set($Language->g('The post has been deleted successfully'));
|
||||
Redirect::page('admin', 'manage-posts');
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ function addPage($args)
|
||||
// Add the page.
|
||||
if( $dbPages->add($args) )
|
||||
{
|
||||
//$dbTags->reindexPages( $dbPages->db );
|
||||
|
||||
Alert::set($Language->g('Page added successfully'));
|
||||
Redirect::page('admin', 'manage-pages');
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
function addPost($args)
|
||||
{
|
||||
global $dbPosts;
|
||||
global $dbTags;
|
||||
global $Language;
|
||||
|
||||
// Page status, published or draft.
|
||||
@ -24,6 +25,9 @@ function addPost($args)
|
||||
// Add the page.
|
||||
if( $dbPosts->add($args) )
|
||||
{
|
||||
// Regenerate the database tags
|
||||
$dbTags->reindexPosts( $dbPosts->db );
|
||||
|
||||
Alert::set($Language->g('Post added successfully'));
|
||||
Redirect::page('admin', 'manage-posts');
|
||||
}
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
<label>
|
||||
<?php $Language->p('Title') ?>
|
||||
<input id="jstitle" name="title" type="text" class="width-80" value="<?php echo $_Page->title() ?>">
|
||||
<input id="jstitle" name="title" type="text" class="width-90" value="<?php echo $_Page->title() ?>">
|
||||
</label>
|
||||
|
||||
<label class="width-80">
|
||||
<label class="width-90">
|
||||
<?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span>
|
||||
<textarea id="jscontent" name="content" rows="15"><?php echo $_Page->contentRaw(false) ?></textarea>
|
||||
</label>
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
<label>
|
||||
<?php $Language->p('Title') ?>
|
||||
<input id="jstitle" name="title" type="text" class="width-80" value="<?php echo $_Post->title() ?>">
|
||||
<input id="jstitle" name="title" type="text" class="width-90" value="<?php echo $_Post->title() ?>">
|
||||
</label>
|
||||
|
||||
<label class="width-80">
|
||||
<label class="width-90">
|
||||
<?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span>
|
||||
<textarea id="jscontent" name="content" rows="15"><?php echo $_Post->contentRaw(false) ?></textarea>
|
||||
</label>
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
<label>
|
||||
<?php $Language->p('Title') ?>
|
||||
<input id="jstitle" name="title" type="text" class="width-80">
|
||||
<input id="jstitle" name="title" type="text" class="width-90">
|
||||
</label>
|
||||
|
||||
<label class="width-80">
|
||||
<label class="width-90">
|
||||
<?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span>
|
||||
<textarea id="jscontent" name="content" rows="15"></textarea>
|
||||
</label>
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
<label>
|
||||
<?php $Language->p('Title') ?>
|
||||
<input id="jstitle" name="title" type="text" class="width-80">
|
||||
<input id="jstitle" name="title" type="text" class="width-90">
|
||||
</label>
|
||||
|
||||
<label class="width-80">
|
||||
<label class="width-90">
|
||||
<?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span>
|
||||
<textarea id="jscontent" name="content" rows="15" ></textarea>
|
||||
</label>
|
||||
|
30
install.php
30
install.php
@ -197,6 +197,12 @@ function install($adminPassword, $email)
|
||||
error_log($errorText, 0);
|
||||
}
|
||||
|
||||
if(!mkdir(PATH_PLUGINS_DATABASES.'simplemde', $dirpermissions, true))
|
||||
{
|
||||
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES;
|
||||
error_log($errorText, 0);
|
||||
}
|
||||
|
||||
if(!mkdir(PATH_UPLOADS, $dirpermissions, true))
|
||||
{
|
||||
$errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS;
|
||||
@ -294,6 +300,24 @@ function install($adminPassword, $email)
|
||||
|
||||
file_put_contents(PATH_PLUGINS_DATABASES.'pages'.DS.'db.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
||||
|
||||
// File plugins/simplemde/db.php
|
||||
file_put_contents(
|
||||
PATH_PLUGINS_DATABASES.'simplemde'.DS.'db.php',
|
||||
$dataHead.json_encode(
|
||||
array(
|
||||
'position'=>0
|
||||
),
|
||||
JSON_PRETTY_PRINT),
|
||||
LOCK_EX
|
||||
);
|
||||
|
||||
// File tags.php
|
||||
$data = array(
|
||||
'postsIndex'=>array(),
|
||||
'pagesIndex'=>array()
|
||||
);
|
||||
|
||||
file_put_contents(PATH_DATABASES.'tags.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
|
||||
|
||||
// File index.txt for error page
|
||||
$data = 'Title: '.$Language->get('Error').'
|
||||
@ -305,11 +329,9 @@ function install($adminPassword, $email)
|
||||
$data = 'Title: '.$Language->get('First post').'
|
||||
Content:
|
||||
|
||||
'.$Language->get('Congratulations you have successfully installed your Bludit').'
|
||||
---
|
||||
## '.$Language->get('Congratulations you have successfully installed your Bludit').'
|
||||
|
||||
'.$Language->get('Whats next').'
|
||||
---
|
||||
### '.$Language->get('Whats next').'
|
||||
- '.$Language->get('Manage your Bludit from the admin panel').'
|
||||
- '.$Language->get('Follow Bludit on').' [Twitter](https://twitter.com/bludit) / [Facebook](https://www.facebook.com/pages/Bludit/239255789455913) / [Google+](https://plus.google.com/+Bluditcms)
|
||||
- '.$Language->get('Visit the support forum').'
|
||||
|
@ -93,6 +93,7 @@ include(PATH_ABSTRACT.'plugin.class.php');
|
||||
include(PATH_KERNEL.'dbposts.class.php');
|
||||
include(PATH_KERNEL.'dbpages.class.php');
|
||||
include(PATH_KERNEL.'dbusers.class.php');
|
||||
include(PATH_KERNEL.'dbtags.class.php');
|
||||
include(PATH_KERNEL.'dblanguage.class.php');
|
||||
include(PATH_KERNEL.'dbsite.class.php');
|
||||
include(PATH_KERNEL.'post.class.php');
|
||||
@ -126,6 +127,7 @@ if(Session::started()===false) {
|
||||
$dbPosts = new dbPosts();
|
||||
$dbPages = new dbPages();
|
||||
$dbUsers = new dbUsers();
|
||||
$dbTags = new dbTags();
|
||||
$Site = new dbSite();
|
||||
$Url = new Url();
|
||||
$Parsedown = new Parsedown();
|
||||
|
67
kernel/dbtags.class.php
Normal file
67
kernel/dbtags.class.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php defined('BLUDIT') or die('Bludit CMS.');
|
||||
|
||||
class dbTags extends dbJSON
|
||||
{
|
||||
/*
|
||||
$postsIndex['tag1']['name'] = 'Tag 1';
|
||||
$postsIndex['tag1']['posts'] = array('post1','post2','post3');
|
||||
$postsIndex['tag2']['name'] = 'Tag 2';
|
||||
$postsIndex['tag2']['posts'] = array('post1','post5');
|
||||
*/
|
||||
private $dbFields = array(
|
||||
'postsIndex'=>array('inFile'=>false, 'value'=>array()),
|
||||
'pagesIndex'=>array('inFile'=>false, 'value'=>array())
|
||||
);
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct(PATH_DATABASES.'tags.php');
|
||||
}
|
||||
|
||||
public function countPostsByTag($tagKey)
|
||||
{
|
||||
if( isset($this->db['postsIndex'][$tagKey]) ) {
|
||||
return count($this->db['postsIndex'][$tagKey]['posts']);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function reindexPosts($db)
|
||||
{
|
||||
$tagsIndex = array();
|
||||
$currentDate = Date::current(DB_DATE_FORMAT);
|
||||
|
||||
// Foreach post
|
||||
foreach($db as $postKey=>$values)
|
||||
{
|
||||
if( ($values['status']==='published') && ($values['date']<=$currentDate) )
|
||||
{
|
||||
$explode = explode(',', $values['tags']);
|
||||
|
||||
// Foreach tag from post
|
||||
foreach($explode as $tagName)
|
||||
{
|
||||
$tagName = trim($tagName);
|
||||
$tagKey = Text::cleanUrl($tagName);
|
||||
|
||||
if( isset($tagsIndex[$tagKey]) ) {
|
||||
array_push($tagsIndex[$tagKey]['posts'], $postKey);
|
||||
}
|
||||
else {
|
||||
$tagsIndex[$tagKey]['name'] = $tagName;
|
||||
$tagsIndex[$tagKey]['posts'] = array($postKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db['postsIndex'] = $tagsIndex;
|
||||
if( $this->save() === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
body {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
*:first-child {
|
||||
margin-top: 0;
|
||||
}
|
7
plugins/simplemde/css/simplemde.min.css
vendored
Normal file
7
plugins/simplemde/css/simplemde.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
14
plugins/simplemde/js/simplemde.min.js
vendored
Normal file
14
plugins/simplemde/js/simplemde.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -23,9 +23,13 @@ class pluginsimpleMDE extends Plugin {
|
||||
$language = $Site->shortLanguage();
|
||||
$pluginPath = $this->htmlPath();
|
||||
|
||||
$html = '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">';
|
||||
$html .= '<link rel="stylesheet" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">';
|
||||
$html .= '<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>';
|
||||
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
|
||||
$html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';
|
||||
|
||||
//$html = '<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">';
|
||||
//$html .= '<link rel="stylesheet" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">';
|
||||
//$html .= '<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>';
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -50,14 +54,14 @@ class pluginsimpleMDE extends Plugin {
|
||||
$html .=
|
||||
'var simplemde = new SimpleMDE({
|
||||
element: document.getElementById("jscontent"),
|
||||
status: true,
|
||||
status: false,
|
||||
toolbarTips: true,
|
||||
toolbarGuideIcon: true,
|
||||
autofocus: true,
|
||||
lineWrapping: false,
|
||||
indentWithTabs: true,
|
||||
tabSize: 4,
|
||||
spellChecker: true
|
||||
spellChecker: false
|
||||
});';
|
||||
$html .= '}); </script>';
|
||||
}
|
||||
|
12
plugins/tags/language/en_US.json
Executable file
12
plugins/tags/language/en_US.json
Executable file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Tags list",
|
||||
"description": "Shows all tags.",
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "http://www.bludit.com",
|
||||
"version": "0.1",
|
||||
"releaseDate": "2015-08-02"
|
||||
}
|
||||
}
|
51
plugins/tags/plugin.php
Executable file
51
plugins/tags/plugin.php
Executable file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class pluginTags extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->dbFields = array(
|
||||
'label'=>'Tags'
|
||||
);
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
global $Language;
|
||||
|
||||
$html = '<div>';
|
||||
$html .= '<label>Plugin label</label>';
|
||||
$html .= '<input name="label" id="jslabel" type="text" value="'.$this->getDbField('label').'">';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function siteSidebar()
|
||||
{
|
||||
global $Language;
|
||||
global $dbTags;
|
||||
|
||||
$html = '<div class="plugin plugin-tags">';
|
||||
$html .= '<h2>'.$this->getDbField('label').'</h2>';
|
||||
$html .= '<div class="plugin-content">';
|
||||
|
||||
$db = $dbTags->db['postsIndex'];
|
||||
|
||||
$html .= '<ul>';
|
||||
|
||||
foreach($db as $tagKey=>$fields)
|
||||
{
|
||||
$count = $dbTags->countPostsByTag($tagKey);
|
||||
|
||||
// Print the parent
|
||||
$html .= '<li><a href="tag/'.$tagKey.'">'.$fields['name'].' ('.$count.')</a></li>';
|
||||
}
|
||||
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user