Exemple #1
0
 function __construct($file, $firstLine = true)
 {
     $this->file = $file;
     $this->db = array();
     $this->dbBackup = array();
     $this->firstLine = $firstLine;
     if (file_exists($file)) {
         // Read JSON file.
         $lines = file($file);
         // Remove the first line, the first line is for security reasons.
         if ($firstLine) {
             unset($lines[0]);
         }
         // Regenerate the JSON file.
         $implode = implode($lines);
         // Unserialize, JSON to Array.
         $array = $this->unserialize($implode);
         if (empty($array)) {
             Log::set(__METHOD__ . LOG_SEP . 'Invalid JSON file: ' . $file . ', cannot be decoded. Check the file content.');
         } else {
             $this->db = $array;
             $this->dbBackup = $array;
         }
     } else {
         Log::set(__METHOD__ . LOG_SEP . 'File ' . $file . ' does not exists');
     }
 }
Exemple #2
0
function deleteUser($args, $deleteContent = false)
{
    global $dbUsers;
    global $dbPosts;
    global $Language;
    global $Login;
    // The user admin cannot be deleted.
    if ($args['username'] == 'admin') {
        return false;
    }
    // The editors cannot delete users.
    if ($Login->role() !== 'admin') {
        return false;
    }
    if ($deleteContent) {
        $dbPosts->deletePostsByUser($args['username']);
    } else {
        $dbPosts->linkPostsToUser($args['username'], 'admin');
    }
    if ($dbUsers->delete($args['username'])) {
        Alert::set($Language->g('User deleted'));
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to delete the user.');
    }
}
Exemple #3
0
function updateBludit()
{
    global $Site;
    global $dbPosts;
    // Check if Bludit need to be update.
    if ($Site->currentBuild() < BLUDIT_BUILD || isset($_GET['update'])) {
        // --- Update dates ---
        foreach ($dbPosts->db as $key => $post) {
            $date = Date::format($post['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
            if ($date !== false) {
                $dbPosts->setPostDb($key, 'date', $date);
            }
        }
        $dbPosts->save();
        // --- Update directories ---
        $directories = array(PATH_POSTS, PATH_PAGES, PATH_PLUGINS_DATABASES, PATH_UPLOADS_PROFILES, PATH_UPLOADS_THUMBNAILS, PATH_TMP);
        foreach ($directories as $dir) {
            // Check if the directory is already created.
            if (!file_exists($dir)) {
                // Create the directory recursive.
                mkdir($dir, DIR_PERMISSIONS, true);
            }
        }
        // Set and save the database.
        $Site->set(array('currentBuild' => BLUDIT_BUILD));
        Log::set('updateBludit' . LOG_SEP . 'System updated');
    }
}
Exemple #4
0
function addUser($args)
{
    global $dbUsers;
    global $Language;
    // Check if the username already exist in db.
    if (Text::isEmpty($args['username'])) {
        Alert::set($Language->g('username-field-is-empty'));
        return false;
    }
    if ($dbUsers->userExists($args['username'])) {
        Alert::set($Language->g('username-already-exists'));
        return false;
    }
    // Validate password.
    if ($args['password'] != $args['confirm-password'] || Text::isEmpty($args['password'])) {
        Alert::set($Language->g('The password and confirmation password do not match'));
        return false;
    }
    // Add the user.
    if ($dbUsers->add($args)) {
        Alert::set($Language->g('user-has-been-added-successfully'));
        return true;
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the account.');
        return false;
    }
}
Exemple #5
0
 public function __construct($form = null)
 {
     Log::set('Initialize Model class');
     if ($form !== false) {
         $this->_form = $form;
     }
     $this->setKeys();
 }
Exemple #6
0
 /**
  * Constructor
  *
  * @access    public
  */
 public function __construct($props = [])
 {
     if (count($props) > 0) {
         $this->initialize($props);
     }
     Log::set('Initialize Upload class');
     //		log_message('debug', "Upload Class Initialized");
 }
 public static function destroy()
 {
     session_destroy();
     unset($_SESSION);
     self::$started = false;
     Log::set(__METHOD__ . LOG_SEP . 'Session destroyed.');
     return !isset($_SESSION);
 }
Exemple #8
0
function updateBludit()
{
    global $Site;
    global $dbPosts;
    global $dbPages;
    // Check if Bludit need to be update.
    if ($Site->currentBuild() < BLUDIT_BUILD || isset($_GET['update'])) {
        // LOG
        Log::set('UPDATE SYSTEM - Starting...');
        // LOG
        Log::set('UPDATE SYSTEM - Checking posts.');
        // Update posts
        foreach ($dbPosts->db as $key => $post) {
            // Dates
            $date = Date::format($post['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
            if ($date !== false) {
                $dbPosts->setPostDb($key, 'date', $date);
            }
            // Checksum
            if (empty($post['md5file'])) {
                $checksum = md5_file(PATH_POSTS . $key . DS . FILENAME);
                $dbPosts->setPostDb($key, 'md5file', $checksum);
            }
        }
        $dbPosts->save();
        // LOG
        Log::set('UPDATE SYSTEM - Checking pages.');
        // Update pages
        foreach ($dbPages->db as $key => $page) {
            $date = Date::format($page['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
            if ($date !== false) {
                $dbPages->setPageDb($key, 'date', $date);
            }
            // Checksum
            if (empty($post['md5file'])) {
                $checksum = md5_file(PATH_PAGES . $key . DS . FILENAME);
                $dbPages->setPageDb($key, 'md5file', $checksum);
            }
        }
        $dbPages->save();
        // LOG
        Log::set('UPDATE SYSTEM - Checking directories.');
        // --- Update directories ---
        $directories = array(PATH_POSTS, PATH_PAGES, PATH_PLUGINS_DATABASES, PATH_UPLOADS_PROFILES, PATH_UPLOADS_THUMBNAILS, PATH_TMP);
        foreach ($directories as $dir) {
            // Check if the directory is already created.
            if (!file_exists($dir)) {
                // Create the directory recursive.
                mkdir($dir, DIR_PERMISSIONS, true);
            }
        }
        // Set and save the database.
        $Site->set(array('currentBuild' => BLUDIT_BUILD));
        // LOG
        Log::set('UPDATE SYSTEM - Updated...');
    }
}
Exemple #9
0
 public function __construct()
 {
     Log::set('Initialize Debug class');
     if (ENVIRONMENT == 'development') {
         if ((!isset($_SERVER['HTTP_X_REQUESTED_WITH']) or $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') && !CMD_MODE) {
             $this->displayDebugger();
         }
     }
 }
Exemple #10
0
 private function ping()
 {
     if ($this->getDbField('ping')) {
         // Get the authentication key
         $authKey = $this->getDbField('authKey');
         // Just a request HTTP with the website URL
         Log::set(file_get_contents('https://www.bludit.com/api.php?authKey=' . $authKey));
     }
 }
 public function addLoginFail()
 {
     $ip = $this->getUserIp();
     // Save the database
     $this->db[$ip] = (int) $this->db[$ip] + 1;
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return true;
 }
Exemple #12
0
function deletePage($key)
{
    global $dbPages;
    global $Language;
    if ($dbPages->delete($key)) {
        Alert::set($Language->g('The page has been deleted successfully'));
        Redirect::page('admin', 'manage-pages');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to delete the page.');
    }
}
Exemple #13
0
 public function __construct()
 {
     Log::set('Initialize Input class');
     $this->input = ['cookie' => $_COOKIE, 'get' => $_GET, 'post' => $_POST, 'request' => $_REQUEST, 'files' => $_FILES, 'server' => $_SERVER, 'env' => $_ENV];
     if ($this->cookie('session_id')) {
         session_id($this->cookie('session_id'));
     }
     if (Brightery::SuperInstance()->Config->get('Config.enable_session')) {
         $this->activateSession();
     }
     array_walk_recursive($this->input, 'self::InputFilter');
 }
Exemple #14
0
function addPage($args)
{
    global $dbPages;
    global $Language;
    // Add the page.
    if ($dbPages->add($args)) {
        Alert::set($Language->g('Page added successfully'));
        Redirect::page('admin', 'manage-pages');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the page.');
    }
}
Exemple #15
0
function deletePost($key)
{
    global $dbPosts;
    global $Language;
    if ($dbPosts->delete($key)) {
        // Reindex tags, this function is in 70.posts.php
        reIndexTagsPosts();
        Alert::set($Language->g('The post has been deleted successfully'));
        Redirect::page('admin', 'manage-posts');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to delete the post.');
    }
}
Exemple #16
0
function deletePage($key)
{
    global $dbPages;
    global $Language;
    if ($dbPages->delete($key)) {
        // Call the plugins after post created.
        Theme::plugins('afterPageDelete');
        Alert::set($Language->g('The page has been deleted successfully'));
        Redirect::page('admin', 'manage-pages');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to delete the page.');
    }
}
Exemple #17
0
 public function __construct()
 {
     Log::set('Initialize Router class');
     define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']);
     $this->route = Brightery::SuperInstance()->Config->get('Route');
     unset($this->route['default']);
     $this->controllerPaths = new stdClass();
     $this->controllerPaths->root = APPLICATION . '/controllers';
     $this->controllerPaths->modules = APPLICATION . '/modules/*/controllers';
     //        $this->request = $this->app->request;
     //        $this->headers = $this->app->request->headers;
     //        $this->userAgent = $this->app->request->getUserAgent();
 }
Exemple #18
0
 public function set($args)
 {
     foreach ($args as $field => $value) {
         if (isset($this->dbFields[$field])) {
             $this->db[$field] = Sanitize::html($value);
         }
     }
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return true;
 }
function buildPost($key)
{
    global $dbPosts;
    global $dbUsers;
    global $Parsedown;
    global $Site;
    // Post object.
    $Post = new Post($key);
    if (!$Post->isValid()) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the post from file with key: ' . $key);
        return false;
    }
    // Page database.
    $db = $dbPosts->getDb($key);
    if (!$db) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the post from database with key: ' . $key);
        return false;
    }
    // Foreach field from database.
    foreach ($db as $field => $value) {
        if ($field == 'unixTimeCreated') {
            // Format dates, not overwrite from file fields.
            $Post->setField('unixTimeCreated', $value, false);
            $Post->setField('date', Date::format($value, '%d %B'), false);
            $Post->setField('timeago', Date::timeago($value), false);
        } else {
            // Other fields, not overwrite from file fields.
            $Post->setField($field, $value, false);
        }
    }
    // Content in raw format
    $contentRaw = $Post->content();
    $Post->setField('contentRaw', $contentRaw, true);
    // Parse the content
    $content = $Parsedown->text($contentRaw);
    // Parse Markdown.
    $content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS);
    // Parse img src relative to absolute.
    $Post->setField('content', $content, true);
    // Pagebrake
    $explode = explode(PAGE_BREAK, $content);
    $Post->setField('breakContent', $explode[0], true);
    $Post->setField('readMore', !empty($explode[1]), true);
    // Parse username for the post.
    if ($dbUsers->userExists($Post->username())) {
        $user = $dbUsers->getDb($Post->username());
        $Post->setField('authorFirstName', $user['firstName'], false);
        $Post->setField('authorLastName', $user['lastName'], false);
    }
    return $Post;
}
Exemple #20
0
function buildPost($key)
{
    global $dbPosts;
    global $dbUsers;
    global $Parsedown;
    global $Site;
    // Post object, content from FILE.
    $Post = new Post($key);
    if (!$Post->isValid()) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the post from file with key: ' . $key);
        return false;
    }
    // Post database, content from DATABASE JSON.
    $db = $dbPosts->getDb($key);
    if (!$db) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the post from database with key: ' . $key);
        return false;
    }
    // Foreach field from DATABASE.
    foreach ($db as $field => $value) {
        $Post->setField($field, $value);
    }
    // Content in raw format
    $contentRaw = $Post->content();
    $Post->setField('contentRaw', $contentRaw, true);
    // Parse the content
    $content = Text::pre2htmlentities($contentRaw);
    // Parse pre code with htmlentities
    $content = $Parsedown->text($content);
    // Parse Markdown.
    $content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS);
    // Parse img src relative to absolute.
    $Post->setField('content', $content, true);
    // Pagebrake
    $explode = explode(PAGE_BREAK, $content);
    $Post->setField('breakContent', $explode[0], true);
    $Post->setField('readMore', !empty($explode[1]), true);
    // Date format
    $postDate = $Post->date();
    $Post->setField('dateRaw', $postDate, true);
    $postDateFormated = $Post->dateRaw($Site->dateFormat());
    $Post->setField('date', $postDateFormated, true);
    // Parse username for the post.
    if ($dbUsers->userExists($Post->username())) {
        $user = $dbUsers->getDb($Post->username());
        $Post->setField('authorFirstName', $user['firstName'], false);
        $Post->setField('authorLastName', $user['lastName'], false);
    }
    return $Post;
}
Exemple #21
0
 private static function getImage($url)
 {
     $logElements = array();
     $startTime = microtime(true);
     $url = (string) $url;
     $name = end(explode("/", $url));
     $filename = self::$imagePath . "/" . $name;
     $result = file_put_contents($filename, file_get_contents($url));
     $endTime = microtime(true);
     $execTime = number_format($endTime - $startTime, 5);
     $logElements[] = $url;
     $logElements[] = $result;
     $logElements[] = $execTime;
     Log::set(implode(',', $logElements));
 }
Exemple #22
0
function addPost($args)
{
    global $dbPosts;
    global $Language;
    // Add the page.
    if ($dbPosts->add($args)) {
        // Reindex tags, this function is in 70.posts.php
        reIndexTagsPosts();
        Alert::set($Language->g('Post added successfully'));
        Redirect::page('admin', 'manage-posts');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the post.');
    }
    return false;
}
Exemple #23
0
function addPage($args)
{
    global $dbPages;
    global $Language;
    // Add the page, if the $key is FALSE the creation of the post failure.
    $key = $dbPages->add($args);
    if ($key) {
        // Call the plugins after page created.
        Theme::plugins('afterPageCreate');
        // Alert the user
        Alert::set($Language->g('Page added successfully'));
        Redirect::page('admin', 'manage-pages');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the page.');
    }
}
Exemple #24
0
function buildPage($key)
{
    global $dbPages;
    global $dbUsers;
    global $Parsedown;
    global $Site;
    // Page object, content from FILE.
    $Page = new Page($key);
    if (!$Page->isValid()) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the page from file with key: ' . $key);
        return false;
    }
    // Page database, content from DATABASE JSON.
    $db = $dbPages->getPageDB($key);
    if (!$db) {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying build the page from database with key: ' . $key);
        return false;
    }
    // Foreach field from DATABASE.
    foreach ($db as $field => $value) {
        $Page->setField($field, $value);
    }
    // Content in raw format
    $contentRaw = $Page->content();
    $Page->setField('contentRaw', $Page->content(), true);
    // Parse markdown content.
    $content = Text::pre2htmlentities($contentRaw);
    // Parse pre code with htmlentities
    $content = $Parsedown->text($content);
    // Parse Markdown.
    $content = Text::imgRel2Abs($content, HTML_PATH_UPLOADS);
    // Parse img src relative to absolute.
    $Page->setField('content', $content, true);
    // Pagebrake
    $explode = explode(PAGE_BREAK, $content);
    $Page->setField('breakContent', $explode[0], true);
    $Page->setField('readMore', !empty($explode[1]), true);
    // Date format
    $pageDate = $Page->date();
    $Page->setField('dateRaw', $pageDate, true);
    $pageDateFormated = $Page->dateRaw($Site->dateFormat());
    $Page->setField('date', $pageDateFormated, true);
    // User object
    $username = $Page->username();
    $Page->setField('user', $dbUsers->getUser($username));
    return $Page;
}
Exemple #25
0
 public function __construct()
 {
     Log::set('Initialize Path class');
     $this->stdin();
     $this->path['self'] = pathinfo(__FILE__, PATHINFO_BASENAME);
     $this->path['styles'] = Brightery::pathBuilder([ROOT, 'styles']);
     $this->path['source'] = Brightery::pathBuilder([ROOT, 'source']);
     $this->path['system'] = Brightery::pathBuilder([$this->path['source'], SYSTEM_FOLDER]);
     $this->path['cdn'] = Brightery::pathBuilder([ROOT, 'cdn']);
     $this->path['application'] = Brightery::pathBuilder([$this->path['source'], 'app']);
     $this->path['controllers'] = Brightery::pathBuilder([$this->path['application'], 'controllers']);
     $this->path['models'] = Brightery::pathBuilder([$this->path['application'], 'models']);
     $this->path['helpers'] = Brightery::pathBuilder([$this->path['application'], 'helpers']);
     $this->path['system_helpers'] = Brightery::pathBuilder([$this->path['system'], 'helpers']);
     $this->path['libraries'] = Brightery::pathBuilder([$this->path['application'], 'libraries']);
     $this->pathConstants();
 }
