Member
Member
BertSimons   2008-01-29, 22:58
#1

I have some 'unique' tags, e.g there is only one instance of such a tag.
using printAllTagsAs() clicking such a tag first takes you to the search php from where only, since it is unique, one image or album shows up.
what I wanted is for these 'unique' tags to go straight to the image or album page.

I kind of hustled together something that works for albums with a 'unique' tag.

in the function printAlltagsAs() I added an if condition for the '$val', so if a tag occures only once a different link is printed, one straight to the album or image;

`

if ($val==1){

$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";

$album = mysql_query($sql);

$a = mysql_fetch_array($album);

$path=rewrite_path("/index.php?album=" . urlencode($a[2]));

echo "t".$key."n";

}else{

    $key = str_replace('"', '', $key);

    echo "t".

    $key.$counter."n";

}

`

this works well for albums with only one unique tag, you can see it at www.bertsimons.nl e.g the tags 18+ or wishlist take you straight to these albums
unfortunatly my sql query knowledge is not enough to write a query that also queries the images and returns their location if the single tag matches the key.

any suggestions?

Member
Member
sbillard   2008-01-30, 00:42
#2

The SQL is almost identical, just substitute "images" for "albums". So, your code would look something like:

`if ($val==1){

$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";

$album = mysql_query($sql);

if ($album) {

$a = mysql_fetch_array($album);

$path=rewrite_path("/index.php?album=" . urlencode($a[2]));

echo "t".$key."n";

} else {

$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";

$image = mysql_query($sql);

}

}else{

$key = str_replace('"', '', $key);

echo "t".

$key.$counter."n";

}`

Member
Member
BertSimons   2008-01-30, 02:03
#3

pff took me another hour.. your :-)

but is is working.. see the tag unique on my site..

code used to get the image link was this `{

$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";

$image = mysql_query($sql);

$i = mysql_fetch_array($image);

$albumid = $i[1];

$image = $i[2];

$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$albumid."%'";

$album = mysql_query($sql);

$album = mysql_fetch_array($album);

$album = $album[2];

$path=rewrite_path("/index.php?album=" . $album ."&image=".$image);

echo "t".$key."n";

}`

thanks!

Member
Member
sbillard   2008-01-30, 02:54
#4

What happens if the image is password protected or invisible? If that all works this might be a good feature option to add to the core.

Administrator
Administrator
acrylian   2008-01-30, 10:12
#5

Protected albums and not published images probably won't work with these queries. Both queries would need a "AND show = 1" (show in backticks of course!). And the checkAlbumPassword()-loop we use in the rss would need to be included in the second query, too, I guess.

BertSimons: I also suggest that you use the db functions we have, would save you a few lines of code...:-)
That would look like $i = query_full_array("SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'") for the first query.

Member
Member
BertSimons   2008-01-30, 10:13
#6

unique tags from invisible albums or image didn't shoiw up in the taglist. uniique tags from password protected albums showed up but pointed to the password form so that's ok too. however unique tagged images in password protected albums did show up.

so had to add something. code is now
`if(!$links) {

    echo "t".$key.$counter."n";

  } else {

if ($val==1){

$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";

$album = mysql_query($sql);

$a = mysql_fetch_array($album);

if (!empty($a)) { $path=rewrite_path("/index.php?album=" . urlencode($a[2]));

echo "t".$key."n";

}else{

$sql="SELECT * FROM ". prefix("images") ." WHERE tags LIKE '%".$key."%'";

$image = mysql_query($sql);

$i = mysql_fetch_array($image);

$albumidimage = $i[1];

$image = $i[2];

$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$albumidimage."%'";

$album = mysql_query($sql);

$album = mysql_fetch_array($album);

$albumpath = $album[2];

$passwordcheck=$album[18];

if (empty($passwordcheck)){

$path=rewrite_path("/index.php?album=" . $albumpath ."&image=".$image);

echo "t".$key."n";

}

}

}else{

    $key = str_replace('"', '', $key);

    echo "t".

    $key.$counter."n";

}

  }

}

} // while end

echo "n";

}`

so it works with me here, second opinion testing required off course.

I guess getting the fields from the query table with $album[18] etc is not so nice when table fields are going to be added and the nuber changes

Administrator
Administrator
acrylian   2008-01-30, 10:38
#7

I haven't tested you code. But please note that the password field in the albums table only protects that album, not the sub albums of that album. We have a function for this called checkAlbumPassword() that does that: http://www.zenphoto.org/documentation/zenphoto/_functions.php.html#functioncheckAlbumPassword

You could take a look at the rss feed of the nightly where this is used.

Member
Member
BertSimons   2008-01-30, 12:11
#8

yes you are right..code only checks to see if album in which unique tagged image is found is password protected and not checks wheter it's album's parentalbum(s) is protected..
i'll look into that later this week

Member
Member
sbillard   2008-01-30, 17:58
#9

I think the main problem is that something with a "unique" tag in the search may not actually be unique if there is another image/album that has the tag but is protected/invisible.

Somehow what is needed is to use the zenphoto search again for the unique tag.

Member
Member
BertSimons   2008-01-30, 23:35
#10

I am very busy right now with a not behind my pc deadline project so can't look into that right away but this weekend ill do some math..

perhaps it's to do like this

$val now is calculated by getAlltags which is defined in the templates function only to select those WHERE show = 1

so a new function getAllTagsEvenThoseWhoAreHidden() could return the number of a certain tag including hidden and protected images.
then in the PrintTagsAs() function the number could be reduced by 1 if an image or album with this tage is set as not shown and also be reduced by one if the image has a password.
If this results in a number of 1 the tag can be considered as a unique tag to up show in the taglist, and then depending on if it's in a parent album which is protected or set to invisble be shown or not.

Member
Member
sbillard   2008-01-31, 01:46
#11

I was thinking more on the lines:

`if ($val=1) {

$search = new SearchEngine();

$search->words = $uniqueTag;

$search->fields = SEARCH_TAG;

$search->dates = '';

$uniqueAlbum = $search->getAlbums();

if (count($uniqueAlbum) > 0) {

} else {

$uniqueImage = $search->getSearchImages();

if (count($uniqueImage) > 0) {

} else {

}`

This way the search engine will be using the same queries/password protection as the tag query.

Of course the stuff within the `` is left to the 'student' as the professor likes to say.

Member
Member
BertSimons   2008-02-03, 20:38
#12

basically got it working.

before printing the unique tag link i checked in a while loop if one of the unique tagged image's or album's parent albums is flagged as protected or invisible and if so not to print it's link.

`

...................

echo "t".$key.$counter."n";

} else {

if ($val==1){

$sql="SELECT * FROM ". prefix("albums") ." WHERE tags LIKE '%".$key."%'";

$album = mysql_query($sql);

$album = mysql_fetch_array($album);

$parentid = $album[1];

$path=rewrite_path("/index.php?album=" . urlencode($album[2]));

if (!empty($album)) {

$check=0;

while (!empty($parentid)) {

$sql = "SELECT * FROM ". prefix("albums") ." WHERE id LIKE '%".$parentid."%'";

$album = mysql_query($sql);

$album = mysql_fetch_array($album);

$parentid = $album[1];

if ($album[7] == 0){$check=$check+1;}

if (!empty($album[18])){$check=$check+1;}

}

if ($check

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.