예제 #1
0
 /**
  * getFileForPhotoWithScale function.
  * 
  * @access private
  * @param Models\Photo $photo
  * @param mixed $scale
  * @return [$file, $temp, $mtime]
  */
 private static function getFileForPhotoWithScale(Models\Photo $photo, $scale)
 {
     $extension = $photo->extension;
     $bucket = 'other';
     $path = '';
     if ($scale == 'photo') {
         if ($photo->get('modified')) {
             $path = '/' . $photo->get('id') . '_mod.' . $extension;
         } else {
             $bucket = 'photo';
             $path = rtrim('/' . ltrim($photo->get('path'), '/'), '/') . '/' . $photo->get('filename');
         }
     } elseif ($scale == 'scaled') {
         $thumbSize = Models\Preferences::valueForModuleWithKey('CameraLife', 'scaledsize');
         $path = "/{$photo->get('id')}_{$thumbSize}.{$extension}";
     } elseif ($scale == 'thumbnail') {
         $thumbSize = Models\Preferences::valueForModuleWithKey('CameraLife', 'thumbsize');
         $path = "/{$photo->get('id')}_{$thumbSize}.{$extension}";
     } elseif (is_numeric($scale)) {
         $valid = preg_split('/[, ]+/', Models\Preferences::valueForModuleWithKey('CameraLife', 'optionsizes'));
         if (!in_array($scale, $valid)) {
             throw new \Exception('This image size has not been allowed');
         }
         $path = "/{$photo->get('id')}_{$scale}.{$extension}";
     } else {
         throw new \Exception('Missing or bad size parameter');
     }
     $fileStore = Models\FileStore::fileStoreWithName($bucket);
     list($file, $temp, $mtime) = $fileStore->getFile($path);
     if (!$file) {
         $photo->generateThumbnail();
         list($file, $temp, $mtime) = $fileStore->getFile($path);
     }
     return [$file, $temp, $mtime];
 }
 public function handlePost($get, $post, $files, $cookies)
 {
     if (Models\User::currentUser($cookies)->authorizationLevel < 5) {
         throw new \Exception('You are not authorized to view this page');
     }
     $prefs = array();
     foreach ($post as $key => $val) {
         if ($key == 'target') {
             continue;
         } else {
             $array = explode('|', $key);
             if (count($array) != 2) {
                 $cameralife->error('Invalid module / key');
             }
             $prefs[] = array('module' => $array[0], 'param' => $array[1], 'value' => $val);
         }
     }
     foreach ($prefs as $pref) {
         if (isset($pref['module']) && isset($pref['param']) && isset($pref['value'])) {
             Models\Preferences::setValueForModuleWithKey($pref['value'], $pref['module'], $pref['param']);
         } else {
             var_dump($prefs);
             die('passed wrong');
         }
     }
     echo "UPDATE DONE";
 }
 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 */
     $view = new Views\AdminCommentsView();
     $view->checkpointId = intval(Models\Preferences::valueForModuleWithKey('CameraLife', 'checkpointcomments'));
     $view->checkpointDate = Models\Database::selectOne('logs', 'max(user_date)', 'id=' . $view->checkpointId);
     $view->showFromMe = isset($get['fromMe']) && $get['fromMe'];
     $view->showFromRegistered = isset($get['fromRegistered']) && $get['fromRegistered'];
     $view->showFromUnregistered = isset($get['fromUnregistered']) && $get['fromUnregistered'];
     if (!$view->showFromMe && !$view->showFromRegistered && !$view->showFromUnregistered) {
         $view->showFromMe = true;
         $view->showFromRegistered = true;
         $view->showFromUnregistered = true;
     }
     /* Query the comment logs */
     $currentUser = Models\User::currentUser($cookies);
     $condition = "(0 ";
     $condition .= $view->showFromMe ? "OR username = '******' " : '';
     $condition .= $view->showFromRegistered ? "OR (username LIKE '_%' AND username != '" . $currentUser->name . "')" : '';
     $condition .= $view->showFromUnregistered ? "OR username = '' " : '';
     $condition .= ") ";
     $condition .= " AND id > " . $view->checkpointId;
     $query = Models\Database::select('comments', '*', $condition);
     $commentRecords = array();
     while ($record = $query->fetchAssoc()) {
         $commentRecords[] = $record;
     }
     $view->commentRecords = $commentRecords;
     $this->htmlHeader($cookies);
     $view->render();
     $this->htmlFooter();
 }
 public function render()
 {
     echo "<h2>Settings for " . $this->moduleName . "</h2>\n";
     if (isset($module->about)) {
         echo "<p class=\"lead\">" . $module->about . "</p>\n";
     }
     if (!count($this->preferences)) {
         echo "<p>(no settings for this module)</p>\n";
         return;
     }
     echo "<form class=\"form-horizontal\" method=\"post\">\n";
     echo "<input type=\"hidden\" name=\"target\" value=\"" . $_SERVER['PHP_SELF'] . "\" />\n";
     foreach ($this->preferences as $pref) {
         $tag = $pref['module'] . '|' . $pref['key'];
         $value = Models\Preferences::valueForModuleWithKey($pref['module'], $pref['key']);
         echo '<div class="form-group row">';
         echo '  <label class="col-md-2 form-control-label" for="' . $tag . '">' . $pref['name'] . '</label>';
         echo '  <div class="col-md-10">' . PHP_EOL;
         if ($pref['type'] == 'number') {
             echo "      <input class=\"form-control\" type=\"number\" name=\"{$tag}\" value=\"{$value}\" />\n";
         } elseif ($pref['type'] == 'string') {
             echo "      <input class=\"form-control\" type=\"text\" name=\"{$tag}\" value=\"" . htmlspecialchars($value) . "\" />\n";
         }
         if ($pref['type'] == 'directory' || $pref['type'] == 'directoryrw') {
             echo "      <input class=\"form-control\" type=\"text\" name=\"{$tag}\" value=\"{$value}\" />\n";
             if (!is_dir($value) && !is_dir(constant('BASE_DIR') . "/{$value}")) {
                 echo '<p class="text-error">This is not a directory</p>';
             } elseif ($pref['type'] == 'directoryrw' && !is_writable($value) && !is_writable(constant('BASE_DIR') . "/{$value}")) {
                 echo '<p class="form-control-static text-error">This directory is not writable</p>';
             }
         } elseif (is_array($pref['type'])) {
             // enumeration
             echo "      <select class=\"form-control\" name=\"{$tag}\">\n";
             foreach ($pref['type'] as $index => $desc) {
                 $extra = $index == $value ? 'selected' : '';
                 echo "        <option {$extra} value=\"{$index}\">{$desc}</option>\n";
             }
             echo "      </select />\n";
         } elseif ($pref['type'] == 'yesno') {
             echo "      <select name=\"{$tag}\">\n";
             foreach (array('1' => 'Yes', '0' => 'No') as $index => $desc) {
                 if ($index == $value) {
                     echo "        <option class=\"form-control\" selected value=\"{$index}\">{$desc}</option>\n";
                 } else {
                     echo "        <option value=\"{$index}\">{$desc}</option>\n";
                 }
             }
             echo "      </select />\n";
         }
         if (isset($pref['desc'])) {
             echo '    <small class="text-muted">' . $pref['desc'] . '</small>';
         }
         echo '  </div>';
         echo '</div>' . PHP_EOL;
     }
     echo '<div class="control-group"><div class="controls"><input type="submit" value="Save changes" class="btn btn-primary"/></div></div>';
     echo "</form>\n";
 }
