本文整理汇总了PHP中Safe::unlink方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::unlink方法的具体用法?PHP Safe::unlink怎么用?PHP Safe::unlink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::unlink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
// analyse each script
foreach ($files as $file) {
// ensure we have enough time to process this script
Safe::set_time_limit(30);
// the origin file
$origin = 'skins/' . $skin . $file;
// the target file
if ($file == '/' . $skin . '.css') {
$target = 'skins/' . $directory . '/' . $directory . '.css';
} else {
$target = 'skins/' . $directory . $file;
}
// ensure the path has been created
Safe::make_path(dirname($target));
// unlink previous files, if any
Safe::unlink($context['path_to_root'] . $target);
// transcode php files
if (preg_match('/(\\.php|\\.css)$/i', $target) && ($content = Safe::file_get_contents($context['path_to_root'] . $origin))) {
// change internal reference
$content = preg_replace('/skins\\/' . preg_quote($skin, '/') . '/i', 'skins/' . $directory, $content);
$content = preg_replace('/\'' . preg_quote($skin, '/') . '\'/i', "'" . $directory . "'", $content);
$content = preg_replace('/' . preg_quote($skin, '/') . '\\.css/i', $directory . ".css", $content);
// 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++;
}
示例2: send_body
/**
* 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();
}
示例3: sprintf
$context['text'] .= '<p>' . sprintf(i18n::s('The configuration file for virtual host %s has been deleted.'), $id) . '</p>';
// remember the change
$label = sprintf(i18n::c('%s has been deleted'), $file);
Logger::remember('control/virtual.php: ' . $label);
}
// follow-up commands
$follow_up = i18n::s('What do you want to do now?');
$menu = array();
$menu = array_merge($menu, array('control/virtual.php' => i18n::s('Manage virtual hosts')));
$menu = array_merge($menu, array('control/' => i18n::s('Control Panel')));
$follow_up .= Skin::build_list($menu, 'menu_bar');
$context['text'] .= Skin::build_block($follow_up, 'bottom');
// save the content of an updated file
} elseif ($id && isset($_REQUEST['content']) && $_REQUEST['content']) {
// backup the old version, if any
Safe::unlink($context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php.bak');
Safe::rename($context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php', $context['path_to_root'] . 'parameters/virtual_' . $id . '.include.php.bak');
// actual save
if (Safe::file_put_contents('parameters/virtual_' . $id . '.include.php', $_REQUEST['content']) != strlen($_REQUEST['content'])) {
Logger::error(sprintf(i18n::s('The target file %s may have been corrupted. Please check file content manually, and revert to the backup file, with the extension .bak, if necessary.'), 'parameters/virtual_' . $id . '.include.php'));
} else {
$context['text'] .= '<p>' . sprintf(i18n::s('The target file %s has been successfully updated.'), 'parameters/virtual_' . $id . '.include.php') . '</p>';
$context['text'] .= Skin::build_box(i18n::s('Configuration'), Safe::highlight_string($_REQUEST['content']), 'unfolded');
// follow-up commands
$follow_up = i18n::s('What do you want to do now?');
$menu = array();
$menu = array_merge($menu, array('control/virtual.php?id=' . urlencode($id) => i18n::s('View the configuration file')));
$menu = array_merge($menu, array('control/virtual.php' => i18n::s('Manage virtual hosts')));
$menu = array_merge($menu, array('control/' => i18n::s('Control Panel')));
$follow_up .= Skin::build_list($menu, 'menu_bar');
$context['text'] .= Skin::build_block($follow_up, 'bottom');
示例4: elseif
// only *.css and template.php can be modified
} elseif ($file && !preg_match('/(\\.css|template\\.php)$/i', $file)) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// ensure the file already exists
} elseif ($file && !file_exists($context['path_to_root'] . 'skins/' . $skin . '/' . $file)) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// save the content of an updated file
} elseif (isset($_REQUEST['content']) && $_REQUEST['content']) {
// warning if modification of some reference skin
if (isset($_REQUEST['content']) && $_REQUEST['content'] && preg_match('/^(boxesandarrows|digital|joi|skeleton)$/', $skin)) {
Logger::error(sprintf(i18n::s('Do not attempt to modify a reference theme directly, your changes would be overwritten on next software update. %s instead to preserve your work over time.'), Skin::build_link('skins/derive.php', i18n::s('Derive a theme'), 'shortcut')));
}
// backup the old version, if any
Safe::unlink($context['path_to_root'] . 'skins/' . $skin . '/' . $file . '.bak');
Safe::rename($context['path_to_root'] . 'skins/' . $skin . '/' . $file, $context['path_to_root'] . 'skins/' . $skin . '/' . $file . '.bak');
// actual save
if (Safe::file_put_contents('skins/' . $skin . '/' . $file, $_REQUEST['content']) != strlen($_REQUEST['content'])) {
Logger::error(sprintf(i18n::s('The target file %s may have been corrupted. Please check file content manually, and revert to the backup file, with the extension .bak, if necessary.'), 'skins/' . $skin . '/' . $file));
} else {
$context['text'] .= '<p>' . sprintf(i18n::s('The target file %s has been successfully updated.'), 'skins/' . $skin . '/' . $file) . '</p>';
// follow-up commands
$follow_up = i18n::s('What do you want to do now?');
$menu = array();
$menu = array_merge($menu, array('skins/test.php?skin=' . urlencode($skin) => i18n::s('Test this theme')));
$menu = array_merge($menu, array('skins/edit.php?skin=' . urlencode($skin) => i18n::s('Edit this theme')));
$menu = array_merge($menu, array('skins/' => i18n::s('Themes')));
$menu = array_merge($menu, array('skins/configure.php' => i18n::s('Configure the page factory')));
$follow_up .= Skin::build_list($menu, 'menu_bar');
$context['text'] .= Skin::build_block($follow_up, 'bottom');
示例5: elseif
$context['text'] .= Skin::finalize_list($menu, 'assistant_bar');
// end of the form
$context['text'] .= '</div></form>';
// set the focus
Page::insert_script('$("#files_extensions").focus();');
// general help on this form
$help = '<p>' . i18n::s('Shared files are not put in the database, but in the file system of the web server.') . '</p>' . '<p>' . i18n::s('If you cannot upload files because of permissions settings, use the configuration panel for users to disable all uploads.') . '</p>';
$context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
// no modifications in demo mode
} elseif (file_exists($context['path_to_root'] . 'parameters/demo.flag')) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.'));
// save updated parameters
} else {
// backup the old version
Safe::unlink($context['path_to_root'] . 'parameters/files.include.php.bak');
Safe::rename($context['path_to_root'] . 'parameters/files.include.php', $context['path_to_root'] . 'parameters/files.include.php.bak');
// build the new configuration file
$content = '<?php' . "\n" . '// This file has been created by the configuration script files/configure.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n" . 'global $context;' . "\n";
if (isset($_REQUEST['files_extensions'])) {
$content .= '$context[\'files_extensions\']=\'' . addcslashes($_REQUEST['files_extensions'], "\\'") . "';\n";
}
if (isset($_REQUEST['files_on_ftp'])) {
$content .= '$context[\'files_on_ftp\']=\'' . addcslashes($_REQUEST['files_on_ftp'], "\\'") . "';\n";
}
if (isset($_REQUEST['files_path'])) {
$content .= '$context[\'files_path\']=\'' . addcslashes($_REQUEST['files_path'], "\\'") . "';\n";
}
if (isset($_REQUEST['files_url'])) {
$content .= '$context[\'files_url\']=\'' . addcslashes($_REQUEST['files_url'], "\\'") . "';\n";
}
示例6: process
//.........这里部分代码省略.........
// the <Blogger>...</Blogger> block
$areas = preg_split('/<Blogger>(.*?)<\\/Blogger>/is', trim($template), -1, PREG_SPLIT_DELIM_CAPTURE);
$template = '';
$index = 0;
foreach ($areas as $area) {
// blogging area
if ($index == 1) {
$template .= '<?php ' . "\n" . '// display the menu bar, if any' . "\n" . 'if(@count($context[\'page_menu\']) > 0)' . "\n" . ' echo Skin::build_list($context[\'page_menu\'], \'page_menu\');' . "\n" . "\n" . '// display the prefix, if any' . "\n" . 'if($context[\'prefix\'])' . "\n" . ' echo $context[\'prefix\'];' . "\n" . "\n" . '// display the error message, if any' . "\n" . 'if($context[\'error\'])' . "\n" . ' echo Skin::build_block($context[\'error\'], \'error\');' . "\n" . "\n" . '// display the page image, if any' . "\n" . 'if($context[\'page_image\'])' . "\n" . ' echo \'<img src="\'.$context[\'page_image\'].\'" class="icon" alt="" />\';' . "\n" . "\n" . '// the main part of the page' . "\n" . 'echo $context[\'text\'];' . "\n" . "\n" . '// display the suffix, if any' . "\n" . 'if($context[\'suffix\'])' . "\n" . ' echo \'<p>\'.$context[\'suffix\'].\'</p>\';' . "\n" . '?>';
// make a skin for each item of the blogging area
// break lines to not interfere with regular code
$area = str_replace("\n", "'\n\t\t\t.'", addcslashes(trim($area), "'"));
// <$BlogDateHeaderDate$>
$from = '/<\\$BlogDateHeaderDate\\$>/i';
$to = '\'.Skin::build_date($item[\'create_date\']).\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemArchiveFileName$>
$from = '/<\\$BlogItemArchiveFileName\\$>/i';
$to = '\'.$context[\'url_to_root\'].Articles::get_permalink($item).\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemAuthor$>
$from = '/<\\$BlogItemAuthor\\$>/i';
$to = '\'.$item[\'create_name\'].\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemAuthorNickname$>
$from = '/<\\$BlogItemAuthorNickname\\$>/i';
$to = '\'.$item[\'create_name\'].\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemBody$>
$article_prefix .= 'unset($BlogItemBody);' . "\n" . '// the introduction' . "\n" . 'if($item[\'introduction\'])' . "\n" . ' $BlogItemBody .= Codes::beautify(trim($item[\'introduction\']));' . "\n" . 'elseif(!is_object($overlay)) {' . "\n" . ' // extract up to markup, if any' . "\n" . ' $raw = preg_split(\'/(\\[|<)/\', $item[\'description\']);' . "\n" . ' $BlogItemBody .= Skin::strip(trim($raw[0]), 30);' . "\n" . '}' . "\n" . 'if($suffix)' . "\n" . ' $BlogItemBody = \' - \'.$suffix;' . "\n" . "\n" . '// insert overlay data, if any' . "\n" . 'if(is_object($overlay))' . "\n" . ' $BlogItemBody .= $overlay->get_text(\'list\', $item);' . "\n" . "\n";
$from = '/<\\$BlogItemBody\\$>/i';
$to = '\'.$BlogItemBody.\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemCommentCount$>
$article_prefix .= 'unset($BlogItemCommentCount);' . "\n" . '// info on related comments' . "\n" . 'include_once $context[\'path_to_root\'].\'comments/comments.php\';' . "\n" . '$BlogItemCommentCount = Comments::count_for_anchor(\'article:\'.$item[\'id\']);' . "\n" . "\n";
$from = '/<\\$BlogItemCommentCount\\$>/i';
$to = '\'.$BlogItemCommentCount.\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemControl$> -- the menu bar for associates and poster
$article_prefix .= 'unset($BlogItemControl);' . "\n" . 'if(Surfer::is_associate() || Surfer::is($item[\'create_id\']) || Surfer::is($item[\'edit_id\'])) {' . "\n" . ' $menu = array( Articles::get_url($item[\'id\'], \'edit\') => i18n::s(\'edit\'),' . "\n" . ' Articles::get_url($item[\'id\'], \'delete\') => i18n::s(\'delete\') );' . "\n" . ' $BlogItemControl = \' \'.Skin::build_list($menu, \'menu\');' . "\n" . '}' . "\n" . "\n";
$from = '/<\\$BlogItemControl\\$>/i';
$to = '\'.$BlogItemControl.\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemDateTime$>
$from = '/<\\$BlogItemDateTime\\$>/i';
$to = '\'.Skin::build_date($item[\'create_date\']).\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemNumber$>
$from = '/<\\$BlogItemNumber\\$>/i';
$to = '\'.$item[\'id\'].\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemPermalinkURL$>
$from = '/<\\$BlogItemPermalinkURL\\$>/i';
$to = '\'.$context[\'url_to_root\'].Articles::get_permalink($item).\'';
$area = preg_replace($from, $to, $area);
// <$BlogItemTitle$> -- it has to be the last one for this item
$from = '/<\\$BlogItemTitle\\$>/i';
list($item_prefix, $item_suffix) = preg_split($from, $area);
// make a skin
$skin .= "\n" . ' function layout_article($item, $variant = \'compact\') {' . "\n" . ' global $context;' . "\n" . ' ' . str_replace("\n", "\n\t\t", $article_prefix) . "\n" . ' // array($prefix, $title, $suffix, $type, $icon)' . "\n" . ' $prefix = \'' . trim($item_prefix) . '\';' . "\n" . ' $title = trim($item[\'title\']);' . "\n" . ' $suffix = \'' . trim($item_suffix) . '\';' . "\n" . ' return array($prefix, $title, $suffix, \'article\', NULL);' . "\n" . "\t}\n";
} else {
// suffix block
$template .= $area;
}
$index++;
}
// skin end
$skin .= "}\n" . '?>' . "\n";
// backup the old skin, if any
Safe::unlink($context['path_to_root'] . 'skins/' . $directory . '/skin.php.bak');
Safe::rename($context['path_to_root'] . 'skins/' . $directory . '/skin.php', $context['path_to_root'] . 'skins/' . $directory . '/skin.php.bak');
// create a new skin file
if (!$skin) {
Logger::error(i18n::s('No blogging block has been found.'));
} elseif (!Safe::make_path('skins/' . $directory)) {
Logger::error(sprintf(i18n::s('Impossible to create path %s.'), 'skins/' . $directory));
} elseif (!($handle = Safe::fopen($context['path_to_root'] . 'skins/' . $directory . '/skin.php', 'wb'))) {
Logger::error(sprintf(i18n::s('Impossible to write to %s.'), $context['path_to_root'] . 'skins/' . $directory . '/skin.php'));
} else {
fwrite($handle, $skin);
fclose($handle);
}
// backup the old template, if any
Safe::unlink($context['path_to_root'] . 'skins/' . $directory . '/template.php.bak');
if (!$template) {
Logger::error(i18n::s('Empty template file'));
} else {
Safe::rename($context['path_to_root'] . 'skins/' . $directory . '/template.php', $context['path_to_root'] . 'skins/' . $directory . '/template.php.bak');
}
// create a new template file
if (!Safe::make_path('skins/' . $directory)) {
Logger::error(sprintf(i18n::s('Impossible to create path %s.'), 'skins/' . $directory));
} elseif (!($handle = Safe::fopen($context['path_to_root'] . 'skins/' . $directory . '/template.php', 'wb'))) {
Logger::error(sprintf(i18n::s('Impossible to write to %s.'), $context['path_to_root'] . 'skins/' . $directory . '/template.php'));
} else {
fwrite($handle, $template);
fclose($handle);
$context['text'] .= '<p>' . sprintf(i18n::s('Template has been imported. Check skin %s'), Skin::build_link('skins/test.php?skin=' . $directory, $directory, 'shortcut')) . "</p>\n";
}
return NULL;
}
示例7: foreach
$context['text'] .= '<p>' . i18n::s('Review provided information and go to the bottom of the page to move forward.') . "</p>\n";
}
// include all scripts named 'hook.php' recursively
foreach ($scanned as $name) {
include_hook($context['path_to_root'] . $name);
}
global $scanned_directories;
if ($scanned_directories > 1) {
$context['text'] .= sprintf(i18n::s('%d directories have been scanned.'), $scanned_directories) . BR . "\n";
}
// no hook has been found
if (!count($hooks)) {
$context['text'] .= i18n::s('No item has been found.');
} else {
// backup the old version
Safe::unlink('../parameters/hooks.include.php.bak');
Safe::rename('../parameters/hooks.include.php', '../parameters/hooks.include.php.bak');
// what we have to produce
$called_items = array();
$included_items = array();
$included_items['tick'] = '';
$linked_items = array();
$served_items = array();
// we will remember a xml file as well
$xml = '';
// consider each hook
foreach ($hooks as $hook) {
// bad script!
if (!$hook['id'] || !$hook['type'] || $hook['type'] != 'call' && !$hook['script']) {
$context['text'] .= '<p><strong>' . i18n::s('Bad hook:') . '</strong>' . BR . "\n";
foreach ($hook as $name => $value) {
示例8: purge
/**
* purge some temporary files
*
* This function works in conjunction with Cache::hash().
*
* @param string extension of files to purge
*/
public static function purge($type = '*')
{
global $context;
// delete files cached by yacs
if ($items = Safe::glob($context['path_to_root'] . 'temporary/cache_*.' . $type)) {
foreach ($items as $name) {
Safe::unlink($name);
}
}
// also delete files cached by SimplePie
if ($items = Safe::glob($context['path_to_root'] . 'temporary/*.spc')) {
foreach ($items as $name) {
Safe::unlink($name);
}
}
}
示例9: array
// analyse each script
$footprints = array();
foreach ($scripts as $file) {
// silently skip configuration files
if (strpos($file, '.include.php')) {
continue;
}
// process only reference scripts
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();
示例10: outputJSON
$_SESSION['last_uploaded'][$name]['tmp_name'] = $path;
// @see safe::is_uploaded_file()
$_SESSION['last_uploaded']['pathes'][] = $path;
$preview = Files::preview($path, $name);
// Success!
outputJSON('File uploaded successfully to "' . UPLOAD_PATH . $_FILES[$name]['name'] . '".', 'success', $preview);
}
} elseif ($action === 'destroy') {
if ($name === "all") {
foreach ($_SESSION['last_uploaded'] as $up) {
// destroy file
if (isset($up['tmp_name'])) {
Safe::unlink($up['tmp_name']);
}
}
unset($_SESSION['last_uploaded']);
outputJSON(i18n::s('all temporary file destroyed'), 'success');
}
if (isset($_SESSION['last_uploaded'][$name])) {
$filename = $_SESSION['last_uploaded'][$name]['name'];
// destroy file
Safe::unlink($_SESSION['last_uploaded'][$name]['tmp_name']);
// destroy session memory
unset($_SESSION['last_uploaded'][$name]);
outputJSON(sprintf(i18n::s('temporary file %s destroyed'), $filename), 'success', Skin::build_input_file($name));
}
}
////// no direct access
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
render_skin();
示例11: explode_callback
function explode_callback($name)
{
global $context;
// reject all files put in sub-folders
$file_path = Files::get_path($_REQUEST['anchor'], 'images');
if (($path = substr($name, strlen($file_path . '/'))) && strpos($path, '/') !== FALSE) {
Safe::unlink($name);
} elseif (!($attributes = Safe::GetImageSize($name))) {
Safe::unlink($name);
} elseif ($attributes[0] > 5000 || $attributes[1] > 5000) {
Safe::unlink($name);
}
}
示例12: xml_parser_create
$parser = xml_parser_create();
xml_set_element_handler($parser, 'parse_tag_open', 'parse_tag_close');
xml_set_character_data_handler($parser, 'parse_cdata');
// case is meaningful
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, FALSE);
// parse data
if (!xml_parse($parser, $content)) {
Logger::error('Parsing error: ' . xml_error_string(xml_get_error_code($parser)) . ' at line ' . xml_get_current_line_number($parser));
} else {
$context['text'] = '<p>' . i18n::s('Following items have been processed:') . "</p>\n";
$context['text'] .= '<ul>' . $parsing_report . '</ul>';
}
xml_parser_free($parser);
}
// delete the temporary file
Safe::unlink($file_upload);
// clear the full cache
Cache::clear();
}
} else {
// the form to post a file
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form" enctype="multipart/form-data"><div>';
// the file
$label = i18n::s('File');
$input = '<input type="file" name="upload" id="upload" size="30" />' . ' (< ' . $context['file_maximum_size'] . i18n::s('bytes') . ')';
$hint = i18n::s('Select the file to upload');
$fields[] = array($label, $input, $hint);
// build the form
$context['text'] .= Skin::build_form($fields);
// the submit button
$context['text'] .= '<p>' . Skin::build_submit_button(i18n::s('Submit')) . '</p>';
示例13: save_patterns
/**
* internal method to store patterns of this serveur in a file
* this to spare time for parsing each extension in /codes at page loading
* @see method render
*
* @global array $context
* @param array $patterns_map
*/
private static function save_patterns($patterns_map)
{
global $context;
// backup the old version
Safe::unlink($context['path_to_root'] . 'codes/patterns.auto.php.bak');
Safe::rename($context['path_to_root'] . 'codes/patterns.auto.php', $context['path_to_root'] . 'codes/auto.patterns.auto.php.bak');
$content = '<?php' . "\n" . '// This file has been created by the script codes/codes.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, Please do not modify it manually.' . "\n";
foreach ($patterns_map as $pattern => $action) {
$content .= '$patterns_map[\'' . $pattern . '\']="' . addcslashes(str_replace("\n", '\\n', $action), '"') . "\";\n";
}
if (!Safe::file_put_contents('codes/patterns.auto.php', $content)) {
Logger::error(sprintf(i18n::s('ERROR: Impossible to write to the file %s. The configuration has not been saved.'), 'codes/patterns.auto.php'));
}
}
示例14: purge_run_once
/**
* 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);
}
}
示例15: elseif
$context['text'] .= Skin::finalize_list($menu, 'assistant_bar');
// end of the form
$context['text'] .= '</div></form>';
// set the focus
Page::insert_script('$("#flash_font_r").focus();');
// general help on this form
$help = '<p>' . i18n::s('Do not set any background color to achieve a transparent object.') . '</p>';
$context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help');
// no modifications in demo mode
} elseif (file_exists($context['path_to_root'] . 'parameters/demo.flag')) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation in demonstration mode.'));
// save updated parameters
} else {
// backup the old version
Safe::unlink($context['path_to_root'] . 'parameters/feeds.flash.include.php.bak');
Safe::rename($context['path_to_root'] . 'parameters/feeds.flash.include.php', $context['path_to_root'] . 'parameters/feeds.flash.include.php.bak');
// build the new configuration file
$content = '<?php' . "\n" . '// This file has been created by the configuration script feeds/flash/configure.php' . "\n" . '// on ' . gmdate("F j, Y, g:i a") . ' GMT, for ' . Surfer::get_name() . '. Please do not modify it manually.' . "\n";
if (isset($_REQUEST['flash_font_r'])) {
$content .= '$context[\'flash_font_r\']=' . addcslashes($_REQUEST['flash_font_r'], "\\'") . ";\n";
}
if (isset($_REQUEST['flash_font_g'])) {
$content .= '$context[\'flash_font_g\']=' . addcslashes($_REQUEST['flash_font_g'], "\\'") . ";\n";
}
if (isset($_REQUEST['flash_font_b'])) {
$content .= '$context[\'flash_font_b\']=' . addcslashes($_REQUEST['flash_font_b'], "\\'") . ";\n";
}
if (isset($_REQUEST['flash_background_r'])) {
$content .= '$context[\'flash_background_r\']=' . addcslashes($_REQUEST['flash_background_r'], "\\'") . ";\n";
}