Дополнительная фотография в профиле

Пробовал вставить дополнительную фотографию в профиле по принципу этой статьи livestreet.ru/blog/1964.html. Не получилось, выдает ошибки. Мои действия:

1) Добавил поле в mysql в таблицу prefix_user, после foto назвал foto2. параметры прописал эдентичные.
2) В classes/actions/ActionSettings.class.php добавил после:

/**
* Загрузка фото, делаем ресайзы
*/			
if (isset($_FILES['foto']) and is_uploaded_file($_FILES['foto']['tmp_name'])) {				
if ($sFileFoto=$this->User_UploadFoto($_FILES['foto'],$this->oUserCurrent)) {	
$this->oUserCurrent->setProfileFoto($sFileFoto);			
} else {
$bError=true;
$this->Message_AddError($this->Lang_Get('settings_profile_foto_error'),$this->Lang_Get('error'));
}
}
/**
 * Удалить фото
*/
if (isset($_REQUEST['foto_delete'])) {
$this->User_DeleteFoto($this->oUserCurrent);
$this->oUserCurrent->setProfileFoto(null);
}

добавил вот это

/**
 * Загрузка фото2, делаем ресайзы
*/			
if (isset($_FILES['foto2']) and is_uploaded_file($_FILES['foto2']['tmp_name'])) {				
if ($sFileFoto2=$this->User_UploadFoto2($_FILES['foto2'],$this->oUserCurrent)) {	
$this->oUserCurrent->setProfileFoto2($sFileFoto2);			
} else {
$bError=true;
$this->Message_AddError($this->Lang_Get('settings_profile_foto_error'),$this->Lang_Get('error'));
}
}
/**
 * Удалить фото
 */
if (isset($_REQUEST['foto2_delete'])) {
$this->User_DeleteFoto2($this->oUserCurrent);
$this->oUserCurrent->setProfileFoto2(null);
}

3) В classes/modules/user/entity/User.entity.class.php после:

    public function getProfileFoto() {
        return $this->_aData['user_profile_foto'];
    }  

добавил

	    public function getProfileFoto2() {
        return $this->_aData['user_profile_foto2'];
    } 

и после

    public function setProfileFoto($data) {
    	$this->_aData['user_profile_foto']=$data;
    }  

добавил

	    public function setProfileFoto2($data) {
    	$this->_aData['user_profile_foto2']=$data;
    }

4) В classes/modules/user/mapper/User.mapper.class.php после

user_profile_foto = ? ,	

добавил

user_profile_foto2 = ? ,	

и после

$oUser->getProfileFoto(),

добавил

$oUser->getProfileFoto(),

5) В templates/skin/тема/actions/ActionSettings/profile.tpl после:

				{if $oUserCurrent->getProfileFoto()}
					<img src="{$oUserCurrent->getProfileFoto()}" border="0">					
					<input type="checkbox" id="foto_delete" name="foto_delete" value="on"> — <label for="foto_delete"><span class="form">{$aLang.settings_profile_foto_delete}</span></label><br />
				{/if}
				<p><label for="foto">{$aLang.settings_profile_foto}:</label><br /><input type="file" id="foto" name="foto"/></p>

добавил:

				{if $oUserCurrent->getProfileFoto2()}
					<img src="{$oUserCurrent->getProfileFoto2()}" border="0">					
					<input type="checkbox" id="foto2_delete" name="foto2_delete" value="on"> — <label for="foto2_delete"><span class="form">{$aLang.settings_profile_foto_delete}</span></label>
					<br />
				{/if}
				<p><label for="foto2">{$aLang.settings_profile_foto2}:</label><br /><input type="file" id="foto2" name="foto2"/></p>

При попытках загрузить фото и фото2 выдает множество ошибок, а если в ActionSettings заменить это

if ($sFileFoto2=$this->User_UploadFoto2($_FILES['foto2'],$this->oUserCurrent)) 

на это

if ($sFileFoto2=$this->User_UploadFoto($_FILES['foto2'],$this->oUserCurrent)) 

загрузится только foto2. В mysql в foto прописваются пути к картинкам которых просто нет в папке upload. Кто может помочь, 2й день работаю над этим. Над сайтом уже почти месяц осталось только это сделать. Жду ответов гуру)

5 комментариев

avatar
вирсия движка 0.4.2
avatar
Такие реализации лучше делать в виде плагинов, а не менять исходники в основном дистрибутиве.
Сейчас сам в своём плагине делаю что то похожее, так же нечего пока не получается..:(
avatar
Как вариант можете оставить

if ($sFileFoto2=$this->User_UploadFoto2($_FILES['foto2'],$this->oUserCurrent)) 


и в User.class.php добавить

/**
	 * Upload user foto2
	 *
	 * @param  array           $aFile
	 * @param  ModuleUser_EntityUser $oUser
	 * @return string
	 */
	public function UploadFoto2($aFile,$oUser) {
		if(!is_array($aFile) || !isset($aFile['tmp_name'])) {
			return false;
		}
				
		$sFileTmp=Config::Get('sys.cache.dir').func_generator();
		if (!move_uploaded_file($aFile['tmp_name'],$sFileTmp)) {
			return false;
		}
		$sDirUpload=$this->Image_GetIdDir($oUser->getId());
		$aParams=$this->Image_BuildParams('foto2');
		
		if ($sFileFoto2=$this->Image_Resize($sFileTmp,$sDirUpload,func_generator(6),Config::Get('view.img_max_width'),Config::Get('view.img_max_height'),250,null,true,$aParams)) {
			@unlink($sFileTmp);
			/**
			 * удаляем старое фото
			 */
			$this->DeleteFoto2($oUser);
			return $this->Image_GetWebPath($sFileFoto2);
		}
		@unlink($sFileTmp);
		return false;
	}
	/**
	 * Delete user foto from server
	 *
	 * @param ModuleUser_EntityUser $oUser
	 */
	public function DeleteFoto2($oUser) {
		@unlink($this->Image_GetServerPath($oUser->getProfileFoto2()));
	}


Подход не самый лучший, наверное, с точки зрения программирования, но зато все работает
avatar
спасибо огромное
avatar
Для 0.5 пойдет?)
Только зарегистрированные и авторизованные пользователи могут оставлять комментарии.