Exemple #1
0
    /** ----------------------------------------
    /**  Image Resizing
    /** ----------------------------------------*/
	
	function _image_resize($filename, $type = 'avatar', $axis = 'width')
	{
		global $PREFS;
		
		if ( ! class_exists('Image_lib'))
		{
			require PATH_CORE.'core.image_lib'.EXT;
		}
		
		$IM = new Image_lib();
		
		if ($type == 'avatar')
		{
			$max_width	= ($PREFS->ini('avatar_max_width') == '' OR $PREFS->ini('avatar_max_width') == 0) ? 100 : $PREFS->ini('avatar_max_width');
			$max_height	= ($PREFS->ini('avatar_max_height') == '' OR $PREFS->ini('avatar_max_height') == 0) ? 100 : $PREFS->ini('avatar_max_height');	
			$image_path = $PREFS->ini('avatar_path', TRUE).'uploads/';
		}
		elseif ($type == 'photo')
		{
			$max_width	= ($PREFS->ini('photo_max_width') == '' OR $PREFS->ini('photo_max_width') == 0) ? 100 : $PREFS->ini('photo_max_width');
			$max_height	= ($PREFS->ini('photo_max_height') == '' OR $PREFS->ini('photo_max_height') == 0) ? 100 : $PREFS->ini('photo_max_height');	
			$image_path = $PREFS->ini('photo_path', TRUE);		
		}
		else
		{
			$max_width	= ($PREFS->ini('sig_img_max_width') == '' OR $PREFS->ini('sig_img_max_width') == 0) ? 100 : $PREFS->ini('sig_img_max_width');
			$max_height	= ($PREFS->ini('sig_img_max_height') == '' OR $PREFS->ini('sig_img_max_height') == 0) ? 100 : $PREFS->ini('sig_img_max_height');	
			$image_path = $PREFS->ini('sig_img_path', TRUE);		
		}

		$res = $IM->set_properties(			
									array(
											'resize_protocol'	=> $PREFS->ini('image_resize_protocol'),
											'libpath'			=> $PREFS->ini('image_library_path'),
											'maintain_ratio'	=> TRUE,
											'master_dim'		=> $axis,
											'file_path'			=> $image_path,
											'file_name'			=> $filename,
											'quality'			=> 75,
											'dst_width'			=> $max_width,
											'dst_height'		=> $max_height
											)
									);
		if ( ! $IM->image_resize())
		{
			return FALSE;
		}
	
		return TRUE;
	}
