/** * @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 before() { // Execute parent::before first parent::before(); // Get the river name from the url $river_name_url = $this->request->param('name'); $action = $this->request->action(); // Find the matching river from the visited account's rivers. if (($river = $this->account_service->has_river($this->visited_account, $river_name_url)) !== FALSE) { $this->river = $this->river_service->get_river_by_id($river['id'], $this->user); } if ($river_name_url and !$this->river and $action != 'manage') { $this->redirect($this->dashboard_url, 302); } // Action involves a specific river, check permissions if ($this->river) { $this->owner = $this->river['is_owner'] or $this->river['is_collaborator']; $this->is_collaborator = $this->river['is_collaborator']; $this->public = (bool) $this->river['public']; // If this river is not public and no ownership... if (!$this->public and !$this->owner and !$this->is_collaborator) { $this->redirect($this->dashboard_url, 302); } $this->river_base_url = $this->river_service->get_base_url($this->river); $this->settings_url = $this->river_base_url . '/settings'; // Navigation Items $this->nav = Swiftriver_Navs::river($this->river); if ($this->owner) { $this->page_title = $this->river['name']; } else { $this->page_title = $this->river['account']['account_path'] . ' / ' . $this->river['name']; } $this->template->header->title = $this->page_title; $this->template->content = View::factory('pages/river/layout')->bind('droplets_view', $this->droplets_view)->bind('river_base_url', $this->river_base_url)->bind('settings_url', $this->settings_url)->bind('owner', $this->owner)->bind('anonymous', $this->anonymous)->bind('user', $this->user)->bind('nav', $this->nav)->bind('active', $this->active)->bind('page_title', $this->page_title)->bind('follow_button', $follow_button)->bind('is_collaborator', $this->is_collaborator); $view_data = array('channels_config' => json_encode(Swiftriver_Plugins::channels()), 'channels' => json_encode($this->river['channels']), 'channels_base_url' => $this->river_base_url . '/settings/channels/options', 'river' => $this->river); $this->template->content->set($view_data); $this->template->header->js .= HTML::script("themes/default/media/js/channels.js"); // Show the follow button? if (!$this->owner and !$this->is_collaborator) { $is_following = $this->river_service->is_follower($this->river['id'], $this->user['id']); $river_data = json_encode(array('id' => $this->river['id'], 'name' => $this->river['name'], 'type' => 'river', 'following' => $is_following)); $follow_button = View::factory('template/follow')->bind('data', $river_data)->bind('action_url', $action_url); $action_url = URL::site($this->river['url'] . '/manage'); } } }
/** * @return void */ public function before() { // Execute parent::before first parent::before(); // Get the river name from the url $river_name_url = $this->request->param('name'); $action = $this->request->action(); // This check should be made when this controller is accessed // and the database id of the rive is non-zero $this->river = ORM::factory('river')->where('river_name_url', '=', $river_name_url)->where('account_id', '=', $this->visited_account->id)->find(); if ($river_name_url and !$this->river->loaded() and $action != 'manage') { $this->request->redirect($this->dashboard_url); } // Action involves a specific river, check permissions if ($this->river->loaded()) { $this->owner = $this->river->is_owner($this->user->id); $this->collaborator = $this->river->is_collaborator($this->user->id); // If this river is not public and no ownership... if (!$this->river->river_public and !$this->owner and !$this->collaborator) { $this->request->redirect($this->dashboard_url); } $this->river_base_url = $this->river->get_base_url(); $this->settings_url = $this->river_base_url . '/settings'; // Navigation Items $this->nav = Swiftriver_Navs::river($this->river); if ($this->river->account->user->id == $this->user->id or $this->river->account->user->username == 'public') { $this->template->header->title = $this->river->river_name; } else { $this->template->header->title = $this->river->account->account_path . ' / ' . $this->river->river_name; } $this->template->content = View::factory('pages/river/layout')->bind('river', $this->river)->bind('droplets_view', $this->droplets_view)->bind('river_base_url', $this->river_base_url)->bind('settings_url', $this->settings_url)->bind('owner', $this->owner)->bind('anonymous', $this->anonymous)->bind('user', $this->user)->bind('nav', $this->nav)->bind('active', $this->active); $this->template->content->is_collaborator = $this->collaborator; if (!$this->owner) { $river_item = json_encode(array('id' => $this->river->id, 'type' => 'river', 'subscribed' => $this->river->is_subscriber($this->user->id))); // Action URL - To handle the follow/unfollow actions on the river $action_url = URL::site() . $this->visited_account->account_path . '/user/river/manage'; $this->template->content->river_item = $river_item; $this->template->content->action_url = $action_url; } } }