Custom Php Controller Not Working -


this site link http://theadvocates.site/easyclients/lawyers.tm/ homepage working when go specific page http://theadvocates.site/easyclients/lawyers.tm/template/4law/home/get_started error 404 page here framework file, controller , get_started.php file

prodframework.php

<?php    class framework {  public $config = array(     'script_path'       => '/home/theadvoc/public_html/easyclients/lawyers.tm',      'web_path'          => '',      #'file_path'            => '/home/dan/public_html/framework/files/',      #'file_web_path'        => 'http://4law.i-tul.com/files/',      'full_web_path'     => 'http://lawyers.tm',      'template_name'     => '4law',      'encryption_key'    => '123654$#*(7j(gdj7@)(ej**9@9ska90be8$7os0465*i',      'log_error'         => true,      'secure_head'       => false,      'site_name'         => '#4law',      'ga_account'        => 'ua-24372412-1'  );      /*      prodframework differs framework in config array above.      initializers can't dynamic, switch still needs happen.      different user, different db, different codebase.      additional sad: extensions of don't call parent::__construct      */        public $info;               // debug information current module/page/routing      public $modules;            // loaded modules          /*       * method determines module , page display       * needs cleaned       */      public function route()      {            // parse request url          $_server['request_uri'] = str_replace($this->config['web_path'], '', $_server['request_uri']);         //echo "bb".$_server['request_uri'];          $routes = explode('/', trim($_server['request_uri'], '/'));     //echo "routes[0]".$routes[0];     //echo "routes[1]".$routes[1];          // check variables passed through url (/page/my_var:value/)             $query_vars = array();          if(is_array($routes))          {              foreach($routes $part)              {                  if(preg_match('/([a-za-z_-]*):([0-9a-za-z_-]*)/', $part, $match))                  {                      $query_vars[$match['1']] = $match['2'];                  }else{                      $routes_new[] = $part;                  }              }              $routes = $routes_new;          }            // empty module name, default home          if(empty($routes[0]))          {              $routes[0] = 'home';          }          /**           * google/splash page fix seo friendly controller dashes           */          if(preg_match("/\-/", $routes[0])){              $routes[0] = preg_replace("/\-/", '', $routes[0]);              //die(pr($routes[0]));          }                   // empty page name, default index          if(empty($routes[1]))          {              $routes[1] = 'index';          }else if(is_numeric($routes[1])){              $routes[2] = $routes[1];              $routes[1] = 'index';          }          $routes[0] = 'home';         $routes[1] = 'index';          // prep module name          $routes[0] = ucfirst($routes[0]);             // make sure requested page exists         if(            !file_exists("{$this->config['script_path']}/framework/controller/{$routes[0]}.php")           )         {             echo "xxxx ";             echo $this->config['script_path']."/framework/controller/".$routes[0].".php";             echo " zzzz";         }         if(            !file_exists("template/{$this->config['template_name']}/{$routes[0]}/{$routes[1]}.php")           )         {             echo "yyyy ";             echo "template/{$this->config['template_name']}/{$routes[0]}/{$routes[1]}.php";             echo " ffff";          }          if(!file_exists("{$this->config['script_path']}/framework/controller/{$routes[0]}.php") || !file_exists("template/{$this->config['template_name']}/{$routes[0]}/{$routes[1]}.php"))          {                $routes[0] = 'error';              $routes[1] = 'index';          }            // set controller          $frm = $this->load_controller($routes[0]);            // check controller          if($frm === false)          {              exit;          }            // set query vars          $frm->info['query_vars'] = $query_vars;            // set current module          $frm->info['current_module'] = $routes[0];            // set current page          $frm->info['current_page'] = $routes[1];            // pass routing information          $frm->info['raw_route'] = $routes;            // render current page          $frm->render($routes[1]);      }            /*       * load model class       */      function load_model($module_name)      {          $location = "{$this->config['script_path']}/framework/model/{$module_name}.php";          // make sure module not loaded          if(!is_object($this->$module_name) && file_exists($location))          {              // load module current object              include_once($location);              $this->$module_name = new $module_name();              return $this->$module_name;          }else{              return false;          }      }            /*       * load helper class       */      function load_helper($module_name)      {          $location = "{$this->config['script_path']}/framework/helper/{$module_name}.php";          // make sure module not loaded          if(!is_object($this->$module_name))          {              if(file_exists($location))              {                  // load module current object                  include_once($location);                  $this->$module_name = new $module_name();                  return $this->$module_name;              }else{                  die("could not load helper.");              }          }          return $this->$module_name;      }          /*       * load controller class       */      function load_controller($module_name)      {          $location = "{$this->config['script_path']}/framework/controller/{$module_name}.php";          // make sure module not loaded          if(!is_object($this->$module_name) && file_exists($location))          {              // load module current object              include_once($location);              $module_name = "{$module_name}_controller";              $this->$module_name = new $module_name();              return $this->$module_name;          }else{              return false;          }      }          /*       * render current page (header, page, footer)       */      function render($page)      {          $this->load_model('user');          // if secure module, make sure user logged in          if($this->config['secure_module'] == true && $this->user->check_login() === false)          {              // secure module, , user not logged in              include("{$this->config['script_path']}/template/{$this->config['template_name']}/user/login.php");              exit;          }          // see if page load function exists          $function_name = $this->info['current_page'];          if(method_exists($this, $function_name))          {              $this->$function_name();          }          // load requested page          $this->render_head();          include_once("{$this->config['script_path']}/template/{$this->config['template_name']}/{$this->info['current_module']}/{$page}.php");          $this->render_foot();      }            /*       * render header (called $this->render())       */      function render_head()      {          if(is_array($this->disable_headers) && in_array($this->info['current_page'], $this->disable_headers))          {              return true;          }          if(file_exists("template/{$this->config['template_name']}/{$this->info['current_module']}/head.php"))          {              include(("template/{$this->config['template_name']}/{$this->info['current_module']}/head.php"));          }else if(file_exists("template/{$this->config['template_name']}/head.php")){              include("template/{$this->config['template_name']}/head.php");          }      }            /*       * render footer (called $this->render())       */      function render_foot()      {          if(is_array($this->disable_headers) && in_array($this->info['current_page'], $this->disable_headers))          {              return true;          }          if(file_exists("template/{$this->config['template_name']}/{$this->info['current_module']}/foot.php"))          {              include("template/{$this->config['template_name']}/{$this->info['current_module']}/foot.php");          }else if(file_exists("template/{$this->config['template_name']}/foot.php")){              include("template/{$this->config['template_name']}/foot.php");          }      }            /*       * render partial element       */      function render_partial($partial_name)      {          // lock file path partial directory          $partial_name = str_replace('/', '', $partial_name);          $location = "template/{$this->config['template_name']}/{$this->info['current_module']}/partial/{$partial_name}.php";          if(file_exists($location))          {              $info = $this->info;              include($location);          }      }            /*       * add error string or array       */      function add_error($error)      {          // see if error reporting has been disabled          if($this->config['log_error'] === true)          {              $e = array(                  'request' => $_server['request_uri'],                  'post' => $_post,                  'get' => $_get,                  'error' => $error              );              $_session['error'][] = $e;              $this->load_helper('db');              $arr = array(                  'error_array'   => print_r($_session['error'], true)              );          }      }            /*       * render error array       */      function show_error()      {          if(is_array($_session['error']))          {              echo '<div class="error_message">';              echo '<pre>';              print_r($_session['error']);              echo '</pre>';              echo '</div>';              $_session['error'] = '';          }      }            function show_flash()      {          if(is_array($_session['flash']))          {              echo '<div class="message">';              foreach($_session['flash'] $m)              {                  echo "<p>{$m}</p>\n";              }              echo '</div>';          }          $_session['flash'] = '';      }            function add_flash($message)      {          if(!empty($message))          {              $_session['flash'][] = $message;          }      }              function show_error_message()      {          if(is_array($_session['errorflash']))          {              echo '<div class="error_message">';              foreach($_session['errorflash'] $m)              {                  echo "<p>{$m}</p>\n";              }              echo '</div>';          }          $_session['errorflash'] = '';      }            function add_error_message($message)      {          if(!empty($message))          {              $_session['errorflash'][] = $message;          }      }            /*       * encrypt string       */      function encrypt_string($text)      {          return trim(base64_encode(mcrypt_encrypt(mcrypt_rijndael_256, $this->config->config->encryption_key, $text, mcrypt_mode_ecb, mcrypt_create_iv(mcrypt_get_iv_size(mcrypt_rijndael_256, mcrypt_mode_ecb), mcrypt_rand))));      }            /*       * decrypt string       */      function decrypt_string($text)      {          return trim(mcrypt_decrypt(mcrypt_rijndael_256, $this->config->encryption_key, base64_decode($text), mcrypt_mode_ecb, mcrypt_create_iv(mcrypt_get_iv_size(mcrypt_rijndael_256, mcrypt_mode_ecb), mcrypt_rand)));      }          public function image_url($path)      {          $path = trim($path, ' /');          if($this->config['web_path'] == '/')          {              $wp = '';          }else{              $wp = $this->config['web_path'];          }          return "{$wp}/template/{$this->config['template_name']}/images/{$path}";      }          public function link_url($path)      {          $path = trim($path, ' /');          if($this->config['web_path'] == '/')          {              $wp = '';          }else{              $wp = $this->config['web_path'];          }          return "{$wp}/{$path}";      }          public function page_path()      {          return "{$this->config['web_path']}/".strtolower($this->info['current_module'])."/{$this->info['current_page']}";      }          public function reload_page($path=null)      {          header("location: {$this->config['web_path']}/{$this->info['current_module']}/{$this->info['current_page']}$path");          exit;      }                              public function load($load_id, $field_name = '')      {          // load database module          $this->load_module('db');            return $this->db->load(strtolower($this->info['current_module']), $load_id, $field_name);        }          function contextual_time($small_ts, $large_ts=false) {      if(intval($small_ts)===0) return "never";    if(!$large_ts) $large_ts = time();    $n = $large_ts - $small_ts;    if($n <= 1) return 'less 1 second ago';    if($n < (60)) return $n . ' seconds ago';    if($n < (60*60)) { $minutes = round($n/60); return 'about ' . $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ago'; }    if($n < (60*60*16)) { $hours = round($n/(60*60)); return 'about ' . $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ago'; }    if($n < (time() - strtotime('yesterday'))) return 'yesterday';    if($n < (60*60*24)) { $hours = round($n/(60*60)); return 'about ' . $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ago'; }    if($n < (60*60*24*6.5)) return 'about ' . round($n/(60*60*24)) . ' days ago';    if($n < (time() - strtotime('last week'))) return 'last week';    if(round($n/(60*60*24*7))  == 1) return 'about week ago';    if($n < (60*60*24*7*3.5)) return 'about ' . round($n/(60*60*24*7)) . ' weeks ago';    if($n < (time() - strtotime('last month'))) return 'last month';    if(round($n/(60*60*24*7*4))  == 1) return 'about month ago';    if($n < (60*60*24*7*4*11.5)) return 'about ' . round($n/(60*60*24*7*4)) . ' months ago';    if($n < (time() - strtotime('last year'))) return 'last year';    if(round($n/(60*60*24*7*52)) == 1) return 'about year ago';    if($n >= (60*60*24*7*4*12)) return 'about ' . round($n/(60*60*24*7*52)) . ' years ago';     return false;  }          function getmodel($cls, $dbmode="write", $id=null)      {          $db = $this->getdb( $dbmode );          if(!class_exists($cls))              require_once( model_path . "$cls.class.php" );          return new $cls($db,$id);      }          /*** getdb ***      @static      @access public      @param  string  dbmode      @return dbc      */      function getdb( $dbmode="write" )      {          if(!class_exists('dbc'))              require_once( cls_path . "dbc.class.php" );            $home = defined('in_development') && in_development===true          ?   "fourlaw"          :   "portal";          return new dbc( sql_path. $home."_dbuser_$dbmode.ini" );      }        function isajax()       {        return $_server[ 'http_x_requested_with' ] === 'xmlhttprequest';      }          /*** getaudit ***      @static      @access public      @return object  audit model      */      function getaudit()      {          return new audit( framework::getdb() );      }        /*** notifyrolechange ***      produce message indicating admin      acting admin, , offer them way out      @access private      @return void      */      function notifyrolechange()      {          if(!$_session['login']['admin_id'])              return;            require_once( model_path . "admin.class.php" );          $admin = new admin($this->getdb(), $_session['login']['admin_id']);          $tpl = new tpl( tpl_path . "role_notify.tpl");          $tpl->setattribs(array          (              "self" => $admin->getshortname(),              "role" => $this->user->getmodel()->getfullname()          ));            $this->add_error_message( $tpl->parse() );      }        /**      @static      @return bool      */      function adminid()      {          return util::first($_session['login']['true_admin_id'],  $_session['login']['admin_id']);      }  }      // global debug function  function pr($data)  {      echo "<pre style=\"color:#fff;background:#333;\">";      if($data === true || $data === false)      {          var_dump($data);      }else{          print_r($data);      }        echo "</pre>";  } ?> 

home.php controller

<?php  class home_controller extends framework {      public $form_recipients;     public $form_subject = "contact lawyers.tm";      public function __construct() {         $this->form_recipients = array(contact_email);     }      public function index() {          }      public function pricing() { }      public function company() { }      public function contact() {          echo "testing";       }       public function test() {         echo "test!";     }      public function get_started() {          include_once('the')     }      public function new_case() { }      public function proxy_aimcrm_js() {         $ch = curl_init('https://www.aimcrm.com/remote/ap_js.php?f='.intval($this->info['raw_route'][2]).'&o='.intval($this->info['raw_route'][3]));         curl_setopt($ch, curlopt_returntransfer, true);         $js = curl_exec($ch);         header("content-type: text/javascript");         echo str_replace('http://www.aimcrm.com/images/', 'https://www.aimcrm.com/images/', $js);         exit;     }      protected function postcontactform() {         $msg = false;          if(!empty($_post)) {             $post = array_map('home_controller::postfilter', $_post);             $this->load_helper('validate');             if(!$this->validate->run($post, array(                 'name' => array('reqd' => 'please provide name.'),                 'email' => array('email' => 'please provide valid email address.')))) {                 return $this->validate->firsterror();             }             $body = <<<eot $this->form_subject  name: {$post['name']} address: {$post['address']} email: {$post['email']} phone: {$post['phone']} best time contact: {$post['time']}  eot;             $email = str_replace("\n", '', $post['email']);             $headers = "from: {$email}\r\n"                 ."reply-to: {$email}";              foreach($this->form_recipients $recip) {                 mail($recip, $this->form_subject, $body, $headers);             }              $msg = $post['name'].", information has been received , soon.";         }          return $msg;     }      private static function postfilter($str) {         return trim(htmlentities(strip_tags($str)));     }  }  ?> 

get_started.php

<? require('splash.php'); ?> <div class="center"> <div class="content-top"></div> <div class="content get_started contact-form"> <table border="0"><tr> <td class="left"> <h2>getting started</h2> <h4>please send me more information lawyers.tm law firm.</h4> </td> <td class="right"> <?php $this->form_subject = "please send me more information lawyers.tm"; require('contact-form.php'); ?> </td> </tr></table> </div> <div class="content-bottom"></div> <div class="clear"></div> </div> 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -