Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AppError extends ErrorHandler {
- function missingController($params){
- //echo 'missing controller';
- $this->error404($params);
- }
- function missingAction($params){//if debug is greater than 0 this will kick in. Production should be 0 (which will error404())
- echo 'missing action';
- //$this->error404($params);
- }
- function error404($params){
- extract($params);
- //fb($params);
- App::import('Tracking');
- //App::import('Session');
- $track = new TrackingComponent;
- //fb($url,'non-normalized');
- $url = Router::normalize($url);
- //fb($url,'normalized');
- //get source
- $source = $track->getAliasSource($url);
- if($source){//does this url exist in the alias database? if so get source
- //fb($source,'SourceCode');
- $redirectURL = $track->getAliasURL($source);
- //fb('The alias URL for '.$source.' is '.$redirectURL);
- } else {//theres no source/alias - check for alternative URL using keywords table eg. 'handsets' 'worldphone'
- //fb($url,'The is no source,Checking For substitute');
- $redirectURL = $track->substituteURL($url);
- //as its not a true page, log it in the 404 'broken links' table
- //($redirectURL) ? fb($redirectURL,'Yes') : fb('No Substitute, 404 iminent') ;
- //fb('Tracking '.$url.' as a broken link in 404 table');
- //$track->track404($url);
- }
- //so at this point we should have a redirectURL, or if not it really is a 404.
- //if we do have a redirect url...
- if($redirectURL) {
- //fb('Theres a redirect URL',$redirectURL);
- //check visitors ip address to see if its one of ours
- $this->controller->Session->write("ourIP",$ourIP = $track->checkIP( env('REMOTE_ADDR') ));
- //fb($ourIP,'Have just checked ourIP and written to session value');
- if(!$ourIP){//its not one of ours, treat as a customer.
- //fb('Its not our IP, so its a customer');
- //check to see if they have been dealt with yet - is it a new visit?
- if(!$this->controller->Session->check("visitor")){//new visitor
- //fb('Theres no session value set');
- //track visitor in visitors table (user agent, ip etc)
- //fb('Its a customer, there is a redirect URL, and this is their first page on the site. We track them.');
- //is there a visitor cookie?
- if($this->controller->Cookie->read('visitor')){
- //yes
- $visitorId = $track->trackVisitor($url,$this->controller->Cookie->read('visitor'));
- }else{
- //no
- //insert visitor and grab visitorId ready to write into session and cookie
- $visitorId = $track->trackVisitor($url);
- }
- //fb('writing cookie');
- $this->controller->Cookie->name = 'Mobal';
- $this->controller->Cookie->time = 3600; // or '1 hour'
- $this->controller->Cookie->domain = '.mobal.com';//env('SERVER_NAME');
- $this->controller->Cookie->write('visitor',$visitorId,false,'90 days');
- //fb('setting session');
- $this->controller->Session->write('visitor',$visitorId);
- //track visit & write session
- //check for source
- if($source){//track source
- //fb($source,'Track dat source homey');
- $track->trackSource($visitorId,$source);
- //fb('Source Tracked! using '.$visitorId);
- }
- } //else { fb('Already been, so dont track');}
- }
- //redirect
- //fb('301 Redirecting to '.$redirectURL);
- $this->controller->redirect($redirectURL,301);
- }else{ //no urls match:404 time
- $track->track404($url);
- $this->controller->layout = '404';
- $this->controller->set(array(
- 'url' => $url,
- 'title' =>'Page cannot be found'
- ));
- header("HTTP/1.0 404 Not Found");
- $this->_outputMessage('missing');
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement