Post Subject: The PHP thread
Posted on: Jan 11, 2008
ok I have a friend who wants me to help him setup a website and he has a template he wants to use and since I don't want to be stuck having him continually asking me either how to update the html or asking me to do it for him I was wondering if I could get some help in making a couple php lines to add into the template.
The first thing is theres a recent works section for images and I was wondering if there would be a way to add a php script into that section to scan a specific forum database table for different image file extensions and pull them to the from page when a new one is added....via image link or uploaded. *oh yea and it would have to be able to thumbnail them to so it doesn't take up a ton of room*
The second I need is a script that would be able to do basically the same as the image script only difference is instead of pulling up images I would need it to be able to basically do what fusionmods does for propagating the news and reviews to the front page from posts on the forum news section, preferably without having to mod the forum software, so like basically just by pulling the data straight from the database if possible. My Site: http://www.bcmodding.net
My Laptop's Spec's:
Core i5 2410m 2.3Ghz
6GB DDR3 Ram
Nvidia GT 525m 1GB video card
500GB Sata HD
16x DVD-RW +/- drive
17.3 inch 900p LED Screen
The first part may be a bit tricky depending on exactly how everything is setup. Making the connection (as long as it's on your server) isn't a big deal at all, but if you're looking to parse images from the thread thats where it gets tricky because you'll need to use a regular expression to remove each image from the thread. If you set up your own image database i would reccomend storing all the images in a common directory and storing the file names along with any additional info with them in the table, that way you could grab the most recent along with the extra info. The most simplistic way of doing things would be to just upload them to a directory and grab the files that have the .jpg and gif extensions and display them, though you loose any additional information you might want to display along with them such as image descriptions, but this last method does not require a database.
Now when you say display a thumb does you want to resize the actual image thus lowering the image size? or do you jsut meen display an 800x600 image at a 100x75 size? the second is easy, to do the image resizing, you'll want to research the gd library a little. it isn't to difficult if you have a decent grasp on programming.
---------------------------------------------
For the second part thats relativly simple and you have a few options. The way I do it here is I added a button (visible to those with the user levels) to promote threads to news. ultimatly you'll want to reuse some of the forum code but i'll get to that part in a minute. The button calls a script and sends the threadId as a parameter. The script queries the database for that thread ID and copies it into a news table. Since this has been an evolutionary process and the news is a seperate functional part from the forum, if you wanted to have all your news always posted in the forum you could instead just add a table that stores a threadID and the news would grab those threads, but that would require that every news posting be posted in the forums, where as here that isn't required. The advantage is that it won't fill your database as fast.
Now the part where you'll wanna use some of the forum scripting. All forums use bbc (bulletin board code), and a variety of other string parsing functions. This is why you can type a link and have it display as a link without the link tags on here. The way you'll want to set that up to work is, once you query the news information, you'll want to run it through the string parsing thread. this will convert your thread from bbc to html and do a little error checking. Once it returns the string, you can easily just print it out to the screen.
Now I know that might have been a bit technical without giving any actual php but the best things to do is really plan your code before even starting to write it, otherwise you'll usually end up regreting it later on. If you have any questions on how to write it, shoot me an email and if you don't have my email (can't remember for sure, lol), just pm or im me and i'll help you on the exact coding aspect. I'm not to big on giving out copies of the site's code just because of the time invested in it, and potential security factors, but in this case it wouldn't do much good anyways. This site is sooo integrated that it would be difficult to isolate such small portions of the site. Everything in here has been coded with a very object oriented approach so a lot of the code has multiple uses. But like I said, hit me up and I can give yo a hand on the actual coding aspect of it.
If con is the opposite of pro, is Congress the opposite of progress?
it is all such a headache o.O might just be faster for me to modify an existing template for something like wordpress to look like the template he's using. lol but yea for the images I want them to be like the 100x17 from the original size and link to a larger image when clicked.
if your just parsing from a thread it'd be somewhat ineffecient then to do that. you'll need to parse the thread (maybe tag each thread that you've parsed already so you don't repeat the parsings), then once you find an image, rebuild it in a lower image size, then store the link to the origional as well as the thumb nail. it's run somewhat slow just because rebuilding an image is probably one of the more time consuming processes that php has to offer, atleast that i've come across so far.
If con is the opposite of pro, is Congress the opposite of progress?
well I can hack away at php to make minor modifications but the site isn't mine it's a friends and well with what it would take to setup the necessary php code I may as well just remake a template for something like wordpress cause then all I have to do is mess around with the alignments more or less, as for the naming of the topic meh it works, its' not like the topic is limited to just my question I figure rather then a ton of threads being created to ask a repeated question any questions asked in here and answered may give insight and create less clutter in the database. *I know the tactic never seems to work but meh*