Пример #1
0
 public function get($id_media)
 {
     // Pictures data from database
     $picture = $id_media ? $this->media_model->get($id_media) : FALSE;
     $options = $this->uri->uri_to_assoc();
     unset($options['get']);
     if (empty($options['size'])) {
         $options['size'] = 120;
     }
     // Path to the picture
     if ($picture && file_exists($picture_path = DOCPATH . $picture['path'])) {
         $thumb_path = DOCPATH . Settings::get('files_path') . str_replace(Settings::get('files_path') . '/', '/.thumbs/', $picture['base_path']);
         $thumb_file_path = $this->medias->get_thumb_file_path($picture, $options);
         $refresh = !empty($options['refresh']) ? TRUE : FALSE;
         // If no thumb, try to create it
         if (!file_exists($thumb_file_path) or $refresh === TRUE) {
             try {
                 $thumb_file_path = $this->medias->create_thumb(DOCPATH . $picture['path'], $thumb_file_path, $options);
             } catch (Exception $e) {
                 // $return_thumb_path = FCPATH.'themes/'.Settings::get('theme_admin').'/styles/'.Settings::get('backend_ui_style').'/images/icon_48_no_folder_rights.png';
             }
         }
         $mime = get_mime_by_extension($thumb_file_path);
         $content = read_file($thumb_file_path);
         $this->push_thumb($content, $mime, 0);
     } else {
         $mime = 'image/png';
         $content = read_file(FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_source_picture.png');
         $this->push_thumb($content, $mime, 0);
     }
 }
Пример #2
0
 public function unused_media_delete()
 {
     // 'unusedMediaContainer'
     $files = $this->input->post('files');
     $nb = $this->media_model->delete_files($files);
     $this->unused_media_report();
 }
Пример #3
0
 public function get_thumb($id)
 {
     // Pictures data from database
     $picture = $id ? $this->media_model->get($id) : FALSE;
     // Path to the picture
     if ($picture && file_exists($picture_path = DOCPATH . $picture['path'])) {
         $thumb_path = DOCPATH . Settings::get('files_path') . str_replace(Settings::get('files_path') . '/', '/.thumbs/', $picture['base_path']);
         $return_thumb_path = $thumb_path . $picture['file_name'];
         // If no thumb, try to create it
         if (!file_exists($thumb_path . $picture['file_name'])) {
             $settings = array('size' => Settings::get('media_thumb_size') != '' ? Settings::get('media_thumb_size') : 120, 'unsharpmask' => false);
             try {
                 $return_thumb_path = $this->medias->create_thumb(DOCPATH . $picture['path'], $thumb_path . $picture['file_name'], $settings);
             } catch (Exception $e) {
                 $return_thumb_path = FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_folder_rights.png';
             }
         }
         $mime = get_mime_by_extension($return_thumb_path);
         $content = read_file($return_thumb_path);
         self::push_thumb($content, $mime, 0);
     } else {
         $mime = 'image/png';
         $content = read_file(FCPATH . 'themes/' . Settings::get('theme_admin') . '/styles/' . Settings::get('backend_ui_style') . '/images/icon_48_no_source_picture.png');
         self::push_thumb($content, $mime, 0);
     }
 }
Пример #4
0
 /**
  * Download media with given ID
  *
  * @param   int     $id_media
  * @param   string  $hash       SHA-1 hash to verify a valid (intentionally public) download link
  */
 public function download($id_media, $hash)
 {
     $id_media = (int) $id_media;
     if ($hash !== sha1($id_media . config_item('encryption_key'))) {
         show_error('Access Denied');
     }
     $media = $id_media ? $this->media_model->get($id_media) : FALSE;
     $filePath = substr(BASEPATH, 0, -7) . $media['path'];
     if ($id_media === 0 || !file_exists($filePath)) {
         show_404();
     }
     header('Content-length: ' . filesize($filePath));
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="' . $media['file_name'] . '"');
     die(file_get_contents($filePath));
 }
Пример #5
0
 /**
  * Constructor
  *
  * @access	public
  */
 public function __construct()
 {
     parent::__construct();
     $this->table = 'media';
     $this->pk_name = 'id_media';
     $this->lang_table = 'media_lang';
     self::$_UNUSED_IGNORED_FILES = array(Settings::get('no_source_picture'), 'index.html', 'watermark.png');
     log_message('debug', __CLASS__ . " Class Initialized");
 }
Пример #6
0
 /**
  * Add a new avatar image to user profile
  */
 public function add_avatar($path)
 {
     $this->load->model('Media_model');
     // removing old avatar
     if (!is_null($this->avatar)) {
         $media_old = $this->Media_model->get_by_id($this->avatar);
         if ($media_old) {
             $media_old->delete();
         }
     }
     //saving new avatar
     $media = new Media_model();
     if ($media->insert($path)) {
         $this->avatar = $media->id;
         return $this->update();
     } else {
         return false;
     }
 }