当前位置: 首页>>代码示例>>PHP>>正文


PHP add_alternative_file函数代码示例

本文整理汇总了PHP中add_alternative_file函数的典型用法代码示例。如果您正苦于以下问题:PHP add_alternative_file函数的具体用法?PHP add_alternative_file怎么用?PHP add_alternative_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_alternative_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: alt_from_resource

function alt_from_resource($source,$target,$name='',$delete=false){
	// Copy a resource as an alt file of another resource
	// alt is the source resource, $ref is the target resource that will get the new alternate
	global $view_title_field;
	$srcdata=get_resource_data($source);
	$srcext = $srcdata['file_extension'];
	$srcpath = get_resource_path($source,true,"",false,$srcext);
	if ($name == ''){
		$name = sql_value("select value from resource_data where resource_type_field = '$view_title_field' and resource = '$source'",'Untitled');
	}

	$description = '';
	if (!file_exists($srcpath)){
		echo "ERROR: File not found.";
		return false;
	} else {

		$file_size = filesize_unlimited($srcpath);
		$altid = add_alternative_file($target,$name,$description="",$file_name="",$file_extension="",$file_size,$alt_type='');
		$newpath = get_resource_path($target,true,"",true,$srcext,-1,1,false,'',$altid);
		copy($srcpath,$newpath);
		# Preview creation for alternative files (enabled via config)
                global $alternative_file_previews;
                if ($alternative_file_previews){
			create_previews($target,false,$srcext,false,false,$altid);
               	}
		if ($delete){
			// we are supposed to delete the original resource when we're done
			# Not allowed to edit this resource? They shouldn't have been able to get here.
			if ((!get_edit_access($source,$srcdata["archive"]))||checkperm('D')) {
				exit ("Permission denied.");
			} else {
				delete_resource($source);
			}
		}
		return true;

	}
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:39,代码来源:resource_to_alt.php

示例2: ProcessFolder


//.........这里部分代码省略.........
                                            # Save the value
                                            #print_r($path_parts);
                                            $value = $path_parts[$level - 1];
                                            if ($staticsync_extension_mapping_append_values) {
                                                $given_value = $value;
                                                // append the values if possible...not used on dropdown, date, categroy tree, datetime, or radio buttons
                                                $field_info = get_resource_type_field($field);
                                                if (in_array($field['type'], array(0, 1, 2, 4, 5, 6, 7, 8))) {
                                                    $old_value = sql_value("select value value from resource_data where resource={$r} and resource_type_field={$field}", "");
                                                    $value = append_field_value($field_info, $value, $old_value);
                                                }
                                            }
                                            update_field($r, $field, trim($value));
                                            if (strtotime(trim($value))) {
                                                add_keyword_mappings($r, trim($value), $field, false, true);
                                            } else {
                                                add_keyword_mappings($r, trim($value), $field);
                                            }
                                            if ($staticsync_extension_mapping_append_values) {
                                                $value = $given_value;
                                            }
                                            echo " - Extracted metadata from path: {$value}" . PHP_EOL;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #Resize only original images.
                    if (!word_in_string($exclude_resize, explode('/', $fullpath))) {
                        echo "Creating preview..";
                        create_previews($r, false, $extension, false, false, -1, false, $staticsync_ingest);
                    }
                    # update access level
                    sql_query("UPDATE resource SET access = '{$accessval}',archive='{$staticsync_defaultstate}' WHERE ref = '{$r}'");
                    # Add any alternative files
                    $altpath = $fullpath . $staticsync_alternatives_suffix;
                    if ($staticsync_ingest && file_exists($altpath)) {
                        $adh = opendir($altpath);
                        while (($altfile = readdir($adh)) !== false) {
                            $filetype = filetype($altpath . "/" . $altfile);
                            if ($filetype == "file" && substr($file, 0, 1) != "." && strtolower($file) != "thumbs.db") {
                                # Create alternative file
                                # Find extension
                                $ext = explode(".", $altfile);
                                $ext = $ext[count($ext) - 1];
                                $description = str_replace("?", strtoupper($ext), $lang["originalfileoftype"]);
                                $file_size = filesize_unlimited($altpath . "/" . $altfile);
                                $aref = add_alternative_file($r, $altfile, $description, $altfile, $ext, $file_size);
                                $path = get_resource_path($r, true, '', true, $ext, -1, 1, false, '', $aref);
                                rename($altpath . "/" . $altfile, $path);
                                # Move alternative file
                            }
                        }
                    }
                    # Add to collection
                    if ($staticsync_autotheme) {
                        $test = '';
                        $test = sql_query("SELECT * FROM collection_resource WHERE collection='{$collection}' AND resource='{$r}'");
                        if (count($test) == 0) {
                            sql_query("INSERT INTO collection_resource (collection, resource, date_added)\n                                            VALUES ('{$collection}', '{$r}', NOW())");
                        }
                    }
                } else {
                    # Import failed - file still being uploaded?
                    echo " *** Skipping file - it was not possible to move the file (still being imported/uploaded?)" . PHP_EOL;
                }
            } else {
                # check modified date and update previews if necessary
                $filemod = filemtime($fullpath);
                if (array_key_exists($shortpath, $modtimes) && $filemod > strtotime($modtimes[$shortpath])) {
                    # File has been modified since we last created previews. Create again.
                    $rd = sql_query("SELECT ref, has_image, file_modified, file_extension FROM resource\n                                        WHERE file_path='" . escape_check($shortpath) . "'");
                    if (count($rd) > 0) {
                        $rd = $rd[0];
                        $rref = $rd["ref"];
                        echo "Resource {$rref} has changed, regenerating previews: {$fullpath}" . PHP_EOL;
                        extract_exif_comment($rref, $rd["file_extension"]);
                        # extract text from documents (e.g. PDF, DOC).
                        global $extracted_text_field;
                        if (isset($extracted_text_field)) {
                            if (isset($unoconv_path) && in_array($extension, $unoconv_extensions)) {
                                // omit, since the unoconv process will do it during preview creation below
                            } else {
                                extract_text($rref, $extension);
                            }
                        }
                        # Store original filename in field, if set
                        global $filename_field;
                        if (isset($filename_field)) {
                            update_field($rref, $filename_field, $file);
                        }
                        create_previews($rref, false, $rd["file_extension"], false, false, -1, false, $staticsync_ingest);
                        sql_query("UPDATE resource SET file_modified=NOW() WHERE ref='{$rref}'");
                    }
                }
            }
        }
    }
}
开发者ID:vachanda,项目名称:ResourceSpace,代码行数:101,代码来源:staticsync.php

