示例#1
0
 /**
  * Get the URI segments after the base url
  *
  * @return array
  */
 function getURISegments()
 {
     if ($this->_router !== null) {
         $url = $this->_router->getMatchedRoute();
     } else {
         $url = str_replace($this->_config->system->base_url, '', $this->_fullUrl);
     }
     PPI_Helper::getRegistry()->set('PPI::Request_URI', $url);
     return explode('/', trim($url, '/'));
 }
示例#2
0
/**
 * The default exception handler
 *
 * @param object $oException The exception object
 * @return void
 */
function ppi_exception_handler($oException)
{
    if (!$oException instanceof Exception) {
        return false;
    }
    $error = array();
    foreach (array('code', 'message', 'file', 'line', 'traceString') as $field) {
        $fieldName = "_{$field}";
        if (!property_exists($oException, $fieldName)) {
            continue;
        }
        if ($field == 'traceString') {
            $error['backtrace'] = $oException->{$fieldName};
        } else {
            $error[$field] = $oException->{$fieldName};
        }
    }
    try {
        if (!PPI_Registry::getInstance()->exists('PPI_Config')) {
            $oException->show_exceptioned_error($error);
            return;
        }
        $oConfig = PPI_Helper::getConfig();
        $error['sql'] = PPI_Helper::getRegistry()->get('PPI_Model::PPI_Model_Queries', array());
        // email the error with the backtrace information to the developer
        if (!isset($oConfig->system->log_errors) || $oConfig->system->log_errors != false) {
            // get the email contents
            $emailContent = $oException instanceof PPI_Exception ? $oException->getErrorForEmail($error) : '';
            $oLog = new PPI_Model_Log();
            $oLog->addExceptionLog(array('code' => $oException->_code, 'message' => $oException->_message, 'file' => $oException->_file, 'line' => $oException->_line, 'backtrace' => $error['backtrace'], 'post' => serialize($_POST), 'cookie' => serialize($_COOKIE), 'get' => serialize($_GET), 'session' => serialize($_SESSION), 'content' => $emailContent));
            if ($oConfig->system->email_errors) {
                //@mail($oConfig->system->developer_email, 'PHP Exception For '.getHostname(), $emailContent);
                //include CORECLASSPATH.'mail.php';
                //$mail = new Mail();
                //$mail->send();
            }
            // write the error to the php error log
            writeErrorToLog($error['message'] . ' in file: ' . $error['file'] . ' on line: ' . $error['line']);
            $oException->show_exceptioned_error($error);
        }
    } catch (PPI_Exception $e) {
        writeErrorToLog($e->getMessage());
    } catch (Exception $e) {
        writeErrorToLog($e->getMessage());
    } catch (PDOException $e) {
        writeErrorToLog($e->getMessage());
    }
    $oException->show_exceptioned_error($error);
    // @todo This should go to an internal error page which doesn't use framework components and show the error code
    //	ppi_show_exceptioned_error($error);
}
示例#3
0
 /**
  * Get the routes, either from the cache or newly from disk
  *
  * @return array
  */
 function getRoute()
 {
     $this->routes = file_get_contents(APPFOLDER . 'Config/routes.php');
     ppi_dump($this->routes, true);
     // Loop through the route array looking for wild-cards
     foreach ($this->routes as $key => $val) {
         // Convert wild-cards to RegEx
         $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
         // Does the RegEx match?
         if (preg_match('#^' . $key . '$#', $uri)) {
             // Do we have a back-reference?
             if (strpos($val, '$') !== FALSE and strpos($key, '(') !== FALSE) {
                 $val = preg_replace('#^' . $key . '$#', $val, $uri);
             }
             $this->_set_request(explode('/', $val));
             return;
         }
     }
     PPI_Helper::getRegistry()->set();
     return self::$_routes;
 }
示例#4
0
 /**
  * Returns the session object
  *
  * @return object PPI_Model_Session
  */
 protected function getRegistry()
 {
     return PPI_Helper::getRegistry();
 }
