예제 #1
0
 public function action_get_index_collection()
 {
     // Get the post query
     $posts_query = $this->_build_query();
     // Get the count of ALL records
     $count_query = clone $posts_query;
     $total_records = (int) $count_query->select(array(DB::expr('COUNT(DISTINCT `post`.`id`)'), 'records_found'))->limit(NULL)->offset(NULL)->find_all()->get('records_found');
     // Fetch posts from db
     $posts = $posts_query->find_all();
     // Get query count
     $post_query_sql = $posts_query->last_query();
     // Generate filename using hashed query params and ids
     $filename = 'export-' . hash('sha256', implode('-', $this->request->query()) . '~' . '-' . $this->request->param('id')) . '.csv';
     // Get existing tsv file
     $tsv_file = Kohana::$config->load('media.media_upload_dir') . $filename;
     // Only generate a new if the file doesn't exist
     if (!file_exists($tsv_file)) {
         // Supported headers for the TSV file
         $tsv_headers = array("ID", "PARENT", "USER", "FORM", "TITLE", "CONTENT", "TYPE", "STATUS", "SLUG", "LOCALE", "CREATED", "UPDATED", "TAGS", "SETS");
         // Generate tab separated values (tsv)
         $tsv_text = $this->_generate_tsv($tsv_headers, $posts);
         // Write tsv to file
         $this->_write_tsv_to_file($tsv_text, $filename);
     }
     // Relative path
     $relative_path = str_replace(APPPATH . 'media' . DIRECTORY_SEPARATOR, '', Kohana::$config->load('media.media_upload_dir'));
     // Build download link
     $download_link = URL::site(Media::uri($relative_path . $filename), Request::current());
     // Respond with download link and record count
     $this->_response_payload = array('total_count' => $total_records, 'link' => $download_link);
 }
예제 #2
0
파일: Media.php 프로젝트: gjorgiev/platform
 protected function format_o_filename($value)
 {
     if ($cdnBaseUrl = Kohana::$config->load('cdn.baseurl')) {
         return $cdnBaseUrl . $value;
     } else {
         return URL::site(Media::uri($this->get_relative_path() . $value), Request::current());
     }
 }
예제 #3
0
 /**
  * Prepare media data for API
  *
  * @return array $response - array to be returned by API (as json)
  */
 public function for_api()
 {
     $response = array();
     if ($this->loaded()) {
         // Set image dimensions from the config file
         $medium_width = Kohana::$config->load('media.image_medium_width');
         $medium_height = Kohana::$config->load('media.image_medium_height');
         $thumbnail_width = Kohana::$config->load('media.image_thumbnail_width');
         $thumbnail_height = Kohana::$config->load('media.image_thumbnail_height');
         $upload_path = Kohana::$config->load('media.media_upload_dir');
         $relative_path = str_replace(Kohana::$config->load('imagefly.source_dir'), '', Kohana::$config->load('media.media_upload_dir'));
         $original_file = $upload_path . $this->o_filename;
         $response = array('id' => $this->id, 'user' => empty($this->user_id) ? NULL : array('id' => $this->user_id, 'url' => Ushahidi_Api::url('users', $this->user_id)), 'url' => Ushahidi_Api::url('media', $this->id), 'caption' => $this->caption, 'mime' => $this->mime, 'original_file_url' => URL::site(Media::uri($relative_path . $this->o_filename), Request::current()), 'original_file_size' => is_file($original_file) ? filesize($upload_path . $this->o_filename) : 0, 'original_width' => $this->o_width, 'original_height' => $this->o_height, 'medium_file_url' => $this->_resized_url($medium_width, $medium_height, $relative_path . $this->o_filename), 'medium_width' => $medium_width, 'medium_height' => $medium_height, 'thumbnail_file_url' => $this->_resized_url($thumbnail_width, $thumbnail_height, $relative_path . $this->o_filename), 'thumbnail_width' => $thumbnail_width, 'thumbnail_height' => $thumbnail_height, 'created' => ($created = DateTime::createFromFormat('U', $this->created)) ? $created->format(DateTime::W3C) : $this->created, 'updated' => ($updated = DateTime::createFromFormat('U', $this->updated)) ? $updated->format(DateTime::W3C) : $this->updated);
     } else {
         $response = array('errors' => array('Media does not exist'));
     }
     return $response;
 }
예제 #4
0
 protected function format_o_filename($value)
 {
     return URL::site(Media::uri($this->get_relative_path() . $value), Request::current());
 }