示例3: fclose

         fclose($out);
     } else {
         die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
     }
 }
 // Check if file has been uploaded
 if (!$chunks || $chunk == $chunks - 1) {
     // Strip the temp .part suffix off
     rename("{$plfilepath}.part", $plfilepath);
     # Additional ResourceSpace upload code
     $plupload_upload_location = $plfilepath;
     if (!hook("initialuploadprocessing")) {
         if ($alternative != "") {
             # Upload an alternative file (JUpload only)
             # Add a new alternative file
             $aref = add_alternative_file($alternative, $plfilename);
             # Work out the extension
             $extension = explode(".", $plfilepath);
             $extension = trim(strtolower($extension[count($extension) - 1]));
             # Find the path for this resource.
             $path = get_resource_path($alternative, true, "", true, $extension, -1, 1, false, "", $aref);
             # Move the sent file to the alternative file location
             # PLUpload - file was sent chunked and reassembled - use the reassembled file location
             $result = rename($plfilepath, $path);
             if ($result === false) {
                 exit("ERROR: File upload error. Please check the size of the file you are trying to upload.");
             }
             chmod($path, 0777);
             $file_size = @filesize_unlimited($path);
             # Save alternative file data.
             sql_query("update resource_alt_files set file_name='" . escape_check($plfilename) . "',file_extension='" . escape_check($extension) . "',file_size='" . $file_size . "',creation_date=now() where resource='{$alternative}' and ref='{$aref}'");
开发者ID:vongalpha,项目名称:resourcespace,代码行数:31,代码来源:upload_plupload.php

示例4: hook

 $tmp = hook("preventgeneratealt", "", array($file));
 if ($tmp === true) {
     $generate = false;
 }
 if ($generate) {
     if (!hook("removepreviousalts", "", array($ffmpeg_alternatives, $file, $n))) {
         # Remove any existing alternative file(s) with this name.
         # SQL Connection may have hit a timeout
         sql_connect();
         $existing = sql_query("select ref from resource_alt_files where resource='{$ref}' and name='" . escape_check($ffmpeg_alternatives[$n]["name"]) . "'");
         for ($m = 0; $m < count($existing); $m++) {
             delete_alternative_file($ref, $existing[$m]["ref"]);
         }
     }
     # Create the alternative file.
     $aref = add_alternative_file($ref, $ffmpeg_alternatives[$n]["name"]);
     $apath = get_resource_path($ref, true, "", true, $ffmpeg_alternatives[$n]["extension"], -1, 1, false, "", $aref);
     # Process the video
     $shell_exec_cmd = $ffmpeg_fullpath . "  {$ffmpeg_global_options} -y -i " . escapeshellarg($file) . " " . $ffmpeg_alternatives[$n]["params"] . " " . escapeshellarg($apath);
     $tmp = hook("ffmpegmodaltparams", "", array($shell_exec_cmd, $ffmpeg_fullpath, $file, $n, $aref));
     if ($tmp) {
         $shell_exec_cmd = $tmp;
     }
     $output = run_command($shell_exec_cmd);
     if (isset($qtfaststart_path)) {
         if ($qtfaststart_path && file_exists($qtfaststart_path . "/qt-faststart") && in_array($ffmpeg_alternatives[$n]["extension"], $qtfaststart_extensions)) {
             $apathtmp = $apath . ".tmp";
             rename($apath, $apathtmp);
             $output = run_command($qtfaststart_path . "/qt-faststart " . escapeshellarg($apathtmp) . " " . escapeshellarg($apath) . " 2>&1");
             unlink($apathtmp);
         }
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:31,代码来源:ffmpeg_processing.php

示例5: ProcessFolder


//.........这里部分代码省略.........
                                $path_parts = explode("/", $shortpath);
                                if ($level < count($path_parts)) {
                                    # Save the value
                                    print_r($path_parts);
                                    $value = $path_parts[$level - 1];
                                    update_field($r, $field, $value);
                                    echo " - Extracted metadata from path: {$value}\n";
                                }
                            }
                        }
                    }
                    // add the timestamp from this run to the keywords field to help retrieve this batch later
                    $currentkeywords = sql_value("select value from resource_data where resource = '{$r}' and resource_type_field = '1'", "");
                    if (strlen($currentkeywords) > 0) {
                        $currentkeywords .= ',';
                    }
                    update_field($r, 1, $currentkeywords . $staticsync_run_timestamp);
                    if (function_exists('staticsync_local_functions')) {
                        // if local cleanup functions have been defined, run them
                        staticsync_local_functions($r);
                    }
                    # Add any alternative files
                    $altpath = $fullpath . $staticsync_alternatives_suffix;
                    if ($staticsync_ingest && file_exists($altpath)) {
                        $adh = opendir($altpath);
                        while (($altfile = readdir($adh)) !== false) {
                            $filetype = filetype($altpath . "/" . $altfile);
                            if ($filetype == "file" && substr($file, 0, 1) != "." && strtolower($file) != "thumbs.db") {
                                # Create alternative file
                                global $lang;
                                # Find extension
                                $ext = explode(".", $altfile);
                                $ext = $ext[count($ext) - 1];
                                $aref = add_alternative_file($r, $altfile, strtoupper($ext) . " " . $lang["file"], $altfile, $ext, filesize_unlimited($altpath . "/" . $altfile));
                                $path = get_resource_path($r, true, "", true, $ext, -1, 1, false, "", $aref);
                                rename($altpath . "/" . $altfile, $path);
                                # Move alternative file
                            }
                        }
                    }
                    # check for alt files that match suffix list
                    if ($staticsync_alt_suffixes) {
                        $ss_nametocheck = substr($file, 0, strlen($file) - strlen($extension) - 1);
                        //review all files still in directory and see if they are alt files matching this one
                        $althandle = opendir($folder);
                        while (($altcandidate = readdir($althandle)) !== false) {
                            if ($filetype == "file" && substr($file, 0, 1) != "." && strtolower($file) != "thumbs.db") {
                                # Find extension
                                $ext = explode(".", $altcandidate);
                                $ext = $ext[count($ext) - 1];
                                $altcandidate_name = substr($altcandidate, 0, strlen($altcandidate) - strlen($ext) - 1);
                                $altcandidate_validated = false;
                                foreach ($staticsync_alt_suffix_array as $sssuffix) {
                                    if ($altcandidate_name == $ss_nametocheck . $sssuffix) {
                                        $altcandidate_validated = true;
                                        $thisfilesuffix = $sssuffix;
                                        break;
                                    }
                                }
                                if ($altcandidate_validated) {
                                    echo date('Y-m-d H:i:s    ');
                                    echo "    Attaching {$altcandidate} as alternative.\n";
                                    $filetype = filetype($folder . "/" . $altcandidate);
                                    # Create alternative file
                                    global $lang;
                                    if (preg_match("/^_VERSO[0-9]*/i", $thisfilesuffix)) {
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:67,代码来源:staticsync_alt.php

示例6: ProcessFolder


//.........这里部分代码省略.........
                                        {
                                        # Save the value
                                        print_r($path_parts);
                                        $value = $path_parts[$level-1];
                                        update_field ($r, $field, $value);
                                        echo " - Extracted metadata from path: $value" . PHP_EOL;
                                        }
                                    }
                                }
                            }
                        }

                    # update access level
                    sql_query("UPDATE resource SET access = '$accessval',archive='$staticsync_defaultstate' WHERE ref = '$r'");

                    # Add any alternative files
                    $altpath = $fullpath . $staticsync_alternatives_suffix;
                    if ($staticsync_ingest && file_exists($altpath))
                        {
                        $adh = opendir($altpath);
                        while (($altfile = readdir($adh)) !== false)
                            {
                            $filetype = filetype($altpath . "/" . $altfile);
                            if (($filetype == "file") && (substr($file,0,1) != ".") && (strtolower($file) != "thumbs.db"))
                                {
                                # Create alternative file                               
                                # Find extension
                                $ext = explode(".", $altfile);
                                $ext = $ext[count($ext)-1];
                                
                                $description = str_replace("?", strtoupper($ext), $lang["originalfileoftype"]);
                                $file_size   = filesize_unlimited($altpath . "/" . $altfile);
                                
                                $aref = add_alternative_file($r, $altfile, $description, $altfile, $ext, $file_size);
                                $path = get_resource_path($r, true, '', true, $ext, -1, 1, false, '', $aref);
                                rename($altpath . "/" . $altfile,$path); # Move alternative file
                                }
                            }   
                        }

                    # Add to collection
                    if ($staticsync_autotheme)
                        {
                        $test = ''; 
                        $test = sql_query("SELECT * FROM collection_resource WHERE collection='$collection' AND resource='$r'");
                        if (count($test) == 0)
                            {
                            sql_query("INSERT INTO collection_resource (collection, resource, date_added) 
                                            VALUES ('$collection', '$r', NOW())");
                            }
                        }
                    }
                else
                    {
                    # Import failed - file still being uploaded?
                    echo " *** Skipping file - it was not possible to move the file (still being imported/uploaded?)" . PHP_EOL;
                    }
                }
            else
                {
                # check modified date and update previews if necessary
                $filemod = filemtime($fullpath);
                if (array_key_exists($shortpath,$modtimes) && ($filemod > strtotime($modtimes[$shortpath])))
                    {
                    # File has been modified since we last created previews. Create again.
                    $rd = sql_query("SELECT ref, has_image, file_modified, file_extension FROM resource 
开发者ID:artsmia,项目名称:mia_resourcespace,代码行数:67,代码来源:staticsync.php

示例7: exit

*/
global $calibre_extensions;
global $calibre_path;
if (in_array($extension, $calibre_extensions) && isset($calibre_path) && !isset($newfile)) {
    $calibrecommand = $calibre_path . "/ebook-convert";
    if (!file_exists($calibrecommand)) {
        exit("Calibre executable not found at '{$calibre_path}'");
    }
    $path_parts = pathinfo($file);
    $basename_minus_extension = remove_extension($path_parts['basename']);
    $pdffile = $path_parts['dirname'] . "/" . $basename_minus_extension . ".pdf";
    $wait = run_command("xvfb-run " . $calibrecommand . " " . escapeshellarg($file) . " " . $pdffile . " ");
    if (file_exists($pdffile)) {
        # Attach this PDF file as an alternative download.
        sql_query("delete from resource_alt_files where resource = '" . $ref . "' and unoconv='1'");
        $alt_ref = add_alternative_file($ref, "PDF version");
        $alt_path = get_resource_path($ref, true, "", false, "pdf", -1, 1, false, "", $alt_ref);
        copy($pdffile, $alt_path);
        unlink($pdffile);
        sql_query("update resource_alt_files set file_name='{$ref}-converted.pdf',description='generated by Open Office',file_extension='pdf',file_size='" . filesize_unlimited($alt_path) . "',unoconv='1' where resource='{$ref}' and ref='{$alt_ref}'");
        # Set vars so we continue generating thumbs/previews as if this is a PDF file
        $extension = "pdf";
        $file = $alt_path;
    }
}
/* ----------------------------------------
	Try OpenDocument Format
   ----------------------------------------
*/
if (($extension == "odt" || $extension == "ott" || $extension == "odg" || $extension == "otg" || $extension == "odp" || $extension == "otp" || $extension == "ods" || $extension == "ots" || $extension == "odf" || $extension == "otf" || $extension == "odm" || $extension == "oth") && !isset($newfile)) {
    run_command("unzip -p " . escapeshellarg($file) . " \"Thumbnails/thumbnail.png\" > {$target}");
开发者ID:vongalpha,项目名称:resourcespace,代码行数:31,代码来源:preview_preprocessing.php

示例8: create_previews

function create_previews($ref, $thumbonly = false, $extension = "jpg", $previewonly = false, $previewbased = false, $alternative = -1)
{
    global $imagemagick_path, $preview_generate_max_file_size;
    # Debug
    debug("create_previews(ref={$ref},thumbonly={$thumbonly},extension={$extension},previewonly={$previewonly},previewbased={$previewbased},alternative={$alternative})");
    # File checksum (experimental) - disabled for now
    if (!$previewonly) {
        generate_file_checksum($ref, $extension);
    }
    # first reset preview tweaks to 0
    sql_query("update resource set preview_tweaks = '0|1' where ref = '{$ref}'");
    # pages/tools/update_previews.php?previewbased=true
    # use previewbased to avoid touching original files (to preserve manually-uploaded preview images
    # when regenerating previews (i.e. for watermarks)
    if ($previewbased) {
        $file = get_resource_path($ref, true, "lpr", false, "jpg", -1, 1, false, "", $alternative);
        if (!file_exists($file)) {
            $file = get_resource_path($ref, true, "scr", false, "jpg", -1, 1, false, "", $alternative);
            if (!file_exists($file)) {
                $file = get_resource_path($ref, true, "pre", false, "jpg", -1, 1, false, "", $alternative);
            }
        }
    } else {
        if (!$previewonly) {
            $file = get_resource_path($ref, true, "", false, $extension, -1, 1, false, "", $alternative);
        } else {
            # We're generating based on a new preview (scr) image.
            $file = get_resource_path($ref, true, "tmp", false, "jpg");
        }
    }
    # Debug
    debug("File source is {$file}");
    # Make sure the file exists
    if (!file_exists($file)) {
        return false;
    }
    # If configured, make sure the file is within the size limit for preview generation
    if (isset($preview_generate_max_file_size)) {
        $filesize = filesize_unlimited($file) / (1024 * 1024);
        # Get filesize in MB
        if ($filesize > $preview_generate_max_file_size) {
            return false;
        }
    }
    # Locate imagemagick.
    $convert_fullpath = get_utility_path("im-convert");
    if ($convert_fullpath == false) {
        exit("Could not find ImageMagick 'convert' utility at location '{$imagemagick_path}'");
    }
    # Handle alternative image file generation.
    global $image_alternatives;
    if (isset($image_alternatives) && $alternative == -1) {
        for ($n = 0; $n < count($image_alternatives); $n++) {
            $exts = explode(",", $image_alternatives[$n]["source_extensions"]);
            if (in_array($extension, $exts)) {
                # Remove any existing alternative file(s) with this name.
                $existing = sql_query("select ref from resource_alt_files where resource='{$ref}' and name='" . escape_check($image_alternatives[$n]["name"]) . "'");
                for ($m = 0; $m < count($existing); $m++) {
                    delete_alternative_file($ref, $existing[$m]["ref"]);
                }
                # Create the alternative file.
                $aref = add_alternative_file($ref, $image_alternatives[$n]["name"]);
                $apath = get_resource_path($ref, true, "", true, $image_alternatives[$n]["target_extension"], -1, 1, false, "", $aref);
                # Process the image
                $command = $convert_fullpath . " " . $image_alternatives[$n]["params"] . " " . escapeshellarg($file) . " " . escapeshellarg($apath);
                $output = run_command($command);
                if (file_exists($apath)) {
                    # Update the database with the new file details.
                    $file_size = filesize_unlimited($apath);
                    sql_query("update resource_alt_files set file_name='" . escape_check($image_alternatives[$n]["filename"] . "." . $image_alternatives[$n]["target_extension"]) . "',file_extension='" . escape_check($image_alternatives[$n]["target_extension"]) . "',file_size='" . $file_size . "',creation_date=now() where ref='{$aref}'");
                }
            }
        }
    }
    if ($extension == "jpg" || $extension == "jpeg" || $extension == "png" || $extension == "gif") {
        if (isset($imagemagick_path)) {
            create_previews_using_im($ref, $thumbonly, $extension, $previewonly, $previewbased, $alternative);
        } else {
            # ----------------------------------------
            # Use the GD library to perform the resize
            # ----------------------------------------
            # For resource $ref, (re)create the various preview sizes listed in the table preview_sizes
            # Only create previews where the target size IS LESS THAN OR EQUAL TO the source size.
            # Set thumbonly=true to (re)generate thumbnails only.
            $sizes = "";
            if ($thumbonly) {
                $sizes = " where id='thm' or id='col'";
            }
            if ($previewonly) {
                $sizes = " where id='thm' or id='col' or id='pre' or id='scr'";
            }
            # fetch source image size, if we fail, exit this function (file not an image, or file not a valid jpg/png/gif).
            if ((list($sw, $sh) = @getimagesize($file)) === false) {
                return false;
            }
            $ps = sql_query("select * from preview_size {$sizes}");
            for ($n = 0; $n < count($ps); $n++) {
                # fetch target width and height
                $tw = $ps[$n]["width"];
                $th = $ps[$n]["height"];
//.........这里部分代码省略.........
开发者ID:vongalpha,项目名称:resourcespace,代码行数:101,代码来源:image_processing.php

示例9: create_previews

function create_previews($ref, $thumbonly = false, $extension = "jpg", $previewonly = false, $previewbased = false, $alternative = -1, $ignoremaxsize = false, $ingested = false)
{
    global $keep_for_hpr, $imagemagick_path, $preview_generate_max_file_size, $autorotate_no_ingest;
    // keep_for_hpr will be set to true if necessary in preview_preprocessing.php to indicate that an intermediate jpg can serve as the hpr.
    // otherwise when the file extension is a jpg it's assumed no hpr is needed.
    # Debug
    debug("create_previews(ref={$ref},thumbonly={$thumbonly},extension={$extension},previewonly={$previewonly},previewbased={$previewbased},alternative={$alternative},ingested={$ingested})");
    if (!$previewonly) {
        // make sure the extension is the same as the original so checksums aren't done for previews
        $o_ext = sql_value("select file_extension value from resource where ref={$ref}", "");
        if ($extension == $o_ext) {
            debug("create_previews - generate checksum for {$ref}");
            generate_file_checksum($ref, $extension);
        }
    }
    # first reset preview tweaks to 0
    sql_query("update resource set preview_tweaks = '0|1' where ref = '{$ref}'");
    // for compatibility with transform plugin, remove any
    // transform previews for this resource when regenerating previews
    $tpdir = get_temp_dir() . "/transform_plugin";
    if (is_dir($tpdir) && file_exists("{$tpdir}/pre_{$ref}.jpg")) {
        unlink("{$tpdir}/pre_{$ref}.jpg");
    }
    # pages/tools/update_previews.php?previewbased=true
    # use previewbased to avoid touching original files (to preserve manually-uploaded preview images
    # when regenerating previews (i.e. for watermarks)
    if ($previewbased || $autorotate_no_ingest && !$ingested) {
        $file = get_resource_path($ref, true, "lpr", false, "jpg", -1, 1, false, "", $alternative);
        if (!file_exists($file)) {
            $file = get_resource_path($ref, true, "scr", false, "jpg", -1, 1, false, "", $alternative);
            if (!file_exists($file)) {
                $file = get_resource_path($ref, true, "pre", false, "jpg", -1, 1, false, "", $alternative);
                if (!file_exists($file) && $autorotate_no_ingest && !$ingested) {
                    $file = get_resource_path($ref, true, "", false, $extension, -1, 1, false, "", $alternative);
                }
            }
        }
    } else {
        if (!$previewonly) {
            $file = get_resource_path($ref, true, "", false, $extension, -1, 1, false, "", $alternative);
        } else {
            # We're generating based on a new preview (scr) image.
            $file = get_resource_path($ref, true, "tmp", false, "jpg");
        }
    }
    # Debug
    debug("File source is {$file}");
    # Make sure the file exists, if not update preview_attempts so that we don't keep trying to generate a preview
    if (!file_exists($file)) {
        sql_query("update resource set preview_attempts=ifnull(preview_attempts,0) + 1 where ref='{$ref}'");
        return false;
    }
    # If configured, make sure the file is within the size limit for preview generation
    if (isset($preview_generate_max_file_size) && !$ignoremaxsize) {
        $filesize = filesize_unlimited($file) / (1024 * 1024);
        # Get filesize in MB
        if ($filesize > $preview_generate_max_file_size) {
            return false;
        }
    }
    # Locate imagemagick.
    $convert_fullpath = get_utility_path("im-convert");
    if ($convert_fullpath == false) {
        debug("ERROR: Could not find ImageMagick 'convert' utility at location '{$imagemagick_path}'");
        return false;
    }
    # Handle alternative image file generation.
    global $image_alternatives;
    if (isset($image_alternatives) && $alternative == -1) {
        for ($n = 0; $n < count($image_alternatives); $n++) {
            $exts = explode(",", $image_alternatives[$n]["source_extensions"]);
            if (in_array($extension, $exts)) {
                # Remove any existing alternative file(s) with this name.
                $existing = sql_query("select ref from resource_alt_files where resource='{$ref}' and name='" . escape_check($image_alternatives[$n]["name"]) . "'");
                for ($m = 0; $m < count($existing); $m++) {
                    delete_alternative_file($ref, $existing[$m]["ref"]);
                }
                # Create the alternative file.
                $aref = add_alternative_file($ref, $image_alternatives[$n]["name"]);
                $apath = get_resource_path($ref, true, "", true, $image_alternatives[$n]["target_extension"], -1, 1, false, "", $aref);
                $source_profile = '';
                if ($image_alternatives[$n]["icc"] === true) {
                    $iccpath = get_resource_path($ref, true, '', false, $extension) . '.icc';
                    global $icc_extraction;
                    global $ffmpeg_supported_extensions;
                    if (!file_exists($iccpath) && $extension != "pdf" && !in_array($extension, $ffmpeg_supported_extensions)) {
                        // extracted profile doesn't exist. Try extracting.
                        extract_icc_profile($ref, $extension);
                    }
                    if (file_exists($iccpath)) {
                        $source_profile = ' -strip -profile ' . $iccpath;
                    }
                }
                # Process the image
                $version = get_imagemagick_version();
                if ($version[0] > 5 || $version[0] == 5 && $version[1] > 5 || $version[0] == 5 && $version[1] == 5 && $version[2] > 7) {
                    // Use the new imagemagick command syntax (file then parameters)
                    $command = $convert_fullpath . ' ' . escapeshellarg($file) . ($extension == 'psd' ? '[0] +matte' : '') . $source_profile . ' ' . $image_alternatives[$n]['params'] . ' ' . escapeshellarg($apath);
                } else {
                    // Use the old imagemagick command syntax (parameters then file)
//.........这里部分代码省略.........
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:101,代码来源:image_processing.php

示例10: ProcessFolder


//.........这里部分代码省略.........
													echo "Will set access level to " . $lang['access' . $n] . " ($n)\n";
												}
											}

										} else {
										# Save the value
										print_r($path_parts);
										$value=$path_parts[$level-1];
										update_field ($r,$field,$value);
										echo " - Extracted metadata from path: $value\n";
										}
									}
								}
							}
						}
					
					// update access level
					sql_query("update resource set access = '$accessval' where ref = '$r'");
					
					# Add any alternative files
					$altpath=$fullpath . $staticsync_alternatives_suffix;
					if ($staticsync_ingest && file_exists($altpath))
						{
						$adh=opendir($altpath);
						while (($altfile = readdir($adh)) !== false)
							{
							$filetype=filetype($altpath . "/" . $altfile);
							if (($filetype=="file") && (substr($file,0,1)!=".") && (strtolower($file)!="thumbs.db"))
								{
								# Create alternative file
								global $lang;
								
								# Find extension
								$ext=explode(".",$altfile);$ext=$ext[count($ext)-1];
								
								$aref = add_alternative_file($r, $altfile, str_replace("?",strtoupper($ext),$lang["originalfileoftype"]), $altfile, $ext, filesize_unlimited($altpath . "/" . $altfile));
								$path=get_resource_path($r, true, "", true, $ext, -1, 1, false, "", $aref);
								rename ($altpath . "/" . $altfile,$path); # Move alternative file
								}
							}	
						}
					
					# Add to collection
					if ($staticsync_autotheme)
						{
						$test="";	
						$test=sql_query("select * from collection_resource where collection='$collection' and resource='$r'");
						if (count($test)==0){
							sql_query("insert into collection_resource(collection,resource,date_added) values ('$collection','$r',now())");
							}
						}
					}
				else
					{
					# Import failed - file still being uploaded?
					echo " *** Skipping file - it was not possible to move the file (still being imported/uploaded?) \n";
					}
				}
			else
				{
				# check modified date and update previews if necessary
				$filemod=filemtime($fullpath);
				if (array_key_exists($shortpath,$modtimes) && ($filemod>strtotime($modtimes[$shortpath])))
					{
					# File has been modified since we last created previews. Create again.
					$rd=sql_query("select ref,has_image,file_modified,file_extension from resource where file_path='" . (escape_check($shortpath)) . "'");
					if (count($rd)>0)
						{
						$rd=$rd[0];
						$rref=$rd["ref"];
						
						echo "Resource $rref has changed, regenerating previews: $fullpath\n";
						extract_exif_comment($rref,$rd["file_extension"]);
						
						# extract text from documents (e.g. PDF, DOC).
						global $extracted_text_field;
						if (isset($extracted_text_field)) {
							if (isset($unoconv_path) && in_array($extension,$unoconv_extensions)){
								// omit, since the unoconv process will do it during preview creation below
								}
							else {
							extract_text($rref,$extension);
							}
						}

						# Store original filename in field, if set
						global $filename_field;
						if (isset($filename_field))
							{
							update_field($rref,$filename_field,$file);	
							}
						
						create_previews($rref,false,$rd["file_extension"]);
						sql_query("update resource set file_modified=now() where ref='$rref'");
						}
					}
				}
			}	
		}	
	}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:staticsync.php

示例11: file

 if ($generate) {
     if (!hook("removepreviousalts", "", array($ffmpeg_alternatives, $file, $n))) {
         # Remove any existing alternative file(s) with this name.
         # SQL Connection may have hit a timeout
         sql_connect();
         $existing = sql_query("select ref from resource_alt_files where resource='{$ref}' and name='" . escape_check($ffmpeg_alternatives[$n]["name"]) . "'");
         for ($m = 0; $m < count($existing); $m++) {
             delete_alternative_file($ref, $existing[$m]["ref"]);
         }
     }
     $alt_type = '';
     if (isset($ffmpeg_alternatives[$n]['alt_type'])) {
         $alt_type = $ffmpeg_alternatives[$n]["alt_type"];
     }
     # Create the alternative file.
     $aref = add_alternative_file($ref, $ffmpeg_alternatives[$n]["name"], '', '', '', 0, $alt_type);
     $apath = get_resource_path($ref, true, "", true, $ffmpeg_alternatives[$n]["extension"], -1, 1, false, "", $aref);
     # Process the video
     $shell_exec_cmd = $ffmpeg_fullpath . "  {$ffmpeg_global_options} -y -i " . escapeshellarg($file) . " " . $ffmpeg_alternatives[$n]["params"] . " " . escapeshellarg($apath);
     $tmp = hook("ffmpegmodaltparams", "", array($shell_exec_cmd, $ffmpeg_fullpath, $file, $n, $aref));
     if ($tmp) {
         $shell_exec_cmd = $tmp;
     }
     $output = run_command($shell_exec_cmd);
     if (isset($qtfaststart_path)) {
         if ($qtfaststart_path && file_exists($qtfaststart_path . "/qt-faststart") && in_array($ffmpeg_alternatives[$n]["extension"], $qtfaststart_extensions)) {
             $apathtmp = $apath . ".tmp";
             rename($apath, $apathtmp);
             $output = run_command($qtfaststart_path . "/qt-faststart " . escapeshellarg($apathtmp) . " " . escapeshellarg($apath) . " 2>&1");
             unlink($apathtmp);
         }
开发者ID:claytondaley,项目名称:resourcespace,代码行数:31,代码来源:ffmpeg_processing.php

示例12: HookImagestreamUpload_pluploadInitialuploadprocessing


//.........这里部分代码省略.........
                        }
                        if ($height % 2) {
                            $height++;
                        }
                    }
                    if ($imageindex == count($imagestream_filelist) - 1) {
                        $additionalfile = $filenumber + 1;
                        $additionalfile = sprintf("%03d", $additionalfile);
                        copy($imagestream_workingfiles . DIRECTORY_SEPARATOR . "imagestream" . $filenumber . ".jpg", $imagestream_workingfiles . DIRECTORY_SEPARATOR . "imagestream" . $additionalfile . ".jpg");
                        $deletion_array[] = $imagestream_workingfiles . DIRECTORY_SEPARATOR . "imagestream" . $additionalfile . ".jpg";
                    }
                    $filenumber++;
                }
                #end of loop for each uploadedfile
                $imageindex++;
            }
            #Add the resource and move this zip file, set extension
            # Add to collection?
            if ($collection_add != "") {
                add_resource_to_collection($ref, $collection_add);
            }
            # Log this
            daily_stat("Resource upload", $ref);
            resource_log($ref, "u", 0);
            #Change this!!!!!!!!!!!
            #$status=upload_file($ref,true,false,false));
            if (!$config_windows) {
                @chmod($imagestreamzippath, 0777);
            }
            # Store extension in the database and update file modified time.
            sql_query("update resource set file_extension='zip',preview_extension='zip',file_modified=now(), has_image=0 where ref='{$ref}'");
            #update_field($ref,$filename_field,$filename);
            update_disk_usage($ref);
            # create the mp4 version
            # Add a new alternative file
            $aref = add_alternative_file($ref, "MP4 version");
            $imagestreamqtfile = get_resource_path($ref, true, "", false, "mp4", -1, 1, false, "", $aref);
            $shell_exec_cmd = $ffmpeg_fullpath . " -loglevel panic -y -r " . $imagestream_transitiontime . " -i " . $imagestream_workingfiles . DIRECTORY_SEPARATOR . "imagestream%3d.jpg -r " . $imagestream_transitiontime . " -s {$width}x{$height} " . $imagestreamqtfile;
            echo "Running command: " . $shell_exec_cmd;
            if ($config_windows) {
                $shell_exec_cmd = $ffmpeg_fullpath . " -loglevel panic -y -r " . $imagestream_transitiontime . " -i " . $imagestream_workingfiles . DIRECTORY_SEPARATOR . "imagestream%%3d.jpg -r " . $imagestream_transitiontime . " -s {$width}x{$height} " . $imagestreamqtfile;
                file_put_contents(get_temp_dir() . DIRECTORY_SEPARATOR . "imagestreammp4" . $session_hash . ".bat", $shell_exec_cmd);
                $shell_exec_cmd = get_temp_dir() . DIRECTORY_SEPARATOR . "imagestreammp4" . $session_hash . ".bat";
                $deletion_array[] = $shell_exec_cmd;
            }
            run_command($shell_exec_cmd);
            debug("DEBUG created slideshow MP4 video");
            if (!$config_windows) {
                @chmod($imagestreamqtfile, 0777);
            }
            $file_size = @filesize_unlimited($imagestreamqtfile);
            # Save alternative file data.
            sql_query("update resource_alt_files set file_name='quicktime.mp4',file_extension='mp4',file_size='" . $file_size . "',creation_date=now() where resource='{$ref}' and ref='{$aref}'");
            #create the FLV preview as per normal video processing if possible?
            if ($height < $ffmpeg_preview_min_height) {
                $height = $ffmpeg_preview_min_height;
            }
            if ($width < $ffmpeg_preview_min_width) {
                $width = $ffmpeg_preview_min_width;
            }
            if ($height > $ffmpeg_preview_max_height) {
                $width = ceil($width * ($ffmpeg_preview_max_height / $height));
                $height = $ffmpeg_preview_max_height;
            }
            if ($width > $ffmpeg_preview_max_width) {
                $height = ceil($height * ($ffmpeg_preview_max_width / $width));
                $width = $ffmpeg_preview_max_width;
            }
            $flvzippreviewfile = get_resource_path($ref, true, "pre", false, $ffmpeg_preview_extension);
            $shell_exec_cmd = $ffmpeg_fullpath . " -loglevel panic -y -i " . $imagestreamqtfile . " {$ffmpeg_preview_options} -s {$width}x{$height} " . $flvzippreviewfile;
            debug("Running command: " . $shell_exec_cmd);
            if ($config_windows) {
                file_put_contents(get_temp_dir() . DIRECTORY_SEPARATOR . "imagestreamflv" . $session_hash . ".bat", $shell_exec_cmd);
                $shell_exec_cmd = get_temp_dir() . DIRECTORY_SEPARATOR . "imagestreamflv" . $session_hash . ".bat";
                $deletion_array[] = $shell_exec_cmd;
            }
            run_command($shell_exec_cmd);
            debug("DEBUG created slideshow FLV video");
            if (!$config_windows) {
                @chmod($flvzippreviewfile, 0777);
            }
            #Tidy up
            rcRmdir($imagestream_workingfiles);
            rcRmdir($targetDir);
            foreach ($deletion_array as $tmpfile) {
                debug("\r\nDEBUG: Deleting: " . $tmpfile);
                delete_exif_tmpfile($tmpfile);
            }
            echo "SUCCESS";
            #return true;
            exit;
        } else {
            echo "SUCCESS";
            exit;
        }
        return true;
    } else {
        return false;
    }
}
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:101,代码来源:upload_plupload.php

