コード例 #1
0
/**
 * Write out the XML history for a given project and version to a file.
 *
 * @param $xml
 *   String containing the XML representation of the history.
 * @param $project
 *   An object containing (at least) the title and uri of project.
 * @param $api_version
 *   The API compatibility version the history is for.
 */
function project_release_history_write_xml($xml, $project = NULL, $api_version = NULL)
{
    // Dublin core namespace according to http://dublincore.org/documents/dcmi-namespace/
    $dc_namespace = 'xmlns:dc="http://purl.org/dc/elements/1.1/"';
    if (!isset($project)) {
        // We are outputting a global project list.
        $project_dir = HISTORY_ROOT . '/project-list';
        $filename = $project_dir . '/project-list-all.xml';
        $tmp_filename = $filename . '.new';
        $errors = array('mkdir' => array('message' => 'ERROR: mkdir(@dir) failed, cannot write project list.', 'args' => array('@dir' => $project_dir)), 'unlink' => array('message' => 'ERROR: unlink(@file) failed, cannot write project list.', 'args' => array('@file' => $tmp_filename)), 'rename' => array('message' => 'ERROR: rename(@old, @new) failed, cannot write project list.', 'args' => array('@old' => $tmp_filename, '@new' => $filename)));
        $full_xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
        $full_xml .= '<projects ' . $dc_namespace . ">\n" . $xml . "</projects>\n";
    } else {
        // Setup the filenames we'll be using.  Normally, we'd have to be
        // extra careful with $project->uri to avoid malice here, however,
        // that's validated on the project edit form to prevent any funny
        // characters, so that much is safe.  The rest of these paths are
        // just from the global variables at the top of this script, so we
        // can trust those.  The only one we should be careful of is the
        // taxonomy term for the API compatibility.
        $safe_api_vers = strtr($api_version, '/', '_');
        $project_dir = HISTORY_ROOT . '/' . $project->uri;
        $project_id = $project->uri . '-' . $safe_api_vers . '.xml';
        $filename = $project_dir . '/' . $project_id;
        $tmp_filename = $filename . '.new';
        $errors = array('mkdir' => array('message' => "ERROR: mkdir(@dir) failed, can't write history for %project.", 'args' => array('@dir' => $project_dir, '%project' => $project->title)), 'unlink' => array('message' => "ERROR: unlink(@file) failed, can't write history for %project.", 'args' => array('@file' => $tmp_filename, '%project' => $project->title)), 'rename' => array('message' => "ERROR: rename(@old, @new) failed, can't write history for %project.", 'args' => array('@old' => $tmp_filename, '@new' => $filename, '%project' => $project->title)));
        $full_xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
        $full_xml .= '<project ' . $dc_namespace . ">\n" . $xml . "</project>\n";
    }
    // Make sure we've got the right project-specific subdirectory.
    if (!is_dir($project_dir) && !mkdir($project_dir)) {
        wd_err($errors['mkdir']);
        return FALSE;
    }
    // Make sure the "[project]-[version].xml.new" file doesn't exist.
    if (is_file($tmp_filename) && !unlink($tmp_filename)) {
        wd_err($errors['unlink']);
        return FALSE;
    }
    // Write the XML history to "[project]-[version].xml.new".
    if (!($hist_fd = fopen($tmp_filename, 'xb'))) {
        wd_err(array('message' => "ERROR: fopen(@file, 'xb') failed", 'args' => array('@file' => $tmp_filename)));
        return FALSE;
    }
    if (!fwrite($hist_fd, $full_xml)) {
        wd_err(array('message' => "ERROR: fwrite(@file) failed" . '<pre>' . check_plain($full_xml), 'args' => array('@file' => $tmp_filename)));
        return FALSE;
    }
    // We have to close this handle before we can rename().
    fclose($hist_fd);
    // Now we can atomically rename the .new into place in the "live" spot.
    if (!_rename($tmp_filename, $filename)) {
        wd_err($errors['rename']);
        return FALSE;
    }
    return TRUE;
}
コード例 #2
0
ファイル: checkimages.php プロジェクト: 4images/4images
             $error_minor = 1;
         }
         if (!$error_minor) {
             if ($image_media_file != $image_media_file_backup && file_exists(THUMB_PATH . "/" . $cat_id . "/" . $image_media_file_backup)) {
                 if (($file_name = _rename(THUMB_PATH . "/" . $cat_id, $image_media_file_backup, $image_media_file, 1)) && file_exists(THUMB_PATH . "/" . $cat_id . "/" . $file_name)) {
                     $log[] = str_replace("{from}", $image_media_file_backup, str_replace("{to}", $file_name, $lang['cni_thumbnail_rename_success']));
                     $image_thumb_file = $file_name;
                 } else {
                     $log[] = str_replace("{from}", $image_media_file_backup, str_replace("{to}", $image_media_file, $lang['cni_thumbnail_rename_error']));
                     $image_thumb_file = "";
                     //    							$image_thumb_file = $image_media_file_backup;
                 }
             }
             if ($big && $big_file) {
                 if ($image_media_file != $big_file) {
                     if (($file_name = _rename($big_dir, $big_file, $image_media_file, 1)) && file_exists($big_dir . "/" . $file_name)) {
                         $big_file = $file_name;
                         $log[] = str_replace("{from}", $big_folder . "/" . $image_media_file_backup, str_replace("{to}", $big_folder . "/" . $big_file, $lang['cni_file_rename_success']));
                     } else {
                         $log[] = str_replace("{from}", $big_folder . "/" . $image_media_file_backup, str_replace("{to}", $big_folder . "/" . $image_media_file, $lang['cni_file_rename_error']));
                     }
                 }
             }
         }
     }
 }
 $file = MEDIA_PATH . "/" . $cat_id . "/" . $image_media_file;
 $image_info = false;
 $do_resize = false;
 $do_annotate = false;
 $do_backup = false;