示例#1
0
 public function actionUpload()
 {
     $params = Yii::app()->params;
     $file = CUploadedFile::getInstanceByName('avatar');
     try {
         if ($file === null) {
             throw new Exception(Yii::t('common', 'No file uploaded'), 1);
         }
         if ($file->getHasError()) {
             throw new Exception(Yii::t('common', 'Upload failed, please contact the administrator'), $file->getError());
         }
         $imagesize = getimagesize($file->getTempName());
         if ($imagesize === false) {
             throw new Exception(Yii::t('common', 'Invalid file type of image'), 2);
         }
         if ($imagesize[0] > $params['avatar']['width'] || $imagesize[1] > $params['avatar']['height']) {
             throw new Exception(Yii::t('common', 'Image height or width exceeded, the limited width is {width} and height is {height}', array('{width}' => $params['avatar']['width'], '{height}' => $params['avatar']['height'])), 3);
         }
         if (filesize($file->getTempName()) > $params['avatar']['size']) {
             throw new Exception(Yii::t('common', 'File is too large, the limited size is {size}', array('{size}' => sprintf('%.2fMB', $params['avatar']['size'] / 1048576))), 4);
         }
         $basePath = $params->staticPath;
         $extension = image_type_to_extension($imagesize[2]);
         $md5 = md5(file_get_contents($file->getTempName()));
         $filename = $md5 . $extension;
         $dirname = 'upload/' . $md5[0] . '/';
         $fullPath = $params->staticPath . $dirname . $filename;
         $fullDir = dirname($fullPath);
         if (!is_dir($fullDir)) {
             mkdir($fullDir, 0755, true);
         }
         if (file_exists($fullPath) || $file->saveAs($fullPath)) {
             $userAvatar = new UserAvatar();
             $userAvatar->user_id = $this->user->id;
             $userAvatar->md5 = $md5;
             $userAvatar->extension = $extension;
             $userAvatar->width = $imagesize[0];
             $userAvatar->height = $imagesize[1];
             $userAvatar->add_time = time();
             $userAvatar->save(false);
             $this->user->avatar_id = $userAvatar->id;
             $this->user->save();
             $url = $params->staticUrlPrefix . $dirname . $filename;
             $errorCode = 0;
             $errorMsg = '';
         } else {
             throw new Exception(Yii::t('common', 'Upload failed, please contact the administrator'), 1);
         }
     } catch (Exception $e) {
         $url = '';
         $errorCode = $e->getCode();
         $errorMsg = $e->getMessage();
     }
     $this->render('upload', array('url' => $url, 'errorCode' => $errorCode, 'errorMsg' => $errorMsg));
 }
