public function handleGet($get, $post, $files, $cookies)
 {
     if (Models\User::currentUser($cookies)->authorizationLevel < 5) {
         throw new \Exception('You are not authorized to view this page');
     }
     ini_set('max_execution_time', 9000);
     chdir(constant('BASE_DIR'));
     $lastdone = isset($get['lastdone']) ? (int) $get['lastdone'] : 0;
     $starttime = isset($get['starttime']) ? (int) $get['starttime'] : time();
     $numdone = isset($get['numdone']) ? (int) $get['numdone'] : 0;
     $phpself = self::getUrl();
     /* Rescan */
     if (!isset($get['lastdone'])) {
         Models\Folder::update();
     }
     /* Set up the page view */
     $this->htmlHeader($cookies);
     //TODO BREAKING MVC HERE BECAUSE OF INTREMENTAL RENDERING
     echo '<h2>Rendering thumbnails <small>To avoid a delay when viewing photos for the first time</small></h2>';
     $total = Models\Database::selectOne('photos', 'count(*)');
     $done = Models\Database::selectOne('photos', 'count(*)', "id <= {$lastdone}");
     $todo = Models\Database::selectOne('photos', 'count(*)', "id > {$lastdone}");
     $timeleft = ceil((time() - $starttime) * $todo / ($numdone + $done / 1000 + 1) / 60);
     echo "<p>Progress: " . number_format($done) . ' of ' . number_format($total) . " done";
     echo " (about {$timeleft} minutes left)";
     echo "</p>\n";
     $percentage = $done / $total * 100;
     echo "<progress class=\"progress\" value=\"{$percentage}\" max=\"100\">{$percentage}%</progress>";
     $next1000 = Models\Database::select('photos', 'id', "id > {$lastdone} AND status != 9", 'ORDER BY id LIMIT 500');
     $fixed = 0;
     flush();
     while (($next = $next1000->fetchAssoc()) && $fixed < 10) {
         $photo = Models\Photo::getPhotoWithID($next['id']);
         $redo = $photo->isCacheMissing();
         if ($redo) {
             echo "<div>Updating #" . $next['id'] . "</div>\n";
             $photo->generateThumbnail();
             echo "<div>Updated #" . $next['id'] . "</div>\n";
             flush();
             $fixed++;
             $photo->destroy();
         }
         $lastdone = $next['id'];
     }
     $numdone += $fixed;
     if ($todo > 0) {
         echo "<script language='javascript'>window.setTimeout('window.location=\"" . htmlspecialchars($phpself) . "?lastdone={$lastdone}&starttime={$starttime}&numdone={$numdone}\"',400)</script>\n";
         echo "<p><a href=\"?lastdone={$lastdone}&starttime={$starttime}&numdone={$numdone}\">Click here to continue</a> if the Javascript redirect doesn't work.</p>\n";
     }
     $this->htmlFooter();
 }
Exemplo n.º 2
0
 public function __construct($modelId)
 {
     parent::__construct();
     if (!Models\Photo::photoExists(intval($modelId))) {
         header("HTTP/1.0 404 Not Found");
         throw new \Exception('Photo #' . intval($modelId) . ' not found.');
     }
     $this->model = Models\Photo::getPhotoWithID($modelId);
     $this->title = $this->model->get('description');
     $this->icon = 'photo';
     $this->url = self::getUrlForID($this->model->id);
     //todo: done by parent?
     $this->imageType = 'image/jpeg';
     $this->image = $this->model->getMediaURL('thumbnail');
     $this->imageType = 'image/jpeg';
     $this->imageWidth = $this->model->get('tn_width');
     $this->imageHeight = $this->model->get('tn_height');
 }
