Skip to content

Instantly share code, notes, and snippets.

@TakamiChie
Created May 1, 2016 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakamiChie/6641af04425bfbedbc64f3cfd38feaca to your computer and use it in GitHub Desktop.
Save TakamiChie/6641af04425bfbedbc64f3cfd38feaca to your computer and use it in GitHub Desktop.
Pico0.8→1.0対応スクリプト
<?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