Example #1
0
 /**
  * Get pages
  *
  *  <code>
  *      $pages = Pages::getPages('blog');
  *  </code>
  *
  * @access  public
  * @param  string  $url        Url
  * @param  string  $order_by   Order by
  * @param  string  $order_type Order type
  * @param  array   $ignore     Pages to ignore
  * @param  int     $limit      Limit of pages
  * @return array
  */
 public static function getPages($url = '', $order_by = 'date', $order_type = 'DESC', $ignore = array('404'), $limit = null)
 {
     $pages = File::scan(STORAGE_PATH . '/pages/' . $url, 'md');
     if ($pages) {
         foreach ($pages as $page) {
             $pages_cache_id .= filemtime($page);
         }
         // Create Unique Cache ID for Pages
         $pages_cache_id = md5('pages' . ROOT_DIR . $url . $order_by . $order_type . implode(",", $ignore) . ($limit === null ? 'null' : $limit) . $pages_cache_id);
     }
     if (Cache::driver()->contains($pages_cache_id)) {
         return Cache::driver()->fetch($pages_cache_id);
     } else {
         foreach ($pages as $key => $page) {
             if (!in_array(basename($page, '.md'), $ignore)) {
                 $content = file_get_contents($page);
                 $_page = explode('---', $content, 3);
                 $_pages[$key] = Yaml::parse($_page[1]);
                 $url = str_replace(STORAGE_PATH . '/pages', Url::getBase(), $page);
                 $url = str_replace('index.md', '', $url);
                 $url = str_replace('.md', '', $url);
                 $url = str_replace('\\', '/', $url);
                 $url = rtrim($url, '/');
                 $_pages[$key]['url'] = $url;
                 $_content = $_page[2];
                 // Parse page for summary <!--more-->
                 if (($pos = strpos($_content, "<!--more-->")) === false) {
                     $_content = Filter::apply('content', $_content);
                 } else {
                     $_content = explode("<!--more-->", $_content);
                     $_content['summary'] = Filter::apply('content', $_content[0]);
                     $_content['content'] = Filter::apply('content', $_content[0] . $_content[1]);
                 }
                 if (is_array($_content)) {
                     $_pages[$key]['summary'] = $_content['summary'];
                     $_pages[$key]['content'] = $_content['content'];
                 } else {
                     $_pages[$key]['summary'] = $_content;
                     $_pages[$key]['content'] = $_content;
                 }
                 $_pages[$key]['slug'] = basename($page, '.md');
             }
         }
         $_pages = Arr::subvalSort($_pages, $order_by, $order_type);
         if ($limit != null) {
             $_pages = array_slice($_pages, null, $limit);
         }
         Cache::driver()->save($pages_cache_id, $_pages);
         return $_pages;
     }
 }
