Esempio n. 1
0
 /**
  * @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;
     }
 }
Esempio n. 2
0
 /**
  * Bucket management restful API
  * 
  */
 public function action_manage()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     switch ($this->request->method()) {
         case "GET":
             echo json_encode($this->user->get_buckets_array($this->user));
             break;
         case "PUT":
             // No anonymous buckets
             if ($this->anonymous) {
                 throw new HTTP_Exception_403();
             }
             $bucket_array = json_decode($this->request->body(), TRUE);
             $bucket_orm = ORM::factory('bucket', $bucket_array['id']);
             if (!$bucket_orm->loaded()) {
                 throw new HTTP_Exception_404();
             }
             if (!$bucket_array['subscribed']) {
                 // Unsubscribing
                 // Unfollow
                 if ($this->user->has('bucket_subscriptions', $bucket_orm)) {
                     $this->user->remove('bucket_subscriptions', $bucket_orm);
                 }
                 // Stop collaborating
                 $collaborator_orm = $bucket_orm->bucket_collaborators->where('user_id', '=', $this->user->id)->where('collaborator_active', '=', 1)->find();
                 if ($collaborator_orm->loaded()) {
                     $collaborator_orm->delete();
                     $bucket_array['is_owner'] = FALSE;
                     $bucket_array['collaborator'] = FALSE;
                 }
             } else {
                 // Subscribing
                 if (!$this->user->has('bucket_subscriptions', $bucket_orm)) {
                     $this->user->add('bucket_subscriptions', $bucket_orm);
                 }
             }
             // Return updated bucket
             echo json_encode($bucket_array);
             break;
         case "POST":
             // No anonymous buckets
             if ($this->anonymous) {
                 throw new HTTP_Exception_403();
             }
             $bucket_array = json_decode($this->request->body(), TRUE);
             try {
                 $bucket_array['user_id'] = $this->user->id;
                 $bucket_array['account_id'] = $this->account->id;
                 $bucket_orm = Model_Bucket::create_from_array($bucket_array);
                 echo json_encode($bucket_orm->get_array($this->user, $this->user));
             } catch (ORM_Validation_Exception $e) {
                 $this->response->status(400);
                 $this->response->headers('Content-Type', 'application/json');
                 $errors = array();
                 foreach ($e->errors('validation') as $message) {
                     $errors[] = $message;
                 }
                 echo json_encode(array('errors' => $errors));
             } catch (Database_Exception $e) {
                 $this->response->status(400);
                 $this->response->headers('Content-Type', 'application/json');
                 $errors = array(__("A bucket with the name ':name' already exists", array(':name' => $bucket_array['bucket_name'])));
                 echo json_encode(array('errors' => $errors));
             }
             break;
         case "DELETE":
             $bucket_id = intval($this->request->param('id', 0));
             $bucket_orm = ORM::factory('bucket', $bucket_id);
             if ($bucket_orm->loaded()) {
                 if (!$bucket_orm->is_creator($this->user->id)) {
                     // Only creator can delete
                     throw new HTTP_Exception_403();
                 }
                 $bucket_orm->delete();
             } else {
                 throw new HTTP_Exception_404();
             }
             break;
     }
     // Force refresh of cached buckets
     if (in_array($this->request->method(), array('DELETE', 'PUT', 'POST'))) {
         Cache::instance()->delete('user_buckets_' . $this->user->id);
     }
 }
Esempio n. 3
0
 /**
  * Searches and display the buckets
  */
 public function action_buckets()
 {
     $this->sub_content = View::factory('pages/search/buckets')->bind('search_term', $this->search_term)->bind('buckets', $buckets);
     $this->template->content->search_scope = Cookie::get(Swiftriver::COOKIE_PREVIOUS_SEARCH_SCOPE);
     // Get buckets - public, owned and those collaborating on
     $buckets = Model_Bucket::get_like($this->search_term, $this->user->id);
 }