Improves on tag system
This commit is contained in:
parent
0abe9599cc
commit
030b9e6d15
@ -21,37 +21,4 @@ if($Login->role()!=='admin') {
|
||||
// Main after POST
|
||||
// ============================================================================
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$themes = buildThemes();
|
||||
|
@ -179,6 +179,19 @@ button.delete-button:hover {
|
||||
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 {
|
||||
|
||||
|
@ -20,7 +20,22 @@ class HTML {
|
||||
public static function formClose()
|
||||
{
|
||||
$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
|
||||
@ -52,22 +67,104 @@ class 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);
|
||||
|
||||
echo '<div id="jstagList"></div>';
|
||||
|
||||
$script = '<script>
|
||||
$("input[name=\"'.$args['name'].'\"]").autoComplete({
|
||||
minChars: 1,
|
||||
source: function(term, suggest){
|
||||
term = term.toLowerCase();
|
||||
var choices = ['.$args['words'].'];
|
||||
var matches = [];
|
||||
for (i=0; i<choices.length; i++)
|
||||
if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
|
||||
suggest(matches);
|
||||
}
|
||||
|
||||
'.$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,
|
||||
source: function(term, suggest){
|
||||
term = term.toLowerCase();
|
||||
var choices = ['.$args['words'].'];
|
||||
var matches = [];
|
||||
for (i=0; i<choices.length; i++)
|
||||
if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
|
||||
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>';
|
||||
|
||||
echo $script;
|
||||
@ -157,7 +254,7 @@ $("input[name=\"'.$args['name'].'\"]").autoComplete({
|
||||
$html = '<!-- BLUDIT QUICK IMAGES -->';
|
||||
$html .= '
|
||||
<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);
|
||||
|
@ -77,11 +77,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
|
||||
));
|
||||
|
||||
// Tags input
|
||||
HTML::formInputAutocomplete(array(
|
||||
HTML::tagsAutocomplete(array(
|
||||
'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',
|
||||
'tip'=>$L->g('Write the tags separated by commas'),
|
||||
'label'=>$L->g('Tags'),
|
||||
'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
|
||||
));
|
||||
|
@ -71,11 +71,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
|
||||
));
|
||||
|
||||
// Tags input
|
||||
HTML::formInputAutocomplete(array(
|
||||
HTML::tagsAutocomplete(array(
|
||||
'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',
|
||||
'tip'=>$L->g('Write the tags separated by commas'),
|
||||
'label'=>$L->g('Tags'),
|
||||
'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
|
||||
));
|
||||
|
@ -64,11 +64,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
|
||||
));
|
||||
|
||||
// Tags input
|
||||
HTML::formInputAutocomplete(array(
|
||||
HTML::tagsAutocomplete(array(
|
||||
'name'=>'tags',
|
||||
'value'=>'',
|
||||
'tip'=>$L->g('Type the tag and press enter'),
|
||||
'class'=>'uk-width-1-1 uk-form-large',
|
||||
'tip'=>$L->g('Write the tags separated by commas'),
|
||||
'label'=>$L->g('Tags'),
|
||||
'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
|
||||
));
|
||||
|
@ -64,11 +64,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
|
||||
));
|
||||
|
||||
// Tags input
|
||||
HTML::formInputAutocomplete(array(
|
||||
HTML::tagsAutocomplete(array(
|
||||
'name'=>'tags',
|
||||
'value'=>'',
|
||||
'tip'=>$L->g('Type the tag and press enter'),
|
||||
'class'=>'uk-width-1-1 uk-form-large',
|
||||
'tip'=>$L->g('Write the tags separated by commas'),
|
||||
'label'=>$L->g('Tags'),
|
||||
'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
|
||||
));
|
||||
|
@ -4,49 +4,72 @@
|
||||
// Variables
|
||||
// ============================================================================
|
||||
|
||||
$theme = array(
|
||||
'name'=>'',
|
||||
'description'=>'',
|
||||
'author'=>'',
|
||||
'email'=>'',
|
||||
'website'=>'',
|
||||
'version'=>'',
|
||||
'releaseDate'=>''
|
||||
);
|
||||
|
||||
// ============================================================================
|
||||
// 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
|
||||
// ============================================================================
|
||||
|
||||
$langLocaleFile = PATH_THEME.'languages'.DS.$Site->locale().'.json';
|
||||
$langDefaultFile = PATH_THEME.'languages'.DS.'en_US.json';
|
||||
$database = false;
|
||||
|
||||
// Theme meta data from English
|
||||
if( Sanitize::pathFile($langDefaultFile) ) {
|
||||
$database = new dbJSON($langDefaultFile, false);
|
||||
$themeMetaData = $database->db['theme-data'];
|
||||
// Load the language file
|
||||
$languageFilename = PATH_THEME.DS.'languages'.DS.$Site->locale().'.json';
|
||||
if( !Sanitize::pathFile($languageFilename) ) {
|
||||
$languageFilename = PATH_THEME.DS.'languages'.DS.'en_US.json';
|
||||
}
|
||||
|
||||
// Check if exists locale language
|
||||
if( Sanitize::pathFile($langLocaleFile) ) {
|
||||
$database = new dbJSON($langLocaleFile, false);
|
||||
}
|
||||
|
||||
if($database!==false)
|
||||
if( Sanitize::pathFile($languageFilename) )
|
||||
{
|
||||
$databaseArray = $database->db;
|
||||
$database = file_get_contents($languageFilename);
|
||||
$database = json_decode($database, true);
|
||||
|
||||
// Theme data
|
||||
$theme = $themeMetaData;
|
||||
// Remote the name and description.
|
||||
unset($database['theme-data']);
|
||||
|
||||
// Remove theme meta data
|
||||
unset($databaseArray['theme-data']);
|
||||
|
||||
// Add new words/phrase from language theme
|
||||
$Language->add($databaseArray);
|
||||
// Load words from the theme language
|
||||
if(!empty($database)) {
|
||||
$Language->add($database);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class dbPages extends dbJSON
|
||||
'date'=> array('inFile'=>false, 'value'=>''),
|
||||
'position'=> array('inFile'=>false, 'value'=>0),
|
||||
'coverImage'=> array('inFile'=>false, 'value'=>''),
|
||||
'hash'=> array('inFile'=>false, 'value'=>'')
|
||||
'checksum'=> array('inFile'=>false, 'value'=>'')
|
||||
);
|
||||
|
||||
function __construct()
|
||||
@ -78,7 +78,7 @@ class dbPages extends dbJSON
|
||||
|
||||
// Create Hash
|
||||
$serialize = serialize($dataForDb+$dataForFile);
|
||||
$dataForDb['hash'] = sha1($serialize);
|
||||
$dataForDb['checksum'] = sha1($serialize);
|
||||
|
||||
// Make the directory. Recursive.
|
||||
if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) {
|
||||
@ -164,7 +164,7 @@ class dbPages extends dbJSON
|
||||
|
||||
// Create Hash
|
||||
$serialize = serialize($dataForDb+$dataForFile);
|
||||
$dataForDb['hash'] = sha1($serialize);
|
||||
$dataForDb['checksum'] = sha1($serialize);
|
||||
|
||||
// Move the directory from old key to new key.
|
||||
if($newKey!==$args['key'])
|
||||
|
@ -12,7 +12,7 @@ class dbPosts extends dbJSON
|
||||
'allowComments'=> array('inFile'=>false, 'value'=>false),
|
||||
'date'=> array('inFile'=>false, 'value'=>''),
|
||||
'coverImage'=> array('inFile'=>false, 'value'=>''),
|
||||
'hash'=> array('inFile'=>false, 'value'=>'')
|
||||
'checksum'=> array('inFile'=>false, 'value'=>'')
|
||||
);
|
||||
|
||||
private $numberPosts = array(
|
||||
@ -161,7 +161,7 @@ class dbPosts extends dbJSON
|
||||
|
||||
// Create Hash
|
||||
$serialize = serialize($dataForDb+$dataForFile);
|
||||
$dataForDb['hash'] = sha1($serialize);
|
||||
$dataForDb['checksum'] = sha1($serialize);
|
||||
|
||||
// Make the directory.
|
||||
if( Filesystem::mkdir(PATH_POSTS.$key) === false ) {
|
||||
|
@ -224,5 +224,6 @@
|
||||
"blog": "Blog",
|
||||
"more-images": "More images",
|
||||
"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."
|
||||
}
|
Loading…
Reference in New Issue
Block a user