Improves on tag system

This commit is contained in:
dignajar 2016-01-16 11:01:29 -03:00
parent 0abe9599cc
commit 030b9e6d15
11 changed files with 196 additions and 95 deletions

View File

@ -21,37 +21,4 @@ if($Login->role()!=='admin') {
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
$themes = array(); $themes = buildThemes();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
foreach($themesPaths as $themePath)
{
// Check if the theme is translated.
$languageFilename = $themePath.DS.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = $themePath.DS.'languages'.DS.'en_US.json';
}
if( Sanitize::pathFile($languageFilename) )
{
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
$database = $database['theme-data'];
$database['dirname'] = basename($themePath);
// --- Metadata ---
$filenameMetadata = $themePath.DS.'metadata.json';
if( Sanitize::pathFile($filenameMetadata) )
{
$metadataString = file_get_contents($filenameMetadata);
$metadata = json_decode($metadataString, true);
$database = $database + $metadata;
// Theme data
array_push($themes, $database);
}
}
}

View File

@ -179,6 +179,19 @@ button.delete-button:hover {
text-transform: uppercase; text-transform: uppercase;
} }
#jstagList {
margin-top: 5px;
}
#jstagList span {
background: #f1f1f1;
border-radius: 3px;
color: #2672ec;
margin-right: 5px;
padding: 3px 10px;
cursor: pointer;
}
/* ----------- BLUDIT IMAGES V8 ----------- */ /* ----------- BLUDIT IMAGES V8 ----------- */
#bludit-images-v8 { #bludit-images-v8 {

View File

