/** * Update previews for given ref. * * @param $ref Resource ref to update * @return bool True is resource exists */ function update_preview($ref) { global $previewbased; $resourceinfo = sql_query("select ref, file_extension from resource where ref='{$ref}'"); if (count($resourceinfo) > 0) { create_previews($ref, false, $previewbased ? "jpg" : $resourceinfo[0]["file_extension"], false, $previewbased); return true; } return false; }
/** * Update previews for given ref. * * @param $ref Resource ref to update * @return bool True is resource exists */ function update_preview($ref) { global $previewbased; $resourceinfo = sql_query("select ref, file_extension, file_path from resource where ref='{$ref}'"); if (count($resourceinfo) > 0) { if (!empty($resourceinfo[0]['file_path'])) { $ingested = false; } else { $ingested = true; } create_previews($ref, false, $previewbased ? "jpg" : $resourceinfo[0]["file_extension"], false, $previewbased, -1, false, $ingested); hook("afterupdatepreview", "", array($ref)); return true; } return false; }
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; } }
public function updateResource() { $rid = $this->resourceId(); // resource does not exist - create it if ($rid == 0) { $rid = create_resource($this->type); } else { update_resource_type($rid, $this->type); } foreach ($this->fields as $k => $v) { update_field($rid, $k, $v); } if (file_exists($this->filename)) { $extension = explode(".", $this->filename); if (count($extension) > 1) { $extension = trim(strtolower($extension[count($extension) - 1])); } else { $extension = ""; } $path = get_resource_path($rid, true, "", true, $extension); copy($this->filename, $path); create_previews($rid, false, $extension); # add file extension sql_query("update resource set file_extension='" . escapeString($extension) . "' where ref='" . escapeString($rid) . "'"); } # add resource to collection (if the collection exists) if ($this->collection != null) { $col_ref = sql_value("select ref as value from collection where name='" . escapeString($this->collection) . "'", 0); if (isset($col_ref)) { add_resource_to_collection($rid, $col_ref); } } # set access rights if ($this->access != null) { sql_query("update resource set access='" . escapeString($this->access) . "' where ref='" . escapeString($rid) . "'"); } }
} 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) { $path = ''; $stack[] = $dir; while ($stack) { $thisdir = array_pop($stack); if ($dircont = scandir($thisdir)) {
$origalttitle = $lang['priorversion']; $origaltdesc = $lang['replaced'] . " " . strftime("%Y-%m-%d, %H:%M"); $origfilename = sql_value("select value from resource_data left join resource_type_field on resource_data.resource_type_field = resource_type_field.ref where resource = '{$ref}' and name = 'original_filename'", $ref . "_original.{$orig_ext}"); $origalt = add_alternative_file($ref, $origalttitle, $origaltdesc); $origaltpath = get_resource_path($ref, true, "", true, $orig_ext, -1, 1, false, "", $origalt); $mporig = round($origwidth * $origheight / 1000000, 2); $filesizeorig = filesize_unlimited($originalpath); rename($originalpath, $origaltpath); $result = sql_query("update resource_alt_files set file_name='{$origfilename}',file_extension='{$orig_ext}',file_size = '{$filesizeorig}' where ref='{$origalt}'"); $neworigpath = get_resource_path($ref, true, '', false, $new_ext); rename($newpath, $neworigpath); $result = sql_query("update resource set file_extension = '{$new_ext}' where ref = '{$ref}' limit 1"); // update extension resource_log($ref, 't', '', 'original transformed'); create_previews($ref, false, $orig_ext, false, false, $origalt); create_previews($ref, false, $new_ext); # delete existing resource_dimensions sql_query("delete from resource_dimensions where resource='{$ref}'"); sql_query("insert into resource_dimensions (resource, width, height, file_size) values ('{$ref}', '{$newfilewidth}', '{$newfileheight}', '{$newfilesize}')"); # call remove annotations, since they will not apply to transformed hook("removeannotations"); // remove the cached transform preview, since it will no longer be accurate if (file_exists(get_temp_dir() . "/transform_plugin/pre_{$ref}.jpg")) { unlink(get_temp_dir() . "/transform_plugin/pre_{$ref}.jpg"); } redirect("pages/view.php?ref={$ref}"); exit; } elseif (getval("slideshow", "") != "" && !$cropperestricted) { # Produce slideshow. $sequence = getval("sequence", ""); if (!is_numeric($sequence)) {
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); } }
echo "Just added so may not have finished copying, resetting attempts \n"; sql_query("UPDATE resource SET preview attempts=0 WHERE ref='" . $resource['ref'] . "'"); continue; } #check whether resource already has mp3 preview in which case we set preview_attempts to 5 if ($resource['file_extension'] != "mp3" && file_exists(get_resource_path($resource['ref'], true, "", false, "mp3"))) { $ref = $resource['ref']; echo "Resource already has mp3 preview\n"; sql_query("update resource set preview_attempts=5 where ref='{$ref}'"); } elseif ($resource['preview_attempts'] < 5 and $resource['file_extension'] != "") { if (!empty($resource['file_path'])) { $ingested = false; } else { $ingested = true; } create_previews($resource['ref'], false, $resource['file_extension'], false, false, -1, $ignoremaxsize, $ingested); echo sprintf("Processed resource %d in %01.2f seconds.\n", $resource['ref'], microtime(true) - $start_time); } else { sql_query("update resource set preview_attempts=ifnull(preview_attempts,0) + 1 where ref='" . $resource['ref'] . "'"); echo sprintf("Skipped resource " . $resource['ref'] . " - maximum attempts reached or nonexistent file extension. \n"); } if ($multiprocess) { // We exit in order to avoid fork bombing. exit(0); } } } } // Test if we can create a new fork } // For each resources
$collection = getvalescaped('collection', "", true); $result = move_uploaded_file($_FILES['userfile']['tmp_name'], $filepath); $wait = sql_query("update resource set file_extension='{$extension}',preview_extension='jpg',file_modified=now() ,has_image=0 where ref='{$ref}'"); # Store original filename in field, if set global $filename_field; if (isset($filename_field)) { $wait = update_field($ref, $filename_field, $_FILES['userfile']['name']); } // extract metadata $wait = extract_exif_comment($ref, $extension); $resource = get_resource_data($ref); //create previews if ($camera_autorotation) { AutoRotateImage($filepath); } $wait = create_previews($ref, false, $extension); // add resource to collection if ($collection != "") { $collection_exists = sql_value("select name value from collection where ref='" . escape_check($collection) . "'", ""); if ($collection_exists != "") { if (!add_resource_to_collection($ref, $collection)) { header("HTTP/1.0 403 Forbidden."); echo "HTTP/1.0 403 Forbidden. Collection is not writable by this user.\n"; exit; } } else { header("HTTP/1.0 403 Forbidden."); echo "HTTP/1.0 403 Forbidden. Collection does not exist.\n"; exit; } }
case "rotateclock": tweak_preview_images($ref, 270, 0, $resource["preview_extension"]); break; case "rotateanti": tweak_preview_images($ref, 90, 0, $resource["preview_extension"]); break; case "gammaplus": tweak_preview_images($ref, 0, 1.3, $resource["preview_extension"]); break; case "gammaminus": tweak_preview_images($ref, 0, 0.7, $resource["preview_extension"]); break; case "restore": sql_query("update resource set preview_attempts=0 WHERE ref='" . $ref . "'"); if ($enable_thumbnail_creation_on_upload) { create_previews($ref, false, $resource["file_extension"], false, false, -1, true); refresh_collection_frame(); } else { sql_query("update resource set preview_attempts=0, has_image=0 where ref='{$ref}'"); } break; } hook("moretweakingaction", "", array($tweak, $ref, $resource)); # Reload resource data. $resource = get_resource_data($ref, false); } # Simulate reupload (preserving filename and thumbs, but otherwise resetting metadata). if (getval("exif", "") != "") { upload_file($ref, $no_exif = false, true); resource_log($ref, "r", ""); }
function update_resource($r, $path, $type, $title, $ingest = false, $createPreviews = true) { # Update the resource with the file at the given path # Note that the file will be used at it's present location and will not be copied. global $syncdir, $staticsync_prefer_embedded_title; update_resource_type($r, $type); # Work out extension based on path $extension = explode(".", $path); if (count($extension) > 1) { $extension = trim(strtolower(end($extension))); } else { //No extension $extension = ""; } # file_path should only really be set to indicate a staticsync location. Otherwise, it should just be left blank. if ($ingest) { $file_path = ""; } else { $file_path = escape_check($path); } # Store extension/data in the database sql_query("update resource set archive=0,file_path='" . $file_path . "',file_extension='{$extension}',preview_extension='{$extension}',file_modified=now() where ref='{$r}'"); # Store original filename in field, if set if (!$ingest) { # This file remains in situ; store the full path in file_path to indicate that the file is stored remotely. global $filename_field; if (isset($filename_field)) { $s = explode("/", $path); $filename = end($s); update_field($r, $filename_field, $filename); } } else { # This file is being ingested. Store only the filename. $s = explode("/", $path); $filename = end($s); global $filename_field; if (isset($filename_field)) { update_field($r, $filename_field, $filename); } # Move the file global $syncdir; $destination = get_resource_path($r, true, "", true, $extension); $result = rename($syncdir . "/" . $path, $destination); if ($result === false) { # The rename failed. The file is possibly still being copied or uploaded and must be ignored on this pass. # Delete the resouce just created and return false. delete_resource($r); return false; } chmod($destination, 0777); } # generate title and extract embedded metadata # order depends on which title should be the default (embedded or generated) if ($staticsync_prefer_embedded_title) { update_field($r, 8, $title); extract_exif_comment($r, $extension); } else { extract_exif_comment($r, $extension); update_field($r, 8, $title); } # Ensure folder is created, then create previews. get_resource_path($r, false, "pre", true, $extension); if ($createPreviews) { # Attempt autorotation global $autorotate_ingest; if ($ingest && $autorotate_ingest) { AutoRotateImage($destination); } # Generate previews/thumbnails (if configured i.e if not completed by offline process 'create_previews.php') global $enable_thumbnail_creation_on_upload; if ($enable_thumbnail_creation_on_upload) { create_previews($r, false, $extension, false, false, -1, false, $ingest); } } # Pass back the newly created resource ID. return $r; }
function upload_preview($ref) { hook("removeannotations", "", array($ref)); # Upload a preview image only. $processfile = $_FILES['userfile']; $filename = strtolower(str_replace(" ", "_", $processfile['name'])); # Work out extension $extension = explode(".", $filename); $extension = trim(strtolower($extension[count($extension) - 1])); if ($extension == "jpeg") { $extension = "jpg"; } # Move uploaded file into position. $filepath = get_resource_path($ref, true, "tmp", true, $extension); $result = move_uploaded_file($processfile['tmp_name'], $filepath); if ($result != false) { chmod($filepath, 0777); } # Create previews create_previews($ref, false, $extension, true); # Delete temporary file, if not transcoding. if (!sql_value("SELECT is_transcoding value FROM resource WHERE ref = '" . escape_check($ref) . "'", false)) { unlink($filepath); } return true; }
function HookVideo_spliceViewAfterresourceactions() { global $videosplice_resourcetype, $resource, $lang, $config_windows, $resourcetoolsGT; if ($resource["resource_type"] != $videosplice_resourcetype) { return false; } # Not the right type. if (getval("video_splice_cut_from_hours", "") != "") { # Process actions $error = ""; # Receive input $fh = getvalescaped("video_splice_cut_from_hours", ""); $fm = getvalescaped("video_splice_cut_from_minutes", ""); $fs = getvalescaped("video_splice_cut_from_seconds", ""); $th = getvalescaped("video_splice_cut_to_hours", ""); $tm = getvalescaped("video_splice_cut_to_minutes", ""); $ts = getvalescaped("video_splice_cut_to_seconds", ""); $preview = getvalescaped("preview", "") != ""; # Calculate a duration, as needed by FFMPEG $from_seconds = $fh * 60 * 60 + $fm * 60 + $fs; $to_seconds = $th * 60 * 60 + $tm * 60 + $ts; $seconds = $to_seconds - $from_seconds; # Any problems? if ($seconds <= 0) { $error = $lang["error-from_time_after_to_time"]; } # Convert seconds to HH:MM:SS as required by FFmpeg. $dh = floor($seconds / (60 * 60)); $dm = floor(($seconds - $dh * 60 * 60) / 60); $ds = floor($seconds - $dh * 60 * 60 - $dm * 60); # Show error message if necessary if ($error != "") { ?> <script type="text/javascript"> alert("<?php echo $error; ?> "); </script> <?php } else { # Process video. $ss = $fh . ":" . $fm . ":" . $fs; $t = str_pad($dh, 2, "0", STR_PAD_LEFT) . ":" . str_pad($dm, 2, "0", STR_PAD_LEFT) . ":" . str_pad($ds, 2, "0", STR_PAD_LEFT); # Establish FFMPEG location. $ffmpeg_fullpath = get_utility_path("ffmpeg"); # Work out source/destination global $ffmpeg_preview_extension, $ref; if (file_exists(get_resource_path($ref, true, "pre", false, $ffmpeg_preview_extension))) { $source = get_resource_path($ref, true, "pre", false, $ffmpeg_preview_extension, -1, 1, false, "", -1, false); } else { $source = get_resource_path($ref, true, "", false, $ffmpeg_preview_extension, -1, 1, false, "", -1, false); } # Preview only? global $userref; if ($preview) { # Preview only. $target = get_temp_dir() . "/video_splice_preview_" . $userref . "." . $ffmpeg_preview_extension; } else { # Not a preview. Create a new resource. $newref = copy_resource($ref); $target = get_resource_path($newref, true, "", true, $ffmpeg_preview_extension, -1, 1, false, "", -1, false); # Set parent resource field details. global $videosplice_parent_field; update_field($newref, $videosplice_parent_field, $ref . ": " . $resource["field8"] . " [{$fh}:{$fm}:{$fs} - {$th}:{$tm}:{$ts}]"); # Set created_by, archive and extension sql_query("update resource set created_by='{$userref}',archive=-2,file_extension='" . $ffmpeg_preview_extension . "' where ref='{$newref}'"); } # Unlink the target if (file_exists($target)) { unlink($target); } if ($config_windows) { # Windows systems have a hard time with the long paths used for video generation. $target_ext = strrchr($target, '.'); $source_ext = strrchr($source, '.'); $target_temp = get_temp_dir() . "/vs_t" . $newref . $target_ext; $target_temp = str_replace("/", "\\", $target_temp); $source_temp = get_temp_dir() . "/vs_s" . $ref . $source_ext; $source_temp = str_replace("/", "\\", $source_temp); copy($source, $source_temp); $shell_exec_cmd = $ffmpeg_fullpath . " -y -i " . escapeshellarg($source_temp) . " -ss {$ss} -t {$t} " . escapeshellarg($target_temp); $output = exec($shell_exec_cmd); rename($target_temp, $target); unlink($source_temp); } else { $shell_exec_cmd = $ffmpeg_fullpath . " -y -i " . escapeshellarg($source) . " -ss {$ss} -t {$t} " . escapeshellarg($target); $output = exec($shell_exec_cmd); } #echo "<p>" . $shell_exec_cmd . "</p>"; # Generate preview/thumbs if not in preview mode if (!$preview) { include_once "../include/image_processing.php"; create_previews($newref, false, $ffmpeg_preview_extension); # Add the resource to the user's collection. global $usercollection, $baseurl; add_resource_to_collection($newref, $usercollection); ?> <script type="text/javascript"> top.collections.location.href="<?php echo $baseurl; ?> /pages/collections.php?nc=<?php echo time(); ?> "; </script> <?php } } } ?> <li><a href="#" onClick=" if (document.getElementById('videocut').style.display=='block') {document.getElementById('videocut').style.display='none';} else {document.getElementById('videocut').style.display='block';} return false;"><?php echo ($resourcetoolsGT ? "> " : "") . $lang["action-cut"]; ?> </a></li> <form id="videocut" style="<?php if (!(isset($preview) && $preview)) { ?> display:none;<?php } ?> padding:10px 0 3px 0;" method="post"> <table> <tr> <td><?php echo $lang["from-time"]; ?> </td> <td><?php echo $lang["hh"]; ?> <select name="video_splice_cut_from_hours"> <?php for ($n = 0; $n < 100; $n++) { ?> <option <?php if (isset($fh) && $fh == $n) { ?> selected<?php } ?> ><?php echo str_pad($n, 2, "0", STR_PAD_LEFT); ?> </option><?php } ?> </select></td> <td><?php echo $lang["mm"]; ?> <select name="video_splice_cut_from_minutes"> <?php for ($n = 0; $n < 60; $n++) { ?> <option <?php if (isset($fm) && $fm == $n) { ?> selected<?php } ?> ><?php echo str_pad($n, 2, "0", STR_PAD_LEFT); ?> </option><?php } ?> </select></td> <td><?php echo $lang["ss"]; ?> <select name="video_splice_cut_from_seconds"> <?php for ($n = 0; $n < 60; $n++) { ?> <option <?php if (isset($fs) && $fs == $n) { ?> selected<?php } ?> ><?php echo str_pad($n, 2, "0", STR_PAD_LEFT); ?> </option><?php } ?> </select></td> </tr> <tr> <td><?php echo $lang["to-time"]; ?> </td> <td><?php echo $lang["hh"]; ?> <select name="video_splice_cut_to_hours"> <?php for ($n = 0; $n < 100; $n++) { ?> <option <?php if (isset($th) && $th == $n) { ?> selected<?php } ?> ><?php echo str_pad($n, 2, "0", STR_PAD_LEFT); ?> </option><?php } ?> </select></td> <td><?php echo $lang["mm"]; ?> <select name="video_splice_cut_to_minutes"> <?php for ($n = 0; $n < 60; $n++) { ?> <option <?php if (isset($tm) && $tm == $n) { ?> selected<?php } ?> ><?php echo str_pad($n, 2, "0", STR_PAD_LEFT); ?> </option><?php } ?> </select></td> <td><?php echo $lang["ss"]; ?> <select name="video_splice_cut_to_seconds"> <?php for ($n = 0; $n < 60; $n++) { ?> <option <?php if (isset($ts) && $ts == $n) { ?> selected<?php } ?> ><?php echo str_pad($n, 2, "0", STR_PAD_LEFT); ?> </option><?php } ?> </select></td> </tr> <tr><td colspan=4 align="center"> <input type="submit" name="preview" value="<?php echo $lang["action-preview"]; ?> " style="width:40%;"> <input type="submit" name="cut" value="<?php echo $lang["action-cut"]; ?> " style="width:40%;"> </td></tr> </table> <?php if (isset($preview) && $preview) { # Show the preview # Work out a colour theme global $userfixedtheme; $theme = isset($userfixedtheme) && $userfixedtheme != "" ? $userfixedtheme : getval("colourcss", "greyblu"); $colour = "505050"; if ($theme == "greyblu") { $colour = "446693"; } global $baseurl; # Embedded preview player ?> <p align="center"> <object type="application/x-shockwave-flash" data="../lib/flashplayer/player_flv_maxi.swf" width="240" height="135"> <param name="allowFullScreen" value="true" /> <param name="movie" value="../lib/flashplayer/player_flv_maxi.swf" /> <param name="FlashVars" value="flv=<?php echo convert_path_to_url($target); ?> &width=240&height=135&margin=0&buffer=10&showvolume=0&volume=200&showtime=0&autoplay=1&autoload=1&showfullscreen=0&showstop=0&playercolor=<?php echo $colour; ?> " /> </object> </p> <?php } ?> </form> <?php return true; }
} else { $shell_exec_cmd = "cat {$vidlist} > " . escapeshellarg($targetmpg); } $output = exec($shell_exec_cmd); # Remove the temporary files. for ($n = 0; $n < count($videos); $n++) { $intermediary = get_temp_dir() . "/video_splice_temp_" . $videos[$n]["ref"] . ".mpg"; if ($config_windows) { $intermediary = str_replace("/", "\\", $intermediary); } unlink($intermediary); } # Update the file extension & date. $result = sql_query("update resource set file_extension = 'mpg', creation_date = now() where ref = '{$ref}' limit 1"); # Create previews. create_previews($ref, false, "mpg"); redirect("pages/view.php?ref=" . $ref); } include "../../../include/header.php"; ?> <h1><?php echo $lang["splice"]; ?> </h1> <p><?php echo $lang["intro-splice"]; ?> </p> <p><?php echo $lang["drag_and_drop_to_rearrange"];
$command = $basecommand . " \"{$path}\""; $command .= " -delete 1--1 -flatten "; // make sure we're only operating on first layer; fixes embedded preview weirdness if ($rotation > 0) { $command .= " -rotate {$rotation} "; } $command .= " \"{$newpath}\""; //echo " $command<br>"; $shell_result = run_command($command); if (file_exists($newpath) && filesize_unlimited($newpath) > 0) { // success! if (!rename($newpath, $path)) { echo " " . str_replace("%res", $resource, $lang['error-unable-to-rename']) . "<br />\n"; $failcount++; } else { create_previews($resource, false, $new_ext); // get final pixel dimensions of resulting file $newfilesize = filesize_unlimited($path); $newfiledimensions = getimagesize($path); $newfilewidth = $newfiledimensions[0]; $newfileheight = $newfiledimensions[1]; # delete existing resource_dimensions sql_query("delete from resource_dimensions where resource='{$resource}'"); sql_query("insert into resource_dimensions (resource, width, height, file_size) values ('{$resource}', '{$newfilewidth}', '{$newfileheight}', '{$newfilesize}')"); resource_log($resource, 't', '', 'batch transform'); echo "<img src='" . get_resource_path($resource, false, "thm", false, 'jpg', -1, 1) . "' /><br />\n"; echo " " . $lang['success'] . "<br />\n"; $successcount++; } } else { echo " " . str_replace("%res", $resource, $lang['error-transform-failed']) . "<br />\n";
$shell_exec_cmd = str_replace("/", "\\", $shell_exec_cmd); } $output = exec($shell_exec_cmd); # Remove the temporary files. for ($n = 0; $n < count($videos); $n++) { $intermediary = get_temp_dir() . "/video_splice_temp_" . $videos[$n]["ref"] . ".mpg"; if ($config_windows) { $intermediary = str_replace("/", "\\", $intermediary); } unlink($intermediary); } unlink($targetmpg); # Update the file extension. $result = sql_query("update resource set file_extension = '{$ffmpeg_preview_extension}' where ref = '{$ref}' limit 1"); # Create previews. create_previews($ref, false, $ffmpeg_preview_extension); redirect("pages/view.php?ref=" . $ref); } include "../../../include/header.php"; ?> <h1><?php echo $lang["splice"]; ?> </h1> <p><?php echo $lang["intro-splice"]; ?> </p> <p><?php echo $lang["drag_and_drop_to_rearrange"];
function ProcessFolder($folder) { global $lang, $syncdir, $nogo, $staticsync_max_files, $count, $done, $modtimes, $lastsync, $ffmpeg_preview_extension, $staticsync_autotheme, $staticsync_folder_structure, $staticsync_extension_mapping_default, $staticsync_extension_mapping, $staticsync_mapped_category_tree, $staticsync_title_includes_path, $staticsync_ingest, $staticsync_mapfolders, $staticsync_alternatives_suffix, $theme_category_levels, $staticsync_defaultstate; $collection = 0; echo "Processing Folder: $folder" . PHP_EOL; # List all files in this folder. $dh = opendir($folder); while (($file = readdir($dh)) !== false) { if ( $file == '.' || $file == '..') { continue; } $filetype = filetype($folder . "/" . $file); $fullpath = $folder . "/" . $file; $shortpath = str_replace($syncdir . "/", '', $fullpath); # Work out extension $extension = explode(".", $file); if(count($extension)>1) { $extension = trim(strtolower($extension[count($extension)-1])); } else { //No extension $extension=""; } if ($staticsync_mapped_category_tree) { $path_parts = explode("/", $shortpath); array_pop($path_parts); touch_category_tree_level($path_parts); } # -----FOLDERS------------- if ((($filetype == "dir") || $filetype == "link") && (strpos($nogo, "[$file]") === false) && (strpos($file, $staticsync_alternatives_suffix) === false)) { # Recurse ProcessFolder($folder . "/" . $file); } # -------FILES--------------- if (($filetype == "file") && (substr($file,0,1) != ".") && (strtolower($file) != "thumbs.db")) { /* Below Code Adapted from CMay's bug report */ global $banned_extensions; # Check to see if extension is banned, do not add if it is banned if(array_search($extension, $banned_extensions)){continue;} /* Above Code Adapted from CMay's bug report */ $count++; if ($count > $staticsync_max_files) { return(true); } # Already exists? if (!isset($done[$shortpath])) { echo "Processing file: $fullpath" . PHP_EOL; if ($collection == 0 && $staticsync_autotheme) { # Make a new collection for this folder. $e = explode("/", $shortpath); $theme = ucwords($e[0]); $themesql = "theme='" . ucwords(escape_check($e[0])) . "'"; $themecolumns = "theme"; $themevalues = "'" . ucwords(escape_check($e[0])) . "'"; if ($staticsync_folder_structure) { for ($x=0;$x<count($e)-1;$x++) { if ($x != 0) { $themeindex = $x+1; if ($themeindex >$theme_category_levels) { $theme_category_levels = $themeindex; if ($x == count($e)-2) { echo PHP_EOL . PHP_EOL . "UPDATE THEME_CATEGORY_LEVELS TO $themeindex IN CONFIG!!!!" . PHP_EOL . PHP_EOL; } } $th_name = ucwords(escape_check($e[$x])); $themesql .= " AND theme{$themeindex} = '$th_name'"; $themevalues .= ",'$th_name'"; $themecolumns .= ",theme{$themeindex}"; } } } $name = (count($e) == 1) ? '' : $e[count($e)-2]; echo "Collection $name, theme=$theme" . PHP_EOL; $escaped_name = escape_check($name); $collection = sql_value("SELECT ref value FROM collection WHERE name='$escaped_name' AND $themesql", 0); if ($collection == 0) { sql_query("INSERT INTO collection (name,created,public,$themecolumns,allow_changes) VALUES ('$escaped_name', NOW(), 1, $themevalues, 0)"); $collection = sql_insert_id(); } } # Work out a resource type based on the extension. $type = $staticsync_extension_mapping_default; reset($staticsync_extension_mapping); foreach ($staticsync_extension_mapping as $rt => $extensions) { if (in_array($extension,$extensions)) { $type = $rt; } } $modified_type = hook('modify_type', 'staticsync', array( $type )); if (is_numeric($modified_type)) { $type = $modified_type; } # Formulate a title if ($staticsync_title_includes_path) { $title_find = array('/', '_', ".$extension" ); $title_repl = array(' - ', ' ', ''); $title = ucfirst(str_ireplace($title_find, $title_repl, $shortpath)); } else { $title = str_ireplace(".$extension", '', $file); } $modified_title = hook('modify_title', 'staticsync', array( $title )); if ($modified_title !== false) { $title = $modified_title; } # Import this file $r = import_resource($shortpath, $type, $title, $staticsync_ingest); if ($r !== false) { # Add to mapped category tree (if configured) if (isset($staticsync_mapped_category_tree)) { $basepath = ''; # Save tree position to category tree field # For each node level, expand it back to the root so the full path is stored. for ($n=0;$n<count($path_parts);$n++) { if ($basepath != '') { $basepath .= "~"; } $basepath .= $path_parts[$n]; $path_parts[$n] = $basepath; } update_field($r, $staticsync_mapped_category_tree, "," . join(",", $path_parts)); } # default access level. This may be overridden by metadata mapping. $accessval = 0; # StaticSync path / metadata mapping # Extract metadata from the file path as per $staticsync_mapfolders in config.php if (isset($staticsync_mapfolders)) { foreach ($staticsync_mapfolders as $mapfolder) { $match = $mapfolder["match"]; $field = $mapfolder["field"]; $level = $mapfolder["level"]; if (strpos("/" . $shortpath, $match) !== false) { # Match. Extract metadata. $path_parts = explode("/", $shortpath); if ($level < count($path_parts)) { // special cases first. if ($field == 'access') { # access level is a special case # first determine if the value matches a defined access level $value = $path_parts[$level-1]; for ($n=0; $n<3; $n++){ # if we get an exact match or a match except for case if ($value == $lang["access" . $n] || strtoupper($value) == strtoupper($lang['access' . $n])) { $accessval = $n; echo "Will set access level to " . $lang['access' . $n] . " ($n)" . PHP_EOL; } } } else { # 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 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'"); } } } } } }
} break; case "gammaminus": foreach ($resources as $resource) { tweak_preview_images($resource['ref'], 0, 0.7, $resource["preview_extension"]); } break; case "restore": foreach ($resources as $resource) { $ref = $resource['ref']; if (!empty($resource['file_path'])) { $ingested = false; } else { $ingested = true; } create_previews($resource['ref'], false, $resource["file_extension"], false, false, -1, true, $ingested); } break; } refresh_collection_frame(); $done = true; } include "../include/header.php"; ?> <p style="margin:7px 0 7px 0;padding:0;"><a onClick="return CentralSpaceLoad(this,true);" href="<?php if ($backto != '') { echo $backto; } else { echo $baseurl_short . 'pages/search'; } ?>
function ProcessFolder($folder) { #echo "<br>processing folder $folder"; global $syncdir, $nogo, $max, $count, $done, $modtimes, $lastsync, $ffmpeg_preview_extension, $staticsync_autotheme, $staticsync_extension_mapping_default, $staticsync_extension_mapping, $staticsync_mapped_category_tree, $staticsync_title_includes_path, $staticsync_ingest, $staticsync_mapfolders, $staticsync_alternatives_suffix, $staticsync_alt_suffixes, $staticsync_alt_suffix_array, $file_minimum_age, $staticsync_run_timestamp; $collection = 0; echo "Processing Folder: {$folder}\n"; # List all files in this folder. $dh = opendir($folder); echo date('Y-m-d H:i:s '); echo "Reading from {$folder}\n"; while (($file = readdir($dh)) !== false) { // because of alternative processing, some files may disappear during the run // that's ok - just ignore it and move on if (!file_exists($folder . "/" . $file)) { echo date('Y-m-d H:i:s '); echo "File {$file} missing. Moving on.\n"; continue; } $filetype = filetype($folder . "/" . $file); $fullpath = $folder . "/" . $file; $shortpath = str_replace($syncdir . "/", "", $fullpath); if ($staticsync_mapped_category_tree) { $path_parts = explode("/", $shortpath); array_pop($path_parts); touch_category_tree_level($path_parts); } # -----FOLDERS------------- if (($filetype == "dir" || $filetype == "link") && $file != "." && $file != ".." && strpos($nogo, "[" . $file . "]") === false && strpos($file, $staticsync_alternatives_suffix) === false) { # Recurse #echo "\n$file : " . filemtime($folder . "/" . $file) . " > " . $lastsync; if (true || strlen($lastsync) == "" || filemtime($folder . "/" . $file) > $lastsync - 26000) { ProcessFolder($folder . "/" . $file); } } # -------FILES--------------- if ($filetype == "file" && substr($file, 0, 1) != "." && strtolower($file) != "thumbs.db" && !ss_is_alt($file)) { // we want to make sure we don't touch files that are too new // so check this if (time() - filectime($folder . "/" . $file) < $file_minimum_age) { echo date('Y-m-d H:i:s '); echo " {$file} too new -- skipping .\n"; //echo filectime($folder . "/" . $file) . " " . time() . "\n"; continue; } # Already exists? if (!in_array($shortpath, $done)) { $count++; if ($count > $max) { return true; } echo date('Y-m-d H:i:s '); echo "Processing file: {$fullpath}\n"; if ($collection == 0 && $staticsync_autotheme) { # Make a new collection for this folder. $e = explode("/", $shortpath); $theme = ucwords($e[0]); $name = count($e) == 1 ? "" : $e[count($e) - 2]; echo date('Y-m-d H:i:s '); echo "\nCollection {$name}, theme={$theme}"; $collection = sql_value("select ref value from collection where name='" . escape_check($name) . "' and theme='" . escape_check($theme) . "'", 0); if ($collection == 0) { sql_query("insert into collection (name,created,public,theme,allow_changes) values ('" . escape_check($name) . "',now(),1,'" . escape_check($theme) . "',0)"); $collection = sql_insert_id(); } } # Work out extension $extension = explode(".", $file); $extension = trim(strtolower($extension[count($extension) - 1])); // if coming from collections or la folders, assume these are the resource types if (stristr(strtolower($fullpath), 'collection services/curatorial')) { $type = 5; } elseif (stristr(strtolower($fullpath), 'collection services/conservation')) { $type = 5; } elseif (stristr(strtolower($fullpath), 'collection services/library_archives')) { $type = 6; } else { # Work out a resource type based on the extension. $type = $staticsync_extension_mapping_default; reset($staticsync_extension_mapping); foreach ($staticsync_extension_mapping as $rt => $extensions) { if ($rt == 5 or $rt == 6) { continue; } // we already eliminated those if (in_array($extension, $extensions)) { $type = $rt; } } } # Formulate a title if ($staticsync_title_includes_path) { $title = str_ireplace("." . $extension, "", str_replace("/", " - ", $shortpath)); $title = ucfirst(str_replace("_", " ", $title)); } else { $title = str_ireplace("." . $extension, "", $file); } # Import this file $r = import_resource($shortpath, $type, $title, $staticsync_ingest); if ($r !== false) { # Add to mapped category tree (if configured) if (isset($staticsync_mapped_category_tree)) { $basepath = ""; # Save tree position to category tree field # For each node level, expand it back to the root so the full path is stored. for ($n = 0; $n < count($path_parts); $n++) { if ($basepath != "") { $basepath .= "~"; } $basepath .= $path_parts[$n]; $path_parts[$n] = $basepath; } update_field($r, $staticsync_mapped_category_tree, "," . join(",", $path_parts)); #echo "update_field($r,$staticsync_mapped_category_tree," . "," . join(",",$path_parts) . ");\n"; } # StaticSync path / metadata mapping # Extract metadata from the file path as per $staticsync_mapfolders in config.php if (isset($staticsync_mapfolders)) { foreach ($staticsync_mapfolders as $mapfolder) { $match = $mapfolder["match"]; $field = $mapfolder["field"]; $level = $mapfolder["level"]; if (strpos("/" . $shortpath, $match) !== false) { # Match. Extract metadata. $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)) { $alt_title = "Verso"; } elseif (preg_match("/^_DNG[0-9]*/i", $thisfilesuffix)) { $alt_title = "DNG"; } 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 = $altcandidate; } $aref = add_alternative_file($r, $alt_title, strtoupper($ext) . " " . $lang["file"], $altcandidate, $ext, filesize_unlimited($folder . "/" . $altcandidate)); $path = get_resource_path($r, true, "", true, $ext, -1, 1, false, "", $aref); rename($folder . "/" . $altcandidate, $path); # Move alternative file global $alternative_file_previews; if ($alternative_file_previews) { create_previews($r, false, $ext, false, false, $aref); } } } } } # Add to collection if ($staticsync_autotheme) { sql_query("insert into collection_resource(collection,resource,date_added) values ('{$collection}','{$r}',now())"); } // fix permissions // get directory to fix global $scramble_key; $permfixfolder = "/hne/rs/filestore/"; for ($n = 0; $n < strlen($r); $n++) { $permfixfolder .= substr($r, $n, 1); if ($n == strlen($r) - 1) { $permfixfolder .= "_" . substr(md5($r . "_" . $scramble_key), 0, 15); } $permfixfolder .= "/"; } exec("/bin/chown -R wwwrun {$permfixfolder}"); exec("/bin/chgrp -R www {$permfixfolder}"); } else { # Import failed - file still being uploaded? echo date('Y-m-d H:i:s '); 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 date('Y-m-d H:i:s '); echo "Resource {$rref} has changed, regenerating previews: {$fullpath}\n"; create_previews($rref, false, $rd["file_extension"]); sql_query("update resource set file_modified=now() where ref='{$rref}'"); } } } } } }
# # include "../../include/db.php"; include "../../include/authenticate.php"; if (!checkperm("a")) { exit("Permission denied"); } include "../../include/general.php"; include "../../include/image_processing.php"; include "../../include/resource_functions.php"; $max = sql_value("select max(ref) value from resource_alt_files", 0); $ref = getvalescaped("ref", 1); $previewbased = getvalescaped("previewbased", false); $resourceinfo = sql_query("select a.ref,a.resource,a.file_extension from resource_alt_files a join resource r on a.resource=r.ref where a.ref='{$ref}' and length(a.file_extension)>0"); if (count($resourceinfo) > 0) { create_previews($resourceinfo[0]["resource"], false, $previewbased ? "jpg" : $resourceinfo[0]["file_extension"], false, $previewbased, $ref); ?> <img src="<?php echo get_resource_path($resourceinfo[0]["resource"], false, "pre", false, "jpg", -1, 1, false, "", $ref); ?> "> <?php } else { echo "Skipping {$ref}"; } if ($ref < $max && getval("only", "") == "") { ?> <meta http-equiv="refresh" content="1;url=<?php echo $baseurl; ?> /pages/tools/update_previews_alternative.php?ref=<?php
function save_alternative_file($resource,$ref) { # Saves the 'alternative file' edit form back to the database $sql=""; # Uploaded file provided? if (array_key_exists("userfile",$_FILES)) { # Fetch filename / path $processfile=$_FILES['userfile']; $filename=strtolower(str_replace(" ","_",$processfile['name'])); # Work out extension $extension=explode(".",$filename);$extension=trim(strtolower($extension[count($extension)-1])); # Find the path for this resource. $path=get_resource_path($resource, true, "", true, $extension, -1, 1, false, "", $ref); # Debug debug("Uploading alternative file $ref with extension $extension to $path"); if ($filename!="") { $result=move_uploaded_file($processfile['tmp_name'], $path); if ($result==false) { exit("File upload error. Please check the size of the file you are trying to upload."); } else { chmod($path,0777); $file_size = @filesize_unlimited($path); $sql.=",file_name='" . escape_check($filename) . "',file_extension='" . escape_check($extension) . "',file_size='" . $file_size . "',creation_date=now()"; } # Preview creation for alternative files (enabled via config) global $alternative_file_previews; if ($alternative_file_previews) { create_previews($resource,false,$extension,false,false,$ref); } } } # Save data back to the database. sql_query("update resource_alt_files set name='" . getvalescaped("name","") . "',description='" . getvalescaped("description","") . "',alt_type='" . getvalescaped("alt_type","") . "' $sql where resource='$resource' and ref='$ref'"); # Update disk usage update_disk_usage($resource); }
# get file metadata extract_exif_comment($r,$file['extension']); echo "Extracting Metadata... \r\n"; # Ensure folder is created, then create previews. get_resource_path($r,false,"pre",true,$file['extension']); if ($build_collection){ # Add Resource to Collection echo "Adding Resource $r to Collection $collection \r\n"; add_resource_to_collection($r,$collection,true); } # Generate previews/thumbnails (if configured i.e if not completed by offline process 'create_previews.php') global $enable_thumbnail_creation_on_upload; if ($enable_thumbnail_creation_on_upload) { create_previews($r,false,$file['extension']); echo "Creating Previews... \r\n"; } if (!$build_collection && $checkmail_confirm){ email_resource($r,$subject,$applicationname,$fromusername,$lang['yourresourcehasbeenuploaded'],0,$expires="",$fromaddress,$applicationname); echo "Email Confirmation sent. \r\n"; } if ($checkmail_purge){$delete=true;} $files[$n]['ref']=$r; $refs[]=$r; } if ($build_collection && $checkmail_confirm){ email_collection($collection,$subject,$email_from,$fromaddress,$lang['yourresourceshavebeenuploaded'],false,0,$expires="",$fromaddress,$applicationname);
$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}'"); if ($alternative_file_previews_batch) { create_previews($alternative, false, $extension, false, false, $aref); } echo "SUCCESS"; exit; } if ($replace == "" && $replace_resource == "") { # Standard upload of a new resource $ref = copy_resource(0 - $userref); # Copy from user template # 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);
function ProcessFolder($folder) { #echo "<br>processing folder $folder"; global $syncdir,$nogo,$max,$count,$done,$modtimes,$lastsync, $ffmpeg_preview_extension, $staticsync_autotheme, $staticsync_folder_structure,$staticsync_extension_mapping_default, $staticsync_extension_mapping, $staticsync_mapped_category_tree,$staticsync_title_includes_path, $staticsync_ingest, $staticsync_mapfolders,$staticsync_alternatives_suffix; $collection=0; echo "Processing Folder: $folder\n"; # List all files in this folder. $dh=opendir($folder); while (($file = readdir($dh)) !== false) { $filetype=filetype($folder . "/" . $file); $fullpath=$folder . "/" . $file; $shortpath=str_replace($syncdir . "/","",$fullpath); # Work out extension $extension=explode(".",$file);$extension=trim(strtolower($extension[count($extension)-1])); if ($staticsync_mapped_category_tree) { $path_parts=explode("/",$shortpath); array_pop($path_parts); touch_category_tree_level($path_parts); } # -----FOLDERS------------- if ((($filetype=="dir") || $filetype=="link") && ($file!=".") && ($file!="..") && (strpos($nogo,"[" . $file . "]")===false) && strpos($file,$staticsync_alternatives_suffix)===false) { # Recurse #echo "\n$file : " . filemtime($folder . "/" . $file) . " > " . $lastsync; if (true || (strlen($lastsync)=="") || (filemtime($folder . "/" . $file)>($lastsync-26000))) { ProcessFolder($folder . "/" . $file); } } # -------FILES--------------- if (($filetype=="file") && (substr($file,0,1)!=".") && (strtolower($file)!="thumbs.db")) { # Already exists? if (!in_array($shortpath,$done)) { $count++;if ($count>$max) {return(true);} echo "Processing file: $fullpath\n"; if ($collection==0 && $staticsync_autotheme) { # Make a new collection for this folder. $e=explode("/",$shortpath); $theme=ucwords($e[0]); $themesql="theme='".ucwords(escape_check($e[0]))."'"; $themecolumns="theme"; $themevalues="'".ucwords(escape_check($e[0]))."'"; if ($staticsync_folder_structure){ for ($x=0;$x<count($e)-1;$x++){ if ($x==0){} else {$themeindex=$x+1; global $theme_category_levels; if ($themeindex>$theme_category_levels){ $theme_category_levels=$themeindex; if ($x==count($e)-2){echo "\n\nUPDATE THEME_CATEGORY_LEVELS TO $themeindex IN CONFIG!!!!\n\n";} } $themesql.=" and theme".$themeindex."='".ucwords(escape_check($e[$x]))."'"; $themevalues.=",'".ucwords(escape_check($e[$x]))."'"; $themecolumns.=",theme".$themeindex; } } } $name=(count($e)==1?"":$e[count($e)-2]); echo "\nCollection $name, theme=$theme"; $collection=sql_value("select ref value from collection where name='" . escape_check($name) . "' and " . $themesql ,0); if ($collection==0){ sql_query("insert into collection (name,created,public,$themecolumns,allow_changes) values ('" . escape_check($name) . "',now(),1,".$themevalues.",0)"); $collection=sql_insert_id(); } } # Work out a resource type based on the extension. $type=$staticsync_extension_mapping_default; reset ($staticsync_extension_mapping); foreach ($staticsync_extension_mapping as $rt=>$extensions) { if (in_array($extension,$extensions)) {$type=$rt;} } # Formulate a title if ($staticsync_title_includes_path) { $title=str_ireplace("." . $extension,"",str_replace("/"," - ",$shortpath)); $title=ucfirst(str_replace("_"," ",$title)); } else { $title=str_ireplace("." . $extension,"",$file); } # Import this file $r=import_resource($shortpath,$type,$title,$staticsync_ingest); if ($r!==false) { # Add to mapped category tree (if configured) if (isset($staticsync_mapped_category_tree)) { $basepath=""; # Save tree position to category tree field # For each node level, expand it back to the root so the full path is stored. for ($n=0;$n<count($path_parts);$n++) { if ($basepath!="") {$basepath.="~";} $basepath.=$path_parts[$n]; $path_parts[$n]=$basepath; } update_field ($r,$staticsync_mapped_category_tree,"," . join(",",$path_parts)); #echo "update_field($r,$staticsync_mapped_category_tree," . "," . join(",",$path_parts) . ");\n"; } // default access level. This may be overridden by metadata mapping. $accessval = 0; # StaticSync path / metadata mapping # Extract metadata from the file path as per $staticsync_mapfolders in config.php if (isset($staticsync_mapfolders)) { foreach ($staticsync_mapfolders as $mapfolder) { $match=$mapfolder["match"]; $field=$mapfolder["field"]; $level=$mapfolder["level"]; global $lang; if (strpos("/" . $shortpath,$match)!==false) { # Match. Extract metadata. $path_parts=explode("/",$shortpath); if ($level<count($path_parts)) { // special cases first. if ($field == 'access') { // access level is a special case // first determine if the value matches a defined access level $value = $path_parts[$level-1]; for ($n=0; $n<3; $n++){ // if we get an exact match or a match except for case if ($value == $lang["access" . $n] || strtoupper($value) == strtoupper($lang['access' . $n])){ $accessval = $n; 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'"); } } } } } }
function ProcessFolder($folder, $version_dir, &$resource_array, &$resource_error) { global $lang, $syncdir, $nogo, $staticsync_max_files, $count, $done, $modtimes, $lastsync, $ffmpeg_preview_extension, $staticsync_autotheme, $staticsync_folder_structure, $staticsync_extension_mapping_default, $staticsync_extension_mapping, $staticsync_mapped_category_tree, $staticsync_title_includes_path, $staticsync_ingest, $staticsync_mapfolders, $staticsync_alternatives_suffix, $theme_category_levels, $staticsync_defaultstate, $additional_archive_states, $staticsync_extension_mapping_append_values, $image_alternatives, $exclude_resize, $post_host, $media_endpoint, $image_required_height, $sync_bucket, $aws_key, $aws_secret_key; $collection = 0; echo "Processing Folder: {$folder}" . PHP_EOL; #$alt_path = get_resource_path(59, TRUE, '', FALSE, 'png', -1, 1, FALSE, '', 4); # List all files in this folder. $dh = opendir($folder); while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') { continue; } $filetype = filetype($folder . "/" . $file); $fullpath = $folder . "/" . $file; $shortpath = str_replace($syncdir . "/", '', $fullpath); # Work out extension $extension = explode(".", $file); if (count($extension) > 1) { $extension = trim(strtolower($extension[count($extension) - 1])); } else { //No extension $extension = ""; } if (strpos($fullpath, $nogo)) { echo "This directory is to be ignored." . PHP_EOL; continue; } if ($staticsync_mapped_category_tree) { $path_parts = explode("/", $shortpath); array_pop($path_parts); touch_category_tree_level($path_parts); } # -----FOLDERS------------- if (($filetype == "dir" || $filetype == "link") && strpos($nogo, "[{$file}]") === false && strpos($file, $staticsync_alternatives_suffix) === false) { # Get current version direcotries. if (preg_match("/[0-9]{2}-[0-9]{2}-[0-9]{4}\$/", $file)) { if (!in_array($file, $version_dir)) { array_push($version_dir, $file); } if (preg_match('/in_progress*/', $file)) { echo "The Barcode is still being processed." . PHP_EOL; continue; } } # Recurse ProcessFolder($folder . "/" . $file, $version_dir, $resource_array, $resource_error); } $psd_files = array(); if (preg_match('/images/', $fullpath)) { $path_array = explode('/', $fullpath); $psd_array = array_splice($path_array, 0, array_search('images', $path_array)); $psd_path = implode('/', $psd_array) . '/psd/'; $psd_files = array_diff(scandir($psd_path), array('..', '.')); foreach ($psd_files as $index => $psd_file) { $psd_files[$index] = pathinfo($psd_file, PATHINFO_FILENAME); } } # -------FILES--------------- if ($filetype == "file" && substr($file, 0, 1) != "." && strtolower($file) != "thumbs.db") { /* Below Code Adapted from CMay's bug report */ global $banned_extensions; # Check to see if extension is banned, do not add if it is banned if (array_search($extension, $banned_extensions)) { continue; } /* Above Code Adapted from CMay's bug report */ $count++; if ($count > $staticsync_max_files) { return true; } $last_sync_date = sql_value("select value from sysvars where name = 'last_sync'", ""); $file_creation_date = date("Y-m-d H:i:s", filectime($fullpath)); if (isset($last_sync_date) && $last_sync_date > $file_creation_date) { echo "No new file found.." . PHP_EOL; continue; } # Already exists? if (!isset($done[$shortpath])) { echo "Processing file: {$fullpath}" . PHP_EOL; if ($collection == 0 && $staticsync_autotheme) { # Make a new collection for this folder. $e = explode("/", $shortpath); $theme = ucwords($e[0]); $themesql = "theme='" . ucwords(escape_check($e[0])) . "'"; $themecolumns = "theme"; $themevalues = "'" . ucwords(escape_check($e[0])) . "'"; if ($staticsync_folder_structure) { for ($x = 0; $x < count($e) - 1; $x++) { if ($x != 0) { $themeindex = $x + 1; if ($themeindex > $theme_category_levels) { $theme_category_levels = $themeindex; if ($x == count($e) - 2) { echo PHP_EOL . PHP_EOL . "UPDATE THEME_CATEGORY_LEVELS TO {$themeindex} IN CONFIG!!!!" . PHP_EOL . PHP_EOL; } } $th_name = ucwords(escape_check($e[$x])); $themesql .= " AND theme{$themeindex} = '{$th_name}'"; $themevalues .= ",'{$th_name}'"; $themecolumns .= ",theme{$themeindex}"; } } } $name = count($e) == 1 ? '' : $e[count($e) - 2]; echo "Collection {$name}, theme={$theme}" . PHP_EOL; $ul_username = $theme; $escaped_name = escape_check($name); $collection = sql_value("SELECT ref value FROM collection WHERE name='{$escaped_name}' AND {$themesql}", 0); if ($collection == 0) { sql_query("INSERT INTO collection (name,created,public,{$themecolumns},allow_changes)\n VALUES ('{$escaped_name}', NOW(), 1, {$themevalues}, 0)"); $collection = sql_insert_id(); } } # Work out a resource type based on the extension. $type = $staticsync_extension_mapping_default; reset($staticsync_extension_mapping); foreach ($staticsync_extension_mapping as $rt => $extensions) { if (in_array($extension, $extensions)) { $type = $rt; } } $modified_type = hook('modify_type', 'staticsync', array($type)); if (is_numeric($modified_type)) { $type = $modified_type; } # Formulate a title if ($staticsync_title_includes_path) { $title_find = array('/', '_', ".{$extension}"); $title_repl = array(' - ', ' ', ''); $title = ucfirst(str_ireplace($title_find, $title_repl, $shortpath)); } else { $title = str_ireplace(".{$extension}", '', $file); } $modified_title = hook('modify_title', 'staticsync', array($title)); if ($modified_title !== false) { $title = $modified_title; } # Import this file #$r = import_resource($shortpath, $type, $title, $staticsync_ingest); #Check for file name containing the psd. if (!empty($psd_files)) { $image_file_array = explode('/', $fullpath); $image_file = $image_file_array[count($image_file_array) - 1]; $image_psd_name = explode('_', $image_file)[0]; if (array_search($image_psd_name, $psd_files)) { #Image name is in right format. if (!validate_image_size($fullpath, $image_required_height)) { $resource_error['size'][$file] = $fullpath; } $r = import_resource($fullpath, $type, $title, $staticsync_ingest); sql_query("INSERT INTO resource_data (resource,resource_type_field,value)\n VALUES ('{$r}', (SELECT ref FROM resource_type_field WHERE name = 'logical_id'), '{$image_psd_name}')"); $original_filepath = sql_query("SELECT value FROM resource_data WHERE resource = '{$r}' AND\n resource_type_field = (SELECT ref FROM resource_type_field where name = 'original_filepath')"); if (isset($original_filepath)) { sql_query("INSERT INTO resource_data (resource,resource_type_field,value)\n VALUES ('{$r}',(SELECT ref FROM resource_type_field WHERE name = 'original_filepath'), '{$fullpath}')"); } } else { echo "Filename '{$fullpath}' is not in right format.." . PHP_EOL; $resource_error['name'][$file] = $fullpath; continue; } } elseif (word_in_string($exclude_resize, explode('/', $fullpath))) { $r = import_resource($fullpath, $type, $title, $staticsync_ingest); } if ($r !== false) { array_push($resource_array, $r); # Create current version for resource. #print_r($version_dir); if (count($version_dir) == 1) { sql_query("INSERT into resource_data (resource,resource_type_field,value)\n VALUES ('{$r}',(SELECT ref FROM resource_type_field WHERE name = 'current'), 'TRUE')"); } $sync_status = sync_to_s3($syncdir, $sync_bucket, $aws_key, $aws_secret_key); if (!$sync_status) { echo "Failed to sync"; } # Add to mapped category tree (if configured) if (isset($staticsync_mapped_category_tree)) { $basepath = ''; # Save tree position to category tree field # For each node level, expand it back to the root so the full path is stored. for ($n = 0; $n < count($path_parts); $n++) { if ($basepath != '') { $basepath .= "~"; } $basepath .= $path_parts[$n]; $path_parts[$n] = $basepath; } update_field($r, $staticsync_mapped_category_tree, "," . join(",", $path_parts)); } #This is an override to add user data to the resouces if (!isset($userref)) { $ul_username = ucfirst(strtolower($ul_username)); $current_user_ref = sql_query("Select ref from user where username = '******' "); if (!empty($current_user_ref)) { $current_user_ref = $current_user_ref[0]['ref']; sql_query("UPDATE resource SET created_by='{$current_user_ref}' where ref = {$r}"); } } # default access level. This may be overridden by metadata mapping. $accessval = 0; # StaticSync path / metadata mapping # Extract metadata from the file path as per $staticsync_mapfolders in config.php if (isset($staticsync_mapfolders)) { foreach ($staticsync_mapfolders as $mapfolder) { $match = $mapfolder["match"]; $field = $mapfolder["field"]; $level = $mapfolder["level"]; if (strpos("/" . $shortpath, $match) !== false) { # Match. Extract metadata. $path_parts = explode("/", $shortpath); if ($level < count($path_parts)) { // special cases first. if ($field == 'access') { # access level is a special case # first determine if the value matches a defined access level $value = $path_parts[$level - 1]; for ($n = 0; $n < 3; $n++) { # if we get an exact match or a match except for case if ($value == $lang["access" . $n] || strtoupper($value) == strtoupper($lang['access' . $n])) { $accessval = $n; echo "Will set access level to " . $lang['access' . $n] . " ({$n})" . PHP_EOL; } } } else { if ($field == 'archive') { # archive level is a special case # first determin if the value matches a defined archive level $value = $mapfolder["archive"]; $archive_array = array_merge(array(-2, -1, 0, 1, 2, 3), $additional_archive_states); if (in_array($value, $archive_array)) { $archiveval = $value; echo "Will set archive level to " . $lang['status' . $value] . " ({$archiveval})" . PHP_EOL; } } else { # 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}'"); } } } } } }
# 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. $gscommand2 = $ghostscript_fullpath . " -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=" . escapeshellarg($copy_path) . " -dFirstPage=" . $n . " -dLastPage=" . $n . " " . escapeshellarg($file); $output = run_command($gscommand2); # Update the file extension sql_query("update resource set file_extension='pdf' where ref='{$copy}'"); # Create preview for the page. $pdf_split_pages_to_resources = false; # So we don't get stuck in a loop creating split pages for the single page PDFs. create_previews($copy, false, "pdf"); $pdf_split_pages_to_resources = true; } } // set page number if (isset($pagecount) && $alternative != -1) { sql_query("update resource_alt_files set page_count={$pagecount} where ref={$alternative}"); } else { if (isset($pagecount)) { sql_query("update resource_dimensions set page_count={$pagecount} where resource={$ref}"); } } } else { # Not a PDF file, so single extraction only. create_previews_using_im($ref, false, $extension, $previewonly, false, $alternative); } } # If a file has been created, generate previews just as if a JPG was uploaded. if (isset($newfile)) { create_previews($ref, false, "jpg", $previewonly, false, $alternative); }
run_command($command); $convert_fullpath = get_utility_path("im-convert"); if ($convert_fullpath == false) { exit("Could not find ImageMagick 'convert' utility at location '{$imagemagick_path}'"); } $command = $convert_fullpath . " -resize " . $contact_sheet_preview_size . " -quality 90 -colorspace " . $imagemagick_colorspace . " \"" . get_temp_dir() . "/contactsheetrip.jpg\" \"" . get_temp_dir() . "/contactsheet.jpg\"" . ($config_windows ? "" : " 2>&1"); run_command($command); exit; } #check configs, decide whether PDF outputs to browser or to a new resource. if ($contact_sheet_resource == true) { $newresource = create_resource(1, 0); update_field($newresource, 8, i18n_get_collection_name($collectiondata) . " " . $date); update_field($newresource, $filename_field, $newresource . ".pdf"); #Relate all resources in collection to the new contact sheet resource relate_to_collection($newresource, $collection); #update file extension sql_query("update resource set file_extension='pdf' where ref='{$newresource}'"); # Create the file in the new resource folder: $path = get_resource_path($newresource, true, "", true, "pdf"); $pdf->Output($path, 'F'); #Create thumbnails and redirect browser to the new contact sheet resource create_previews($newresource, true, "pdf"); redirect($baseurl_short . "pages/view.php?ref=" . $newresource); } else { $out1 = ob_get_contents(); if ($out1 != "") { ob_end_clean(); } $pdf->Output(i18n_get_collection_name($collectiondata) . ".pdf", "D"); }
$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) { create_previews($ref, false, "pdf", false, false, $aref); } # Update size. sql_query("update resource_alt_files set file_size='" . filesize_unlimited($copy_path) . "' where ref='{$aref}'"); } else { # Update the file extension sql_query("update resource set file_extension='pdf' where ref='{$copy}'"); # Create preview for the page. create_previews($copy, false, "pdf"); } } redirect("pages/view.php?ref=" . $ref); } include "../../../include/header.php"; ?> <div class="BasicsBox"> <h1><?php echo $lang["splitpdf"]; ?> </h1> <p><?php echo $lang["splitpdf_pleaseselectrange"];
case "rotateclock": tweak_preview_images($ref,270,0,$resource["preview_extension"]); break; case "rotateanti": tweak_preview_images($ref,90,0,$resource["preview_extension"]); break; case "gammaplus": tweak_preview_images($ref,0,1.3,$resource["preview_extension"]); break; case "gammaminus": tweak_preview_images($ref,0,0.7,$resource["preview_extension"]); break; case "restore": if ($enable_thumbnail_creation_on_upload) { create_previews($ref,false,$resource["file_extension"]); refresh_collection_frame(); } else { sql_query("update resource set preview_attempts=0, has_image=0 where ref='$ref'"); } break; } hook("moretweakingaction", "", array($tweak, $ref, $resource)); # Reload resource data. $resource=get_resource_data($ref,false); }
include dirname(__FILE__) . "/../../../include/db.php"; include dirname(__FILE__) . "/../../../include/general.php"; include dirname(__FILE__) . "/../../../include/resource_functions.php"; include dirname(__FILE__) . "/../../../include/image_processing.php"; include_once(dirname(__FILE__) . "/../../elastic_search/include/elastic_functions.php"); if(!isset($argv)){ echo("ERROR: No Arguments where passed with elastic search cron job \n"); }else{ ini_set('max_execution_time', 1200); $resourcetype = $argv[1]; $ref = trim($argv[2]); $extension = $argv[3]; $attempts = $argv[4]; if($resourcetype == 3 || $resourcetype == 4){ $cp = create_previews($ref,$thumbonly=true,$extension); if($cp == true && $resourcetype == 3){ $thumb_path = get_resource_path($ref,true,"thm",false,"jpg"); $im_fullpath = get_utility_path("im-composite"); $command = $im_fullpath . " -gravity center /var/www/gfx/video-overlay.png " . escapeshellarg($thumb_path) . " : " . escapeshellarg($thumb_path) . " 2>&1"; $report_original = run_command($command); } }else{ //create preview files in that directory $cp = create_previews_using_im($ref,false,$extension); } if ($cp == true){ sql_query("UPDATE resource SET is_transcoding = 0 WHERE ref = $ref"); //send result to elast search now that we have preview $results=array();