Firefox PHP

Picture in Profile 1.0

Posted by pat 
All files from this thread

File Name File Size   Posted by Date  
PinP10_hacked-files.zip 11.9 KB open | download pat 07/07/2004 Read message
picProcessor.php 4.9 KB open | download pat 07/09/2004 Read message
picProcessor.php 5.1 KB open | download pat 07/09/2004 Read message
pat
Picture in Profile 1.0
July 03, 2004 09:40PM
Hi,

This Code-Hack allows users to choose a picture that is shown in their profile. User has to upload picture to his/her "My Files" section and then is able to select it for display in his/her profile in by choosing it in "Edit My Profile"

Good News first: as of this version all of the following requirements are met:
-User can choose from a list of pictures(and only pictures are presented as of now) taken from the already uploaded files from "My Files".
-You as admin can set the output size of the image and it will be resized and/or cropped to meet requirements .
-The resized and/or cropped picture will be cached.
-You dont have to change a whole lot of the core-code, as I do all the Image manipulation in a separate file called picProcessor.php

(See the source-code of picProcessor.php for more details on settings.)

Now the bad news:
An installed GD-Library is required on the server you run this Hack, if you want the image-manipulation abilities.
The way I do the resizing is fairly good in quality (In fact it's excellent in my opinion ;-) but it will make the server beg for mercy. So You might/might not (I have no experience with it yet) run into some challenges if you are running it on a server with shared webspace and millions of users wanting to change/set their picture all at the same time .
But don't worry all that could happen is, that the web-hoster kicks you out and sends some monkey-faces to smash your car ;-?

On the other Hand the resized images are cached in "my_pic"-folder so the server-load shouldn't be that heavy once the user has choosen his/her picture and hopfully doesn't change it every other day. Speeking of caching, I had to do it the normal way of storing files in folder not in db (but I would like to do it the Phorum way with a later Version), so you'll have to take care to chmod "picProcessor.php" executable and the folder "cache/my_pic/" writable, the latter only if not permitted by script due to server config.

Let's do the hacking:

First of all Put "picProcessor.php" into the main Phorum folder, than go to admin "Users/Groups"->"Custom Profiles" and add the Field Name "my_pic".


After that, these files need to be modified:

1. phorum5\include\controlcenter\user.php

2. phorum5\profile.php

3. phorum5\include\lang\your-langfile.php

4. phorum5\templates\your-template\cc_usersettings.tpl

5. phorum5\templates\your-template\cc_start.tpl
& phorum5\templates\your-template\profile.tpl




@1. add:

// generate users-pic_file-list for pic in profile...
$picFiles = phorum_db_get_user_file_list($PHORUM["user"]["user_id"]);

$picTypes = "gif,jpeg,jpg,png";
$picAllowed_exts=explode(",", $picTypes);

if(!empty($picFiles)){
foreach($picFiles as $key => $file)
{
$picExt=strtolower(substr($picFiles[$key]["filename"], strrpos($picFiles[$key]["filename"], ".")+1));
if(in_array($picExt, $picAllowed_exts))
{
$picFiles[$key]["url"]=phorum_get_url(PHORUM_FILE_URL, "file=$key");
}
else
{
unset($picFiles[$key]);
}
}
}

//...and put it into array
$PHORUM["DATA"]["FILES"] = $picFiles;


@2. add:
// generate users-file-list for pic in profile...
$files = phorum_db_get_user_file_list($PHORUM["user"]["user_id"]);
foreach($files as $key => $file) {
$files[$key]["url"]=phorum_get_url(PHORUM_FILE_URL, "file=$key");
}
//...and put it into array
$PHORUM["DATA"]["FILES"] = $files;




@3. add:

"MyPic" => "My Picture",
"NoPic" => "-No Picture-",



@4. add:
<tr>
<td nowrap="nowrap">{LANG->MyPic}:&nbsp;</td>
<td><select name="my_pic">
{LOOP FILES}
<option value="{FILES->url}">{FILES->filename}</option>
{/LOOP FILES}
<option value="">{LANG->NoPic}</option>
</select>
</td>
</tr>


@5. add: (Put your desired measurements here -line3- for newX and newY or leave it out and put it in picProcessor.php)

{if PROFILE->my_pic}
<tr><td align="right" colspan="2"><img src="picProcessor.php?filename={PROFILE->my_pic}&newX=400&newY=300" alt="{LANG->MyPic}"></td></tr>
<tr><td align="right" colspan="2"><i>{LANG->MyPic}</i></td></tr>
<tr><td>&nbsp;</td></tr>
{/if}


Still to do:
-Find a way to delete cached pics when user alters it's choice. As of now you have to delete all the files in "cache/my_pics/" every once in a while or wait until you run out of diskspace... ;-)

-Next Step for me will be to try and make most of the Stuff a module. But I've never made a module before so I don't know what can- and how it is done, but i'll try.


To the Avartar-People:
Please put your modifikations here, so that we have all in one place. Note that picProcessor.php is able to crop an image with minimal loss to fit a given size: 80x80 Pixel for example.

If someone finds out Improvement of any kind, let me know.

pat



Please make sure
-after your template-modifications
delete the "old" template-files in phorum-cache-directory.

-Download picProcessor.php v1.0a




Edited 17 time(s). Last edit at 09/20/2005 09:27PM by pat.
Re: Picture in Profile 1.0
July 04, 2004 07:36PM
3rd filename should probably be without controlcenter

2nd ... why do you do that stuff there?


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
pat
Re: Picture in Profile 1.0
July 04, 2004 08:37PM
Hi Thomas,

> 3rd filename should probably be without controlcenter
Absolutely right, I've corrected that, thanx ...

> 2nd ... why do you do that stuff there?
I could have stored the complete url in "my_pic" but decided to generate a fresh file list just in case something with the urls is changed during beta...

pat




Edited 1 time(s). Last edit at 07/04/2004 11:06PM by pat.
Re: Picture in Profile 1.0
July 06, 2004 10:02AM
Hi Pat,

thank you for your work, this addition rocks.
Nevertheless, I still have a problem.
I've changed everything according to your description and also added picProcessor.php to the phorum main folder. After uploading a pic into a user profile and selecting it, the output doesn't display the pic. The source generated looks like this:
<!-- user picture -->
<tr><td align="right" colspan="2"><img src="picProcessor.php?filename=http://localhost/phorum/file.php?0,file=3&newX=80&newY=100" alt="Mein Bild"></td></tr>
<tr><td align="right" colspan="2"><i>Mein Bild</i></td></tr>
<tr><td>&nbsp;</td></tr>
<!-- end user picture -->

The second problem is really weird: The possibility to upload a file in the user profile is available only for the admin, but not for "normal" users.

Do you have any suggestions what I've probably done wrong?

Edit: I just found out, that only admins have the upload feature available inn their profile... ??

Regards,
#ayshe



Edited 1 time(s). Last edit at 07/06/2004 10:28AM by #ayshe.
Re: Picture in Profile 1.0
July 06, 2004 12:22PM
> Edit: I just found out, that only admins have the upload feature available inn their profile... ??

you just need to enable it through the admin.


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: Picture in Profile 1.0
July 06, 2004 04:01PM
@ thomas: thank you, you were right. You know the phrase "Man sieht den Wald vor lauter Bäumen nicht"...

@ pat: Still, the pictures are not shown in the profile after a picture is chosen. What might be the reason?

Regards,
#ayshe


*******************
[www.rot65.de]
*******************
Re: Picture in Profile 1.0
July 06, 2004 04:07PM
I guess you get a broken image-icon with the url above?
try to open that image and check for errors.


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: Picture in Profile 1.0
July 06, 2004 04:34PM
Hi Thomas,

the image URL is generated by the pic processor (if I understood Pat's code right), thus the code for pic is as posted above:
<img src="picProcessor.php?filename=http://localhost/phorum/file.php?0,file=3&newX=80&newY=100" alt="Mein Bild">

I assume, that there is a little mistake in the picprocessor - or I have to change something in it's code that Pat didn't mention yet.

Regards,
#ayshe


*******************
[www.rot65.de]
*******************
Re: Picture in Profile 1.0
July 06, 2004 04:38PM
like I told before, it shows probably a broken image in your browser, try to open this to see possible error-messages.


Thomas Seifert
Phorum Development Team / Mysnip-Solutions.de
Custom Phorum and general software development
worry-free Phorum Hosting
Re: Picture in Profile 1.0
July 06, 2004 04:50PM
Hi,

well, I can't open the picture. IE displays a 'missing picture' image (the one with the red cross in it), Mozialla just displays the 'alt' text. Context menu in IE on the picture -> 'show picture' -> nothing happens.
The only information I can achieve is the img tag as quotet before.

Regards,
#ayshe


*******************
[www.rot65.de]
*******************
Sorry, only registered users may post in this forum.

Click here to login