Exemplo n.º 1
0
 public function init()
 {
     $dbParams = ['driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'dbname' => $this->dbname, 'charset' => 'utf8mb4'];
     $this->pathProxy = $this->path . DIRECTORY_SEPARATOR . 'proxy';
     if (!is_dir($this->pathCache)) {
         File::createDirectory($this->pathCache);
     }
     if (!is_dir($this->pathProxy)) {
         File::createDirectory($this->pathProxy);
     }
     $config = new Configuration();
     $cache = new \Doctrine\Common\Cache\FilesystemCache($this->pathCache);
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver($this->path);
     $config->setMetadataDriverImpl($driverImpl);
     $config->setProxyDir($this->pathProxy);
     $config->setProxyNamespace('app\\tables\\proxy');
     if ($this->applicationMode == "development") {
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $config->setAutoGenerateProxyClasses(false);
     }
     $this->doctrine = EntityManager::create($dbParams, $config);
 }
Exemplo n.º 2
0
 /**
  * Sube imagen de perfil y background de usuario.
  *
  * @param Request $request [description]
  *
  * @return [String] [Url de la imagen]
  */
 public function upload(Request $request)
 {
     $v = \Validator::make($request->all(), ['file' => 'image']);
     if ($v->fails()) {
         return $v->errors()->toJson();
     }
     return File::section('profile_img')->upload($request->file('file'));
 }
Exemplo n.º 3
0
 public function __construct()
 {
     $this->path = MAIN_DIRECTORY . DIRECTORY_SEPARATOR . 'log';
     if (!is_dir($this->path)) {
         File::createDirectory($this->path, $this->dirMode, true);
     }
     $this->logFile = $this->path . DIRECTORY_SEPARATOR . 'app.log';
     $this->log = new Logger('app');
     $webProcessor = new WebProcessor();
     $format = "[%datetime%] %channel%.%level_name%: %message% %extra.ip% %extra.http_method% %context% %extra%\n";
     $formatter = new LineFormatter($format, null, true);
     $logRotate = new RotatingFileHandler($this->logFile, 45, Logger::INFO, true, 0777);
     $logRotate->setFormatter($formatter);
     $this->log->pushHandler($logRotate);
     $this->log->pushProcessor($webProcessor);
 }
Exemplo n.º 4
0
    public function show($segments)
    {
        $entry = array();
        $data = DB::query('select webcams.title, webcams.caption, webcams.code, webcams.location, users.username, users.title as user_title
			from webcams 
			join users on users.id = webcams.user_id 
			where webcams.code = \'' . $segments[1] . '\'', 1);
        if ($data) {
            $files = File::dir_content(PATH_WEBCAM . $data['username'], '', 'lastsnap.jpg');
            $dotssize = 16;
            $dotssize = count($files);
            $select = array();
            if (count($files)) {
                sort($files);
                foreach ($files as $i => $file) {
                    $tmp = stat(PATH_WEBCAM . $data['username'] . '/' . $file);
                    if (isset($segments[2]) && isset($segments[3])) {
                        if ($tmp[9] >= $segments[2] && $tmp[9] <= $segments[3]) {
                            //$select[] = array($tmp[9],date('Y m d H:i:s',$tmp[9]),timespan($tmp[9]));
                        } else {
                            unset($files[$i]);
                        }
                    } else {
                        if ($i == count($files) - 1) {
                            $segments[3] = $tmp[9];
                        }
                    }
                    $select[] = array($tmp[9], date('Y m d H:i:s', $tmp[9]), timespan($tmp[9]));
                }
                if ($segments[4] == null) {
                    $segments[4] = 1000;
                }
                if ($segments[5] == null) {
                    $segments[5] = 500;
                }
                $stat = stat(PATH_WEBCAM . $data['username'] . '/' . $files[count($files) - 1]);
                $entry = $data;
                $entry['count'] = count($files);
                $entry['timespan'] = timespan($stat[9]);
                //$entry['files'] = array_slice($files,count($files)-$dotssize,count($files));
                $entry['files'] = $files;
            }
        }
        return array('view' => 'webcams/show', 'select' => $select, 'segments' => $segments, 'entry' => $entry);
    }
Exemplo n.º 5
0
 /**
  * upload
  * this method allows uploading one or more than one file
  * @param  [object] $files catains all the file information
  * @return [array] returns an array with the file(s) uploaded
  */
 public function upload($files)
 {
     //checking if it's just one file
     if ($files instanceof UploadedFile) {
         $many = false;
         //more than one file
     } elseif (is_array($files)) {
         $many = true;
         //there was no files selected
     } else {
         return '';
     }
     //one file validation
     if (!$many) {
         $files = [$files];
     }
     /**
      * $uploaded
      * It is the array that will contains all the uploaded files information
      * @var array
      */
     $uploaded = [];
     foreach ($files as $file) {
         $info = (object) pathinfo(strtolower($file->getClientOriginalName()));
         $options = (object) $this->options;
         //setting file path
         $path = [storage_path(), self::$default_path, $options->path];
         if (@$options->code && \Auth::check()) {
             $path[] = \Auth::id();
         }
         //user folder
         if (@$options->subpath) {
             $path[] = $options->subpath;
         }
         //file type validation - if file type or any file type are allowed
         if ((!isset($options->valid) || preg_match($options->valid, '.' . $info->extension)) && $file->isValid()) {
             //subfolder
             $path = implode('/', $path);
             //destiny file
             $file_destiny = md5(time()) . '.' . $info->extension;
             //folder validation - if there is not folder, it will be created
             if (!is_dir($path)) {
                 mkdir($path, 0777, true);
             }
             //uploading file
             $return = $file->move($path, $file_destiny);
             //normalization of the file sent
             $this->normalice("{$path}/{$file_destiny}");
             //keeping the uploaded file path
             $uploaded[] = explode(self::$default_path, str_replace('\\', '/', $return))[1];
         } else {
             $MaxFilesize = File::formatBytes($file->getMaxFilesize());
             $uploaded[] = "Error: " . trans('globals.file_upload_error', ['MaxFilesize' => $MaxFilesize]);
         }
     }
     return $many ? $uploaded : $uploaded[0];
 }
Exemplo n.º 6
0
 /**
  *   upload the software file in txt format.
  *
  *   @param Resquest     file to upload
  *
  *   @return string
  */
 public function upload_software(Request $request)
 {
     $v = Validator::make($request->all(), ['file' => 'mimes:zip,rar']);
     if ($v->fails()) {
         return $v->errors()->toJson();
     }
     return 'README.7z';
     return File::section('product_software')->upload($request->file('file'));
 }
Exemplo n.º 7
0
$segments = array_values(array_filter(explode('/', $request_uri)));
$missing_page = '../views/missing.html';
$link = false;
$mode = isset($segments[1]) && $segments[1] == 'views' ? 'include' : 'app';
use App\Helpers\DB;
use App\Helpers\File;
if ($segments[0] == 'webcams' && isset($segments[1])) {
    if (defined('DBPASS')) {
        $link = DB::connect(DBHOST, DBUSER, DBPASS, DBNAME);
    }
    $data = DB::query('select webcams.title, webcams.caption, webcams.code, webcams.location, users.username, users.title as user_title
		from webcams 
		join users on users.id = webcams.user_id 
		where webcams.code = \'' . $segments[1] . '\'', 1);
    if ($data) {
        $files = File::dir_content(PATH_WEBCAM . $data['username'], '', 'lastsnap.jpg');
        $config['og'] = array('title' => $data['title'], 'description' => $data['caption'], 'url' => 'http://social.devmeta.net/webcams/' . $data['code'], 'image' => 'http://social.devmeta.net/upload/webcams/' . $data['username'] . '/' . $files[count($files) - 1]);
    }
}
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    if ($mode == 'app') {
        if (defined('DBPASS')) {
            $link = DB::connect(DBHOST, DBUSER, DBPASS, DBNAME);
        }
        $uname = $segments[0];
        $umethod = "";
        if (strpos($uname, '-') > -1) {
            $umethod = substr(strstr($uname, '-'), 1);
            $uname = strstr($uname, '-', true);
        }
        $controller = $uname;
Exemplo n.º 8
0
 /**
  * Sube uno o varios archivos
  * @param  String $files    archivo(s) a subir
  * @return String/array     Url o array de urls de archivo(s) subido(s)
  */
 public function upload($files)
 {
     if ($files instanceof UploadedFile) {
         $many = false;
     } elseif (is_array($files)) {
         $many = true;
     } else {
         return '';
     }
     if (!$many) {
         $files = [$files];
     }
     $uploaded = [];
     foreach ($files as $file) {
         $info = (object) pathinfo($file->getClientOriginalName());
         $options = (object) $this->options;
         #Se configura el path con los datos pasados
         $path = [storage_path(), self::$default_path, $options->path];
         if (@$options->code && \Auth::check()) {
             $path[] = \Auth::id();
         }
         //Carpeta de usuario
         if (@$options->subpath) {
             $path[] = $options->subpath;
         }
         #validamos si se permite cualquier archivo o si el tipo de archivo esta permitido
         if ((!isset($options->valid) || preg_match($options->valid, '.' . $info->extension)) && $file->isValid()) {
             //subcarpeta
             $path = implode('/', $path);
             #archivo destino
             $file_destiny = md5(time()) . '.' . $info->extension;
             #Si no existe directorio se crea
             if (!is_dir($path)) {
                 mkdir($path, 0777, true);
             }
             #Se sube la imagen
             $return = $file->move($path, $file_destiny);
             $this->normalice("{$path}/{$file_destiny}");
             #guarda la ruta de la imagen subida
             $uploaded[] = explode(self::$default_path, str_replace('\\', '/', $return))[1];
         } else {
             $MaxFilesize = File::formatBytes($file->getMaxFilesize());
             $uploaded[] = "Error: " . trans('globals.file_upload_error', ['MaxFilesize' => $MaxFilesize]);
         }
     }
     return $many ? $uploaded : $uploaded[0];
 }