function HookAnnotateAllAfterreindexresource($ref) { // make sure annotation indexing isn't lost when doing a reindex. $notes = sql_query("select * from annotate_notes where ref='{$ref}'"); global $pagename; foreach ($notes as $note) { #Add annotation to keywords $keywordtext = substr(strstr($note['note'], ": "), 2); # don't add the username to the keywords add_keyword_mappings($ref, i18n_get_indexable($keywordtext), -1, false, false, "annotation_ref", $note['note_id']); } }
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}'"); } } } } } }
} set_time_limit(60 * 60 * 5); echo "<pre>"; $resources = sql_query("select r.ref,u.username,u.fullname from \ncollection_resource left join resource r on collection_resource.resource = r.ref \nleft outer join user u on r.created_by=u.ref where collection_resource.collection = '{$collection}' order by ref"); for ($n = 0; $n < count($resources); $n++) { $ref = $resources[$n]["ref"]; # Delete existing keywords sql_query("delete from resource_keyword where resource='{$ref}'"); # Index fields $data = get_resource_field_data($ref); for ($m = 0; $m < count($data); $m++) { if ($data[$m]["keywords_index"] == 1) { #echo $data[$m]["value"]; $value = $data[$m]["value"]; if ($data[$m]["type"] == 3 || $data[$m]["type"] == 2) { # Prepend a comma when indexing dropdowns $value = "," . $value; } # Date field? These need indexing differently. $is_date = $data[$m]["type"] == 4 || $data[$m]["type"] == 6; add_keyword_mappings($ref, i18n_get_indexable($value), $data[$m]["ref"], $data[$m]["partial_index"], $is_date); } } # Also index contributed by field. add_keyword_mappings($ref, $resources[$n]["username"] . " " . $resources[$n]["fullname"], -1); # Always index the resource ID as a keyword remove_keyword_mappings($ref, $ref, -1); add_keyword_mappings($ref, $ref, -1); $words = sql_value("select count(*) value from resource_keyword where resource='{$ref}'", 0); echo "Done {$ref} ({$n}/" . count($resources) . ") - {$words} words<br />\n"; }
function reindex_resource($ref) { global $index_contributed_by; # Reindex a resource. Delete all resource_keyword rows and create new ones. # Delete existing keywords sql_query("delete from resource_keyword where resource='$ref'"); # Index fields $data=get_resource_field_data($ref,false,false); # Fetch all fields and do not use permissions. for ($m=0;$m<count($data);$m++) { if ($data[$m]["keywords_index"]==1) { #echo $data[$m]["value"]; $value=$data[$m]["value"]; if ($data[$m]["type"]==3 || $data[$m]["type"]==2) { # Prepend a comma when indexing dropdowns $value="," . $value; } # Date field? These need indexing differently. $is_date=($data[$m]["type"]==4 || $data[$m]["type"]==6); add_keyword_mappings($ref,i18n_get_indexable($value),$data[$m]["ref"],$data[$m]["partial_index"],$is_date); } } # Also index contributed by field, unless disabled if ($index_contributed_by) { $resource=get_resource_data($ref); $userinfo=get_user($resource["created_by"]); add_keyword_mappings($ref,$userinfo["username"] . " " . $userinfo["fullname"],-1); } # Always index the resource ID as a keyword remove_keyword_mappings($ref, $ref, -1); add_keyword_mappings($ref, $ref, -1); hook("afterreindexresource","all",array($ref)); }
function updateResourcesFromContacts($resourcestoupdate,$rs_fields,$resref, $oldvals,$oldvalmatch){ $resourceupdates = array(); $resources=array(); $rf=array(); $rv=array(); $toindex=array();//empty array vars //filter for only resources where this name matches the resource_field_type $filteredray = array(); for ($ru=0; $ru<count($resourcestoupdate); $ru++){ if($resourcestoupdate[$ru]['resource_type_field']==$resref){ $filteredray[] = $resourcestoupdate[$ru]; }; }; //loop through the filtered resources for($r=0; $r<count($filteredray); $r++){ //for all of the resources and foreach mapped resource field foreach($rs_fields as $k => $v){ if($v !=""){ // Check to see if resource data exists for that field and resource $exists = sql_query("SELECT * FROM resource_data WHERE resource ='".$filteredray[$r]['resource']."' AND resource_type_field='".$k."'"); //if it doesn't exist and the value has changed if(empty($exists) && !in_array($v,$oldvals[0])){ //push the data that needs to be INSERTED $resourceupdates[]="(".$filteredray[$r]['resource'].",".$k.",'".$v."')"; $oldkey = matcholdkey($k,$oldvalmatch); $toindex[]=$k.",'".$v."',".$filteredray[$r]['resource'].",'".$oldvals[0][$oldkey]."'"; // else if the value does exist and the value has changed }else if(!in_array($v,$oldvals[0])){ //push the data that needs to be UPDATED $resources[]=$filteredray[$r]['resource']; $rf[]=$k; $rv[]=$v; $oldkey=matcholdkey($k,$oldvalmatch); $toindex[]=$k.",'".$v."',".$filteredray[$r]['resource'].",'".$oldvals[0][$oldkey]."'"; }; }; }; };//end filtered loop $updateq = ""; //if there is data to INSERT build the statement if(!empty($resourceupdates)){ sql_query("INSERT INTO resource_data (resource, resource_type_field, value) VALUES ". join(",",$resourceupdates)); } //if there is data to UPDATE build the statement if(!empty($resources)){ $updateq = "UPDATE resource_data SET value = CASE resource_type_field"; foreach($rs_fields as $k => $v){ if($v !=""){ $updateq .= " WHEN $k THEN '$v' \n"; } }; $updateq .= "ELSE value END "; $updateq .= "WHERE resource IN (" . join(",",$resources).")"; sql_query($updateq);//update } //add remove and index keywords for($ti = 0; $ti<count($toindex);$ti++){ $toind = explode(",", $toindex[$ti]); remove_keyword_mappings($toind[2],$toind[3],$toind[0]); add_keyword_mappings($toind[2],$toind[1],$toind[0]); } $results=array(); for($fr=0; $fr<count($filteredray); $fr++){ $ref=$filteredray[$fr]['resource']; $results[]=get_resource_data($ref); } //elastic search $results=mia_results($results); $resource_types=get_resource_types(); $results=mia_elastic_encode($resource_types,$results,false); for($e=0; $e<count($results); $e++){ $resourcetype=get_resource_type_name($results[$e]['resource_type']); $ref=$results[$e]['ref']; push_RStoElastic($resourcetype,$ref,json_encode($results[$e])); } };//end function
function upload_file($ref, $no_exif = false, $revert = false, $autorotate = false) { hook("beforeuploadfile", "", array($ref)); hook("clearaltfiles", "", array($ref)); // optional: clear alternative files before uploading new resource # revert is mainly for metadata reversion, removing all metadata and simulating a reupload of the file from scratch. hook("removeannotations", "", array($ref)); $exiftool_fullpath = get_utility_path("exiftool"); # Process file upload for resource $ref if ($revert == true) { global $filename_field; $original_filename = get_data_by_field($ref, $filename_field); # Field 8 is used in a special way for staticsync, don't overwrite. $test_for_staticsync = get_resource_data($ref); if ($test_for_staticsync['file_path'] != "") { $staticsync_mod = " and resource_type_field != 8"; } else { $staticsync_mod = ""; } sql_query("delete from resource_data where resource={$ref} {$staticsync_mod}"); sql_query("delete from resource_keyword where resource={$ref} {$staticsync_mod}"); #clear 'joined' display fields which are based on metadata that is being deleted in a revert (original filename is reinserted later) $display_fields = get_resource_table_joins(); if ($staticsync_mod != "") { $display_fields_new = array(); for ($n = 0; $n < count($display_fields); $n++) { if ($display_fields[$n] != 8) { $display_fields_new[] = $display_fields[$n]; } } $display_fields = $display_fields_new; } $clear_fields = ""; for ($x = 0; $x < count($display_fields); $x++) { $clear_fields .= "field" . $display_fields[$x] . "=''"; if ($x < count($display_fields) - 1) { $clear_fields .= ","; } } sql_query("update resource set " . $clear_fields . " where ref={$ref}"); #also add the ref back into keywords: add_keyword_mappings($ref, $ref, -1); $extension = sql_value("select file_extension value from resource where ref={$ref}", ""); $filename = get_resource_path($ref, true, "", false, $extension); $processfile['tmp_name'] = $filename; } else { # Work out which file has been posted if (isset($_FILES['userfile'])) { $processfile = $_FILES['userfile']; } elseif (isset($_FILES['Filedata'])) { $processfile = $_FILES['Filedata']; } # Java upload (at least) needs this # Plupload needs this if (isset($_REQUEST['name'])) { $filename = $_REQUEST['name']; } else { $filename = $processfile['name']; } global $filename_field; if ($no_exif && isset($filename_field)) { $user_set_filename = get_data_by_field($ref, $filename_field); if (trim($user_set_filename) != '') { // Get extension of file just in case the user didn't provide one $path_parts = pathinfo($filename); $original_extension = $path_parts['extension']; $filename = $user_set_filename; // If the user filename doesn't have an extension add the original one $path_parts = pathinfo($filename); if (!isset($path_parts['extension'])) { $filename .= '.' . $original_extension; } } } } # Work out extension if (!isset($extension)) { # first try to get it from the filename $extension = explode(".", $filename); if (count($extension) > 1) { $extension = escape_check(trim(strtolower($extension[count($extension) - 1]))); } else { if ($exiftool_fullpath != false) { $file_type_by_exiftool = run_command($exiftool_fullpath . " -filetype -s -s -s " . escapeshellarg($processfile['tmp_name'])); if (strlen($file_type_by_exiftool) > 0) { $extension = str_replace(" ", "_", trim(strtolower($file_type_by_exiftool))); $filename = $filename; } else { return false; } } else { return false; } } } # Banned extension? global $banned_extensions; if (in_array($extension, $banned_extensions)) { return false; } $status = "Please provide a file name."; $filepath = get_resource_path($ref, true, "", true, $extension); if (!$revert) { # Remove existing file, if present hook("beforeremoveexistingfile", "", array("resourceId" => $ref)); $old_extension = sql_value("select file_extension value from resource where ref='{$ref}'", ""); if ($old_extension != "") { $old_path = get_resource_path($ref, true, "", true, $old_extension); if (file_exists($old_path)) { unlink($old_path); } } // also remove any existing extracted icc profiles $icc_path = get_resource_path($ref, true, "", true, $extension . '.icc'); if (file_exists($icc_path)) { unlink($icc_path); } global $pdf_pages; $iccx = 0; // if there is a -0.icc page, run through and delete as many as necessary. $finished = false; $badicc_path = str_replace(".icc", "-{$iccx}.icc", $icc_path); while (!$finished) { if (file_exists($badicc_path)) { unlink($badicc_path); $iccx++; $badicc_path = str_replace(".icc", "-{$iccx}.icc", $icc_path); } else { $finished = true; } } $iccx = 0; } if (!$revert) { if ($filename != "") { global $jupload_alternative_upload_location, $plupload_upload_location; if (isset($plupload_upload_location)) { # PLUpload - file was sent chunked and reassembled - use the reassembled file location $result = rename($plupload_upload_location, $filepath); } elseif (isset($jupload_alternative_upload_location)) { # JUpload - file was sent chunked and reassembled - use the reassembled file location $result = rename($jupload_alternative_upload_location, $filepath); } else { # Standard upload. if (!$revert) { $result = move_uploaded_file($processfile['tmp_name'], $filepath); } else { $result = true; } } if ($result == false) { $status = "File upload error. Please check the size of the file you are trying to upload."; return false; } else { global $camera_autorotation; global $ffmpeg_audio_extensions; if ($camera_autorotation) { if ($autorotate && !in_array($extension, $ffmpeg_audio_extensions)) { AutoRotateImage($filepath); } } chmod($filepath, 0777); global $icc_extraction; global $ffmpeg_supported_extensions; if ($icc_extraction && $extension != "pdf" && !in_array($extension, $ffmpeg_supported_extensions)) { extract_icc_profile($ref, $extension); } $status = "Your file has been uploaded."; } } } # Store extension in the database and update file modified time. if ($revert) { $has_image = ""; } else { $has_image = ",has_image=0"; } sql_query("update resource set file_extension='{$extension}',preview_extension='jpg',file_modified=now() {$has_image} where ref='{$ref}'"); # delete existing resource_dimensions sql_query("delete from resource_dimensions where resource='{$ref}'"); # get file metadata if (!$no_exif) { extract_exif_comment($ref, $extension); } else { global $merge_filename_with_title, $lang; if ($merge_filename_with_title) { $merge_filename_with_title_option = urlencode(getval('merge_filename_with_title_option', '')); $merge_filename_with_title_include_extensions = urlencode(getval('merge_filename_with_title_include_extensions', '')); $merge_filename_with_title_spacer = urlencode(getval('merge_filename_with_title_spacer', '')); $original_filename = ''; if (isset($_REQUEST['name'])) { $original_filename = $_REQUEST['name']; } else { $original_filename = $processfile['name']; } if ($merge_filename_with_title_include_extensions == 'yes') { $merged_filename = $original_filename; } else { $merged_filename = strip_extension($original_filename); } // Get title field: $resource = get_resource_data($ref); $read_from = get_exiftool_fields($resource['resource_type']); for ($i = 0; $i < count($read_from); $i++) { if ($read_from[$i]['name'] == 'title') { $oldval = get_data_by_field($ref, $read_from[$i]['ref']); if (strpos($oldval, $merged_filename) !== FALSE) { continue; } switch ($merge_filename_with_title_option) { case $lang['merge_filename_title_do_not_use']: // Do nothing since the user doesn't want to use this feature break; case $lang['merge_filename_title_replace']: $newval = $merged_filename; break; case $lang['merge_filename_title_prefix']: $newval = $merged_filename . $merge_filename_with_title_spacer . $oldval; if ($oldval == '') { $newval = $merged_filename; } break; case $lang['merge_filename_title_suffix']: $newval = $oldval . $merge_filename_with_title_spacer . $merged_filename; if ($oldval == '') { $newval = $merged_filename; } break; default: // Do nothing break; } update_field($ref, $read_from[$i]['ref'], $newval); } } } } # extract text from documents (e.g. PDF, DOC). global $extracted_text_field; if (isset($extracted_text_field) && !$no_exif) { if (isset($unoconv_path) && in_array($extension, $unoconv_extensions)) { // omit, since the unoconv process will do it during preview creation below } else { extract_text($ref, $extension); } } # Store original filename in field, if set global $filename_field, $amended_filename; if (isset($filename_field)) { if (isset($amended_filename)) { $filename = $amended_filename; } } if (!$revert) { update_field($ref, $filename_field, $filename); } else { update_field($ref, $filename_field, $original_filename); } if (!$revert) { # Clear any existing FLV file or multi-page previews. global $pdf_pages; for ($n = 2; $n <= $pdf_pages; $n++) { # Remove preview page. $path = get_resource_path($ref, true, "scr", false, "jpg", -1, $n, false); if (file_exists($path)) { unlink($path); } # Also try the watermarked version. $path = get_resource_path($ref, true, "scr", false, "jpg", -1, $n, true); if (file_exists($path)) { unlink($path); } } # Remove any FLV video preview (except if the actual resource is an FLV file). global $ffmpeg_preview_extension; if ($extension != $ffmpeg_preview_extension) { $path = get_resource_path($ref, true, "", false, $ffmpeg_preview_extension); if (file_exists($path)) { unlink($path); } } # Remove any FLV preview-only file $path = get_resource_path($ref, true, "pre", false, $ffmpeg_preview_extension); if (file_exists($path)) { unlink($path); } # Remove any MP3 (except if the actual resource is an MP3 file). if ($extension != "mp3") { $path = get_resource_path($ref, true, "", false, "mp3"); if (file_exists($path)) { unlink($path); } } # Create previews global $enable_thumbnail_creation_on_upload; if ($enable_thumbnail_creation_on_upload) { create_previews($ref, false, $extension); } else { # Offline thumbnail generation is being used. Set 'has_image' to zero so the offline create_previews.php script picks this up. sql_query("update resource set has_image=0 where ref='{$ref}'"); } } # Update file dimensions get_original_imagesize($ref, $filepath, $extension); hook("Uploadfilesuccess", "", array("resourceId" => $ref)); # Update disk usage update_disk_usage($ref); # Log this activity. $log_ref = resource_log($ref, "u", 0); hook("upload_image_after_log_write", "", array($ref, $log_ref)); return $status; }
die("no"); } $top = getvalescaped('top', ''); $left = getvalescaped('left', ''); $width = getvalescaped('width', ''); $height = getvalescaped('height', ''); $text = getvalescaped('text', ''); $text = str_replace("<br />\n", " ", $text); // remove the breaks added by get.php $id = getvalescaped('id', ''); $preview_width = getvalescaped('pw', ''); $preview_height = getvalescaped('ph', ''); $oldtext = sql_value("select note value from annotate_notes where ref='{$ref}' and note_id='{$id}'", ""); if ($oldtext != "") { remove_keyword_mappings($ref, i18n_get_indexable($oldtext), -1, false, false, "annotation_ref", $id); } sql_query("delete from annotate_notes where ref='{$ref}' and note_id='{$id}'"); if (substr($text, 0, strlen($username)) != $username) { $text = $username . ": " . $text; } sql_query("insert into annotate_notes (ref,top_pos,left_pos,width,height,preview_width,preview_height,note,user) values ('{$ref}','{$top}','{$left}','{$width}','{$height}','{$preview_width}','{$preview_height}','{$text}','{$userref}') "); $annotateid = sql_insert_id(); echo $annotateid; $notes = sql_query("select * from annotate_notes where ref='{$ref}'"); sql_query("update resource set annotation_count=" . count($notes) . " where ref={$ref}"); #Add annotation to keywords $keywordtext = substr(strstr($text, ": "), 2); # don't add the username to the keywords debug("adding annotation to resource keywords. Keywords: " . $keywordtext); add_keyword_mappings($ref, i18n_get_indexable($keywordtext), -1, false, false, "annotation_ref", $annotateid); #add_keyword_mappings($ref,$text,-1);
$data = sql_query("select * from resource_data {$joindata} where resource_type_field='{$field}' and length(value)>0 {$conditionand} and value is not null"); $n = 0; $total = count($data); foreach ($data as $row) { $n++; $ref = $row["resource"]; $value = $row["value"]; if ($fieldinfo["type"] == 3 || $fieldinfo["type"] == 2 || $fieldinfo["type"] == 9) { # Prepend a comma when indexing dropdowns to ensure full value is also indexed $value = "," . $value; } # Date field? These need indexing differently. $is_date = $fieldinfo["type"] == 4 || $fieldinfo["type"] == 6; $is_html = $fieldinfo["type"] == 8; # function add_keyword_mappings($ref,$string,$resource_type_field,$partial_index=false,$is_date=false) add_keyword_mappings($ref, i18n_get_indexable($value), $field, $fieldinfo["partial_index"], $is_date, '', '', $is_html); echo "Done {$ref} - " . htmlspecialchars(substr($value, 0, 50)) . "... ({$n}/{$total})\n"; if ($n / 20 == floor($n / 20) || $n == $total) { ?> <script>window.scroll(0,document.height);</script><?php } flush(); } echo "Reindex complete\n\n\n"; } else { $extratext = ""; if ($collectionid != "") { $collectionname = sql_value("select name as value from collection where ref='{$collectionid}'", ''); $extratext = " for collection '" . $collectionname . "'"; } ?>