Example #1
0
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;
}
Example #2
0
function buildPlugins()
{
    global $plugins;
    global $pluginsEvents;
    global $Language;
    global $Site;
    // List plugins directories
    $list = Filesystem::listDirectories(PATH_PLUGINS);
    // Get declared clasess before load plugins clasess, this list doesn't have the plugins clasess.
    $currentDeclaredClasess = get_declared_classes();
    // Load each plugin clasess
    foreach ($list as $pluginPath) {
        // Check if the directory has the plugin.php
        if (file_exists($pluginPath . DS . 'plugin.php')) {
            include $pluginPath . DS . 'plugin.php';
        }
    }
    // Get plugins clasess loaded
    $pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
    foreach ($pluginsDeclaredClasess as $pluginClass) {
        $Plugin = new $pluginClass();
        // Check if the plugin is translated.
        $languageFilename = PATH_PLUGINS . $Plugin->directoryName() . DS . 'languages' . DS . $Site->locale() . '.json';
        if (!Sanitize::pathFile($languageFilename)) {
            $languageFilename = PATH_PLUGINS . $Plugin->directoryName() . DS . 'languages' . DS . 'en_US.json';
        }
        $database = file_get_contents($languageFilename);
        $database = json_decode($database, true);
        // Set name and description from the language file.
        $Plugin->setMetadata('name', $database['plugin-data']['name']);
        $Plugin->setMetadata('description', $database['plugin-data']['description']);
        // Remove name and description, and add new words if there are.
        unset($database['plugin-data']);
        if (!empty($database)) {
            $Language->add($database);
        }
        // Push Plugin to array all plugins installed and not installed.
        $plugins['all'][$pluginClass] = $Plugin;
        // If the plugin is installed, order by hooks.
        if ($Plugin->installed()) {
            foreach ($pluginsEvents as $event => $value) {
                if (method_exists($Plugin, $event)) {
                    array_push($plugins[$event], $Plugin);
                }
            }
        }
    }
}
Example #3
0
function build_plugins()
{
    global $plugins;
    global $pluginsEvents;
    global $Language;
    global $Site;
    // List plugins directories
    $list = Filesystem::listDirectories(PATH_PLUGINS);
    // Get declared clasess before load plugins clasess, this list doesn't have the plugins clasess.
    $currentDeclaredClasess = get_declared_classes();
    // Load each plugin clasess
    foreach ($list as $pluginPath) {
        include $pluginPath . DS . 'plugin.php';
    }
    // Get plugins clasess loaded
    $pluginsDeclaredClasess = array_diff(get_declared_classes(), $currentDeclaredClasess);
    foreach ($pluginsDeclaredClasess as $pluginClass) {
        $Plugin = new $pluginClass();
        // Default language and meta data for the plugin
        $tmpMetaData = array();
        $languageFilename = PATH_PLUGINS . $Plugin->directoryName() . DS . 'languages' . DS . 'en_US.json';
        $database = new dbJSON($languageFilename, false);
        $tmpMetaData = $database->db['plugin-data'];
        // Check if the plugin is translated.
        $languageFilename = PATH_PLUGINS . $Plugin->directoryName() . DS . 'languages' . DS . $Site->locale() . '.json';
        if (Sanitize::pathFile($languageFilename)) {
            $database = new dbJSON($languageFilename, false);
            $tmpMetaData = array_merge($tmpMetaData, $database->db['plugin-data']);
        }
        // Set plugin meta data
        $Plugin->setData($tmpMetaData);
        // Add words to language dictionary.
        unset($database->db['plugin-data']);
        $Language->add($database->db);
        // Push Plugin to array all plugins installed and not installed.
        $plugins['all'][$pluginClass] = $Plugin;
        // If the plugin is installed, order by hooks.
        if ($Plugin->installed()) {
            foreach ($pluginsEvents as $event => $value) {
                if (method_exists($Plugin, $event)) {
                    array_push($plugins[$event], $Plugin);
                }
            }
        }
    }
}
Example #4
0
 function __construct($locale)
 {
     $this->data = array();
     $this->db = array();
     $this->currentLocale = 'en_US';
     // Default language en_US
     $filename = PATH_LANGUAGES . 'en_US.json';
     if (Sanitize::pathFile($filename)) {
         $Tmp = new dbJSON($filename, false);
         $this->db = array_merge($this->db, $Tmp->db);
     }
     // User language
     $filename = PATH_LANGUAGES . $locale . '.json';
     if (Sanitize::pathFile($filename) && $locale !== "en_US") {
         $this->currentLocale = $locale;
         $Tmp = new dbJSON($filename, false);
         $this->db = array_merge($this->db, $Tmp->db);
     }
     $this->data = $this->db['language-data'];
     unset($this->db['language-data']);
 }
