Ejemplo n.º 1
0
	function savephoto()
	{
		require_once (JPATH_SITE. DS .'components'.DS.'com_awdwall'.DS. 'models' . DS . 'wall.php');
		require_once (JPATH_SITE. DS .'components'.DS.'com_awdwall'.DS. 'libraries' . DS . 'class.upload.php');	
		$mainframe= JFactory::getApplication();
 		$option = JRequest::getCmd('option');
		$db		=& JFactory::getDBO();
		$app = JFactory::getApplication('site');
		$config =  & $app->getParams('com_awdwall');
		$tempwidth 		= $config->get('width', 725);
		$scalimgwidth=$tempwidth-15;
		$albumid=$_REQUEST['id'];
		$firsttime=$_REQUEST['firsttime'];
		$user =& JFactory::getUser();
	 	$row = new TableAwd_add_photos($db);
		$post	= JRequest::get( 'post' );
		 
		 
		jimport('joomla.filesystem.file');
		jimport('joomla.filesystem.folder');
		 
		$path=JPATH_SITE. '/images/awd_photo/'; 
		
		$thumbpath=JPATH_SITE. '/images/awd_photo/awd_thumb_photo/'; 
		$largepath=JPATH_SITE. '/images/awd_photo/awd_large_photo/'; 
		$oripath=JPATH_SITE. '/images/awd_photo/awd_ori_photo/'; 


		if (ini_get('safe_mode')=='On')
		{
			$msg=JText::_('Directory creation not allowed while running in SAFE MODE as this can cause problems.');
			$mainframe->redirect(JRoute::_('index.php?option=com_awdjomalbum',false), $msg ); 
			exit();
		}  
		
		if(!is_dir( $path ) && !is_file( $path ))
		{
			//jimport('joomla.filesystem.*');
			JFolder::create($path);		 
		}
		
		
		if(!is_dir($thumbpath)&& !is_file($thumbpath))
		{
			// jimport('joomla.filesystem.*');
			JFolder::create($thumbpath);				
		}
		if(!is_dir($oripath)&& !is_file($oripath))
		{
			// jimport('joomla.filesystem.*');
			JFolder::create($thumbpath);				
		}
		
		if(!is_dir($largepath)&& !is_file($largepath))
		{
			// jimport('joomla.filesystem.*');
			JFolder::create($largepath);				
		}
    $files = array();
    foreach ($_FILES['photo'] as $k => $l) {
        foreach ($l as $i => $v) {
            if (!array_key_exists($i, $files))
                $files[$i] = array();
            $files[$i][$k] = $v;
        }
    }
	
  foreach ($files as $file) {
  	if($file['name']!='')
	{
		$filename='';
		$userfile_name='';
		$filename=$file['name'];
		$todaydate=time();
		$filename=str_replace(" ","_",$filename);
		preg_match('/\.[^\.]+$/i',$filename,$ext);
		$rand=rand(120,10000);
		$userfile_name=strtolower($rand.'_'.$todaydate.'.'.$ext[0]);
		$userfile_type=strtolower($file['type']);
		if($file['size']<=5000000)
		{
			if($userfile_type=='image/jpeg' || $userfile_type=='image/jpg' ||  
			$userfile_type=='image/pjpeg' || $userfile_type=='image/x-png' || 
			$userfile_type=='image/png' || $userfile_type=='image/gif' )
			{ 
					   $handle = new upload($file);
					   if ($handle->uploaded)
					   {
							$filename1 = preg_replace("/\\.[^.\\s]{3,4}$/", "", $userfile_name); 
							$folder=$path;
							processthumb($handle,$filename1,$folder);
							
							$handle->image_resize          = true;
							$handle->image_ratio        = true;
							//$handle->image_x               = $scalimgwidth;
							$handle->image_x               = 600;
							$handle->image_y               = 500;
							$folder=$largepath;
							processthumb($handle,$filename1,$folder);
							
							
							$handle->image_resize          = true;
							$handle->image_ratio_crop      = true;
							$handle->image_x               = 145;
							$handle->image_y               = 110;
							$folder=$thumbpath;
							//$filename2='tn145'.$filename1;
							processthumb($handle,$filename1,$folder);
							$today=date("Y-m-d h:i:s");
								$qry = "INSERT INTO  #__awd_jomalbum_photos(id, userid, albumid, image_name, title, published, upload_date) VALUES ('',$user->id, '$albumid', '$userfile_name', '', '1','$today' )"; 
										
								$db->setQuery( $qry);
								if (!$db->query()) {
									return JError::raiseWarning( 500, $db->getError() );
								}
								$photoid=$db->insertid();
								$photolink=JRoute::_('index.php?option=com_awdjomalbum&view=awdimagelist&tmpl=component&pid='.$photoid.'&albumid='.$albumid.'&Itemid='.AwdwallHelperUser::getComItemId(),false);
								$photosrc=JURI::base().'images/awd_photo/awd_thumb_photo/'.$userfile_name;
								$imagelist=$imagelist.'<div style="float:left; max-height:75px; width:75px; padding:3px;"><a href="'.$photolink.'" class="awdiframe" ><img src="'.$photosrc.'"  width="72" border="0" /></a></div>';
							
					   }
			
			} // if($userfile_type=='image/jpeg'
			else
			{
				$errmsgs[]=$filename.'&nbsp;'.JText::_('did not uploaded due to incorrect format');
				$this->setMessage(JText::_('Invaild image, Please try to upload only jpg or png or gif images.') );
				$this->setRedirect(JRoute::_( 'index.php?option=com_awdjomalbum',false));
			}
		
		} // if($file['size']<=5000000)
		else
		{
			$errmsgs[]='Image '.$filename.'&nbsp;'.JText::_('did not uploaded due to bigger size');
		}	
	
	 } // if($file['name']!='')
	
  } //  foreach ($files as $file)
		
	if($errmsgs)
	{
		foreach($errmsgs as $errmsg)
		{
			$msg.=$errmsg."<br>";
		}
	}else{
	$msg=JText::_('Photo uploaded successfully');
	}
	
	
	//addming to jomsocial activity streams
		// sending the wall post 
		if($firsttime){
		$album=getAlbumDetail($albumid);
		if($album->privacy!=3){
			$albumlink=JRoute::_('index.php?option=com_awdjomalbum&view=awdalbumimages&albumid='.$albumid.'&Itemid='.AwdwallHelperUser::getComItemId(),false);
			$wmsg=JText::_('has uploded the album').'&nbsp;<a href="'.$albumlink.'">'.$album->name.'</a><br>'.$imagelist.'<div style="clear:both"></div>';
			$wall 				=& JTable::getInstance('Wall', 'Table');									
			$wall->user_id		= $user->id;			
			$wall->group_id		= $groupId;			
			$wall->type			= $type;			
			$wall->commenter_id	= $user->id;			
			$wall->user_name	= '';			
			$wall->avatar		= '';			
			$wall->message		= nl2br($wmsg);			
			$wall->reply		= 0;			
			$wall->is_read		= 0;			
			$wall->is_pm		= 0;			
			$wall->is_reply		= 0;			
			$wall->posted_id	= NULL;			
			$wall->wall_date	= time();			
			$wall->type = JRequest::getString('type', 'text');	
			$wall->store();
			//insert into awd_wall_ privacy table.
			$query = 'INSERT INTO #__awd_wall_privacy(wall_id, privacy) VALUES(' . $wall->id . ', ' . $album->privacy . ')';
			$db->setQuery($query);
			$db->query();
			}
		}					
			//echo $id;

	$this->setMessage($msg); 
	$this->setRedirect( JRoute::_('index.php?option=com_awdjomalbum&view=awdalbumlist&wuid='.$user->id.'&Itemid='.AwdwallHelperUser::getComItemId(),false));
	
	}
