public function browse() { $this->_checkPermission(); $params = func_get_args(); $this->path = join('/', $params); // make sure there's a / at the end if (substr($this->path, -1, 1) != '/') { $this->path .= '/'; } //security // we dont allow back link if (strpos($this->path, '..') !== false) { if (Plugin::isEnabled('statistics_api')) { $user = null; if (AuthUser::isLoggedIn()) { $user = AuthUser::getUserName(); } $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $event = array('event_type' => 'hack_attempt', 'description' => __('A possible hack attempt was detected.'), 'ipaddress' => $ip, 'username' => $user); Observer::notify('stats_file_manager_hack_attempt', $event); } } $this->fullpath = FILES_DIR . '/sidebarlink/images/'; // clean up nicely $this->fullpath = preg_replace('/\\/\\//', '/', $this->fullpath); $this->display('sidebarlink/index', array('dir' => $this->path, 'files' => $this->_getListFiles(), 'sidebarlinks' => Record::findAllFrom('SidebarLink', '1=1 ORDER BY id desc'), 'pages' => Record::findAllFrom('Page', 'parent_id=1 OR parent_id=0 order by parent_id,position'))); }
public function send($title, $text, $from = NULL, $to, $parent_id = 0, $to_from = TRUE) { if (!is_array($to)) { $to = array($to); } if (!empty($to)) { if ($from !== NULL and $to_from === TRUE) { $to[] = $from; } $to = array_unique($to); $users = DB::select('id', 'email')->from('users')->where('id', 'IN', $to)->execute()->as_array('id', 'email'); $message = Kses::filter($text, Kohana::$config->load('global')->get('allowed_html_tags')); $data = array('created_on' => date('Y-m-d H:i:s'), 'text' => $message, 'title' => $title, 'from_user_id' => $from); list($message_id, $rows) = DB::insert($this->table_name())->columns(array_keys($data))->values($data)->execute($this->_db); if ($message_id) { $insert = DB::insert('messages_users')->columns(array('status', 'user_id', 'message_id', 'parent_id')); foreach ($users as $id => $email) { $insert->values(array('status' => self::STATUS_NEW, 'user_id' => (int) $id, 'message_id' => $message_id, 'parent_id' => (int) $parent_id)); self::clear_cache($id); Observer::notify('send_message', (int) $id, $text); } $insert->execute($this->_db); if ($from !== NULL) { Api::post('user-messages.mark_read', array('id' => $message_id, 'uid' => $from)); } return $message_id; } } return FALSE; }
public static function loadFiles($path) { if (endsWith($path, "dashboard")) { $css = "dashboard.wolf.css"; if (Setting::get("theme") === "fox_theme") { $css = "dashboard.fox.css"; } else { if (Setting::get("theme") === "wordpress-3.8") { $css = "dashboard.wordpress.css"; } } $file = PATH_PUBLIC . "wolf/plugins/dashboard/system/css/" . $css; ?> <link rel="stylesheet" type="text/css" href="<?php echo $file; ?> " media="screen" /><?php Observer::notify("dashboard_load_css"); $file = PATH_PUBLIC . "wolf/plugins/dashboard/system/js/script.dashboard.js"; ?> <script type="text/javascript" language="javascript" src="<?php echo $file; ?> "></script><?php Observer::notify("dashboard_load_js"); } }
public function on_page_load() { $username = Auth::get_username(); Auth::instance()->logout(TRUE); Observer::notify('admin_after_logout', $username); HTTP::redirect($this->get('next_url', Request::current()->referrer())); }
public function before() { $page = strtolower(substr(get_class($this), 11)); Model_Navigation::init(Kohana::$config->load('sitemap')->as_array()); parent::before(); $navigation = Model_Navigation::get(); $this->page = Model_Navigation::$current; if ($this->auto_render !== TRUE) { return; } $this->template->set_global(array('page_body_id' => $this->get_path(), 'page_name' => $page, 'page' => $this->page)); if ($this->request->is_iframe()) { $navigation = NULL; $this->template->footer = NULL; $this->template->breadcrumbs = NULL; Config::set('site', 'profiling', 'no'); $this->query_params = array('type' => 'iframe'); } else { $this->template->breadcrumbs = Config::get('site', 'breadcrumbs') == Config::YES ? $this->breadcrumbs : NULL; $this->template->footer = View::factory('system/blocks/footer'); } $this->template->theme = 'theme-' . Model_User_Meta::get('admin_theme', Config::get('global', 'default_theme')); $this->template->bind_global('navigation', $navigation); Observer::notify('controller_before_' . $this->get_path()); }
public function on_page_load() { $email_ctx_id = $this->get('email_id_ctx', 'email'); $email = $this->_ctx->get($email_ctx_id); $referrer_page = Request::current()->referrer(); $next_page = $this->get('next_url', Request::current()->referrer()); if (!Valid::email($email)) { Messages::errors(__('Use a valid e-mail address.')); HTTP::redirect($referrer_page); } $user = ORM::factory('user', array('email' => $email)); if (!$user->loaded()) { Messages::errors(__('No user found!')); HTTP::redirect($referrer_page); } $reflink = ORM::factory('user_reflink')->generate($user, 'forgot', array('next_url' => URL::site($this->next_url, TRUE))); if (!$reflink) { Messages::errors(__('Reflink generate error')); HTTP::redirect($referrer_page); } Observer::notify('admin_login_forgot_before', $user); try { Email_Type::get('user_request_password')->send(array('username' => $user->username, 'email' => $user->email, 'reflink' => Route::url('reflink', array('code' => $reflink)), 'code' => $reflink)); Messages::success(__('Email with reflink send to address set in your profile')); } catch (Exception $e) { Messages::error(__('Something went wrong')); } HTTP::redirect($next_page); }
function comment_save(&$page) { // check if we need to save a comment if (!isset($_POST['comment'])) { return; } global $__FROG_CONN__; if ($page->comment_status != Comment::OPEN) { return; } $data = $_POST['comment']; if (is_null($data)) { return; } if (!isset($data['author_name']) or trim($data['author_name']) == '') { return; } if (!isset($data['author_email']) or trim($data['author_email']) == '') { return; } if (!isset($data['body']) or trim($data['body']) == '') { return; } use_helper('Kses'); $allowed_tags = array('a' => array('href' => array(), 'title' => array()), 'abbr' => array('title' => array()), 'acronym' => array('title' => array()), 'b' => array(), 'blockquote' => array('cite' => array()), 'br' => array(), 'code' => array(), 'em' => array(), 'i' => array(), 'p' => array(), 'strike' => array(), 'strong' => array()); // get the setting for comments moderations //$sql = 'SELECT value FROM '.TABLE_PREFIX.'setting WHERE name=\'auto_approve_comment\''; //$stmt = $__FROG_CONN__->prepare($sql); //$stmt->execute(); //$auto_approve_comment = (int) $stmt->fetchColumn(); $auto_approve_comment = 1; $sql = 'INSERT INTO ' . TABLE_PREFIX . 'comment (page_id, author_name, author_email, author_link, body, is_approved, created_on) VALUES (' . '\'' . $page->id . '\', ' . $__FROG_CONN__->quote(strip_tags($data['author_name'])) . ', ' . $__FROG_CONN__->quote(strip_tags($data['author_email'])) . ', ' . $__FROG_CONN__->quote(strip_tags($data['author_link'])) . ', ' . $__FROG_CONN__->quote(kses($data['body'], $allowed_tags)) . ', ' . $__FROG_CONN__->quote($auto_approve_comment) . ', ' . $__FROG_CONN__->quote(date('Y-m-d H:i:s')) . ')'; $__FROG_CONN__->exec($sql); Observer::notify('comment_after_add'); }
public function display($view, $vars = array(), $exit = true) { Observer::notify('system.display'); echo $this->render($view, $vars); if ($exit) { Observer::notify('system.shutdown'); exit; } }
function ru_logout() { // Allow plugins to handle logout events Observer::notify('logout_requested'); $username = AuthUser::getUserName(); AuthUser::logout(); Observer::notify('admin_after_logout', $username); redirect(get_url()); }
function funky_cache_delete_all() { $cache = FunkyCachePage::findAllFrom('FunkyCachePage'); foreach ($cache as $page) { $page->delete(); } $message = sprintf('Cache was automatically cleared.'); Observer::notify('log_event', $message, 'funky_cache', 7); }
public function action_logout() { $this->auto_render = FALSE; Auth::instance()->logout(TRUE); Observer::notify('admin_after_logout', Auth::get_username()); if ($next_url = Flash::get('redirect')) { $this->go($next_url); } $this->go_home(); }
public function action_index() { $id = (int) $this->request->param('id'); Observer::notify('handler_requested', $id); $widget = Widget_Manager::load($id); if ($widget === NULL or !$widget->is_handler()) { $this->go_home(); } $widget->run(); }
public function rest_put() { $layout = new Model_File_Layout($this->param('name', NULL, TRUE)); $layout->content = $this->param('content', NULL); $status = $layout->save(); if (!$status) { throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Something went wrong!'); } else { $this->json_redirect('layout/edit/' . $layout->name); $this->message('Layout has been saved!'); Observer::notify('layout_after_add', $layout); } $this->response($layout); }
public function rest_put() { $snippet = new Model_File_Snippet($this->param('name', NULL, TRUE)); $snippet->content = $this->param('content', NULL); $status = $snippet->save(); if (!$status) { throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Snippet :name has not been added!', array(':name' => $snippet->name)); } else { $this->json_redirect('snippet/edit/' . $snippet->name); $this->message('Snippet :name has been saved!', array(':name' => $snippet->name)); Observer::notify('snippet_after_add', $snippet); } $this->response(array('name' => $snippet->name, 'content' => $snippet->content)); }
protected function _login(Validation $validation, $remember) { if ($validation->check()) { Observer::notify('login_before', $validation); if (Auth::instance()->login($validation[$this->get('login_field')], $validation[$this->get('password_field')], $remember)) { Observer::notify('login_success', $validation[$this->get('login_field')]); HTTP::redirect($this->get_next_url()); } else { Observer::notify('login_failed', $validation); Messages::errors(__('Login failed. Please check your login data and try again.')); } } HTTP::redirect(Request::current()->referrer()); }
/** * * @throws Installer_Exception */ public function action_go() { $this->auto_render = FALSE; $post = $this->request->post('install'); try { $this->_installer->install($post); Observer::notify('after_install', $post); Cache::clear_file(); } catch (Validation_Exception $e) { Messages::errors($e->errors('validation')); $this->go_back(); } catch (Exception $e) { Messages::errors($e->getMessage()); $this->go_back(); } $this->go($post['admin_dir_name'] . '/login'); }
public function post_save() { $settings = $this->param('setting', array(), TRUE); $filter = Filter::factory($settings)->rule('site.allow_html_title', FALSE, Config::NO); $validation = Validation::factory(array()); Observer::notify('validation_settings', $validation, $filter, $settings); $filter->run(); $validation = $validation->copy($filter->data()); if (!$validation->check()) { throw new API_Validation_Exception($validation->errors('validation')); } $settings = $validation->data(); Config::set_from_array($settings); Observer::notify('save_settings', $settings); Kohana::$log->add(Log::INFO, ':user change Settings')->write(); $this->message('Settings has been saved!'); }
/** * Creates a page version children * * @param the current page */ public static function callback_page_updated($page) { if ($page->behavior_id == 'version' || $page->behavior_id == 'current_version') { return; } $new_version = PageVersion::createFrom($page); $new_version->save(); Observer::notify('version_add_after_save', $new_version); /* Clone the page parts. */ $page_parts = PagePart::findByPageId($page->id); if (count($page_parts)) { foreach ($page_parts as $part) { $part->page_id = $new_version->id; $part->id = null; $part->save(); } } }
protected function _execute(array $params) { if ($params['db_driver'] === NULL) { $params['db_driver'] = Minion_CLI::read(__('Please enter database driver (:types)', array(':types' => implode(', ', array_keys($this->_installer->database_drivers()))))); } if ($params['locale'] === NULL) { $params['locale'] = Minion_CLI::read(__('Please enter locale (:types)', array(':types' => implode(', ', array_keys(I18n::available_langs()))))); } if ($params['db_name'] === NULL) { $params['db_name'] = Minion_CLI::read(__('Please enter database name')); } if ($params['timezone'] === NULL) { $answer = Minion_CLI::read(__('Select current timezone automaticly (:current)', array(':current' => date_default_timezone_get())), array('y', 'n')); if ($answer == 'y') { $params['timezone'] = date_default_timezone_get(); } else { $params['timezone'] = Minion_CLI::read(__('Please enter current timezone (:site)', array(':site' => 'http://www.php.net/manual/en/timezones.php')), DateTimeZone::listIdentifiers()); } } if ($params['cache_type'] === NULL) { $params['cache_type'] = Minion_CLI::read(__('Please enter cache type (:types)', array(':types' => implode(', ', array_keys($this->_installer->cache_types()))))); } if ($params['session_type'] === NULL) { $session_types = Kohana::$config->load('installer')->get('session_types', array()); $params['session_type'] = Minion_CLI::read(__('Please enter session type (:types)', array(':types' => implode(', ', array_keys($this->_installer->session_types()))))); } if ($params['password'] !== NULL) { unset($params['password_generate']); $params['password_field'] = $params['password_confirm'] = $params['password']; } try { $this->_installer->install($params); Observer::notify('after_install', $params); Cache::clear_file(); Minion_CLI::write('=============================================='); Minion_CLI::write(__('KodiCMS installed successfully')); Minion_CLI::write('=============================================='); $install_data = Session::instance()->get_once('install_data'); Minion_CLI::write(__('Login: :login', array(':login' => Arr::get($install_data, 'username')))); Minion_CLI::write(__('Password: :password', array(':password' => Arr::get($install_data, 'password_field')))); } catch (Exception $e) { Minion_CLI::write(__(':text | :file [:line]', array(':text' => $e->getMessage(), ':file' => $e->getFile(), ':line' => $e->getLine()))); } }
public static function loadWidgets($path) { // LOAD CORE WIDGETS $dir = dirname(dirname(__FILE__)) . DS . "widgets" . DS; if (is_dir($dir)) { if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false) { if (!in_array($file, array(".", "..")) && is_dir($dir . $file)) { if (file_exists($dir . $file . DS . "index.php")) { include_once $dir . $file . DS . "index.php"; } } } closedir($handle); } } // SET PLUGIN WIDGET OBSERVER Observer::notify("dashboard_load_widgets"); // RETURN return $path; }
function save() { $settings = array(); $settings['funky_cache_by_default'] = $_POST['funky_cache_by_default']; $settings['funky_cache_suffix'] = $_POST['funky_cache_suffix']; $settings['funky_cache_folder'] = $_POST['funky_cache_folder']; if (Plugin::setAllSettings($settings, 'funky_cache')) { Flash::set('success', __('The cache settings have been updated.')); $message = sprintf('The cache settings were updated by :username.'); Observer::notify('log_event', $message, 'funky_cache', 5); } else { Flash::set('error', 'The cache settings could not be updated due to an error.'); $message = sprintf('An attempt by :username to update the cache settings failed.'); Observer::notify('log_event', $message, 'funky_cache', 2); } redirect(get_url('plugin/funky_cache/settings')); }
} ?> ><?php echo __('Event Banner'); ?> </a></li> <?php foreach (Plugin::$controllers as $plugin_name => $plugin) { if ($plugin->show_tab && AuthUser::hasPermission($plugin->permissions)) { ?> <?php Observer::notify('view_backend_list_plugin', $plugin_name, $plugin); ?> <li id="<?php echo $plugin_name; ?> -plugin" class="plugin"><a href="<?php echo get_url('plugin/' . $plugin_name); ?> "<?php if ($ctrl == 'plugin' && $action == $plugin_name) { echo ' class="current"'; } ?> ><?php echo __($plugin->label); ?>
/** * Обновление позици виджета на странице * * При передачи названия блока есть два системных состояния * 0 - Скрытый виджет * -1 - Удалить со страницы * * @param integer $page_id * @param integer $widget_id * @param array $data array(['block'] => [String], 'position' => [Integer]) */ public static function update_location_by_page($page_id, $widget_id, array $data) { if ($data['block'] < 0) { DB::delete('page_widgets')->where('widget_id', '=', (int) $widget_id)->where('page_id', '=', (int) $page_id)->execute(); } else { DB::update('page_widgets')->where('widget_id', '=', (int) $widget_id)->where('page_id', '=', (int) $page_id)->set(array('block' => $data['block'], 'position' => (int) $data['position']))->execute(); } Observer::notify('widget_set_location', array((int) $page_id)); }
?');"> <img src="<?php echo URI_PUBLIC; ?> wolf/admin/images/icon-remove.gif" alt="delete image" title="Delete Image" /> </a> </td> </tr> <?php } } ?> </tbody> </table> <?php Observer::notify('villa_edit_view_after_details', $villa); ?> </form> <br> <div id="boxes"> <div class="window" id="upload-file-popup"> <form action="<?php echo get_url('villa/upload/' . $villa->id); ?> " method="post" enctype="multipart/form-data"> <div class="titlebar"> <?php echo __('Image Upload'); ?>
function delete_about() { $this->_checkPermission(); $paths = func_get_args(); $id = urldecode(join('/', $paths)); $about = Record::findByIdFrom('About', $id); $file = FILES_DIR . '/about/' . $about->filename; $filename = array_pop($paths); $paths = join('/', $paths); if (is_file($file)) { if (!unlink($file)) { Flash::set('error', __('Permission denied!')); } } // find the about to delete if ($about = Record::findByIdFrom('About', $id)) { if ($about->delete()) { Flash::set('success', __('This aboutBanner has been deleted.')); Observer::notify('snippet_after_delete', $about); } else { Flash::set('error', __('This about Banner has not been deleted!')); } } else { Flash::set('error', __('About Banner not found!')); } redirect(get_url('about')); }
function unapprove($id) { // find the user to unapprove if ($comment = Record::findByIdFrom('Comment', $id)) { $comment->is_approved = 0; if ($comment->save()) { Flash::set('success', __('Comment has been unapproved!')); Observer::notify('comment_after_unapprove', $comment); } } else { Flash::set('error', __('Comment not found!')); } redirect(get_url('plugin/comment')); }
public function browse() { $this->_checkPermission(); $params = func_get_args(); $this->path = join('/', $params); // make sure there's a / at the end if (substr($this->path, -1, 1) != '/') { $this->path .= '/'; } //security // we dont allow back link if (strpos($this->path, '..') !== false) { if (Plugin::isEnabled('statistics_api')) { $user = null; if (AuthUser::isLoggedIn()) { $user = AuthUser::getUserName(); } $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $event = array('event_type' => 'hack_attempt', 'description' => __('A possible hack attempt was detected.'), 'ipaddress' => $ip, 'username' => $user); Observer::notify('stats_file_manager_hack_attempt', $event); } } $this->display('testimonial/index', array('testimonials' => Record::query('select * from ' . TABLE_PREFIX . 'testimonial ORDER BY ' . TABLE_PREFIX . 'testimonial.sequence, ' . TABLE_PREFIX . 'testimonial.id desc'), 'pages' => Record::findAllFrom('Page', 'parent_id=1 order by parent_id,position'))); }
public function before_delete() { Kohana::$log->add(Log::INFO, 'Role :role has been deleted by :user', array(':role' => HTML::anchor(Route::get('backend')->uri(array('controller' => 'roles', 'action' => 'edit', 'id' => $this->id)), $this->name)))->write(); Observer::notify('role_delete', $this->id); return TRUE; }
/** * Runs checks and stores a page. * * @param string $action What kind of action this is: add or edit. * @param mixed $id Page to edit if any. */ private function _store($action, $id = false) { // Sanity checks if ($action == 'edit' && !$id) { throw new Exception('Trying to edit page when $id is false.'); } use_helper('Validate'); $data = $_POST['page']; $data['is_protected'] = !empty($data['is_protected']) ? 1 : 0; Flash::set('post_data', (object) $data); // Add pre-save checks here $errors = false; // CSRF checks if (isset($_POST['csrf_token'])) { $csrf_token = $_POST['csrf_token']; if (!SecureToken::validateToken($csrf_token, BASE_URL . 'page/' . $action)) { $errors[] = __('Invalid CSRF token found!'); } } else { $errors[] = __('No CSRF token found!'); } $data['title'] = trim($data['title']); if (empty($data['title'])) { $errors[] = __('You have to specify a title!'); } $data['slug'] = trim($data['slug']); if (empty($data['slug']) && $id != '1') { $errors[] = __('You have to specify a slug!'); } else { if ($data['slug'] == ADMIN_DIR) { $errors[] = __('You cannot have a slug named :slug!', array(':slug' => ADMIN_DIR)); } if (!Validate::slug($data['slug']) && (!empty($data['slug']) && $id == '1')) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'slug')); } } // Check all numerical fields for a page $fields = array('parent_id', 'layout_id', 'needs_login'); foreach ($fields as $field) { if (!Validate::digit($data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } // Check all date fields for a page $fields = array('created_on', 'published_on', 'valid_until'); foreach ($fields as $field) { if (isset($data[$field])) { $data[$field] = trim($data[$field]); if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/D', (string) $data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } } // Check all time fields for a page $fields = array('created_on_time', 'published_on_time', 'valid_until_time'); foreach ($fields as $field) { if (isset($data[$field])) { $data[$field] = trim($data[$field]); if (!empty($data[$field]) && !(bool) preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/D', (string) $data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } } } // Check alphanumerical fields $fields = array('keywords', 'description'); foreach ($fields as $field) { use_helper('Kses'); $data[$field] = kses(trim($data[$field]), array()); /* if (!empty($data[$field]) && !Validate::alpha_comma($data[$field])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => $field)); } * */ } // Check behaviour_id field if (!empty($data['behaviour_id']) && !Validate::slug($data['behaviour_id'])) { $errors[] = __('Illegal value for :fieldname field!', array(':fieldname' => 'behaviour_id')); } // Make sure the title doesn't contain HTML if (Setting::get('allow_html_title') == 'off') { use_helper('Kses'); $data['title'] = kses(trim($data['title']), array()); } // Create the page object to be manipulated and populate data if ($action == 'add') { $page = new Page($data); } else { $page = Record::findByIdFrom('Page', $id); $page->setFromData($data); } // Upon errors, rebuild original page and return to screen with errors if (false !== $errors) { $tags = $_POST['page_tag']; // Rebuild time fields if (isset($page->created_on)) { $page->created_on = $page->created_on . ' ' . $page->created_on_time; } if (isset($page->published_on)) { $page->published_on = $page->published_on . ' ' . $page->published_on_time; } if (isset($page->valid_until)) { $page->valid_until = $page->valid_until . ' ' . $page->valid_until_time; } // Rebuild parts $part = $_POST['part']; if (!empty($part)) { $tmp = false; foreach ($part as $key => $val) { $tmp[$key] = (object) $val; } $part = $tmp; } // Set the errors to be displayed. Flash::setNow('error', implode('<br/>', $errors)); // display things ... $this->setLayout('backend'); $this->display('page/edit', array('action' => $action, 'csrf_token' => SecureToken::generateToken(BASE_URL . 'page/' . $action), 'page' => (object) $page, 'tags' => $tags, 'filters' => Filter::findAll(), 'behaviors' => Behavior::findAll(), 'page_parts' => (object) $part, 'layouts' => Record::findAllFrom('Layout'))); } // Notify if ($action == 'add') { Observer::notify('page_add_before_save', $page); } else { Observer::notify('page_edit_before_save', $page); } // Time to actually save the page // @todo rebuild this so parts are already set before save? // @todo determine lazy init impact if ($page->save()) { // Get data for parts of this page $data_parts = $_POST['part']; Flash::set('post_parts_data', (object) $data_parts); if ($action == 'edit') { $old_parts = PagePart::findByPageId($id); // check if all old page part are passed in POST // if not ... we need to delete it! foreach ($old_parts as $old_part) { $not_in = true; foreach ($data_parts as $part_id => $data) { $data['name'] = trim($data['name']); if ($old_part->name == $data['name']) { $not_in = false; // this will not really create a new page part because // the id of the part is passed in $data $part = new PagePart($data); $part->page_id = $id; Observer::notify('part_edit_before_save', $part); $part->save(); Observer::notify('part_edit_after_save', $part); unset($data_parts[$part_id]); break; } } if ($not_in) { $old_part->delete(); } } } // add the new parts foreach ($data_parts as $data) { $data['name'] = trim($data['name']); $part = new PagePart($data); $part->page_id = $page->id; Observer::notify('part_add_before_save', $part); $part->save(); Observer::notify('part_add_after_save', $part); } // save tags $page->saveTags($_POST['page_tag']['tags']); Flash::set('success', __('Page has been saved!')); } else { Flash::set('error', __('Page has not been saved!')); $url = 'page/'; $url .= $action == 'edit' ? 'edit/' . $id : 'add/'; redirect(get_url($url)); } if ($action == 'add') { Observer::notify('page_add_after_save', $page); } else { Observer::notify('page_edit_after_save', $page); } // save and quit or save and continue editing ? if (isset($_POST['commit'])) { redirect(get_url('page')); } else { redirect(get_url('page/edit/' . $page->id)); } }
* @see http://kohanaframework.org/guide/using.configuration * @see http://php.net/timezones */ date_default_timezone_set(DEFAULT_TIMEZONE); /** * Cookie Salt * @see http://kohanaframework.org/3.3/guide/kohana/cookies * * If you have not defined a cookie salt in your Cookie class then * uncomment the line below and define a preferrably long salt. */ Cookie::$salt = COOKIE_SALT; /** * Set the default session type */ Session::$default = SESSION_TYPE; /** * Enable modules. Modules are referenced by a relative or absolute path. */ Kohana::modules(array('users' => MODPATH . 'users', 'kodicms' => MODPATH . 'kodicms', 'assets' => MODPATH . 'assets', 'cache' => MODPATH . 'cache', 'database' => MODPATH . 'database', 'logs' => MODPATH . 'logs', 'auth' => MODPATH . 'auth', 'orm' => MODPATH . 'orm', 'oauth' => MODPATH . 'oauth', 'minion' => MODPATH . 'minion', 'pagination' => MODPATH . 'pagination', 'email' => MODPATH . 'email', 'email_queue' => MODPATH . 'email_queue', 'filesystem' => MODPATH . 'filesystem', 'image' => MODPATH . 'image', 'scheduler' => MODPATH . 'scheduler', 'snippet' => MODPATH . 'snippet', 'pages' => MODPATH . 'pages', 'page_parts' => MODPATH . 'page_parts', 'tags' => MODPATH . 'tags', 'widget' => MODPATH . 'widget', 'reflinks' => MODPATH . 'reflinks', 'elfinder' => MODPATH . 'elfinder', 'api' => MODPATH . 'api', 'navigation' => MODPATH . 'navigation', 'breadcrumbs' => MODPATH . 'breadcrumbs', 'behavior' => MODPATH . 'behavior', 'plugins' => MODPATH . 'plugins', 'datasource' => MODPATH . 'datasource', 'search' => MODPATH . 'search', 'sidebar' => MODPATH . 'sidebar', 'update' => MODPATH . 'update', 'captcha' => MODPATH . 'captcha', 'dashboard' => MODPATH . 'dashboard')); Kohana::$config->attach(new Config_Database()); Observer::notify('modules::after_load'); Kohana::$log->attach(new Log_Database('logs')); Route::set('user', ADMIN_DIR_NAME . '/<action>(?next=<next_url>)', array('action' => '(login|logout|forgot)'))->defaults(array('controller' => 'login')); Route::set('templates', ADMIN_DIR_NAME . '/(<controller>(/<action>(/<id>)))', array('controller' => '(layout|snippet)', 'id' => '.*'))->defaults(array('controller' => 'index', 'action' => 'index')); Route::set('downloader', '(' . ADMIN_DIR_NAME . '/)download/<path>', array('path' => '.*'))->defaults(array('directory' => 'system', 'controller' => 'download', 'action' => 'index')); Route::set('backend', ADMIN_DIR_NAME . '(/<controller>(/<action>(/<id>)))')->defaults(array('controller' => 'dashboard', 'action' => 'index')); Route::set('system', '<directory>-<controller>-<action>(/<id>)', array('directory' => '(ajax|action|form)', 'controller' => '[A-Za-z\\_]+', 'action' => '[A-Za-z\\_]+', 'id' => '.+')); Route::set('default', '(<page>)(<suffix>)', array('page' => '.*', 'suffix' => URL_SUFFIX))->defaults(array('controller' => 'front', 'action' => 'index', 'suffix' => URL_SUFFIX)); Observer::notify('system::init');