Location: PHPKode > scripts > Gmail Gallery > gmail-gallery/gimggallery.class.php
<?php
/**
 * @package GImgGallery
 * @author Markus Paul - Idea by Luis Ignacio Larrateguy GImageGallery
 * @access public 
 */
class GImgGallery {

	var $m_obj_Gmailer;
	
	function GImgGallery($str_login, $str_password, $int_timezone) 
	{
		require_once('libgmailer.php');
		$this->m_obj_Gmailer = new GMailer();
		$this->m_obj_Gmailer->setLoginInfo($str_login, $str_password, $int_timezone);
		$this->m_obj_Gmailer->connectNoCookie();
	}
	
	/**
	 * 
	 *
	 * @return array $arr_return[x] = labels
	 */
	function getAllLabels() 
	{
		$this->m_obj_Gmailer->fetchBox(GM_STANDARD, "all", 0);
		$tmp_sp = $this->m_obj_Gmailer->getSnapshot(GM_STANDARD);
		return $tmp_sp->label_list;
	}
	
	/**
	 * Generates all informations for free gallery creation
	 *
	 * @param String $str_label
	 * @return array $arr_r[x][images][all images]
	 */
	function getGalleryRaw($str_label) 
	{
		$arr_r = array();		
		$this->m_obj_Gmailer->fetchBox(GM_LABEL, $str_label, 0);
		$tmp_sp = $this->m_obj_Gmailer->getSnapshot(GM_CONVERSATION);
		
		if(!$tmp_sp->box) return false;
		
		
		
		foreach ($tmp_sp->box as $arr_mail) 
		{
			$arr_tmp = array();			
			for ($i = 0; $i < count($arr_mail["attachment"]); $i++) 
			{		
					
				$img_name = explode('_thumb', $arr_mail["attachment"][$i]);
				$img_name = explode('.', $img_name[0]);
				$img_name = $img_name[0];
				
				if(strpos($arr_mail["attachment"][$i], '_thumb') !== false) 
				{
					$arr_tmp[$img_name]['tb_no'] = '0.' . (string) ( $i+1 );
					$arr_tmp[$img_name]['tb_type'] = substr($arr_mail["attachment"][$i], -3);
				} else {
					$arr_tmp[$img_name]['img_no'] = '0.' . (string) ( $i+1 );
					$arr_tmp[$img_name]['img_type'] = substr($arr_mail["attachment"][$i], -3);
				}		
			}		
			
				
			$arr_r[] = array(	'label'		=>	$str_label,
								'msgid' 	=> 	$arr_mail['msgid'],
								'msg_title'	=>	$arr_mail["subj"],
								'images'	=>	$arr_tmp);			
			unset($arr_tmp);
			
			
		}
				
		return $arr_r;
	}
	
	/**
	 * Generates a gallery with full path to the images with links (same subject same gallery!!!)
	 *
	 * @param String $str_label
	 * @return array $arr_r['Mail Subject'][x] = '<a link full image><img thumbnail image></a>'
	 */
	function getGallery($str_label) 
	{
		$arr_r = array();
		$tmp_gallery = $this->getGalleryRaw($str_label);	
		if(!$tmp_gallery) return false;
		foreach ($tmp_gallery as $arr_msg) 
		{
			foreach ($arr_msg['images'] as $arr_img) 
			{
				$arr_r[strip_tags($arr_msg['msg_title'])][] = '<a href="gimggalleryimg.php?img_type='.$arr_img['img_type'].'&imgid='.$arr_img['img_no'].'&msgid='.$arr_msg['msgid'].'"><img src="gimggalleryimg.php?img_type='.$arr_img['tb_type'].'&imgid='.$arr_img['tb_no'].'&msgid='.$arr_msg['msgid'].'"></a>';
			}
		}
		return $arr_r;
	}
	
	/**
	 * Output the image (gimggalleryimg.php)
	 *
	 * @param String $str_imgid
	 * @param String $str_msgid
	 * @param String $str_img_type
	 */
	function getImage($str_imgid, $str_msgid, $str_img_type) 	
	{
		switch ($str_img_type) {
			case 'jpg' || 'JPG':
				header( "Content-Type: image/jpeg");				
				break;
			case 'png' || 'PNG':
				header( "Content-Type: image/png");				
				break;
			case 'gif' ||'GIF':
				header( "Content-Type: image/gif");				
				break;			
		}		
		$this->m_obj_Gmailer->fetchBox(GM_STANDARD, "all", 0);
		$tmp_sp = $this->m_obj_Gmailer->getSnapshot(GM_CONVERSATION);		
		@$this->m_obj_Gmailer->getAttachment( $str_imgid, $str_msgid, "php://output" );
	}
	
	function destroy() 	
	{
		$this->m_obj_Gmailer->disconnect();
	}
}
?>
Return current item: Gmail Gallery