Example #1
0
 public function index($page = 1)
 {
     $page = (int) $page;
     $sortField = Request::get('field', 'created_at');
     $orderMethod = strtoupper(Request::get('order', 'desc'));
     $notify = ['error' => null, 'message' => null];
     $comment = new \App\Model\Comment();
     try {
         if (Request::post('comment')) {
             $name = Request::post('name');
             $email = Request::post('email');
             $homepage = Request::post('homepage');
             $captcha = Request::post('captcha');
             $csrToken = Request::post('csrf_token');
             $ip = Request::getIp();
             $agent = Request::getUseAgent();
             $message = Request::post('message');
             if (!Protection::validateCsrfToken($csrToken)) {
                 throw new \Exception('Error token validation');
             }
             if (empty($name)) {
                 throw new \Exception('Empty name');
             }
             if (!Captcha::validate($captcha)) {
                 throw new \Exception('Error validate captcha');
             }
             if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
                 throw new \Exception('Email not valid');
             }
             if (!empty($homepage) && !filter_var($homepage, FILTER_VALIDATE_URL)) {
                 throw new \Exception('Homepage is not valid');
             }
             if (empty($message)) {
                 throw new \Exception('Empty message');
             }
             $params = ['name' => $name, 'email' => $email, 'homepage' => $homepage, 'ip' => $ip, 'agent' => $agent, 'message' => $message, 'created_at' => time()];
             if (!$comment->save($params)) {
                 throw new \Exception('Error save comment');
             }
             $notify['message'] = 'Comment success add';
             unset($_POST);
         }
     } catch (\Exception $e) {
         $notify['error'] = $e->getMessage();
     }
     $commentList = [];
     try {
         if (!in_array($sortField, $comment->sortListAllow)) {
             throw new \Exception('Error validate field');
         }
         if (!in_array($orderMethod, $comment->orderListAllow)) {
             throw new \Exception('Error validate order parametr');
         }
         $commentList = $comment->commentList($page, $sortField, $orderMethod);
     } catch (\Exception $e) {
         $notify['error'] = $e->getMessage();
     }
     $this->render('index', ['commentList' => $commentList, 'commentCount' => $comment->getCount()['count'], 'pageCount' => \App\Model\Comment::PAGE_COUNT, 'page' => $page, 'notify' => $notify]);
 }
Example #2
0
 function byUrl($config = null, $url = null)
 {
     $cfg = $config;
     $parts_uri = explode('/', $url ? $url : Request::uri());
     if (end($parts_uri) == '') {
         unset($parts_uri[count($parts_uri) - 1]);
     }
     array_shift($parts_uri);
     $count_parts_uri = count($parts_uri);
     if (!$count_parts_uri) {
         $count_parts_uri = 1;
         $parts_uri = [0 => ''];
     }
     $data = array();
     $continue = false;
     $done = false;
     foreach ($cfg as $num => $route) {
         $data = array();
         $parts_route = explode('/', $route['pattern']);
         if (count($parts_route) != $count_parts_uri) {
             continue;
         }
         $cmbnd = array_combine($parts_route, $parts_uri);
         $continue = false;
         foreach ($cmbnd as $key => $value) {
             if (strlen($key) && $key[0] == ':') {
                 $key = substr($key, 1);
                 $data[$key] = $value;
                 continue;
             }
             if ($key != $value) {
                 $continue = true;
                 break;
             }
         }
         if ($continue) {
             continue;
         }
         $done = true;
         break;
     }
     if ($done) {
         $params = isset($route['params']) ? array_merge($data, $route['params']) : $data;
         $route['params'] = $params;
         list($controller, $method) = explode('/', $route['action']);
         $route['controller'] = $controller;
         $route['method'] = $method;
         return array_merge($this->config, $route);
     }
     return null;
 }
Example #3
0
 public function delete()
 {
     try {
         $family = new \App\Model\FamilyTree();
         $id = (int) Request::post('id');
         if (empty($id)) {
             throw new \Exception('Empty id');
         }
         if (!$family->delete($id)) {
             throw new \Exception('Error delete family');
         }
         $notify['message'] = 'delete family success';
     } catch (\Exception $e) {
         $notify['error'] = $e->getMessage();
     }
     header("Content-type: application/json");
     $this->render('add', ['notify' => $notify]);
 }
Example #4
0
 public function index()
 {
     $message = ['error' => null, 'content' => null];
     try {
         $route = \Aqua\Aqua::$app->getRouter();
         $config = \Aqua\Base\Config\Manager::get('router');
         $params = $route->byUrl($config, \Aqua\Base\Request::getUri());
         ob_start();
         $run = $this->run($params['controller'], $params['method'], $params['params']);
         if (!$run) {
             throw new \Exception('Error find action');
         }
         $message['content'] = ob_get_contents();
         ob_end_clean();
     } catch (\Exception $e) {
         header("HTTP/1.0 404 Not Found");
         $message['error'] = $e->getMessage();
     }
     $this->render('index', $message);
 }
Example #5
0
    <div class="control-group">
        <label class="control-label" for="captcha">captcha (Сколько букв с слове "три")</label>
        <div class="controls">
            <input name="captcha" id="captcha" type="text" placeholder="captcha" required value="<?php 
echo Html::escape(Request::post('captcha'));
?>
">
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" for="message">Message</label>
        <div class="controls">
            <textarea name="message" required cols="40" id="message" placeholder="You Message" rows="10"><?php 
echo Html::escape(Request::post('message'));
?>
</textarea>
        </div>
    </div>

    <div class="form-actions">
        <button type="submit" class="btn btn-success">Submit Message</button>
        <button type="reset" class="btn">Cancel</button>
    </div>

    <?php 
if (!empty($notify['error'])) {
    ?>
        <div style="color: red"><?php 
    echo $notify['error'];
Example #6
0
 public function getRootPath()
 {
     return Request::getDocumentRoot();
 }