View source
<?php
namespace Drupal\views_slideshow_cycle\Commands;
use Drush\Commands\DrushCommands;
use Drush\Drush;
class ViewsSlideshowCycleCommands extends DrushCommands {
public function downloadCycle() {
$this
->installLibrary('jQuery Cycle', 'libraries/jquery.cycle', 'jquery.cycle.all.js', 'https://raw.githubusercontent.com/malsup/cycle/3.0.3/jquery.cycle.all.js');
}
public function downloadJson2() {
$this
->installLibrary('JSON2', 'libraries/json2', 'json2.js', 'https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js');
}
public function downloadHoverIntent() {
$this
->installLibrary('jQuery HoverIntent', 'libraries/jquery.hoverIntent', 'jquery.hoverIntent.js', 'https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js');
}
public function downloadPause() {
$this
->installLibrary('jQuery Pause', 'libraries/jquery.pause', 'jquery.pause.js', 'https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js');
}
public function downloadLib() {
$this
->downloadCycle();
$this
->downloadHoverIntent();
$this
->downloadJson2();
$this
->downloadPause();
}
protected function installLibrary($name, $path, $filename, $url) {
if (!is_dir($path)) {
drush_op('mkdir', $path, 0755, TRUE);
$this
->logger()
->info(dt('Directory @path was created', [
'@path' => $path,
]));
}
$perms = substr(sprintf('%o', fileperms($path)), -4);
if ($perms !== '0755') {
Drush::process('chmod 755 ' . $path);
}
else {
$perms = NULL;
}
$dir = getcwd();
if (is_file($path . '/' . $filename)) {
$this
->logger()
->notice(dt('@name appears to be already installed.', [
'@name' => $name,
]));
}
elseif (drush_op('chdir', $path) && Drush::process('wget ' . $url)) {
$this
->logger()
->success(dt('The latest version of @name has been downloaded to @path', [
'@name' => $name,
'@path' => $path,
]));
}
else {
$this
->logger()
->warning(dt('Drush was unable to download the @name library to @path', [
'@name' => $name,
'@path' => $path,
]));
}
chdir($dir);
if ($perms) {
Drush::process('chmod ' . $perms . ' ' . $path);
}
}
}