Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
adds directory listing to backend prime page
Browse files Browse the repository at this point in the history
  • Loading branch information
cdowdy committed Sep 12, 2017
1 parent 58ef541 commit 357e209
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 69 deletions.
94 changes: 54 additions & 40 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ var scriptPaths = [
'node_modules/lazysizes/lazysizes.min.js'
];

var ioLazyLoad = [
var nodeScripts = [
'node_modules/intersection-observer/intersection-observer.js',
'node_modules/iolazyload/dist/js/iolazy.min.js',
'./web/js/lazyload.js'
'node_modules/iolazyload/dist/js/iolazy.min.js'
];


Expand All @@ -28,73 +27,88 @@ gulp.task('browser-sync', function() {
});


// gulp.task('sass', function() {
// return gulp.src('./web/scss/app1.scss')
// .pipe($.sass({
// includePaths: sassPaths,
// outputStyle: 'compressed' // if css compressed **file size**
// })
// .on('error', $.sass.logError))
// .pipe($.autoprefixer({
// browsers: ['last 2 versions', 'ie >= 9']
// }))
// .pipe(gulp.dest('./web/css'))
// .pipe(gulp.dest('../../../../public/extensions/vendor/cdowdy/betterthumbs/css'))
// .pipe(browserSync .stream());
// });
gulp.task('sass', function() {
return gulp.src('./web/scss/main.scss')
.pipe($.sass({
includePaths: sassPaths,
outputStyle: 'compressed' // if css compressed **file size**
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'ie >= 9']
}))
.pipe( $.rename({
basename: "betterthumbs",
}))

.pipe(gulp.dest('../../../../public/extensions/vendor/cdowdy/betterthumbs/css') )
.pipe(gulp.dest('./web/css'))
.pipe(browserSync.stream());
});

gulp.task( 'docs_css', function () {
return gulp.src('./web/css/betterthumbs.css')
// .pipe($.concat('betterthumbs.files.css'))
// .pipe($.cssnano())
.pipe(cachebust.resources())
.pipe($.rename(function (path) {
path.basename += '.min';
return path;
}))
// .pipe(cachebust.resources())
// .pipe($.rename(function (path) {
// path.basename += '.min';
// return path;
// }))
.pipe(gulp.dest('../../../../public/extensions/vendor/cdowdy/betterthumbs/css'))
.pipe(gulp.dest('./web/css'))
});

gulp.task('docs_js', function () {
return gulp.src(['./web/js/betterthumbs.file.delete.js','./web/js/betterthumbs.prime.js' ])
return gulp.src(['./web/js/betterthumbs.file.delete.js','./web/js/betterthumbs.prime.js', './web/js/awesomplete.js' ])
.pipe($.concat('betterthumbs.js'))
.pipe($.uglify())
.pipe(cachebust.resources())
.pipe($.rename(function (path) {
path.basename += '.min';
return path;
}))
// .pipe(cachebust.resources())
// .pipe($.rename(function (path) {
// path.basename += '.min';
// return path;
// }))
.pipe(gulp.dest('../../../../public/extensions/vendor/cdowdy/betterthumbs/js'))
.pipe(gulp.dest('./web/js'))
});

