forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 cpmFetch by vuud => Topic started by: nickfzx on March 25, 2007, 03:36:20 am

Title: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 25, 2007, 03:36:20 am
so this is my setup:  Coppermine 1.4.10 (older version of cpmfetch but will update soon to 1.9/2.0).  there are no public galleries only member galleries and there are over 1000 of these.

I would like to be able to select certain images to be shown via cpmfetch as they are uploaded, this way people can upload lot's of work but only the good stuff gets shown on my homepage.

But there are lot's of uploads to different member galleries each day so manually changing the cpmfetch object everyday is not an option.

What would be cool is if I could add images to my Favourites when I see one that I want to be shown on the homepage and then cpmfetch just grabs the 8 most recent additions from my favourites.

Now I am not sure if this is possible with the favorites folder but it is this sort of functionality I want...I don't really care how it's done.  As long as it is only the admins who can choose what gets shown via cpmfetch.

Help with this will have my heartfelt thanks :)
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 25, 2007, 03:54:42 am
so this is my setup:  Coppermine 1.4.10 (older version of cpmfetch but will update soon to 1.9/2.0).  there are no public galleries only member galleries and there are over 1000 of these.

I would like to be able to select certain images to be shown via cpmfetch as they are uploaded, this way people can upload lot's of work but only the good stuff gets shown on my homepage.

But there are lot's of uploads to different member galleries each day so manually changing the cpmfetch object everyday is not an option.

What would be cool is if I could add images to my Favourites when I see one that I want to be shown on the homepage and then cpmfetch just grabs the 8 most recent additions from my favourites.

Now I am not sure if this is possible with the favorites folder but it is this sort of functionality I want...I don't really care how it's done.  As long as it is only the admins who can choose what gets shown via cpmfetch.

Help with this will have my heartfelt thanks :)


There is a favorites folder?

Okay, let me mull this over.  I will probably add in something for favorites though - if its like I think that would be cool.

I'll think about this a bit...


Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 25, 2007, 04:20:22 am
yeah sorry it isn't a favorites "folder"...i'm not really sure what it is...some sort of private collection of images from anywhere in coppermine, i haven't looked at the code for it.

Thanks for your help...I will be interested in seeing what you come up with.

I was thinking about trying to code this --> when cpmfetch calls the images it could do a check to see if the image has been okayed for cpmfetch by an admin.  So maybe during approval when I'm going through the images and approving them I could click a check-box that reads "allow cpmfetch to display this" and then when cpmfetch grabs all the latest uploads it could filter out the none checked ones.

that might be a bit complicated for me (although I have started reading PHP & MYSQL by larry ullman, a whole 700 pages of fun :) ) so maybe I'll get better at coding php but in the meantime I look forward to hearing your thoughts on this.

Cheers :)
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 25, 2007, 06:48:38 am
yeah sorry it isn't a favorites "folder"...i'm not really sure what it is...some sort of private collection of images from anywhere in coppermine, i haven't looked at the code for it.

Thanks for your help...I will be interested in seeing what you come up with.

I was thinking about trying to code this --> when cpmfetch calls the images it could do a check to see if the image has been okayed for cpmfetch by an admin.  So maybe during approval when I'm going through the images and approving them I could click a check-box that reads "allow cpmfetch to display this" and then when cpmfetch grabs all the latest uploads it could filter out the none checked ones.

that might be a bit complicated for me (although I have started reading PHP & MYSQL by larry ullman, a whole 700 pages of fun :) ) so maybe I'll get better at coding php but in the meantime I look forward to hearing your thoughts on this.

Cheers :)


Well, the favorites sound like it will be easiest.  Usually you don't want to start changing the CPG code

 1) You could break something
 2) Makes upgrades a pain

which

 3) Makes it more likely you would skip a security patch


How do you add something to favorites???
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 25, 2007, 07:02:34 am
yeah i know about not messing with the code but sometimes it can't be helped if you want something specific...what I do is just document any changes I make quite carefully so when I upgrade it is a bit easier knowing all the changes I make.

You add to favorites by opening the image...clicking on file information and "add to favorites" is in there.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 25, 2007, 06:10:14 pm
yeah i know about not messing with the code but sometimes it can't be helped if you want something specific...what I do is just document any changes I make quite carefully so when I upgrade it is a bit easier knowing all the changes I make.

