/** * dynamically generate the page * * @see skins/index.php */ function send_body() { global $context, $local; // $local is required to localize included scripts // include every script that has to be run once global $scripts, $scripts_count; if (@count($scripts)) { // the alphabetical order may be used to control script execution order sort($scripts); reset($scripts); // process each script one by one foreach ($scripts as $item) { // do not execute on first installation if (file_exists('../parameters/switch.on') || file_exists('../parameters/switch.off')) { // ensure we have a valid database resource if (!$context['connection']) { break; } // remember this as an event Logger::remember('scripts/run_once.php: ' . sprintf(i18n::c('script %s has been executed'), $item)); // where scripts actually are $actual_item = str_replace('//', '/', $context['path_to_root'] . 'scripts/run_once/' . $item); // include the script to execute it $scripts_count++; echo Skin::build_block($item, 'subtitle'); include $actual_item; echo "\n"; } // ensure enough overall execution time Safe::set_time_limit(30); // stamp the file to remember execution time Safe::touch($actual_item); // rename the script to avoid further execution Safe::unlink($actual_item . '.done'); Safe::rename($actual_item, $actual_item . '.done'); } // refresh javascript libraries Cache::purge('js'); } // report on actual execution if ($scripts_count) { echo '<p> </p><p>' . sprintf(i18n::ns('%d script has been executed', '%d scripts have been executed', $scripts_count), $scripts_count) . "</p>\n"; } else { echo '<p>' . i18n::s('No script has been executed') . "</p>\n"; } // display the total execution time $time = round(get_micro_time() - $context['start_time'], 2); if ($time > 30) { echo '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>'; } // if the server has been switched off, go back to the control panel if (file_exists('../parameters/switch.off')) { echo '<form method="get" action="' . $context['url_to_root'] . 'control/">' . "\n" . '<p class="assistant_bar">' . Skin::build_submit_button(i18n::s('Control Panel')) . '</p>' . "\n" . '</form>' . "\n"; // else back to the control panel as well, but without a button } else { $menu = array('control/' => i18n::s('Control Panel')); echo Skin::build_list($menu, 'menu_bar'); } // purge the cache, since it is likely that we have modified some data Cache::clear(); }
if (!($footprint = Scripts::hash($file))) { $context['text'] .= sprintf(i18n::s('%s is not a reference script'), $file) . BR . "\n"; continue; } // store the footprint for later use --number of lines, content hash $footprints[$file] = array($footprint[0], $footprint[1]); // ensure a clean reference store Safe::unlink($context['path_to_reference'] . $file); // create adequate path if (!Safe::make_path($context['path_to_reference'] . dirname($file))) { $context['text'] .= sprintf(i18n::s('Impossible to create path %s.'), $context['path_to_reference'] . dirname($file)) . BR . "\n"; } elseif (!Safe::copy($context['path_to_root'] . $file, $context['path_to_reference'] . $file)) { $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $file) . BR . "\n"; } else { // try to preserve the modification date Safe::touch($context['path_to_reference'] . $file, Safe::filemtime($context['path_to_root'] . $file)); // this will be filtered by umask anyway Safe::chmod($context['path_to_reference'] . $file, $context['file_mask']); } // avoid timeouts if (!(count($footprints) % 50)) { Safe::set_time_limit(30); SQL::ping(); } } if (count($footprints)) { $context['text'] .= sprintf(i18n::s('%d reference scripts have been copied.'), count($footprints)) . "\n"; } $context['text'] .= "</p>\n"; // purge documentation pages $context['text'] .= '<p>' . i18n::s('Purging the documentation pages...') . "</p>\n";
// not part of the reference set anymore $content = preg_replace('/\\s*\\*\\s+@reference\\s*\\n/i', "\n", $content); // save it as the new cache file if (Safe::file_put_contents($target, $content)) { $context['text'] .= sprintf(i18n::s('%s has been transcoded'), $target) . BR . "\n"; } else { $context['text'] .= sprintf(i18n::s('Impossible to write to %s.'), $target) . BR . "\n"; $errors++; } // copy the file } elseif (!Safe::copy($context['path_to_root'] . $origin, $context['path_to_root'] . $target)) { $context['text'] .= sprintf(i18n::s('Impossible to copy file %s.'), $target) . BR . "\n"; $errors++; // attempt to preserve the modification date of the origin file } else { Safe::touch($context['path_to_root'] . $target, Safe::filemtime($context['path_to_root'] . $origin)); $context['text'] .= sprintf(i18n::s('%s has been copied'), $target) . BR . "\n"; } // this will be filtered by umask anyway Safe::chmod($context['path_to_root'] . $target, $context['file_mask']); } $context['text'] .= "</p>\n"; } // some errors have occured if ($errors) { $context['text'] .= '<p>' . i18n::s('Operation has failed.') . "</p>\n"; } else { $context['text'] .= '<p>' . i18n::s('Congratulations, themes have been updated.') . '</p>' . '<p>' . sprintf(i18n::s('Feel free to change and adjust files at skins/%s to better suit your needs.'), $directory) . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array();
/** * flag all scripts in scripts/run_once * */ public static function purge_run_once() { global $context; // silently purge pending run-once scripts, if any if ($handle = Safe::opendir($context['path_to_root'] . 'scripts/run_once')) { // process every file in the directory while (($node = Safe::readdir($handle)) !== FALSE) { // skip special entries if ($node[0] == '.') { continue; } // we are only interested in php scripts if (!preg_match('/\\.php$/i', $node)) { continue; } // full name $target = $context['path_to_root'] . 'scripts/run_once/' . $node; // skip directories and links if (!is_file($target)) { continue; } // check we have enough permissions if (!is_readable($target)) { continue; } // stamp the file to remember execution time Safe::touch($target); // flag script as being already processed Safe::unlink($target . '.done'); Safe::rename($target, $target . '.done'); } Safe::closedir($handle); } }