示例#5
0
    /**
     * Show this exception
     *
     * @param string $p_aError Error information from the custom error log
     * @return void
     */
    function show_exceptioned_error($p_aError = "")
    {
        $p_aError['sql'] = PPI_Helper::getRegistry()->get('PPI_Model::Query_Backtrace', array());
        if (!empty($p_aError)) {
            try {
                $logInfo = $p_aError;
                unset($logInfo['code']);
                $logInfo['sql'] = serialize($logInfo['sql']);
                $oModel = new PPI_Model_Shared('ppi_exception', 'id');
                $oModel->insert($logInfo);
            } catch (PPI_Exception $e) {
            } catch (Exception $e) {
            }
            try {
                $oEmail = new PPI_Email_PHPMailer();
                $oConfig = PPI_Helper::getConfig();
                $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                $userAgent = $_SERVER['HTTP_USER_AGENT'];
                $ip = $_SERVER['REMOTE_ADDR'];
                $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Not Available';
                if (isset($oConfig->system->error->email)) {
                    $emailBody = <<<EOT
Hey Support Team,
An error has occured. The following information will help you debug:

Message:    {$p_aError['message']}
Line:       {$p_aError['line']}
File:       {$p_aError['file']}
URL:        {$url}
User Agent: {$userAgent}
IP:         {$ip}
Referer:    {$referer}
Backtrace:  {$p_aError['backtrace']}

EOT;
                    $aErrorConfig = $oConfig->system->error->email->toArray();
                    $aEmails = array_map('trim', explode(',', $aErrorConfig['to']));
                    foreach ($aEmails as $email) {
                        $name = '';
                        if (strpos($email, ':') !== false) {
                            list($name, $email) = explode(':', $email, 2);
                        }
                        $oEmail->AddAddress($email, $name);
                    }
                    $fromEmail = $aErrorConfig['from'];
                    $fromName = '';
                    if (strpos($fromEmail, ':') !== false) {
                        list($fromName, $fromEmail) = explode(':', $fromEmail, 2);
                    }
                    $oEmail->SetFrom($fromEmail, $fromName);
                    $oEmail->Subject = $aErrorConfig['subject'];
                    $oEmail->Body = $emailBody;
                    $oEmail->Send();
                }
            } catch (PPI_Exception $e) {
            } catch (Exception $e) {
            }
        }
        $oApp = PPI_Helper::getRegistry()->get('PPI_App', false);
        if ($oApp === false) {
            $sSiteMode = 'development';
            $heading = "Exception";
            require SYSTEMPATH . 'View/fatal_code_error.php';
            echo $header . $html . $footer;
            exit;
        }
        $sSiteMode = $oApp->getSiteMode();
        if ($sSiteMode == 'development') {
            $heading = "Exception";
            $baseUrl = PPI_Helper::getConfig()->system->base_url;
            require SYSTEMPATH . 'View/code_error.php';
            echo $header . $html . $footer;
        } else {
            $oView = new PPI_View();
            $oView->load('framework/error', array('message' => $p_aError['message'], 'errorPageType' => '404'));
        }
        exit;
    }
示例#6
0
 function __construct()
 {
     $this->_uri = PPI_Helper::getRegistry()->get('PPI::Request_URI');
 }
示例#7
0
 /**
  * Obtain the list of default view variables
  *
  * @todo review making var names not HNC prefixed.
  * @param array $options
  * @return array
  */
 function getDefaultRenderValues(array $options, $p_oConfig)
 {
     $authData = PPI_Helper::getSession()->getAuthData();
     $oDispatch = PPI_Helper::getDispatcher();
     $request = array('controller' => $oDispatch->getControllerName(), 'method' => $oDispatch->getMethodName());
     return array('isLoggedIn' => !empty($authData), 'config' => $p_oConfig, 'request' => $request, 'input' => PPI_Helper::getInput(), 'authData' => $authData, 'baseUrl' => $p_oConfig->system->base_url, 'fullUrl' => PPI_Helper::getFullUrl(), 'currUrl' => PPI_Helper::getCurrUrl(), 'viewDir' => $options['viewDir'], 'actionFile' => $options['actionFile'], 'responseCode' => PPI_Helper::getRegistry()->get('PPI_View::httpResponseCode', 200), 'stylesheetFiles' => PPI_View_Helper::getStylesheets(), 'javascriptFiles' => PPI_View_Helper::getJavascripts(), 'authInfo' => $authData, 'aAuthInfo' => $authData, 'bIsLoggedIn' => !empty($authData), 'oConfig' => $p_oConfig);
 }