You add to favorites by opening the image...clicking on file information and "add to favorites" is in there.


Thanks,

Well, I took a quick look at it wont be as simple as I thought it would be to use the favorites.  here is what the favorites table looks like inside cpg...

Code: [Select]
mysql> select * from cpg_favpics;
+---------+----------------------+
| user_id | user_favpics         |
+---------+----------------------+
|       1 | YToxOntpOjA7aToyMzt9 |
+---------+----------------------+


So I have to figure out what the second part is there... great fun.







Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 08:47:56 pm
see post below...
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 08:57:21 pm
this is the code that handles grabbing the fav picks from the database...copied from init.inc.php:

Code: [Select]
// If the person is logged in get favs from DB those in the DB have precedence
if (USER_ID > 0){
        $sql = "SELECT user_favpics FROM {$CONFIG['TABLE_FAVPICS']} WHERE user_id = ".USER_ID;
        $results = cpg_db_query($sql);
        $row = mysql_fetch_array($results);
        if (!empty($row['user_favpics'])){
                $FAVPICS = @unserialize(@base64_decode($row['user_favpics']));
        }else{
                $FAVPICS = array();
        }
}

this is clearly the line of interest:

Code: [Select]
$FAVPICS = @unserialize(@base64_decode($row['user_favpics']));
so looked up what it is and it seems that the function for decoding this is built into php.

so here is an example from the php manual:

Quote
Example 2439. base64_decode() example
<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>

The above example will output:

This is an encoded string

this is the url: http://uk2.php.net/base64_decode

efficiency might be an issue here...if evertime someone loads a page with cpmfetch on it has to run the decoder...not sure what the effects on the server would be.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 26, 2007, 09:52:17 pm
this is the code that handles grabbing the fav picks from the database...copied from init.inc.php:

Code: [Select]
// If the person is logged in get favs from DB those in the DB have precedence
if (USER_ID > 0){
        $sql = "SELECT user_favpics FROM {$CONFIG['TABLE_FAVPICS']} WHERE user_id = ".USER_ID;
        $results = cpg_db_query($sql);
        $row = mysql_fetch_array($results);
        if (!empty($row['user_favpics'])){
                $FAVPICS = @unserialize(@base64_decode($row['user_favpics']));
        }else{
                $FAVPICS = array();
        }
}

this is clearly the line of interest:

Code: [Select]
$FAVPICS = @unserialize(@base64_decode($row['user_favpics']));
so looked up what it is and it seems that the function for decoding this is built into php.

so here is an example from the php manual:

this is the url: http://uk2.php.net/base64_decode

efficiency might be an issue here...if evertime someone loads a page with cpmfetch on it has to run the decoder...not sure what the effects on the server would be.

Ahhh, thank you!

<?php
$str = 'YToxOntpOjA7aToyMzt9';
echo print_r(unserialize(base64_decode($str)));
?>

I did this to get a view of what is in there...

I got:

Code: [Select]
Array
(
    [0] => 23
)


I'm have to check, but that seems to be the image pid.  I have remote access to my test stuff, but it would be a pain to get in there now and add in some more.  I will know more later.  I only added one, so I am not sure how it works when you add more.

As for it bogging down the server, I don't *think* it would be an issue in most cases.  The shear number of DB calls a forum, or gallery does to just render a page is massive compared to the typically one call CpmFetch does.   Of course if you are google or something, every cycle and byte saved helps.  I doubt it will be noticeable to a user or the system.

If we get something working, I can benchmark it fully.

I did a run of 100,000 iterations of unseralizing and decoding the base 64 and it took about 1.86 seconds.  If you have 100,000 favorites... well, thats a different story.  And we would only have to deserialize the ones we were going to display (for random anyway).   Either way, its gonna be two sql calls perhaps... 

Hmmm






Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 10:10:49 pm
hey thanks for all your help...

I was just checking out your new cpmfetch for developers site...a really good recourse, thanks for linking my site.

I ran the php with my favorites (i have quite a few in my folder) and can confirm that yep they are the pid 's.