示例13: elseif

                } elseif (preg_match("/^_ORIG[0-9]*/i", $thisfilesuffix)) {
                    $alt_title = "Original Scan";
                } elseif (preg_match("/^_TPV[0-9]*/i", $thisfilesuffix)) {
                    $alt_title = "Title Page Verso";
                } elseif (preg_match("/^_TP[0-9]*/i", $thisfilesuffix)) {
                    $alt_title = "Title Page";
                } elseif (preg_match("/^_COV[0-9]*/i", $thisfilesuffix)) {
                    $alt_title = "Cover";
                } elseif (preg_match("/^_SCR[0-9]*/i", $thisfilesuffix)) {
                    $alt_title = "Inscription";
                } elseif (preg_match("/^_EX[0-9]*/i", $thisfilesuffix)) {
                    $alt_title = "Enclosure";
                } else {
                    $alt_title = $filename;
                }
                $aref = add_alternative_file($resource, $alt_title, strtoupper($ext) . " " . $lang["file"], $thefile, $ext, filesize_unlimited($thefile));
                $path = get_resource_path($resource, true, "", true, $ext, -1, 1, false, "", $aref);
                rename($thefile, $path);
                # Move alternative file
                global $alternative_file_previews;
                if ($alternative_file_previews) {
                    create_previews($resource, false, $ext, false, false, $aref);
                }
            } else {
                echo date('Y-m-d H:i:s    ');
                echo "matching resource not found.\n";
            }
        }
    }
}
function dir_tree($dir)
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:31,代码来源:ss_alt_makeup.php