예제 #5
0
 protected function htmlBareFooter()
 {
     $view = new Views\FooterView();
     $view->statsUrl = StatisticsController::getUrl();
     $view->analyticsId = Models\Preferences::valueForModuleWithKey('BootstrapTheme', 'analytics');
     $view->ownerEmail = Models\Preferences::valueForModuleWithKey('CameraLife', 'owner_email');
     $view->extraJavascript = $this->footerJavascript;
     $view->mainPageOpenGraph = $this;
     $view->render();
 }
예제 #6
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 */
     $view = new Views\AdminLogsView();
     $view->checkpointId = intval(Models\Preferences::valueForModuleWithKey('CameraLife', 'checkpointlogs'));
     $view->checkpointDate = Models\Database::selectOne('logs', 'max(user_date)', 'id=' . $view->checkpointId);
     $view->showFromMe = isset($get['fromMe']) && $get['fromMe'];
     $view->showFromRegistered = isset($get['fromRegistered']) && $get['fromRegistered'];
     $view->showFromUnregistered = isset($get['fromUnregistered']) && $get['fromUnregistered'];
     $view->showChangedPhotos = isset($get['changedPhotos']) && $get['changedPhotos'];
     $view->showChangedTags = isset($get['changedTags']) && $get['changedTags'];
     $view->showChangedUsers = isset($get['changedUsers']) && $get['changedUsers'];
     $view->showChangedPrefs = isset($get['changedPreferences']) && $get['changedPreferences'];
     if (!$view->showFromMe && !$view->showFromRegistered && !$view->showFromUnregistered) {
         $view->showFromMe = true;
         $view->showFromRegistered = true;
         $view->showFromUnregistered = true;
     }
     if (!$view->showChangedPhotos && !$view->showChangedTags && !$view->showChangedUsers && !$view->showChangedPrefs) {
         $view->showChangedPhotos = true;
         $view->showChangedTags = true;
         $view->showChangedUsers = true;
         $view->showChangedPrefs = true;
     }
     /* Query the audit logs */
     $currentUser = Models\User::currentUser($cookies);
     $condition = "(0 ";
     $condition .= $view->showChangedPhotos ? "OR record_type = 'photo' " : '';
     $condition .= $view->showChangedTags ? "OR record_type = 'album' " : '';
     $condition .= $view->showChangedUsers ? "OR record_type = 'user' " : '';
     $condition .= $view->showChangedPrefs ? "OR record_type = 'preference' " : '';
     $condition .= ") AND (0 ";
     $condition .= $view->showFromMe ? "OR user_name = '" . $currentUser->name . "' " : '';
     $condition .= $view->showFromRegistered ? "OR (user_name LIKE '_%' AND user_name != '" . $currentUser->name . "')" : '';
     $condition .= $view->showFromUnregistered ? "OR user_name = '' " : '';
     $condition .= ") ";
     $condition .= " AND logs.id > " . $view->checkpointId;
     $extra = "GROUP BY record_id, record_type, value_field ORDER BY maxid DESC";
     $query = Models\Database::select('logs', 'record_type, record_id, value_field, MAX(logs.id) as maxid', $condition, $extra);
     $auditTrails = array();
     while ($record = $query->fetchAssoc()) {
         $auditTrails[] = Models\AuditTrail::getAuditTrailWithID($record['maxid']);
     }
     $view->auditTrails = $auditTrails;
     $this->htmlHeader($cookies);
     $view->render();
     $this->htmlFooter();
 }
 public function handlePost($get, $post, $files, $cookies)
 {
     if (Models\User::currentUser($cookies)->authorizationLevel < 5) {
         throw new \Exception('You are not authorized to view this page');
     }
     if (!isset($post['target'])) {
         throw new \Exception('No target specified');
     }
     foreach ($post as $key => $val) {
         if ($key == 'target') {
             continue;
         } else {
             $array = explode('|', $key);
             if (count($array) != 2) {
                 throw new \Exception('Invalid module / key');
             }
             Models\Preferences::setValueForModuleWithKey($val, $array[0], $array[1]);
         }
     }
     header("Location: " . htmlspecialchars($post['target']));
 }
