It would be great to implement some form of Password Protect for albums or entire directory, not using .htaccess. A guy just released something of interest for Wordpress that is similar to what I am thinking of.
http://broome.us/archives/2007/01/31/the-wordpress-password-plugin/Regards...
Comments
I would like to have albums I can share with say family members only who have a password.
I have the same situation as you, there are albums I would only like family to view.
This is an album without a password:
http://www.newwws.be/zenphoto/mieren
And this is an album with a password:
http://www.newwws.be/zenphoto/test (the password is zen)
I work with a theme that uses a configuration file for each album. In that configuration file I can select whether to use a password or not. The cookie is valid for 30 minutes. After that time people will have to re-enter the password again. If you want to see the form in action again and don't want to wait 30 minutes, you can change the toplevel domain of the links into .org / .net / .tv / .us / .co.uk / .be
groeten, Miriam
If it's not too much trouble, you should share your work with the forum here? It might benefit others, if it's something you can package up easily. I'd be happy to write up the wiki article and place it in the ZenphotoHacks portion of the wiki. There have been a number of people (especially in this thread) asking about something like this. I know that this is planned for eventual release in the core zenphoto code, but this might help "hold" people over until that feature is integrated in the code.
FIRST...
Place this PHP code BEFORE the line with <!DOCTYPE etc....> in album.php
`
<?php<br />
#========================[Private album]===========================
/* $newwws_password is set in the album specific configuration file, but */
/* if the name of an album starts starts with an underscore, we consider it to be */
/* a private album too. The default-password will be zen */
if (substr(getAlbumTitle(), 0, 1) == "_" && empty($newwws_password)) $newwws_password = "zen";
/* Check if this is a private album and ask for a password */
$newwws_passwordfile = $themepath . "/" . $theme . "/" . "newwws_password.php";
if (empty($newwws_password)){
$newwws_askforpassword = false;
} else {
$newwws_askforpassword = true;
}
$newwws_password_soll = $newwws_password;
$newwws_password_ist = $_POST['newwws_pw'];
if($_COOKIE["newwws_".strtolower(str_replace(" ", "_", getAlbumTitle()))] == "OK") $newwws_password_ist = $newwws_password_soll;
if ($newwws_password_ist == $newwws_password_soll) {
$newwws_askforpassword = false;
setcookie ("newwws_".strtolower(str_replace(" ", "_", getAlbumTitle())),"OK",time()+1800, "/");
}
?>
`
SECOND...
Place this code in a new PHP-file called newwws_password.php in the same folder as album.php
`
">
`
THIRD...
Look in album.php for the line with the code for the thumbnails and replace it with this code. I've placed that code in a new php-file. With an include I can add that php-file to album.php:
`
<?php <br />
if ($newwws_askforpassword){
include("$newwws_passwordfile");
} else {
/* place the original thumbs generating code here */
/* or include another php-file with the thumbs-code */
include("$newwws_thumbs_php");
}
?>
`
FOURTH...
Enhance this - I'm not a programmer
I hope this helps.
Groeten, Miriam
Thanks! Maybe those who had the request out there for this can give it a try and see how it works for them. Meantime, as I get a chance I'll post it to the wiki.
password is defaulted to "zen".
i'll put this up on the wiki for reference.
Based on what I see in the code: yes.
Might be able to be tweaked a little, but I think that's what Miriam meant by Item #4: "Enhance this - I'm not a programmer"
@miriam. Is the newwws-theme that you use publicly available. You say that, "I work with a theme that uses a configuration file for each album." Maybe that enables you to set a unique password for each album. If so, please do add the theme to @thinkdreams growing collection of ZP themes. Thanks again and incidentally, you have a wonderful site.
Thanks much for your insight! As soon as I am able I am going to test this out and will let you know how it goes.
Will be interesting to see if I can get this to work along with Zenpress plugin to link photo in a post to an album.
No, but you'll have to find yourself a way to set the variable $newwws_password to a unique value for every album. If $newwws_password is not empty, the user will be asked to enter the password stored in $newwws_password.
I adapted the code a bit so a default password will be asked for every album with a name that starts with an underscore.
The newwws theme is highly configurable. Without a configuration file it will show 18 thumbnails in 3 rows of 6 thumbnails and on a default background. With the configuration file you can change the number of thumbnails on each row, let's say 6-4-2 or 5-4-3. It's also possible to use a different background for every page in an album and by selecting another css and/or another script it is possible to change the way the thumbnails look.
Despite it is easy to work with the configuration files, it is also possible to work without. In that case the theme will use the default settings.
The newwws theme is far from ready and it will take some time before I will make it available to other people.
Groeten, Miriam
I can't promise that it will be future compatible, but I will try my best to abstract as much of the code as possible which should help to make it compatible for future versions.
As soon as I have it done (I am working on it for a customer), I will share it here.
Just wanted to give everyone a heads up.
1. I assume you will allow different passwords for diferent albums.
2. You may also want to consider allowing more than one password per album. Here is why. Supposing you want to show off a client album to another party. You can give them password access to the same client album (presumably with permission of your client) but only for a week. At the end of the week you disable the second password but your client's original password remains unchanged.
3. Best to store the passwords in a separate DB table so that if Tristan updates the usual DB tables your table will remain unaffected.
4. You must already have thought of this but obviously avoid changing the core Zenphoto files as far as possible. Better to add files to /zen and if necessary to add lines to existing files than to replace existing code within files. That is another way to keep it compatible with future versions.
I tried to do from my cpanel but I cant do just the admin.php file.
If someone knows please advise. Can this be done with htaccess?
Thanks
My key goal was to create an album password protection mechanism that works with zenphoto without altering the core code, in fact I didn't want to touch the database either. The reason for this was to help prevent future releases from breaking functionality.
What I have accomplished so far:
All passwords for albums (those that are protected) are stored in a yaml file (you can read more about it here: http://www.yaml.org). This file contains the album->foldername and the password for that album. If the album->foldername is not located in the yaml file that album is not protected. Editing of the yaml file is done through an extension to the admin section. When editing an album, one new line of code is added there (again wanted minimal data changes for the core code) that when clicked will take you to a new_file that adds that album->foldername to the yaml file and allows you to type in a password for it. Or if there was already a password, allows you to change or delete it. My customer is currently testing it out for me and will let me know if there are any first round bugs in it. I am also cleaning the code a bit more so I can package it up easier.
Just wanted to send out an update on the progress.
Also, many thanks to miriam for the initial code posted, it helped give me the idea for not integrating it totally into zenphoto, but instead abstract much of it. Also, I ripped the login form from the example, I hate typing mundane HTML code out.
This add for Zenphoto looks great, I've read the "Password Protected Albums" article on ZenphotoHacks page but i don't understand where i must paste the source code on step third...
I'm using the steril theme , this is what my album.php looks like, can someone helps me ?
Thanks in advance !
<?php
#========================[Private album]===========================
/* $newwws_password is set in the album specific configuration file, but */
/* if the name of an album starts starts with an underscore, we consider it to be */
/* a private album too. The default-password will be zen */
if (substr(getAlbumTitle(), 0, 1) == "_" && empty($newwws_password)) $newwws_password = "zen";
/* Check if this is a private album and ask for a password */
$newwws_passwordfile = $themepath . "/" . $theme . "/" . "newwws_password.php";
if (empty($newwws_password)){
$newwws_askforpassword = false;
} else {
$newwws_askforpassword = true;
}
$newwws_password_soll = $newwws_password;
$newwws_password_ist = $_POST['newwws_pw'];
if($_COOKIE["newwws_".strtolower(str_replace(" ", "_", getAlbumTitle()))] == "OK") $newwws_password_ist = $newwws_password_soll;
if ($newwws_password_ist == $newwws_password_soll) {
$newwws_askforpassword = false;
setcookie ("newwws_".strtolower(str_replace(" ", "_", getAlbumTitle())),"OK",time()+1800, "/");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php printGalleryTitle(); ?> | <?=getAlbumTitle();?></title>
<link rel="stylesheet" href="<?= $_zp_themeroot ?>/zen.css" type="text/css" />
<?php zenJavascript(); ?>
</head>
<body>
<div id="main">
<div id="gallerytitle">
<h2><span>" title="Gallery Index"><?=getGalleryTitle();?> | <?php printParentBreadcrumb(); ?></span> <?php printAlbumTitle(true);?></h2>
<?php echo getGalleryDescription(); ?>
</div>
<div id="padbox">
<div class="albumdesc2"><?php printAlbumDesc(true); ?></div>
<div id="albums">
<?php while (next_album()): ?>
<div class="album">
<div class="imagethumb">
" title="View album: <?=getAlbumTitle();?>"><?php printAlbumThumbImage(getAlbumTitle()); ?>
</div>
<div class="albumdesc">
<small><? printAlbumDate("Date Taken: "); ?></small>
<h3>" title="View album: <?=getAlbumTitle();?>"><?php printAlbumTitle(); ?></h3> <?php printAlbumDesc(); ?>
</div>
<p style="clear: both; ">
</div>
<?php endwhile; ?>
</div>
<div id="images">
<?php while (next_image()): ?>
<div class="image">
<div class="imagethumb">" title="<?=getImageTitle();?>"><?php printImageThumb(getImageTitle()); ?></div>
</div>
<?php endwhile; ?>
</div>
<?php printPageListWithNav("« précédent", "suivant »"); ?>
</div>
</div>
<div id="credit"><?php printAdminLink('Admin', '', ' | '); ?>Propulsé par ZenPhoto - Edition VirusPhoto</div>
</body>
</html>
Adding a password input alongside the album at creation isn't hard, but storing and calling the data is what I can't figure out.
Edit: OK, I'm definitely not smart enough for this. Is anyone else willing to develop this? I'll donate money for this functionality - I just need it soon.
<?php if (!defined('WEBPATH')) die(); ?>
<?php
#========================[Private album]===========================
/* $newwws_password is set in the album specific configuration file, but */
/* if the name of an album starts starts with an underscore, we consider it to be */
/* a private album too. The default-password will be zen */
if (substr(getAlbumTitle(), 0, 1) == "_" && empty($newwws_password)) $newwws_password = "zen";
/* Check if this is a private album and ask for a password */
$newwws_passwordfile = $themepath . "/" . $theme . "/" . "newwws_password.php";
if (empty($newwws_password)){
$newwws_askforpassword = false;
} else {
$newwws_askforpassword = true;
}
$newwws_password_soll = $newwws_password;
$newwws_password_ist = $_POST['newwws_pw'];
if($_COOKIE["newwws_".strtolower(str_replace(" ", "_", getAlbumTitle()))] == "OK") $newwws_password_ist = $newwws_password_soll;
if ($newwws_password_ist == $newwws_password_soll) {
$newwws_askforpassword = false;
setcookie ("newwws_".strtolower(str_replace(" ", "_", getAlbumTitle())),"OK",time()+1800, "/");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php printGalleryTitle(); ?> | <?php echo getAlbumTitle();?></title>
<link rel="stylesheet" href="<?php echo $_zp_themeroot ?>/zen.css" type="text/css" />
<?php zenJavascript(); ?>
</head>
<body>
<div id="main">
<div id="gallerytitle">
<h2><span>" title="Gallery Index"><?php echo getGalleryTitle();?> | </span> <?php printAlbumTitle(true);?></h2>
</div>
<?php printAlbumDesc(true); ?>
<div id="images">
<?php while (next_image()): ?>
<div class="image">
<div class="imagethumb">" title="<?php echo getImageTitle();?>"><?php printImageThumb(getImageTitle()); ?></div>
</div>
<?php endwhile; ?>
</div>
<?php printPageListWithNav("« prev", "next »"); ?>
<div id="enableSorting">
<?php printSortableAlbumLink('Click to sort album', 'Manual sorting', NULL, 'sort'); ?>
</div>
</div>
<div id="credit"><?php printAdminLink('Admin', '', ' | '); ?>Powered by zenphoto</div>
</body>
</html>
I have it working on my gallery at http://www.thinkdreams.com/devzen. Make sure you name all the galleries you want to password protect with underscores `_`. The code you need to add (which may look different in whatever theme you use) is (and this is based on default theme):
`<?php<br />
if ($newwws_askforpassword){
include("$newwws_passwordfile");
} else { ?>
<?php while (next_image()): ?>
<?php endwhile; ?>
<?php } ?>`
What I did was add in the lines miriam mentioned:
`<?php<br />
if ($newwws_askforpassword){
include("$newwws_passwordfile");
} else {
/* place the original thumbs generating code here */
/* or include another php-file with the thumbs-code */
include("$newwws_thumbs_php");
}
?>`
right above the lines in the default theme that look like:
`
<?php while (next_image()): ?>
<?php endwhile; ?>
which generate the thumbnails you see in the album display page. Then just cut n paste the thumbnail code into the "miriam" code shown above (making sure to use proper php script start and end statements (`<?php` and `?>`). Once that's done, it should work fine.
Hopefully that will get you started on the right path.
`$newwws_password = "zen";`
at or around line 6 in the album.php.
And if anyone looks at my gallery, the password is bob, not zen. I was experimenting. I chose "bob". Don't know why.