grabbing last uploaded from a favourites folder (or whatever works) grabbing last uploaded from a favourites folder (or whatever works)
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

grabbing last uploaded from a favourites folder (or whatever works)

Started by nickfzx, March 25, 2007, 03:36:20 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

nickfzx

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 :)

vuud

Quote from: 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 :)


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


Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

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 :)

vuud

Quote from: 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 :)


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???
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

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.

vuud

Quote from: 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.


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


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.







Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

see post below...

nickfzx

this is the code that handles grabbing the fav picks from the database...copied from init.inc.php:

// 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:

$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:

QuoteExample 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.

vuud

Quote from: 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:

// 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:

$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:


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






Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

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:
<?php
$str 
'YTozNDp7aTowO2k6ODI5O2k6MTtpOjg0ODtpOjI7aTo4NDU7aTozO2k6ODQ5O2k6NDtpOjMyOTtpOjU7aToxMDYwO2k6NjtpOjEwNzQ7aTo3O2k6MTEyMDtpOjg7aToxMTE5O2k6OTtpOjExMTM7aToxMDtpOjExMDM7aToxMTtpOjEwOTQ7aToxMjtpOjEwOTU7aToxMztpOjExNDg7aToxNDtpOjExNTA7aToxNTtpOjk2NztpOjE2O2k6MTIxNjtpOjE3O2k6MTIzNztpOjE4O2k6NzkzO2k6MTk7aToxMjYzO2k6MjA7aToxMjY0O2k6MjE7aToxMjYxO2k6MjI7aToxMjU0O2k6MjM7aToxMzMyO2k6MjQ7aToxNDg5O2k6MjU7aToxNTc5O2k6MjY7aToxNTc4O2k6Mjc7aToxNTU2O2k6Mjg7aToxNTY2O2k6Mjk7aToxNTUxO2k6MzA7aToxNjY2O2k6MzE7aToxNzM0O2k6MzI7aToxODk4O2k6MzM7aToxOTczO30=';
echo 
print_r(unserialize(base64_decode($str)));
?>


this was the output:
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?

vuud

Quote
this was the output:
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


Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

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.

vuud

Quote from: 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.

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

Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

last added to favorites is perfect...don't worry about last uploaded from favorites, is a little pointless if you can do last added.

vuud

Quote from: 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.

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

:D
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

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 :)

nickfzx

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.

nickfzx

any luck on this yet? Let me know if you need some help or someone to test it out.  :)

vuud

Quote from: 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.  :)

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
Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

nickfzx

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