コード例 #1
0
ファイル: 99.themes.php プロジェクト: michaelctorres/bludit
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;
}
コード例 #2
0
ファイル: page.class.php プロジェクト: michaelctorres/bludit
 public function children()
 {
     $tmp = array();
     //$paths = glob(PATH_PAGES.$this->getField('key').DS.'*', GLOB_ONLYDIR);
     $paths = Filesystem::listDirectories(PATH_PAGES . $this->getField('key') . DS);
     foreach ($paths as $path) {
         array_push($tmp, basename($path));
     }
     return $tmp;
 }
コード例 #3
0
ファイル: 60.plugins.php プロジェクト: vorons/bludit
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);
                }
            }
        }
    }
}
コード例 #4
0
ファイル: 80.plugins.php プロジェクト: clstrfcuk/bludit
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);
                }
            }
        }
    }
}
コード例 #5
0
ファイル: 99.themes.php プロジェクト: vorons/bludit
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;
}
コード例 #6
0
ファイル: dbpages.class.php プロジェクト: clstrfcuk/bludit
 public function regenerateCli()
 {
     $db = $this->db;
     $newPaths = array();
     $fields = array();
     // Default fields and value
     foreach ($this->dbFields as $field => $options) {
         if (!$options['inFile']) {
             $fields[$field] = $options['value'];
         }
     }
     //$tmpPaths = glob(PATH_PAGES.'*', GLOB_ONLYDIR);
     $tmpPaths = Filesystem::listDirectories(PATH_PAGES);
     foreach ($tmpPaths as $directory) {
         $key = basename($directory);
         if (file_exists($directory . DS . 'index.txt')) {
             // The key is the directory name
             $newPaths[$key] = true;
         }
         // Recovery pages from subdirectories
         //$subPaths = glob($directory.DS.'*', GLOB_ONLYDIR);
         $subPaths = Filesystem::listDirectories($directory . DS);
         foreach ($subPaths as $subDirectory) {
             $subKey = basename($subDirectory);
             if (file_exists($subDirectory . DS . 'index.txt')) {
                 // The key is composed by the directory/subdirectory
                 $newPaths[$key . '/' . $subKey] = true;
             }
         }
     }
     foreach ($newPaths as $key => $value) {
         if (!isset($this->db[$key])) {
             // Default values for the new pages.
             $fields['status'] = CLI_STATUS;
             $fields['date'] = Date::current(DB_DATE_FORMAT);
             $fields['username'] = '******';
             // Create the entry for the new page.
             $this->db[$key] = $fields;
         }
         $Page = new Page($key);
         // Update all fields from FILE to DATABASE.
         foreach ($fields as $f => $v) {
             // If the field exists on the FILE, update it.
             if ($Page->getField($f)) {
                 $valueFromFile = $Page->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;
                     }
                 } else {
                     // Sanitize the values from file.
                     $this->db[$key][$f] = Sanitize::html($valueFromFile);
                 }
             }
         }
     }
     // Remove old pages from db
     foreach (array_diff_key($db, $newPaths) as $key => $data) {
         unset($this->db[$key]);
     }
     // 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;
 }
コード例 #7
0
ファイル: themes.php プロジェクト: rayblo/bludit
// ============================================================================
if ($Login->role() !== 'admin') {
    Alert::set($Language->g('you-do-not-have-sufficient-permissions'));
    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
コード例 #8
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'] = '******';
     // Recovery posts from the first level of directories
     $tmpPaths = Filesystem::listDirectories(PATH_POSTS);
     foreach ($tmpPaths as $directory) {
         if (file_exists($directory . DS . 'index.txt')) {
             // The key is the directory name.
             $key = basename($directory);
             // All keys posts
             $allPosts[$key] = true;
             // Create the new entry if not exists on DATABASE.
             if (!isset($this->db[$key])) {
                 // New entry on database
                 $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;
 }