/** * @return void */ public function before() { // Execute parent::before first parent::before(); // Get the river/bucket name from the url $name_url = $this->request->param('name', 0); $this->context = $this->request->param('context'); switch ($this->context) { case "river": // Make sure River exists $this->river = ORM::factory('river')->where('river_name_url', '=', $name_url)->where('account_id', '=', $this->visited_account->id)->find(); if (!$this->river->loaded()) { // It doesn't -- redirect back to dashboard $this->request->redirect($this->dashboard_url); } // Is the logged in user an owner if ($this->river->is_owner($this->user->id)) { $this->owner = TRUE; } // If this river is not public and no ownership... if (!$this->river->river_public and !$this->owner) { $request->redirect($this->dashboard_url); } $this->id = $this->river->id; $this->droplets = Model_River::get_droplets($this->user->id, $this->river->id, 0); // Default template for river content $this->template->content = View::factory('pages/river/layout')->bind('river', $this->river)->bind('droplets_view', $droplets_view)->bind('river_base_url', $this->river_base_url)->bind('settings_url', $this->settings_url)->bind('owner', $this->owner)->bind('user', $this->user)->bind('river_base_url', $this->river_base_url)->bind('nav', $this->nav); // Trend template $droplets_view = View::factory('pages/trend/river')->bind('trend', $this->trend); // Set the base url for this specific river $this->river_base_url = $this->river->get_base_url(); // Settings url $this->settings_url = $this->river_base_url . '/settings'; // Navigation Items $this->nav = Swiftriver_Navs::river($this->river); break; case "bucket": // Make sure Bucket exists $this->bucket = ORM::factory('bucket')->where('bucket_name_url', '=', $name_url)->where('account_id', '=', $this->visited_account->id)->find(); if (!$this->bucket->loaded()) { // It doesn't -- redirect back to dashboard $this->request->redirect($this->dashboard_url); } $this->id = $this->bucket->id; $this->droplets = Model_Bucket::get_droplets($this->user->id, $this->bucket->id, 0); // Default template for bucket trends $this->template->content = View::factory('pages/trend/bucket')->bind('bucket', $this->bucket)->bind('droplets', $this->droplets)->bind('more_url', $this->more_url)->bind('drops_url', $drops_url)->bind('active', self::$active)->bind('trend', $this->trend); // Set the base url for this specific bucket $this->bucket_base_url = $this->bucket->get_base_url(); $drops_url = URL::site() . $this->bucket->account->account_path . '/bucket/' . $this->bucket->bucket_name_url; $this->more_url = url::site() . $this->account->account_path . '/bucket/' . $this->bucket->bucket_name_url . '/more'; break; } }
/** * @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(); } } }
/** * Endpoint for extending the lifetime of the river * If the current user is not an owner of the river, they are redirected * the the river's main page */ public function action_extend() { if (!$this->owner) { $this->request->redirect($this->river_base_url); } $this->auto_render = FALSE; $this->template = ""; // Get the token if (isset($_GET['token']) and ($extension_token = $_GET['token']) !== NULL) { if ($this->river->expiry_extension_token === $extension_token) { $this->river->extend_lifetime(); } } // Redirect to the landing page $this->request->redirect($this->river_base_url); }
/** * Create a New River * Step 1 * @return void */ public function action_index() { $this->step_content = View::factory('pages/river/create/name')->bind('post', $post)->bind('errors', $errors); // Check for form submission if ($_POST and CSRF::valid($_POST['form_auth_id'])) { $post = Arr::extract($_POST, array('river_name', 'river_public')); try { $river = Model_River::create_new($post['river_name'], $post['river_public'], $this->user->account); // Redirect to the /create/open/<id> to open channels $this->request->redirect(URL::site() . $this->account_path . '/river/create/open/' . $river->id); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('validation'); } catch (Database_Exception $e) { $errors = array(__("A river with the name ':name' already exists", array(':name' => $post['river_name']))); } } }
/** * Searches and displays the users */ public function action_rivers() { $this->sub_content = View::factory('pages/search/rivers')->bind('search_term', $this->search_term)->bind('rivers', $rivers); $this->template->content->search_scope = Cookie::get(Swiftriver::COOKIE_PREVIOUS_SEARCH_SCOPE); // Get rivers - public, owned and those collaborating on $rivers = Model_River::get_like($this->search_term, $this->user->id); }