here is what I ran:
Code: [Select]
<?php
$str 
'YTozNDp7aTowO2k6ODI5O2k6MTtpOjg0ODtpOjI7aTo4NDU7aTozO2k6ODQ5O2k6NDtpOjMyOTtpOjU7aToxMDYwO2k6NjtpOjEwNzQ7aTo3O2k6MTEyMDtpOjg7aToxMTE5O2k6OTtpOjExMTM7aToxMDtpOjExMDM7aToxMTtpOjEwOTQ7aToxMjtpOjEwOTU7aToxMztpOjExNDg7aToxNDtpOjExNTA7aToxNTtpOjk2NztpOjE2O2k6MTIxNjtpOjE3O2k6MTIzNztpOjE4O2k6NzkzO2k6MTk7aToxMjYzO2k6MjA7aToxMjY0O2k6MjE7aToxMjYxO2k6MjI7aToxMjU0O2k6MjM7aToxMzMyO2k6MjQ7aToxNDg5O2k6MjU7aToxNTc5O2k6MjY7aToxNTc4O2k6Mjc7aToxNTU2O2k6Mjg7aToxNTY2O2k6Mjk7aToxNTUxO2k6MzA7aToxNjY2O2k6MzE7aToxNzM0O2k6MzI7aToxODk4O2k6MzM7aToxOTczO30=';
echo 
print_r(unserialize(base64_decode($str)));
?>

this was the output:
Code: [Select]
Array ( [0] => 829 [1] => 848 [2] => 845 [3] => 849 [4] => 329 [5] => 1060 [6] => 1074 [7] => 1120 [8] => 1119 [9] => 1113 [10] => 1103 [11] => 1094 [12] => 1095 [13] => 1148 [14] => 1150 [15] => 967 [16] => 1216 [17] => 1237 [18] => 793 [19] => 1263 [20] => 1264 [21] => 1261 [22] => 1254 [23] => 1332 [24] => 1489 [25] => 1579 [26] => 1578 [27] => 1556 [28] => 1566 [29] => 1551 [30] => 1666 [31] => 1734 [32] => 1898 [33] => 1973 ) 1
so they match up fine to the pictures and are in the order that I added them to my favorites...not sure what the trailing '1' is right at the end of the ouput?
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 26, 2007, 10:42:06 pm
Quote
this was the output:
Code: [Select]
Array ( [0] => 829 [1] => 848 [2] => 845 [3] => 849 [4] => 329 [5] => 1060 [6] => 1074 [7] => 1120 [8] => 1119 [9] => 1113 [10] => 1103 [11] => 1094 [12] => 1095 [13] => 1148 [14] => 1150 [15] => 967 [16] => 1216 [17] => 1237 [18] => 793 [19] => 1263 [20] => 1264 [21] => 1261 [22] => 1254 [23] => 1332 [24] => 1489 [25] => 1579 [26] => 1578 [27] => 1556 [28] => 1566 [29] => 1551 [30] => 1666 [31] => 1734 [32] => 1898 [33] => 1973 ) 1
so they match up fine to the pictures and are in the order that I added them to my favorites...not sure what the trailing '1' is right at the end of the ouput?

I think the trailing one is part of the way it stores arrays internally and maybe part of the serializing and such.  Hmmm.

Cool on this... I can probably add in a random from favorites...  Will be two sql calls, but what the heck. 

Thanks for your help in sorting this out - saved me a bunch of legwork.   At least from this point on, its fairly simple :D


Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 10:44:40 pm
Oh could you do a last added to favorites or last uploaded from favorites...I don't think I would use a random from favorites.

Thanks for doing this...really appreciated.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 26, 2007, 11:10:06 pm
Oh could you do a last added to favorites or last uploaded from favorites...I don't think I would use a random from favorites.

Thanks for doing this...really appreciated.

I will probably just do both... once the logic to create the sql call for the pid's is created its not that hard.

I will do the last added to favorites... the last uploaded would be more SQL work to query them all for file creation dates...  I'd have to get all the favorites, then parse them...

Hmmm

Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 11:18:53 pm
last added to favorites is perfect...don't worry about last uploaded from favorites, is a little pointless if you can do last added.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 26, 2007, 11:20:25 pm
last added to favorites is perfect...don't worry about last uploaded from favorites, is a little pointless if you can do last added.

