Activity Stream
48,167 MEMBERS
61113 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default See real OOP (Snippet from Litewarez V2) Webmasters CP

    PHP Code: 
    class xxxxxx{
        
    //Handle Registration
        
    function handle_registration(){
            
    $this->username     $this->registry->get('input')->POST['username'];
            
    $this->password     $this->registry->get('input')->POST['password'];
            
    $this->password2     $this->registry->get('input')->POST['password2'];
            
    $this->alias         $this->registry->get('input')->POST['alias'];
            
    $this->website         $this->registry->get('input')->POST['website'];
            
    $this->email         $this->registry->get('input')->POST['email'];
            
    $this->sitename     $this->registry->get('input')->POST['sitename'];
            
    $this->location     $this->registry->get('input')->POST['location'];
            
            
    //Check for isset() and strlen and regex char checks
            
    if(isset($this->username) || isset($this->password) || isset($this->password2) || isset($this->alias) || isset($this->website) || isset($this->email) ){
                
    //Form has been sent
                
    if(strlen($this->username)    == 0){$this->register_errors['no_username'] = true;}
                if(
    strlen($this->password)    == 0){$this->register_errors['no_password'] = true;}
                if(
    strlen($this->password2)    == 0){$this->register_errors['no_password2'] = true;}
                if(
    strlen($this->alias)     == 0){$this->register_errors['no_alias']    = true;}
                if(
    strlen($this->website)    == 0){$this->register_errors['no_website']    = true;}
                if(
    strlen($this->email)        == 0){$this->register_errors['no_email']    = true;}
                if(
    strlen($this->sitename)    == 0){$this->register_errors['no_sitename']    = true;}
                
                
    //Min Len
                
    if(strlen($this->username)    != && strlen($this->username) < 6){$this->register_errors['username_too_short'] = true;}
                if(
    strlen($this->password)    != && strlen($this->password) < 6){$this->register_errors['password_too_short'] = true;}
                if(
    strlen($this->password2)    != && strlen($this->password2)< 6){$this->register_errors['password2_too_short'] = true;}
                if(
    strlen($this->alias)     != && strlen($this->alias)     < 4){$this->register_errors['alias_too_short'] = true;}
                if(
    strlen($this->sitename)    != && strlen($this->sitename) < 4){$this->register_errors['sitename_too_short'] = true;}
                
                
    //Max Len
                
    if(strlen($this->username)    > 32){$this->register_errors['username_too_long'] = true;}
                if(
    strlen($this->password)    > 32){$this->register_errors['password_too_long'] = true;}
                if(
    strlen($this->alias)        > 32){$this->register_errors['alias_too_long'] = true;}
                if(
    strlen($this->sitename)    > 32){$this->register_errors['sitename_too_long'] = true;}
                
                
    //Location can be defualtized
                
    $this->location = isset($this->location) ? $this->location "GB"// defualt to uk !
            
                
    if(count($this->register_errors) == 0){
                    
    //everything is inputted and is the correct lenght
                    //Check the webiste domain is valid!
                    
    $this->website str_replace('www.','',$this->website); // Remove www. for the below regex
                    
    if(!strstr('http://',$this->website)){$this->website 'http://' $this->website;} //Adds http:// if not existsing
                    
    if(!filter_var($this->website,FILTER_VALIDATE_URL)){$this->register_errors['invalid_website'] = true;}
                    
    //Set email back to the domain no HTTP for database insert later
                    
    $this->website str_replace("http://","",$this->website);
                    
                    
    //Check the email regex! - Taken from phpBB get_preg_expression()
                    
    if(!filter_var($this->email,FILTER_VALIDATE_EMAIL)){$this->register_errors['email_invalid'] = true;}
                    
                    
    //Username and email validation
                    
    if(!preg_match("/^[a-zA-Z0-9\_]+$/",$this->username)){$this->register_errors['username_invalid'] = true;}
                    if(!
    preg_match("/^[a-zA-Z0-9\_]+$/",$this->password)){$this->register_errors['password_invalid'] = true;}
                    if(!
    preg_match("/^[a-zA-Z0-9\_\s]+$/",$this->alias)){$this->register_errors['alias_invalid'] = true;}
                    
                    
    //Now check see if the passwords match.
                    
    if(strcmp($this->password,$this->password2) != 0){$this->register_errors['passwords_no_match'] = true;}
                    
                    
    //Do  Location validate
                    
                    
    if(count($this->register_errors) == 0){
                        
    //Proceed to the dabase recorde creation

                        //Check if email or doman or username is in use !
                        
                        //EMAIL
                        
    $this->sql "SELECT webmaster_id FROM ".WEBMASTERS_TABLE." WHERE xxxx = '%s'";
                        
    $this->sql sprintf($this->sql,$this->email);
                        
    $this->registry->get('database')->query($this->sql);
                        if(
    $this->registry->get('database')->num_rows() == 0){
                            
    //ok so the email is not in use well check the username
                            
    $this->sql "SELECT xxxx FROM ".WEBMASTERS_TABLE." WHERE xxxxx = '%s'";
                            
    $this->sql sprintf($this->sql,$this->username);
                            
    $this->registry->get('database')->query($this->sql);
                            
                            if(
    $this->registry->get('database')->num_rows() == 0){
                                
    //No user has got this username just have to check make sure the domain is available
                                
    $this->sql "SELECT xxxx FROM ".SITES_TABLE." WHERE xxxx = '%s'";
                                
    $this->sql sprintf($this->sql,$this->website);
                                
    $this->registry->get('database')->query($this->sql);
                                if(
    $this->registry->get('database')->num_rows() == 0){
                                    
    //Insert new user and website
                                    /*
                                        Ready for registration
                                    */
                                    //Buld the queryies
                                        //Need to insert the website first to get teh ID number
                                        
    $this->site_name_clean preg_replace("/[^a-zA-Z0-9\_]+/","_",strtolower($this->sitename));
                                        
    $this->sql_site "INSERT INTO ".SITES_TABLE." VALUES (NULL,'%s','%s','%s','%s',0,0,0)";
                                        
    $this->sql_site sprintf($this->sql_site,$this->sitename,$this->site_name_clean,$this->website,$this->email);
                                        
    //Insert Sites
                                        
    $this->registry->get('database')->query($this->sql_site);
                                        
    $this->siteId $this->registry->get('database')->getInsertId();
                                            
                                        
    //No we can add the user to the webmasters table !
                                        
    $this->sql_webmaster "INSERT INTO ".WEBMASTERS_TABLE." VALUES(NULL,%d,'%s','%s','%s','%s','%s','%s')";
                                        
    $this->pass_enc $this->saltString($this->password);
                                        
    $this->realIp $this->registry->get('input')->getRealIp();
                                        
    $this->sql_webmaster sprintf($this->sql_webmaster,$this->siteId,$this->alias,$this->username,$this->pass_enc,$this->email,$this->location,$this->realIp);
                                        
    //Insert webmasters
                                        
    $this->registry->get('database')->query($this->sql_webmaster);

                                        
    //Send heaers && add a session key for a registration note on the login page!
                                        
    $this->registry->get('session')->add('session_registered',time());
                                        
    $this->registry->get('output')->redirect(_WEBMASTERS_ROOT);
                                }else{
                                    
    $this->register_errors['website_in_use'] = true;
                                }
                            }else{
                                
    $this->register_errors['username_in_use'] = true;
                            }
                        }else{
                            
    $this->register_errors['email_in_use'] = true;
                        }
                    }
                }
            }
        }


    This is a snippet of the registration validation class for my new Webmasters CP and im posting this to show you at what OOP is all about !!!!!!
    litewarez Reviewed by litewarez on . See real OOP (Snippet from Litewarez V2) Webmasters CP class xxxxxx{ //Handle Registration function handle_registration(){ $this->username = $this->registry->get('input')->POST; $this->password = $this->registry->get('input')->POST; $this->password2 = $this->registry->get('input')->POST; $this->alias = $this->registry->get('input')->POST; $this->website = $this->registry->get('input')->POST; $this->email = $this->registry->get('input')->POST; $this->sitename = $this->registry->get('input')->POST; Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Respected Developer
    Website's:
    X4B.org
    Hmm as much as some of this is a good idea, lookup trigger_error and custom error handlers, much better really as they are built in to php (faster and means you can interprete php errors in the same code).

    The only other issue I can see is the speed of the page, but thats your choice, another peice of OOP from my language class, Ill post it 2morro or later tonight.

  4.     
    #3
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    i have custom error handler that logs all errors and sends emails with updates every 6 hours, also stops the error output to the users but not my IP, this way only i can see errors and uses will just get system offline message !.. thought ahead you see

    and this is very throughout checking, its pretty fast to be honest, this and about 18 other classes including Db, User Tracker, Sucurity on all Inout requests GET,POST etc and stuff like Smarty system and custom config class loads in about 0.0280ms
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  5.     
    #4
    Respected Developer
    Website's:
    X4B.org
    hmm I have the same thing, tho I do show messages in a nice way. Only Its implemented with trigger_error

    I need to add a load timer to my script so we can compare. Have you got filtering and validation in the whole WCDDL script?

    I might have to implement something like your registry class, it does look nice to the eye really.

  6.     
    #5
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    my system is all coded by myself lol, WCDDL is good but its just for average warez sites and thats not my idea, and the registry class is a piece of piss to do and the best thing is you just globalize in your constructs like

    function __construct(){
    global $registry;
    $this->registry = $regsitry;
    }

    and i have an object file to load all objects like this

    PHP Code: 
    <?php
    if(!defined('IN_SITE')){die('Hacking Attempt!');}

    //Error Handling Ssytem

    //Instantate Registry objects
    $registry = new registry();                            //    Core Registry
    //Instantate all other objects into the registry
    $registry->put('database',        new $dbType());        //    Database
    $registry->get('database')->connect();                //    Run the connection
    $registry->put('session',        new session);        //    Session
    $registry->put('input',            new input);            //    Input
    $registry->put('output',        new output);         //    Output handler
    $registry->put('helpers',        new helpers);        //    Helpers
    $registry->put('user_tracker',    new user_tracker);    //    users_online + ip tracking etc
    $registry->put('smarty',        new Smarty);        //    Smarty Tempalte Engine
    $registry->put('litewarez',        new Litewarez);        //    Litewarez Core
    $registry->put('tagcloud',        new tagcloud);        //    Litewarez Tag Cloud Links
    $registry->put('breadcrumb',    new breadcrumb);    //    Breadcrumbs
    ?>
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  7.     
    #6
    Respected Developer
    Website's:
    X4B.org
    Yeah I know, WCDDL isnt that great but its quite alot of work to make one from scratch and maintain it. I know the registry class is a piece of piss but I was thinking of making it even quicker and using php's magic methods

    If I had the time I should really finnish of DDL2 (aka the new name of uDDL) but yeah, then again Im not even happy with that really, I made it a bit to complex in some areas.

  8.     
    #7
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    yea i love the magic methods aswell lol, me and you should talk.. could do with another programmer for litewarez !.. seems like you know your shit more than most users around here.. nice to have sum on ya level ol
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  9.     
    #8
    Respected Developer
    Website's:
    X4B.org
    hmm add me to msn, splitice@hotmail.com

  10.     
    #9
    Respected Developer
    This doesn't show what OOP is all about, all it shows is a method in a class. Besides, PHP is a poor language for showcasing OOP since it doesn't enforce it.

    What OOP is about: http://en.wikipedia.org/wiki/Object-...ed_programming

  11.     
    #10
    Respected Developer
    Website's:
    X4B.org
    Very true, one of the most annoying things in php is you cant reassign $this.

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Snippet of the Day
    By SplitIce in forum Web Development Area
    Replies: 41
    Last Post: 26th Aug 2012, 06:09 PM
  2. Litewarez Feture list (Reason why your site belongs on Litewarez)
    By litewarez in forum Webmaster Discussion
    Replies: 42
    Last Post: 15th May 2010, 05:58 PM
  3. Litewarez Webmasters Notification system
    By litewarez in forum Forum and DDL Discussion
    Replies: 15
    Last Post: 24th Dec 2009, 01:52 PM
  4. Help required with Litewarez V2 Webmasters
    By litewarez in forum Forum and DDL Discussion
    Replies: 5
    Last Post: 26th Oct 2009, 05:13 AM
  5. Litewarez Webmasters, Screen Shot? What you think?
    By litewarez in forum Site Reviews
    Replies: 4
    Last Post: 27th Dec 2008, 03:32 AM

Tags for this Thread

BE SOCIAL