Hi, I'm trying to make a modification to zenphoto so that it reads cookies/get variables to determine if it needs to filter images by resolution (by filename in this case, because the resolution is always in the image filename) and then do it.
What I have so far is I have changed lines 1160-1189 in zp-core/class-album.php from this:
`
function loadFileNames($dirs=false) {
if ($this->isDynamic()) { // there are no 'real' files
return array();
}
$albumdir = getAlbumFolder() . $this->name . "/";
if (!is_dir($albumdir) || !is_readable($albumdir)) {
if (!is_dir($albumdir)) {
$msg = sprintf(gettext("Error: The album %s cannot be found."), htmlspecialchars($this->name));
} else {
$msg = sprintf(gettext("Error: The album %s is not readable."), htmlspecialchars($this->name));
}
die($msg);
}
$dir = opendir($albumdir);
$files = array();
$others = array();
while (false !== ($file = readdir($dir))) {
if ($dirs && (is_dir($albumdir.$file) && (substr($file, 0, 1) != '.') ||
hasDyanmicAlbumSuffix($file))) {
$files[] = $file;
} else if (!$dirs && is_file($albumdir.$file)) {
if (is_valid_other_type($file)) {
$files[] = $file;
$others[] = $file;
} else if (is_valid_image($file)) {
$files[] = $file;
}
}
}
`
To this:
`
function loadFileNames($dirs=false) {
$filterWidth = "no";
if (isset($_COOKIE['Height']) && isset($_COOKIE['Width'])) {
if (is_numeric($_COOKIE['Height']) && is_numeric($_COOKIE['Width'])) {
$filterWidth = $_COOKIE['Width'];
$filterHeight = $_COOKIE['Height'];
}
}
if (isset($_GET['height']) && isset($_GET['width']) && isset($_GET['pref'])) {
if (is_numeric($_GET['height']) && is_numeric($_GET['width']) && $_GET['pref'] == "set") {
$filterWidth = $_GET['width'];
$filterHeight = $_GET['height'];
}
elseif ($_GET['pref'] == "unset") {
$filterWidth = "no";
}
}
if ($this->isDynamic()) { // there are no 'real' files
return array();
}
$albumdir = getAlbumFolder() . $this->name . "/";
if (!is_dir($albumdir) || !is_readable($albumdir)) {
if (!is_dir($albumdir)) {
$msg = sprintf(gettext("Error: The album %s cannot be found."), htmlspecialchars($this->name));
} else {
$msg = sprintf(gettext("Error: The album %s is not readable."), htmlspecialchars($this->name));
}
die($msg);
}
$dir = opendir($albumdir);
$files = array();
$others = array();
if ($filterWidth == "no") {
while (false !== ($file = readdir($dir))) {
if ($dirs && (is_dir($albumdir.$file) && (substr($file, 0, 1) != '.') || hasDyanmicAlbumSuffix($file))) {
$files[] = $file;
}
elseif (!$dirs && is_file($albumdir.$file)) {
if (is_valid_image($file)) {
$files[] = $file;
}
}
}
}
else {
while (false !== ($file = readdir($dir))) {
if ($dirs && (is_dir($albumdir.$file) && (substr($file, 0, 1) != '.') || hasDyanmicAlbumSuffix($file))) {
$isUserResolution = strpos($file,$filterWidth."x".$filterHeight);
if ($isUserResolution !== false) {
$files[] = $file;
}
}
elseif (!$dirs && is_file($albumdir.$file)) {
if (is_valid_image($file)) {
$isUserResolution = strpos($file,$filterWidth."x".$filterHeight);
if ($isUserResolution !== false) {
$files[] = $file;
}
}
}
}
}
`
Which you can see here
http://dmb2.dualmonitorbackgrounds.comSo you'll see it breaks it. It works fine if you click the text near the top of the page "Click here to only show 0000x0000 backgrounds", it filters the images properly, but for some reason it breaks it when the cookie/get is unset. There must be something stupid I've missed but I just can't see it myself. I'm hoping someone can glance at the code and spot what I've done wrong. Thanks in advance
Comments
Please, keep it friendly !!
I need people to be able to go to www.dualmonitorbackgrounds.com and click the link "only show backgrounds at your resolution" and then it dynamically filters the resolutions. Using zenphoto's built-in image manipulation doesn't work for me because an automatic system doesn't know which parts of the image are important or not. A lot of the backgrounds I upload that have different available resolutions have had care taken to make the different sizes, not just a quick crop/resize job.
Anyway I'm fully capable of writing the code by myself I just wanted a little help with a problem, often an outsider can see it much quicker than the developers themselves.
I'm happy to wait to see if someone sees anything wrong with my code, I can work on other features in the meantime
Anyway I really would suggest to do this as a plugin and not as a core hack. You will get problems as soon as you want to update for sure. You could probably also use tags and/or dynamic albums for that, too....
I'll just look for help on a general PHP forum, this one seems to have really changed since I last visited. I remember threads full of people posting cool code hacks and not worrying about blemishing the almighty core, bring back those days!
Sorry, I don't know what it is with us.... All I said is that we generally don't recommend hacking the core.. I generally just wanted to show some other possibilites than hacking the core since we now have plugins for exactly these things.
If you don't want to take suggestions you of course can change and hack the core as you like, that is what open source is about.
I am sorry I personally just don't have the time to get into your code right now. If others want to help right on.
No need to speak of old times..:-)
The main thing I'm concerned with is server load (which is why I usually edit cores instead of make extensions) because with this website it is pretty popular and makes the server cry sometimes. I will definitely give it a try though. Thanks