Пример #1
0
 /**
  * Checks if the value is a file.
  * @return ValidationState 
  */
 public function validation()
 {
     parent::validation();
     if ($this->validationState->getError($this->fieldName) == null && !is_file(\Pvik\Core\Path::realPath($this->getPOST()))) {
         $this->validationState->setError($this->fieldName, 'Must be a valid file.');
     }
     return $this->validationState;
 }
Пример #2
0
 /**
  * Loads the given configs into \Pvik\Core\Config.
  * @param array $configPaths
  * @return \Pvik\Core\Core
  */
 public function loadConfig(array $configPaths)
 {
     foreach ($configPaths as $configPath) {
         Config::load(Path::realPath($configPath));
     }
     Log::writeLine('[Info] Loaded: ' . implode(",", $configPaths));
     return $this;
 }
Пример #3
0
 /**
  * Execute a view.
  * @param string $actionName
  * @param string $folder
  */
 protected function executeViewByAction($actionName, $folder = null)
 {
     if ($folder == null) {
         $folder = Config::$config['DefaultViewsFolder'];
     }
     $viewPath = Path::realPath($folder . $this->controllerName . '/' . $actionName . '.php');
     \Pvik\Core\Log::writeLine('Executing view: ' . $viewPath);
     $view = new View($viewPath, $this);
 }
Пример #4
0
 /**
  * 
  */
 public function __construct()
 {
     $this->logTrace = array();
     $date = new \DateTime();
     if (Config::$config['Log']['UseOneFile'] == false) {
         $generatedFilePath = Path::realPath('~/logs') . '/log-' . $date->getTimestamp() . '.txt';
     } else {
         $generatedFilePath = Path::realPath('~/logs/log-file.txt');
     }
     $this->logFileHandle = fopen($generatedFilePath, 'w');
 }
Пример #5
0
 /**
  * Updates the model.
  */
 public function update()
 {
     $fieldName = $this->fieldName;
     $field = $this->configurationHelper->getField($fieldName);
     // wrong 'UseField' configuration
     if (!isset($field['UseField']) || !$this->fieldDefinitionHelper->fieldExists($field['UseField'])) {
         throw new \Exception('PvikAdminTools: UseField for ' . $fieldName . ' is not set up correctly. UseField is missing or it the stated field does not exists.');
     }
     $useField = $field['UseField'];
     $this->model->{$fieldName} = filesize(\Pvik\Core\Path::realPath($this->getPOST($useField)));
 }
Пример #6
0
 /**
  * Starts the route manager
  * @throws \Pvik\Web\NoRouteFoundException
  */
 public function start()
 {
     if (Config::$config['UnderConstruction']['Enabled'] == true) {
         $this->executeUnderConstruction(Path::realPath(Config::$config['UnderConstruction']['Path']));
     } else {
         //Request::getInstance()->fetchUrl();
         $request = $this->findRoute();
         if ($request != null) {
             // start output buffering
             ob_start();
             $route = $request->getRoute();
             // execute controller
             ControllerManager::executeController($route['Controller'], $route['Action'], $request);
             // end output buffering and output the buffer
             echo ob_get_clean();
         } else {
             throw new \Pvik\Web\NoRouteFoundException('No route found for ' . $this->url);
         }
     }
 }
Пример #7
0
 /**
  * Logic for uploading a file.
  */
 public function uploadFileAction()
 {
     if ($this->checkPermission()) {
         $validationState = new ValidationState();
         $uploaded = false;
         // post data send
         if ($this->request->isPOST('submit')) {
             $folders = \Pvik\Core\Config::$config['PvikAdminTools']['FileFolders'];
             $selectedFolder = $this->request->getPOST('folder');
             $folderValid = false;
             foreach ($folders as $folder) {
                 if ($selectedFolder == $folder) {
                     $folderValid = true;
                     break;
                 }
             }
             if ($folderValid && isset($_FILES['file']) && $_FILES['file']['error'] == 0) {
                 $fileName = $_FILES['file']['name'];
                 if ($this->request->isPOST('name') && $this->request->getPOST('name') != '') {
                     $fileName = $this->request->getPOST('name');
                 }
                 $diretoryName = dirname(\Pvik\Core\Path::realPath($selectedFolder . $fileName));
                 if (!is_dir($diretoryName)) {
                     if (!mkdir($diretoryName, 0777, true)) {
                         $validationState->setError('File', 'error creating folder');
                     }
                 }
                 if ($validationState->isValid()) {
                     move_uploaded_file($_FILES['file']['tmp_name'], \Pvik\Core\Path::realPath($selectedFolder . $fileName));
                     $uploaded = true;
                 }
             } else {
                 $validationState->setError('File', 'error uploading');
             }
         }
         $this->viewData->set('ValidationState', $validationState);
         $this->viewData->set('Uploaded', $uploaded);
         $this->executeView();
     }
 }
Пример #8
0
 /**
  * Tries to load a class.
  * @param String $class  
  */
 protected function loadClass($class)
 {
     if ($class[0] !== '\\') {
         $class = '\\' . $class;
     }
     $name = $class;
     foreach ($this->getNamespaceAssociationList() as $namespace => $path) {
         if (strpos($name, $namespace . '\\') === 0) {
             // starts with
             $name = str_replace($namespace, $path, $name);
             break;
         }
     }
     $path = str_replace('\\', '/', $name);
     $path = str_replace('//', '/', $path);
     $path = Path::realPath($path . '.php');
     if (file_exists($path)) {
         require $path;
         if (class_exists('\\Pvik\\Core\\Log')) {
             Log::writeLine('[Include] ' . $path);
         }
         return true;
     }
 }
Пример #9
0
 /**
  * Tries to show an error page for an exception.
  * @param \Exception $exception 
  */
 public static function showErrorPage(\Exception $exception)
 {
     try {
         $exceptionClass = get_class($exception);
         $errorPages = Config::$config['ErrorPages'];
         if (isset($errorPages[$exceptionClass])) {
             $file = Path::realPath($errorPages[$exceptionClass]);
             if (file_exists($file)) {
                 self::executeErrorPage($exception, $file);
             } else {
                 throw new \Exception('Erropage ' . $file . ' not found');
             }
         } else {
             $file = Path::realPath($errorPages['Default']);
             if (file_exists($file)) {
                 self::executeErrorPage($exception, $file);
             } else {
                 throw new \Exception('Erropage ' . $file . ' not found');
             }
         }
     } catch (Exception $ex) {
         echo $ex->getMessage();
     }
 }
Пример #10
0
 /**
  * Shortcut to Path::realPath function
  * @param string $path
  * @return string
  */
 protected function realPath($path)
 {
     return Path::realPath($path);
 }