Example #5
0
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);
            if (empty($database)) {
                Log::set('99.themes.php' . LOG_SEP . 'Language file error on theme ' . $themePath);
                break;
            }
            $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['compatible'] = false;
                if (!empty($metadata['compatible'])) {
                    $explode = explode(',', $metadata['compatible']);
                    if (in_array(BLUDIT_VERSION, $explode)) {
                        $database['compatible'] = true;
                    }
                }
                $database = $database + $metadata;
                array_push($themes, $database);
            }
        }
    }
    return $themes;
}
Example #6
0
 private function build($path)
 {
     if (!Sanitize::pathFile($path . FILENAME)) {
         return false;
     }
     $tmp = 0;
     $lines = file($path . FILENAME);
     foreach ($lines as $lineNumber => $line) {
         $parts = array_map('trim', explode(':', $line, 2));
         // Lowercase variable
         $parts[0] = Text::lowercase($parts[0]);
         // If variables is content then break the foreach and process the content after.
         if ($parts[0] === 'content') {
             $tmp = $lineNumber;
             break;
         }
         if (!empty($parts[0]) && !empty($parts[1])) {
             // Sanitize all fields, except Content.
             $this->vars[$parts[0]] = Sanitize::html($parts[1]);
         }
     }
     // Process the content.
     if ($tmp !== 0) {
         // Next line after "Content:" variable
         $tmp++;
         // Remove lines after Content
         $output = array_slice($lines, $tmp);
         if (!empty($parts[1])) {
             array_unshift($output, "\n");
             array_unshift($output, $parts[1]);
         }
         $implode = implode($output);
         $this->vars['content'] = $implode;
         // Sanitize content.
         //$this->vars['content'] = Sanitize::html($implode);
     }
 }
Example #7
0
?>
</head>
<body class="uk-height-1-1">

<!-- Plugins -->
<?php 
Theme::plugins('loginBodyBegin');
?>

<div class="uk-vertical-align uk-text-center uk-height-1-1">
<div class="uk-vertical-align-middle login-box">
<h1>BLUDIT</h1>
<?php 
if (Alert::defined()) {
    echo '<div class="uk-alert uk-alert-danger">' . Alert::get() . '</div>';
}
if (Sanitize::pathFile(PATH_ADMIN_VIEWS, $layout['view'] . '.php')) {
    include PATH_ADMIN_VIEWS . $layout['view'] . '.php';
}
?>
</div>
</div>

<!-- Plugins -->
<?php 
Theme::plugins('loginBodyEnd');
?>

</body>
</html>
Example #8
0
    Redirect::page('admin', 'dashboard');
}
// ============================================================================
// Main after POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
$themes = array();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
foreach ($themesPaths as $themePath) {
    $langLocaleFile = $themePath . DS . 'languages' . DS . $Site->locale() . '.json';
    $langDefaultFile = $themePath . DS . 'languages' . DS . 'en_US.json';
    // Check if exists default language
    if (Sanitize::pathFile($langDefaultFile)) {
        $database = new dbJSON($langDefaultFile, false);
        $databaseArray = $database->db;
        $themeMetaData = $database->db['theme-data'];
        // Check if exists locale language
        if (Sanitize::pathFile($langLocaleFile)) {
            $database = new dbJSON($langLocaleFile, false);
            $themeMetaData = array_merge($themeMetaData, $database->db['theme-data']);
        }
        $themeMetaData['dirname'] = basename($themePath);
        // Theme data
        array_push($themes, $themeMetaData);
    }
}
Example #9
0
<?php

defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
// Request $_POST
// $filename: Name of file to delete, just the filename
$filename = isset($_POST['filename']) ? $_POST['filename'] : '';
if (empty($filename)) {
    echo json_encode(array('status' => 0, 'msg' => 'The filename is empty.'));
    exit;
}
// Check if the filename exist and Sanitize::pathFile it's necesary for security reasons.
if (Sanitize::pathFile(PATH_UPLOADS . $filename)) {
    // Delete the file.
    Filesystem::rmfile(PATH_UPLOADS . $filename);
    // Delete the thumnails.
    Filesystem::rmfile(PATH_UPLOADS_THUMBNAILS . $filename);
    echo json_encode(array('status' => 1, 'msg' => 'The file was deleted.'));
    exit;
}
echo json_encode(array('status' => 0, 'msg' => 'The file does not exist.'));
Example #10
0
    Redirect::page('admin', 'dashboard');
}
// ============================================================================
// Main after POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
$themes = array();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
// Load each plugin clasess
foreach ($themesPaths as $themePath) {
    $langLocaleFile = $themePath . DS . 'languages' . DS . $Site->locale() . '.json';
    $langDefaultFile = $themePath . DS . 'languages' . DS . 'en_US.json';
    $database = false;
    // Check if exists locale language
    if (Sanitize::pathFile($langLocaleFile)) {
        $database = new dbJSON($langLocaleFile, false);
    } elseif (Sanitize::pathFile($langDefaultFile)) {
        $database = new dbJSON($langDefaultFile, false);
    }
    if ($database !== false) {
        $databaseArray = $database->db;
        $databaseArray['theme-data']['dirname'] = basename($themePath);
        // Theme data
        array_push($themes, $databaseArray['theme-data']);
    }
}
Example #11
0
<?php

defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
if ($Login->role() !== 'admin') {
    Alert::set($Language->g('you-do-not-have-sufficient-permissions'));
    Redirect::page('admin', 'dashboard');
}
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
$themeDirname = $layout['parameters'];
if (Sanitize::pathFile(PATH_THEMES . $themeDirname)) {
    $Site->set(array('theme' => $themeDirname));
    Alert::set($Language->g('The changes have been saved'));
} else {
    Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to install the theme: ' . $themeDirname);
}
Redirect::page('admin', 'themes');
Example #12
0
 public function cliMode()
 {
     // LOG
     Log::set('CLI MODE - PAGES - Starting...');
     $pageList = array();
     $pagesDirectories = Filesystem::listDirectories(PATH_PAGES);
     foreach ($pagesDirectories as $directory) {
         if (Sanitize::pathFile($directory . DS . FILENAME)) {
             // The key is the directory name
             $key = basename($directory);
             // Add the page key to the list
             $pageList[$key] = true;
             // LOG
             Log::set('CLI MODE - Page found, key: ' . $key);
             // Search sub-pages
             $subPaths = Filesystem::listDirectories($directory . DS);
             foreach ($subPaths as $subDirectory) {
                 // The key of the sub-page
                 $subKey = basename($subDirectory);
                 if (Sanitize::pathFile($subDirectory . DS . FILENAME)) {
                     // Add the key of the sub-page, the key is composed by the directory/subdirectory
                     $pageList[$key . '/' . $subKey] = true;
                     // LOG
                     Log::set('CLI MODE - Page found, key: ' . $key);
                 }
             }
         }
     }
     foreach ($pageList as $key => $value) {
         if (!isset($this->db[$key])) {
             // LOG
             Log::set('CLI MODE - The page is not in the database, key: ' . $key);
             // Insert new post
             $this->cliModeInsert($key);
         } else {
             $checksum = md5_file(PATH_PAGES . $key . DS . FILENAME);
             // If checksum is different, update the post
             if (!isset($this->db[$key]['md5file']) || $this->db[$key]['md5file'] !== $checksum) {
                 // LOG
                 Log::set('CLI MODE - Different md5 checksum, key: ' . $key);
                 // Update the post
                 $this->cliModeInsert($key, $update = true);
             }
         }
     }
     // LOG
     Log::set('CLI MODE - Cleaning database...');
     foreach (array_diff_key($this->db, $pageList) as $key => $data) {
         // LOG
         Log::set('CLI MODE - Removing page from database, key: ' . $key);
         // Remove the page from database
         unset($this->db[$key]);
     }
     // Save the database
     $this->save();
     // LOG
     Log::set('CLI MODE - PAGES - Finishing...');
     return true;
 }
Example #13
0
// --- PHP Classes ---
include PATH_ABSTRACT . 'dbjson.class.php';
include PATH_HELPERS . 'sanitize.class.php';
include PATH_HELPERS . 'valid.class.php';
include PATH_HELPERS . 'text.class.php';
include PATH_HELPERS . 'log.class.php';
include PATH_HELPERS . 'date.class.php';
include PATH_KERNEL . 'dblanguage.class.php';
// --- LANGUAGE ---
// Try to detect language from HTTP
$explode = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$localeFromHTTP = empty($explode[0]) ? 'en_US' : str_replace('-', '_', $explode[0]);
if (isset($_GET['language'])) {
    $localeFromHTTP = Sanitize::html($_GET['language']);
}
if (!Sanitize::pathFile(PATH_LANGUAGES . $localeFromHTTP . '.json')) {
    $localeFromHTTP = 'en_US';
}
$Language = new dbLanguage($localeFromHTTP);
// --- LOCALE ---
setlocale(LC_ALL, $localeFromHTTP);
// --- TIMEZONE ---
// Check if timezone is defined in php.ini
$iniDate = ini_get('date.timezone');
if (empty($iniDate)) {
    // Timezone not defined in php.ini, then UTC as default.
    date_default_timezone_set('UTC');
}
// ============================================================================
// FUNCTIONS
// ============================================================================
Example #14
0
<?php