Ejemplo n.º 2
0
	function awdProfileDisplay($user)
	{
	if($user)
	{
		
			$db		=& JFactory::getDBO();
			global $ueConfig;
			require_once(JPATH_COMPONENT . DS . 'plugin'. DS .'user' . DS . 'plug_awdwallcbavatar'. DS . 'class.upload.php');
				$sql="select count(*) as countx from  #__awd_wall_users where user_id=".$user->user_id;
				$db->setQuery( $sql );
				$countx=$db->loadResult();
				if(empty($countx))
				{
					$sql="INSERT INTO  #__awd_wall_users (`user_id`)VALUES (".$user->user_id.");";
					$db->setQuery( $sql );
					if (!$db->query())
					{
						return JError::raiseWarning( 500, $db->getError() );
					}
				}
				
				$sql="select avatar from  #__comprofiler where user_id=".$user->user_id;
				$db->setQuery( $sql );
				$avatar=$db->loadResult();
				
				
				if($avatar==NULL || $avatar=='')
				{
					//$avatar='pending_n.png';
					$avatar='nophoto_n.png';
					// update blank image to the table and folder
					$sql="select avatar from  #__awd_wall_users where user_id=".$user->user_id;
					$db->setQuery( $sql );
					$wavatar=$db->loadResult();
					//exit;
					if($avatar!=$wavatar )
					{
						$deleteimagepath1=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original'. DS .$wavatar;
						$deleteimagepath2=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn133'.$wavatar;
						$deleteimagepath3=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn51'.$wavatar;
						$deleteimagepath4=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn40'.$wavatar;
						$deleteimagepath5=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn32'.$wavatar;
						$deleteimagepath6=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn19'.$wavatar;
						unlink($deleteimagepath1);
						unlink($deleteimagepath2);
						unlink($deleteimagepath3);
						unlink($deleteimagepath4);
						unlink($deleteimagepath5);
						unlink($deleteimagepath6);
						
						$sql="update #__awd_wall_users SET `avatar` = '' where user_id=".$user->user_id;
						$db->setQuery( $sql );
						if (!$db->query())
						{
							return JError::raiseWarning( 500, $db->getError() );
						}
						// update the default image of cb
						$cbtemplate=$ueConfig['templatedir'];
						$imagepath=JPATH_SITE. DS . 'components'. DS .'com_comprofiler' .DS.'plugin'.DS.'templates'.DS.$cbtemplate.DS.'images'.DS.'avatar'.DS.$avatar;
						$handle = new upload($imagepath);
					
						if ($handle->uploaded) 
						{
							$filename = preg_replace("/\\.[^.\\s]{3,4}$/", "", $avatar);
							
							$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original';
							processthumb($handle,$filename,$folder);
							
							$handle->image_resize          = true;
							$handle->image_ratio_y        = true;
							$handle->image_x               = 133;
							
							$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
							$filename2='tn133'.$filename;
							processthumb($handle,$filename2,$folder);
							
							$handle->image_resize          = true;
							$handle->image_ratio_crop      = true;
							$handle->image_x               = 51;
							$handle->image_y               = 51;
							$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
							$filename2='tn51'.$filename;
							processthumb($handle,$filename2,$folder);
							
							$handle->image_resize          = true;
							$handle->image_ratio_crop      = true;
							$handle->image_x               = 40;
							$handle->image_y               = 40;
							$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
							$filename2='tn40'.$filename;
							processthumb($handle,$filename2,$folder);
							
							$handle->image_resize          = true;
							$handle->image_ratio_crop      = true;
							$handle->image_x               = 32;
							$handle->image_y               = 32;
							$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
							$filename2='tn32'.$filename;
							processthumb($handle,$filename2,$folder);
							
							$handle->image_resize          = true;
							$handle->image_ratio_crop      = true;
							$handle->image_x               = 19;
							$handle->image_y               = 19;
							$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
							$filename2='tn19'.$filename;
							processthumb($handle,$filename2,$folder);
							
							$sql="update #__awd_wall_users SET `avatar` = '".strtolower($avatar)."' where user_id=".$user->user_id;
							$db->setQuery( $sql );
							if (!$db->query())
							{
								return JError::raiseWarning( 500, $db->getError() );
							}
						
						}
						
					}
					
				}
				else
				{
					// update uploaded image to the table and folder
						$gpos = strpos($avatar, 'gallery');
						//if($gpos==TRUE)
						if($gpos !== false)
						{
	
						
	
								$sql="select avatar as wallavatar from  #__awd_wall_users where user_id=".$user->user_id;
								$db->setQuery( $sql );
								$wallavatar=$db->loadResult();
								
								$imagepath=JPATH_BASE. DS . 'images'. DS .'comprofiler' . DS .$avatar ;
								$avatar=str_replace('gallery/','',$avatar);
								
								if($wallavatar!=$avatar)
								{
									
									$deleteimagepath1=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original'. DS .$wallavatar;
									$deleteimagepath2=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn133'.$wallavatar;
									$deleteimagepath3=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn51'.$wallavatar;
									$deleteimagepath4=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn40'.$wallavatar;
									$deleteimagepath5=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn32'.$wallavatar;
									$deleteimagepath6=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn19'.$wallavatar;
									unlink($deleteimagepath1);
									unlink($deleteimagepath2);
									unlink($deleteimagepath3);
									unlink($deleteimagepath4);
									unlink($deleteimagepath5);
									unlink($deleteimagepath6);
									
									$handle = new upload($imagepath);
									if ($handle->uploaded) 
									{
										
										$filename = preg_replace("/\\.[^.\\s]{3,4}$/", "", $avatar);
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original';
										processthumb($handle,$filename,$folder);
										
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn133'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn51'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 40;
										$handle->image_y               = 40;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn40'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 32;
										$handle->image_y               = 32;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn32'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 19;
										$handle->image_y               = 19;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn19'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$sql="update #__awd_wall_users SET `avatar` = '".strtolower($avatar)."' where user_id=".$user->user_id;
										$db->setQuery( $sql );
										if (!$db->query())
										{
											return JError::raiseWarning( 500, $db->getError() );
										}
								
								} // if ($handle->uploaded) 
							} // if($wallavatar!=$avatar)
						
						}
						else
						{
						
							if($user->avatarapproved==1)
							{
								
								$sql="select avatar from  #__awd_wall_users where user_id=".$user->user_id;
								$db->setQuery( $sql );
								$wavatar=$db->loadResult();
								
								if($user->avatar!=$wavatar)
								{
									
									$deleteimagepath1=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original'. DS .$wavatar;
									$deleteimagepath2=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn133'.$wavatar;
									$deleteimagepath3=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn51'.$wavatar;
									$deleteimagepath4=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn40'.$wavatar;
									$deleteimagepath5=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn32'.$wavatar;
									$deleteimagepath6=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn19'.$wavatar;
									unlink($deleteimagepath1);
									unlink($deleteimagepath2);
									unlink($deleteimagepath3);
									unlink($deleteimagepath4);
									unlink($deleteimagepath5);
									unlink($deleteimagepath6);
						
									
									$imagepath=JPATH_BASE. DS . 'images'. DS .'comprofiler' . DS .$avatar ;
									$handle = new upload($imagepath);
									if ($handle->uploaded) 
									{
										
										$filename = preg_replace("/\\.[^.\\s]{3,4}$/", "", $avatar);
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original';
										processthumb($handle,$filename,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_y        = true;
										$handle->image_x               = 133;
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn133'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 51;
										$handle->image_y               = 51;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn51'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 40;
										$handle->image_y               = 40;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn40'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 32;
										$handle->image_y               = 32;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn32'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 19;
										$handle->image_y               = 19;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn19'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$sql="update #__awd_wall_users SET `avatar` = '".strtolower($avatar)."' where user_id=".$user->user_id;
										$db->setQuery( $sql );
										if (!$db->query())
										{
											return JError::raiseWarning( 500, $db->getError() );
										}
									
									}
								}
								
							}
							else
							{
								$avatar='pending_n.png';
								$preavatar=$user->avatar;
								//$avatar='nophoto_n.png';
								
								
								
								// update blank image to the table and folder
								$sql="select avatar from  #__awd_wall_users where user_id=".$user->user_id;
								$db->setQuery( $sql );
								$wavatar=$db->loadResult();
								
								if($preavatar!=$wavatar)
								{
									$sql="update #__awd_wall_users SET `avatar` = '' where user_id=".$user->user_id;
									$db->setQuery( $sql );
									if (!$db->query())
									{
										return JError::raiseWarning( 500, $db->getError() );
									}
									
									$deleteimagepath1=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original'. DS .$wavatar;
									$deleteimagepath2=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn133'.$wavatar;
									$deleteimagepath3=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn51'.$wavatar;
									$deleteimagepath4=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn40'.$wavatar;
									$deleteimagepath5=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn32'.$wavatar;
									$deleteimagepath6=JPATH_SITE. DS .'images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb'. DS .'tn19'.$wavatar;
									unlink($deleteimagepath1);
									unlink($deleteimagepath2);
									unlink($deleteimagepath3);
									unlink($deleteimagepath4);
									unlink($deleteimagepath5);
									unlink($deleteimagepath6);
						
									
									// update the default image of cb
									$cbtemplate=$ueConfig['templatedir'];
									$imagepath=JPATH_SITE. DS . 'components'. DS .'com_comprofiler' .DS.'plugin'.DS.'templates'.DS.$cbtemplate.DS.'images'.DS.'avatar'.DS.$avatar;
									$handle = new upload($imagepath);
								
								
									if ($handle->uploaded) 
									{
										$filename = preg_replace("/\\.[^.\\s]{3,4}$/", "", $avatar);
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'original';
										processthumb($handle,$filename,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_y        = true;
										$handle->image_x               = 133;
										
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn133'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 51;
										$handle->image_y               = 51;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn51'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 40;
										$handle->image_y               = 40;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn40'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 32;
										$handle->image_y               = 32;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn32'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$handle->image_resize          = true;
										$handle->image_ratio_crop      = true;
										$handle->image_x               = 19;
										$handle->image_y               = 19;
										$folder='images' . DS . 'wallavatar' . DS . $user->user_id . DS . 'thumb';
										$filename2='tn19'.$filename;
										processthumb($handle,$filename2,$folder);
										
										$sql="update #__awd_wall_users SET `avatar` = '".strtolower($avatar)."' where user_id=".$user->user_id;
										$db->setQuery( $sql );
										if (!$db->query())
										{
											return JError::raiseWarning( 500, $db->getError() );
										}
									
									}
									
								}
							}
						
						}
					
				}
	
		
	}
	}
Ejemplo n.º 3
0
	function saveGroup()
	{
		JRequest::checkToken() or die( 'Invalid Token' );
		require_once (JPATH_COMPONENT . DS . 'models' . DS . 'wall.php');			
		$itemId = AwdwallHelperUser::getComItemId();
		//$itemId=$_REQUEST['Itemid'];
		$user 		= &JFactory::getUser();			
		$db 		= &JFactory::getDBO();
		$groupTitle = JRequest::getString('group_title', '');
		$groupDes  	= JRequest::getString('group_description', '');
		$privacy	= JRequest::getInt('group_type', 1);
		$groupId	= JRequest::getInt('awd_group_id', 0);
		if($groupId==0)
		{
			$newgrp=1;
		}
		else
		{
			$newgrp=0;
		}
			
		if((int)$user->id){
			// upload image
			$arrExt 	= explode(',', AwdwallHelperUser::getImageExt());
			$image 	= JRequest::getVar('awd_group_image', null, 'files', 'array');
			$fileName = '';
			$des = '';
			if($image['name'] != ''){
				jimport('joomla.filesystem.file');
				jimport('joomla.filesystem.folder');
				$time = time();
				//Clean up filename to get rid of strange characters like spaces etc
				$fileName = $time . '_' . JFile::makeSafe($image['name']);
				$fileName = str_replace(' ', '_', $fileName);
				$src 	= $image['tmp_name'];
				$dest 	= 'images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'original' . DS . $fileName; 
			}
			if($groupId == 0){
				$query = "INSERT INTO #__awd_groups(creator, title, description, privacy, image, created_date) VALUES(" . $user->id . ", '" . $groupTitle . "', '" . $groupDes . "', ". $privacy .", '" . $fileName . "', '" . time() . "')";
			}else{
			
			if($fileName == ''){
				$fileName = JRequest::getString('awd_group_old_image', '');
			}
							
			$query = "UPDATE #__awd_groups SET title = '". $groupTitle ."', description = '" .$groupDes. "', privacy = " . $privacy . ", image='" . $fileName . "' WHERE id = " . $groupId;
			}
		
			$db->setQuery($query);			
			
			// store like to database
			if (!$db->query()){	
				$this->setRedirect(JRoute::_('index.php?option=com_awdwall&view=awdwall&layout=mywall&Itemid=' . $$itemId , false ), $db->getErrorMsg());		
			}
			if($groupId == 0)
				$groupId = $db->insertid();
			if($image['name'] != ''){
				jimport('joomla.filesystem.file');
				jimport('joomla.filesystem.folder');
				$time = time();
				//Clean up filename to get rid of strange characters like spaces etc
				$fileName = $time . '_' . JFile::makeSafe($image['name']);
				$fileName = str_replace(' ', '_', $fileName);
				$src 	= $image['tmp_name'];
				$dest 	= 'images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'original' . DS . $fileName; 
			}
			
			// upload
			if($image['name'] != ''){
			if(in_array(strtolower(JFile::getExt($fileName)), $arrExt)){
				   require_once (JPATH_COMPONENT . DS . 'libraries' . DS . 'class.upload.php');	
				   $handle = new upload($_FILES['awd_group_image']);
				   if ($handle->uploaded) {
				   
						$filename = preg_replace("/\\.[^.\\s]{3,4}$/", "", $fileName);
						$filename1 = preg_replace("/\\.[^.\\s]{3,4}$/", "", $fileName);
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'original';
						processthumb($handle,$filename,$folder);
						
						$handle->image_resize          = true;
						$handle->image_ratio_crop      = true;
						$handle->image_x               = 133;
						
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'thumb';
						$filename='tn133'.$filename1;
						processthumb($handle,$filename,$folder);
						
						$handle->image_resize          = true;
						$handle->image_ratio_crop      = true;
						$handle->image_x               = 51;
						$handle->image_y               = 51;
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'thumb';
						$filename='tn51'.$filename1;
						processthumb($handle,$filename,$folder);
						
						$handle->image_resize          = true;
						$handle->image_ratio_crop      = true;
						$handle->image_x               = 64;
						$handle->image_y               = 64;
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'thumb';
						$filename='tn64'.$filename1;
						processthumb($handle,$filename,$folder);
						
						$handle->image_resize          = true;
						$handle->image_ratio_crop      = true;
						$handle->image_x               = 40;
						$handle->image_y               = 40;
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'thumb';
						$filename='tn40'.$filename1;
						processthumb($handle,$filename,$folder);
						
						$handle->image_resize          = true;
						$handle->image_ratio_crop      = true;
						$handle->image_x               = 32;
						$handle->image_y               = 32;
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'thumb';
						$filename='tn32'.$filename1;
						processthumb($handle,$filename,$folder);
						
						$handle->image_resize          = true;
						$handle->image_ratio_crop      = true;
						$handle->image_x               = 19;
						$handle->image_y               = 19;
						$folder='images' . DS . 'awdgrp_images' . DS . $groupId . DS . 'thumb';
						$filename='tn19'.$filename1;
						processthumb($handle,$filename,$folder);
						
				   }
					
					
					
					
				}else {
					//Redirect and notify user file is not right extension
					$this->setRedirect(JRoute::_('index.php?option=com_awdwall&task=viewgroup&groupid=' . $groupId . '&Itemid='  . $itemId, false));
				}
			
			}
		}else{
			$this->setRedirect(JRoute::_('index.php?option=com_awdwall&&layout=mywall&Itemid=' . $itemId, false), JText::_('Need to login'));
		}
					// store into wall
			if( $newgrp==1 && $groupId!=0)
			{		
				if($privacy==1)
				{
					
					$grplink=JRoute::_('index.php?option=com_awdwall&task=viewgroup&groupid=' . $groupId . '&Itemid='  . $itemId);
					
					
					
					$Itemid = AwdwallHelperUser::getComItemId();
					$wall 				=& JTable::getInstance('Wall', 'Table');						
					$wall->user_id		= $user->id ;
					$wall->type			= 'text';
					$wall->commenter_id	= $user->id;
					$wall->user_name	= '';
					$wall->avatar		= '';
					$wall->message		= JText::sprintf('HAS CREATED THE GROUP', $grplink, $groupTitle);	
					$wall->reply		= 0;
					$wall->is_read		= 0;
					$wall->is_pm		= 0;
					$wall->is_reply		= 0;
					$wall->posted_id	= NULL;
					$wall->wall_date	= time();
		
					// store wall to database
					if (!$wall->store()){				
						$this->setRedirect(JRoute::_('index.php?option=com_awdwall&&view=awdwall&layout=main&Itemid='.$itemId , false ), JText::_('Post Failed'));
					}
				}
			
			}
		$this->setRedirect(JRoute::_('index.php?option=com_awdwall&task=viewgroup&groupid=' . $groupId . '&Itemid='  . $itemId, false));
	}