Filtering by filename

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.com
So 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

  • acrylian Administrator, Developer
    I am sorry, I don't understand why you need that. If you need to show images in different resolutions for a wallpaper gallery for example why don't you use the image sizing functions that zenphoto provides? You could make a separate theme page for that or do it even on image.php directly. Much easier than hacking the core.
  • I didn't ask if you thought I needed it, I already know I need it. I just wanted to know if someone could see why that code isn't working as intended.
  • fretzl Administrator, Developer
    I didn't ask if you thought I needed it
    Please, keep it friendly !!
  • I didn't mean to be unfriendly, on the contrary I was trying to assure him I really do want this feature to work :) Sorry if it seemed hostile.

    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 :)
  • acrylian Administrator, Developer
    I understood it the same way as fretzl and was about to not answer or answer a certain way...written text easily can lead to unnecssary misunderandings...

    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 have been using zenphoto for over 2 years and from day one I have always customized the core, I have systems in place to ensure upgrading to new versions works flawlessly.
    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!
  • acrylian Administrator, Developer
    blemishing the almighty core
    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..:-)
  • Well I'll have a look at the plugin functionality, I had noticed it but hadn't tried it. It looks cool :)
    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
Sign In or Register to comment.