@ -20,7 +20,22 @@ class HTML {
public static function formClose() public static function formClose()
{ {
$html = '</form>'; $html = '</form>';
echo $html;
$script = '<script>
$(document).ready(function() {
// Prevent the form submit when press enter key.
$("form").keypress(function(e) {
if (e.which == 13) {
return false;
}
});
});
</script>';
echo $html.$script;
} }
// label, name, value, tip // label, name, value, tip
@ -52,12 +67,62 @@ class HTML {
echo $html; echo $html;
} }
public static function formInputAutocomplete($args) public static function tagsAutocomplete($args)
{ {
// Tag array for Javascript
$tagArray = 'var tagArray = [];';
if(!empty($args['value'])) {
$tagArray = 'var tagArray = ["'.implode('","', $args['value']).'"]';
}
$args['value'] = '';
// Text input
self::formInputText($args); self::formInputText($args);
echo '<div id="jstagList"></div>';
$script = '<script> $script = '<script>
$("input[name=\"'.$args['name'].'\"]").autoComplete({
'.$tagArray.'
function insertTag(tag)
{
// Clean the input text
$("#jstags").val("");
if(tag.trim()=="") {
return true;
}
// Check if the tag is already inserted.
var found = $.inArray(tag, tagArray);
if(found == -1) {
tagArray.push(tag);
renderTagList();
}
}
function removeTag(tag)
{
var found = $.inArray(tag, tagArray);
if(found => 0) {
tagArray.splice(found, 1);
renderTagList();
}
}
function renderTagList()
{
if(tagArray.length == 0) {
$("#jstagList").html("");
}
else {
$("#jstagList").html("<span>"+tagArray.join("</span><span>")+"</span>");
}
}
$("#jstags").autoComplete({
minChars: 1, minChars: 1,
source: function(term, suggest){ source: function(term, suggest){
term = term.toLowerCase(); term = term.toLowerCase();
@ -66,8 +131,40 @@ $("input[name=\"'.$args['name'].'\"]").autoComplete({
for (i=0; i<choices.length; i++) for (i=0; i<choices.length; i++)
if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]); if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
suggest(matches); suggest(matches);
},
onSelect: function(e, value, item) {
// Insert the tag when select whit the mouse click.
insertTag(value);
} }
}); });
$(document).ready(function() {
// When the page is loaded render the tags
renderTagList();
// Remove the tag when click on it.
$("body").on("click", "#jstagList > span", function() {
value = $(this).html();
removeTag(value);
});
// Insert tag when press enter key.
$("#jstags").keypress(function(e) {
if (e.which == 13) {
var value = $(this).val();
insertTag(value);
}
});
// When form submit.
$("form").submit(function(e) {
var list = tagArray.join(",");
$("#jstags").val(list);
});
});
</script>'; </script>';
echo $script; echo $script;
@ -157,7 +254,7 @@ $("input[name=\"'.$args['name'].'\"]").autoComplete({
$html = '<!-- BLUDIT QUICK IMAGES -->'; $html = '<!-- BLUDIT QUICK IMAGES -->';
$html .= ' $html .= '
<div id="bludit-quick-images"> <div id="bludit-quick-images">
<div id="bludit-quick-images-thumbnails"> <div id="bludit-quick-images-thumbnails" onmousedown="return false">
'; ';
$thumbnailList = Filesystem::listFiles(PATH_UPLOADS_THUMBNAILS,'*','*',true); $thumbnailList = Filesystem::listFiles(PATH_UPLOADS_THUMBNAILS,'*','*',true);

View File

@ -77,11 +77,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>$_Page->tags(), 'value'=>$_Page->tags(true),
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -71,11 +71,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>$_Post->tags(), 'value'=>$_Post->tags(true),
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -64,11 +64,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>'', 'value'=>'',
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -64,11 +64,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>'', 'value'=>'',
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -4,49 +4,72 @@
// Variables // Variables
// ============================================================================ // ============================================================================
$theme = array(
'name'=>'',
'description'=>'',
'author'=>'',
'email'=>'',
'website'=>'',
'version'=>'',
'releaseDate'=>''
);
// ============================================================================ // ============================================================================
// Functions // Functions
// ============================================================================ // ============================================================================
function buildThemes()
{
global $Site;
$themes = array();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
foreach($themesPaths as $themePath)
{
// Check if the theme is translated.
$languageFilename = $themePath.DS.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = $themePath.DS.'languages'.DS.'en_US.json';
}
if( Sanitize::pathFile($languageFilename) )
{
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
$database = $database['theme-data'];
$database['dirname'] = basename($themePath);
// --- Metadata ---
$filenameMetadata = $themePath.DS.'metadata.json';
if( Sanitize::pathFile($filenameMetadata) )
{
$metadataString = file_get_contents($filenameMetadata);
$metadata = json_decode($metadataString, true);
$database = $database + $metadata;
// Theme data
array_push($themes, $database);
}
}
}
return $themes;
}
// ============================================================================ // ============================================================================
// Main // Main
// ============================================================================ // ============================================================================
$langLocaleFile = PATH_THEME.'languages'.DS.$Site->locale().'.json'; // Load the language file
$langDefaultFile = PATH_THEME.'languages'.DS.'en_US.json'; $languageFilename = PATH_THEME.DS.'languages'.DS.$Site->locale().'.json';
$database = false; if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = PATH_THEME.DS.'languages'.DS.'en_US.json';
// Theme meta data from English
if( Sanitize::pathFile($langDefaultFile) ) {
$database = new dbJSON($langDefaultFile, false);
$themeMetaData = $database->db['theme-data'];
} }
// Check if exists locale language if( Sanitize::pathFile($languageFilename) )
if( Sanitize::pathFile($langLocaleFile) ) {
$database = new dbJSON($langLocaleFile, false);
}
if($database!==false)
{ {
$databaseArray = $database->db; $database = file_get_contents($languageFilename);
$database = json_decode($database, true);
// Theme data // Remote the name and description.
$theme = $themeMetaData; unset($database['theme-data']);
// Remove theme meta data // Load words from the theme language
unset($databaseArray['theme-data']); if(!empty($database)) {
$Language->add($database);
// Add new words/phrase from language theme }
$Language->add($databaseArray);
} }

View File

@ -14,7 +14,7 @@ class dbPages extends dbJSON
'date'=> array('inFile'=>false, 'value'=>''), 'date'=> array('inFile'=>false, 'value'=>''),
'position'=> array('inFile'=>false, 'value'=>0), 'position'=> array('inFile'=>false, 'value'=>0),
'coverImage'=> array('inFile'=>false, 'value'=>''), 'coverImage'=> array('inFile'=>false, 'value'=>''),
'hash'=> array('inFile'=>false, 'value'=>'') 'checksum'=> array('inFile'=>false, 'value'=>'')
); );
function __construct() function __construct()
@ -78,7 +78,7 @@ class dbPages extends dbJSON
// Create Hash // Create Hash
$serialize = serialize($dataForDb+$dataForFile); $serialize = serialize($dataForDb+$dataForFile);
$dataForDb['hash'] = sha1($serialize); $dataForDb['checksum'] = sha1($serialize);
// Make the directory. Recursive. // Make the directory. Recursive.
if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) { if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) {
@ -164,7 +164,7 @@ class dbPages extends dbJSON
// Create Hash // Create Hash
$serialize = serialize($dataForDb+$dataForFile); $serialize = serialize($dataForDb+$dataForFile);
$dataForDb['hash'] = sha1($serialize); $dataForDb['checksum'] = sha1($serialize);
// Move the directory from old key to new key. // Move the directory from old key to new key.
if($newKey!==$args['key']) if($newKey!==$args['key'])

View File

@ -12,7 +12,7 @@ class dbPosts extends dbJSON
'allowComments'=> array('inFile'=>false, 'value'=>false), 'allowComments'=> array('inFile'=>false, 'value'=>false),
'date'=> array('inFile'=>false, 'value'=>''), 'date'=> array('inFile'=>false, 'value'=>''),
'coverImage'=> array('inFile'=>false, 'value'=>''), 'coverImage'=> array('inFile'=>false, 'value'=>''),
'hash'=> array('inFile'=>false, 'value'=>'') 'checksum'=> array('inFile'=>false, 'value'=>'')
); );
private $numberPosts = array( private $numberPosts = array(
@ -161,7 +161,7 @@ class dbPosts extends dbJSON
// Create Hash // Create Hash
$serialize = serialize($dataForDb+$dataForFile); $serialize = serialize($dataForDb+$dataForFile);
$dataForDb['hash'] = sha1($serialize); $dataForDb['checksum'] = sha1($serialize);
// Make the directory. // Make the directory.
if( Filesystem::mkdir(PATH_POSTS.$key) === false ) { if( Filesystem::mkdir(PATH_POSTS.$key) === false ) {

View File

@ -224,5 +224,6 @@
"blog": "Blog", "blog": "Blog",
"more-images": "More images", "more-images": "More images",
"double-click-on-the-image-to-add-it": "Double click on the image to add it.", "double-click-on-the-image-to-add-it": "Double click on the image to add it.",
"click-here-to-cancel": "Click here to cancel." "click-here-to-cancel": "Click here to cancel.",
"type-the-tag-and-press-enter": "Type the tag and press enter."
} }