public function action_index() { $this->template->header->css = HTML::style("themes/default/media/css/home.css"); $this->template->header->title = __('Welcome'); $this->template->content = View::factory('pages/welcome/main'); $this->template->content->set(array('public_registration_enabled' => (bool) Swiftriver::get_setting('public_registration_enabled'), 'anonymous' => $this->anonymous)); }
/** * Log User In * * @return void */ public function action_index() { $this->template->content->active = 'login'; $this->template->content->public_registration_enabled = Swiftriver::get_setting('public_registration_enabled'); if ($this->user) { $this->redirect($this->dashboard_url, 302); } // Get the referriing URL $this->referrer = $this->request->query('redirect_to'); //Check for system messages $session = Session::instance(); $messages = $session->get_once('system_messages'); if ($messages) { $this->messages = $messages; } $errors = $session->get_once('system_errors'); if ($errors) { $this->errors = $errors; } // Check, has the form been submitted, if so, setup validation if ($this->request->post('username') and $this->request->post('password')) { // Validate the form token if (CSRF::valid($this->request->post('form_auth_id'))) { $username = $this->request->post('username'); $password = $this->request->post('password'); // Check Auth if the post data validates using the rules setup in the user model if (Auth::instance()->login($username, $password, $this->request->post('remember') == 1)) { // Always redirect after a successful POST to prevent refresh warnings // First check if a referrer was provided in the post parameters // and if not provided, use the referrer from the request otherwise // just redirect to the user profile if the above are not found or do // not point to a url in this site $redirect_to = $this->request->post('referrer'); if (empty($redirect_to)) { $redirect_to = $this->request->referrer(); } Kohana::$log->add(Log::DEBUG, __("Redirecting to :redirect_to", array(":redirect_to" => $redirect_to))); $this->redirect($redirect_to, 302); } else { $this->template->content->set('username', $username); // Get errors for display in view $validation = Validation::factory($this->request->post())->rule('username', 'not_empty')->rule('password', 'not_empty'); if ($validation->check()) { $validation->error('password', 'invalid'); } foreach ($validation->errors('login') as $error) { Swiftriver_Messages::add_message('failure', __('Failure'), $error, FALSE); } $this->redirect(URL::site('login', TRUE), 302); } } else { // Show invalid request message Kohana::$log->add(Log::ERROR, "Invalid CSRF token :token", array(':token' => $this->request->post('form_auth_id'))); } } }
/** * Generates a Response for all Exceptions without a specific override * * @return Response */ public function get_response() { // Log the exception Kohana_Exception::log($this); $response = Response::factory(); $view = Swiftriver::get_base_error_view(); $view->content = View::factory('pages/errors/404')->set('page', $this->request()->uri()); $response->body($view->render()); return $response; }
/** * Exception handler, logs the exception and generates a * Response object for display * * @param Exception $e * @return boolean */ public static function _handler(Exception $e) { // Log the error Kohana::$log->add(Log::ERROR, $e->getMessage()); // Generate the response $response = Response::factory(); $view = Swiftriver::get_base_error_view(); $view->content = View::factory('pages/errors/default'); $response->body($view->render()); return $response; }
/** * List all the available settings * * @return void */ public function action_index() { $this->template->header->title = __('Application Settings'); $this->settings_content = View::factory('pages/settings/main')->bind('action_url', $action_url); $this->active = 'main'; $action_url = URL::site('settings/main/manage'); // Setting items $settings = array('site_name' => '', 'site_locale' => '', 'email_domain' => '', 'comments_email_domain' => '', 'public_registration_enabled' => '', 'anonymous_access_enabled' => '', 'general_invites_enabled' => '', 'default_river_lifetime' => '', 'river_expiry_notice_period' => '', 'default_river_quota' => '', 'default_river_drop_quota' => ''); if ($this->request->post()) { // Setup validation for the application settings $validation = Validation::factory($this->request->post())->rule('site_name', 'not_empty')->rule('site_locale', 'not_empty')->rule('email_domain', 'not_empty')->rule('comments_email_domain', 'not_empty')->rule('default_river_lifetime', 'not_empty')->rule('default_river_lifetime', 'digit')->rule('river_expiry_notice_period', 'not_empty')->rule('river_expiry_notice_period', 'digit')->rule('form_auth_token', array('CSRF', 'valid'))->rule('default_river_quota', 'digit')->rule('default_river_drop_quota', 'digit'); if ($validation->check()) { // Set the setting key values $settings = array('site_name' => $this->request->post('site_name'), 'site_locale' => $this->request->post('site_locale'), 'email_domain' => $this->request->post('email_domain'), 'comments_email_domain' => $this->request->post('comments_email_domain'), 'public_registration_enabled' => $this->request->post('public_registration_enabled') == 1, 'anonymous_access_enabled' => $this->request->post('anonymous_access_enabled') == 1, 'general_invites_enabled' => $this->request->post('general_invites_enabled') == 1, 'default_river_lifetime' => $this->request->post('default_river_lifetime'), 'river_expiry_notice_period' => $this->request->post('river_expiry_notice_period'), 'default_river_quota' => $this->request->post('default_river_quota'), 'default_river_drop_quota' => $this->request->post('default_river_drop_quota')); // Update the settings Swiftriver::update_settings($settings); $this->settings_content->set('messages', array(__('The site settings have been updated.'))); } else { $this->settings_content->set('errors', $validation->errors('user')); } } $this->settings_content->settings = Swiftriver::get_settings(array_keys($settings)); }
/** * Creates and returns the base view for rendering error pages * Error handlers that use this method must set the $content * property of the view * * @return View */ public static function get_base_error_view() { $view = View::factory('template/layout')->set('footer', View::factory('template/footer'))->bind('header', $header); // Header // Params for the <head> section $dashboard_url = URL::site('/', TRUE); $_head_params = array('meta' => "", 'js' => "", 'css' => "", 'messages' => json_encode(array()), 'dashboard_url' => $dashboard_url); $header = View::factory('template/header')->set('show_nav', TRUE)->set('site_name', Swiftriver::get_setting('site_name'))->set($_head_params)->bind('nav_header', $nav_header); // Navigation header $nav_header = View::factory('template/nav/header')->set('user', NULL)->set('anonymous', FALSE)->set('dashboard_url', $dashboard_url); return $view; }
window.logged_in_user = <?php echo $user['id']; ?> ; <?php } else { ?> window.logged_in_account = null; window.logged_in_account_path = null; window.logged_in_user = null; <?php } ?> window.public_registration_enabled = <?php echo Swiftriver::get_setting('public_registration_enabled') ? "true" : "false"; ?> ; window.site_url = "<?php echo URL::base(TRUE, FALSE); ?> "; window.system_messages = <?php echo $messages; ?> ; </script> <?php echo HTML::script("themes/default/media/js/jquery-1.7.2.min.js"); // Outside events plugin
/** * @return void */ public function action_index() { // Get the id of the current river $river_id = $this->river['id']; // The maximum droplet id for pagination and polling $max_droplet_id = $this->river['max_drop_id']; // River filters $filters = $this->get_filters(); //Get Droplets $droplets_array = $this->river_service->get_drops($river_id, 1, 20, NULL, $max_droplet_id, (bool) $this->photos, $filters); // Bootstrap the droplet list $this->template->header->js .= HTML::script("themes/default/media/js/drops.js"); $droplet_js = View::factory('pages/drop/js/drops')->set('fetch_base_url', $this->river_base_url)->set('default_view', 'drops')->set('photos', $this->photos ? 1 : 0)->set('polling_enabled', TRUE); // Check if any filters exist and modify the fetch urls $droplet_js->filters = NULL; if (!empty($filters)) { $encoded_filters = array(); parse_str(http_build_query($filters), $encoded_filters); $droplet_js->filters = json_encode($encoded_filters); } $droplet_js->droplet_list = json_encode($droplets_array); $droplet_js->max_droplet_id = $max_droplet_id; // No content view $no_content_view = empty($this->river['channels']) ? View::factory('pages/river/no-channels') : View::factory('pages/river/no-drops')->set('has_drops', $max_droplet_id > 0); // Select droplet list view with drops view as the default if list not specified $this->droplets_view = View::factory('pages/drop/drops')->set('no_content_view', $no_content_view)->set('asset_templates', View::factory('template/assets'))->bind('droplet_js', $droplet_js)->bind('user', $this->user)->bind('owner', $this->owner)->bind('anonymous', $this->anonymous); // Show expiry notice to owners only if ($this->owner and $this->river['expired']) { $this->droplets_view->nothing_to_display = ""; $expiry_notice = View::factory('pages/river/expiry_notice'); $expiry_notice->river_base_url = $this->river_base_url . "/extend"; $expiry_notice->extension_period = Swiftriver::get_setting('default_river_lifetime'); $this->droplets_view->river_notice = $expiry_notice; } elseif ($this->owner and $this->river['full']) { $this->droplets_view->nothing_to_display = ""; $this->droplets_view->river_notice = View::factory('pages/river/full_notice'); } else { $this->droplets_view->river_notice = ''; } // Extend rivers accessed by an owner during notice perio if ($this->owner and !$this->river['expired'] and FALSE) { $days_remaining = $this->river->get_days_to_expiry(); $notice_period = Swiftriver::get_setting('default_river_lifetime'); if ($days_remaining <= $notice_period and $this->river->is_notified()) { Kohana::$log->add(Log::DEBUG, __("Extending lifetime of river with id :id", array(':id' => $this->river->id))); $this->river->extend_lifetime(); } } }
* Attach the file write to logging. Multiple writers are supported. */ Kohana::$log->attach(new Log_File(APPPATH . 'logs')); /** * Attach a file reader to config. Multiple readers are supported. */ Kohana::$config->attach(new Config_File()); /** * Enable modules. Modules are referenced by a relative or absolute path. */ Kohana::modules(array('auth' => MODPATH . 'auth', 'orm' => MODPATH . 'orm', 'riverid' => MODPATH . 'riverid', 'cache' => MODPATH . 'cache', 'dummy' => MODPATH . 'dummy_cache', 'database' => MODPATH . 'database', 'image' => MODPATH . 'image', 'pagination' => MODPATH . 'pagination', 'themes/default' => THEMEPATH . 'default', 'csrf' => MODPATH . 'csrf', 'K3-Cache_Redis' => MODPATH . 'K3-Cache_Redis')); /** * Initialize the SwiftRiver runtime environment * Load plugins, themes and set the Cookie properties */ Swiftriver::init(); /** * Swiftriver Password Reset Route */ Route::set('login_reset', 'login/reset/<email>/<token>', array('email' => '[^/]++'))->defaults(array('controller' => 'login', 'action' => 'reset')); /** * Swiftriver Account Create Route */ Route::set('login_create', 'login/create/<email>/<token>', array('email' => '[^/]++'))->defaults(array('controller' => 'login', 'action' => 'create')); /** * Swiftriver Change Email Route */ Route::set('login_changeemail', 'login/changeemail/<old_email>/<new_email>/<token>', array('old_email' => '[^/]++', 'new_email' => '[^/]++'))->defaults(array('controller' => 'login', 'action' => 'changeemail')); /** * Swiftriver Login Route */
/** * Dashboard Navigation Links * * @param string $user - logged in user * @return array $nav */ protected static function get_nav($user) { $nav = array(); // Activity Stream $nav[] = array('id' => 'activities-navigation-link', 'url' => '', 'label' => __('Activity')); // Content $nav[] = array('id' => 'content-navigation-link', 'url' => '/content', 'label' => __('Content')); // Invite if (Swiftriver::get_setting('general_invites_enabled') and $user->invites > 0) { $nav[] = array('id' => 'invite-navigation-link', 'url' => '/invite', 'label' => __('Invites')); } // SwiftRiver Plugin Hook -- Add Nav Items Swiftriver_Event::run('swiftriver.dashboard.nav', $nav); return $nav; }
/** * Get the comments from email domain * * @return string */ public static function get_comments_email_domain() { return Swiftriver::get_setting('comments_email_domain'); }
/** * Creates a image link. * * echo HTML::image('media/img/logo.png', array('alt' => 'My Company')); * * @param string file name * @param array default attributes * @param mixed protocol to pass to URL::base() * @param boolean include the index page * @return string * @uses URL::base * @uses HTML::attributes */ public static function image($file, array $attributes = NULL, $protocol = NULL, $index = FALSE) { $file = Swiftriver::get_cdn_url($file); return parent::image($file, $attributes, $protocol, $index); }
/** * The before() method is called before main controller action. * In our template controller we override this method so that we can * set up default values. These variables are then available to our * controllers if they need to be modified. * * @return void */ public function before() { // Execute parent::before first parent::before(); try { $this->session = Session::instance(); } catch (ErrorException $e) { session_destroy(); } // Load the default Cache engine $this->cache = Cache::instance(); // Open session $this->session = Session::instance(); // SwiftRiver API $this->api = SwiftRiver_Client::instance(); // Services $this->account_service = new Service_Account($this->api); $this->river_service = new Service_River($this->api); $this->bucket_service = new Service_Bucket($this->api); $this->form_service = new Service_Form($this->api); // Initialize the dashboard url $this->dashboard_url = URL::site(FALSE, TRUE); if (Auth::instance()->logged_in()) { try { $auth = Auth::instance()->get_user(); $this->api->set_access_token($auth['access_token']); $this->user = $this->account_service->get_logged_in_account(); if ($this->user['owner']['username'] == 'public') { if (strtolower($this->request->controller()) == 'login' or !(bool) Swiftriver::get_setting('anonymous_access_enabled')) { Auth::instance()->logout(); } } } catch (Swiftriver_API_Exception_Authorization $e) { Auth::instance()->logout(); } catch (Swiftriver_API_Exception_Forbidden $e) { Auth::instance()->logout(); } } // If we're not logged in, gives us chance to auto login $supports_auto_login = new ReflectionClass(get_class(Auth::instance())); $supports_auto_login = $supports_auto_login->hasMethod('auto_login'); if (!Auth::instance()->logged_in() and $supports_auto_login) { // Controller exempt from auth check $exempt_controllers = Kohana::$config->load('auth.ignore_controllers'); Auth::instance()->auto_login(); if (!Auth::instance()->get_user() and !in_array(strtolower($this->request->controller()), $exempt_controllers)) { $this->login_required(); } } if ($this->auth_required !== FALSE and Auth::instance()->logged_in($this->auth_required) === FALSE) { if (Auth::instance()->logged_in()) { // User is logged in but not on the secure_actions list $this->access_required(); } else { $this->login_required(); } } if ($this->user) { // Is anonymous logged in? if ($this->user['owner']['username'] == 'public') { $this->anonymous = TRUE; } // Is this user an admin? $this->admin = FALSE; // FIXME:$this->user->is_admin(); if (strtolower(Kohana::$config->load('auth.driver')) == 'riverid' and !in_array($this->user->username, Kohana::$config->load('auth.exempt'))) { $this->riverid_auth = TRUE; } // Logged in user's dashboard url if ($this->anonymous) { $this->dashboard_url = URL::site('welcome'); } else { $this->dashboard_url = URL::site($this->user['account_path'], TRUE); } // Build the base URL $visited_account_path = $this->request->param('account'); if ($visited_account_path and $visited_account_path != $this->user['account_path']) { $this->base_url = URL::site($visited_account_path . '/' . strtolower($this->request->controller())); try { $this->visited_account = $this->account_service->get_account_by_name($visited_account_path); } catch (Swiftriver_API_Exception $e) { // Visited account doesn't exist? $this->redirect($this->dashboard_url, 302); } } else { $this->base_url = URL::site($this->user['account_path'] . '/' . strtolower($this->request->controller())); $this->visited_account = $this->user; } } // Load Header & Footer & variables if ($this->auto_render) { $this->template->header = View::factory('template/header')->bind('user', $this->user)->bind('site_name', $site_name)->bind('dashboard_url', $this->dashboard_url); $this->template->header->js = ''; // Dynamic Javascript $this->template->header->css = ''; // Dynamic CSS $this->template->header->meta = ''; $this->template->header->show_nav = TRUE; $site_name = Swiftriver::get_setting('site_name'); // System messages $this->template->header->messages = json_encode($this->session->get_once('messages')); // Header Nav $this->template->header->nav_header = View::factory('template/nav/header')->bind('user', $this->user)->bind('admin', $this->admin)->bind('account', $this->account)->bind('anonymous', $this->anonymous)->bind('dashboard_url', $this->dashboard_url)->bind('show_search_bar', $show_search_bar)->bind('controller', $controller); $controller = strtolower($this->request->controller()); if ($this->user) { $this->template->header->nav_header->num_notifications = 0; if (!($buckets = Cache::instance()->get('user_buckets_' . $this->user['id'], FALSE))) { $buckets = json_encode($this->account_service->get_buckets($this->user, $this->user)); //Cache::instance()->set('user_buckets_'.$this->user->id, $buckets, 3600 + rand(0,3600)); } $this->template->header->bucket_list = $buckets; if (!($rivers = Cache::instance()->get('user_rivers_' . $this->user['id'], FALSE))) { $rivers = json_encode($this->account_service->get_rivers($this->user, $this->user)); //Cache::instance()->set('user_rivers_'.$this->user->id, $rivers, 3600 + rand(0,3600)); } $this->template->header->river_list = $rivers; if (!($forms = Cache::instance()->get('user_forms_' . $this->user['id'], FALSE))) { $forms = json_encode($this->account_service->get_forms($this->user, $this->user)); //Cache::instance()->set('user_forms_'.$this->user->id, $rivers, 3600 + rand(0,3600)); } $this->template->header->form_list = $forms; } $this->template->content = ''; $this->template->footer = View::factory('template/footer'); } }