示例14: recover_resource_files

function recover_resource_files($id, $res, $meta, $alts)
{
    // this is where we actually start doing the import
    global $res_skipped;
    $ext = pathinfo($res, PATHINFO_EXTENSION);
    if (sql_value("select count(*) value from resource where ref = '{$id}'", "0") > 0) {
        echo "resource {$id} already exists! Skipping!\n";
        $res_skipped++;
        return false;
    } else {
        echo "new resource\n";
        // 1: photo, 2:document, 3:video, 4: audio
        // going to have to guess at the type for now, since the xml file did not record it. Fixme - xml file should have this.
        global $ffmpeg_supported_extensions, $ffmpeg_audio_extensions, $camera_autorotation_ext, $unoconv_extensions;
        if (in_array($ext, $ffmpeg_supported_extensions)) {
            $rtype = '3';
        } elseif (in_array($ext, $ffmpeg_audio_extensions)) {
            $rtype = '4';
        } elseif (in_array($ext, $unoconv_extensions)) {
            $rtype = '2';
        } elseif (in_array($ext, $camera_autorotation_ext)) {
            $rtype = '1';
        } else {
            $rtype = 'null';
        }
        $sql = "insert into resource (ref, title, file_extension,resource_type) values ('{$id}','RECOVERED','{$ext}','{$rtype}')";
        sql_query($sql);
        $newpath = get_resource_path($id, true, '', true, $ext);
        if (!copy($res, $newpath)) {
            echo "ERROR copying {$res}.\n";
            die;
        }
        // fixme: add alternates
        foreach ($alts as $altid => $altpath) {
            $filext = pathinfo($altpath, PATHINFO_EXTENSION);
            $filesize = filesize_unlimited($altpath);
            $newid = add_alternative_file($id, "{$altid}.{$filext}", '', '', $filext, $filesize);
            $newpath = get_resource_path($id, true, "", false, $filext, -1, 1, false, "", $newid);
            if (!copy($altpath, $newpath)) {
                echo "ERROR copying {$res}.\n";
                die;
            }
            echo "previews: " . create_previews($id, false, $filext, false, false, $newid);
            echo "\n\n";
        }
        create_previews($id, false, $ext);
        populate_metadata_from_dump($id, $meta);
    }
}
开发者ID:perryrothjohnson,项目名称:resourcespace,代码行数:49,代码来源:recover.php