示例#2
0
function blogPostWithCategory($blogPostId, $title, $userId, $userFirst, $userLast, $date, $categoryId, $categoryName, $answered = false, $isOpen = true)
{
    ?>
    <div class="row">
        <h4>
            <div>
                <a href="?page=question&id=<?php 
    echo $blogPostId;
    ?>
"><?php 
    echo $title;
    ?>
</a>
                <?php 
    if ($answered) {
        echo '<span class="glyphicon glyphicon-ok" style="color:green"></span>';
    }
    if (!$isOpen) {
        echo '<span class="glyphicon glyphicon-remove" style="color:red"></span>';
    }
    ?>
                 <br/>
            </div>
        </h4>
        <h5>
            <a href="?page=category_questions&id=<?php 
    echo $categoryId;
    ?>
"><?php 
    echo $categoryName;
    ?>
</a>
        </h5>
        <?php 
    $ua = new UserAvatar($userId);
    ?>
        <p>by <a href="?page=profile&id=<?php 
    echo $userId;
    ?>
"><?php 
    echo $userFirst . " " . $userLast . " " . $ua->getImage(15, 15);
    ?>
</a></p>

        <p><span class="glyphicon glyphicon-time"></span> <?php 
    echo $date;
    ?>
</p>
        <hr>
    </div>

<?php 
}
示例#3
0
    $email = $SessionPerson->email();
}
if (isset($_POST["submit"]) && $page->getQuery("sent")) {
    $fileName = $id . ".png";
    move_uploaded_file($_FILES['avatar']['tmp_name'], ICONS_DIR . $fileName);
    $page->removeQuery("sent");
    $page->redirect();
} else {
    $page->showHeader();
    ?>


	<div class="container col-md-8">
		<div class="panel-body text-center">
			<?php 
    $ua = new UserAvatar($id);
    echo $ua->getImage(140, 140);
    ?>
			<br/>
			<?php 
    if ($id == $SessionPerson->id()) {
        ?>
				<form action="?page=profile&sent=true" method="post" enctype="multipart/form-data">
					<br/>
					<input type="file" name="avatar" id="avatar" value="Upload Avatar" class="col-md-offset-4"/>
					<br/>
					<input type="submit" name="submit" id="submit" value="Upload"/>
				</form>
			<?php 
    }
    ?>
示例#4
0
				<li>

					<form class="navbar-form navbar-left" role="search" method="post" action="?page=search">
						<div class="form-group">
							<input type="text" id="search" name="search" class="form-control" placeholder="Search">
						</div>
						<input type="submit" id="search_submit" name="search_submit" value="Go!" />
					</form>
				</li>
				<ul class="nav navbar-nav">
                    <?php 
if ($this->isAuth()) {
    //If logged in
    ?>
                            <li><a href="?page=profile"><?php 
    $ua = new UserAvatar($this->person->id());
    echo $ua->getImage();
    ?>
 Welcome <?php 
    echo $this->person->fullName();
    ?>
 (<?php 
    echo $this->person->points();
    ?>
)</a></li>
                            <li><a href="?page=logout">Logout</a></li>
                   <?php 
} else {
    // not Logged in
    ?>
                        <li><a href="?page=login">Sign In</a></li>
示例#5
0
$RENDENGINE->render($rendlist);
?>
	
	<input name="files" type="file" accept="image/*">
	<div class="form-group">
		<button type="submit" class="btn" value="Submit">Submit</button>
	</div>

</form>

<?php 
if (isset($_POST) && !array_diff($post_array, array_keys($_POST))) {
    $SANTIZER = new InputSanitizer($_POST);
    $SANTIZER->addFilter("about", FILTER_SANITIZE_STRING);
    $sant_arr = $SANTIZER->filter();
    /*
    	We will not worry about deleting the old image for now. Should be implemented later, however.
    */
    $connection2 = $DB->connect();
    if ($avatar_img != null) {
        require $_SERVER['DOCUMENT_ROOT'] . "/Common/ImageManager/useravatar.php";
        $img_mang = new UserAvatar($avatar_img);
        $ava_path = $img_mang->createImage($USERSESS->getUserID());
        (new sqlDBExecute($connection2, "UPDATE USERINFO SET About = \$1,AvatarPath = \$2 WHERE UserID = \$3", array($sant_arr[0], $ava_path, $USERSESS->getUserID())))->execute();
    } else {
        /*Redundent for now*/
        (new sqlDBExecute($connection2, "UPDATE USERINFO SET About = \$1 WHERE UserID = \$2", array($sant_arr[0], $USERSESS->getUserID())))->execute();
    }
}
?>
 
示例#6
0
 public static function importByUrlAndUserId($pUrl, $pUserId, $pOnlineIdentity)
 {
     try {
         $lImported = ImageImporter::importImageFromUrl($pUrl, $pUserId);
         if ($lImported) {
             $lAvatar = new UserAvatar();
             $lAvatar->setUserId($pUserId);
             $lAvatar->setAvatar(md5(strtolower($pUrl)) . '-' . $pUserId . '.jpg');
             $lAvatar->setOnlineIdentityId($pOnlineIdentity->getId());
             // inititalize gravatar info
             $lAvatar->setImportedIdentifier($pUrl);
             // generate missing
             $lAvatar->generateAvatarThumbnails();
             $lAvatar->setImportedCommunity($pOnlineIdentity->getCommunityId());
             $lAvatar->save();
         }
     } catch (Exception $e) {
         sfContext::getInstance()->getLogger()->err("{ImageImporter} Exception: " . print_r($e, true));
     }
 }
示例#7
0
                    ?>
                        <div class="container col-md-8">
                            <div class="panel
                    <?php 
                    if ($hasAnswer && $a["id"] == $post["correctAnswerId"]) {
                        echo "panel-success";
                    } else {
                        echo "panel-info";
                    }
                    ?>
">
                                <div class="panel-heading">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <?php 
                    $ua = new UserAvatar($a["user_id"]);
                    echo $ua->getImage(30, 30);
                    ?>
                                            <a href="?page=profile&id=<?php 
                    echo $userA["id"];
                    ?>
"><?php 
                    echo $userA["first_name"] . " " . $userA["last_name"];
                    ?>
</a>
                                            <?php 
                    if ($BlogPosts->isPoster($id, $SessionPerson->id()) && !$hasAnswer) {
                        ?>
                                                [<a href="<?php 
                        echo $page->currentURL() . "&mark=" . $a["id"];
                        ?>