Example #2
0
 /**
  * Constructor.
  *
  * @access  protected
  */
 protected function __construct()
 {
     $blocks_cache_id = '';
     $blocks = File::scan(STORAGE_PATH . '/blocks', 'md');
     foreach ($blocks as $block) {
         $blocks_cache_id .= filemtime($block);
     }
     // Create Unique Cache ID for Block
     $blocks_cache_id = md5('blocks' . ROOT_DIR . $blocks_cache_id);
     if (Cache::driver()->contains($blocks_cache_id)) {
         Cache::driver()->fetch($blocks_cache_id);
     } else {
         Config::set('system.pages.flush_cache', true);
         Cache::driver()->save($blocks_cache_id, $blocks_cache_id);
     }
 }
 /**
  * Main Emails admin function
  */
 public static function main()
 {
     // Init vars
     $email_templates_path = STORAGE . DS . 'emails' . DS;
     $email_templates_list = array();
     // Check for get actions
     // -------------------------------------
     if (Request::get('action')) {
         // Switch actions
         // -------------------------------------
         switch (Request::get('action')) {
             // Plugin action
             // -------------------------------------
             case "edit_email_template":
                 if (Request::post('edit_email_template') || Request::post('edit_email_template_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         // Save Email Template
                         File::setContent(STORAGE . DS . 'emails' . DS . Request::post('email_template_name') . '.email.php', Request::post('content'));
                         Notification::set('success', __('Your changes to the email template <i>:name</i> have been saved.', 'emails', array(':name' => Request::post('email_template_name'))));
                         if (Request::post('edit_email_template_and_exit')) {
                             Request::redirect('index.php?id=emails');
                         } else {
                             Request::redirect('index.php?id=emails&action=edit_email_template&filename=' . Request::post('email_template_name'));
                         }
                     }
                 }
                 $content = File::getContent($email_templates_path . Request::get('filename') . '.email.php');
                 // Display view
                 View::factory('box/emails/views/backend/edit')->assign('content', $content)->display();
                 break;
         }
     } else {
         // Get email templates
         $email_templates_list = File::scan($email_templates_path, '.email.php');
         // Display view
         View::factory('box/emails/views/backend/index')->assign('email_templates_list', $email_templates_list)->display();
     }
 }
 /**
  * Backup admin
  */
 public static function main()
 {
     $backups_path = ROOT . DS . 'backups';
     // Create backup
     // -------------------------------------
     if (Request::post('create_backup')) {
         if (Security::check(Request::post('csrf'))) {
             @set_time_limit(0);
             @ini_set("memory_limit", "512M");
             $zip = Zip::factory();
             // Add storage folder
             $zip->readDir(STORAGE . DS, false);
             // Add public folder
             $zip->readDir(ROOT . DS . 'public' . DS, false);
             // Add plugins folder
             $zip->readDir(PLUGINS . DS, false, null, array(PLUGINS . DS . 'box'));
             if ($zip->archive($backups_path . DS . Date::format(time(), "Y-m-d-H-i-s") . '.zip')) {
                 Notification::set('success', __('Backup was created', 'backup'));
             } else {
                 Notification::set('error', __('Backup was not created', 'backup'));
             }
             Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Delete backup
     // -------------------------------------
     if (Request::get('id') == 'backup' && Request::get('delete_file')) {
         if (Security::check(Request::get('token'))) {
             if (File::delete($backups_path . DS . Request::get('delete_file'))) {
                 Notification::set('success', __('Backup was deleted', 'backup'));
             } else {
                 Notification::set('error', __('Backup was not deleted', 'backup'));
             }
             Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Download backup
     // -------------------------------------
     if (Request::get('download')) {
         if (Security::check(Request::get('token'))) {
             File::download($backups_path . DS . Request::get('download'));
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Restore backup
     // -------------------------------------
     if (Request::get('restore')) {
         if (Security::check(Request::get('token'))) {
             $tmp_dir = ROOT . DS . 'tmp' . DS . uniqid('backup_');
             if (Dir::create($tmp_dir)) {
                 $file_locations = Zip::factory()->extract($backups_path . DS . Request::get('restore'), $tmp_dir);
                 if (!empty($file_locations)) {
                     Dir::copy($tmp_dir, ROOT . DS);
                     Notification::set('success', __('Backup was restored', 'backup'));
                 } else {
                     Notification::set('error', __('Unzip error', 'backup'));
                 }
             } else {
                 Notification::set('error', __('Backup was not restored', 'backup'));
             }
             Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Display view
     View::factory('box/backup/views/backend/index')->assign('backups_list', File::scan($backups_path, '.zip'))->display();
 }
Example #5
0
      *   }
      *
      */
     $json = json_decode(File::getContent($mediaFile), true);
 } else {
     die('OOps Whrere is media.json file!');
 }
 // get single id of album or all albums
 if (Request::get('action') == 'view' && Request::get('id')) {
     // id of album
     $id = Request::get('id');
     if ($id) {
         // get id on json
         $media = $json[$id];
         // get all images of this album
         $mediaImages = File::scan(ROOT_DIR . $media['images']);
         // get images of this album
         $albumImages = '';
         // check files
         if (count($mediaImages) > 0) {
             foreach ($mediaImages as $image) {
                 $albumImages .= '<img class="thumbnail img-responsive" src="public/media/albums/album_' . $id . '/' . File::name($image) . '.' . File::ext($image) . '">';
             }
         }
         // template
         $templateSingle = '<h3>' . toHtml($media['title']) . '</h3>
         ' . toHtml($media['desc']) . '
         <p><b>Tag: </b><span class="label label-info">' . toHtml($media['tag']) . '</span></p>' . $albumImages;
         // return
         echo $templateSingle;
     }
Example #6
0
 /**
  * Clean Monstra TMP folder.
  */
 public static function cleanTmp()
 {
     // Cleanup minify
     if (count($files = File::scan(MINIFY, array('css', 'js', 'php'))) > 0) {
         foreach ($files as $file) {
             File::delete(MINIFY . DS . $file);
         }
     }
     // Cleanup cache
     if (count($namespaces = Dir::scan(CACHE)) > 0) {
         foreach ($namespaces as $namespace) {
             Dir::delete(CACHE . DS . $namespace);
         }
     }
 }
    if (Session::exists('user')) {
        // show pages
        $p->view('pages', ['title' => Panel::$lang['Pages'], 'content' => File::scan(ROOTBASE . DS . 'storage' . DS . 'pages')]);
    } else {
        Request::redirect($p::$site['url'] . '/' . $p::$site['backend_folder']);
    }
});
/*
* @name   Blocks
* @desc   if session user get Blocks
* @desc   if not redirecto to login page
*/
$p->route('/blocks', function () use($p) {
    if (Session::exists('user')) {
        // show pages
        $p->view('blocks', ['title' => Panel::$lang['Blocks'], 'content' => File::scan(ROOTBASE . DS . 'storage' . DS . 'blocks')]);
    } else {
        Request::redirect($p::$site['url'] . '/' . $p::$site['backend_folder']);
    }
});
/*  Action functions
-------------------------------------*/
/*
* @name   Logout
* @desc   rediterct to hombe url
*/
$p->route('/action/logout', function () use($p) {
    if (Session::exists('user')) {
        Session::delete('user');
        Session::destroy();
        Request::redirect($p::$site['url']);
Example #8
0
 /**
  * Get pages
  *
  *  <code>
  *      $pages = Morfy::getPages('blog');
  *  </code>
  *
  * @access  public
  * @param  string  $url        Url
  * @param  string  $order_by   Order by
  * @param  string  $order_type Order type
  * @param  array   $ignore     Pages to ignore
  * @param  int     $limit      Limit of pages
  * @return array
  */
 public static function getPages($url = '', $order_by = 'date', $order_type = 'DESC', $ignore = array('404'), $limit = null)
 {
     $pages = File::scan(PAGES_PATH . '/' . $url, 'md');
     foreach ($pages as $key => $page) {
         if (!in_array(basename($page, '.md'), $ignore)) {
             $content = file_get_contents($page);
             $_page = explode('---', $content, 3);
             $_pages[$key] = Spyc::YAMLLoad($_page[1]);
             $url = str_replace(PAGES_PATH, static::$site['url'], $page);
             $url = str_replace('index.md', '', $url);
             $url = str_replace('.md', '', $url);
             $url = str_replace('\\', '/', $url);
             $url = rtrim($url, '/');
             $_pages[$key]['url'] = $url;
             $_content = static::parseContent($_page[2]);
             if (is_array($_content)) {
                 $_pages[$key]['summary'] = $_content['summary'];
                 $_pages[$key]['content'] = $_content['content'];
             } else {
                 $_pages[$key]['summary'] = $_content;
                 $_pages[$key]['content'] = $_content;
             }
             $_pages[$key]['slug'] = basename($page, '.md');
         }
     }
     $_pages = Arr::subvalSort($_pages, $order_by, $order_type);
     if ($limit != null) {
         $_pages = array_slice($_pages, null, $limit);
     }
     return $_pages;
 }
 /**
  * Plugins admin
  */
 public static function main()
 {
     // Get siteurl
     $site_url = Option::get('siteurl');
     // Get installed plugin from $plugins array
     $installed_plugins = Plugin::$plugins;
     // Get installed users plugins
     $_users_plugins = array();
     foreach (Plugin::$plugins as $plugin) {
         if ($plugin['privilege'] !== 'box') {
             $_users_plugins[] = $plugin['id'];
         }
     }
     // Get plugins table
     $plugins = new Table('plugins');
     // Delete plugin
     // -------------------------------------
     if (Request::get('delete_plugin')) {
         if (Security::check(Request::get('token'))) {
             // Nobody cant remove box plugins
             if ($installed_plugins[Text::lowercase(str_replace("Plugin", "", Request::get('delete_plugin')))]['privilege'] !== 'box') {
                 // Run plugin uninstaller file
                 $plugin_name = Request::get('delete_plugin');
                 if (File::exists(PLUGINS . DS . $plugin_name . DS . 'install' . DS . $plugin_name . '.uninstall.php')) {
                     include PLUGINS . DS . $plugin_name . DS . 'install' . DS . $plugin_name . '.uninstall.php';
                 }
                 // Clean Monstra TMP folder.
                 Monstra::cleanTmp();
                 // Increment Styles and Javascript version
                 Stylesheet::stylesVersionIncrement();
                 Javascript::javascriptVersionIncrement();
                 // Delete plugin form plugins table
                 $plugins->deleteWhere('[name="' . Request::get('delete_plugin') . '"]');
                 // Redirect
                 Request::redirect('index.php?id=plugins');
             }
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Install new plugin
     // -------------------------------------
     if (Request::get('install')) {
         if (Security::check(Request::get('token'))) {
             // Load plugin install xml file
             $plugin_xml = XML::loadFile(PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . Request::get('install'));
             // Add plugin to plugins table
             $plugins->insert(array('name' => basename(Request::get('install'), '.manifest.xml'), 'location' => (string) $plugin_xml->plugin_location, 'status' => (string) $plugin_xml->plugin_status, 'priority' => (int) $plugin_xml->plugin_priority));
             // Clean Monstra TMP folder.
             Monstra::cleanTmp();
             Stylesheet::stylesVersionIncrement();
             Javascript::javascriptVersionIncrement();
             // Run plugin installer file
             $plugin_name = str_replace(array("Plugin", ".manifest.xml"), "", Request::get('install'));
             if (File::exists(PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . $plugin_name . '.install.php')) {
                 include PLUGINS . DS . basename(Text::lowercase(Request::get('install')), '.manifest.xml') . DS . 'install' . DS . $plugin_name . '.install.php';
             }
             Request::redirect('index.php?id=plugins');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Delete plugin from server
     // -------------------------------------
     if (Request::get('delete_plugin_from_server')) {
         if (Security::check(Request::get('token'))) {
             // Clean Monstra TMP folder.
             Monstra::cleanTmp();
             Stylesheet::stylesVersionIncrement();
             Javascript::javascriptVersionIncrement();
             Dir::delete(PLUGINS . DS . basename(Request::get('delete_plugin_from_server'), '.manifest.xml'));
             Request::redirect('index.php?id=plugins');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Upload & extract plugin archive
     // -------------------------------------
     if (Request::post('upload_file')) {
         if (Security::check(Request::post('csrf'))) {
             if ($_FILES['file']) {
                 if (in_array(File::ext($_FILES['file']['name']), array('zip'))) {
                     $tmp_dir = ROOT . DS . 'tmp' . DS . uniqid('plugin_');
                     $error = 'Plugin was not uploaded';
                     if (Dir::create($tmp_dir)) {
                         $file_locations = Zip::factory()->extract($_FILES['file']['tmp_name'], $tmp_dir);
                         if (!empty($file_locations)) {
                             $manifest = '';
                             foreach ($file_locations as $filepath) {
                                 if (substr($filepath, -strlen('.manifest.xml')) === '.manifest.xml') {
                                     $manifest = $filepath;
                                     break;
                                 }
                             }
                             if (!empty($manifest) && basename(dirname($manifest)) === 'install') {
                                 $manifest_file = pathinfo($manifest, PATHINFO_BASENAME);
                                 $plugin_name = str_replace('.manifest.xml', '', $manifest_file);
                                 if (Dir::create(PLUGINS . DS . $plugin_name)) {
                                     $tmp_plugin_dir = dirname(dirname($manifest));
                                     Dir::copy($tmp_plugin_dir, PLUGINS . DS . $plugin_name);
                                     Notification::set('success', __('Plugin was uploaded', 'plugins'));
                                     $error = false;
                                 }
                             }
                         }
                     } else {
                         $error = 'System error';
                     }
                 } else {
                     $error = 'Forbidden plugin file type';
                 }
             } else {
                 $error = 'Plugin was not uploaded';
             }
             if ($error) {
                 Notification::set('error', __($error, 'plugins'));
             }
             if (Request::post('dragndrop')) {
                 Request::shutdown();
             } else {
                 Request::redirect($site_url . '/admin/index.php?id=plugins#installnew');
             }
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Installed plugins
     $plugins_installed = array();
     // New plugins
     $plugins_new = array();
     // Plugins to install
     $plugins_to_intall = array();
     // Scan plugins directory for .manifest.xml
     $plugins_new = File::scan(PLUGINS, '.manifest.xml');
     // Get installed plugins from plugins table
     $plugins_installed = $plugins->select(null, 'all', null, array('location', 'priority'), 'priority', 'ASC');
     // Update $plugins_installed array. extract plugins names
     foreach ($plugins_installed as $plg) {
         $_plg[] = basename($plg['location'], 'plugin.php') . 'manifest.xml';
     }
     // Diff
     $plugins_to_install = array_diff($plugins_new, $_plg);
     // Create array of plugins to install
     $count = 0;
     foreach ($plugins_to_install as $plugin) {
         $plg_path = PLUGINS . DS . Text::lowercase(basename($plugin, '.manifest.xml')) . DS . 'install' . DS . $plugin;
         if (file_exists($plg_path)) {
             $plugins_to_intall[$count]['path'] = $plg_path;
             $plugins_to_intall[$count]['plugin'] = $plugin;
             $count++;
         }
     }
     // Draw template
     View::factory('box/plugins/views/backend/index')->assign('installed_plugins', $installed_plugins)->assign('plugins_to_intall', $plugins_to_intall)->assign('_users_plugins', $_users_plugins)->assign('fileuploader', array('uploadUrl' => $site_url . '/admin/index.php?id=plugins', 'csrf' => Security::token(), 'errorMsg' => __('Upload server error', 'filesmanager')))->display();
 }
Example #10
0
            // show pages
            $p->view('templates', array('title' => Panel::$lang['Javascript'], 'offset' => $offset, 'total' => ceil(count($content) / $per_page), 'prev' => $prev, 'next' => $next, 'content' => $showPag[$offset - 1]));
        } else {
            // show pages
            $p->view('templates', array('title' => Panel::$lang['Javascript'], 'offset' => 1, 'total' => 1, 'prev' => '', 'next' => '', 'content' => $content));
        }
    } else {
        Request::redirect($p::$site['url'] . '/' . $p::$site['backend_folder']);
    }
});
/*    TEMPLATES
-----------------------------*/
/*
* @name   Templates
* @desc   if session user get Templates
* @desc   if not redirecto to login page
*/
$p->route('/backups', function () use($p) {
    if (Session::exists('user')) {
        $content = File::scan(BACKUPS, '.zip');
        if ($content) {
            // show pages
            $p->view('backups', array('title' => Panel::$lang['Backups'], 'content' => $content));
        } else {
            // show pages
            $p->view('backups', array('title' => Panel::$lang['Backups'], 'content' => $content));
        }
    } else {
        Request::redirect($p::$site['url'] . '/' . $p::$site['backend_folder']);
    }
});
Example #11
0
 /**
  * main events admin function
  */
 public static function main()
 {
     $path = ROOT . DS . 'public' . DS . 'uploads' . DS;
     // Request: add event
     if (Request::post('add_event')) {
         if (Security::check(Request::post('csrf'))) {
             if (EventsRepository::insert(EventsAdmin::_getEventData())) {
                 Notification::set('success', __('Event was added with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->insert() returned an error. Event could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus(EventsRepository::getLastId()) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: edit event
     if (Request::post('edit_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('edit_event');
             if (EventsRepository::update($id, EventsAdmin::_getEventData())) {
                 Notification::set('success', __('Event was updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: restore event
     if (Request::post('restore_trash_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('restore_trash_event');
             if (EventsRepository::update($id, array('deleted' => 0))) {
                 Notification::set('success', __('Event has been restored from trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event could not be restored.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete event
     if (Request::post('delete_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_event');
             if (EventsRepository::update($id, array('deleted' => 1))) {
                 Notification::set('success', __('Event has been moved to trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event could not be deleted.', 'events'));
             }
             $record = EventsRepository::getById($id);
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete trash event
     if (Request::post('delete_trash_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_trash_event');
             if (EventsRepository::delete($id)) {
                 Notification::set('success', __('Event has been deleted permanently with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->delete() returned an error. Event could not be deleted.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: update event status ['published','draft']
     if (Request::get('eventaction') and Request::get('eventaction') == 'update_status') {
         if (Security::check(Request::get('token'))) {
             $id = (int) Request::get('event_id');
             if (EventsRepository::update($id, array('status' => Request::get('status')))) {
                 Notification::set('success', __('Event status has been updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event status could not be updated.', 'events'));
             }
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: add category
     if (Request::post('add_category')) {
         if (Security::check(Request::post('csrf'))) {
             if (CategoriesRepository::insert(EventsAdmin::_getCategoryData())) {
                 Notification::set('success', __('Category was added with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->insert() returned an error. Category could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: edit category
     if (Request::post('edit_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('edit_category');
             if (CategoriesRepository::update($id, EventsAdmin::_getCategoryData())) {
                 Notification::set('success', __('Category was updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Category could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: restore category
     if (Request::post('restore_trash_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('restore_trash_category');
             if (CategoriesRepository::update($id, array('deleted' => 0))) {
                 Notification::set('success', __('Category has been restored from trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Category could not be restored.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete category
     if (Request::post('delete_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_category');
             if (!CategoriesRepository::hasEvents($id)) {
                 if (CategoriesRepository::update($id, array('deleted' => 1))) {
                     Notification::set('success', __('Category has been moved to trash with success!', 'events'));
                 } else {
                     Notification::set('error', __('Table->update() returned an error. Category could not be deleted.', 'events'));
                 }
             } else {
                 Notification::set('error', __('Deletion failed. This category is assigned to at least one event. Remove this category from every event to delete it.', 'events'));
             }
             Request::redirect('index.php?id=events#categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete trash category
     if (Request::post('delete_trash_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_trash_category');
             if (CategoriesRepository::delete($id)) {
                 Notification::set('success', __('Category has been deleted permanently with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->delete() returned an error. Category could not be deleted.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: add location
     if (Request::post('add_location')) {
         if (Security::check(Request::post('csrf'))) {
             if (LocationsRepository::insert(EventsAdmin::_getLocationData())) {
                 Notification::set('success', __('Location was added with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->insert() returned an error. Location could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: edit location
     if (Request::post('edit_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('edit_location');
             if (LocationsRepository::update($id, EventsAdmin::_getLocationData())) {
                 Notification::set('success', __('Location was updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Location could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: restore location
     if (Request::post('restore_trash_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('restore_trash_location');
             if (LocationsRepository::update($id, array('deleted' => 0))) {
                 Notification::set('success', __('Location has been restored from trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Location could not be restored.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete location
     if (Request::post('delete_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_location');
             if (!LocationsRepository::hasEvents($id)) {
                 if (LocationsRepository::update($id, array('deleted' => 1))) {
                     Notification::set('success', __('Location has been moved to trash with success!', 'events'));
                 } else {
                     Notification::set('error', __('Table->update() returned an error. Location could not be deleted.', 'events'));
                 }
             } else {
                 Notification::set('error', __('Deletion failed. This location is assigned to at least one event. Remove this location from every event to delete it.', 'events'));
             }
             Request::redirect('index.php?id=events#locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete trash location
     if (Request::post('delete_trash_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_trash_location');
             if (LocationsRepository::delete($id)) {
                 Notification::set('success', __('Location has been deleted permanently with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->delete() returned an error. Location could not be deleted.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // get upload directories
     $directory_list = Dir::scan($path);
     $directories = array(DS => DS);
     if (!empty($directory_list)) {
         foreach ($directory_list as $directory_name) {
             $directories[$directory_name] = DS . $directory_name;
         }
         ksort($directories);
     }
     // Get files
     $file_list = File::scan($path . Option::get('events_image_directory'));
     $files = array('' => '');
     if (!empty($file_list)) {
         foreach ($file_list as $file_name) {
             $files[$file_name] = $file_name;
         }
         ksort($files);
     }
     if (Request::get('action')) {
         switch (Request::get('action')) {
             // Request: configuration
             case "configuration":
                 // Request: options
                 if (Request::post('events_options_update') or Request::post('events_options_update_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         Option::update('events_image_directory', (string) Request::post('events_image_directory'));
                         Option::update('events_placeholder_archive', (string) Request::post('events_placeholder_archive'));
                         Notification::set('success', __('Configuration has been saved with success!', 'events'));
                         Request::redirect('index.php?id=events' . (Request::post('events_options_update') ? '&action=configuration' : ''));
                     } else {
                         Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
                         die;
                     }
                 }
                 // Request: action: resize images
                 if (Request::post('events_action_resize_images') or Request::post('events_action_resize_images_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         $n = 0;
                         $size = (int) Request::post('events_action_resize_size');
                         $image_dir = $path . Option::get('events_image_directory');
                         $image_dir_res = $path . Option::get('events_image_directory') . DS . 'resized';
                         $images = File::scan($image_dir);
                         if (!empty($images)) {
                             // create 'resized' directory if not exists
                             if (!Dir::exists($image_dir_res)) {
                                 Dir::create($image_dir_res);
                             }
                             foreach ($images as $file_name) {
                                 if (File::exists($image_dir_res . DS . $file_name)) {
                                     if (Request::post('events_action_resize_overwrite')) {
                                         File::delete($image_dir_res . DS . $file_name);
                                     } else {
                                         continue;
                                     }
                                 }
                                 list($width, $height) = getimagesize($image_dir . DS . $file_name);
                                 $image_orientation = $width > $height ? Image::HEIGHT : Image::WIDTH;
                                 Image::factory($image_dir . DS . $file_name)->resize($size, $size, $image_orientation)->save($image_dir_res . DS . $file_name);
                                 $n++;
                             }
                             Notification::set('success', __($n . ' images have been resized and saved with success!', 'events'));
                         } else {
                             Notification::set('error', __('There are no images to resize in configured image directory.', 'events'));
                         }
                         Request::redirect('index.php?id=events' . (Request::post('events_action_resize_images') ? '&action=configuration' : ''));
                     } else {
                         Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
                         die;
                     }
                 }
                 // Display configuration view
                 View::factory('events/views/backend/configuration')->assign('directories', $directories)->display();
                 break;
                 // Request: statistics
             // Request: statistics
             case "stats":
                 // category-events
                 $categories = CategoriesRepository::getAll();
                 $categories_active = CategoriesRepository::getActive();
                 $categories_data = array();
                 foreach ($categories_active as $c) {
                     $categories_data[$c['id']] = array('title' => '"' . $c['title'] . '"', 'color' => '"#' . $c['color'] . '"', 'highlight' => '"' . EventsAdmin::adjustBrightness('#' . $c['color'], 25) . '"', 'count' => $categories[$c['id']]['count']);
                 }
                 // location-events
                 $locations = LocationsRepository::getAll();
                 $locations_active = LocationsRepository::getActive();
                 $locations_data = array();
                 foreach ($locations_active as $l) {
                     $locations_data[$l['id']] = array('title' => '"' . $l['title'] . '"', 'count' => $locations[$l['id']]['count']);
                 }
                 $locations_data = EventsAdmin::_sortArrayByFields($locations_data, array('count' => SORT_DESC, 'title' => array(SORT_ASC, SORT_STRING)));
                 // year-events and year-visitors
                 $years_data = array();
                 $categories_years_events = array();
                 foreach (EventsRepository::getYearEvents() as $year => $events) {
                     $years_data[$year] = array('number_events' => count($events), 'number_visitors' => array_sum(array_column($events, 'number_visitors')));
                     foreach ($events as $event) {
                         $categories_years_events[$event['category']][$year][] = $event;
                     }
                 }
                 $categories_years_data = array();
                 $categories_years_visitors = array();
                 foreach ($categories_years_events as $category => $years) {
                     foreach ($years as $year => $events) {
                         foreach ($years_data as $total_year => $total_count) {
                             if ($year == $total_year) {
                                 $categories_years_data[$category][$year] = count($events);
                                 $categories_years_visitors[$category][$year] = array_sum(array_column($events, 'number_visitors'));
                             } else {
                                 if (array_key_exists($total_year, $categories_years_data[$category])) {
                                     $categories_years_data[$category][$year] = count($events);
                                     $categories_years_visitors[$category][$year] = array_sum(array_column($events, 'number_visitors'));
                                 } else {
                                     $categories_years_data[$category][$total_year] = 0;
                                     $categories_years_visitors[$category][$total_year] = 0;
                                 }
                             }
                         }
                     }
                 }
                 // locations
                 $locations_list = array();
                 $coordinates = array();
                 $longitudes = array();
                 $latitudes = array();
                 // get location data ready to use with OSM JavaScript
                 foreach (LocationsRepository::getActive() as $location) {
                     if ($location['address']) {
                         $locations_list[] = '"' . $location['address'] . '"';
                         $coordinates[] = $location['lon'] . ',' . $location['lat'];
                         $longitudes[] = $location['lon'];
                         $latitudes[] = $location['lat'];
                     }
                 }
                 // calculate map center
                 $longitudes = EventsAdmin::_removeOutliers($longitudes, 0.5);
                 $latitudes = EventsAdmin::_removeOutliers($latitudes, 0.5);
                 $coordinates_average = array('lon' => array_sum($longitudes) / count($longitudes), 'lat' => array_sum($latitudes) / count($latitudes));
                 // event visitors and staff
                 $participants = array();
                 $events = EventsRepository::getVisitorsAndStaff();
                 foreach ($events as $event) {
                     if (!CategoriesRepository::hiddenInArchive($event['category'])) {
                         $participants[$event['category']][] = array('title' => $event['title'], 'visitors' => (int) $event['number_visitors'], 'staff' => (int) $event['number_staff']);
                     }
                 }
                 // Display statistics view
                 View::factory('events/views/backend/statistics')->assign('categories', $categories)->assign('categories_active', $categories_active)->assign('categories_data', $categories_data)->assign('locations', $locations)->assign('locations_active', $locations_active)->assign('locations_data', $locations_data)->assign('years_data', $years_data)->assign('categories_years_data', $categories_years_data)->assign('categories_years_visitors', $categories_years_visitors)->assign('coordinates', $coordinates)->assign('coordinates_average', $coordinates_average)->assign('participants', $participants)->display();
                 break;
         }
     } else {
         // Display index view
         View::factory('events/views/backend/index')->assign('categories', CategoriesRepository::getAll())->assign('categories_active', CategoriesRepository::getActive())->assign('categories_select', CategoriesRepository::getActiveForSelect())->assign('categories_deleted', CategoriesRepository::getDeleted())->assign('locations', LocationsRepository::getAll())->assign('locations_active', LocationsRepository::getActive())->assign('locations_select', LocationsRepository::getActiveForSelect())->assign('locations_deleted', LocationsRepository::getDeleted())->assign('events_active', EventsRepository::getActive())->assign('events_upcoming', EventsRepository::getUpcoming())->assign('events_past', EventsRepository::getPast())->assign('events_draft', EventsRepository::getDraft())->assign('events_deleted', EventsRepository::getDeleted())->assign('imagepath', DS . 'public' . DS . 'uploads' . DS . Option::get('events_image_directory') . DS)->assign('files', $files)->display();
     }
 }
Example #12
0
										' . Panel::$lang['back'] . '
									</a>
								</div>
							</div>'));
});
/*    SEARCH IN THEMES
-----------------------------*/
/*
* @name   Search
* @sample /action/searchinthemes/findme
*/
$p->route('/action/searchinthemes/(:any)', function ($query = '') use($p) {
    // get file url
    $directory = THEMES;
    // scan to obtain files
    $scan = File::scan($directory);
    // start template
    $result = '<ul class="list-group">';
    // init count to 0
    $count = 0;
    foreach ($scan as $item) {
        // remove storage\$dir
        $item = str_replace(THEMES, '', $item);
        // search query with preg_match
        if (preg_match('/' . urldecode($query) . '/i', $item)) {
            // count +1
            ++$count;
            // template
            $result .= '<li class="list-group-item clearfix">
							' . $item . '
							<a class="btn btn-primary pull-right" href="
Example #13
0
$p->route(array('/media/uploads/(:num)', '/media/uploads/(:num)/(:num)'), function ($id, $offset = 1) use($p) {
    if (Session::exists('user')) {
        $info = '';
        // items per page
        $per_page = $p::$site['backend_pagination_media'];
        // array json
        $json = array();
        // next prev
        $prev = '';
        $next = '';
        // template
        $templateAll = '';
        // json file
        $file = ROOTBASE . '/public/media/albums/album_' . $id;
        // get json file
        $scan = File::scan($file);
        // get json file fow with and height
        $jsonFile = PUBLICFOLDER . '/media/mdb.json';
        $json = json_decode(File::getContent($jsonFile), true);
        // upload files
        $error = '';
        $AllowedExtensions = array('gif', 'jpeg', 'jpg', 'png', 'md', 'txt', 'zip', 'pdf', 'mp4', 'webm', 'html', 'css', 'js', 'mp3', 'vaw', 'doc');
        if (Request::post('uploadMedia')) {
            if (Request::post('token')) {
                // check if exists
                if (File::exists(PUBLICFOLDER . '/media/albums/album_' . $id . '/' . $_FILES['media_upload']['name'])) {
                    $error = '<span class="label label-danger">' . Panel::$lang['File_Name_Exists'] . '</span>';
                } else {
                    // check file types
                    if (!in_array(File::ext($_FILES['media_upload']['name']), $AllowedExtensions)) {
                        die('Extension not allowed');
 public static function init()
 {
     // login vars
     $user = trim(Config::get('plugins.gallery.email'));
     $password = trim(Config::get('plugins.gallery.password'));
     $token = trim(Config::get('plugins.gallery.token'));
     $hash = md5($token . $password);
     // get plugin info
     //var_dump(json_encode(Config::get('plugins.gallery'),true));
     $template = Template::factory(PLUGINS_PATH . '/gallery/templates/');
     $template->setOptions(['strip' => false]);
     $jsonFile = '';
     $format = '';
     $thumbnails_path = '';
     $photos_path = '';
     $json = '';
     $info = '';
     // check if dir exists if not create
     if (!Dir::exists(ROOT_DIR . '/public/gallery')) {
         Dir::create(ROOT_DIR . '/public/gallery');
     }
     if (!Dir::exists(ROOT_DIR . '/public/gallery/thumbnails')) {
         Dir::create(ROOT_DIR . '/public/gallery/thumbnails');
     }
     if (!Dir::exists(ROOT_DIR . '/public/gallery/galleries')) {
         Dir::create(ROOT_DIR . '/public/gallery/galleries');
     }
     if (!File::exists(ROOT_DIR . '/public/gallery/gallery.json')) {
         File::setContent(ROOT_DIR . '/public/gallery/gallery.json', '[]');
     } else {
         $jsonFile = ROOT_DIR . '/public/gallery/gallery.json';
         $format = array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG');
         $thumbnails_path = ROOT_DIR . '/public/gallery/thumbnails/';
         $photos_path = ROOT_DIR . '/public/gallery/galleries/';
         // decode json
         $json = json_decode(File::getContent($jsonFile), true);
     }
     // show loginbtn
     if (Session::exists(Config::get('plugins.gallery.name') . '_user')) {
         // logout
         if (Request::post('access_logout')) {
             Session::delete(Config::get('plugins.gallery.name') . '_user');
             Request::redirect(Url::getBase() . '/' . strtolower(Config::get('plugins.gallery.name')));
         }
         // create gallery
         if (Request::post('createGallery')) {
             if (Request::post('token')) {
                 // id
                 $id = time();
                 // json array remenber encode
                 $json[$id] = array('id' => $id, 'title' => Request::post('title') ? Request::post('title') : 'No title', 'desc' => Request::post('desc') ? Request::post('desc') : 'No desc', 'thumbnail' => '/public/gallery/thumbnails/' . $id . '.png', 'photos' => ROOT_DIR . '/public/gallery/galleries/' . $id . '/');
                 Dir::create($photos_path . $id);
                 // save content
                 if (File::setContent($jsonFile, json_encode($json))) {
                     self::upload('thumbnail', 'thumbnail', $format, $thumbnails_path, $id);
                     self::upload('photos', 'photos', $format, $photos_path, $id);
                     return self::set_msg('Success The gallery has been created');
                 }
             } else {
                 die('Crsf detect!');
             }
         }
         // update gallery
         if (Request::post('updateGallery')) {
             if (Request::post('token')) {
                 // json array remenber encode
                 $id = Request::post('update_id');
                 $json[$id] = array('id' => $id, 'title' => Request::post('update_title') ? Request::post('update_title') : 'No title', 'desc' => Request::post('update_desc') ? Request::post('update_desc') : 'No desc', 'thumbnail' => '/public/gallery/thumbnails/' . $id . '.png', 'photos' => ROOT_DIR . '/public/gallery/galleries/' . $id . '/');
                 // save content
                 if (File::setContent($jsonFile, json_encode($json))) {
                     //upload images
                     self::upload('thumbnail', 'update_thumbnail', $format, $thumbnails_path, $id);
                     self::upload('photos', 'update_photos', $format, $photos_path, $id);
                     return self::set_msg('Success The gallery has been updated');
                 }
             } else {
                 die('Crsf detect!');
             }
         }
         // resize gallery
         if (Request::post('resizeGallery')) {
             if (Request::post('token')) {
                 $uid = Request::post('gallery_id');
                 $w = Request::post('gallery_w');
                 $h = Request::post('gallery_h');
                 $files = File::scan($photos_path . $uid);
                 foreach ($files as $file) {
                     // Load the original image
                     $image = new SimpleImage($file);
                     $image->resize($w, $h, true);
                     $image->save($file);
                 }
                 return self::set_msg('Success The gallery Photos, has been resized');
             }
         }
         // resize thumbnail
         if (Request::post('resizeThumbnail')) {
             if (Request::post('token')) {
                 $uid = Request::post('gallery_id');
                 $tw = Request::post('gallery_tw');
                 $th = Request::post('gallery_th');
                 $dir = ROOT_DIR . '/public/gallery/thumbnails/' . $uid . '.png';
                 // Load the original image
                 $image = new SimpleImage($dir);
                 $image->resize($tw, $th, true);
                 $image->save($dir);
                 return self::set_msg('Success The gallery Thumbnail, has been created');
             }
         }
         // remove file
         if (Request::get('rem')) {
             $file = base64_decode(Request::get('rem'));
             $uid = Request::get('id');
             File::delete($file);
             self::set_msg('Success The Image  has been deleted');
         }
         // remove gallery
         if (Request::get('del')) {
             $id_of_gallery = Request::get('del');
             unset($json[$id_of_gallery]);
             if (File::setContent($jsonFile, json_encode($json))) {
                 File::delete(ROOT_DIR . '/public/gallery/thumbnails/' . $id_of_gallery . '.png');
                 Dir::delete($photos_path . $id_of_gallery);
                 self::set_msg('Success The Gallery ' . $id_of_gallery . ' has been deleted');
                 Request::redirect(Url::getBase() . '/gallery');
             }
         }
         // show template
         return $template->display('admin.tpl', ['info' => self::get_msg(), 'title' => Config::get('plugins.gallery.name') . ' Admin Area', 'root_dir' => ROOT_DIR, 'info' => $info, 'content' => $json ? array_reverse($json) : '']);
     } else {
         // login access
         if (Request::post('access_login')) {
             if (Request::post('token')) {
                 if (Request::post('password') == $password && Request::post('email') == $user) {
                     @Session::start();
                     Session::set(Config::get('plugins.gallery.name') . '_user', $hash);
                     // show admin template
                     Request::redirect(Url::getBase() . '/gallery');
                 } else {
                     // password not correct show error
                     $template->display('partials/error.tpl', ['title' => 'Access Error', 'content' => Config::get('plugins.gallery.errorPassword')]);
                 }
             } else {
                 // crsf
                 die('crsf detect');
             }
         }
         // template
         return $template->display('home.tpl', ['root_dir' => ROOT_DIR, 'content' => $json ? array_reverse($json) : '']);
     }
 }
 /**
  * Pages admin function
  */
 public static function main()
 {
     $current_theme = Option::get('theme_site_name');
     $site_url = Option::get('siteurl');
     $templates_path = THEMES_SITE;
     $errors = array();
     $pages = new Table('pages');
     PagesAdmin::$pages = $pages;
     $users = new Table('users');
     $user = $users->select('[id=' . Session::get('user_id') . ']', null);
     // Page author
     if (!empty($user['firstname'])) {
         $author = empty($user['lastname']) ? $user['firstname'] : $user['firstname'] . ' ' . $user['lastname'];
     } else {
         $author = Session::get('user_login');
     }
     $author = Html::toText($author);
     // Status array
     $status_array = array('published' => __('Published', 'pages'), 'draft' => __('Draft', 'pages'));
     // Access array
     $access_array = array('public' => __('Public', 'pages'), 'registered' => __('Registered', 'pages'));
     // Check for get actions
     // ---------------------------------------------
     if (Request::get('action')) {
         // Switch actions
         // -----------------------------------------
         switch (Request::get('action')) {
             // Clone page
             // -------------------------------------
             case "clone_page":
                 if (Security::check(Request::get('token'))) {
                     // Generate rand page name
                     $rand_page_name = Request::get('name') . '_clone_' . date("Ymd_His");
                     // Get original page
                     $orig_page = $pages->select('[slug="' . Request::get('name') . '"]', null);
                     // Generate rand page title
                     $rand_page_title = $orig_page['title'] . ' [copy]';
                     // Clone page
                     if ($pages->insert(array('slug' => $rand_page_name, 'template' => $orig_page['template'], 'parent' => $orig_page['parent'], 'robots_index' => $orig_page['robots_index'], 'robots_follow' => $orig_page['robots_follow'], 'status' => $orig_page['status'], 'access' => isset($orig_page['access']) ? $orig_page['access'] : 'public', 'expand' => isset($orig_page['expand']) ? $orig_page['expand'] : '0', 'title' => $rand_page_title, 'meta_title' => $orig_page['meta_title'], 'description' => $orig_page['description'], 'keywords' => $orig_page['keywords'], 'tags' => $orig_page['tags'], 'date' => $orig_page['date'], 'author' => $orig_page['author']))) {
                         // Get cloned page ID
                         $last_id = $pages->lastId();
                         // Save cloned page content
                         File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt', File::getContent(STORAGE . DS . 'pages' . DS . $orig_page['id'] . '.page.txt'));
                         // Send notification
                         Notification::set('success', __('The page <i>:page</i> cloned.', 'pages', array(':page' => Security::safeName(Request::get('name'), '-', true))));
                     }
                     // Run add extra actions
                     Action::run('admin_pages_action_clone');
                     // Redirect
                     Request::redirect('index.php?id=pages');
                 } else {
                     die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                 }
                 break;
                 // Add page
                 // -------------------------------------
             // Add page
             // -------------------------------------
             case "add_page":
                 // Add page
                 if (Request::post('add_page') || Request::post('add_page_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         // Get parent page
                         if (Request::post('pages') == '0') {
                             $parent_page = '';
                         } else {
                             $parent_page = Request::post('pages');
                         }
                         // Validate
                         //--------------
                         if (trim(Request::post('page_name')) == '') {
                             $errors['pages_empty_name'] = __('Required field', 'pages');
                         }
                         if (trim(Request::post('page_title')) == '') {
                             $errors['pages_empty_title'] = __('Required field', 'pages');
                         }
                         if (count($pages->select('[slug="' . Security::safeName(Request::post('page_name'), '-', true) . '"]')) != 0) {
                             $errors['pages_exists'] = __('This page already exists', 'pages');
                         }
                         // Prepare date
                         if (Valid::date(Request::post('page_date'))) {
                             $date = strtotime(Request::post('page_date'));
                         } else {
                             $date = time();
                         }
                         if (Request::post('robots_index')) {
                             $robots_index = 'noindex';
                         } else {
                             $robots_index = 'index';
                         }
                         if (Request::post('robots_follow')) {
                             $robots_follow = 'nofollow';
                         } else {
                             $robots_follow = 'follow';
                         }
                         // If no errors then try to save
                         if (count($errors) == 0) {
                             // Insert new page
                             if ($pages->insert(array('slug' => Security::safeName(Request::post('page_name'), '-', true), 'template' => Request::post('templates'), 'parent' => $parent_page, 'status' => Request::post('status'), 'access' => Request::post('access'), 'expand' => '0', 'robots_index' => $robots_index, 'robots_follow' => $robots_follow, 'title' => Request::post('page_title'), 'meta_title' => Request::post('page_meta_title'), 'description' => Request::post('page_description'), 'keywords' => Request::post('page_keywords'), 'tags' => Request::post('page_tags'), 'date' => $date, 'author' => $author))) {
                                 // Get inserted page ID
                                 $last_id = $pages->lastId();
                                 // Save content
                                 File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt', XML::safe(Request::post('editor')));
                                 // Send notification
                                 Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
                             }
                             // Run add extra actions
                             Action::run('admin_pages_action_add');
                             // Redirect
                             if (Request::post('add_page_and_exit')) {
                                 Request::redirect('index.php?id=pages');
                             } else {
                                 Request::redirect('index.php?id=pages&action=edit_page&name=' . Security::safeName(Request::post('page_name'), '-', true));
                             }
                         }
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 // Get all pages
                 $pages_list = $pages->select('[slug!="error404" and parent=""]');
                 $pages_array[] = '-none-';
                 foreach ($pages_list as $page) {
                     $pages_array[$page['slug']] = $page['title'];
                 }
                 // Get all templates
                 $templates_list = File::scan($templates_path, '.template.php');
                 foreach ($templates_list as $file) {
                     $templates_array[basename($file, '.template.php')] = basename($file, '.template.php');
                 }
                 // Save fields
                 if (Request::post('page_name')) {
                     $post_name = Request::post('page_name');
                 } else {
                     $post_name = '';
                 }
                 if (Request::post('page_title')) {
                     $post_title = Request::post('page_title');
                 } else {
                     $post_title = '';
                 }
                 if (Request::post('page_meta_title')) {
                     $post_meta_title = Request::post('page_meta_title');
                 } else {
                     $post_meta_title = '';
                 }
                 if (Request::post('page_keywords')) {
                     $post_keywords = Request::post('page_keywords');
                 } else {
                     $post_keywords = '';
                 }
                 if (Request::post('page_description')) {
                     $post_description = Request::post('page_description');
                 } else {
                     $post_description = '';
                 }
                 if (Request::post('page_tags')) {
                     $post_tags = Request::post('page_tags');
                 } else {
                     $post_tags = '';
                 }
                 if (Request::post('editor')) {
                     $post_content = Request::post('editor');
                 } else {
                     $post_content = '';
                 }
                 if (Request::post('templates')) {
                     $post_template = Request::post('templates');
                 } else {
                     $post_template = 'index';
                 }
                 if (Request::post('status')) {
                     $post_status = Request::post('status');
                 } else {
                     $post_status = 'published';
                 }
                 if (Request::post('access')) {
                     $post_access = Request::post('access');
                 } else {
                     $post_access = 'public';
                 }
                 if (Request::post('pages')) {
                     $parent_page = Request::post('pages');
                 } else {
                     if (Request::get('parent_page')) {
                         $parent_page = Request::get('parent_page');
                     } else {
                         $parent_page = '';
                     }
                 }
                 if (Request::post('robots_index')) {
                     $post_robots_index = true;
                 } else {
                     $post_robots_index = false;
                 }
                 if (Request::post('robots_follow')) {
                     $post_robots_follow = true;
                 } else {
                     $post_robots_follow = false;
                 }
                 //--------------
                 // Generate date
                 $date = Date::format(time(), 'Y-m-d H:i:s');
                 // Set Tabs State - page
                 Notification::setNow('page', 'page');
                 // Display view
                 View::factory('box/pages/views/backend/add')->assign('post_name', $post_name)->assign('post_title', $post_title)->assign('post_meta_title', $post_meta_title)->assign('post_description', $post_description)->assign('post_keywords', $post_keywords)->assign('post_tags', $post_tags)->assign('post_content', $post_content)->assign('pages_array', $pages_array)->assign('parent_page', $parent_page)->assign('templates_array', $templates_array)->assign('post_template', $post_template)->assign('post_status', $post_status)->assign('post_access', $post_access)->assign('status_array', $status_array)->assign('access_array', $access_array)->assign('date', $date)->assign('post_robots_index', $post_robots_index)->assign('post_robots_follow', $post_robots_follow)->assign('errors', $errors)->display();
                 break;
                 // Edit page
                 // -------------------------------------
             // Edit page
             // -------------------------------------
             case "edit_page":
                 if (Request::post('edit_page') || Request::post('edit_page_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         // Get pages parent
                         if (Request::post('pages') == '0') {
                             $parent_page = '';
                         } else {
                             $parent_page = Request::post('pages');
                         }
                         // Save field
                         $post_parent = Request::post('pages');
                         // Validate
                         //--------------
                         if (trim(Request::post('page_name')) == '') {
                             $errors['pages_empty_name'] = __('Required field', 'pages');
                         }
                         if (count($pages->select('[slug="' . Security::safeName(Request::post('page_name'), '-', true) . '"]')) != 0 and Security::safeName(Request::post('page_old_name'), '-', true) !== Security::safeName(Request::post('page_name'), '-', true)) {
                             $errors['pages_exists'] = __('This page already exists', 'pages');
                         }
                         if (trim(Request::post('page_title')) == '') {
                             $errors['pages_empty_title'] = __('Required field', 'pages');
                         }
                         // Save fields
                         if (Request::post('page_name')) {
                             $post_name = Request::post('page_name');
                         } else {
                             $post_name = '';
                         }
                         if (Request::post('page_title')) {
                             $post_title = Request::post('page_title');
                         } else {
                             $post_title = '';
                         }
                         if (Request::post('page_meta_title')) {
                             $post_meta_title = Request::post('page_meta_title');
                         } else {
                             $post_meta_title = '';
                         }
                         if (Request::post('page_keywords')) {
                             $post_keywords = Request::post('page_keywords');
                         } else {
                             $post_keywords = '';
                         }
                         if (Request::post('page_description')) {
                             $post_description = Request::post('page_description');
                         } else {
                             $post_description = '';
                         }
                         if (Request::post('page_tags')) {
                             $post_tags = Request::post('page_tags');
                         } else {
                             $post_tags = '';
                         }
                         if (Request::post('editor')) {
                             $post_content = Request::post('editor');
                         } else {
                             $post_content = '';
                         }
                         if (Request::post('templates')) {
                             $post_template = Request::post('templates');
                         } else {
                             $post_template = 'index';
                         }
                         if (Request::post('status')) {
                             $post_status = Request::post('status');
                         } else {
                             $post_status = 'published';
                         }
                         if (Request::post('access')) {
                             $post_access = Request::post('access');
                         } else {
                             $post_access = 'public';
                         }
                         if (Request::post('robots_index')) {
                             $post_robots_index = true;
                         } else {
                             $post_robots_index = false;
                         }
                         if (Request::post('robots_follow')) {
                             $post_robots_follow = true;
                         } else {
                             $post_robots_follow = false;
                         }
                         //--------------
                         // Prepare date
                         if (Valid::date(Request::post('page_date'))) {
                             $date = strtotime(Request::post('page_date'));
                         } else {
                             $date = time();
                         }
                         if (Request::post('robots_index')) {
                             $robots_index = 'noindex';
                         } else {
                             $robots_index = 'index';
                         }
                         if (Request::post('robots_follow')) {
                             $robots_follow = 'nofollow';
                         } else {
                             $robots_follow = 'follow';
                         }
                         if (count($errors) == 0) {
                             // Update parents in all childrens
                             if (Security::safeName(Request::post('page_name'), '-', true) !== Security::safeName(Request::post('page_old_name'), '-', true) and Request::post('old_parent') == '') {
                                 $_pages = $pages->select('[parent="' . Text::translitIt(trim(Request::post('page_old_name'))) . '"]');
                                 if (!empty($_pages)) {
                                     foreach ($_pages as $_page) {
                                         $pages->updateWhere('[parent="' . $_page['parent'] . '"]', array('parent' => Security::safeName(Request::post('page_name'), '-', true)));
                                     }
                                 }
                                 if ($pages->updateWhere('[slug="' . Request::get('name') . '"]', array('slug' => Security::safeName(Request::post('page_name'), '-', true), 'template' => Request::post('templates'), 'parent' => $parent_page, 'title' => Request::post('page_title'), 'meta_title' => Request::post('page_meta_title'), 'description' => Request::post('page_description'), 'keywords' => Request::post('page_keywords'), 'tags' => Request::post('page_tags'), 'robots_index' => $robots_index, 'robots_follow' => $robots_follow, 'status' => Request::post('status'), 'access' => Request::post('access'), 'date' => $date, 'author' => $author))) {
                                     File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor')));
                                     Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
                                 }
                                 // Run edit extra actions
                                 Action::run('admin_pages_action_edit');
                             } else {
                                 if ($pages->updateWhere('[slug="' . Request::get('name') . '"]', array('slug' => Security::safeName(Request::post('page_name'), '-', true), 'template' => Request::post('templates'), 'parent' => $parent_page, 'title' => Request::post('page_title'), 'meta_title' => Request::post('page_meta_title'), 'description' => Request::post('page_description'), 'keywords' => Request::post('page_keywords'), 'tags' => Request::post('page_tags'), 'robots_index' => $robots_index, 'robots_follow' => $robots_follow, 'status' => Request::post('status'), 'access' => Request::post('access'), 'date' => $date, 'author' => $author))) {
                                     File::setContent(STORAGE . DS . 'pages' . DS . Request::post('page_id') . '.page.txt', XML::safe(Request::post('editor')));
                                     Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Security::safeName(Request::post('page_title'), '-', true))));
                                 }
                                 // Run edit extra actions
                                 Action::run('admin_pages_action_edit');
                             }
                             // Redirect
                             if (Request::post('edit_page_and_exit')) {
                                 Request::redirect('index.php?id=pages');
                             } else {
                                 Request::redirect('index.php?id=pages&action=edit_page&name=' . Security::safeName(Request::post('page_name'), '-', true));
                             }
                         }
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 // Get all pages
                 $pages_list = $pages->select();
                 $pages_array[] = '-none-';
                 // Foreach pages find page whithout parent
                 foreach ($pages_list as $page) {
                     if (isset($page['parent'])) {
                         $c_p = $page['parent'];
                     } else {
                         $c_p = '';
                     }
                     if ($c_p == '') {
                         // error404 is system "constant" and no child for it
                         if ($page['slug'] !== 'error404' && $page['slug'] !== Request::get('name')) {
                             $pages_array[$page['slug']] = $page['title'];
                         }
                     }
                 }
                 // Get all templates
                 $templates_list = File::scan($templates_path, '.template.php');
                 foreach ($templates_list as $file) {
                     $templates_array[basename($file, '.template.php')] = basename($file, '.template.php');
                 }
                 $page = $pages->select('[slug="' . Request::get('name') . '"]', null);
                 if ($page) {
                     $page_content = File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt');
                     // Safe fields or load fields
                     if (Request::post('page_name')) {
                         $slug_to_edit = Request::post('page_name');
                     } else {
                         $slug_to_edit = $page['slug'];
                     }
                     if (Request::post('page_title')) {
                         $title_to_edit = Request::post('page_title');
                     } else {
                         $title_to_edit = $page['title'];
                     }
                     if (Request::post('page_meta_title')) {
                         $meta_title_to_edit = Request::post('page_meta_title');
                     } else {
                         $meta_title_to_edit = isset($page['meta_title']) ? $page['meta_title'] : '';
                     }
                     if (Request::post('page_description')) {
                         $description_to_edit = Request::post('page_description');
                     } else {
                         $description_to_edit = $page['description'];
                     }
                     if (Request::post('page_keywords')) {
                         $keywords_to_edit = Request::post('page_keywords');
                     } else {
                         $keywords_to_edit = $page['keywords'];
                     }
                     if (Request::post('page_tags')) {
                         $tags_to_edit = Request::post('page_tags');
                     } else {
                         $tags_to_edit = isset($page['tags']) ? $page['tags'] : '';
                     }
                     if (Request::post('editor')) {
                         $to_edit = Request::post('editor');
                     } else {
                         $to_edit = Text::toHtml($page_content);
                     }
                     if (Request::post('robots_index')) {
                         $post_robots_index = true;
                     } else {
                         if ($page['robots_index'] == 'noindex') {
                             $post_robots_index = true;
                         } else {
                             $post_robots_index = false;
                         }
                     }
                     if (Request::post('robots_follow')) {
                         $post_robots_follow = true;
                     } else {
                         if ($page['robots_follow'] == 'nofollow') {
                             $post_robots_follow = true;
                         } else {
                             $post_robots_follow = false;
                         }
                     }
                     if (Request::post('pages')) {
                         // Get pages parent
                         if (Request::post('pages') == '-none-') {
                             $parent_page = '';
                         } else {
                             $parent_page = Request::post('pages');
                         }
                         // Save field
                         $parent_page = Request::post('pages');
                     } else {
                         $parent_page = $page['parent'];
                     }
                     if (Request::post('templates')) {
                         $template = Request::post('templates');
                     } else {
                         $template = $page['template'];
                     }
                     if (Request::post('status')) {
                         $status = Request::post('status');
                     } else {
                         $status = $page['status'];
                     }
                     if (Request::post('access')) {
                         $access = Request::post('access');
                     } else {
                         $access = isset($page['access']) ? $page['access'] : 'public';
                     }
                     // Generate date
                     $date = Request::post('date') ? Request::post('date') : Date::format($page['date'], 'Y-m-d H:i:s');
                     Notification::setNow('page', 'page');
                     // Display view
                     View::factory('box/pages/views/backend/edit')->assign('slug_to_edit', $slug_to_edit)->assign('title_to_edit', $title_to_edit)->assign('meta_title_to_edit', $meta_title_to_edit)->assign('description_to_edit', $description_to_edit)->assign('keywords_to_edit', $keywords_to_edit)->assign('tags_to_edit', $tags_to_edit)->assign('page', $page)->assign('to_edit', $to_edit)->assign('pages_array', $pages_array)->assign('parent_page', $parent_page)->assign('templates_array', $templates_array)->assign('template', $template)->assign('status_array', $status_array)->assign('access_array', $access_array)->assign('status', $status)->assign('access', $access)->assign('date', $date)->assign('post_robots_index', $post_robots_index)->assign('post_robots_follow', $post_robots_follow)->assign('errors', $errors)->display();
                 }
                 break;
                 // Delete page
                 // -------------------------------------
             // Delete page
             // -------------------------------------
             case "delete_page":
                 // Error 404 page can not be removed
                 if (Request::get('slug') !== 'error404') {
                     if (Security::check(Request::get('token'))) {
                         // Get specific page
                         $page = $pages->select('[slug="' . Request::get('name') . '"]', null);
                         //  Delete page and update <parent> fields
                         if ($pages->deleteWhere('[slug="' . $page['slug'] . '" ]')) {
                             $_pages = $pages->select('[parent="' . $page['slug'] . '"]');
                             if (!empty($_pages)) {
                                 foreach ($_pages as $_page) {
                                     $pages->updateWhere('[slug="' . $_page['slug'] . '"]', array('parent' => ''));
                                 }
                             }
                             File::delete(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt');
                             Notification::set('success', __('Page <i>:page</i> deleted', 'pages', array(':page' => Html::toText($page['title']))));
                         }
                         // Run delete extra actions
                         Action::run('admin_pages_action_delete');
                         // Redirect
                         Request::redirect('index.php?id=pages');
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 break;
                 // Update page access
                 // -------------------------------------
             // Update page access
             // -------------------------------------
             case "update_access":
                 if (Request::get('slug') !== 'error404') {
                     if (Security::check(Request::get('token'))) {
                         $pages->updateWhere('[slug="' . Request::get('slug') . '"]', array('access' => Request::get('access')));
                         // Run delete extra actions
                         Action::run('admin_pages_action_update_access');
                         // Send notification
                         Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Request::get('slug'))));
                         // Redirect
                         Request::redirect('index.php?id=pages');
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 break;
                 // Update page status
                 // -------------------------------------
             // Update page status
             // -------------------------------------
             case "update_status":
                 if (Request::get('name') !== 'error404') {
                     if (Security::check(Request::get('token'))) {
                         $pages->updateWhere('[slug="' . Request::get('slug') . '"]', array('status' => Request::get('status')));
                         // Run delete extra actions
                         Action::run('admin_pages_action_update_status');
                         // Send notification
                         Notification::set('success', __('Your changes to the page <i>:page</i> have been saved.', 'pages', array(':page' => Request::get('slug'))));
                         // Redirect
                         Request::redirect('index.php?id=pages');
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 break;
         }
         // Its mean that you can add your own actions for this plugin
         Action::run('admin_pages_extra_actions');
     } else {
         // Index action
         // -------------------------------------
         // Init vars
         $pages_array = array();
         $count = 0;
         // Get pages
         $pages_list = $pages->select(null, 'all', null, array('slug', 'title', 'status', 'date', 'author', 'expand', 'access', 'parent', 'template', 'tags'));
         // Loop
         foreach ($pages_list as $page) {
             $pages_array[$count]['title'] = $page['title'];
             $pages_array[$count]['meta_title'] = isset($page['meta_title']) ? $page['meta_title'] : '';
             $pages_array[$count]['parent'] = $page['parent'];
             $pages_array[$count]['_status'] = $page['status'];
             $pages_array[$count]['_access'] = $page['access'];
             $pages_array[$count]['status'] = $status_array[$page['status']];
             $pages_array[$count]['access'] = isset($access_array[$page['access']]) ? $access_array[$page['access']] : $access_array['public'];
             // hack for old Monstra Versions
             $pages_array[$count]['date'] = $page['date'];
             $pages_array[$count]['author'] = $page['author'];
             $pages_array[$count]['expand'] = $page['expand'];
             $pages_array[$count]['slug'] = $page['slug'];
             $pages_array[$count]['tags'] = $page['tags'];
             $pages_array[$count]['template'] = $page['template'];
             if (isset($page['parent'])) {
                 $c_p = $page['parent'];
             } else {
                 $c_p = '';
             }
             if ($c_p != '') {
                 $_page = $pages->select('[slug="' . $page['parent'] . '"]', null);
                 if (isset($_page['title'])) {
                     $_title = $_page['title'];
                 } else {
                     $_title = '';
                 }
                 $pages_array[$count]['sort'] = $_title . ' ' . $page['title'];
             } else {
                 $pages_array[$count]['sort'] = $page['title'];
             }
             $_title = '';
             $count++;
         }
         // Sort pages
         $pages = Arr::subvalSort($pages_array, 'sort');
         // Display view
         View::factory('box/pages/views/backend/index')->assign('pages', $pages)->assign('site_url', $site_url)->display();
     }
 }
 /**
  * System plugin admin
  */
 public static function main()
 {
     if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
         $filters = Filter::$filters;
         $plugins = Plugin::$plugins;
         $components = Plugin::$components;
         $actions = Action::$actions;
         // Get pages table
         $pages = new Table('pages');
         // Get system timezone
         $system_timezone = Option::get('timezone');
         // Get languages files
         $language_files = File::scan(PLUGINS_BOX . DS . 'system' . DS . 'languages' . DS, '.lang.php');
         foreach ($language_files as $language) {
             $parts = explode('.', $language);
             $languages_array[$parts[0]] = I18n::$locales[$parts[0]];
         }
         // Get all pages
         $pages_array = array();
         $pages_list = $pages->select('[slug!="error404" and parent="" and status="published"]');
         foreach ($pages_list as $page) {
             $pages_array[$page['slug']] = Html::toText($page['title']);
         }
         // Create Sitemap
         // -------------------------------------
         if (Request::get('sitemap') == 'create') {
             if (Security::check(Request::get('token'))) {
                 Notification::set('success', __('Sitemap created', 'system'));
                 Sitemap::create();
                 Request::redirect('index.php?id=system');
             } else {
                 die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
             }
         }
         // Delete temporary files
         // -------------------------------------
         if (Request::get('temporary_files') == 'delete') {
             if (Security::check(Request::get('token'))) {
                 Monstra::cleanTmp();
                 if (count(File::scan(MINIFY, array('css', 'js', 'php'))) == 0 && count(Dir::scan(CACHE)) == 0) {
                     Notification::set('success', __('Temporary files deleted', 'system'));
                     Request::redirect('index.php?id=system');
                 }
             } else {
                 die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
             }
         }
         // Set maintenance state on or off
         // -------------------------------------
         if (Request::get('maintenance')) {
             if (Security::check(Request::get('token'))) {
                 if ('on' == Request::get('maintenance')) {
                     Option::update('maintenance_status', 'on');
                     Request::redirect('index.php?id=system');
                 }
                 if ('off' == Request::get('maintenance')) {
                     Option::update('maintenance_status', 'off');
                     Request::redirect('index.php?id=system');
                 }
             } else {
                 die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
             }
         }
         // Edit settings
         // -------------------------------------
         if (Request::post('edit_settings')) {
             if (Security::check(Request::post('csrf'))) {
                 // Add trailing slashes
                 $_site_url = Request::post('system_url');
                 Option::update(array('sitename' => Request::post('site_name'), 'keywords' => Request::post('site_keywords'), 'description' => Request::post('site_description'), 'slogan' => Request::post('site_slogan'), 'defaultpage' => Request::post('site_default_page'), 'siteurl' => $_site_url, 'timezone' => Request::post('system_timezone'), 'system_email' => Request::post('system_email'), 'language' => Request::post('system_language'), 'maintenance_message' => Request::post('site_maintenance_message')));
                 Notification::set('success', __('Your changes have been saved.', 'system'));
                 Request::redirect('index.php?id=system');
             } else {
                 die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
             }
         }
         // Its mean that you can add your own actions for this plugin
         Action::run('admin_system_extra_actions');
         // Display view
         View::factory('box/system/views/backend/index')->assign('pages_array', $pages_array)->assign('languages_array', $languages_array)->display();
     } else {
         Request::redirect('index.php?id=users&action=edit&user_id=' . Session::get('user_id'));
     }
 }
 /**
  * Snippets admin function
  */
 public static function main()
 {
     // Init vars
     $snippets_path = STORAGE . DS . 'snippets' . DS;
     $snippets_list = array();
     $errors = array();
     // Check for get actions
     // -------------------------------------
     if (Request::get('action')) {
         // Switch actions
         // -------------------------------------
         switch (Request::get('action')) {
             // Add snippet
             // -------------------------------------
             case "add_snippet":
                 if (Request::post('add_snippets') || Request::post('add_snippets_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         if (trim(Request::post('name')) == '') {
                             $errors['snippets_empty_name'] = __('Required field', 'snippets');
                         }
                         if (file_exists($snippets_path . Security::safeName(Request::post('name')) . '.snippet.php')) {
                             $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
                         }
                         if (count($errors) == 0) {
                             // Save snippet
                             File::setContent($snippets_path . Security::safeName(Request::post('name')) . '.snippet.php', Request::post('content'));
                             Notification::set('success', __('Your changes to the snippet <i>:name</i> have been saved.', 'snippets', array(':name' => Security::safeName(Request::post('name')))));
                             if (Request::post('add_snippets_and_exit')) {
                                 Request::redirect('index.php?id=snippets');
                             } else {
                                 Request::redirect('index.php?id=snippets&action=edit_snippet&filename=' . Security::safeName(Request::post('name')));
                             }
                         }
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 // Save fields
                 if (Request::post('name')) {
                     $name = Request::post('name');
                 } else {
                     $name = '';
                 }
                 if (Request::post('content')) {
                     $content = Request::post('content');
                 } else {
                     $content = '';
                 }
                 // Display view
                 View::factory('box/snippets/views/backend/add')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->display();
                 break;
                 // Edit snippet
                 // -------------------------------------
             // Edit snippet
             // -------------------------------------
             case "edit_snippet":
                 // Save current snippet action
                 if (Request::post('edit_snippets') || Request::post('edit_snippets_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         if (trim(Request::post('name')) == '') {
                             $errors['snippets_empty_name'] = __('Required field', 'snippets');
                         }
                         if (file_exists($snippets_path . Security::safeName(Request::post('name')) . '.snippet.php') and Security::safeName(Request::post('snippets_old_name')) !== Security::safeName(Request::post('name'))) {
                             $errors['snippets_exists'] = __('This snippet already exists', 'snippets');
                         }
                         // Save fields
                         if (Request::post('content')) {
                             $content = Request::post('content');
                         } else {
                             $content = '';
                         }
                         if (count($errors) == 0) {
                             $snippet_old_filename = $snippets_path . Request::post('snippets_old_name') . '.snippet.php';
                             $snippet_new_filename = $snippets_path . Security::safeName(Request::post('name')) . '.snippet.php';
                             if (!empty($snippet_old_filename)) {
                                 if ($snippet_old_filename !== $snippet_new_filename) {
                                     rename($snippet_old_filename, $snippet_new_filename);
                                     $save_filename = $snippet_new_filename;
                                 } else {
                                     $save_filename = $snippet_new_filename;
                                 }
                             } else {
                                 $save_filename = $snippet_new_filename;
                             }
                             // Save snippet
                             File::setContent($save_filename, Request::post('content'));
                             Notification::set('success', __('Your changes to the snippet <i>:name</i> have been saved.', 'snippets', array(':name' => basename($save_filename, '.snippet.php'))));
                             if (Request::post('edit_snippets_and_exit')) {
                                 Request::redirect('index.php?id=snippets');
                             } else {
                                 Request::redirect('index.php?id=snippets&action=edit_snippet&filename=' . Security::safeName(Request::post('name')));
                             }
                         }
                     } else {
                         die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                     }
                 }
                 if (Request::post('name')) {
                     $name = Request::post('name');
                 } else {
                     $name = File::name(Request::get('filename'));
                 }
                 $content = File::getContent($snippets_path . Request::get('filename') . '.snippet.php');
                 // Display view
                 View::factory('box/snippets/views/backend/edit')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->display();
                 break;
             case "delete_snippet":
                 if (Security::check(Request::get('token'))) {
                     File::delete($snippets_path . Request::get('filename') . '.snippet.php');
                     Notification::set('success', __('Snippet <i>:name</i> deleted', 'snippets', array(':name' => File::name(Request::get('filename')))));
                     Request::redirect('index.php?id=snippets');
                 } else {
                     die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
                 }
                 break;
         }
     } else {
         // Get snippets
         $snippets_list = File::scan($snippets_path, '.snippet.php');
         // Display view
         View::factory('box/snippets/views/backend/index')->assign('snippets_list', $snippets_list)->display();
     }
 }
 /**
  * Get Scripts
  *
  * @param  string $theme Theme name
  * @return mixed
  */
 public static function getScripts($theme = null)
 {
     $theme = $theme === null ? null : (string) $theme;
     if ($theme == null) {
         $theme = Option::get('theme_site_name');
     }
     $scripts = array();
     // Get all templates in current theme folder
     $scripts = File::scan(THEMES_SITE . DS . $theme . DS . 'js' . DS, '.js');
     return $scripts ? $scripts : array();
 }