defined('BLUDIT') or die('Bludit CMS.');
// Boot rules
include PATH_RULES . '70.posts.php';
include PATH_RULES . '70.pages.php';
include PATH_RULES . '80.plugins.php';
include PATH_RULES . '99.header.php';
include PATH_RULES . '99.paginator.php';
include PATH_RULES . '99.themes.php';
// Plugins before site loaded
Theme::plugins('beforeSiteLoad');
// Theme init.php
if (Sanitize::pathFile(PATH_THEMES, $Site->theme() . DS . 'init.php')) {
    include PATH_THEMES . $Site->theme() . DS . 'init.php';
}
// Theme HTML
if (Sanitize::pathFile(PATH_THEMES, $Site->theme() . DS . 'index.php')) {
    include PATH_THEMES . $Site->theme() . DS . 'index.php';
} else {
    $Language->p('Please check your theme configuration');
}
// Plugins after site loaded
Theme::plugins('afterSiteLoad');
Example #15
0
    // User not logged.
    // Slug is login.
    // Slug is login-email.
    if ($Url->notFound() || !$Login->isLogged() || $Url->slug() === 'login' || $Url->slug() === 'login-email') {
        $layout['controller'] = 'login';
        $layout['view'] = 'login';
        $layout['template'] = 'login.php';
        if ($Url->slug() === 'login-email') {
            $layout['controller'] = 'login-email';
            $layout['view'] = 'login-email';
        }
        // Generate the tokenCSRF for the user not logged, when the user log-in the token will be change.
        $Security->generateTokenCSRF();
    }
    // Load plugins before the admin area will be load.
    Theme::plugins('beforeAdminLoad');
    // Load init.php if the theme has one.
    if (Sanitize::pathFile(PATH_ADMIN_THEMES, $Site->adminTheme() . DS . 'init.php')) {
        include PATH_ADMIN_THEMES . $Site->adminTheme() . DS . 'init.php';
    }
    // Load controller.
    if (Sanitize::pathFile(PATH_ADMIN_CONTROLLERS, $layout['controller'] . '.php')) {
        include PATH_ADMIN_CONTROLLERS . $layout['controller'] . '.php';
    }
    // Load view and theme.
    if (Sanitize::pathFile(PATH_ADMIN_THEMES, $Site->adminTheme() . DS . $layout['template'])) {
        include PATH_ADMIN_THEMES . $Site->adminTheme() . DS . $layout['template'];
    }
    // Load plugins after the admin area is loaded.
    Theme::plugins('afterAdminLoad');
}
Example #16
0
 public function regenerateCli()
 {
     $db = $this->db;
     $allPosts = array();
     $fields = array();
     $currentDate = Date::current(DB_DATE_FORMAT);
     // Generate default fields and values.
     foreach ($this->dbFields as $field => $options) {
         if (!$options['inFile']) {
             $fields[$field] = $options['value'];
         }
     }
     $fields['status'] = CLI_STATUS;
     $fields['date'] = $currentDate;
     $fields['username'] = CLI_USERNAME;
     // Get all posts from the first level of directories.
     $tmpPaths = Filesystem::listDirectories(PATH_POSTS);
     foreach ($tmpPaths as $directory) {
         // Check if the post have the index.txt file.
         if (Sanitize::pathFile($directory . DS . 'index.txt')) {
             // The key is the directory name.
             $key = basename($directory);
             $allPosts[$key] = true;
             // Create the new entry if not exist inside the DATABASE.
             if (!isset($this->db[$key])) {
                 // New entry on database with the default fields and values.
                 $this->db[$key] = $fields;
             }
             // Create the post from FILE.
             $Post = new Post($key);
             // Update all fields from FILE to DATABASE.
             foreach ($fields as $f => $v) {
                 // If the field exists on the FILE, update it.
                 if ($Post->getField($f)) {
                     $valueFromFile = $Post->getField($f);
                     if ($f == 'tags') {
                         // Generate tags array.
                         $this->db[$key]['tags'] = $this->generateTags($valueFromFile);
                     } elseif ($f == 'date') {
                         // Validate Date from file
                         if (Valid::date($valueFromFile, DB_DATE_FORMAT)) {
                             $this->db[$key]['date'] = $valueFromFile;
                             if ($valueFromFile > $currentDate) {
                                 $this->db[$key]['status'] = 'scheduled';
                             }
                         }
                     } else {
                         // Sanitize the values from file.
                         $this->db[$key][$f] = Sanitize::html($valueFromFile);
                     }
                 }
             }
         }
     }
     // Remove orphan posts from db, the orphan posts are posts deleted by hand (directory deleted).
     foreach (array_diff_key($db, $allPosts) as $key => $data) {
         unset($this->db[$key]);
     }
     // Sort posts before save.
     $this->sortByDate();
     // Save the database.
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return $this->db != $db;
 }