CodeIgniter Forums
Controller extension error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Controller extension error (/showthread.php?tid=46785)



Controller extension error - El Forum - 11-15-2011

[eluser]Unknown[/eluser]
A client project which I have taken over has the /app/libraries/MY_controller.php object:

Code:
if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends Controller {

function MY_Controller() {
      parent::Controller();
        



  

}

function wrapOutput($content,$title=null,$desc=null,$keywords=null,$metaRobot=null,$bodyClass=null) {
       empty($title) ? $title = "" : $title=$title;
       empty($desc) ? $desc = "" : $desc=$desc;
       empty($keywords) ? $keywords = "" : $keywords=$keywords;
       empty($metaRobot) ? $metaRobot = "index, follow" : $metaRobot=$metaRobot;
       empty($bodyClass) ? $bodyClass = "default" : $bodyClass=$bodyClass;
      
       //$flash = $this->db_session->flashdata('flashMessage');
       $lpage = $this->uri->total_segments();
   $booking =$this->session->userdata('booking');
       $data = array(
      'metaTitle' => $title,
      'metaDesc' => $desc,
      'metaKeyWords' => $keywords,
      'metaRobot' => $metaRobot,
      'content' => $content,
      'bodyClass' => $bodyClass,
      

     );
   if($bodyClass == 'root'){
       $this->load->view('wrapper',$data);
   } else {
       $this->load->view('wrapper-internal',$data);
   }
    }


function get_convio_content($page) {
  $url = "http://www.clientsite.com/stars/$page.html";
  
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
  $output = curl_exec($ch);
  curl_close($ch);
  
  //need to parse out content:
  $page = array();
  $page['title'] = "";
  $page['body'] = "";

  //strip out hard references
  $output = preg_replace("#http://www.clientsite.com#s", "", $output);
  
  //step 1. get <title></title>
  if(preg_match("/&lt;title&gt;(.*?)<\/title>/s", $output, $m)) {
   $page['title'] = $m[1];
  }

  //step 2. get  <div id="contentDiv"><p>Welcome!</p></div>
  if(preg_match("/<div id=\"contentDiv\">.*?<\/script>.*?<\/script>(.*?)<\/div>/s", $output, $m)) {
   $page['body'] = $m[1];
  }

  return $page;  
}
}

After a year of proper functioning, with no known code changes, this scraping has recently begun failing. (Grabbing some javascript from the source page, rather than the contents of contentDiv.)

I have found a solution that works outside the codeigniter paradigm, on a test system, but when I try the exact same solution in the above object, it fails. Hard. (Rather than blank content, the whole page is blank, indicating some sort of PHP error.) This is the code with which I tried to replace "step 2":

Code:
$domd = new DOMDocument(); // fails here
libxml_use_internal_errors(true);
$domd->loadHTML($output);
libxml_use_internal_errors(false);
$div = $domd->getElementById("contentDiv");
if ($div) {
  $dom2 = new DOMDocument();
    $dom2->appendChild($dom2->importNode($div, true));
mail('[email protected]', 'success', $dom2->saveHTML());
  
} else {
mail('[email protected]', 'failure', 'did not provide a properly constructed contentDiv');
}

Any idea why that failure might occur?

I know this is not strictly a codeigniter issue, but hours of Googling make me no wiser, so I am hoping for some help here.

Thanx,

ks