Exemple #2
0
function Thumbnail($path, $filename)
{
    $size = getimagesize($path . $filename);
    if (THUMBNAIL_ON_UPLOAD == true) {
        $image_lib = new Image_lib();
        $config = array();
        $config['source_image'] = $path . $filename;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = THUMBNAIL_MAINTAIN_RATIO;
        $config['height'] = THUMBNAIL_HEIGHT;
        $config['width'] = THUMBNAIL_WIDTH;
        $config['thumb_marker'] = THUMBNAIL_POSTFIX;
        $image_lib->initialize($config);
        $image_lib->resize();
    }
}
Exemple #3
0
 /** -----------------------------------
     /**  Create image thumbnail
     /** -----------------------------------*/
 function create_thumb()
 {
     global $IN, $DSP, $LANG, $PREFS, $LANG, $DB;
     if ($_POST['width_unit'] == 'percent') {
         $_POST['width'] = ceil($_POST['width'] / 100 * $_POST['width_orig']);
     }
     if ($_POST['height_unit'] == 'percent') {
         $_POST['height'] = ceil($_POST['height'] / 100 * $_POST['height_orig']);
     }
     foreach ($_POST as $key => $val) {
         ${$key} = $val;
     }
     //print_r($_POST); exit;
     if ($width == $width_orig and $height == $height_orig) {
         return $DSP->error_message($LANG->line('image_size_not_different'));
     }
     if ($width != $width_orig or $height_orig != $height) {
         $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '" . $DB->escape_str($id) . "'");
         $thumb_prefix = $PREFS->ini('thumbnail_prefix') == '' ? 'thumb' : $PREFS->ini('thumbnail_prefix');
         /** --------------------------------
         			/**  Invoke the Image Lib Class
         			/** --------------------------------*/
         require PATH_CORE . 'core.image_lib' . EXT;
         $IM = new Image_lib();
         /** --------------------------------
         			/**  Resize the image
         			/** --------------------------------*/
         $res = $IM->set_properties(array('resize_protocol' => $PREFS->ini('image_resize_protocol'), 'libpath' => $PREFS->ini('image_library_path'), 'thumb_prefix' => $source == 'orig' ? '' : $thumb_prefix, 'file_path' => $query->row['server_path'], 'file_name' => $file_name, 'dst_width' => $width, 'dst_height' => $height, 'maintain_ratio' => FALSE));
         if ($res === FALSE or !$IM->image_resize()) {
             return $IM->show_error();
         }
     }
     $this->finalize_uploaded_file(array('id' => $id, 'field_group' => $field_group, 'orig_name' => $file_name, 'file_name' => $IM->thumb_name, 'is_image' => 1, 'step' => 2, 'source' => $source));
 }
 /** -------------------------------------
     /**  Uploading Attachments
     /** -------------------------------------*/
 function _attach_file()
 {
     global $IN, $DB, $FNS, $PREFS, $LOC, $LANG, $SESS;
     /** -------------------------------------
     		/**  Check the paths
     		/** -------------------------------------*/
     if ($this->upload_path == '') {
         return $LANG->line('unable_to_recieve_attach');
     }
     if (!@is_dir($this->upload_path) or !@is_writable($this->upload_path)) {
         return $LANG->line('unable_to_recieve_attach');
     }
     /** -------------------------------------
     		/**  Are there previous attachments?
     		/** -------------------------------------*/
     $this->attachments = array();
     $attachments_size = 0;
     if ($IN->GBL('attach') !== FALSE && $IN->GBL('attach') != '') {
         $query = $DB->query("SELECT attachment_id, attachment_size, attachment_location\n        \t\t\t\t\t\t FROM exp_message_attachments\n        \t\t\t\t\t\t WHERE attachment_id IN ('" . str_replace('|', "','", $IN->GBL('attach')) . "')");
         if ($query->num_rows + 1 > $this->max_attachments) {
             return $LANG->line('no_more_attachments');
         } elseif ($query->num_rows > 0) {
             foreach ($query->result as $row) {
                 if (!file_exists($row['attachment_location'])) {
                     continue;
                 }
                 $this->attachments[] = $row['attachment_id'];
                 $attachments_size += $row['attachment_size'];
             }
         }
     }
     /** -------------------------------------
     		/**  Attachment too hefty?
     		/** -------------------------------------*/
     if ($this->attach_maxsize != 0 && $attachments_size + $_FILES['userfile']['size'] / 1024 > $this->attach_maxsize) {
         return $LANG->line('attach_too_large');
     }
     /** -------------------------------------
     		/**  Fetch the size of all attachments
     		/** -------------------------------------*/
     if ($this->attach_total != '0') {
         $query = $DB->query("SELECT SUM(attachment_size) AS total FROM exp_message_attachments WHERE is_temp != 'y'");
         if (!empty($query->row['total'])) {
             // Is the size of the new file (along with the previous ones) too large?
             if (ceil($query->row['total'] + $_FILES['userfile']['size'] / 1024) > $this->attach_total * 1000) {
                 return $LANG->line('too_many_attachments');
             }
         }
     }
     /** -------------------------------------
     		/**  Separate the filename form the extension
     		/** -------------------------------------*/
     if (!class_exists('Image_lib')) {
         require PATH_CORE . 'core.image_lib' . EXT;
     }
     $IM = new Image_lib();
     $split = $IM->explode_name($_FILES['userfile']['name']);
     $filename = $split['name'];
     $extension = $split['ext'];
     $filehash = $FNS->random('alpha', 20);
     /** -------------------------------------
     		/**  Upload the image
     		/** -------------------------------------*/
     if (!class_exists('Upload')) {
         require PATH_CORE . 'core.upload' . EXT;
     }
     $UP = new Upload();
     $UP->set_upload_path($this->upload_path);
     $UP->set_allowed_types('all');
     $UP->new_name = $filehash . $extension;
     if (!$UP->upload_file()) {
         @unlink($UP->new_name);
         if ($UP->error_msg == 'invalid_filetype') {
             $info = implode(', ', $UP->allowed_mimes);
             $info = "<div class='default'>" . $LANG->line($UP->error_msg) . "<div class='default'>" . $LANG->line('allowed_mimes') . '&nbsp;' . $info . "</div>";
             return $info;
         }
         return $UP->error_msg;
     }
     /** -------------------------------------
     		/**  Insert into Database
     		/** -------------------------------------*/
     $this->temp_message_id = $FNS->random('nozero', 10);
     $data = array('attachment_id' => '', 'sender_id' => $this->member_id, 'message_id' => $this->temp_message_id, 'attachment_name' => $filename . $extension, 'attachment_hash' => $filehash, 'attachment_extension' => $extension, 'attachment_location' => $UP->new_name, 'attachment_date' => $LOC->now, 'attachment_size' => ceil($UP->file_size / 1024));
     $DB->query($DB->insert_string('exp_message_attachments', $data));
     $attach_id = $DB->insert_id;
     /** -------------------------------------
     		/**  Change file name with attach ID
     		/** -------------------------------------*/
     // For convenience we use the attachment ID number as the prefix for all files.
     // That way they will be easier to manager.
     // OK, whatever you say, Rick.  -Paul
     if (file_exists($UP->new_name)) {
         $final_name = $attach_id . '_' . $filehash;
         $final_path = $UP->upload_path . $final_name . $extension;
         if (rename($UP->new_name, $final_path)) {
             chmod($final_path, 0777);
             $DB->query("UPDATE exp_message_attachments SET attachment_hash = '{$final_name}', attachment_location = '{$final_path}'  WHERE attachment_id = '{$attach_id}'");
         }
     }
     /** -------------------------------------
     		/**  Load Attachment into array
     		/** -------------------------------------*/
     $this->attachments[] = $attach_id;
     /* -------------------------------------
             /*  Delete Temp Attachments Over 48 Hours Old
     		/*
     		/*  The temp attachments are kept so long because
     		/*  of draft messages that may contain attachments
     		/*  but will not be sent until later.  I think 48
     		/*  hours is enough time.  Any longer and the attachment
     		/*  is gone but the message remains.
             /* -------------------------------------*/
     $expire = $LOC->now - 24 * 60 * 60;
     $result = $DB->query("SELECT attachment_location FROM exp_message_attachments \n\t\t\t\t\t\t\t  WHERE attachment_date < {$expire}\n\t\t\t\t\t\t\t  AND is_temp = 'y'");
     if ($result->num_rows > 0) {
         foreach ($result->result as $row) {
             @unlink($row['attachment_location']);
         }
         $DB->query("DELETE FROM exp_message_attachments WHERE attachment_date < {$expire} AND is_temp='y'");
     }
     return TRUE;
 }