Created
May 1, 2016 07:26
-
-
Save TakamiChie/6641af04425bfbedbc64f3cfd38feaca to your computer and use it in GitHub Desktop.
Pico0.8→1.0対応スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// set to Pico CMS root directory | |
require("lib/Pico.php"); | |
class Replacer extends Pico | |
{ | |
public function run(){ | |
$this->loadConfig(); | |
$files = $this->getFiles($this->getConfig("content_dir"), $this->getConfig("content_ext")); | |
foreach ($files as $file) { | |
echo "> $file\n"; | |
$lines = file_get_contents($file); | |
$lines = preg_replace_callback("|/\*(.*)\*/(.*)|mis", function($matches){ | |
echo "replacing.\n"; | |
$metaa = explode("\n", $matches[1]); | |
$meta = ""; | |
foreach ($metaa as $m) { | |
$meta .= trim($m) . "\n"; | |
} | |
$meta = trim($meta); | |
$description = trim($matches[2]); | |
if(substr_count($meta, "Description") <= 0) { | |
if(substr_count($description, "\n") > 0) { | |
$meta .= "\nDescription: | \n " . implode("\n ", explode("\n", $description)); | |
}else{ | |
$meta .= "\nDescription: $description"; | |
} | |
} | |
return "---\n$meta\n---\n$description"; | |
}, $lines); | |
file_put_contents($file, $lines); | |
echo "done.\n\n"; | |
} | |
echo "finished!\n"; | |
} | |
} | |
(new Replacer( | |
__DIR__, // root dir | |
'config/', // config dir | |
'plugins/', // plugins dir | |
'themes/' // themes dir | |
))->run(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment