myspace style site********

Discussion in 'PHP' started by adamjw3, Apr 14, 2007.

  1. #1
    hi , i'm trying to find tutorials that can help me build a myspace style site,
    i think i understand what i need to do.
    1)create a form that collects users details
    2)stores these details on a database and dynamically create a page with a uniquie id (url) so this page can be found on the web
    3)enable people to search the database for people that want to talk to.

    any ideas guy?

    i'm sure i can create the form and store the data on the database.

    how do i dynamically create a page from a template?????

    what i'm after is a couple of tutorials that can show me how to do these thing individually and then i can workout away of putting them together.

    any help or advice would be great

    :)
     
    adamjw3, Apr 14, 2007 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,845
    Likes Received:
    4,543
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Some thoughts from a woman...

    I'd start by getting smarty as your templating system

    And take a look at phpclasses.org or sourceforge.net for secure login and sign up scripts

    Alternatively wander over to BST and buy one ready made. It won't be 100% what you have in your mind, but you'll learn lots customising it.
     
    sarahk, Apr 14, 2007 IP
  3. PresFox

    PresFox Active Member

    Messages:
    218
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Sarahk is right, for about $150 you have scripts that do what you want.

    Ig your serious about creating it yourself, id google tutorials for the things you mentioned above

    devshed is a good start
     
    PresFox, Apr 14, 2007 IP
  4. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Generally speaking I think Smarty has too much overhead but I think in this situation the extra control that Smarty gives would be perfect for this project.

    As for authentication you might want to look at the Auth PEAR package. LiveUser might make it easier to manage different friend groups but last time I checked I found the documentation quite hard to follow.

    If you really want to get the social community feel you might also want to look at importing your memebers contacts from Gmail, MSN, yahoo etc. It just so happens that I have several scripts on my blog to invite messenger contacts

    [edit]You may also want to look at so called 'friendly' urls[/edit]
     
    streety, Apr 14, 2007 IP
  5. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Add a .htaccess files in your public_html and a 404handler.php files anywhere else. Whenever someone requesting a folder if folder exist then ok display it from there otherwise send the request to 404handler.php run a query there and fetch the data from table and then add those data in the request file and then display.
     
    Subikar, Apr 15, 2007 IP
  6. adamjw3

    adamjw3 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hi guys thanks for the advise but i really want to code it myself and not use any third party solutions, just php and mysql.......

    any help in these areas would be fab...this is a php thread??????

    x
     
    adamjw3, Apr 18, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    A "template system" I often write for myself when I'm writing small ( but still customizable script ) consists of just one class, I'll assume you don't know how to oop, and write procedural code here.

    Basically, instead of the newbie include() being used everywhere to stick together pages, I'll take the skin of the site, and I'll strip everything out of the skin that would need to change, like menu items a nav bar, a login box and whatever else, in thier place, I'll write something like {NAV_BAR}.

    Your procedural code so far would resemble this :

    
    <?
    define( "DEF_SKIN", "/location/to/default/skin.html" );
    
    $skin = null;
    
    function load_skin( )
    {
    	global $skin ;
    	
    	$skin = file_get_contents( DEF_SKIN );
    	if( !$skin )
    	{
    		die( "FATAL : Cannot load skin file" );
    	}		
    	return strlen( $skin );
    }
    ?>
    
    PHP:
    You might decide to set the default skin in some other way, with a db or whatever, but for now I defined the skin path, and the first function gets the code from DEF_SKIN into a global var called $skin

    Before you ouptut the skin to a browser, you need to fill in all the things on the page {}, so the next function / method you would call, would use str_replace to search for predefined skin variables and replace them with globally available data, your code should now look like this :

    
    <?
    define( "DEF_SKIN", "/location/to/default/skin.html" );
    
    $skin = null;
    
    function load_skin( )
    {
    	global $skin ;
    	
    	$skin = file_get_contents( DEF_SKIN );
    	if( !$skin )
    	{
    		die( "FATAL : Cannot load skin file" );
    	}		
    	return strlen( $skin );
    }
    function parse_skin( $title, $menu, $content, $meta )
    {
    	global $skin;
    	
    	$template_vars = array
    	(
    		"{PAGE_TITLE}",
    		"{PAGE_MENU}",
    		"{PAGE_CONTENT}",
    		"{PAGE_META}"
    	);
    	
    	$template_vals = array
    	(
    		$title,
    		$menu,
    		$content,
    		$meta
    	);
    	return str_replace( $template_vars, $template_vals, $skin );
    }
    ?>
    
    PHP:
    Now, to use these functions on a page, you would include them, then call, load_skin() make sure it succeeds,and then do the rest of the programming for that page, when you have everything you need like the title and content of the page ( determined by whatever the script is doing ) you can call echo parse_skin( $title, $menu, $content, $meta )

    The code I used there I just wrote, I never tested in and am not sure if it has syntax errors, however if you have some understanding of php and read all the native function(s) I used there you should be able to work out what I'm trying to show you.
     
    krakjoe, Apr 18, 2007 IP
  8. adamjw3

    adamjw3 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks joe that great help....

    is it kind of like .net with the masterpage templates, all the generic stuff in one place and then load the indivdual data into the middle section or where ever....what books would you recommend for php, mysql?
     
    adamjw3, Apr 18, 2007 IP
  9. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #9
    I can't name any like, but I would imagine if you have experience in OO programming you should look towards the professional range of books as even though the terminology is harder to understand you should feel more comfortable writing the code......
     
    krakjoe, Apr 18, 2007 IP
  10. adamjw3

    adamjw3 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    how did you learn krakjoe? any usefull tutorial sites u know of?
     
    adamjw3, Apr 18, 2007 IP
  11. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #11
    I don't remember a time in my life I couldn't program, even as a child I was fascinated with computers and all things technological, by teenage I was fluent in c and phpfi had just been rewritten into c which gave me a project to follow, at the beginning I had aspiration on making my own scripting engine like php, now though I'll just use thiers.
    I do own several books, however none are specific to php or any other language, the closest I have is a book on ZE from about a year ago ( outdated now ), probably not the best person to ask .....

    The best php site without a doubt is php.net, but then you have to be able to understand php to understand the manual, so that's not much help to you.....
     
    krakjoe, Apr 18, 2007 IP
  12. firmaterra

    firmaterra Peon

    Messages:
    756
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #12
    here's what I did for my community site (this could get rather long winded!)

    i used php, ADOdb, smarty, and a mishmash of ajax.
    1. user details - fairly straightforward. one page collects all there details and you store it in your DB. You'll find that some details will need to be replicated on serveral tables for future use. I found this saves time rather than running serveral queries on different tables later on when the user is expecting things to run smoothly (You won't notice this when its just you as user but wait till you have 10k, 15k, 20k users messing about with pictures/videos/flash!)
    2. When the user signs up profile pictures, skins, videos, pictures etc are all marked as null in the DB.
    3. Profile pictures. I have these stored in one place. When a profile picture is uploaded i update several tables with a 'yes' to the profile picture field. That way whenever your looping through comments you don't have to query the main 'profile' table to figure out if each user has a profile picture. Results are assigned to smarty and its quiet easy to loop through them with {if} tags to display either the profile picture or a default one if no picture exists.
    4. Skins - Once you have the process correct about a profile picture (eg to update several tables as affirmative if one exists) doing a skins template is nearly a replicate of the same process. you need a default skin and default skin text colors and of course a field in your table to mark as 'yes' when the user selects a skin. You'll probably want other users to be able to use skins other people created so you'll need an 'author id' field as well so you can give credit where credit is due :p
    4. Videos/pictures - You'll want to do a number of things here. First converting any videos and pictures uploaded to a smaller size. Compress everything or your bandwidth will go through the roof.For examply with videos you'll probably convert mpeg, avi's etc to FLV's. Then you'll need to figure out runtime (I use FLVMDI to inject metadata ). I assign videos to a 'general' folder and picture to an 'individual' folder as generally videos uploaded to my site are for all to browse rather than 'friends' who the user will only want to share pictures with. Then depending on your options (eg is it a private picture? Can anyone view the video?) you'll need to keep track of everything in your DB. Get ready to be confused :)
    5. Forums - I use this terms loosely to describe anywhere users can submit comments, post topics etc. You may have several such as comments on videos, pictures, maybe 'shout boxes', a larger general forum. Its generally easier to keep all video comments in one table, profile comments in another, and so on.
    7. Flash Files - Those little fancy games etc that people like to put up on their flash boxes - treat these the way you do videos. the process is nearly the same :)
    8. MONEY - I insert this with a word of caution. Community sites eat bandwith. Community sites eat servers. Any site with over 100 users and you'll need to have some way of monetizing it. ADsense won't cover you're costs unless you have an extremely loyal fanbase who are deeply committed to their webmasters finances. Trust me on this. You need to have some idea of where revenue will roll in from.
    9 Security - With so many options in communtiy sites and so many forms, fields, uploads etc you're like a swiss cheese my friend. Full of holes that other are only too happy to poke into :p Check everything. before letting any type of files near your root open em up and check. Then check again. then backup :p

    to answer your rather specific question of dynamically creating a page, i found smarty more than made up for the extra overhead with the ease of implementing each users specific skins/picture/flash files etc. Generally you'll have several items stored in your special 'profile page' table. Like if your user has a flash file. do they have videos. pictures? Are they using a skin or the default one?
    you'll assign the result of a query to that table to an array. then using smarty you'll loop through that array in the template file using {if} loops again. So for instance if you're checking if the user has a profile picture:
    //get user details based on their ID. assume the field profile_picture exists
    $Sql = "SELECT * from PROFILE where ID=$_REQUEST ID";
    $rs=$conn->execute($sql);
    $details=$rs->getrows();
    //assign the results to smarty
    STemplate::assign('details', $details);

    Now in your template file you'll be looping through the results but here we'll assume you just want to check the profile picture...
    //if the field profile picture is marked as 'yes'..one does exist!
    {if $details.profile_picture eq "yes"}<img src="path to users picture">
    {else}
    //go to the default picture
    <img src="path to default picture">
    {/if}


    its a massive undertaking if you're not used to programming and laying out your plan of action for getting throught everything that needs to be done. Get yourself a nice free community based script. Get several. then work your way throught each one modifying what you need, coding new items, getting everything you need to work together. By the time you've done this you'll have learnt as much as if you have started from scratch!

    hope this helps!
     
    firmaterra, Apr 21, 2007 IP