示例15: getval

        break;
    }
}
# Split action
if (getval("method", "") != "") {
    $ranges = getval("ranges", "");
    $rs = explode(",", $ranges);
    # Original file path
    $file = get_resource_path($ref, true, "", true, "pdf");
    foreach ($rs as $r) {
        # For each range
        $s = explode(":", $r);
        $from = $s[0];
        $to = $s[1];
        if (getval("method", "") == "alternativefile") {
            $aref = add_alternative_file($ref, $lang["pages"] . " " . $from . " - " . $to, "", "", "pdf");
            $copy_path = get_resource_path($ref, true, "", true, "pdf", -1, 1, false, "", $aref);
        } else {
            # Create a new resource based upon the metadata/type of the current resource.
            $copy = copy_resource($ref);
            # Find out the path to the original file.
            $copy_path = get_resource_path($copy, true, "", true, "pdf");
        }
        # Extract this one page to a new resource.
        $ghostscript_fullpath = get_utility_path("ghostscript");
        $gscommand = $ghostscript_fullpath . " -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=" . escapeshellarg($copy_path) . "  -dFirstPage=" . $from . " -dLastPage=" . $to . " " . escapeshellarg($file);
        $output = run_command($gscommand);
        if (getval("method", "") == "alternativefile") {
            # Preview creation for alternative files (enabled via config)
            global $alternative_file_previews;
            if ($alternative_file_previews) {
开发者ID:chandradrupal,项目名称:resourcespace,代码行数:31,代码来源:pdf_split.php


注:本文中的add_alternative_file函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。