public function run() { if (!Yii::app()->user->isGuest) { $im = Yii::app()->request->getPost('im'); $inbase = UserImages::model()->findByAttributes(array('name' => $im), 'user_id=' . Yii::app()->user->id); if (!$inbase) { throw new CHttpException(404, 'Ошибка.'); return true; } $rootPath = Yii::app()->getBasePath() . '/..'; $fullpath = $rootPath . '/uploads/userimages/' . $im; if (file_exists($fullpath)) { $image = new Image($fullpath); $image->crop(Yii::app()->request->getPost('w'), Yii::app()->request->getPost('h'), Yii::app()->request->getPost('y'), Yii::app()->request->getPost('x')); $image->save(); MCleaner::cleanTempImg($im); $inbase->getUrl('100x75'); echo Yii::app()->request->getPost('imbox'); } } }
public function actionDeleteProfilePic() { if (isset($_POST['picId'])) { $model = UserImages::model()->findByPk($_POST['picId']); if ($model) { $folder = Yii::getPathOfAlias('webroot') . '/../images/users/'; unlink($folder . $model->ImagePath); $model->delete(); return true; } else { return false; } } Yii::app()->end(); }
public function actionSetAsProfilePic() { $userID = Yii::app()->user->getId(); if (UserImages::model()->findByAttributes(array('UserId' => $userID, 'MainImage' => '1'))) { $model = UserImages::model()->findByAttributes(array('UserId' => $userID, 'MainImage' => '1')); $model->MainImage = 0; $model->save(); } UserImages::model()->updateByPk($_POST['id'], array('MainImage' => 1)); Yii::app()->end(); }
<div class="widget-content nopadding"> <ul class="recent-posts"> <?php $criteria = new CDbCriteria(); $criteria->distinct = true; $criteria->select = "UserId"; $criteria->order = "MembershipStart DESC"; $criteria->limit = 4; $recentMember = MembershipUsers::model()->findAll($criteria); foreach ($recentMember as $mlist) { ?> <li> <div class="user-thumb"> <?php if (UserImages::model()->findByAttributes(array('UserId' => $mlist->user->Objid, 'MainImage' => 1))) { $userImage = UserImages::model()->findByAttributes(array('UserId' => $mlist->user->Objid, 'MainImage' => 1)); ?> <img src="<?php echo Yii::app()->params['siteUrl']; ?> /timthumb.php?src=<?php echo Yii::app()->params['siteUrl']; ?> /images/users/<?php echo $userImage->ImagePath; ?> &w=40&h=40" alt="" /> <?php } else { echo '<img src="' . Yii::app()->theme->baseUrl . '/images/nullImage.png" alt="" />'; }
public function getPhotosCount($id) { $model = UserImages::model()->findAllByAttributes(array("UserId" => $id)); if (count($model) == 0) { return "No"; } else { return count($model); } }
<span id="onlineUser<?php echo $model->Objid; ?> " class="onlineStatus"></span> <?php } ?> <a href="<?php echo Yii::app()->baseUrl; ?> /profile/<?php echo $model->UserId; ?> " target="_blank"> <?php $profileImage = UserImages::model()->findByAttributes(array("UserId" => $model->Objid, "MainImage" => 1)); if (empty($profileImage)) { ?> <img src="<?php echo Yii::app()->theme->baseUrl; ?> /images/fav-empty.png" alt="" /> <?php } else { ?> <img src="<?php echo Yii::app()->baseUrl; ?> /timthumb.php?src=<?php echo Yii::app()->baseUrl; ?>
<div class="form-actions"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn btn-primary')); ?> </div> <?php $this->endWidget(); ?> </div> </div> <div id="photos" class="tab-pane"> <div class="widget-content nopadding"> <?php $userImageList = UserImages::model()->findAllByAttributes(array('UserId' => $model->Objid)); foreach ($userImageList as $list) { ?> <div class="photoBlock" id="photoBlock<?php echo $list->Objid; ?> "> <?php echo CHtml::ajaxLink("", array("users/deleteProfilePic"), array("type" => "POST", "data" => array("picId" => $list->Objid), "success" => "function(){\n\t\t\t\$('#photoBlock" . $list->Objid . "').remove();\n\t\t}", 'beforeSend' => 'function() { if(confirm("Are you sure want to delete image?")) return true; else return false; }'), array("class" => "deletePic")); ?> <img src="<?php