Exemplo n.º 3
0
 public function handleGet($get, $post, $files, $cookies)
 {
     $photo = Models\Photo::getPhotoWithID($get['id']);
     $scale = isset($get['scale']) ? $get['scale'] : null;
     $extension = $photo->extension;
     if (!is_numeric($get['ver'])) {
         throw new \Exception('Required number ver missing! Query string: ' . htmlentities($_SERVER['QUERY_STRING']));
     }
     if ($photo->get('status') != 0) {
         if (Models\User::currentUser($cookies)->authorizationLevel < 5) {
             throw new \Exception('Photo access denied');
         }
     }
     list($file, $temp, $mtime) = self::getFileForPhotoWithScale($photo, $scale);
     if ($extension == 'jpg' || $extension == 'jpeg') {
         header('Content-type: image/jpeg');
     } elseif ($extension == 'png') {
         header('Content-type: image/png');
     } elseif ($extension == 'gif') {
         header('Content-type: image/gif');
     } else {
         throw new \Exception('Unknown photo type');
     }
     header('Content-Disposition: inline; filename="' . htmlentities($photo->get('description')) . '.' . $extension . '";');
     header('Content-Length: ' . filesize($file));
     header("Date: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
     header("Expires: " . gmdate("D, d M Y H:i:s", time() + 2592000) . " GMT");
     // One month
     if ($file) {
         readfile($file);
     }
     if ($temp) {
         unlink($file);
     }
 }
 public function handleGet($get, $post, $files, $cookies)
 {
     if (Models\User::currentUser($cookies)->authorizationLevel < 5) {
         throw new \Exception('You are not authorized to view this page');
     }
     /* Set up the page view */
     $checkpointId = intval(Models\Preferences::valueForModuleWithKey('CameraLife', 'checkpointphotos'));
     $view = new Views\AdminPhotosView();
     $view->isUsingHttps = isset($_SERVER['HTTPS']);
     $view->myUrl = $_SERVER['REQUEST_URI'];
     $query = Models\Database::select('photos', 'id', 'id>:0 AND status!=9', 'ORDER BY id LIMIT 200', null, array($checkpointId));
     $view->photos = array();
     while ($row = $query->fetchAssoc()) {
         $view->photos[] = Models\Photo::getPhotoWithID($row['id']);
         $view->lastReviewItem = $row['id'];
     }
     $done = Models\Database::selectOne('photos', 'count(id)', 'id<=:0 AND status!=9', null, null, array($checkpointId));
     $view->reviewsDone = $done;
     $remaining = Models\Database::selectOne('photos', 'count(id)', 'id>:0 AND status!=9', null, null, array($checkpointId));
     $view->reviewsRemaining = $remaining;
     $this->htmlHeader($cookies);
     $view->render();
     $this->htmlFooter();
 }
Exemplo n.º 5
0
    /**
     * Render the view to standard output
     *
     * @access public
     * @return void
     */
    public function render()
    {
        if ($this->photo->get('status') != 0) {
            echo '<p class="alert alert-danger lead"><strong>Notice:</strong> This photo is not publicly viewable</p>';
        }
        $this->referrer = str_replace(constant('BASE_URL'), '', $this->referrer);
        $this->referrer = preg_replace('|^/|', '', $this->referrer);
        //todo, photo model needs to know referrer
        $photoPrev = $this->photo->getPrevious();
        $photoNext = $this->photo->getNext();
        // Get stuff related to the current user
        if ($this->currentUser->isLoggedIn) {
            $rating = $avg = Models\Database::selectOne('ratings', 'AVG(rating)', 'id=' . $this->photo->get('id') . " AND username='******'");
        } else {
            $rating = $avg = Models\Database::selectOne('ratings', 'AVG(rating)', 'id=' . $this->photo->get('id') . " AND user_ip='" . $this->currentUser->remoteAddr . "'");
        }
        ?>

		<nav class="navbar navbar-light bg-faded navbar-fixed-bottom" style="background:rgba(255,255,255,0.4)">
			<div class="container">
				<form class="form-inline pull-xs-left" method=POST name="form" style="margin-right:10px">
					<input type="hidden" name="action" value="<?php 
        echo $rating ? 'unfavorite' : 'favorite';
        ?>
">
					<?php 
        $count = $this->photo->getLikeCount();
        ?>
					<button class="btn btn-link" type="submit" style="padding:2px">
				        <span class="fa-stack">
				            <i class="fa fa-star<?php 
        echo $rating ? '' : '-o';
        ?>
 fa-stack-2x" style="color:gold"></i>
				            <strong class="fa-stack-1x" style="font-size:0.7em;color:black"><?php 
        echo $count ? $count : '';
        ?>
</strong>
				        </span>				
					</button>
				</form>
			    <a href="<?php 
        echo $this->photo->getMediaURL('photo');
        ?>
"
			        class="btn btn-link pull-xs-left"
			        title="<?php 
        echo $this->photo->get('width');
        ?>
 x <?php 
        echo $this->photo->get('height');
        ?>
px"
					style="margin-right:10px"
				>
			        <i class="fa fa-arrows-alt"></i>
			    </a>
			    <a href="<?php 
        echo $this->contextUrl;
        ?>
"
			        class="btn btn-link pull-xs-left"
			        title="Close"
					style="margin-right:10px"
				>
			        <i class="fa fa-times"></i>
			    </a>
		        <span class="navbar-brand"><?php 
        echo htmlspecialchars($this->openGraphObject->title);
        ?>
</span>
			</div>
		</nav>
 
<div
	id="mainPic" 
	style="position:absolute;top:0;left:0;width:100%;height:100%;background:url(<?php 
        echo $this->photo->getMediaURL('scaled');
        ?>
);background-size:contain;background-repeat:no-repeat;background-position:center"
>

	<img
		src="<?php 
        echo $this->photo->getMediaURL('scaled');
        ?>
"
		alt="<?php 
        echo htmlentities($this->photo->get('description'));
        ?>
"
		style="display:none"
	>
</div>

<div class="container" style="position:absolute;top:100%;height:100%;">
        <h3>Information</h3>
        <dl class="dl-horizontal">
            <?php 
        if ($this->photo->get('username')) {
            echo '         <dt>Author</dt><dd>' . $this->photo->get('username') . '</dd>';
        }
        if ($exif = $this->photo->getEXIF()) {
            foreach ($exif as $key => $val) {
                if ($key == "Location") {
                    echo "         <dt>{$key}</dt><dd><a href=\"http://maps.google.com/maps?q={$val}\">{$val}</a></dd>\n";
                } else {
                    if ($key == "Camera Model") {
                        echo "         <dt>{$key}</dt><dd><a href=\"http://pbase.com/cameras/{$val}\">{$val}</a></dd>\n";
                    } else {
                        echo "         <dt>{$key}</dt><dd>{$val}</dd>\n";
                    }
                }
            }
        }
        ?>
        </dl>
</div>
 
<?php 
        // Cache the next image the user is likely to look at
        if ($photoNext) {
            echo '<img style="display:none" src="' . htmlspecialchars($photoNext->getMediaURL('scaled')) . '" alt="hidden photo">';
        }
    }