Okay, I may be able to do this later tonight.  Not sure.  Of course anything to keep me from writing documentation is welcome!

 :D
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 11:24:25 pm
haha yeah i can see how documentation writing being a bore, its all about making stuff work not explaining it for hacks like me :)

I'll test it out on my machine once you've got something down...no rush :)
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 26, 2007, 11:27:47 pm
oh just a quick point -- I wrote above that the array is in the order I added them to my favorites...well they are actually in the reverse order...the highest number is the most recently added and number 1 is the first image I ever added.

thought this might help.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 30, 2007, 11:08:54 pm
any luck on this yet? Let me know if you need some help or someone to test it out.  :)
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 31, 2007, 12:37:59 am
any luck on this yet? Let me know if you need some help or someone to test it out.  :)

Sorry, Command and Conquer 3 came out a few days ago.  That and the forces of evil at work seem to be coalescing around my desk.  By the time I get home I want to put a foot through my monitor.

I will try to poke it with a stick tonight
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on March 31, 2007, 12:47:02 am
yeah i had a go on the C&C 3 demo the other day but it diddn't run too good on my comp...i have a crap graphics card.

No rush.  ;D

Nick
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on March 31, 2007, 12:50:49 am
yeah i had a go on the C&C 3 demo the other day but it diddn't run too good on my comp...i have a crap graphics card.

No rush.  ;D

Nick

Damn thing keeps crashing my system.  Well, my wifes since I don't have windows on my systems.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on April 11, 2007, 07:01:39 pm
i read through the cpmfetch 2.0 release page...didn't see this feature there.  Is it still on the books to be done?
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on April 11, 2007, 08:09:11 pm
i read through the cpmfetch 2.0 release page...didn't see this feature there.  Is it still on the books to be done?

Sorry, no its not in there.  Just ran out of time.  I have a list for the first development release and I will make sure it is on there for that.

Sorry for it taking so long.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on April 11, 2007, 08:10:55 pm
np...just checking it was still going to happen as it is really going to make a big difference to me as I am going to start re-doing a lot of the layout of my site.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on April 11, 2007, 08:40:12 pm
np...just checking it was still going to happen as it is really going to make a big difference to me as I am going to start re-doing a lot of the layout of my site.


It's been a terrible terrible few months for me as far as spending quality time with my code.  With garden season coming up, I would say that it is not going to be much better over the next few months.

But I will get this in over the next few things I do...  Really.  If you don't see something in a week, ping me again. 
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on April 11, 2007, 08:42:59 pm
awesome...thanks a lot.  I think you will be impressed with what I do with cpmfetch 2.0 as well...it will be a month or so until the updates are made but I think it's going to look really good.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on April 19, 2007, 02:34:57 am
ping

:)
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on April 19, 2007, 03:09:45 am
ping

:)


You are punctual if anything :D

I actually made some progress...  I got CpmFetch into its new SVN repository (so long CVS) and added two new functions that are being paid for development.  Last night I started spec'ing out a call to get user information which is part 1 of your request (I need to get the favorites).

So believe it or not, its 33% done :)

Really!
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on April 19, 2007, 03:12:51 am
awesome...do you have a paypal donation link?...I feel like I owe you a couple of beers worth of $ at least :)

what are the two paid for features?  Or is that confidential.
Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: vuud on April 19, 2007, 04:16:34 am
awesome...do you have a paypal donation link?...I feel like I owe you a couple of beers worth of $ at least :)

what are the two paid for features?  Or is that confidential.

I do have a paypal account for beer...  I will PM you the address.

The features are not very glorious, but will be in the next release.

One allows you to set css ID's on the various parts of the output table - cool if you want to use CSS / Javascript to mess with them after

The other allows you to grab the resultset as data after you generate a table (good when you want to get the stuff to mess with the CSS / Javascript)

I will post the link when the site goes live.

Vuud


Title: Re: grabbing last uploaded from a favourites folder (or whatever works)
Post by: nickfzx on May 10, 2007, 07:14:36 pm
any luck on this feature yet?  ;D