/** * ========================================================================== * GET ALL FILE(S) RECURSIVELY * ========================================================================== * * -- CODE: ----------------------------------------------------------------- * * $files = Get::files( * 'some/path', * 'txt', * 'ASC', * 'update' * ); * * $files = Get::files( * 'some/path', * 'gif,jpg,jpeg,png', * 'ASC', * 'update' * ); * * $files = Get::files( * 'some/path', * 'txt', * 'ASC', * null, * 'key:path' // output only the `path` data * ); * * -------------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Desription * ---------- | ------- | -------------------------------------------------- * $folder | string | Path to folder of file(s) you want to be listed * $e | string | The file extension(s) * $order | string | Ascending or descending? ASC/DESC? * $sorter | string | The key of array item as sorting reference * $filter | string | Filter the resulted array by a keyword * $recursive | boolean | Get file(s) from a folder recursively? * ---------- | ------- | -------------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function files($folder = ASSET, $e = '*', $order = 'ASC', $sorter = 'path', $filter = "", $recursive = true) { $results = array(); $folder = rtrim(File::path($folder), DS); $e = $e ? explode(',', str_replace(' ', "", $e)) : true; if ($files = File::explore($folder, $recursive, true, false)) { if (strpos($filter, 'key:') === 0) { $s = explode(' ', substr($filter, 4), 2); $output = $s[0]; $filter = isset($s[1]) ? $s[1] : ""; $sorter = null; } else { $output = null; } foreach ($files as $k => $v) { $_k = File::B($k); $_kk = DS . str_replace($folder . DS, "", $k); if (!$filter || strpos(File::N($k), $filter) !== false) { if ($v === 1) { if ($e === true || $e === array('*') || Mecha::walk($e)->has(File::E($k))) { $o = File::inspect($k, $output); if (is_null($output)) { $o['is']['hidden'] = strpos($_k, '__') === 0 || strpos($_k, '.') === 0 || strpos($_kk, DS . '__') !== false || strpos($_kk, DS . '.') !== false; } $results[] = $o; } } else { if ($e === true || $e === array('/')) { $results[] = File::inspect($k, $output); } } } } unset($files, $_k, $_kk); return !empty($results) ? Mecha::eat($results)->order($order, $sorter)->vomit() : false; } return false; }
} } $filter = Request::get('q', ""); $filter = $filter ? Text::parse($filter, '->safe_file_name') : false; $takes = glob($d . DS . '*', GLOB_NOSORT); if ($filter) { foreach ($takes as $k => $v) { if (strpos(File::N($v), $filter) === false) { unset($takes[$k]); } } } if ($_files = Mecha::eat($takes)->chunk($offset, $config->per_page * 2)->vomit()) { $files = array(); foreach ($_files as $_file) { $files[] = File::inspect($_file); } $files = Mecha::eat($files)->order('ASC', 'path')->vomit(); unset($_files); } else { $files = false; } Config::set(array('page_title' => $speak->assets . $config->title_separator . $config->manager->title, 'offset' => $offset, 'files' => $files, 'pagination' => Navigator::extract($takes, $offset, $config->per_page * 2, $config->manager->slug . '/asset'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.asset.php')); Shield::lot('segment', 'asset')->attach('manager', false); }); /** * Asset Repair * ------------ */ Route::accept($config->manager->slug . '/asset/repair/(file|files):(:all)', function ($path = "", $old = "") use($config, $speak) { if (Guardian::get('status') !== 'pilot') {
/** * ========================================================================== * GET ADJACENT FILE(S) * ========================================================================== * * -- CODE: ----------------------------------------------------------------- * * $files = Get::adjacentFiles( * 'some/path', * 'txt', * 'ASC', * 'update' * ); * * -------------------------------------------------------------------------- * */ public static function adjacentFiles($folder = ASSET, $extensions = '*', $order = 'DESC', $sorter = 'path', $filter = "", $inclusive = false) { if (!file_exists($folder)) { return false; } $results = array(); $results_inclusive = array(); $extension = str_replace(' ', "", $extensions); $folder = rtrim(File::path($folder), DS); $files = strpos($extension, ',') !== false ? glob($folder . DS . '*.{' . $extension . '}', GLOB_NOSORT | GLOB_BRACE) : glob($folder . DS . '*.' . $extension, GLOB_NOSORT); if ($inclusive) { $files = array_merge($files, glob($folder . DS . '.*', GLOB_NOSORT)); } foreach ($files as $file) { if (is_file($file)) { if (!$filter) { $results_inclusive[] = File::inspect($file); } else { if (strpos(File::B($file), $filter) !== false) { $results_inclusive[] = File::inspect($file); } } $_file = str_replace($folder . DS, "", $file); if (strpos($_file, '__') !== 0 && strpos($_file, '.') !== 0) { if (!$filter) { $results[] = File::inspect($file); } else { if (strpos(File::B($file), $filter) !== false) { $results[] = File::inspect($file); } } } } } if ($inclusive) { unset($results); return !empty($results_inclusive) ? Mecha::eat($results_inclusive)->order($order, $sorter)->vomit() : false; } else { unset($results_inclusive); return !empty($results) ? Mecha::eat($results)->order($order, $sorter)->vomit() : false; } }
/** * ==================================================================== * INSPECT A ZIP FILE * ==================================================================== * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------ | ---------------------------------------------- * $key | string | Key of the resulted array data * $fallback | mixed | Fallback value if array value is not available * --------- | ------ | ---------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function inspect($key = null, $fallback = false) { $results = array(); if (self::$zip->open(self::$open) === true) { $results = array_merge(File::inspect(self::$open), array('status' => self::$zip->status, 'total' => self::$zip->numFiles)); for ($i = 0; $i < $results['total']; ++$i) { $data = self::$zip->statIndex($i); $data['name'] = str_replace(DS . DS, DS, File::path($data['name'])); $results['files'][$i] = $data; } self::$zip->close(); } if (!is_null($key)) { return Mecha::GVR($results, $key, $fallback); } return !empty($results) ? $results : $fallback; }
/** * ==================================================================== * GET IMAGE INFO * ==================================================================== * * -- CODE: ----------------------------------------------------------- * * var_dump(Image::take('photo.jpg')->getInfo()); * * -------------------------------------------------------------------- * * var_dump(Image::take(array('a.jpg', 'b.jpg'))->getInfo()); * * -------------------------------------------------------------------- * * echo Image::take('photo.jpg')->getInfo('width', 0); * * -------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ----- | ----------------------------------------------- * $key | mixed | Key of the resulted array data * $fallback | mixed | Fallback value if data does not exist * --------- | ----- | ----------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function getInfo($key = null, $fallback = false) { File::open(self::$placeholder)->delete(); if (is_array(self::$open)) { $results = array(); foreach (self::$open as $file) { $data = getimagesize($file); $results[] = array_merge(File::inspect($file), array('width' => $data[0], 'height' => $data[1], 'bits' => $data['bits'], 'mime' => $data['mime'])); } return $results; } else { $data = getimagesize(self::$open); $results = array_merge(File::inspect(self::$open), array('width' => $data[0], 'height' => $data[1], 'bits' => $data['bits'], 'mime' => $data['mime'])); if (!is_null($key)) { return isset($results[$key]) ? $results[$key] : $fallback; } return $results; } return false; }
/** * ==================================================================== * INSPECT A ZIP FILE * ==================================================================== * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------ | ---------------------------------------------- * $key | string | Key of the resulted array data * $fallback | mixed | Fallback value if array value is not available * --------- | ------ | ---------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function getInfo($key = null, $fallback = false) { $results = array(); $zip = new ZipArchive(); if (File::exist(self::$open) && $zip->open(self::$open)) { $results = array_merge(File::inspect(self::$open), array('status' => $zip->status, 'total' => $zip->numFiles)); for ($i = 0; $i < $results['total']; ++$i) { $results['files'][$i] = $zip->statIndex($i); } $zip->close(); } if (!is_null($key)) { return Mecha::GVR($results, $key, $fallback); } return !empty($results) ? $results : $fallback; }