예제 #8
0
 public function render()
 {
     echo "<h2>Review New photos</h2>";
     $percentDone = 0;
     $percentDoing = 0;
     if ($this->reviewsDone + $this->reviewsRemaining) {
         $percentDone = $this->reviewsDone * 100 / ($this->reviewsDone + $this->reviewsRemaining);
         $percentDoing = count($this->photos) * 100 / ($this->reviewsDone + $this->reviewsRemaining);
     }
     echo '<div class="progress">';
     echo '<div class="progress-bar progress-bar-success" style="width: ' . $percentDone . '%;"></div>';
     echo '<div class="progress-bar progress-bar-info" style="width: ' . $percentDoing . '%;"></div>';
     echo '</div>';
     if (!$this->isUsingHttps) {
         echo "<p class=\"lead alert alert-danger\"><strong>Warning:</strong> You are viewing this page, which includes private photos, without HTTPS</p>";
     }
     if (count($this->photos) < $this->reviewsRemaining) {
         echo "<p class=\"lead\">There are " . number_format($this->reviewsRemaining) . " new photos since your last review, the first " . number_format(count($this->photos)) . " are shown below.</p>";
     } else {
         echo "<p class=\"lead\">There are " . number_format($this->reviewsRemaining) . " new photos since your last review.</p>";
     }
     echo "<div class=\"row\">";
     $height = Models\Preferences::valueForModuleWithKey('CameraLife', 'thumbsize');
     foreach ($this->photos as $photo) {
         $url = Controllers\PhotoController::getUrlForID($photo->id);
         $color = $photo->get('status') == 0 ? 'default' : 'danger';
         echo '<div class="col-md-2 col-sm-4 bg-' . $color . '" style="height:' . $height . 'px">';
         echo '<a href="' . htmlspecialchars($url) . '">';
         echo '<img class="img-responsive center-block img-rounded" width="' . intval($photo->get('tn_width')) . '" src="' . htmlspecialchars($photo->getMediaURL('thumbnail')) . '" alt="' . htmlentities($photo->get('description')) . '" />';
         echo '</a>';
         echo '</div>';
     }
     echo '</div>';
     $action = Controllers\AdminPreferenceChangeController::getUrl();
     echo '<form method="post" action="' . $action . '">';
     echo '<input type="hidden" name="target" value="' . htmlspecialchars($this->myUrl) . '">';
     echo '<input type="hidden" name="CameraLife|checkpointphotos" value="' . htmlspecialchars($this->lastReviewItem) . '">';
     echo '<button class="btn btn-primary btn-lg">Mark these items as reviewed</button>';
     echo '</form>';
 }
