/** * Lists the themes available for the app * * @return Response */ public function listThemes(Request $request) { // list pages in the site $dir = app()->basePath() . '/' . env('THEMES_LOCATION'); // list files $arr = Utilities::listSpecificFiles($dir, 'theme.json'); $result = array(); foreach ($arr as $item) { // get contents of file $json = json_decode(file_get_contents($item)); // get location of theme $temp = explode('public/themes/', $item); $location = substr($temp[1], 0, strpos($temp[1], '/theme.json')); $json->location = $location; array_push($result, $json); } return response()->json($result); }
/** * Returns a list of specific files * * @param {string} $path the recipient's email address * @return {Array} list occurrences of a specific file (e.g. find all screenshot.png files in a directory) */ public static function listSpecificFiles($dir, $fileName) { $root = scandir($dir); if (!isset($result)) { $result = array(); } foreach ($root as $value) { if ($value === '.' || $value === '..' || $value === '.htaccess') { continue; } if (is_file("{$dir}/{$value}")) { $file = "{$dir}/{$value}"; // match against filename if ($value === $fileName) { $path = "{$dir}/{$value}"; $result[] = $path; } continue; } foreach (Utilities::listSpecificFiles("{$dir}/{$value}", $fileName) as $value) { $result[] = $value; } } return $result; }