示例#1
0
文件: main.php 项目: rukku/SwiftRiver
 /**
  * @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;
     }
 }
示例#2
0
 /**
  * XHR endpoint for fetching droplets
  */
 public function action_droplets()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     switch ($this->request->method()) {
         case "GET":
             $drop_id = $this->request->param('id');
             $page = 1;
             if ($drop_id) {
                 // Specific drop requested
                 $droplets_array = Model_River::get_droplets($this->user->id, $this->river->id, $drop_id);
                 $droplets = array_pop($droplets_array['droplets']);
             } else {
                 //Use page paramter or default to page 1
                 $page = $this->request->query('page') ? intval($this->request->query('page')) : 1;
                 $max_id = $this->request->query('max_id') ? intval($this->request->query('max_id')) : PHP_INT_MAX;
                 $since_id = $this->request->query('since_id') ? intval($this->request->query('since_id')) : 0;
                 $photos = $this->request->query('photos') ? intval($this->request->query('photos')) : 0;
                 $filters = $this->_get_filters();
                 if ($since_id) {
                     $droplets_array = Model_River::get_droplets_since_id($this->user->id, $this->river->id, $since_id, $filters, $photos == 1);
                 } else {
                     $droplets_array = Model_River::get_droplets($this->user->id, $this->river->id, 0, $page, $max_id, NULL, $filters, $photos == 1);
                 }
                 $droplets = $droplets_array['droplets'];
             }
             //Throw a 404 if a non existent page/drop is requested
             if (($page > 1 or $drop_id) and empty($droplets)) {
                 throw new HTTP_Exception_404('The requested page was not found on this server.');
             }
             echo @json_encode($droplets);
             break;
         case "PUT":
             // No anonymous actions
             if ($this->anonymous) {
                 throw new HTTP_Exception_403();
             }
             $droplet_array = json_decode($this->request->body(), TRUE);
             $droplet_id = intval($this->request->param('id', 0));
             $droplet_orm = ORM::factory('droplet', $droplet_id);
             $droplet_orm->update_from_array($droplet_array, $this->user->id);
             break;
         case "DELETE":
             $droplet_id = intval($this->request->param('id', 0));
             $droplet_orm = ORM::factory('droplet', $droplet_id);
             // Does the user exist
             if (!$droplet_orm->loaded()) {
                 throw new HTTP_Exception_404('The requested page :page was not found on this server.', array(':page' => $page));
             }
             // Is the logged in user an owner?
             if (!$this->owner) {
                 throw new HTTP_Exception_403();
             }
             ORM::factory('river', $this->river->id)->remove('droplets', $droplet_orm);
             break;
     }
 }
示例#3
0
 /**
  * Internal helper that performs the search and returns the results
  * to the invoking controller action
  *
  * @param array $parameters An array of search parameters
  * @return array
  */
 private function _handle_drops_search($parameters)
 {
     // Get the page number for the request
     $page = (isset($parameters['page']) and intval($parameters['page']) > 0) ? intval($parameters['page']) : 1;
     // Array to store each of the search results items
     $results = array('droplets' => array(), 'page' => $page);
     $user_id = $this->user->id;
     // Query filters for the droplet fetch
     $query_filters = array('places' => array($this->search_term), 'tags' => array($this->search_term));
     // Check the search scope
     switch ($this->search_scope) {
         // Global search
         case 'all':
             // Get the droplets
             $results['droplets'] = Model_Droplet::search($query_filters, $user_id, $page, $this->photos);
             break;
             // River search
         // River search
         case 'river':
             // Get the river id
             $river_id = Cookie::get('search_item_id');
             $data = Model_River::get_droplets($user_id, $river_id, 0, $page, PHP_INT_MAX, 'DESC', $query_filters, $this->photos);
             $results['droplets'] = $data['droplets'];
             break;
             // Bucket search
         // Bucket search
         case 'bucket':
             // Get the bucket id
             $bucket_id = Cookie::get('search_item_id');
             // Get the droplets
             $data = Model_Bucket::get_droplets($user_id, $bucket_id, 0, $page, PHP_INT_MAX, $this->photos, $query_filters);
             $results['droplets'] = $data['droplets'];
             break;
     }
     // Return
     return $results;
 }