Ejemplo n.º 1
0
 function _countChildren(&$file, &$custom)
 {
     $config = $file->getConfig();
     // Setup file filter
     $fileFilter = new Moxiecode_BasicFileFilter();
     //$fileFilter->setDebugMode(true);
     $fileFilter->setIncludeDirectoryPattern($config['filesystem.include_directory_pattern']);
     $fileFilter->setExcludeDirectoryPattern($config['filesystem.exclude_directory_pattern']);
     $fileFilter->setIncludeFilePattern($config['filesystem.include_file_pattern']);
     $fileFilter->setExcludeFilePattern($config['filesystem.exclude_file_pattern']);
     $fileFilter->setIncludeExtensions($config['filesystem.extensions']);
     $subfiles =& $file->listFilesFiltered($fileFilter);
     $filecount = $dircount = 0;
     foreach ($subfiles as $subfile) {
         if ($subfile->isFile()) {
             $filecount++;
         } else {
             $dircount++;
         }
     }
     $custom["filecount"] = $filecount;
     $custom["dircount"] = $dircount;
 }
Ejemplo n.º 2
0
 /**
  * Verifies that the specified file is valid agains the filters specified in config.
  *
  * @param String $path Path to verify.
  * @param String $action Action to get config options by.
  * @param Array $config Name/Value array of config options.
  * @return int Reason why it was denied.
  */
 function verifyFile($file, $action = false, $config = false)
 {
     $config = $config ? $config : $file->getConfig();
     // Verify filesystem config
     $fileFilter = new Moxiecode_BasicFileFilter();
     $fileFilter->setIncludeDirectoryPattern($config['filesystem.include_directory_pattern']);
     $fileFilter->setExcludeDirectoryPattern($config['filesystem.exclude_directory_pattern']);
     $fileFilter->setIncludeFilePattern($config['filesystem.include_file_pattern']);
     $fileFilter->setExcludeFilePattern($config['filesystem.exclude_file_pattern']);
     $fileFilter->setIncludeExtensions($config['filesystem.extensions']);
     $this->_invalidFileMsg = "{#error.invalid_filename}";
     $status = $fileFilter->accept($file);
     if ($status != BASIC_FILEFILTER_ACCEPTED) {
         if ($status == BASIC_FILEFILTER_INVALID_NAME) {
             if ($file->isFile() && isset($config['filesystem.invalid_file_name_msg'])) {
                 $this->_invalidFileMsg = $config['filesystem.invalid_file_name_msg'];
             } else {
                 if (!$file->isFile() && isset($config['filesystem.invalid_directory_name_msg'])) {
                     $this->_invalidFileMsg = $config['filesystem.invalid_directory_name_msg'];
                 }
             }
             if (!$this->_invalidFileMsg) {
                 $this->_invalidFileMsg = "{#error.invalid_filename}";
             }
         }
         return $status;
     }
     // Verify action specific config
     $fileFilter = new Moxiecode_BasicFileFilter();
     if ($action) {
         if (isset($config[$action . '.include_directory_pattern'])) {
             $fileFilter->setIncludeDirectoryPattern($config[$action . '.include_directory_pattern']);
         }
         if (isset($config[$action . '.exclude_directory_pattern'])) {
             $fileFilter->setExcludeDirectoryPattern($config[$action . '.exclude_directory_pattern']);
         }
         if (isset($config[$action . '.include_file_pattern'])) {
             $fileFilter->setIncludeFilePattern($config[$action . '.include_file_pattern']);
         }
         if (isset($config[$action . '.exclude_file_pattern'])) {
             $fileFilter->setExcludeFilePattern($config[$action . '.exclude_file_pattern']);
         }
         if (isset($config[$action . '.extensions'])) {
             $fileFilter->setIncludeExtensions($config[$action . '.extensions']);
         }
     } else {
         return BASIC_FILEFILTER_ACCEPTED;
     }
     $status = $fileFilter->accept($file);
     if ($status != BASIC_FILEFILTER_ACCEPTED) {
         if ($status == BASIC_FILEFILTER_INVALID_NAME) {
             $this->_invalidFileMsg = "{#error.invalid_filename}";
             if ($file->isFile()) {
                 if (isset($config[$action . '.invalid_file_name_msg'])) {
                     $this->_invalidFileMsg = $config[$action . '.invalid_file_name_msg'];
                 }
             } else {
                 if (isset($config[$action . '.invalid_directory_name_msg'])) {
                     $this->_invalidFileMsg = $config[$action . '.invalid_directory_name_msg'];
                 }
             }
         }
         return $status;
     }
     return BASIC_FILEFILTER_ACCEPTED;
 }
