Пример #1
0
 public function uploadImage($image, $alt)
 {
     try {
         $file = new File($image, 10000);
         $uploadDir = ASSETS . 'uploads/portfolio/gallery/';
         $tmp = ASSETS . 'uploads/portfolio/tmp/';
         $file->setUploadDir($tmp);
         $fileSaver = new FileSaver($file);
         if (!$file->isNormalSize()) {
             throw new \Exception('Very big file size');
         }
         if (!$fileSaver->save()) {
             throw new \Exception('File not selected');
         }
         if (!ImageHelper::isImage($fileSaver->uploadedFile, ['gif', 'png', 'jpg', 'jpeg'])) {
             throw new \Exception('File is not image');
         }
         if (file_exists($uploadDir . $file->getName())) {
             $uniqName = FileHelper::getUniqFileName($uploadDir, FileHelper::getFileExtension($file->getName()));
             $file->setName($uniqName);
         }
         FileHelper::move($fileSaver->uploadedFile, $uploadDir . $file->getName());
         $db = Service::get('db');
         $query = 'INSERT INTO ' . self::getTable() . '(name, alt) VALUES (:name, :alt)';
         $stmt = $db->prepare($query);
         if (!$stmt->execute([':name' => $file->getName(), ':alt' => $alt])) {
             throw new \Exception('File not saved into DB');
         }
         Service::get('session')->setFlushMsg('success', 'File successfully downloaded');
     } catch (\Exception $e) {
         Service::get('session')->setFlushMsg('error', $e->getMessage());
         $response = new ResponseRedirect(Request::getHost() . '/admin');
         $response->send();
     }
 }
Пример #2
0
 public function getRouteClosure()
 {
     return function ($name) {
         $routes = Service::getConfig('routes');
         foreach ($routes as $routeName => $rContent) {
             if ($name == $routeName) {
                 $result = Request::getHost() . $rContent['pattern'];
                 return $result;
             }
         }
         return '';
     };
 }
Пример #3
0
 public function generateRoute($name)
 {
     $routes = Service::getConfig('routes');
     return array_key_exists($name, $routes) ? Request::getHost() . $routes[$name]['pattern'] : NULL;
 }
Пример #4
0
 public function run()
 {
     //print_r($_SERVER);
     $logger = Service::get('logger');
     $router = Service::get('router');
     $route = $router->attemptToFindRoute();
     //Service::get('logger')->log(Password::hash('mirana1111'));
     //print_r($route);
     //Service::get('security')->clear();
     //$size = ImageHelper::getImageSize('C:\xampp\htdocs\portfolio\web\uploads\portfolio\gallery\2.jpg');
     //Service::get('logger')->log($size[1]);
     try {
         if (empty($route)) {
             throw new HttpNotFoundException();
         } else {
             if (isset($route['security'])) {
                 $user = Service::get('security')->getUser();
                 if (isset($route['security']['login_route'])) {
                     Service::get('security')->loginRoute = $route['security']['login_route'];
                 }
                 if (is_null($user)) {
                     $host = Request::getHost();
                     $redirect = new ResponseRedirect($host . Service::get('security')->loginRoute);
                     $redirect->send();
                 }
                 $role = $route['security']['role'];
                 if ($role !== $user->role) {
                     Service::get('session')->setFlushMsg('warning', '�� ���������� ����');
                     $host = Request::getHost();
                     $redirect = new ResponseRedirect($host);
                     $redirect->send();
                 }
                 /*
                                    $c = 0;
                                    for ( ; ; )
                                    {
                                        if ($c > count($routeSecurity) - 1)
                                        {
                                            break;
                                        }
                 
                                        switch($routeSecurity[$c])
                                        {
                                            case 'ROLE_USER':
                                                $user = $security->getUser();
                                                if(is_null($user))
                                                {
                                                    $host = Request::getHost();
                                                    $redirect = new ResponseRedirect($host.$security->loginRoute);
                                                    $redirect->send();
                                                    break;
                                                }
                                                else
                                                {
                 
                                                    break;
                                                }
                                            //continue security
                                        }
                                        ++$c;
                                    }
                 */
             }
             $controllerClass = $route['controller'];
             if (!class_exists($controllerClass)) {
                 $logger->log('Maybe it`s problem with incorrect routes', 'FATAL');
                 throw new ServerException('CrAsHeD!!!! SERVER ERROR', 500);
             }
             $controller = new $controllerClass();
             $action = $route['action'] . 'Action';
             if (!method_exists($controller, $action)) {
                 $logger->log('Maybe it`s problem with incorrect routes', 'FATAL');
                 throw new ServerException('CrAsHeD!!!! SERVER ERROR', 500);
             }
             $reflMethod = new \ReflectionMethod($controllerClass, $action);
             $response = $reflMethod->invokeArgs($controller, isset($route['variables']) ? $route['variables'] : []);
             $response->send();
         }
     } catch (HttpNotFoundException $e) {
         $e->show404page();
     } catch (ServerException $e) {
         $e->crashed();
     } catch (DatabaseException $e) {
         die('Database error: ' . $e->getMessage());
     } catch (\Exception $e) {
     }
     // print_r(Post::find('all'));
     //$request = Service::get('request');
     //echo $request->getFullUrl();
     /*
     $htmlPurifierBuilder = new HtmlPurifierBuilder();
     $purifier = $htmlPurifierBuilder->execute();
     $purifier->delInvalidTags(true);
     echo $purifier->purify('<script> awdasfasfafa</script>');
     */
     //$logger = Service::get('logger');
     //$logger->log('suck');
     //print_r($route);
     // $test = new TestController();
     // echo $test->generateRoute('add_post');
     // $response = $test->render('ok.html');
     // $response->send();
 }
Пример #5
0
        echo \Framework\Request\Request::getHost() . '/uploads/portfolio/gallery/' . $image->name;
        ?>
"></td>
                        <td> <span style="border: 1px black dotted; border-radius: 5px;"><?php 
        echo $image->id;
        ?>
</span></td>
                        <td style="text-align: center"><?php 
        echo $image->name;
        ?>
</td>
                        <td style="text-align: right"><a href="/delete/<?php 
        echo $image->id;
        ?>
"><img src="<?php 
        echo \Framework\Request\Request::getHost() . '/images/glyphicons/glyphicons_remove.png';
        ?>
" alt="delete"></a></td>
                    </tr>

                <?php 
    }
}
?>
                </table>
            </div>

        </div>

    </div>