title: My first OOP aproach in Codeigniter
body: <p>I'm trying to make a crawler to fetch templates from sites that don't offer any API access for later display as affiliate.
  I just started with CI, read the documentation a few times and below you can find my first OOP approach.
  My question is if I'm on the right path of OOP or if are (I'm sure there are) any improvements available to my code. I read alot of OOP tutorials on the web and people seems to have different views of the OOP coding.</p>
  
  <p>Thank you in advance.</p>
  
  <pre><code>&lt;?php
  class Crawler extends CI_Model {
  
  function __construct(){
      parent::__construct();
  }
  
  function get_with_curl($url) {
      if(!ini_get('allow_url_fopen')) {
          return $this-&gt;html = file_get_html($url);
      } else {
          $curl = curl_init(); 
          curl_setopt($curl, CURLOPT_URL, $url);
          curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
          curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
          $str = curl_exec($curl);  
          curl_close($curl);  
  
          return $this-&gt;html = str_get_html($str);
      }
  }
  
  function array_arrange($links){
      $links = array_merge(array_unique($links));
      foreach (range(1, count($links), 2) as $k) {
          unset($links[$k]);
      }
      return array_merge($links);
  }
  
  function diff($source,$links){
      $this-&gt;db-&gt;like('source', $source);
      $this-&gt;db-&gt;from('themes');
      $total = $this-&gt;db-&gt;count_all_results();
  
      if($total &gt;= count($links)){
          return false;
      } else {
          $diff = count($links)-$total;
          $data = array_slice($links,-$diff,$diff,true);
          return $data;
      }
  }
  
  function get_links($url,$find){
      $this-&gt;html = $this-&gt;get_with_curl($url);
      foreach($this-&gt;html-&gt;find($find) as $v){
          $data[] = $v-&gt;href;
      }
      $this-&gt;html-&gt;clear();
      unset($this-&gt;html);
  
      return $data;
  }
  
  function themefyme(){
      $links = $this-&gt;get_links('http://themify.me/themes','ul[class=theme-list] li a');
      $links = $this-&gt;array_arrange($links);
      $links = $this-&gt;diff('themefyme',$links);
      if($links){
          $i = 0;
          foreach($links as $link){
              $this-&gt;html = $this-&gt;get_with_curl($link);
              $data[$i]['source']         = 'themefyme';
              $data[$i]['name']           = strtok($this-&gt;html-&gt;find('h1', 0)-&gt;plaintext,' ');
              $data[$i]['link']           = $link;
              $data[$i]['demo']           = 'http://themify.me/demo/#theme='.strtolower($data[$i]['name']);
              $data[$i]['price']          = filter_var($this-&gt;html-&gt;find('h1 sup', 0)-&gt;plaintext, FILTER_SANITIZE_NUMBER_INT);
              $data[$i]['description']    = $this-&gt;html-&gt;find('big', 0)-&gt;plaintext;
              $data[$i]['features']       = $this-&gt;html-&gt;find('ul', 0)-&gt;plaintext;
              $data[$i]['img_large']      = $this-&gt;html-&gt;find('.theme-large-screen img', 0)-&gt;src;
              $data[$i]['img_thumb']      = 'http://themify.me/wp-content/themes/themify/thumb.php?src='.$data[$i]['img_large'].'&amp;q=90&amp;w=220';
              $i++;
  
              $this-&gt;html-&gt;clear();
              unset($this-&gt;html);
          }
          $this-&gt;db-&gt;insert_batch('themes', $data); 
          return $data;
      }
      return false;
  }
  
  function themefuse(){
      $links = $this-&gt;get_links('http://www.themefuse.com/wp-themes-shop/','.theme-img a');
      $links = $this-&gt;array_arrange($links);
      $links = $this-&gt;diff('themefuse',$links);
      if($links){
          $i = 0;
          foreach($links as $link){
              $this-&gt;html = $this-&gt;get_with_curl($link);
              $data[$i]['source']         = 'themefuse';
              $data[$i]['name']           = $this-&gt;html-&gt;find('.theme-price', 0)-&gt;plaintext;
              $data[$i]['link']           = $link;
              $data[$i]['demo']           = 'http://themefuse.com/demo/wp/'.strtolower($data[$i]['name']).'/';
              $data[$i]['description']    = $this-&gt;html-&gt;find('.short-descr', 0)-&gt;plaintext;
              $data[$i]['highlights']     = $this-&gt;html-&gt;find('.highlights', 0)-&gt;outertext;
              $data[$i]['features']       = $this-&gt;html-&gt;find('.col-features', 0)-&gt;outertext;
              $data[$i]['theme_info']     = $this-&gt;html-&gt;find('.col-themeinfo', 0)-&gt;outertext;
                                            preg_match("/src=(.*?)&amp;amp;/",$this-&gt;html-&gt;find('.slideshow img', 0)-&gt;src, $img);
              $data[$i]['img_large']      = $img[1];
              $data[$i]['img_thumb']      = 'http://themefuse.com/wp-content/themes/themefuse/thumb.php?src='.$img[1].'&amp;h=225&amp;w=431&amp;zc=1&amp;q=100';
              $i++;
  
              $this-&gt;html-&gt;clear();
              unset($this-&gt;html);
          }
          $this-&gt;db-&gt;insert_batch('themes', $data); 
          return $data;
      }
      return false;
  }
  }
  </code></pre>