コード例 #1
0
 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();
 }
コード例 #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');
 }
コード例 #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);
     }
 }
コード例 #4
0
 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();
 }