Remove migration scripts
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$oPDO = new PDO('mysql:dbname=blog;host=localhost;port=3311', 'root', 'root');
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
$aPosts = [];
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile, '.md');
|
||||
$aPosts[implode('-', array_slice(explode('-', $sBasename), 3))] = $sBasename;
|
||||
}
|
||||
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
$sContents = end($aParts);
|
||||
|
||||
|
||||
if (!isset($aYaml['id'])) {
|
||||
continue;
|
||||
}
|
||||
$iId = $aYaml['id'];
|
||||
|
||||
$sQuery = sprintf("SELECT start, end FROM wp_ai1ec_events WHERE post_id = %d", $iId);
|
||||
if ($oStatement = $oPDO->query($sQuery)) {
|
||||
foreach ($oStatement as $aRow) {
|
||||
$iStart = $aRow[0];
|
||||
$iEnd = $aRow[1];
|
||||
break;
|
||||
}
|
||||
$oStart = new DateTime();
|
||||
$oStart->setTimeStamp($iStart);
|
||||
$oEnd = new DateTime();
|
||||
$oEnd->setTimeStamp($iEnd);
|
||||
if ($oStart->diff($oEnd)->format('%a') > 1) {
|
||||
$sStart = $oStart->format('Y-m-d');
|
||||
$sEnd = $oEnd->format('Y-m-d');
|
||||
printf(" from %s to %s\n", $sStart, $sEnd);
|
||||
$aYaml['end_date'] = $sEnd;
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents);
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
}
|
||||
} else {
|
||||
echo "Not found!\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
$sContents = end($aParts);
|
||||
if (!preg_match_all('~\[caption(?:[^\]]+)width="([\d]+)"\]<img src="([^"]+)"(?: width="([^"]+)")? /> ([^\[]+)\[/caption\]~', $sContents, $aMatches, PREG_SET_ORDER)) {
|
||||
echo " no caption found\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($aMatches as $aMatch) {
|
||||
$sCaption = sprintf("{%% include caption.html\n width='%d'%s\n image='%s'\n text='%s'\n%%}", $aMatch[1], empty($aMatch[1]) ? null : sprintf("\n image-width='%d'", $aMatch[1]), $aMatch[2], $aMatch[4]);
|
||||
$sContents = str_replace($aMatch[0], $sCaption, $sContents);
|
||||
}
|
||||
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents);
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
}
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
$sConvert = <<<EOL
|
||||
8220="
|
||||
8221="
|
||||
8217='
|
||||
8230=!
|
||||
8216='
|
||||
8211=-
|
||||
8243="
|
||||
EOL;
|
||||
$aConversions = [];
|
||||
foreach (explode("\n", $sConvert) as $sConversion) {
|
||||
list($iCode, $sConversion) = explode('=', $sConversion);
|
||||
$aConversions[$iCode] = $sConversion;
|
||||
}
|
||||
|
||||
$aCharacters = [];
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
$sContents = end($aParts);
|
||||
if (!preg_match_all('/&#([\d]+);/', $sContents, $aMatches)) {
|
||||
echo " no special character\n";
|
||||
continue;
|
||||
}
|
||||
$aCurrentCharacters = array_unique($aMatches[1]);
|
||||
$aCharacters = array_merge($aCharacters, $aCurrentCharacters);
|
||||
$aCurrentCharacters = array_flip($aCurrentCharacters);
|
||||
foreach ($aConversions as $iCode => $sConversion) {
|
||||
unset($aCurrentCharacters[$iCode]);
|
||||
$sContents = str_replace(sprintf('&#%d;', $iCode), $sConversion, $sContents);
|
||||
}
|
||||
if (count($aCurrentCharacters) > 0) {
|
||||
printf(" unknown characters: %s", implode(', ', array_keys($aCurrentCharacters)));
|
||||
}
|
||||
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents);
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
}
|
||||
// echo implode("\n", array_unique($aCharacters));
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
$sContents = end($aParts);
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim(utf8_encode($sContents));
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
}
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sBase = 'http://localhost/jekyll/blog';
|
||||
|
||||
if (!isset($argv[1]) || !file_exists($argv[1])) {
|
||||
die('no comment file given!');
|
||||
}
|
||||
$aUrls = explode("\n", file_get_contents($argv[1]));
|
||||
|
||||
$aPosts = [];
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile, '.md');
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
if (isset($aYaml['id'])) {
|
||||
$aName = explode('-', $sBasename);
|
||||
$aPosts[$aYaml['id']] = [$sBasename, implode('-', array_slice($aName, 3))];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($aUrls as $sUrl) {
|
||||
$aUrl = explode('=', $sUrl);
|
||||
$sNewUrl = null;
|
||||
if (count($aUrl) > 1) {
|
||||
$sReference = trim(end($aUrl));
|
||||
if (is_numeric($sReference) && isset($aPosts[$sReference][0])) {
|
||||
$sName = $aPosts[$sReference][0];
|
||||
$aName = explode('-', $sName);
|
||||
$sNewUrl = sprintf('%s/%s/%s.html', $sBase, implode('/', array_slice($aName, 0, 3)), implode('-', array_slice($aName, 3)));
|
||||
} else {
|
||||
// printf(" %s\n", $sReference);
|
||||
$aOptions = [];
|
||||
foreach ($aPosts as $aPost) {
|
||||
if (strpos($aPost[1], $sReference) !== false) {
|
||||
$aName = explode('-', $aPost[0]);
|
||||
$aOptions[] = sprintf('%s/%s/%s.html', $sBase, implode('/', array_slice($aName, 0, 3)), implode('-', array_slice($aName, 3)));
|
||||
}
|
||||
}
|
||||
$iCount = count($aOptions);
|
||||
if ($iCount > 0) {
|
||||
$sNewUrl = implode(';', $aOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($sNewUrl) {
|
||||
printf("%s, %s\n", trim($sUrl), $sNewUrl);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
$aPosts = [];
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile, '.md');
|
||||
$aPosts[implode('-', array_slice(explode('-', $sBasename), 3))] = $sBasename;
|
||||
}
|
||||
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
$sContents = end($aParts);
|
||||
if (!preg_match_all('~/\?ai1ec_event=([\w\d-]+)(?:[^ ")]*)~', $sContents, $aMatches, PREG_SET_ORDER)) {
|
||||
echo " no local urls found\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($aMatches as $aMatch) {
|
||||
$sName = $aMatch[1];
|
||||
if (isset($aPosts[$sName])) {
|
||||
$sPost = $aPosts[$sName];
|
||||
printf(" substituting name (%s) with: %s\n", $sName, $sPost);
|
||||
$sContents = str_replace($aMatch[0], sprintf('{%% post_link %s %%}', $sPost), $sContents);
|
||||
} else {
|
||||
printf(" unknown name: %s\n", $sName);
|
||||
}
|
||||
}
|
||||
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents);
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
}
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sCollectionDir = '_old__gallery';
|
||||
$sGalleryDir = '_old_gallery';
|
||||
$sDataDir = '_data/_gallery';
|
||||
$sNewDataDir = '_data/gallery';
|
||||
|
||||
if (!file_exists($sNewDataDir)) {
|
||||
mkdir($sNewDataDir);
|
||||
}
|
||||
|
||||
foreach (glob($sCollectionDir . '/*.md') as $sFile) {
|
||||
$sGallery = basename($sFile, '.md');
|
||||
printf("%s..\n", $sGallery);
|
||||
|
||||
parseFile($sFile, $aYaml, $sContents);
|
||||
if (strpos($aYaml['title'], ' ') !== false) {
|
||||
$aYaml['title'] = sprintf('"%s"', $aYaml['title']);
|
||||
}
|
||||
$aYaml['date'] = date('Y-m-d', $aYaml['date']);
|
||||
if (isset($aYaml['end_date'])) {
|
||||
$aYaml['end_date'] = date('Y-m-d', $aYaml['end_date']);
|
||||
}
|
||||
unset($aYaml['highlight']);
|
||||
|
||||
$aPhotos = explode("\n", trim(str_replace('- ', null, file_get_contents(sprintf('%s/%s.yml', $sDataDir, $sGallery)))));
|
||||
foreach ($aPhotos as $sName) {
|
||||
parseFile(sprintf('%s/%s/%s.md', $sGalleryDir, $sGallery, $sName), $aPhotoYaml, $sContents);
|
||||
if (isset($aPhotoYaml['date'])) {
|
||||
$aPhotoYaml['date'] = date('Y-m-d H:i:s', $aPhotoYaml['date']);
|
||||
}
|
||||
if (!empty($sContents)) {
|
||||
$aPhotoYaml['description'] = sprintf('"%s"', $sContents);
|
||||
}
|
||||
if (empty($aPhotoYaml['title']) == 'null') {
|
||||
unset($aPhotoYaml['title']);
|
||||
}
|
||||
unset($aPhotoYaml['gallery']);
|
||||
unset($aPhotoYaml['layout']);
|
||||
unset($aPhotoYaml['next']);
|
||||
unset($aPhotoYaml['previous']);
|
||||
unset($aPhotoYaml['ordering']);
|
||||
$aYaml['photos'][$sName] = $aPhotoYaml;
|
||||
}
|
||||
$sNewDataFile = sprintf('%s/%s.yml', $sNewDataDir, $sGallery);
|
||||
file_put_contents($sNewDataFile, trim(yamlDump($aYaml)));
|
||||
}
|
||||
|
||||
function parseFile($sFile, &$aYaml, &$sContents = null) {
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('---', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
$sContents = trim(next($aParts));
|
||||
}
|
||||
|
||||
function writeFile($sFile, $aYaml, $sContents) {
|
||||
file_put_contents($sFile, '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . $sContents);
|
||||
}
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
echo "[converting filenames]\n";
|
||||
$aReplace = [];
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sName = basename($sFile, '.md');
|
||||
printf("%s...\n", $sName);
|
||||
if (preg_match('/-[\d]+$/', $sName, $aMatch)) {
|
||||
$sSuffix = $aMatch[0];
|
||||
$sNewName = substr($sName, 0, -strlen($sSuffix));
|
||||
$sNewFile = sprintf('%s/%s.md', $sNewDir, $sNewName);
|
||||
if (file_exists($sNewFile)) {
|
||||
echo " duplicate, appending -x\n";
|
||||
$sNewName .= '-x';
|
||||
$sNewFile = sprintf('%s/%s.md', $sNewDir, $sNewName);
|
||||
}
|
||||
$aReplace[$sName] = $sNewName;
|
||||
copy($sFile, $sNewFile);
|
||||
} else {
|
||||
copy($sFile, sprintf('%s/%s.md', $sNewDir, $sName));
|
||||
}
|
||||
}
|
||||
|
||||
echo "[converting filenames]\n";
|
||||
foreach (glob(sprintf('%s/*.md', $sNewDir)) as $sFile) {
|
||||
$sName = basename($sFile, '.md');
|
||||
printf("%s...\n", $sName);
|
||||
$sContents = file_get_contents($sFile);
|
||||
foreach ($aReplace as $sName => $sNewName) {
|
||||
$iCount = substr_count($sContents, $sName);
|
||||
if ($iCount > 0) {
|
||||
printf(" %s > %s (%d)\n", $sName, $sNewName, $iCount);
|
||||
$sContents = str_replace($sName, $sNewName, $sContents);
|
||||
}
|
||||
}
|
||||
// file_put_contents($sFile, $sNewContents);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
$sContents = end($aParts);
|
||||
if (!preg_match_all('~<a href="([^"]+)"(?: title="([^"]+)")?>([^>]+)</a>~', $sContents, $aMatches, PREG_SET_ORDER)) {
|
||||
echo " no url found\n";
|
||||
continue;
|
||||
}
|
||||
foreach ($aMatches as $aMatch) {
|
||||
$sMarkdown = sprintf('[%s](%s%s)', $aMatch[3], $aMatch[1], empty($aMatch[2]) ? null : sprintf(' "%s"', $aMatch[2]));
|
||||
printf(" replacing: %s\n", $sMarkdown);
|
||||
$sContents = str_replace($aMatch[0], $sMarkdown, $sContents);
|
||||
}
|
||||
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents);
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
}
|
||||
// echo implode("\n", array_unique($aCharacters));
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
$a = 'D:\Todo\Gallery';
|
||||
$f = [];
|
||||
foreach (glob($a . '/*') as $b) {
|
||||
$b = basename($b);
|
||||
if (strpos($b, 'spain-2015') === 0) {
|
||||
foreach (glob($a . '/' . $b . '/*.jpg') as $c) {
|
||||
$f[basename($c)] = $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$d = 'D:\Rik\Photographs\Reis\Spanje 2015';
|
||||
$e = [];
|
||||
foreach (glob($d . '/*') as $b) {
|
||||
if ($b != '.' && $b != '..') {
|
||||
if (is_dir($b)) {
|
||||
foreach (glob($b . '/*.jpg') as $c) {
|
||||
$e[basename($c)] = $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$h = array_intersect_key($f, $e);
|
||||
$g = array_keys($h);
|
||||
|
||||
foreach ($h as $i => $x) {
|
||||
copy($e[$i], $x);
|
||||
}
|
||||
|
||||
print_r(array_keys(array_diff_key($f, $h)));
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
foreach (glob('gallery/*') as $sAlbumPath) {
|
||||
if (!is_dir($sAlbumPath)) continue;
|
||||
$sAlbum = basename($sAlbumPath);
|
||||
foreach (glob($sAlbumPath . '/*.md') as $sFile) {
|
||||
$sPhoto = basename($sFile);
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
if (isset($aYaml['file'])) {
|
||||
$sOriginal = basename($aYaml['file'], '.JPG');
|
||||
printf("[%s] %s = %s\n", $sAlbum, $sPhoto, $sOriginal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile, '.md');
|
||||
printf("%s\n", $sBasename);
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
$sRename = <<<EOF
|
||||
2013-12-08-guy-fawkes-bonfire 2013-11-05-guy-fawkes-bonfire
|
||||
2013-12-08-internationals-trip 2013-11-23-internationals-trip
|
||||
2013-12-08-visit-bram 2013-11-29-visit-bram
|
||||
2013-12-08-visit-dundee 2013-11-24-visit-dundee
|
||||
2013-12-08-visit-school-of-chemistry
|
||||
2013-12-08-whisky-tasting 2013-11-21-whisky-tasting
|
||||
2013-12-12-filmsoc-deep-red 2014-02-13-filmsoc-deep-red
|
||||
2013-12-12-filmsoc-howls-moving-castle 2013-11-07-filmsoc-howls-moving-castle
|
||||
2013-12-12-hi-there
|
||||
2014-01-12-christmas-holidays
|
||||
2014-01-27-cinema-dundee 2014-01-23-cinema-dundee
|
||||
2014-01-27-dinner-simone 2014-01-12-dinner-simone
|
||||
2014-01-27-glasgow
|
||||
2014-01-27-strathkinness 2014-01-25-strathkinness
|
||||
2014-01-28-explorations
|
||||
2014-01-28-laser-tag 2014-01-27-laser-tag
|
||||
2014-02-08-internationals-trip
|
||||
2014-02-08-whisky-tasting 2014-02-06-whisky-tasting
|
||||
2014-02-08-whisky-tasting-x 2014-02-27-whisky-tasting
|
||||
2014-02-21-internationals-dinner
|
||||
2014-02-21-whisky-tasting 2014-02-20-whisky-tasting
|
||||
2014-03-14-60-hour-film-blitz-screening 2014-03-13-60-hour-film-blitz-screening
|
||||
2014-03-14-ski-glenshee 2014-03-09-ski-glenshee
|
||||
2014-03-15-pancake-day-celebration 2014-03-05-pancake-day-celebration
|
||||
2014-03-15-week-10
|
||||
2014-03-19-cinema-dundee 2014-03-15-cinema-dundee
|
||||
2014-03-19-fish-and-chips 2014-03-14-fish-and-chips
|
||||
2014-03-19-goodbye-yusuke 2014-03-17-goodbye-yusuke
|
||||
2014-03-23-crail
|
||||
2014-04-08-whisky-tasting 2014-04-03-whisky-tasting
|
||||
2014-04-14-london 2014-04-10-london
|
||||
2014-04-18-whisky-tasting 2014-04-03-whisky-tasting
|
||||
2014-04-19-cinema-dundee 2014-04-06-cinema-dundee
|
||||
2014-04-21-easter-bbq 2014-04-20-easter-bbq
|
||||
2014-05-04-coastal-path
|
||||
2014-05-04-may-dip 2014-05-01-may-dip
|
||||
2014-05-18-whisky-tasting 2014-05-10-whisky-tasting
|
||||
2014-05-19-cinema-dundee 2014-05-18-cinema-dundee
|
||||
2014-05-19-jose-birthday-bbq 2014-05-16-jose-birthday-bbq
|
||||
2014-05-21-evening-run
|
||||
2014-05-23-anstruther 2014-05-18-edinburgh
|
||||
2014-05-25-edinburgh 2014-05-24-edinburgh
|
||||
2014-05-25-goodbye-julie 2014-05-24-goodbye-julie
|
||||
2014-06-04-birthday-holidays
|
||||
2014-06-09-beach-bbq 2014-06-09-beach-bbq 2014-06-06-beach-bbq 2014-06-09-beach-bbq
|
||||
2014-06-14-netherlands-spain 2014-06-13-netherlands-spain
|
||||
2014-06-24-hike-blair-athol 2014-06-22-hike-blair-athol
|
||||
2014-06-28-goodbye-hubert
|
||||
2014-06-29-car
|
||||
2014-06-29-cinema-dundee-x 2014-07-03-cinema-dundee-x
|
||||
2014-06-29-cinema-dundee 2014-06-28-cinema-dundee
|
||||
2014-06-30-world-cup
|
||||
2014-07-07-car
|
||||
2014-07-07-housewarming-bbq 2014-07-04-housewarming-bbq
|
||||
2014-07-13-cinema-dundee
|
||||
2014-07-20-car
|
||||
2014-08-25-summer-holidays 2014-08-14-summer-holidays
|
||||
2014-08-28-moving
|
||||
2014-08-31-moving
|
||||
2014-09-01-bike
|
||||
2014-09-02-risotto-night
|
||||
2014-09-07-freezer
|
||||
2014-09-09-congress-glasgow 2014-09-04-conference-glasgow
|
||||
2014-09-09-goodbye-alan 2014-08-29-goodbye-alan
|
||||
2014-09-10-car
|
||||
2014-09-14-sports
|
||||
2014-09-26-whisky-tasting 2014-09-25-whisky-tasting
|
||||
2014-09-27-autumn-holidays
|
||||
2014-10-05-italian-birthdays 2014-09-27-italian-birthdays
|
||||
2014-10-05-sports
|
||||
2014-10-05-weekend
|
||||
2014-10-10-whisky-tasting 2014-10-08-whisky-tasting
|
||||
2014-10-11-whisky-tasting 2014-11-06-whisky-tasting
|
||||
2014-10-15-whisky-tasting 2014-11-13-whisky-tasting
|
||||
2014-11-08-explorations
|
||||
2014-11-29-movember
|
||||
2014-12-05-christmas-lunch 2014-12-04-christmas-lunch
|
||||
2014-12-05-kerstsfeer
|
||||
2014-12-05-whisky-tasting 2014-12-04-whisky-tasting
|
||||
2014-12-16-oost-europees-feest 2014-12-13-oost-europees-feest
|
||||
2014-12-17-edinburgh-christmas-market 2014-12-14-edinburgh-christmas-market
|
||||
2015-01-05-christmas-holidays 2014-12-20-christmas-holidays
|
||||
2015-01-05-geneve
|
||||
2015-01-17-ikea 2015-01-18-ikea
|
||||
2015-01-20-basketball
|
||||
2015-02-01-bezoek-angela 2015-01-26-bezoek-angela
|
||||
2015-02-07-whisky-tasting 2015-02-05-whisky-tasting
|
||||
2015-02-14-chocolate-and-whisky-tasting 2015-02-12-chocolate-and-whisky-tasting
|
||||
2015-02-22-half-marathon
|
||||
2015-02-22-international-dinner 2015-02-21-international-dinner
|
||||
2015-02-22-whisky-tasting 2015-02-19-whisky-tasting
|
||||
2015-02-27-chemsoc-pub-quiz
|
||||
2015-03-01-muddy-explorations
|
||||
2015-03-07-whisky-tasting 2015-03-05-whisky-tasting
|
||||
2015-03-20-lazy-friday
|
||||
2015-03-22-60-hour-film-blitz-screening 2015-03-12-60-hour-film-blitz-screening
|
||||
2015-03-22-60-hour-film-blitz 2015-03-07-60-hour-film-blitz
|
||||
2015-03-22-goodbye-jan 2015-03-19-goodbye-jan
|
||||
2015-03-26-thursday-drinks
|
||||
2015-03-28-special-whisky-tasting 2015-03-26-special-whisky-tasting
|
||||
2015-04-03-whisky-tasting 2015-04-02-whisky-tasting
|
||||
2015-04-11-easter-lunch 2015-04-04-easter-lunch
|
||||
2015-04-11-spring-activities
|
||||
2015-04-12-round-the-houses
|
||||
2015-04-18-whisky-tasting 2015-04-16-whisky-tasting
|
||||
2015-04-19-night-run 2015-04-20-night-run
|
||||
2015-04-27-coastal-trail
|
||||
2015-04-27-may-dip 2015-05-01-may-dip
|
||||
2015-04-27-some-saturday
|
||||
2015-06-05-birthday-holidays 2015-05-28-birthday-holidays
|
||||
2015-06-05-goodbye-alba 2015-05-20-goodbye-alba
|
||||
2015-06-20-bbq-bonfire
|
||||
2015-06-20-beach-bbq
|
||||
2015-06-20-summer-activities
|
||||
2015-06-20-whisky-poker 2015-06-18-whisky-poker
|
||||
2015-07-13-spain
|
||||
2015-07-14-half-marathon 2015-07-12-half-marathon
|
||||
2015-07-19-aberdeen-and-dunnottar-castle
|
||||
2015-08-13-summer-holidays
|
||||
2015-08-21-northern-ireland 2015-08-15-northern-ireland
|
||||
2015-08-24-visit-sanne 2015-08-19-visit-sanne
|
||||
2015-08-26-car
|
||||
2015-08-27-whisky-poker 2015-08-26-whisky-poker
|
||||
2015-09-20-autumn-holidays 2015-09-12-autumn-holidays
|
||||
2015-10-05-chariots-of-fire-run 2015-10-04-chariots-of-fire-run
|
||||
2015-10-05-giffordtown-run 2015-09-28-giffordtown-run
|
||||
2015-10-06-running
|
||||
2015-10-12-hike-glen-clova
|
||||
2015-10-12-kingsbarn-distillery-tour 2015-10-11-kingsbarn-distillery-tour
|
||||
2015-10-15-whisky-poker 2015-10-14-whisky-poker
|
||||
2015-11-17-braids-hill-race
|
||||
2015-11-19-whisky-poker
|
||||
2015-11-20-whisky-tasting 2015-11-05-whisky-tasting
|
||||
2015-12-04-whisky-tasting 2015-12-03-whisky-tasting
|
||||
2015-12-06-coastal-path
|
||||
EOF;
|
||||
|
||||
$aRename = explode("\n", $sRename);
|
||||
foreach ($aRename as $i => $sRename) {
|
||||
unset($aRename[$i]);
|
||||
$aSplit = explode(' ', $sRename);
|
||||
if (count($aSplit) > 1) {
|
||||
list($sOld, $sNew) = explode(' ', $sRename);
|
||||
$aRename[$sOld] = $sNew;
|
||||
}
|
||||
}
|
||||
|
||||
$aPosts = [];
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile, '.md');
|
||||
$sContents = file_get_contents($sFile);
|
||||
|
||||
foreach ($aRename as $sOld => $sNew) {
|
||||
if (strpos($sContents, $sOld) !== false) {
|
||||
$sContents = str_replace($sOld, $sNew, $sContents);
|
||||
}
|
||||
}
|
||||
$sNewFile = sprintf('%s/%s.md', $sNewDir, $sBasename);
|
||||
|
||||
file_put_contents($sNewFile, $sContents);
|
||||
}
|
||||
|
||||
foreach ($aRename as $sOld => $sNew) {
|
||||
$sOldFile = sprintf('%s/%s.md', $sNewDir, $sOld);
|
||||
$sNewFile = sprintf('%s/%s.md', $sNewDir, $sNew);
|
||||
rename($sOldFile, $sNewFile);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
if (isset($argv[1])) {
|
||||
$sSourceDir = realpath(rtrim($argv[1]));
|
||||
unset($argv[1]);
|
||||
if (!is_dir($sSourceDir)) {
|
||||
die('Directory does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
require __DIR__ . '/generate-gallery-yaml.php';
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$oPDO = new PDO('mysql:dbname=blog;host=localhost;port=3311', 'root', 'root');
|
||||
|
||||
$sQuery = 'SELECT gid, path, title, galdesc FROM wp_ngg_gallery';
|
||||
if ($oStatement = $oPDO->query($sQuery)) {
|
||||
$aCommands = [];
|
||||
foreach ($oStatement as $aRow) {
|
||||
$iId = $aRow['gid'];
|
||||
$sTitle = $aRow['title'];
|
||||
$sPath = $aRow['path'];
|
||||
$sDescription = $aRow['galdesc'];
|
||||
$sQuery = sprintf('SELECT pid, filename, description, imagedate FROM wp_ngg_pictures WHERE galleryid = %d', $iId);
|
||||
$aFiles = [];
|
||||
if ($oStatement = $oPDO->query($sQuery)) {
|
||||
foreach ($oStatement as $aRow) {
|
||||
$iYear = substr($aRow['imagedate'], 0, 4);
|
||||
$aFiles[basename($aRow['filename'])] = [
|
||||
'id' => $aRow['pid'],
|
||||
'title' => '',
|
||||
'comment' => utf8_encode($aRow['description'])
|
||||
];
|
||||
}
|
||||
$sDir = str_replace('wp-content/gallery/', null, $sPath);
|
||||
if (preg_match('/-[\d]{4}/', $sDir, $aMatch)) {
|
||||
$sCleanDir = str_replace($aMatch[0], null, $sDir);
|
||||
} else {
|
||||
$sCleanDir = $sDir;
|
||||
}
|
||||
$sName = sprintf('%d-%s', $iYear, strtolower(str_replace(' ', '-', $sCleanDir)));
|
||||
$aYaml = getMetaYaml($sDir, false, $sName, $sTitle, utf8_encode($sDescription));
|
||||
$aYaml['id'] = $iId;
|
||||
$aYaml['files'] = $aFiles;
|
||||
$sGalleryDir = sprintf('%s/%s', $sSourceDir, $sDir);
|
||||
if (!is_dir($sGalleryDir)) {
|
||||
printf("Path does not exist: %s\n", $sGalleryDir);
|
||||
continue;
|
||||
}
|
||||
writeMetaYaml($sGalleryDir, $aYaml);
|
||||
$aCommands[] = sprintf('call _scripts/generate-gallery %s "%s"', $sName, $sGalleryDir);
|
||||
} else {
|
||||
die('Failed to get pictures data');
|
||||
}
|
||||
}
|
||||
$aCommands[] = 'yekyll build';
|
||||
file_put_contents(sprintf('%s/commands.bat', $sSourceDir), implode("\n", $aCommands));
|
||||
} else {
|
||||
die('Failed to get gallery data');
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
require __DIR__ . '/../_php/autoload.php';
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$oPDO = new PDO('mysql:dbname=blog;host=localhost;port=3311', 'root', 'root');
|
||||
|
||||
$sNewDir = 'blog/_posts.new';
|
||||
if (!is_dir($sNewDir)) {
|
||||
mkdir($sNewDir);
|
||||
}
|
||||
|
||||
foreach (glob('blog/_posts/*.md') as $sFile) {
|
||||
$sBasename = basename($sFile);
|
||||
|
||||
printf("%s...\n", $sBasename);
|
||||
|
||||
$sContents = file_get_contents($sFile);
|
||||
$aContents = explode("\n", $sContents);
|
||||
$aParts = explode('--', implode("\n", array_slice($aContents, 1)));
|
||||
$aYaml = Yaml::parse(trim(str_replace(" - \n", null, current($aParts))));
|
||||
|
||||
if (strpos(end($aParts), '<') === false) {
|
||||
echo " no html\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($aYaml['id'])) {
|
||||
echo " no id\n";
|
||||
continue;
|
||||
}
|
||||
$iId = $aYaml['id'];
|
||||
$sQuery = sprintf("SELECT post_content FROM wp_posts WHERE post_parent = %d OR guid LIKE '%%p=%d%%' ORDER BY post_date DESC LIMIT 1", $iId, $iId);
|
||||
if ($oStatement = $oPDO->query($sQuery)) {
|
||||
echo " found match in database\n";
|
||||
foreach ($oStatement as $aRow) {
|
||||
$sContents = $aRow[0];
|
||||
break;
|
||||
}
|
||||
$sNewFile = sprintf('%s/%s', $sNewDir, $sBasename);
|
||||
$sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents);
|
||||
file_put_contents($sNewFile, $sNewContents);
|
||||
echo " new file saved!\n";
|
||||
} else {
|
||||
echo " no match in database\n";
|
||||
}
|
||||
}
|
||||
|
||||
function yamlDump($aData) {
|
||||
return str_replace("'", null, Yaml::dump($aData, 4, 2));
|
||||
}
|
||||
Reference in New Issue
Block a user