Exemple #26
0
function updateBludit()
{
    global $Site;
    // Check if Bludit need to be update.
    if ($Site->currentBuild() < BLUDIT_BUILD || isset($_GET['update'])) {
        $directories = array(PATH_POSTS, PATH_PAGES, PATH_PLUGINS_DATABASES, PATH_UPLOADS_PROFILES, PATH_UPLOADS_THUMBNAILS, PATH_TMP);
        foreach ($directories as $dir) {
            // Check if the directory is already created.
            if (!file_exists($dir)) {
                // Create the directory recursive.
                mkdir($dir, DIR_PERMISSIONS, true);
            }
        }
        // Set and save the database.
        $Site->set(array('currentBuild' => BLUDIT_BUILD));
        Log::set('updateBludit' . LOG_SEP . 'System updated');
    }
}
Exemple #27
0
function addPost($args)
{
    global $dbPosts;
    global $Language;
    // Page status, published or draft.
    if (isset($args['publish'])) {
        $args['status'] = "published";
    } else {
        $args['status'] = "draft";
    }
    // Add the page.
    if ($dbPosts->add($args)) {
        Alert::set($Language->g('Post added successfully'));
        Redirect::page('admin', 'manage-posts');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the post.');
    }
}
Exemple #28
0
 public function save()
 {
     $data = '';
     if ($this->firstLine) {
         $data = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>" . PHP_EOL;
     }
     // Serialize database
     $data .= $this->serialize($this->db);
     // Backup the new database.
     $this->dbBackup = $this->db;
     // LOCK_EX flag to prevent anyone else writing to the file at the same time.
     if (file_put_contents($this->file, $data, LOCK_EX)) {
         return true;
     } else {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
 }
Exemple #29
0
function addPost($args)
{
    global $dbPosts;
    global $Language;
    // Add the page, if the $key is FALSE the creation of the post failure.
    $key = $dbPosts->add($args);
    if ($key) {
        // Reindex tags, this function is in 70.posts.php
        reIndexTagsPosts();
        // Call the plugins after post created.
        Theme::plugins('afterPostCreate');
        // Alert for the user
        Alert::set($Language->g('Post added successfully'));
        Redirect::page('admin', 'manage-posts');
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the post.');
    }
    return false;
}
function setSettings($args)
{
    global $Site;
    global $Language;
    // Add slash at the begin and end.
    // This fields are in the settings->advanced mode
    $args['url'] = Text::addSlashes($args['url'], false, true);
    $args['uriPost'] = Text::addSlashes($args['uriPost']);
    $args['uriPage'] = Text::addSlashes($args['uriPage']);
    $args['uriTag'] = Text::addSlashes($args['uriTag']);
    if ($args['uriPost'] == $args['uriPage'] || $args['uriPost'] == $args['uriTag'] || $args['uriPage'] == $args['uriTag']) {
        $args = array();
    }
    if ($Site->set($args)) {
        Alert::set($Language->g('the-changes-have-been-saved'));
    } else {
        Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the settings.');
    }
    return true;
}