/** * Form Component Save */ public static function formComponentSave() { if (Request::post('sandbox_component_save')) { if (Security::check(Request::post('csrf'))) { Option::update('sandbox_template', Request::post('sandbox_form_template')); Request::redirect('index.php?id=themes'); } } }
public function update($data) { global $wpdb; $entity = new Entity(); $option = new Option(); $dataEntity = ['id' => $data['id'], 'name' => $data['name'], 'activate' => $data['activate'], 'sm_entity_id' => $data['sm_entity_id']]; $entity->update($dataEntity); $optionsEntity = ['idSource' => $data['id'], 'category' => $data['category'], 'publish_type' => $data['publish_type'], 'display_type' => $data['display_type'], 'link_canonical' => $data['link_canonical'], 'image' => $data['image'], 'noIndex' => $data['noIndex'], 'noFollow' => $data['noFollow'], 'readmore' => $data['readmore'], 'morebalise' => $data['morebalise']]; $option->update($optionsEntity); }
/** * Main Dashboard admin function */ public static function main() { // set/update google analytics settings if (Request::post('ga_settings_update')) { if (Security::check(Request::post('csrf'))) { // client id $ga_client_id = trim(Request::post('ga_client_id')); if (!empty($ga_client_id)) { $opt_client_id = Option::get('ga_client_id'); if (empty($opt_client_id)) { Option::add('ga_client_id', $ga_client_id); } else { Option::update('ga_client_id', $ga_client_id); } } // API key $ga_api_key = trim(Request::post('ga_api_key')); if (!empty($ga_api_key)) { $opt_api_key = Option::get('ga_api_key'); if (empty($opt_api_key)) { Option::add('ga_api_key', $ga_api_key); } else { Option::update('ga_api_key', $ga_api_key); } } // view id $ga_view_id = trim(Request::post('ga_view_id')); if (!empty($ga_view_id)) { $opt_view_id = Option::get('ga_view_id'); if (empty($opt_view_id)) { Option::add('ga_view_id', $ga_view_id); } else { Option::update('ga_view_id', $ga_view_id); } } // tracking id $ga_tracking_id = trim(Request::post('ga_tracking_id')); if (!empty($ga_tracking_id)) { $opt_view_id = Option::get('ga_tracking_id'); if (empty($opt_view_id)) { Option::add('ga_tracking_id', $ga_tracking_id); } else { Option::update('ga_tracking_id', $ga_tracking_id); } } } } // Display view View::factory('box/dashboard/views/backend/index')->display(); }
/** * main toggle admin function */ public static function main() { // handle option form submit if (Request::post('toggle_options')) { if (Security::check(Request::post('csrf'))) { Option::update('toggle_duration', (int) Request::post('toggle_duration')); Option::update('toggle_easing', Request::post('toggle_easing')); Notification::set('success', __('Configuration has been saved with success!', 'toggle')); } else { Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'toggle')); die; } Request::redirect('index.php?id=toggle'); } // Display view View::factory('toggle/views/backend/index')->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')); } }
/** * javascriptVersionIncrement */ public static function javascriptVersionIncrement() { Option::update('javascript_version', (int) Option::get('javascript_version') + 1); }
if (trim(Request::post('public') !== '')) { $errors['public'] = true; } if (trim(Request::post('storage') !== '')) { $errors['storage'] = true; } if (trim(Request::post('backups') !== '')) { $errors['backups'] = true; } if (trim(Request::post('tmp') !== '')) { $errors['tmp'] = true; } // If errors is 0 then install cms if (count($errors) == 0) { // Update options Option::update(array('maintenance_status' => 'off', 'sitename' => Request::post('sitename'), 'siteurl' => Request::post('siteurl'), 'description' => __('Site description', 'system'), 'keywords' => __('Site keywords', 'system'), 'slogan' => __('Site slogan', 'system'), 'defaultpage' => 'home', 'timezone' => Request::post('timezone'), 'system_email' => Request::post('email'), 'theme_site_name' => 'default', 'theme_admin_name' => 'default')); // Get users table $users = new Table('users'); // Insert new user with role = admin $users->insert(array('login' => Security::safeName(Request::post('login')), 'password' => Security::encryptPassword(Request::post('password')), 'email' => Request::post('email'), 'hash' => Text::random('alnum', 12), 'date_registered' => time(), 'role' => 'admin')); // Write .htaccess $htaccess = file_get_contents('.htaccess'); $save_htaccess_content = str_replace("/%siteurlhere%/", $rewrite_base, $htaccess); $handle = fopen('.htaccess', "w"); fwrite($handle, $save_htaccess_content); fclose($handle); // Installation done :) header("location: index.php?install=done"); } else { Notification::setNow('errors', $errors); }
/** * Themes plugin admin */ public static function main() { // Get current themes $current_site_theme = Option::get('theme_site_name'); $current_admin_theme = Option::get('theme_admin_name'); // Init vars $themes_site = Themes::getSiteThemes(); $themes_admin = Themes::getAdminThemes(); $templates = Themes::getTemplates(); $chunks = Themes::getChunks(); $styles = Themes::getStyles(); $scripts = Themes::getScripts(); $errors = array(); $chunk_path = THEMES_SITE . DS . $current_site_theme . DS; $template_path = THEMES_SITE . DS . $current_site_theme . DS; $style_path = THEMES_SITE . DS . $current_site_theme . DS . 'css' . DS; $script_path = THEMES_SITE . DS . $current_site_theme . DS . 'js' . DS; // Save site theme if (Request::post('save_site_theme')) { if (Security::check(Request::post('csrf'))) { Option::update('theme_site_name', Request::post('themes')); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Styles and Javascript version Stylesheet::stylesVersionIncrement(); Javascript::javascriptVersionIncrement(); Request::redirect('index.php?id=themes'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Save site theme if (Request::post('save_admin_theme')) { if (Security::check(Request::post('csrf'))) { Option::update('theme_admin_name', Request::post('themes')); // Clean Monstra TMP folder. Monstra::cleanTmp(); Request::redirect('index.php?id=themes'); } 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_themes_extra_actions'); // Check for get actions // ------------------------------------- if (Request::get('action')) { // Switch actions // ------------------------------------- switch (Request::get('action')) { // Add chunk // ------------------------------------- case "add_chunk": if (Request::post('add_file') || Request::post('add_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($chunk_path . Security::safeName(Request::post('name'), null, false) . '.chunk.php')) { $errors['file_exists'] = __('This chunk already exists', 'themes'); } if (count($errors) == 0) { // Save chunk File::setContent($chunk_path . Security::safeName(Request::post('name'), null, false) . '.chunk.php', Request::post('content')); Notification::set('success', __('Your changes to the chunk <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name'), null, false)))); if (Request::post('add_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_chunk&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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/themes/views/backend/add')->assign('name', $name)->assign('content', $content)->assign('errors', $errors)->assign('action', 'chunk')->display(); break; // Add template // ------------------------------------- // Add template // ------------------------------------- case "add_template": if (Request::post('add_file') || Request::post('add_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($template_path . Security::safeName(Request::post('name'), null, false) . '.template.php')) { $errors['file_exists'] = __('This template already exists', 'themes'); } if (count($errors) == 0) { // Save chunk File::setContent($template_path . Security::safeName(Request::post('name'), null, false) . '.template.php', Request::post('content')); Notification::set('success', __('Your changes to the chunk <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name'), null, false)))); if (Request::post('add_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_template&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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/themes/views/backend/add')->assign('name', $name)->assign('content', $content)->assign('errors', $errors)->assign('action', 'template')->display(); break; // Add styles // ------------------------------------- // Add styles // ------------------------------------- case "add_styles": if (Request::post('add_file') || Request::post('add_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($style_path . Security::safeName(Request::post('name'), null, false) . '.css')) { $errors['file_exists'] = __('This styles already exists', 'themes'); } if (count($errors) == 0) { // Save chunk File::setContent($style_path . Security::safeName(Request::post('name'), null, false) . '.css', Request::post('content')); Notification::set('success', __('Your changes to the styles <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name'), null, false)))); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Styles version Stylesheet::stylesVersionIncrement(); if (Request::post('add_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_styles&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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/themes/views/backend/add')->assign('name', $name)->assign('content', $content)->assign('errors', $errors)->assign('action', 'styles')->display(); break; // Add script // ------------------------------------- // Add script // ------------------------------------- case "add_script": if (Request::post('add_file') || Request::post('add_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($script_path . Security::safeName(Request::post('name'), null, false) . '.js')) { $errors['file_exists'] = __('This script already exists', 'themes'); } if (count($errors) == 0) { // Save chunk File::setContent($script_path . Security::safeName(Request::post('name'), null, false) . '.js', Request::post('content')); Notification::set('success', __('Your changes to the script <i>:name</i> have been saved.', 'themes', array(':name' => Security::safeName(Request::post('name'), null, false)))); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Javascript version Javascript::javascriptVersionIncrement(); if (Request::post('add_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_script&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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/themes/views/backend/add')->assign('name', $name)->assign('content', $content)->assign('errors', $errors)->assign('action', 'script')->display(); break; // Edit chunk // ------------------------------------- // Edit chunk // ------------------------------------- case "edit_chunk": // Save current chunk action if (Request::post('edit_file') || Request::post('edit_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($chunk_path . Security::safeName(Request::post('name'), null, false) . '.chunk.php') and Security::safeName(Request::post('chunk_old_name'), null, false) !== Security::safeName(Request::post('name'), null, false)) { $errors['file_exists'] = __('This chunk already exists', 'themes'); } // Save fields if (Request::post('content')) { $content = Request::post('content'); } else { $content = ''; } if (count($errors) == 0) { $chunk_old_filename = $chunk_path . Request::post('chunk_old_name') . '.chunk.php'; $chunk_new_filename = $chunk_path . Security::safeName(Request::post('name'), null, false) . '.chunk.php'; if (!empty($chunk_old_filename)) { if ($chunk_old_filename !== $chunk_new_filename) { rename($chunk_old_filename, $chunk_new_filename); $save_filename = $chunk_new_filename; } else { $save_filename = $chunk_new_filename; } } else { $save_filename = $chunk_new_filename; } // Save chunk File::setContent($save_filename, Request::post('content')); Notification::set('success', __('Your changes to the chunk <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.chunk.php')))); if (Request::post('edit_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_chunk&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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($chunk_path . Request::get('filename') . '.chunk.php'); // Display view View::factory('box/themes/views/backend/edit')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->assign('action', 'chunk')->display(); break; // Edit Template // ------------------------------------- // Edit Template // ------------------------------------- case "edit_template": // Save current chunk action if (Request::post('edit_file') || Request::post('edit_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($template_path . Security::safeName(Request::post('name'), null, false) . '.template.php') and Security::safeName(Request::post('template_old_name'), null, false) !== Security::safeName(Request::post('name'), null, false)) { $errors['template_exists'] = __('This template already exists', 'themes'); } // Save fields if (Request::post('content')) { $content = Request::post('content'); } else { $content = ''; } if (count($errors) == 0) { $template_old_filename = $template_path . Request::post('template_old_name') . '.template.php'; $template_new_filename = $template_path . Security::safeName(Request::post('name'), null, false) . '.template.php'; if (!empty($template_old_filename)) { if ($template_old_filename !== $template_new_filename) { rename($template_old_filename, $template_new_filename); $save_filename = $template_new_filename; } else { $save_filename = $template_new_filename; } } else { $save_filename = $template_new_filename; } // Save chunk File::setContent($save_filename, Request::post('content')); Notification::set('success', __('Your changes to the template <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.template.php')))); if (Request::post('edit_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_template&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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($chunk_path . Request::get('filename') . '.template.php'); // Display view View::factory('box/themes/views/backend/edit')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->assign('action', 'template')->display(); break; // Edit Styles // ------------------------------------- // Edit Styles // ------------------------------------- case "edit_styles": // Save current chunk action if (Request::post('edit_file') || Request::post('edit_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($style_path . Security::safeName(Request::post('name'), null, false) . '.css') and Security::safeName(Request::post('styles_old_name'), null, false) !== Security::safeName(Request::post('name'), null, false)) { $errors['file_exists'] = __('This styles already exists', 'themes'); } // Save fields if (Request::post('content')) { $content = Request::post('content'); } else { $content = ''; } if (count($errors) == 0) { $styles_old_filename = $style_path . Request::post('styles_old_name') . '.css'; $styles_new_filename = $style_path . Security::safeName(Request::post('name'), null, false) . '.css'; if (!empty($styles_old_filename)) { if ($styles_old_filename !== $styles_new_filename) { rename($styles_old_filename, $styles_new_filename); $save_filename = $styles_new_filename; } else { $save_filename = $styles_new_filename; } } else { $save_filename = $styles_new_filename; } // Save chunk File::setContent($save_filename, Request::post('content')); Notification::set('success', __('Your changes to the styles <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.css')))); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Styles version Stylesheet::stylesVersionIncrement(); if (Request::post('edit_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_styles&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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($style_path . Request::get('filename') . '.css'); // Display view View::factory('box/themes/views/backend/edit')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->assign('action', 'styles')->display(); break; // Edit Script // ------------------------------------- // Edit Script // ------------------------------------- case "edit_script": // Save current chunk action if (Request::post('edit_file') || Request::post('edit_file_and_exit')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('name')) == '') { $errors['file_empty_name'] = __('Required field', 'themes'); } if (file_exists($script_path . Security::safeName(Request::post('name'), null, false) . '.js') and Security::safeName(Request::post('script_old_name'), null, false) !== Security::safeName(Request::post('name'), null, false)) { $errors['file_exists'] = __('This script already exists', 'themes'); } // Save fields if (Request::post('content')) { $content = Request::post('content'); } else { $content = ''; } if (count($errors) == 0) { $script_old_filename = $script_path . Request::post('script_old_name') . '.js'; $script_new_filename = $script_path . Security::safeName(Request::post('name'), null, false) . '.js'; if (!empty($script_old_filename)) { if ($script_old_filename !== $script_new_filename) { rename($script_old_filename, $script_new_filename); $save_filename = $script_new_filename; } else { $save_filename = $script_new_filename; } } else { $save_filename = $script_new_filename; } // Save chunk File::setContent($save_filename, Request::post('content')); Notification::set('success', __('Your changes to the script <i>:name</i> have been saved.', 'themes', array(':name' => basename($save_filename, '.js')))); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Javascript version Javascript::javascriptVersionIncrement(); if (Request::post('edit_file_and_exit')) { Request::redirect('index.php?id=themes'); } else { Request::redirect('index.php?id=themes&action=edit_script&filename=' . Security::safeName(Request::post('name'), null, false)); } } } 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($script_path . Request::get('filename') . '.js'); // Display view View::factory('box/themes/views/backend/edit')->assign('content', $content)->assign('name', $name)->assign('errors', $errors)->assign('action', 'script')->display(); break; // Delete chunk // ------------------------------------- // Delete chunk // ------------------------------------- case "delete_chunk": if (Security::check(Request::get('token'))) { File::delete($chunk_path . Request::get('filename') . '.chunk.php'); Notification::set('success', __('Chunk <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename'))))); Request::redirect('index.php?id=themes'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } break; // Delete styles // ------------------------------------- // Delete styles // ------------------------------------- case "delete_styles": if (Security::check(Request::get('token'))) { File::delete($style_path . Request::get('filename') . '.css'); Notification::set('success', __('Styles <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename'))))); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Styles version Stylesheet::stylesVersionIncrement(); Request::redirect('index.php?id=themes'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } break; // Delete script // ------------------------------------- // Delete script // ------------------------------------- case "delete_script": if (Security::check(Request::get('token'))) { File::delete($script_path . Request::get('filename') . '.js'); Notification::set('success', __('Script <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename'))))); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Javascript version Javascript::javascriptVersionIncrement(); Request::redirect('index.php?id=themes'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } break; // Delete template // ------------------------------------- // Delete template // ------------------------------------- case "delete_template": if (Security::check(Request::get('token'))) { File::delete($template_path . Request::get('filename') . '.template.php'); Notification::set('success', __('Template <i>:name</i> deleted', 'themes', array(':name' => File::name(Request::get('filename'))))); Request::redirect('index.php?id=themes'); } break; // Clone styles // ------------------------------------- // Clone styles // ------------------------------------- case "clone_styles": if (Security::check(Request::get('token'))) { File::setContent(THEMES_SITE . DS . $current_site_theme . DS . 'css' . DS . Request::get('filename') . '_clone_' . date("Ymd_His") . '.css', File::getContent(THEMES_SITE . DS . $current_site_theme . DS . 'css' . DS . Request::get('filename') . '.css')); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Styles version Stylesheet::stylesVersionIncrement(); Request::redirect('index.php?id=themes'); } break; // Clone script // ------------------------------------- // Clone script // ------------------------------------- case "clone_script": if (Security::check(Request::get('token'))) { File::setContent(THEMES_SITE . DS . $current_site_theme . DS . 'js' . DS . Request::get('filename') . '_clone_' . date("Ymd_His") . '.js', File::getContent(THEMES_SITE . DS . $current_site_theme . DS . 'js' . DS . Request::get('filename') . '.js')); // Clean Monstra TMP folder. Monstra::cleanTmp(); // Increment Javascript version Javascript::javascriptVersionIncrement(); Request::redirect('index.php?id=themes'); } break; // Clone template // ------------------------------------- // Clone template // ------------------------------------- case "clone_template": if (Security::check(Request::get('token'))) { File::setContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') . '_clone_' . date("Ymd_His") . '.template.php', File::getContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') . '.template.php')); Request::redirect('index.php?id=themes'); } break; // Clone chunk // ------------------------------------- // Clone chunk // ------------------------------------- case "clone_chunk": if (Security::check(Request::get('token'))) { File::setContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') . '_clone_' . date("Ymd_His") . '.chunk.php', File::getContent(THEMES_SITE . DS . $current_site_theme . DS . Request::get('filename') . '.chunk.php')); Request::redirect('index.php?id=themes'); } break; } } else { // Display view View::factory('box/themes/views/backend/index')->assign('themes_site', $themes_site)->assign('themes_admin', $themes_admin)->assign('templates', $templates)->assign('chunks', $chunks)->assign('styles', $styles)->assign('scripts', $scripts)->assign('current_site_theme', $current_site_theme)->assign('current_admin_theme', $current_admin_theme)->display(); } }
/** * 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(); } }
/** * stylesVersionIncrement */ public static function stylesVersionIncrement() { Option::update('styles_version', (int) Option::get('styles_version') + 1); }
echo "Création d'une option ... "; $option = new Option(); $option->date = "2015-12-28"; $option->etat = "En cours"; $option->id_utilisateur = 1; $option->id_appartement = 1; // Ajout dans la base echo "OK<br/>Ajout de la option dans la base ... "; $option->insert(); echo "OK<br/>"; // Liste de toutes les options listerTout(); // Apport d'une modification $option->etat = "Rejetee"; echo "Modification de l'état ! Mise à jour dans la base ... "; $option->update(); echo "OK<br/>"; // Sélection de l'appartement $selectionOption = Option::findById($option->id_option); $selectionOption->afficher(); // Suppression du option echo "Suppression de l'option de la base ... "; $selectionOption->delete(); echo "OK<br/>"; // Liste de toutes les options listerTout(); function listerTout() { // Liste de toutes les options echo "Liste des options disponibles dans la base : <br/>"; $listeOptions = Option::findAll();
public function onAfterWrite() { parent::onAfterWrite(); //Check if first write if ($this->firstWrite) { $defaultAttribute = $this->DefaultAttribute(); if ($defaultAttribute && $defaultAttribute->exists()) { $options = $defaultAttribute->Options(); if ($options && $options->exists()) { foreach ($options as $option) { $newOption = new Option(); $newOption->update($option->tomap()); $newOption->ID = null; $newOption->AttributeID = $this->ID; $newOption->write(); } } } } //If product variation does not have a complete set of valid options, then disable it $product = $this->Product(); $variations = $product->Variations(); if ($variations) { foreach ($variations as $variation) { if (!$variation->hasValidOptions()) { $variation->Status = 'Disabled'; $variation->write(); } } } }
/** * Users admin */ public static function main() { // Users roles $roles = array('admin' => __('Admin', 'users'), 'editor' => __('Editor', 'users'), 'user' => __('User', 'users')); // Get uses table $users = new Table('users'); if (Option::get('users_frontend_registration') === 'true') { $users_frontend_registration = true; } else { $users_frontend_registration = false; } if (Request::post('users_frontend_submit')) { if (Security::check(Request::post('csrf'))) { if (Request::post('users_frontend_registration')) { $users_frontend_registration = 'true'; } else { $users_frontend_registration = 'false'; } if (Option::update('users_frontend_registration', $users_frontend_registration)) { Notification::set('success', __('Your changes have been saved.', 'users')); } else { Notification::set('error', __('Your changes was not saved.', 'users')); } Request::redirect('index.php?id=users'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Check for get actions // --------------------------------------------- if (Request::get('action')) { // Switch actions // ----------------------------------------- switch (Request::get('action')) { // Add // ------------------------------------- case "add": if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) { // Errors $errors = array(); if (Request::post('register')) { if (Security::check(Request::post('csrf'))) { $user_login = trim(Request::post('login')); $user_password = trim(Request::post('password')); $user_email = trim(Request::post('email')); if ($user_login == '') { $errors['users_empty_login'] = __('Required field', 'users'); } if ($user_password == '') { $errors['users_empty_password'] = __('Required field', 'users'); } if ($user_email == '') { $errors['users_empty_email'] = __('Required field', 'users'); } if ($users->select("[login='******']")) { $errors['users_this_user_already_exists'] = __('This user already exists', 'users'); } if ($users->select("[email='" . $user_email . "']")) { $errors['users_this_email_already_exists'] = __('This email already exists', 'users'); } if (count($errors) == 0) { if ($users->insert(array('login' => Security::safeName($user_login), 'password' => Security::encryptPassword(Request::post('password')), 'email' => Request::post('email'), 'hash' => Text::random('alnum', 12), 'date_registered' => time(), 'role' => Request::post('role')))) { Notification::set('success', __('New user have been registered.', 'users')); } else { Notification::set('error', __('New user was not registered.', 'users')); } Request::redirect('index.php?id=users'); } } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } // Display view View::factory('box/users/views/backend/add')->assign('roles', $roles)->assign('errors', $errors)->display(); } else { Request::redirect('index.php?id=users&action=edit&user_id=' . Session::get('user_id')); } break; // Edit // ------------------------------------- // Edit // ------------------------------------- case "edit": // Get current user record $user = $users->select("[id='" . (int) Request::get('user_id') . "']", null); if (isset($user['firstname'])) { $user_firstname = $user['firstname']; } else { $user_firstname = ''; } if (isset($user['lastname'])) { $user_lastname = $user['lastname']; } else { $user_lastname = ''; } if (isset($user['email'])) { $user_email = $user['email']; } else { $user_email = ''; } if (isset($user['twitter'])) { $user_twitter = $user['twitter']; } else { $user_twitter = ''; } if (isset($user['skype'])) { $user_skype = $user['skype']; } else { $user_skype = ''; } if (isset($user['about_me'])) { $user_about_me = $user['about_me']; } else { $user_about_me = ''; } if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin', 'editor'))) { if (Request::post('edit_profile') and ((int) Session::get('user_id') == (int) Request::get('user_id') or in_array(Session::get('user_role'), array('admin')))) { if (Security::check(Request::post('csrf'))) { if (Security::safeName(Request::post('login')) != '') { if ($users->update(Request::post('user_id'), array('login' => Security::safeName(Request::post('login')), 'firstname' => Request::post('firstname'), 'lastname' => Request::post('lastname'), 'email' => Request::post('email'), 'skype' => Request::post('skype'), 'twitter' => Request::post('twitter'), 'about_me' => Request::post('about_me'), 'role' => Request::post('role')))) { Notification::set('success', __('Your changes have been saved.', 'users')); } else { Notification::set('error', __('Your changes was not saved.', 'users')); } Request::redirect('index.php?id=users&action=edit&user_id=' . Request::post('user_id')); } } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } if (Request::post('edit_profile_password')) { if (Security::check(Request::post('csrf'))) { if (trim(Request::post('new_password')) != '') { if ($users->update(Request::post('user_id'), array('password' => Security::encryptPassword(trim(Request::post('new_password')))))) { Notification::set('success', __('Your changes have been saved.', 'users')); } else { Notification::set('error', __('Your changes was not saved.', 'users')); } Request::redirect('index.php?id=users&action=edit&user_id=' . Request::post('user_id')); } } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } if ((int) Session::get('user_id') == (int) Request::get('user_id') or in_array(Session::get('user_role'), array('admin')) && count($user) != 0) { // Display view View::factory('box/users/views/backend/edit')->assign('user', $user)->assign('user_firstname', $user_firstname)->assign('user_lastname', $user_lastname)->assign('user_email', $user_email)->assign('user_twitter', $user_twitter)->assign('user_skype', $user_skype)->assign('user_about_me', $user_about_me)->assign('roles', $roles)->display(); } else { echo __('Monstra says: This is not your profile...', 'users'); } } break; // Delete // ------------------------------------- // Delete // ------------------------------------- case "delete": if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin')) && (int) $_SESSION['user_id'] != (int) Request::get('user_id')) { if (Security::check(Request::get('token'))) { $user = $users->select('[id="' . Request::get('user_id') . '"]', null); if ($users->delete(Request::get('user_id'))) { Notification::set('success', __('User <i>:user</i> have been deleted.', 'users', array(':user' => $user['login']))); } else { Notification::set('error', __('User <i>:user</i> was not deleted.', 'users', array(':user' => $user['login']))); } Request::redirect('index.php?id=users'); } else { die('Request was denied because it contained an invalid security token. Please refresh the page and try again.'); } } break; } } else { if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) { // Dislay view View::factory('box/users/views/backend/index')->assign('roles', $roles)->assign('users_list', $users->select())->assign('users_frontend_registration', $users_frontend_registration)->display(); } else { Request::redirect('index.php?id=users&action=edit&user_id=' . Session::get('user_id')); } } }