gulp.task('ioLazyLoad', function () {
return gulp.src(ioLazyLoad)
.pipe($.concat('lazyLoad.js'))
.pipe($.uglify())
gulp.task( 'copy_assets', function() {
return gulp.src( scriptPaths )
.pipe(cachebust.resources())
.pipe($.rename(function (path) {
path.basename += '.min';
return path;
}))
// .pipe($.rename(function (path) {
// path.basename += '.min';
// return path;
// }))
.pipe(gulp.dest('../../../../public/extensions/vendor/cdowdy/betterthumbs/js'))
.pipe(gulp.dest('./web/js'))
});

gulp.task( 'copy_assets', function() {
return gulp.src( scriptPaths )
gulp.task( 'copynodeassets' , function () {
return gulp.src( nodeScripts )
.pipe(cachebust.resources())
.pipe($.uglify())
// .pipe($.rename(function (path) {
// path.basename += '.min';
// return path;
// }))
.pipe(gulp.dest('../../../../public/extensions/vendor/cdowdy/betterthumbs/js'))
// .pipe(gulp.dest('../../public/extensions/vendor/cdowdy/betterthumbs/js'))
.pipe(gulp.dest('./web/js'))
});

gulp.task('dev', ['sass'], function() {

browserSync.init({
proxy: "bolt-extensions.dev/bolt/"
});

gulp.watch(['./web/scss/**/**/*.scss'], ['sass']);
gulp.watch(['../templates/**/**/**.twig']).on('change', browserSync.reload);
});

gulp.task('default', ['sass'], function() {

gulp.watch(['./web/scss/**/*.scss'], ['sass']);
gulp.watch(['../templates/betterthumbs.docs.html.twig']).on('change', browserSync .reload);
gulp.watch(['../templates/betterthumbs.docs.html.twig']).on('change', browserSync.reload);
});


5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "NPM stuff for bolt betterthumbs docs page",
"main": "gulpfile.js",
"devDependencies": {
"gulp": "^3.9.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.0",
"gulp-cachebust": "0.0.6",
"gulp-concat": "^2.6.1",
Expand All @@ -19,7 +19,8 @@
},
"dependencies": {
"browser-sync": "^2.18.2",
"gulp-autoprefixer": "^3.1.0"
"gulp-autoprefixer": "^3.1.0",
"sanitize.css": "^4.1.0"
},
"scripts": {
"start": "gulp",
Expand Down
173 changes: 149 additions & 24 deletions src/Controller/BetterThumbsBackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public function connect( Application $app )
$ctr->post( '/files/delete/all', [ $this, 'deleteAll' ] )
->bind( 'betterthumbs_delete_all' );

$ctr->get( '/files/prime', [ $this, 'primeCache' ] )
$ctr->get( '/files/prime/{directory}', [ $this, 'primeCache' ] )
->assert( "directory", '.+' )
->value( "directory", "index" )
->bind( 'betterthumbs_prime' );

$ctr->post( '/files/prime/do', [ $this, 'doPrime' ] )
Expand Down Expand Up @@ -212,42 +214,47 @@ public function deleteAll( Application $app, Request $request )
*
* @return mixed
*/
public function primeCache( Application $app )
public function primeCache( Application $app, $directory )
{
$adapter = new Local( (new FilePathHelper( $app ) )->boltFilesPath() );
$filesystem = new Filesystem( $adapter );

$fileList = $filesystem->listContents( null, true );
if ( $directory == 'index' ) {
$fileList = $filesystem->listContents( null, false );
} else {
$fileList = $filesystem->listContents( $directory, false );

}

// load in the config helper and get the driver set in the config
$configHelper = new ConfigHelper( $this->config );
$imageDriver = $configHelper->setImageDriver();
// $configHelper = new ConfigHelper( $this->config );
// $imageDriver = $configHelper->setImageDriver();
// get the accepted mime types array
$expectedMimes = $this->checkAccpetedTypes( $imageDriver );
// $expectedMimes = $this->checkAccpetedTypes( $imageDriver );


$files = [];
// $files = [];

// only loop over objects in the filespath that are of the type 'file'
// don't get any images or files from the cache directory
// finally use flysystem, get each objects mimetype and compare it to the accepted ones
// found from $expectedMimes
foreach ( $fileList as $object ) {

if ( $object['type'] == 'file'
&& ! preg_match_all( '/^.cache\//i', $object['dirname'] )
&& in_array( strtolower( $filesystem->getMimetype( $object['path'] ) ), $expectedMimes )
) {

$files[] = [
'filename' => $object['basename'],
'located' => $object['dirname'],
'imagePath' => $object['path'],
'mimeType' => $filesystem->getMimetype( $object['path'] ),
// 'isCached' => $app['betterthumbs']->cache
];
}
}
// foreach ( $fileList as $object ) {
//
// if ( $object['type'] == 'file'
// && ! preg_match_all( '/^.cache\//i', $object['dirname'] )
// && in_array( strtolower( $filesystem->getMimetype( $object['path'] ) ), $expectedMimes )
// ) {
//
// $files[] = [
// 'filename' => $object['basename'],
// 'located' => $object['dirname'],
// 'imagePath' => $object['path'],
// 'mimeType' => $filesystem->getMimetype( $object['path'] ),
//// 'isCached' => $app['betterthumbs']->cache
// ];
// }
// }


$config = $this->config;
Expand All @@ -267,18 +274,63 @@ public function primeCache( Application $app )
}
}

$paths = $filesystem->listContents( null );
$dirs = $this->getAllDirectories($app, $paths );

if ( $directory == 'index') {
$directory = 'files';
}

$context = [

'allFiles' => $files,
// 'allFiles' => $files,
'allFiles' => $this->listFilesToPrime($app, $fileList),
'extConfig' => $selectOptions,
'presets' => $presetSettings,
'allDirectories' => $dirs,
'currentDir' => $directory,
'bthumbsRoute' => $this->buildProperExtensionPath($app)
];

return $app['twig']->render( '@betterthumbs/prime/betterthumbs.prime.html.twig', $context );
}

protected function listFilesToPrime( Application $app, $fileList )
{
$adapter = new Local( (new FilePathHelper( $app ) )->boltFilesPath() );
$filesystem = new Filesystem( $adapter );
// load in the config helper and get the driver set in the config
$configHelper = new ConfigHelper( $this->config );
$imageDriver = $configHelper->setImageDriver();
// get the accepted mime types array
$expectedMimes = $this->checkAccpetedTypes( $imageDriver );

$files = [];

// only loop over objects in the filespath that are of the type 'file'
// don't get any images or files from the cache directory
// finally use flysystem, get each objects mimetype and compare it to the accepted ones
// found from $expectedMimes
foreach ( $fileList as $object ) {

if ( $object['type'] == 'file'
&& ! preg_match_all( '/^.cache\//i', $object['dirname'] )
&& in_array( strtolower( $filesystem->getMimetype( $object['path'] ) ), $expectedMimes )
) {

$files[] = [
'filename' => $object['basename'],
'located' => $object['dirname'],
'imagePath' => $object['path'],
'mimeType' => $filesystem->getMimetype( $object['path'] ),
// 'isCached' => $app['betterthumbs']->cache
];
}
}

return $files;
}

/**
* @param Application $app
* @param $image
Expand Down Expand Up @@ -384,4 +436,77 @@ public function buildProperExtensionPath(Application $app )

return $dashboardRoute . '/' . $extensionsRoute ;
}

/**
* @param $app
* @param $fileList
* @return array
*/
protected function getAllDirectories( $app, $fileList )
{
$filesystem = $this->fsSetup( $app );

$files = [];

foreach ( $fileList as $object ) {
if ( $object['type'] == 'dir'
&& ! preg_match_all( '/.cache/i', $object['dirname'] )
&& ! preg_match_all( '/.cache/i', $object['basename'] )
) {

$listPaths = $filesystem->listContents( $object['path'], true );

$files[] = [
'directory' => $object,
'subdirectory' => $this->listFileSystemPaths( $listPaths )
];
}

}

return $files;

}

protected function listFileSystemPaths( $paths )
{
$pathsList = [];

foreach ( $paths as $object ) {
if ( $object['type'] == 'dir'
&& ! preg_match_all( '/.cache/i', $object['dirname'] )
&& ! preg_match_all( '/.cache/i', $object['basename'] )
) {
$pathsList[] = $object['path'];
}
}

return $pathsList;

}

/**
* @param Application $app
* @return Filesystem
*/
private function fsSetup( Application $app )
{
// for bolt's new filesystem since $app['resources'] and getPath() are deprecated in 3.3+
// and will be removed in 4.0

// if (Version::compare( '3.3.0', '>=')) {
// $boltFilesPath = $app['path_resolver']->resolve('files');
// } else {
// $boltFilesPath = $app['resources']->getPath( 'filespath' );
//
// }

// $boltFilesPath = $this->boltFilesPath($app);
$boltFilesPath = (new FilePathHelper( $app ) )->boltFilesPath() ;

$adapter = new Local( $boltFilesPath );
$filesystem = new Filesystem( $adapter );

return $filesystem;
}
}
Loading

0 comments on commit 357e209

Please sign in to comment.