Ejemplo n.º 1
0
 public function __construct()
 {
     if (!function_exists('curl_init')) {
         wasp_error('cURL Class - PHP was not built with --with-curl, rebuild PHP to use cURL.');
     }
     $this->timeout = 30;
     $this->_options = [];
     $this->useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1';
     $this->_auth_need = false;
 }
Ejemplo n.º 2
0
Archivo: ui.php Proyecto: cruide/wasp
 public function __call($method, $params = null)
 {
     $_ = null;
     try {
         if (!empty($params)) {
             $_ = call_user_func_array([$this->smarty, $method], $params);
         } else {
             $_ = call_user_func([$this->smarty, $method]);
         }
     } catch (UiException $e) {
         wasp_error($e->getMessage());
     }
     return $_;
 }
Ejemplo n.º 3
0
 protected function _clean_key($str)
 {
     if (!preg_match("/^[a-z0-9:_\\/-]+\$/i", $str)) {
         wasp_error("Your request {$str} contains disallowed characters.");
     }
     return $str;
 }
Ejemplo n.º 4
0
 /**
  * Show 401 error message
  * 
  */
 function show_error_401()
 {
     if (is_controller_exists('errors')) {
         redirect(['controller' => 'errors', 'method' => 'unauthorized']);
     }
     wasp_error('401 Unauthorized', null, null, 401);
 }
Ejemplo n.º 5
0
Archivo: app.php Proyecto: cruide/wasp
 private function _execute_services()
 {
     if (is_dir(SERVICES_DIR)) {
         $services = get_files_list(SERVICES_DIR, ['php']);
         if (array_count($services) > 0) {
             ksort($services);
             foreach ($services as $key => $val) {
                 $service_name = str_replace('.php', '', $key);
                 $service_class = '\\App\\Services\\' . studly_case($service_name);
                 try {
                     $tmp = new $service_class();
                 } catch (AppException $e) {
                     wasp_error($e->getMessage());
                 }
                 if ($tmp instanceof Service) {
                     $tmp->execute();
                 } else {
                     wasp_error('Incorrect instance of service class ' . $tmp->className());
                 }
                 unset($tmp);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     global $_REQUEST_URI;
     $superfluous = ['.html', '.htm', '.php5', '.php', '.php3', '.shtml', '.phtml', '.dhtml', '.xhtml', '.inc', '.cgi', '.pl', '.xml', '.js'];
     $this->uri = preg_replace("#/+#s", '/', $_REQUEST_URI);
     $this->uri = preg_replace(["#/\$#s", "#^/+#"], '', $this->uri);
     $this->uri = $this->request = str_replace($superfluous, '', $this->uri);
     $this->_load_routes();
     if (array_count(self::$regexps) > 0) {
         foreach (self::$regexps as $key => $val) {
             if (preg_match('#' . $val['regexp'] . '#is', $this->uri)) {
                 $this->uri = preg_replace('#' . $val['regexp'] . '#is', $val['replace'], $this->uri);
                 break;
             }
         }
     }
     if (preg_match("%[^a-z0-9\\/\\-\\.]%isu", $this->uri)) {
         wasp_error("Abnormal request: {$this->uri}", 500);
     }
     class_alias('\\Wasp\\Router', '\\Router');
     if (empty($this->uri)) {
         $this->controller = 'Index';
         $this->method = 'Default';
         $this->action = snake_case($this->controller) . '/' . snake_case($this->method);
         return;
     }
     $do = explode('/', $this->uri);
     $controller = isset($do[0]) ? $do[0] : null;
     $method = isset($do[1]) ? $do[1] : null;
     if (empty($controller) || !is_action_name($controller)) {
         $this->controller = 'Index';
         $this->method = 'Default';
     } else {
         $this->controller = studly_case($controller);
         if (empty($method) || !is_action_name($method)) {
             $this->method = 'Default';
         } else {
             $this->method = studly_case($method);
         }
     }
     $this->action = snake_case($this->controller, '-') . '/' . snake_case($this->method, '-');
     if ($this->controller == 'Coreinfo') {
         if ($this->method == 'Json') {
             $_ = new \stdClass();
             $_->name = CORE_NAME;
             $_->description = FRAMEWORK;
             $_->version = CORE_VERSION;
             $_->status = CORE_VERSION_NAME;
             $_->author = 'Tishchenko Alexander';
             if (!headers_sent()) {
                 header('Cache-Control: no-cache, must-revalidate');
                 header('Expires: ' . date('r', time() - 86400));
                 header(CONTENT_TYPE_JSON);
             }
             exit(json_encode($_));
         } else {
             if (!headers_sent()) {
                 header(CONTENT_TYPE_XML);
             }
             exit("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coreinfo>\n\t<name><![CDATA[" . CORE_NAME . "]]></name>\n\t<description><![CDATA[" . FRAMEWORK . "]]></description>\n\t" . "<version><![CDATA[" . CORE_VERSION . "]]></version>\n" . "\t<status><![CDATA[" . CORE_VERSION_NAME . "]]></status>\n" . "\t<author><![CDATA[Tishchenko Alexander]]></author>\n" . "</coreinfo>");
         }
     } else {
         if ($this->controller == 'Phpinfo' && DEVELOP_MODE) {
             phpinfo();
             exit;
         } else {
             if (!is_controller_exists($this->controller)) {
                 show_error_404();
             }
         }
     }
     array_shift($do);
     array_shift($do);
     $this->_set_get_params($do);
 }
Ejemplo n.º 7
0
 public function send($template)
 {
     $this->phpmail->MsgHTML($this->ui->fetch($template));
     try {
         $_ = $this->phpmail->send();
     } catch (\Wasp\Exception $e) {
         wasp_error($e->getMessage());
     }
     return $_;
 }
Ejemplo n.º 8
0
 function is_match($value, $validator)
 {
     if (function_exists($validator)) {
         return $validator($value);
     } else {
         wasp_error('Incorrect validator `' . $validator . '`');
     }
 }