本文整理汇总了PHP中Safe::make_path方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::make_path方法的具体用法?PHP Safe::make_path怎么用?PHP Safe::make_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::make_path方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
if ($output['success'] === null) {
// do it
$fields = array('anchor' => $target->get_reference());
if ($file->item['thumbnail_url']) {
// set new thumbnail url
$fields['thumbnail_url'] = $context['url_to_master'] . $context['url_to_root'] . Files::get_path($target->get_reference()) . '/thumbs/' . urlencode($file->item['file_name']);
}
$output['success'] = $file->set_values($fields);
// move file physicaly
if ($output['success']) {
$from = $context['path_to_root'] . Files::get_path($last_parent->get_reference()) . '/' . $file->item['file_name'];
$dir = $context['path_to_root'] . Files::get_path($target->get_reference());
$to = $dir . '/' . $file->item['file_name'];
// check that dir exists
if (!is_dir($dir)) {
Safe::make_path($dir);
}
Safe::rename($from, $to);
// move thumb if any
if ($file->item['thumbnail_url']) {
$from = Files::get_path($last_parent->get_reference()) . '/thumbs/' . $file->item['file_name'];
// make directory thumbs
$to = $dir . '/thumbs/' . $file->item['file_name'];
// check that dir exist
if (!is_dir($dir . '/thumbs')) {
Safe::mkdir($dir . '/thumbs');
}
Safe::rename($from, $to);
}
}
}
示例2: submit_image
/**
* create a referenced image
*
* @param array of entity attributes (e.g., 'Content-Disposition')
* @param string image actual content
* @param array poster attributes
* @param string the target anchor (e.g., 'article:123')
* @param string reference of the object to be extended, if any
* @return string reference to the created object, or NULL
*/
public static function submit_image($entity_headers, $content, $user, $anchor, $target = NULL)
{
global $context;
// retrieve queue parameters
list($server, $account, $password, $allowed, $match, $section, $options, $hooks, $prefix, $suffix) = $context['mail_queue'];
// locate content-disposition
foreach ($entity_headers as $header) {
if (preg_match('/Content-Disposition/i', $header['name'])) {
$content_disposition = $header['value'];
break;
}
}
// find file name in content-disposition
$file_name = '';
if ($content_disposition && preg_match('/filename="*([a-zA-Z0-9\'\\(\\)\\+_,-\\.\\/:=\\? ]+)"*\\s*/i', $content_disposition, $matches)) {
$file_name = $matches[1];
}
// as an alternative, look in content-type
if (!$file_name) {
// locate content-type
foreach ($entity_headers as $header) {
if (preg_match('/Content-Type/i', $header['name'])) {
$content_type = $header['value'];
break;
}
}
// find file name in content-type
if ($content_type && preg_match('/name="*([a-zA-Z0-9\'\\(\\)\\+_,-\\.\\/:=\\? ]+)"*\\s*/i', $content_type, $matches)) {
$file_name = $matches[1];
}
}
// as an alternative, look in content-description
if (!$file_name) {
// locate content-description
foreach ($entity_headers as $header) {
if (preg_match('/Content-Description/i', $header['name'])) {
$content_description = $header['value'];
break;
}
}
// find file name in content-description
$file_name = $content_description;
}
// sanity check
if (!$file_name) {
Logger::remember('agents/messages.php: No file name to use for submitted image');
return NULL;
}
// file size
$file_size = strlen($content);
// sanity check
if ($file_size < 7) {
Logger::remember('agents/messages.php: Short image skipped', $file_name);
return NULL;
}
// sanity check
if (!$anchor) {
Logger::remember('agents/messages.php: No anchor to use for submitted image', $file_name);
return NULL;
}
// get anchor data -- this is a mutable object
$host = Anchors::get($anchor, TRUE);
if (!is_object($host)) {
Logger::remember('agents/messages.php: Unknown anchor ' . $anchor, $file_name);
return NULL;
}
// create target folders
$file_path = Files::get_path($anchor, 'images');
if (!Safe::make_path($file_path)) {
Logger::remember('agents/messages.php: Impossible to create ' . $file_path);
return NULL;
}
if (!Safe::make_path($file_path . '/thumbs')) {
Logger::remember('agents/messages.php: Impossible to create ' . $file_path . '/thumbs');
return NULL;
}
$file_path = $context['path_to_root'] . $file_path . '/';
// save the entity in the file system
if (!($file = Safe::fopen($file_path . $file_name, 'wb'))) {
Logger::remember('agents/messages.php: Impossible to open ' . $file_path . $file_name);
return NULL;
}
if (fwrite($file, $content) === FALSE) {
Logger::remember('agents/messages.php: Impossible to write to ' . $file_path . $file_name);
return NULL;
}
fclose($file);
// get image information
if (!($image_information = Safe::GetImageSize($file_path . $file_name))) {
Safe::unlink($file_path . $file_name);
//.........这里部分代码省略.........
示例3: shrink
/**
* create a thumbnail
*
* @param string the full path to the original file
* @param string the pull path to write the thumbnail
* @param boolean TRUE to resize to 60x60
* @param boolean TRUE to see error messages, if any
* @return TRUE on success, FALSE on error
*/
public static function shrink($original, $target, $fixed = FALSE, $verbose = TRUE)
{
global $context;
$file_name = basename($original);
$open = Image::open($original);
if ($open === FALSE) {
return FALSE;
}
list($image, $image_information) = $open;
// actual width
$width = $image_information[0];
// standard width
if ($fixed) {
$maximum_width = 60;
} elseif (isset($context['thumbnail_width']) && $context['thumbnail_width'] >= 32) {
$maximum_width = $context['thumbnail_width'];
} else {
$maximum_width = 60;
}
// actual height
$height = $image_information[1];
// standard height
if ($fixed) {
$maximum_height = 60;
} elseif (isset($context['thumbnail_height']) && $context['thumbnail_height'] >= 32) {
$maximum_height = $context['thumbnail_height'];
} else {
$maximum_height = 60;
}
// assume resize is not necessary
$thumbnail_height = $height;
$thumbnail_width = $width;
// the image is laid vertically
if ($height > $width) {
// set the thumbnail size
if ($height > $maximum_height) {
$thumbnail_height = $maximum_height;
$thumbnail_width = $width * $thumbnail_height / $height;
}
// the image is laid horizontally
} else {
// set the thumbnail size
if ($width > $maximum_width) {
$thumbnail_width = $maximum_width;
$thumbnail_height = $height * $thumbnail_width / $width;
}
}
// create target folder for the thumbnail
if ($target_path = dirname($target)) {
Safe::make_path($target_path);
}
// we already have a small image
if ($thumbnail_width == $width && $thumbnail_height == $height) {
// copy file content to the thumbnail
if (!copy($original, $target)) {
if ($verbose) {
Logger::error(sprintf(i18n::s('Cannot copy image to %s'), $target));
}
return FALSE;
}
// this will be filtered by umask anyway
Safe::chmod($target, $context['file_mask']);
// job done
return TRUE;
}
// create the thumbnail in memory
$thumbnail = NULL;
if (Image::use_magic()) {
$thumbnail = $image->resizeImage($thumbnail_width, $thumbnail_height, Imagick::FILTER_POINT, 1);
} else {
if ($image_information[2] == 2 && is_callable('ImageCreateTrueColor') && ($thumbnail = ImageCreateTrueColor($thumbnail_width, $thumbnail_height))) {
ImageCopyResampled($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
}
if (!$thumbnail && is_callable('ImageCreate') && ($thumbnail = ImageCreate($thumbnail_width, $thumbnail_height))) {
ImageCopyResized($thumbnail, $image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
}
}
// sanity check
if (!$thumbnail) {
if ($verbose) {
Logger::error(sprintf(i18n::s('Impossible to skrink image %s'), $file_name));
}
return FALSE;
}
// save the thumbnail in the file system
$result = FALSE;
if (Image::use_magic()) {
$result = $image->writeImage($target);
} else {
if ($image_information[2] == 1 && is_callable('ImageGIF')) {
ImageGIF($thumbnail, $target);
//.........这里部分代码省略.........
示例4: make_path
/**
* create a complete path to a file
*
* The target path can be relative to YACS, or an absolute path pointing
* almost anywhere.
*
* @param the target path
* @return TRUE on success, or FALSE on failure
*/
public static function make_path($path)
{
global $context;
// sanity check
if (!$path) {
return TRUE;
}
// translate path
$translated = Safe::realpath($path);
// the path exists
if (is_dir($translated)) {
return TRUE;
}
// create upper level first
$dir_name = dirname($path);
if ($dir_name != $path && preg_match('|/|', $dir_name)) {
// it is mandatory to have upper level
if (!Safe::make_path($dir_name)) {
return FALSE;
}
}
// create last level directory
return Safe::mkdir($translated);
}
示例5: 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;
}
示例6: foreach
// copy files
$context['text'] .= '<p>' . i18n::s('Copying files...') . BR . "\n";
// 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";
示例7: upload
/**
* process uploaded file
*
* This function processes files from the temporary directory, and put them at their definitive
* place.
*
* It returns FALSE if there is a disk error, or if some virus has been detected, or if
* the operation fails for some other reason (e.g., file size).
*
* @param array usually, $_FILES['upload']
* @param string target location for the file
* @param mixed reference to the target anchor, of a function to parse every file individually
* @return mixed file name or array of file names or FALSE if an error has occured
*/
public static function upload($input, $file_path, $target = NULL, $overlay = NULL)
{
global $context, $_REQUEST;
// size exceeds php.ini settings -- UPLOAD_ERR_INI_SIZE
if (isset($input['error']) && $input['error'] == 1) {
Logger::error(i18n::s('The size of this file is over limit.'));
} elseif (isset($input['error']) && $input['error'] == 2) {
Logger::error(i18n::s('The size of this file is over limit.'));
} elseif (isset($input['error']) && $input['error'] == 3) {
Logger::error(i18n::s('No file has been transmitted.'));
} elseif (isset($input['error']) && $input['error'] == 4) {
Logger::error(i18n::s('No file has been transmitted.'));
} elseif (!$input['size']) {
Logger::error(i18n::s('No file has been transmitted.'));
}
// do we have a file?
if (!isset($input['name']) || !$input['name'] || $input['name'] == 'none') {
return FALSE;
}
// access the temporary uploaded file
$file_upload = $input['tmp_name'];
// $_FILES transcoding to utf8 is not automatic
$input['name'] = utf8::encode($input['name']);
// enhance file name
$file_name = $input['name'];
$file_extension = '';
$position = strrpos($input['name'], '.');
if ($position !== FALSE) {
$file_name = substr($input['name'], 0, $position);
$file_extension = strtolower(substr($input['name'], $position + 1));
}
$input['name'] = $file_name;
if ($file_extension) {
$input['name'] .= '.' . $file_extension;
}
// ensure we have a file name
$file_name = utf8::to_ascii($input['name']);
// uploads are not allowed
if (!Surfer::may_upload()) {
Logger::error(i18n::s('You are not allowed to perform this operation.'));
} elseif (!Files::is_authorized($input['name'])) {
Logger::error(i18n::s('This type of file is not allowed.'));
} elseif ($file_path && !Safe::is_uploaded_file($file_upload)) {
Logger::error(i18n::s('Possible file attack.'));
} else {
// create folders
if ($file_path) {
Safe::make_path($file_path);
}
// sanity check
if ($file_path && $file_path[strlen($file_path) - 1] != '/') {
$file_path .= '/';
}
// move the uploaded file
if ($file_path && !Safe::move_uploaded_file($file_upload, $context['path_to_root'] . $file_path . $file_name)) {
Logger::error(sprintf(i18n::s('Impossible to move the upload file to %s.'), $file_path . $file_name));
} else {
// process the file where it is
if (!$file_path) {
$file_path = str_replace($context['path_to_root'], '', dirname($file_upload));
$file_name = basename($file_upload);
}
// check against viruses
$result = Files::has_virus($context['path_to_root'] . $file_path . '/' . $file_name);
// no virus has been found in this file
if ($result == 'N') {
$context['text'] .= Skin::build_block(i18n::s('No virus has been found.'), 'note');
}
// this file has been infected!
if ($result == 'Y') {
// delete this file immediately
Safe::unlink($file_path . '/' . $file_name);
Logger::error(i18n::s('This file has been infected by a virus and has been rejected!'));
return FALSE;
}
// explode a .zip file
include_once $context['path_to_root'] . 'shared/zipfile.php';
if (preg_match('/\\.zip$/i', $file_name) && isset($_REQUEST['explode_files'])) {
$zipfile = new zipfile();
// check files extracted from the archive file
function explode_callback($name)
{
global $context;
// reject all files put in sub-folders
if (($path = substr($name, strlen($context['uploaded_path'] . '/'))) && strpos($path, '/') !== FALSE) {
Safe::unlink($name);
//.........这里部分代码省略.........
示例8: urlencode
$remote_reference = 'http://' . $context['reference_server'] . '/scripts/fetch.php?script=' . urlencode($file);
} else {
$remote_reference = 'http://' . $context['reference_server'] . '/scripts/reference/' . $file;
}
// get the file locally
if (file_exists($local_reference)) {
$content = Safe::file_get_contents($local_reference);
} elseif (($content = http::proceed($remote_reference)) === FALSE) {
$local['error_en'] = 'Unable to get ' . $file;
$local['error_fr'] = 'Impossible d\'obtenir ' . $file;
echo i18n::user('error') . "<br />\n";
}
// we have something in hand
if ($content) {
// create missing directories where applicable
Safe::make_path(dirname($file));
// create backups, if possible
if (file_exists($context['path_to_root'] . $file)) {
Safe::unlink($context['path_to_root'] . $file . '.bak');
Safe::rename($context['path_to_root'] . $file, $context['path_to_root'] . $file . '.bak');
}
// update the target file
if (!Safe::file_put_contents($file, $content)) {
$local['label_en'] = 'Impossible to write to the file ' . $file . '.';
$local['label_fr'] = 'Impossible d\'écrire le fichier ' . $file . '.';
echo i18n::user('label') . "<br />\n";
} else {
$local['label_en'] = 'has been updated';
$local['label_fr'] = 'a été mis à jour';
echo $file . ' ' . i18n::user('label') . "<br />\n";
}
示例9: duplicate_for_anchor
/**
* duplicate all images for a given anchor
*
* This function duplicates records in the database, and changes anchors
* to attach new records as per second parameter.
*
* @param string the source anchor
* @param string the target anchor
* @return int the number of duplicated records
*
* @see shared/anchors.php
*/
public static function duplicate_for_anchor($anchor_from, $anchor_to)
{
global $context;
// look for records attached to this anchor
$count = 0;
$query = "SELECT * FROM " . SQL::table_name('images') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
if (($result = SQL::query($query)) && SQL::count($result)) {
// create target folders
$file_to = $context['path_to_root'] . Files::get_path($item['anchor'], 'images');
if (!Safe::make_path($file_to . '/thumbs')) {
Logger::error(sprintf(i18n::s('Impossible to create path %s.'), $file_to . '/thumbs'));
}
$file_to = $context['path_to_root'] . $file_to . '/';
// the list of transcoded strings
$transcoded = array();
// process all matching records one at a time
$file_from = $context['path_to_root'] . Files::get_path($anchor_from, 'images');
while ($item = SQL::fetch($result)) {
// sanity check
if (!file_exists($context['path_to_root'] . $file_from . '/' . $item['image_name'])) {
continue;
}
// duplicate image file
if (!copy($context['path_to_root'] . $file_from . '/' . $item['image_name'], $file_to . $item['image_name'])) {
Logger::error(sprintf(i18n::s('Impossible to copy file %s.'), $item['image_name']));
continue;
}
// this will be filtered by umask anyway
Safe::chmod($file_to . $item['image_name'], $context['file_mask']);
// copy the thumbnail as well
Safe::copy($context['path_to_root'] . $file_from . '/' . $item['thumbnail_name'], $file_to . $item['thumbnail_name']);
// this will be filtered by umask anyway
Safe::chmod($file_to . $item['thumbnail_name'], $context['file_mask']);
// a new id will be allocated
$old_id = $item['id'];
unset($item['id']);
// target anchor
$item['anchor'] = $anchor_to;
// actual duplication
if ($new_id = Images::post($item)) {
// more pairs of strings to transcode --no automatic solution for [images=...]
$transcoded[] = array('/\\[image=' . preg_quote($old_id, '/') . '/i', '[image=' . $new_id);
// duplicate elements related to this item
Anchors::duplicate_related_to('image:' . $old_id, 'image:' . $new_id);
// stats
$count++;
}
}
// transcode in anchor
if ($anchor = Anchors::get($anchor_to)) {
$anchor->transcode($transcoded);
}
}
// number of duplicated records
return $count;
}
示例10: foreach
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();
}
}