/** * Recursive Glob (http://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file/17161106#17161106) * @param string $pattern Pattern to match against * @param integer [$flags = 0] Any flags to match against * @return array An array of filepaths that match against $pattern */ public static function rglob($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $files = array_merge($files, Secretary::rglob($dir . '/' . basename($pattern), $flags)); } return $files; }
if (!is_dir(dirname($file->path))) { // If the directory tree doesn't already exist mkdir(dirname($file->path), 0777, TRUE); // Recursively create it } file_put_contents(dirname($file->path) . "/" . basename($file->path, ".md") . ".html", $file->contents); // Now lets through the contents there } /* * So we've converted all markdown files - now what? What more do you people want from me?! * Fine we'll move your CSS, images, videos and all that other crap over. */ chdir("../source"); $all = Secretary::rglob('*.*'); // We start off by fetching every file $confs = Secretary::rglob('config.json'); // We get all config.json's $remaining = array_diff($all, $markdowns); // We remove the markdowns we found earlier, we don't want to copy them to the live site $remaining = array_diff($remaining, $confs); // We then remove all configs as well - we definitely don't want them going across CL::printDebug("Copying " . count($remaining) . " misc files to the upload folder."); CL::printDebug("Copying: "); foreach ($remaining as $filepath) { CL::printDebug($filepath, 1); $fileContents = file_get_contents($filepath); // This is a really dirty way to do it, and creates a nasty memory foot print - alternatives? chdir("../upload"); // Change to our upload if (!file_exists(dirname($filepath))) { // If the directory path for the file doesn't already exist, recursively make it