query($sQuery)) { foreach ($oStatement as $aRow) { $sOld = $aRow[1]; if (!in_array($aRow[0], $aIds)) { printf("unused %s (%d)\n", $aRow[1], $aRow[0]); } foreach ($aNew as $sNew) { if (isset($aFixed[$aRow[0]])) { continue 2; } if (strpos($sNew, $sOld) !== false) { unset($aUnused[$sNew]); $aOld[$aRow[0]] = $sNew; continue 2; } } $aManual[] = sprintf('%d %s', $aRow[0], $aRow[1]); } } file_put_contents('tmp1', implode("\n", array_keys($aUnused))); if (count($aManual) > 0) { printf("fix manual entries"); file_put_contents('tmp2', implode("\n", $aManual)); exit(); } $aLookup = array_replace($aFixed, $aOld); $aUnknown = array_diff($aIds, array_keys($aLookup)); if (count($aUnknown) > 0) { printf("fix unknown entries"); file_put_contents('tmp3', implode("\n", $aUnknown)); exit(); } foreach (glob(sprintf('%s/*.md', $sDir)) as $sFile) { $sBasename = basename($sFile, '.md'); printf("%s...\n", $sBasename); parseFile($sFile, $aYaml, $sContents); if (isset($aYaml['end_date'])) { $aYaml['end_date'] = date('Y-m-d', $aYaml['end_date']); } if (preg_match_all('~\[nggallery id=(\d+)\]~', $sContents, $aMatches, PREG_SET_ORDER)) { printf(" number of galleries = %d\n", count($aMatches)); foreach ($aMatches as $aMatch) { $sGallery = $aLookup[$aMatch[1]]; $sReplace = sprintf("{%% include gallery.html gallery='%s' %%}", $sGallery); $sContents = str_replace($aMatch[0], $sReplace, $sContents); } writeFile($sFile, $aYaml, $sContents); echo " new file saved!\n"; } }