TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-05-2009, 12:47 AM   #1 (permalink)
The Contributor
 
Join Date: Nov 2008
Location: Sweden
Posts: 36
Thanks: 1
hjalmar is on a distinguished road
Default c&c and best practise.

Hey guys,

I've been lurking this forum on and off for some time, never really had the time to take part and take my programming seriously. Time has changed and motivation is there so it's hella fun.

Some things like abstract classes, protected, private, singletons, error handling etc hasn't really stuck in my head yet. It's been more reading then actually putting anything down on paper so to say :)

I don't expect you guys to try and explain, that i have a couple of books for but i would like some criticism.

PHP Code:
<?php
    
    
/*
        -- Crawl
    */
    
    
class Crawl{
        
        public 
$markup;
        public 
$url;
        
        public function 
__construct($url){
            
            
$this->url        $url;
            
$this->markup     $this->fetchMarkup();
            
$siteName         $this->siteName();
            
            
/* What site to be crawled */
            
$this->crawl      = new Crawl_method($this->markup);
            
$this->method     $this->crawl->$siteName();
        }
        
        
/*
            - extract what site we are on and choose method accordingly.
            - temp solution, me regepx suxxors ;)
        */
        
public function siteName(){
            
            
$name explode("."$this->url);
            return 
$name[1];
            
        }
        
        
/*
            - grab markup from url.    
        */
        
public function fetchMarkup(){
            
            return 
file_get_contents($this->url);
        
        }
        
        
        
/*
            - save the file.
        */
        
public function saveFile(){
            
            
set_time_limit(0);
            
$uniqid uniqid();
            
            
//create dir
            
mkdir("uploads/{$uniqid}"0777true);
            
            
//grab content
            
$contents file_get_contents($this->method);
            
            
//create .flv file
            
file_put_contents("uploads/{$uniqid}/{$uniqid}.flv"$contents);
            
        }
        
    }
    
    
/*
        - what method to retrieve our .flv file.
    */
    
class Crawl_method{
        
        public 
$markup;
        
        public function 
__construct($markup){
            
            
$this->markup $markup;
        
        }
        
        
        
/*
            - grab url to youtube .flv file
        */
            
        
public function youtube(){
            
//video_id
            
preg_match('/"video_id": "(.*?)"/'$this->markup$match);
            
$id $match[1];
            
            
//t
            
preg_match('/"t": "(.*?)"/'$this->markup$match);
            
$t $match[1];
            
            
$url "http://www.youtube.com/get_video?video_id={$id}&t={$t}";
        
            return 
$url;
            
        }
            
    }
    
?>
Thanks, Hjalmar
hjalmar is offline  
Reply With Quote
Old 05-16-2009, 10:35 PM   #2 (permalink)
The Wanderer
 
gregor171's Avatar
 
Join Date: May 2009
Location: Ljubljana, Slovenia
Posts: 9
Thanks: 0
gregor171 is on a distinguished road
Default

OK... the book I wanted to mention.... just kidding.

I don't get this:
PHP Code:
$this->crawl      = new Crawl_method($this->markup);
$this->method     $this->crawl->$siteName(); 
or maybe I do. I'd usually do this trough magic method __get

Next problem is:
public $markup;
should be private (or protected as in next sample)
Reason behind this is, you want to hide private variables inside the class and use public methods to read their values if you need them outside the class.

U were asking about the true OOP way (one way to get an idea about it):
a part from your Crawl class
PHP Code:
 /* What site to be crawled */
$current_crawler =  $siteName.'_crawler';
$this->crawl      = new $current_crawler ($this->markup);
$this->method     $this->crawl->method(); 
PHP Code:
abstract class Crawl_method{
     
// this class is used for everything that will concern classes derived from this one
    
protected $markup;
        
        public function 
__construct($markup){
            
            
$this->markup $markup;
        
        } 
        
        
// you will implement this function later
        
abstract function method(){}
    
}

class 
youtube_crawler extends Crawl_method{
    
    public function 
__construct($markup){
        
parent::__construct($markup);
    }
    
    public  function 
method(){
        
// your code for youtube goes here
    
}
    

But. This sample is only to demonstrate some basics. Since your sample is simplier, you don't need
protected $markup;
if you don't need it elsewhere. so simplified object would be like:
PHP Code:
abstract class Crawl_method{
     
// this class is used for everything that will concern classes derived from this one
        
        // this method will be enherited in all classes
        
public function some_demo_function(){
            
// code for some demo function just for fun
        

        
        
// you will implement this function later
        
abstract function method(){}
}

class 
youtube_crawler extends Crawl_method{

    public  function 
method($markup){
        
// your code for youtube goes here
    
}

You want to keep thinks as simple as possible.
__________________
WEB Developer
http://xweblabs.com
http://grajzar.info
Send a message via Skype™ to gregor171
gregor171 is offline  
Reply With Quote
The Following User Says Thank You to gregor171 For This Useful Post:
hjalmar (05-21-2009)
Old 05-21-2009, 03:10 AM   #3 (permalink)
The Contributor
 
Join Date: Nov 2008
Location: Sweden
Posts: 36
Thanks: 1
hjalmar is on a distinguished road
Default

Thanks for your reply gregor. I will go through this when i get the time, been a bit short on that again..... latly

But i really appreciate it and i will go throught it and come back with questions if there is any.

cheers!
hjalmar is offline  
Reply With Quote
Old 11-12-2012, 07:43 AM   #4 (permalink)
The Contributor
 
Join Date: Oct 2012
Posts: 46
Thanks: 0
ww628815 is on a distinguished road
Default

The endorsement of the Jordans For Sale by Michael Jordan turned out to be an enormous draw with the strong sales of the shoes since they were launched in 1984. These were also referred to as Air Jordan Retro 9 Sale for quite a while these days will be more popularly often called Jordans. Nike shoes really went the entire hog inside the design and styling from the exclusive type http://www.jordanshoesforsole.com/ athletic shoes by introducing colorise the shoes in my ballet Cheap Nike Air Jordan Retro 11. This included in the style quotient on the Air Jordan Retro 15 and enabled the buyers to have a couple of jogging shoes inside the colors that they had always wanted.

The Jordan shoes have cushioned flexible soles in order to avoid ankle injury.
ww628815 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:33 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design