Ejemplo n.º 3
0
 /**
  * Lists file.
  */
 function _getMediaInfo(&$man, $input)
 {
     $file =& $man->getFile($input["path"]);
     $config = $file->getConfig();
     $parent =& $file->getParentFile();
     $files = array();
     if ($parent->isDirectory()) {
         // Setup file filter
         $fileFilter = new Moxiecode_BasicFileFilter();
         //$fileFilter->setDebugMode(true);
         $fileFilter->setIncludeDirectoryPattern($config['filesystem.include_directory_pattern']);
         $fileFilter->setExcludeDirectoryPattern($config['filesystem.exclude_directory_pattern']);
         $fileFilter->setIncludeFilePattern($config['filesystem.include_file_pattern']);
         $fileFilter->setExcludeFilePattern($config['filesystem.exclude_file_pattern']);
         $fileFilter->setIncludeExtensions($config['filesystem.extensions']);
         $fileFilter->setOnlyFiles(true);
         // List files
         $files =& $parent->listFilesFiltered($fileFilter);
     }
     $match = false;
     $prev = "";
     $next = "";
     foreach ($files as $curfile) {
         if ($curfile->getAbsolutePath() == $file->getAbsolutePath()) {
             $match = true;
             continue;
         } else {
             if (!$match) {
                 $prev = $curfile->getAbsolutePath();
             }
         }
         if ($match) {
             $next = $curfile->getAbsolutePath();
             break;
         }
     }
     $ext = getFileExt($file->getName());
     // Input default size?
     $width = "425";
     $height = "350";
     // All types that getimagesize support
     $imagearray = array('gif', 'jpg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'jpc', 'jp2', 'jpx', 'jb2', 'swc', 'iff', 'wbmp', 'xbm');
     if (in_array($ext, $imagearray)) {
         $sizeinfo = @getimagesize($file->getAbsolutePath());
         if ($sizeinfo) {
             $width = $sizeinfo[0];
             $height = $sizeinfo[1];
         }
     }
     $result = new Moxiecode_ResultSet("name,path,url,size,type,created,modified,width,height,attribs,next,prev,custom");
     $custom = array();
     $man->dispatchEvent("onCustomInfo", array(&$file, "info", &$custom));
     $attribs = ($file->canRead() && checkBool($config["filesystem.readable"]) ? "R" : "-") . ($file->canWrite() && checkBool($config["filesystem.writable"]) ? "W" : "-");
     $url = $man->removeTrailingSlash($config['preview.urlprefix']) . $man->convertPathToURI($file->getAbsolutePath());
     $result->add(utf8_encode($file->getName()), $man->encryptPath($file->getAbsolutePath()), utf8_encode($url), $file->getLength(), $ext, date($config['filesystem.datefmt'], $file->getCreationDate()), date($config['filesystem.datefmt'], $file->getLastModified()), $width, $height, $attribs, $man->encryptPath($next), $man->encryptPath($prev), $custom);
     return $result->toArray();
 }
Ejemplo n.º 4
0
 function _filterFile(&$file, $input)
 {
     $config = $file->getConfig();
     // Setup file filter
     $fileFilter = new Moxiecode_BasicFileFilter();
     //$fileFilter->setDebugMode(true);
     $fileFilter->setIncludeDirectoryPattern($config['filesystem.include_directory_pattern']);
     $fileFilter->setExcludeDirectoryPattern($config['filesystem.exclude_directory_pattern']);
     $fileFilter->setIncludeFilePattern($config['filesystem.include_file_pattern']);
     $fileFilter->setExcludeFilePattern($config['filesystem.exclude_file_pattern']);
     $fileFilter->setIncludeExtensions($config['filesystem.extensions']);
     if (isset($input["only_dirs"]) && checkBool($input["only_dirs"])) {
         $fileFilter->setOnlyDirs(true);
     }
     return $fileFilter->accept($file) > 0;
 }