Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Got rid of more global vars
Removed the remaining global vars from config.inc.php

#28
  • Loading branch information
jeroenrnl committed Dec 16, 2012
1 parent 80861e6 commit 8b29bc0
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 54 deletions.
6 changes: 2 additions & 4 deletions php/album.inc.php
Expand Up @@ -435,8 +435,6 @@ public static function getRoot() {
*/
public static function getTopN(user $user=null) {

global $TOP_N;

if ($user && !$user->is_admin()) {
$sql =
"SELECT al.*, count(distinct ph.photo_id) AS count FROM " .
Expand All @@ -453,7 +451,7 @@ public static function getTopN(user $user=null) {
" AND gp.access_level >= ph.level " .
"GROUP BY al.album_id " .
"ORDER BY count desc, al.album " .
"LIMIT 0, " . escape_string($TOP_N);
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
else {
$sql =
Expand All @@ -463,7 +461,7 @@ public static function getTopN(user $user=null) {
"where pa.album_id = al.album_id " .
"group by al.album_id " .
"order by count desc, al.album " .
"limit 0, " . escape_string($TOP_N);
"limit 0, " . escape_string($user->prefs->get("reports_top_n"));
}

return parent::getTopNfromSQL("album", $sql);
Expand Down
7 changes: 2 additions & 5 deletions php/category.inc.php
Expand Up @@ -382,9 +382,6 @@ public static function getCount($dummy=null) {
* Get Top N categories
*/
public static function getTopN(user $user=null) {

global $TOP_N;

if ($user && !$user->is_admin()) {
$sql =
"select cat.*, count(distinct ph.photo_id) as count from " .
Expand All @@ -404,7 +401,7 @@ public static function getTopN(user $user=null) {
"AND gp.access_level >= ph.level " .
"GROUP BY cat.category_id " .
"ORDER BY count desc, cat.category " .
"LIMIT 0, " . escape_string($TOP_N);
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
else {
$sql =
Expand All @@ -414,7 +411,7 @@ public static function getTopN(user $user=null) {
"where pc.category_id = cat.category_id " .
"group by cat.category_id " .
"order by count desc, cat.category " .
"limit 0, " . escape_string($TOP_N);
"limit 0, " . escape_string($user->prefs->get("reports_top_n"));
}

return parent::getTopNfromSQL("category", $sql);
Expand Down
8 changes: 4 additions & 4 deletions php/config.inc.php
Expand Up @@ -347,9 +347,9 @@
// $MAX_CRUMBS_TO_SHOW = 8;
// $DEFAULT_ROWS = 3;
// $DEFAULT_COLS = 4;
$MAX_PAGER_SIZE = 10;
$RANDOM_PHOTO_MIN_RATING = 5;
$TOP_N = 5;
$SLIDESHOW_TIME = 5; // seconds
// $MAX_PAGER_SIZE = 10;
// $RANDOM_PHOTO_MIN_RATING = 5;
// $TOP_N = 5;
// $SLIDESHOW_TIME = 5; // seconds

?>
4 changes: 2 additions & 2 deletions php/edit_photo.inc.php
Expand Up @@ -80,7 +80,7 @@

<div class="prev"><?php echo $prev_link ? "[ $prev_link ]" : "&nbsp;" ?></div>
<div class="photohdr">
<?php echo $photo->get_fullsize_link($photo->get("name"),$FULLSIZE_NEW_WIN) ?> :
<?php echo $photo->get_fullsize_link($photo->get("name")) ?> :
<?php echo $photo->get("width") ?> x <?php echo $photo->get("height") ?>,
<?php echo $photo->get("size") ?> <?php echo translate("bytes") ?>
</div>
Expand All @@ -105,7 +105,7 @@
?>
</ul>

<?php echo $photo->get_fullsize_link($photo->get_midsize_img(),$FULLSIZE_NEW_WIN) ?>
<?php echo $photo->get_fullsize_link($photo->get_midsize_img()) ?>
<?php
}
?>
Expand Down
2 changes: 1 addition & 1 deletion php/edit_photos.php
Expand Up @@ -382,7 +382,7 @@
$pager_vars[$key] = $val;
}
$request_vars = $pager_vars;
echo pager($offset, $num_photos, $num_pages, $cells, $MAX_PAGER_SIZE, $request_vars, "_off");
echo pager($offset, $num_photos, $num_pages, $cells, $user->prefs->get("max_pageer_size"), $request_vars, "_off");
} // if photos
?>
<br>
Expand Down
10 changes: 3 additions & 7 deletions php/person.inc.php
Expand Up @@ -383,9 +383,6 @@ public static function getCount($dummy=null) {
* Get Top N people
*/
public static function getTopN(user $user=null) {

global $TOP_N;

if ($user && !$user->is_admin()) {
$sql =
"SELECT ppl.*, COUNT(DISTINCT ph.photo_id) AS count FROM " .
Expand All @@ -405,17 +402,16 @@ public static function getTopN(user $user=null) {
" AND gp.access_level >= ph.level " .
"GROUP BY ppl.person_id " .
"ORDER BY count DESC, ppl.last_name, ppl.first_name " .
"LIMIT 0, " . escape_string($TOP_N);
}
else {
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
} else {
$sql =
"select ppl.*, count(*) as count from " .
DB_PREFIX . "people as ppl, " .
DB_PREFIX . "photo_people as pp " .
"where ppl.person_id = pp.person_id " .
"group by ppl.person_id " .
"order by count desc, ppl.last_name, ppl.first_name " .
"limit 0, " . escape_string($TOP_N);
"limit 0, " . escape_string($user->prefs->get("reports_top_n"));
}

return parent::getTopNfromSQL("person", $sql);
Expand Down
5 changes: 3 additions & 2 deletions php/photo.inc.php
Expand Up @@ -532,9 +532,10 @@ function get_thumbnail_link($link = null) {
return " <a href=\"$link\">" . $this->get_image_tag(THUMB_PREFIX) . "</a>";
}

function get_fullsize_link($title, $FULLSIZE_NEW_WIN) {
function get_fullsize_link($title) {
$user=user::getCurrent();
$image = $this->getURL();
$newwin = ($FULLSIZE_NEW_WIN ? "target=\"_blank\"" : "");
$newwin = ($user->prefs->get("fullsize_new_win") ? "target=\"_blank\"" : "");
return "<a href=\"$image\" $newwin>$title</a>";
}

Expand Down
4 changes: 2 additions & 2 deletions php/photo.php
Expand Up @@ -338,7 +338,7 @@
<?php
}
?>
<?php echo $photo->get_fullsize_link($photo->get("name"),$FULLSIZE_NEW_WIN) ?> :
<?php echo $photo->get_fullsize_link($photo->get("name")) ?> :
<?php echo $photo->get("width") ?> x <?php echo $photo->get("height") ?>,
<?php echo $photo->get("size") ?> <?php echo translate("bytes") ?>
</div>
Expand All @@ -362,7 +362,7 @@
}
?>
</ul>
<?php echo $photo->get_fullsize_link($photo->get_midsize_img(),$FULLSIZE_NEW_WIN) ?>
<?php echo $photo->get_fullsize_link($photo->get_midsize_img()) ?>
<?php
if (($user->is_admin() || $user->get("browse_people")) && $people_links = get_photo_person_links($photo)) {
?>
Expand Down
2 changes: 1 addition & 1 deletion php/photos.php
Expand Up @@ -202,7 +202,7 @@
?>
<br>
<?php
echo pager($offset, $num_photos, $num_pages, $cells, $MAX_PAGER_SIZE, $vars, "_off");
echo pager($offset, $num_photos, $num_pages, $cells, $user->prefs->get("max_pager_size"), $vars, "_off");
} // if photos
?>
<br>
Expand Down
7 changes: 2 additions & 5 deletions php/place.inc.php
Expand Up @@ -530,9 +530,6 @@ public static function getCount($dummy=null) {
* Get Top N people
*/
public static function getTopN(user $user=null) {

global $TOP_N;

if ($user && !$user->is_admin()) {
$sql =
"SELECT plc.*, count(distinct ph.photo_id) AS count FROM " .
Expand All @@ -550,7 +547,7 @@ public static function getTopN(user $user=null) {
"' AND gp.access_level >= ph.level " .
"GROUP BY plc.place_id " .
"ORDER BY count desc, plc.title, plc.city " .
"LIMIT 0, $TOP_N";
"LIMIT 0, " . (int) $user->prefs->get("reports_top_n");
}
else {
$sql =
Expand All @@ -560,7 +557,7 @@ public static function getTopN(user $user=null) {
"where plc.place_id = ph.location_id " .
"group by plc.place_id " .
"order by count desc, plc.title, plc.city " .
"limit 0, $TOP_N";
"limit 0, " . (int) $user->prefs->get("reports_top_n");
}

return parent::getTopNfromSQL("place", $sql);
Expand Down
15 changes: 0 additions & 15 deletions php/prefs.inc.php
Expand Up @@ -55,21 +55,6 @@ function lookup_color_scheme($force = 0) {
}

function load($force = 0) {

// these are global vars because originally they were set in
// config.inc.php instead of stored in the db
global $MAX_PAGER_SIZE;
global $RANDOM_PHOTO_MIN_RATING;
global $TOP_N;
global $SLIDESHOW_TIME;
global $FULLSIZE_NEW_WIN;

$MAX_PAGER_SIZE = intval($this->get("max_pager_size"));
$RANDOM_PHOTO_MIN_RATING = intval($this->get("random_photo_min_rating"));
$TOP_N = intval($this->get("reports_top_n"));
$SLIDESHOW_TIME = intval($this->get("slideshow_time"));
$FULLSIZE_NEW_WIN = $this->get("fullsize_new_win");

if ($this->lookup_color_scheme($force)) {
color_scheme::setCurrent($this->color_scheme);
}
Expand Down
8 changes: 4 additions & 4 deletions php/slideshow.php
Expand Up @@ -62,11 +62,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset;?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link TYPE="text/css" REL="stylesheet" HREF="css.php">
<?php
if (!$_pause) {
$header = "<meta http-equiv=\"refresh\" content=\"" . $SLIDESHOW_TIME . ";URL=" . $_SERVER["PHP_SELF"] . "?" . $new_qs. "\">\n";
$header = "<meta http-equiv=\"refresh\" content=\"" . $user->prefs->get("slideshow_time") . ";URL=" . $_SERVER["PHP_SELF"] . "?" . $new_qs. "\">\n";
} else {
$header="";
$new_qs = str_replace("&amp;_pause=1", "", $new_qs);
Expand Down Expand Up @@ -107,12 +107,12 @@
?>
<div class="prev">&nbsp;</div>
<div class="photohdr">
<?php echo $photo->get_fullsize_link($photo->get("name"),$FULLSIZE_NEW_WIN)?>:
<?php echo $photo->get_fullsize_link($photo->get("name"))?>:
<?php echo $photo->get("width") ?> x <?php echo $photo->get("height")?>,
<?php echo $photo->get("size") ?> <?php echo translate("bytes")?>
</div>
<div class="next">&nbsp;</div>
<?php echo $photo->get_fullsize_link($photo->get_midsize_img(),$FULLSIZE_NEW_WIN)?>
<?php echo $photo->get_fullsize_link($photo->get_midsize_img())?>
<?php
if ($people_links = get_photo_person_links($photo)) {
?>
Expand Down
5 changes: 3 additions & 2 deletions php/zoph.php
Expand Up @@ -22,7 +22,7 @@

// get one random photo
$vars["_random"] = 1;
$vars["rating"] = $RANDOM_PHOTO_MIN_RATING;
$vars["rating"] = $user->prefs->get("random_photo_min_rating");
$vars["_rating-op"] = ">=";

$thumnails;
Expand Down Expand Up @@ -72,12 +72,13 @@
<?php
$recent = new Time();
$sub_days = (int) $user->prefs->get("recent_photo_days");
$min_rating = (int) $user->prefs->get("random_photo_min_rating");
$recent->sub(new DateInterval("P" . (int) $sub_days . "D"));
$timestamp=$recent->format("Y-m-d");

echo sprintf(translate("You may search for photos %s taken %s or %s modified %s in the past %s days."), "<a href=\"photos.php?_date-op=%3E%3D&amp;date=" . $timestamp . "\">", "</a>", "<a href=\"photos.php?_timestamp-op=%3E%3D&amp;timestamp=" . $timestamp . "\">", "</a>", $sub_days);
echo "\n";
echo sprintf(translate("Or you may use the %s search page %s to find photos using multiple criteria. You may also view a %s randomly chosen photo %s like the one above."), "<a href=\"search.php\">", "</a>", "<a href=\"photos.php?_random=1&amp;_rating-op=%3E%3D&amp;rating=$RANDOM_PHOTO_MIN_RATING\">","</a>");
echo sprintf(translate("Or you may use the %s search page %s to find photos using multiple criteria. You may also view a %s randomly chosen photo %s like the one above."), "<a href=\"search.php\">", "</a>", "<a href=\"photos.php?_random=1&amp;_rating-op=%3E%3D&amp;rating=" . $min_rating . "\">","</a>");
echo "\n <p class=\"intro\">\n";
echo sprintf(translate("These options are always available in the tabs on the upper right. Use the %s home %s link to return here. Click on any thumbnail to see a larger version along with information about that photo."),"<a href=\"zoph.php\">","</a>");
echo "\n </p>\n";
Expand Down

0 comments on commit 8b29bc0

Please sign in to comment.