예제 #9
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 */
     $view = new Views\AdminView();
     $view->runningVersion = constant('CAMERALIFE_VERSION');
     $view->latestVersion = $this->latestAvailableVersion();
     $checkpointLogs = intval(Models\Preferences::valueForModuleWithKey('CameraLife', 'checkpointlogs'));
     $view->numNewLogs = Models\Database::selectOne('logs', 'COUNT(*)', 'id>' . $checkpointLogs);
     $checkpointComments = intval(Models\Preferences::valueForModuleWithKey('CameraLife', 'checkpointcomments'));
     $view->numNewComments = Models\Database::selectOne('comments', 'COUNT(*)', 'id>' . $checkpointComments);
     $view->numNewUsers = Models\Database::selectOne('users', 'COUNT(*)', 'auth=1');
     $view->numFlagged = Models\Database::selectOne('photos', 'COUNT(*)', 'status=1');
     $view->appearanceUrl = AdminAppearanceController::getUrl();
     $view->logsUrl = AdminLogsController::getUrl();
     $view->commentsUrl = AdminCommentsController::getUrl();
     $view->fileStoreUrl = AdminFileStoreController::getUrl();
     $view->securityUrl = AdminSecurityController::getUrl();
     $view->thumbnailUrl = AdminThumbnailController::getUrl();
     $view->rescanUrl = AdminRescanController::getUrl();
     $view->photosUrl = AdminPhotosController::getUrl();
     $preferences = array();
     $preferences[] = ['module' => 'CameraLife', 'key' => 'sitename', 'type' => 'string', 'name' => 'Site name'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'sitename', 'type' => 'string', 'name' => 'Site abbreviation'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'owner_email', 'type' => 'string', 'name' => 'Owner email address'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'rewrite', 'type' => 'yesno', 'name' => 'Use pretty URLs'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'autorotate', 'type' => 'yesno', 'name' => 'Autorotate photos'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'thumbsize', 'type' => 'number', 'name' => 'Size for thumbnails'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'scaledsize', 'type' => 'number', 'name' => 'Size for preview images'];
     $preferences[] = ['module' => 'CameraLife', 'key' => 'optionsizes', 'type' => 'string', 'name' => 'Other available sizes', 'help' => 'comma separated (you can also leave this blank)'];
     $view->preferences = $preferences;
     $this->htmlHeader($cookies);
     $view->render();
     $this->htmlFooter();
 }
 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();
 }
예제 #11
0
 public static function getUrlForIDWithParameters($modelId, $parameters)
 {
     $reflection = new \ReflectionClass(get_called_class());
     $shortName = $reflection->getShortName();
     $page = lcfirst(basename($shortName, 'Controller'));
     $query = http_build_query($parameters);
     $modelId = ltrim($modelId, '/');
     // TODO, use this http://stackoverflow.com/a/14375686/300224
     if (self::$rewriteEnabled === null) {
         self::$rewriteEnabled = Models\Preferences::valueForModuleWithKey('CameraLife', 'rewrite') == 'yes' || Models\Preferences::valueForModuleWithKey('CameraLife', 'rewrite') == 1;
     }
     if (!self::$rewriteEnabled) {
         return constant('BASE_URL') . '/index.php?page=' . $page . '&id=' . $modelId . ($query ? '&' . $query : '');
     }
     return constant('BASE_URL') . '/' . $page . '/' . $modelId . ($query ? '?' . $query : '');
 }
 public function handlePost($get, $post, $files, $cookies)
 {
     session_start();
     if (!isset($post['host'])) {
         throw new \Exception('HOST is missing');
     }
     if (!isset($post['name'])) {
         throw new \Exception('NAME is missing');
     }
     if (!isset($post['user'])) {
         throw new \Exception('USER is missing');
     }
     if (!isset($post['pass'])) {
         throw new \Exception('PASS is missing');
     }
     if (!isset($post['prefix'])) {
         throw new \Exception('PREFIX is missing');
     }
     if (!isset($_SESSION['openid_identity'])) {
         throw new \Exception('OpenID login is missing');
     }
     Models\Database::$dsn = "mysql:host={$post['host']};dbname={$post['name']}";
     Models\Database::$username = $post['user'];
     Models\Database::$password = $post['pass'];
     Models\Database::$prefix = $post['prefix'];
     Models\Database::setupTables();
     Models\Preferences::setFactoryDefaults();
     Models\User::userWithOpenId($_SESSION['openid_identity'], $_SESSION['openid_email']);
     Models\Database::update('users', ['auth' => 5], 'email="' . $_SESSION['openid_email'] . '"');
     //todo security
     header('Location: ' . MainPageController::getUrl());
     //todo URL / url http://www.teamten.com/lawrence/writings/capitalization_of_initialisms.html
 }