function savetoelastic($ref){ global $baseurl, $pagename; if($pagename != "upload2"){ //error_log($ref); $results=array(); $results[] = get_resource_data($ref,false); $resourcetype=get_resource_type_name($results[0]['resource_type']); if($resourcetype != "Audio"){ $thethumb = $baseurl.str_replace("/var/www/include/..","",get_resource_path($ref,true,"thm",false,"jpg")); if(!file_exists($thethumb)){ $thethumb = $results[0]["thumbnail"] = $baseurl."/gfx/no_preview/extension/".$results[0]['file_extension'].".png"; } $results[0]["thumbnail"]=$thethumb; }else{ $results[0]["thumbnail"] = $baseurl."/gfx/no_preview/extension/".$results[0]['file_extension'].".png"; } if($resourcetype == "Audio"){ $results[0]["preview"]=$baseurl.str_replace("/var/www/include/..","",get_resource_path($ref, true, "", false, "mp3")); }else if($resourcetype == "Video"){ $results[0]["preview"]=$baseurl.str_replace("/var/www/include/..","",get_resource_path($ref, true, "pre", false, "mp4")); } $results = mia_results($results); $results=json_encode($results[0]); $query = push_RStoElastic($resourcetype,$ref,$results); if($query == false){ //failed to connect to elastic search createcron($attempts=1, $ref); }else{ // var_dump($query);exit(); } return; } }
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; } }
function HookResourceofthedayHomeReplaceslideshow() { include_once dirname(__FILE__) . "/../inc/rotd_functions.php"; $rotd = get_resource_of_the_day(); if ($rotd === false) { return false; } # No ROTD, return false to disable hook and display standard slide show. # Fetch resource data $resource = get_resource_data($rotd); # Fetch title $title = sql_value("select value from resource_data where resource='{$rotd}' and resource_type_field=8", ""); # Fetch caption $caption = sql_value("select value from resource_data where resource='{$rotd}' and resource_type_field=18", ""); # Show resource! $pre = get_resource_path($rotd, false, "pre", false, "jpg"); ?> <div class="HomePicturePanel RecordPanel" style="width:350px;padding-left:4px;"> <a href="view.php?ref=<?php echo $rotd; ?> "><img class="ImageBorder" style="margin-bottom: 10px;" src="<?php echo $pre; ?> " /></a> <br /> <h2 ><?php echo i18n_get_translated(htmlspecialchars($title)); ?> </h2> <?php echo $caption; ?> </div> <?php return true; }
function save_proposed_changes($ref) { global $userref, $auto_order_checkbox, $multilingual_text_fields, $languages, $language; # Loop through the field data and save (if necessary) $errors = array(); $fields = get_resource_field_data($ref, false); $resource_data = get_resource_data($ref); for ($n = 0; $n < count($fields); $n++) { if ($fields[$n]["type"] == 2) { # construct the value from the ticked boxes $val = ","; # Note: it seems wrong to start with a comma, but this ensures it is treated as a comma separated list by split_keywords(), so if just one item is selected it still does individual word adding, so 'South Asia' is split to 'South Asia','South','Asia'. $options = trim_array(explode(",", $fields[$n]["options"])); for ($m = 0; $m < count($options); $m++) { $name = $fields[$n]["ref"] . "_" . md5($options[$m]); if (getval($name, "") == "yes") { if ($val != ",") { $val .= ","; } $val .= $options[$m]; } } } elseif ($fields[$n]["type"] == 4 || $fields[$n]["type"] == 6 || $fields[$n]["type"] == 10) { # date type, construct the value from the date/time dropdowns $val = sprintf("%04d", getvalescaped("field_" . $fields[$n]["ref"] . "-y", "")); if ((int) $val <= 0) { $val = ""; } elseif (($field = getvalescaped("field_" . $fields[$n]["ref"] . "-m", "")) != "") { $val .= "-" . $field; if (($field = getvalescaped("field_" . $fields[$n]["ref"] . "-d", "")) != "") { $val .= "-" . $field; if (($field = getval("field_" . $fields[$n]["ref"] . "-h", "")) != "") { $val .= " " . $field . ":"; if (($field = getvalescaped("field_" . $fields[$n]["ref"] . "-i", "")) != "") { $val .= $field; } else { $val .= "00"; } } } } } elseif ($multilingual_text_fields && ($fields[$n]["type"] == 0 || $fields[$n]["type"] == 1 || $fields[$n]["type"] == 5)) { # Construct a multilingual string from the submitted translations $val = getvalescaped("field_" . $fields[$n]["ref"], ""); $val = "~" . $language . ":" . $val; reset($languages); foreach ($languages as $langkey => $langname) { if ($language != $langkey) { $val .= "~" . $langkey . ":" . getvalescaped("multilingual_" . $n . "_" . $langkey, ""); } } } elseif ($fields[$n]["type"] == 3) { $val = getvalescaped("field_" . $fields[$n]["ref"], ""); // if it doesn't already start with a comma, add one if (substr($val, 0, 1) != ',') { $val = ',' . $val; } } else { # Set the value exactly as sent. $val = getvalescaped("field_" . $fields[$n]["ref"], ""); } # Check for regular expression match if (trim(strlen($fields[$n]["regexp_filter"])) >= 1 && strlen($val) > 0) { if (preg_match("#^" . $fields[$n]["regexp_filter"] . "\$#", $val, $matches) <= 0) { global $lang; debug($lang["information-regexp_fail"] . ": -" . "reg exp: " . $fields[$n]["regexp_filter"] . ". Value passed: " . $val); if (getval("autosave", "") != "") { exit; } $errors[$fields[$n]["ref"]] = $lang["information-regexp_fail"] . " : " . $val; continue; } } $error = hook("additionalvalcheck", "all", array($fields, $fields[$n])); if ($error) { global $lang; $errors[$fields[$n]["ref"]] = $error; continue; } if (str_replace("\r\n", "\n", $fields[$n]["value"]) !== str_replace("\r\n", "\n", unescape($val))) { # This value is different from the value we have on record. # Add this to the proposed changes table for the user sql_query("insert into propose_changes_data(resource,user,resource_type_field,value) values('{$ref}','{$userref}','" . $fields[$n]["ref"] . "','" . escape_check($val) . "')"); } } return true; }
if($exists){ $query = sql_query("UPDATE resource_data SET value = '$val' WHERE resource = $ref AND resource_type_field = $key"); if($query === false){ $qerr[]="UPDATE resource_data SET value = '$val' WHERE resource = $ref AND resource_type_field = $key"; } }else{ $query = sql_query("INSERT INTO resource_data VALUES ($ref,$key,'$val')"); if($query === false){ $qerr[]="INSERT INTO resource_data VALUES ($ref,$key,'$val')"; } } } } if(empty($qerr)){ $results=array(); $results[] = get_resource_data($ref,false); $thumb_path = array("thumbnail"=>$baseurl.str_replace("/var/www/include/..","",get_resource_path($ref,true,"thm",false,"jpg"))); $newresults[] = array_merge($thumb_path,$results[0]); $results = $newresults; $results = mia_results($results); $resourcetype=get_resource_type_name($results[0]['resource_type']); $results=json_encode($results[0]); $query = push_RStoElastic($resourcetype,$ref,$results); if($query == false){ //failed to connect to elastic search createcron($attempts=1,$ref); echo("Resolved TMS but failed to connect to Elastic Search. A Cron Job for Elastic Search has been instantiated and will try to resolve the issue" . date('d-m-Y h:i:s')."n"); }else{ echo("Art Object data was successfully resolved from TMS and added to Elastic Search ".date('d-m-Y h:i:s')."\n"); } }else{
function HookAnnotatePreviewPreviewimage2() { global $ajax, $ext, $baseurl, $ref, $k, $search, $offset, $order_by, $sort, $archive, $lang, $download_multisize, $baseurl, $url, $path, $path_orig, $annotate_ext_exclude, $annotate_rt_exclude, $annotate_public_view, $annotate_pdf_output; if (getval("alternative", "") != "") { return false; } $resource = get_resource_data($ref); if (in_array($resource['file_extension'], $annotate_ext_exclude)) { return false; } if (in_array($resource['resource_type'], $annotate_rt_exclude)) { return false; } if (!($k == "") && !$annotate_public_view) { return false; } if (!file_exists($path) && !file_exists($path_orig)) { return false; } if (!file_exists($path)) { $sizes = getimagesize($path_orig); } else { $sizes = getimagesize($path); } $w = $sizes[0]; $h = $sizes[1]; ?> <script type="text/javascript"> button_ok = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["ok"])); ?> "; button_cancel = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["cancel"])); ?> "; button_delete = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["action-delete"])); ?> "; button_add = "> <?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["action-add_note"])); ?> "; button_toggle = "> <?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["action-toggle-on"])); ?> "; button_toggle_off = "> <?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["action-toggle-off"])); ?> "; error_saving = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["error-saving"])); ?> "; error_deleting = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["error-deleting"])); ?> "; </script> <script> jQuery.noConflict(); </script> <div id="wrapper" style="display:block;clear:none;float:left;margin: 0px;"> <div> <img id="toAnnotate" onload="annotate(<?php echo $ref; ?> ,'<?php echo $k; ?> ','<?php echo $w; ?> ','<?php echo $h; ?> ',<?php echo getvalescaped("annotate_toggle", true); ?> );" src="<?php echo $url; ?> " id="previewimage" class="Picture" GALLERYIMG="no" style="display:block;" /> </div> <div style="padding-top:5px;"> <?php // MAGICTOUCH PLUGIN COMPATIBILITY global $magictouch_account_id; if ($magictouch_account_id != "") { global $plugins; global $magictouch_rt_exclude; global $magictouch_ext_exclude; if (in_array("magictouch", $plugins) && !in_array($resource['resource_type'], $magictouch_rt_exclude) && !in_array($resource['file_extension'], $magictouch_ext_exclude) && !defined("MTFAIL")) { ?> <a style="display:inline;float:right;" href="<?php echo getval("from", "") == "search" ? "search.php?" : "preview.php?ref=" . $ref . "&"; ?> search=<?php echo urlencode($search); ?> &offset=<?php echo $offset; ?> &order_by=<?php echo $order_by; ?> &sort=<?php echo $sort; ?> &archive=<?php echo $archive; ?> &k=<?php echo $k; ?> " onClick="document.cookie='annotate=off;';return CentralSpaceLoad(this);">> <?php echo $lang['zoom']; ?> </a><?php } } /////////////// ?> <?php if ($annotate_pdf_output) { ?> <a style="display:inline;float:right;margin-right:10px;" href="<?php echo $baseurl; ?> /plugins/annotate/pages/annotate_pdf_config.php?ref=<?php echo $ref; ?> &ext=<?php echo $resource["preview_extension"]; ?> &k=<?php echo $k; ?> &search=<?php echo urlencode($search); ?> &offset=<?php echo $offset; ?> &order_by=<?php echo $order_by; ?> &sort=<?php echo $sort; ?> &archive=<?php echo $archive; ?> " >> <?php echo $lang["pdfwithnotes"]; ?> </a> <?php } ?> </div></div> <?php return true; }
exit("Permission denied"); } set_time_limit(0); if (!$exiftool_resolution_calc) { die("Please turn on the exiftool resolution calculator in your config.php file."); } else { $exiftool_fullpath = get_utility_path("exiftool"); if ($exiftool_fullpath == false) { die("Could not find exiftool. Aborting..."); } else { # get all resources in the DB $resources = sql_query("select ref,field" . $view_title_field . ",file_extension from resource where ref>0 order by ref"); foreach ($resources as $resource) { $resource_path = get_resource_path($resource['ref'], true, "", false, $resource['file_extension']); if (file_exists($resource_path) && !in_array($resource['file_extension'], $exiftool_no_process)) { $resource = get_resource_data($resource['ref']); $command = $exiftool_fullpath . " -s -s -s -t -composite:imagesize -xresolution -resolutionunit " . escapeshellarg($resource_path); $dimensions_resolution_unit = explode("\t", run_command($command)); # if anything was extracted, update the database. if (count($dimensions_resolution_unit) >= 1 && $dimensions_resolution_unit[0] != '') { # check db for existing record $delete = sql_query("delete from resource_dimensions where resource=" . $resource['ref']); # break down the width and height $wh = explode("x", $dimensions_resolution_unit[0]); if (count($wh) > 1) { $width = $wh[0]; $height = $wh[1]; $filesize = filesize_unlimited($resource_path); $sql_insert = "insert into resource_dimensions (resource,width,height,file_size"; $sql_values = " values('" . $resource['ref'] . "','{$width}','{$height}','{$filesize}'"; if (count($dimensions_resolution_unit) >= 2) {
} # additional access check, as the resource download may be allowed, but access restriction should force watermark. $access = get_resource_access($ref); $use_watermark = check_use_watermark($ref); # If no extension was provided, we fallback to JPG. if ($ext == "") { $ext = "jpg"; } $noattach = getval("noattach", ""); $path = get_resource_path($ref, true, $size, false, $ext, -1, $page, $use_watermark && $alternative == -1, "", $alternative); if (!file_exists($path)) { $path = get_resource_path($ref, true, "", false, $ext, -1, $page, false, "", $alternative); } if (!file_exists($path) && $noattach != "") { # Return icon for file (for previews) $info = get_resource_data($ref); $path = "../gfx/" . get_nopreview_icon($info["resource_type"], $ext, "thm"); } # writing RS metadata to files: exiftool if ($noattach == "" && $alternative == -1) { $tmpfile = write_metadata($path, $ref); if ($tmpfile !== false && file_exists($tmpfile)) { $path = $tmpfile; } } hook('modifydownloadfile'); $filesize = filesize_unlimited($path); header("Content-Length: " . $filesize); # Log this activity (download only, not preview) if ($noattach == "") { daily_stat("Resource download", $ref);
<label for="users"><?php echo $lang["emailtousers"]?></label><?php include "../include/user_select.php"; ?> <div class="clearerleft"> </div> <?php if ($errors!="") { ?><div class="FormError">!! <?php echo $errors?> !!</div><?php } ?> </div> <?php } ?> <?php if ($list_recipients){?> <div class="Question"> <label for="list_recipients"><?php echo $lang["list-recipients-label"]; ?></label><input type=checkbox id="list_recipients" name="list_recipients"> <div class="clearerleft"> </div> </div> <?php } ?> <?php if($useraccess==0) { $resourcedata=get_resource_data($ref,true); if(get_edit_access($ref,$resource['archive'],false,$resource)) {?> <div class="Question"> <label for="grant_internal_access"><?php echo $lang["internal_share_grant_access"] ?></label> <input type=checkbox id="grant_internal_access" name="grant_internal_access" onClick="if(this.checked){jQuery('#question_internal_access').slideDown();}else{jQuery('#question_internal_access').slideUp()};"> <div class="clearerleft"> </div> </div> <?php } }?> <?php if(!hook("replaceemailaccessselector")){?> <div class="Question" id="question_access"> <label for="access"><?php echo $lang["externalselectresourceaccess"]?></label>
function HookAnnotatePreviewPreviewimage2() { global $ext, $baseurl, $ref, $k, $search, $offset, $order_by, $sort, $archive, $lang, $download_multisize, $baseurl, $url, $path, $path_orig, $annotate_ext_exclude, $annotate_rt_exclude, $annotate_public_view, $annotate_pdf_output; if (getval("alternative", "") != "") { return false; } $resource = get_resource_data($ref); if (in_array($resource['file_extension'], $annotate_ext_exclude)) { return false; } if (in_array($resource['resource_type'], $annotate_rt_exclude)) { return false; } if (!($k == "") && !$annotate_public_view) { return false; } if (!file_exists($path) && !file_exists($path_orig)) { return false; } if (!file_exists($path)) { $sizes = getimagesize($path_orig); } else { $sizes = getimagesize($path); } $w = $sizes[0]; $h = $sizes[1]; ?> <style type="text/css" media="all">@import "<?php echo $baseurl; ?> /plugins/annotate/lib/jquery/css/annotation.css";</style> <script type="text/javascript" src="<?php echo $baseurl; ?> /plugins/annotate/lib/jquery/js/jquery.annotate.js"></script> <script type="text/javascript"> button_ok = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["ok"])); ?> "; button_cancel = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["cancel"])); ?> "; button_delete = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["action-delete"])); ?> "; button_add = "> <?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["action-add_note"])); ?> "; error_saving = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["error-saving"])); ?> "; error_deleting = "<?php echo preg_replace("/\r?\n/", "\\n", addslashes($lang["error-deleting"])); ?> "; </script> <script> jQuery.noConflict(); </script> <div id="wrapper" style="display:block;clear:none;float:left;margin: 0px 10px 10px 0px;"> <div> <img id="toAnnotate" src="<?php echo $url; ?> " id="previewimage" class="Picture" GALLERYIMG="no" style="display:block;" /> </div> <div style="padding-top:10px;"> <?php // MAGICTOUCH PLUGIN COMPATIBILITY global $magictouch_account_id; if ($magictouch_account_id != "") { global $plugins; global $magictouch_rt_exclude; global $magictouch_ext_exclude; if (in_array("magictouch", $plugins) && !in_array($resource['resource_type'], $magictouch_rt_exclude) && !in_array($resource['file_extension'], $magictouch_ext_exclude) && !defined("MTFAIL")) { ?> <a style="display:inline;" href="<?php echo getval("from", "") == "search" ? "search.php?" : "preview.php?ref=" . $ref . "&"; ?> search=<?php echo urlencode($search); ?> &offset=<?php echo $offset; ?> &order_by=<?php echo $order_by; ?> &sort=<?php echo $sort; ?> &archive=<?php echo $archive; ?> &k=<?php echo $k; ?> ">> <?php echo $lang['zoom']; ?> </a><?php } } /////////////// ?> <?php if ($annotate_pdf_output) { ?> <a style="display:inline;float:right;" href="<?php echo $baseurl; ?> /plugins/annotate/pages/annotate_pdf_config.php?ref=<?php echo $ref; ?> &ext=<?php echo $resource["preview_extension"]; ?> &k=<?php echo $k; ?> &search=<?php echo urlencode($search); ?> &offset=<?php echo $offset; ?> &order_by=<?php echo $order_by; ?> &sort=<?php echo $sort; ?> &archive=<?php echo $archive; ?> ">> <?php echo $lang["pdfwithnotes"]; ?> </a> <?php } ?> </div></div> <script language="javascript"> jQuery("#toAnnotate").load(function(){ jQuery("#toAnnotate").annotateImage({ getUrl: "<?php echo $baseurl; ?> /plugins/annotate/pages/get.php?ref=<?php echo $ref; ?> &k=<?php echo $k; ?> &pw=<?php echo $w; ?> &ph=<?php echo $h; ?> ", saveUrl: "<?php echo $baseurl; ?> /plugins/annotate/pages/save.php?ref=<?php echo $ref; ?> &k=<?php echo $k; ?> &pw=<?php echo $w; ?> &ph=<?php echo $h; ?> ", deleteUrl: "<?php echo $baseurl; ?> /plugins/annotate/pages/delete.php?ref=<?php echo $ref; ?> &k=<?php echo $k; ?> ", useAjax: true, <?php if ($k == "") { ?> editable: true <?php } else { ?> editable: false <?php } ?> }); }); </script> <?php return true; }
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 upload_video($access_token="") { global $lang, $video_title, $video_description, $video_keywords, $video_category, $filename, $ref, $status, $youtube_video_url, $youtube_publish_developer_key; # Set status as necessary if ($status=="private"){$private = '<yt:private/>';} else{$private = '';} if ($status=="unlisted"){$accesscontrol = '<yt:accessControl action="list" permission="denied"/>';} else{$accesscontrol = '';} $data= '<?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">' . htmlspecialchars( $video_title ) . '</media:title> ' . $private . ' <media:description type="plain">' . htmlspecialchars( $video_description ) . '</media:description> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">' . htmlspecialchars($video_category) .'</media:category> <media:keywords>' . htmlspecialchars($video_keywords) . '</media:keywords> </media:group> ' . $accesscontrol . ' </entry>'; $data.= "\r\n\r\n"; ##### For resumable $headers = array( "Authorization: Bearer " . $access_token, "GData-Version: 2", "X-GData-Key: key=" . $youtube_publish_developer_key, "Content-length: " . strlen($data), "Content-Type: application/atom+xml; charset=UTF-8", "Slug: " . htmlspecialchars($filename), "Connection: close" , "Expect:" ); $youtube_upload_url="http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"; $curl = curl_init($youtube_upload_url); //curl_setopt( $curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"] ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );; curl_setopt( $curl, CURLOPT_TIMEOUT, 10 ); curl_setopt( $curl, CURLINFO_HEADER_OUT , 1 ); curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0 ); curl_setopt( $curl, CURLOPT_POST, 1 ); curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 0 ); curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers ); curl_setopt( $curl, CURLOPT_POSTFIELDS, $data ); curl_setopt($curl, CURLOPT_HEADER, TRUE); $response = curl_exec( $curl ); if(!curl_errno($curl)) { $info = curl_getinfo($curl); if ($info['http_code']==401) { curl_close( $curl ); get_youtube_access_token(true); return array(false,$lang["youtube_publish_renewing_token"],true); } } else { curl_close( $curl ); $upload_result=$lang["error"] . curl_error($curl); return array(false,curl_errno($curl),false); } $header = substr($response, 0, $info['header_size']); $retVal = array(); $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $header)); foreach( $fields as $field ) { if( preg_match('/([^:]+): (.+)/m', $field, $match) ) { $match[1] = preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1]))); if( isset($retVal[$match[1]]) ) { $retVal[$match[1]] = array($retVal[$match[1]], $match[2]); } else { $retVal[$match[1]] = trim($match[2]); } } } if (isset($retVal['Location'])) { $location = $retVal['Location']; } else { $upload_result=$lang["youtube_publish_failedupload_nolocation"]; curl_close( $curl ); return array(false,$upload_result,false); } curl_close( $curl ); # Finally upload the file # Get file info for upload $resource=get_resource_data($ref); $alternative=-1; $ext=$resource["file_extension"]; $path=get_resource_path($ref,true,"",false,$ext,-1,1,false,"",$alternative); # We assign a default mime-type, in case we can find the one associated to the file extension. $mime="application/octet-stream"; # Get mime type via exiftool if possible $exiftool_fullpath = get_utility_path("exiftool"); if ($exiftool_fullpath!=false) { $command=$exiftool_fullpath . " -s -s -s -t -mimetype " . escapeshellarg($path); $mime=run_command($command); } # Override or correct for lack of exiftool with config mappings if (isset($mime_type_by_extension[$ext])) { $mime = $mime_type_by_extension[$ext]; } $video_file = fopen($path, 'rb'); $curl = curl_init($location); curl_setopt($curl, CURLOPT_PUT, 1); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_INFILE, $video_file); // file pointer curl_setopt($curl, CURLOPT_INFILESIZE, filesize($path)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, $mime ); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3600); $response = curl_exec( $curl ); $videoxml = new SimpleXmlElement($response, LIBXML_NOCDATA); $urlAtt = $videoxml->link->attributes(); $youtube_new_url = $urlAtt['href']; $youtube_urlmatch = '#http://(www\.)youtube\.com/watch\?v=([^ &\n]+)(&.*?(\n|\s))?#i'; preg_match($youtube_urlmatch, $youtube_new_url, $matches); $youtube_new_url=$matches[0]; # end of actual file upload fclose($video_file); $video_file = null; return array(true,$youtube_new_url,false); }
# Add language support if available if (file_exists("../lib/plupload/i18n/" . $language . ".js")) { echo "<script type=\"text/javascript\" src=\"../lib/plupload/i18n/" . $language . ".js?" . $css_reload_key . "\"></script>"; } ?> <div class="BasicsBox" > <?php if ($alternative!=""){?><p> <a href="<?php echo $baseurl_short?>pages/edit.php?ref=<?php echo urlencode($alternative)?>&search=<?php echo urlencode($search)?>&offset=<?php echo urlencode($offset)?>&order_by=<?php echo urlencode($order_by)?>&sort=<?php echo urlencode($sort)?>&archive=<?php echo urlencode($archive)?>">< <?php echo $lang["backtoeditresource"]?></a><br / > <a onClick="return CentralSpaceLoad(this,true);" href="<?php echo $baseurl_short?>pages/view.php?ref=<?php echo urlencode($alternative)?>&search=<?php echo urlencode($search)?>&offset=<?php echo urlencode($offset)?>&order_by=<?php echo urlencode($order_by)?>&sort=<?php echo urlencode($sort)?>&archive=<?php echo urlencode($archive)?>">< <?php echo $lang["backtoresourceview"]?></a></p><?php } ?> <?php if ($replace_resource!=""){?><p> <a href="<?php echo $baseurl_short?>pages/edit.php?ref=<?php echo urlencode($replace_resource)?>&search=<?php echo urlencode($search)?>&offset=<?php echo urlencode($offset)?>&order_by=<?php echo urlencode($order_by)?>&sort=<?php echo urlencode($sort)?>&archive=<?php echo urlencode($archive)?>">< <?php echo $lang["backtoeditresource"]?></a><br / > <a onClick="return CentralSpaceLoad(this,true);" href="<?php echo $baseurl_short?>pages/view.php?ref=<?php echo urlencode($replace_resource) ?>&search=<?php echo urlencode($search)?>&offset=<?php echo urlencode($offset)?>&order_by=<?php echo urlencode($order_by)?>&sort=<?php echo urlencode($sort)?>&archive=<?php echo urlencode($archive)?>">< <?php echo $lang["backtoresourceview"]?></a></p><?php } ?> <?php if ($alternative!=""){$resource=get_resource_data($alternative); if ($alternative_file_resource_preview){ $imgpath=get_resource_path($resource['ref'],true,"col",false); if (file_exists($imgpath)){ ?><img src="<?php echo get_resource_path($resource['ref'],false,"col",false);?>"/><?php } } if ($alternative_file_resource_title){ echo "<h2>".$resource['field'.$view_title_field]."</h2><br/>"; } } # Define the titles: if ($replace!="") { # Replace Resource Batch $titleh1 = $lang["replaceresourcebatch"]; $titleh2 = "";
<?php include dirname(__FILE__) . '/../../include/db.php'; include dirname(__FILE__) . '/../../include/general.php'; include dirname(__FILE__) . '/../../include/authenticate.php'; include dirname(__FILE__) . '/../../include/resource_functions.php'; $resource = getvalescaped('resource', ''); $ref = getvalescaped('ref', ''); $type = getvalescaped('type', ''); $resource_data = get_resource_data($resource); // User should have edit access to this resource! if (!get_edit_access($resource, $resource_data['archive'], false, $resource_data)) { exit('Permission denied.'); } if ($type == 'user') { // Delete the user record from the database $query = sprintf(' DELETE FROM resource_custom_access WHERE resource = "%s" AND user = "******"; ', $resource, $ref); } elseif ($type == 'usergroup') { // Delete the user record from the database $query = sprintf(' DELETE FROM resource_custom_access WHERE resource = "%s" AND usergroup = "%s"; ', $resource, $ref); } else { exit('No type'); }
function tile_search_thumbs($tile, $tile_id, $tile_width, $tile_height, $promoted_image = false) { global $baseurl_short, $lang, $dash_tile_shadows; $tile_type = "srch"; $tile_style = "thmbs"; $search_string = explode('?', $tile["link"]); parse_str(str_replace("&", "&", $search_string[1]), $search_string); $count = $tile["resource_count"] ? "-1" : "1"; $search = isset($search_string["search"]) ? $search_string["search"] : ""; $restypes = isset($search_string["restypes"]) ? $search_string["restypes"] : ""; $order_by = isset($search_string["order_by"]) ? $search_string["order_by"] : ""; $archive = isset($search_string["archive"]) ? $search_string["archive"] : ""; $sort = isset($search_string["sort"]) ? $search_string["sort"] : ""; $tile_search = do_search($search, $restypes, $order_by, $archive, $count, $sort, false, 0, false, false, "", false, false); $found_resources = true; $count = count($tile_search); if (!isset($tile_search[0]["ref"])) { $found_resources = false; $count = 0; } if ($found_resources) { $previewresource = $tile_search[0]; if ($promoted_image) { $promoted_image_data = get_resource_data($promoted_image); if ($promoted_image_data !== false) { $previewresource = $promoted_image_data; } } $defaultpreview = false; $previewpath = get_resource_path($previewresource["ref"], true, "pre", false, "jpg", -1, 1, false); if (file_exists($previewpath)) { $previewpath = get_resource_path($previewresource["ref"], false, "pre", false, "jpg", -1, 1, false); } else { $previewpath = $baseurl_short . "gfx/" . get_nopreview_icon($previewresource["resource_type"], $previewresource["file_extension"], false); $defaultpreview = true; } ?> <img src="<?php echo $previewpath; ?> " <?php if ($defaultpreview) { ?> style="position:absolute;top:<?php echo ($tile_height - 128) / 2; ?> px;left:<?php echo ($tile_width - 128) / 2; ?> px;" <?php } else { #fit image to tile size if ($previewresource["thumb_width"] * 0.7 >= $previewresource["thumb_height"]) { $ratio = $previewresource["thumb_height"] / $tile_height; $width = $previewresource["thumb_width"] / $ratio; if ($width < $tile_width) { echo "width='100%' "; } else { echo "height='100%' "; } } else { $ratio = $previewresource["thumb_width"] / $tile_width; $height = $previewresource["thumb_height"] / $ratio; if ($height < $tile_height) { echo "height='100%' "; } else { echo "width='100%' "; } } ?> style="position:absolute;top:0;left:0;" <?php } ?> class="thmbs_tile_img" /> <?php } $icon = ""; if (substr($search_string["search"], 0, 11) == "!collection") { $icon = "collection"; } else { if (substr($search_string["search"], 0, 7) == "!recent" || substr($search_string["search"], 0, 5) == "!last") { $icon = "clock"; } else { $icon = "search"; } } echo "<span class='" . $icon . "-icon'></span>"; if (!empty($tile["title"])) { ?> <h2 class="title thmbs_tile"> <?php echo htmlspecialchars($tile["title"]); ?> </h2> <?php } else { if (!empty($tile["txt"])) { ?> <h2 class="title notitle thmbs_tile"> <?php echo htmlspecialchars($tile["txt"]); ?> </h2> <?php } } if (!empty($tile["title"]) && !empty($tile["txt"])) { ?> <p> <?php echo htmlspecialchars($tile["txt"]); ?> </p> <?php } if (!$found_resources && !$tile["resource_count"]) { echo "<p class='no_resources'>" . $lang["noresourcesfound"] . "</p>"; } if ($tile["resource_count"]) { ?> <p class="tile_corner_box"> <span class="count-icon"></span> <?php echo $count; ?> </p> <?php } if (!$dash_tile_shadows) { ?> <script> jQuery("#<?php echo $tile_id; ?> ").addClass("TileContentShadow"); </script> <?php } }
function email_resource_request($ref, $details) { # E-mails a basic resource request for a single resource (posted) to the team # (not a managed request) global $applicationname, $email_from, $baseurl, $email_notify, $username, $useremail, $userref, $lang, $request_senduserupdates, $watermark, $filename_field, $view_title_field, $access, $resource_type_request_emails; $resourcedata = get_resource_data($ref); $templatevars['thumbnail'] = get_resource_path($ref, true, "thm", false, "jpg", $scramble = -1, $page = 1, $watermark ? $access == 1 ? true : false : false); if (!file_exists($templatevars['thumbnail'])) { $templatevars['thumbnail'] = "../gfx/" . get_nopreview_icon($resourcedata["resource_type"], $resourcedata["file_extension"], false); } if (isset($filename_field)) { $templatevars["filename"] = $lang["fieldtitle-original_filename"] . ": " . get_data_by_field($ref, $filename_field); } if (isset($resourcedata["field" . $view_title_field])) { $templatevars["title"] = $resourcedata["field" . $view_title_field]; } $templatevars['username'] = $username . " (" . $useremail . ")"; $templatevars['formemail'] = getval("email", ""); $templatevars['url'] = $baseurl . "/?r=" . $ref; $templatevars["requesturl"] = $templatevars['url']; $userdata = get_user($userref); $templatevars["fullname"] = $userdata["fullname"]; $htmlbreak = ""; global $use_phpmailer; if ($use_phpmailer) { $htmlbreak = "<br><br>"; } $list = ""; reset($_POST); foreach ($_POST as $key => $value) { if (strpos($key, "_label") !== false) { # Add custom field $data = ""; $data = $_POST[str_replace("_label", "", $key)]; $list .= $htmlbreak . $value . ": " . $data . "\n"; } } $list .= $htmlbreak; $templatevars['list'] = $list; $templatevars['details'] = stripslashes($details); if ($templatevars['details'] != "") { $adddetails = $lang["requestreason"] . ": " . newlines($templatevars['details']) . "\n\n"; } else { return false; } # Add custom fields $c = ""; global $custom_request_fields, $custom_request_required; if (isset($custom_request_fields)) { $custom = explode(",", $custom_request_fields); # Required fields? if (isset($custom_request_required)) { $required = explode(",", $custom_request_required); } for ($n = 0; $n < count($custom); $n++) { if (isset($required) && in_array($custom[$n], $required) && getval("custom" . $n, "") == "") { return false; # Required field was not set. } $c .= i18n_get_translated($custom[$n]) . ": " . getval("custom" . $n, "") . "\n\n"; } } $templatevars["requestreason"] = $lang["requestreason"] . ": " . $templatevars['details'] . $c . ""; $message = $lang["user_made_request"] . "<br /><br />"; $message .= isset($username) ? $lang["username"] . ": " . $username . " (" . $useremail . ")<br />" : ""; $message .= !empty($templatevars["formemail"]) ? $lang["email"] . ":" . $templatevars["formemail"] . "<br />" : ""; $message .= $adddetails . $c . "<br /><br />" . $lang["clicktoviewresource"] . "<br />" . $templatevars['url']; # Check if alternative request email notification address is set $admin_notify_email = $email_notify; if (isset($resource_type_request_emails)) { if (isset($resource_type_request_emails[$resourcedata["resource_type"]])) { $admin_notify_email = $resource_type_request_emails[$resourcedata["resource_type"]]; } } send_mail($admin_notify_email, $applicationname . ": " . $lang["requestresource"] . " - {$ref}", $message, $useremail, $useremail, "emailresourcerequest", $templatevars); if ($request_senduserupdates) { $sender = !empty($useremail) ? $useremail : !empty($templatevars["formemail"]) ? $templatevars["formemail"] : ""; $k = getval("k", "") != "" ? "&k=" . getval("k", "") : ""; $userconfirmmessage = $lang["requestsenttext"] . "<br /><br />" . $lang["requestreason"] . ": " . $templatevars['details'] . $c . "<br /><br />" . $lang["clicktoviewresource"] . "\n{$baseurl}/?r={$ref}" . $k; if ($sender != "") { send_mail($sender, $applicationname . ": " . $lang["requestsent"] . " - {$ref}", $userconfirmmessage, $email_from, $email_notify, "emailuserresourcerequest", $templatevars); } } # Increment the request counter sql_query("update resource set request_count=request_count+1 where ref='{$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
&sort=<?php echo $sort; ?> &archive=<?php echo $archive; ?> ">< <?php echo $lang["backtoresourceview"]; ?> </a></p><?php } ?> <?php if ($alternative != "") { $resource = get_resource_data($alternative); if ($alternative_file_resource_preview) { $imgpath = get_resource_path($resource['ref'], true, "col", false); if (file_exists($imgpath)) { ?> <img src="<?php echo get_resource_path($resource['ref'], false, "col", false); ?> "/><?php } } if ($alternative_file_resource_title) { echo "<h2>" . $resource['field' . $view_title_field] . "</h2><br/>"; } } # Define the titles:
$exif_override=true; } } if($exif_override){ $uploadparams.="&exif_override=true"; } } hook("editbeforesave"); # save data if (!$multiple){ # Upload template: Change resource type $resource_type=getvalescaped("resource_type",""); if ($resource_type!="" && !checkperm("XU{$resource_type}")){ // only if resource specified and user has permission for that resource type update_resource_type($ref,$resource_type); $resource=get_resource_data($ref,false); # Reload resource data. } $save_errors=save_resource_data($ref,$multiple); if($embedded_data_user_select){ $no_exif=getval("exif_option",""); }else{ $no_exif=getval("no_exif",""); } $autorotate = getval("autorotate",""); if ($upload_collection_name_required){ if (getvalescaped("entercolname","")=="" && getval("collection_add","")==-1){ if (!is_array($save_errors)){$save_errors=array();} $save_errors['collectionname']=$lang["requiredfield"]; } } if (($save_errors===true || $is_template)&&(getval("tweak","")=="")){
// get mp3 paths if necessary and set $use_mp3_player switch if (!(isset($resource['is_transcoding']) && $resource['is_transcoding'] == 1) && (in_array($resource["file_extension"], $ffmpeg_audio_extensions) || $resource["file_extension"] == "mp3") && $mp3_player) { $use_mp3_player = true; } else { $use_mp3_player = false; } if ($use_mp3_player) { $mp3realpath = get_resource_path($ref, true, "", false, "mp3"); if (file_exists($mp3realpath)) { $mp3path = get_resource_path($ref, false, "", false, "mp3"); } } # Dev feature - regenerate exif data. if (getval("regenexif", "") != "") { extract_exif_comment($ref, $resource["file_extension"]); $resource = get_resource_data($ref, false); } # Load access level $access = get_resource_access($ref); hook("beforepermissionscheck"); # check permissions (error message is not pretty but they shouldn't ever arrive at this page unless entering a URL manually) if ($access == 2) { exit("This is a confidential resource."); } hook("afterpermissionscheck"); # Establish if this is a metadata template resource, so we can switch off certain unnecessary features $is_template = isset($metadata_template_resource_type) && $resource["resource_type"] == $metadata_template_resource_type; $title_field = $view_title_field; # If this is a metadata template and we're using field data, change title_field to the metadata template title field if (isset($metadata_template_resource_type) && $resource["resource_type"] == $metadata_template_resource_type) { if (isset($metadata_template_title_field)) {
} elseif ($page_end_1 == $page_end_2) { $ynew = max($y_end_1, $y_end_2); } elseif ($page_end_1 > $page_end_2) { $ynew = $y_end_1; } else { $ynew = $y_end_2; } $this->setPage(max($page_end_1, $page_end_2)); $this->SetXY($this->GetX(), $ynew); } } if ($is_collection) { $collectiondata = get_collection($ref); $resources = do_search("!collection{$ref}"); } else { $resourcedata = get_resource_data($ref); $resources = do_search("!list{$ref}"); } // prune unnannotated resources if necessary if ($annotate_pdf_output_only_annotated) { $resources_modified = array(); $x = 0; for ($n = 0; $n < count($resources); $n++) { unset($notes); if ($annotate_pdf_output_only_annotated && $resources[$n]['annotation_count'] != 0) { $resources_modified[$x] = $resources[$n]; $x++; } } $resources = $resources_modified; }
<div class="cta padding-bottom"> <h3><?php _e('Help/Resources', ALM_NAME); ?> </h3> <?php // Parse help/resources JSON feed on dashboard function get_resource_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); return $data; } $resource_url = 'http://download.connekthq.com/ajax-load-more/resources.json'; $resource_json = json_decode(get_resource_data($resource_url)); print "<ul>"; foreach ($resource_json->data->resource as $resource) { print '<li><a target="blank" href="' . $resource->url . '">' . $resource->title . '</a></li>'; } print "</ul>"; ?> <?php _e('<a href="https://github.com/dcooney/wordpress-ajax-load-more" target="blank" class="visit"><i class="fa fa-github"></i> Latest build on Github</a>', ALM_NAME); ?> </div>
function do_report($ref, $from_y, $from_m, $from_d, $to_y, $to_m, $to_d, $download = true, $add_border = false) { # Run report with id $ref for the date range specified. Returns a result array. global $lang, $baseurl; $report = sql_query("select * from report where ref='{$ref}'"); $report = $report[0]; # Translates the report name. $report["name"] = lang_or_i18n_get_translated($report["name"], "report-"); if ($download) { $filename = str_replace(array(" ", "(", ")", "-", "/"), "_", $report["name"]) . "_" . $from_y . "_" . $from_m . "_" . $from_d . "_" . $lang["to"] . "_" . $to_y . "_" . $to_m . "_" . $to_d . ".csv"; header("Content-type: application/octet-stream"); header("Content-disposition: attachment; filename=" . $filename . ""); } if ($results = hook("customreport", "", array($ref, $from_y, $from_m, $from_d, $to_y, $to_m, $to_d, $download, $add_border))) { } else { $sql = $report["query"]; $sql = str_replace("[from-y]", $from_y, $sql); $sql = str_replace("[from-m]", $from_m, $sql); $sql = str_replace("[from-d]", $from_d, $sql); $sql = str_replace("[to-y]", $to_y, $sql); $sql = str_replace("[to-m]", $to_m, $sql); $sql = str_replace("[to-d]", $to_d, $sql); global $view_title_field; #back compatibility for three default reports, to replace "title" with the view_title_field. #all reports should either use r.title or view_title_field when referencing the title column on the resource table. if ($ref == 7 || $ref == 8 || $ref == 9) { $sql = str_replace(",title", ",field" . $view_title_field, $sql); } $sql = str_replace("view_title_field", "field" . $view_title_field, $sql); $sql = str_replace("r.title", "field" . $view_title_field, $sql); $results = sql_query($sql); #echo "\"Number of results: " . count($results) . "\"\n"; } if ($download) { for ($n = 0; $n < count($results); $n++) { $result = $results[$n]; if ($n == 0) { $f = 0; foreach ($result as $key => $value) { $f++; if ($f > 1) { echo ","; } if ($key != "thumbnail") { echo "\"" . lang_or_i18n_get_translated($key, "columnheader-") . "\""; } } echo "\n"; } $f = 0; foreach ($result as $key => $value) { $f++; if ($f > 1) { echo ","; } if ($key != "thumbnail") { $value = lang_or_i18n_get_translated($value, "usergroup-"); $value = str_replace('"', '""', $value); # escape double quotes if (substr($value, 0, 1) == ",") { $value = substr($value, 1); } # Remove comma prefix on dropdown / checkbox values echo "\"" . $value . "\""; } } echo "\n"; } } else { # Not downloading - output a table $border = ""; if ($add_border) { $border = "border=\"1\""; } $output = "<br /><style>.InfoTable td {padding:5px;}</style><table {$border} class=\"InfoTable\">"; for ($n = 0; $n < count($results); $n++) { $result = $results[$n]; if ($n == 0) { $f = 0; $output .= "<tr>\r\n"; foreach ($result as $key => $value) { $f++; if ($key == "thumbnail") { $output .= "<td><strong>Link</strong></td>\r\n"; } else { $output .= "<td><strong>" . lang_or_i18n_get_translated($key, "columnheader-") . "</strong></td>\r\n"; } } $output .= "</tr>\r\n"; } $f = 0; $output .= "<tr>\r\n"; foreach ($result as $key => $value) { $f++; if ($key == "thumbnail") { $thm_path = get_resource_path($value, true, "thm", false, "", $scramble = -1, $page = 1, false); if (!file_exists($thm_path)) { $resourcedata = get_resource_data($value); $thm_url = $baseurl . "/gfx/" . get_nopreview_icon($resourcedata["resource_type"], $resourcedata["file_extension"], true); } else { $thm_url = get_resource_path($value, false, "col", false, "", -1, 1, false); } $output .= "<td><a href=\"" . $baseurl . "/?r=" . $value . "\" target=\"_blank\"><img src=\"" . $thm_url . "\"></a></td>\r\n"; } else { $output .= "<td>" . lang_or_i18n_get_translated($value, "usergroup-") . "</td>\r\n"; } } $output .= "</tr>\r\n"; } $output .= "</table>\r\n"; if (count($results) == 0) { $output .= $lang["reportempty"]; } return $output; } exit; }
function get_resource_path($ref, $getfilepath, $size, $generate = true, $extension = "jpg", $scramble = -1, $page = 1, $watermarked = false, $file_modified = "", $alternative = -1, $includemodified = true) { # returns the correct path to resource $ref of size $size ($size==empty string is original resource) # If one or more of the folders do not exist, and $generate=true, then they are generated if (!preg_match('/^[a-zA-Z0-9]+$/', $extension)) { $extension = "jpg"; } // if(preg_match('/\w/', $extension)){$extension="jpg";} $override = hook("get_resource_path_override", "general", array($ref, $getfilepath, $size, $generate, $extension, $scramble, $page, $watermarked, $file_modified, $alternative, $includemodified)); if (is_string($override)) { return $override; } global $storagedir; if ($size == "") { # For the full size, check to see if the full path is set and if so return that. global $get_resource_path_fpcache; truncate_cache_arrays(); if (!isset($get_resource_path_fpcache[$ref])) { $get_resource_path_fpcache[$ref] = sql_value("select file_path value from resource where ref='{$ref}'", ""); } $fp = $get_resource_path_fpcache[$ref]; # Test to see if this nosize file is of the extension asked for, else skip the file_path and return a $storagedir path. # If using staticsync, file path will be set already, but we still want the $storagedir path for a nosize preview jpg. # Also, returning the original filename when a nosize 'jpg' is looked for is no good, since preview_preprocessing.php deletes $target. $test_ext = explode(".", $fp); $test_ext = trim(strtolower($test_ext[count($test_ext) - 1])); if ($test_ext == $extension && strlen($fp) > 0 && strpos($fp, "/") !== false && !($alternative > 0)) { if ($getfilepath) { global $syncdir; $syncdirmodified = hook("modifysyncdir", "all", array($ref)); if ($syncdirmodified != "") { return $syncdirmodified; } return $syncdir . "/" . $fp; } else { global $baseurl_short, $k; return $baseurl_short . "pages/download.php?ref={$ref}&size={$size}&ext={$extension}&noattach=true&k={$k}&page={$page}"; } } } global $scramble_key; if ($scramble === -1) { # Find the system default scramble setting if not specified if (isset($scramble_key) && $scramble_key != "") { $scramble = true; } else { $scramble = false; } } if ($scramble) { # Create a scrambled path using the scramble key # It should be very difficult or impossible to work out the scramble key, and therefore access # other resources, based on the scrambled path of a single resource. $scramblepath = substr(md5($ref . "_" . $scramble_key), 0, 15); } if ($extension == "") { $extension = "jpg"; } $folder = ""; #if (!file_exists(dirname(__FILE__) . $folder)) {mkdir(dirname(__FILE__) . $folder,0777);} for ($n = 0; $n < strlen($ref); $n++) { $folder .= substr($ref, $n, 1); if ($scramble && $n == strlen($ref) - 1) { $folder .= "_" . $scramblepath; } $folder .= "/"; #echo "<li>" . $folder; if (!file_exists($storagedir . "/" . $folder) && $generate) { @mkdir($storagedir . "/" . $folder, 0777); chmod($storagedir . "/" . $folder, 0777); } } # Add the page to the filename for everything except page 1. if ($page == 1) { $p = ""; } else { $p = "_" . $page; } # Add the alternative file ID to the filename if provided if ($alternative > 0) { $a = "_alt_" . $alternative; } else { $a = ""; } # Add the watermarked url too if ($watermarked) { $p .= "_wm"; } # Fetching the file path? Add the full path to the file $filefolder = $storagedir . "/" . $folder; if ($getfilepath) { $folder = $filefolder; } else { global $storageurl; $folder = $storageurl . "/" . $folder; } if ($scramble) { $file_old = $filefolder . $ref . $size . $p . $a . "." . $extension; $file_new = $filefolder . $ref . $size . $p . $a . "_" . substr(md5($ref . $size . $p . $a . $scramble_key), 0, 15) . "." . $extension; $file = $folder . $ref . $size . $p . $a . "_" . substr(md5($ref . $size . $p . $a . $scramble_key), 0, 15) . "." . $extension; if (file_exists($file_old)) { rename($file_old, $file_new); } } else { $file = $folder . $ref . $size . $p . $a . "." . $extension; } # Append modified date/time to the URL so the cached copy is not used if the file is changed. if (!$getfilepath && $includemodified) { if ($file_modified == "") { $data = get_resource_data($ref); $file .= "?v=" . urlencode($data['file_modified']); } else { # Use the provided value $file .= "?v=" . urlencode($file_modified); } } return $file; }
<?php include "../include/db.php"; include "../include/authenticate.php"; if (!checkperm("g") && !checkperm("v")) {exit ("Permission denied.");} # Cannot e-mail if can't see hi-res images. To avoid loophole whereby users could email resources to an external address, and hence download hi-res versions. include "../include/general.php"; include "../include/resource_functions.php"; $ref=getvalescaped("ref","",true); # Fetch resource data $resource=get_resource_data($ref);if ($resource===false) {exit("Resource not found.");} # fetch the current search $search=getvalescaped("search",""); $order_by=getvalescaped("order_by","relevance"); $offset=getvalescaped("offset",0,true); $restypes=getvalescaped("restypes",""); if (strpos($search,"!")!==false) {$restypes="";} $archive=getvalescaped("archive",0,true); $default_sort="DESC"; if (substr($order_by,0,5)=="field"){$default_sort="ASC";} $sort=getval("sort",$default_sort); # Load access level and check. $access=get_resource_access($ref); if (!($allow_share && ($access==0 || ($access==1 && $restricted_share)))) {exit("Access denied.");} $errors=""; if (getval("save","")!="") { # Email resource
// Replace usernames with their emails foreach ($email_to as $key => $email) { $user_email = sql_value("SELECT email AS value FROM user WHERE username = '******'", NULL); if ($user_email === NULL) { if (strpos($email, '@') === FALSE) { unset($email_to[$key]); continue; } } else { $email_to[$key] = $user_email; } } // Setup email $email_to = implode(',', $email_to); $email_subject = val($settings['email_subject'], 'Asset Manager Client Approval Submission'); $resource = get_resource_data($ref); switch ($status) { case 'approved': $status = 'Approved'; break; case 'minor': $status = 'Not Approved - Minor Changes'; break; case 'major': $status = 'Not Approved - Major Changes'; break; } ob_start(); include '../inc/email.php'; $message = ob_get_clean(); // Send emails
function extract_exif_comment($ref, $extension = "") { # Extract the EXIF comment from either the ImageDescription field or the UserComment # Also parse IPTC headers and insert # EXIF headers $exifoption = getval("no_exif", ""); // This may have been set to a non-standard value if allowing per field selection if ($exifoption == "yes") { $exifoption = "no"; } // Sounds odd but previously was no_exif so logic reversed if ($exifoption == "") { $exifoption = "yes"; } $image = get_resource_path($ref, true, "", false, $extension); if (!file_exists($image)) { return false; } hook("pdfsearch"); global $exif_comment, $exiftool_no_process, $exiftool_resolution_calc, $disable_geocoding, $embedded_data_user_select_fields, $filename_field; $exiftool_fullpath = get_utility_path("exiftool"); if ($exiftool_fullpath != false && !in_array($extension, $exiftool_no_process)) { $resource = get_resource_data($ref); # Field 8 is used in a special way for staticsync; don't overwrite. if ($resource['file_path'] != "") { $omit_title_for_staticsync = true; } else { $omit_title_for_staticsync = false; } hook("beforeexiftoolextraction"); if ($exiftool_resolution_calc) { # see if we can use exiftool to get resolution/units, and dimensions here. # Dimensions are normally extracted once from the view page, but for the original file, it should be done here if possible, # and exiftool can provide more data. $command = $exiftool_fullpath . " -s -s -s -t -composite:imagesize -xresolution -resolutionunit " . escapeshellarg($image); $dimensions_resolution_unit = explode("\t", run_command($command)); # if dimensions resolution and unit could be extracted, add them to the database. # they can be used in view.php to give more accurate data. if (count($dimensions_resolution_unit) == 3) { $dru = $dimensions_resolution_unit; $filesize = filesize_unlimited($image); $wh = explode("x", $dru[0]); $width = $wh[0]; $height = $wh[1]; $resolution = $dru[1]; $unit = $dru[2]; sql_query("insert into resource_dimensions (resource, width, height, resolution, unit, file_size) values ('{$ref}', '{$width}', '{$height}', '{$resolution}', '{$unit}', '{$filesize}')"); } } $read_from = get_exiftool_fields($resource['resource_type']); # run exiftool to get all the valid fields. Use -s -s option so that # the command result isn't printed in columns, which will help in parsing # We then split the lines in the result into an array $command = $exiftool_fullpath . " -s -s -f -m -d \"%Y-%m-%d %H:%M:%S\" -G " . escapeshellarg($image); $metalines = explode("\n", run_command($command)); $metadata = array(); # an associative array to hold metadata field/value pairs # go through each line and split field/value using the first # occurrance of ": ". The keys in the associative array is converted # into uppercase for easier lookup later foreach ($metalines as $metaline) { # Use stripos() if available, but support earlier PHP versions if not. if (function_exists("stripos")) { $pos = stripos($metaline, ": "); } else { $pos = strpos($metaline, ": "); } if ($pos) { # add to the associative array, also clean up leading/trailing space & single quote (on windows sometimes) # Extract group name and tag name. $s = explode("]", substr($metaline, 0, $pos)); if (count($s) > 1 && strlen($s[0]) > 1) { # Extract value $value = trim(substr($metaline, $pos + 2)); # Replace '..' with line feed - either Exiftool itself or Adobe Bridge replaces line feeds with '..' $value = str_replace('....', '\\n\\n', $value); // Two new line feeds in ExifPro are replaced with 4 dots '....' $value = str_replace('...', '.\\n', $value); # Three dots together is interpreted as a full stop then line feed, not the other way round $value = str_replace('..', '\\n', $value); # Extract group name and tag name $groupname = strtoupper(substr($s[0], 1)); $tagname = strtoupper(trim($s[1])); # Store both tag data under both tagname and groupname:tagname, to support both formats when mapping fields. $metadata[$tagname] = $value; $metadata[$groupname . ":" . $tagname] = $value; debug("Exiftool: extracted field '{$groupname}:{$tagname}', value is '{$value}'"); } } } // We try to fetch the original filename from database. $resources = sql_query("SELECT resource.file_path FROM resource WHERE resource.ref = " . $ref); if ($resources) { $resource = $resources[0]; if ($resource['file_path']) { $metadata['FILENAME'] = mb_basename($resource['file_path']); } } if (isset($metadata['FILENAME'])) { $metadata['STRIPPEDFILENAME'] = strip_extension($metadata['FILENAME']); } # Geolocation Metadata Support if (!$disable_geocoding && isset($metadata['GPSLATITUDE'])) { # Set vars $dec_long = 0; $dec_lat = 0; #Convert latititude to decimal. if (preg_match("/^(?<degrees>\\d+) deg (?<minutes>\\d+)' (?<seconds>\\d+\\.?\\d*)\"/", $metadata['GPSLATITUDE'], $latitude)) { $dec_lat = $latitude['degrees'] + $latitude['minutes'] / 60 + $latitude['seconds'] / (60 * 60); } if (preg_match("/^(?<degrees>\\d+) deg (?<minutes>\\d+)' (?<seconds>\\d+\\.?\\d*)\"/", $metadata['GPSLONGITUDE'], $longitude)) { $dec_long = $longitude['degrees'] + $longitude['minutes'] / 60 + $longitude['seconds'] / (60 * 60); } if (strpos($metadata['GPSLATITUDE'], 'S') !== false) { $dec_lat = -1 * $dec_lat; } if (strpos($metadata['GPSLONGITUDE'], 'W') !== false) { $dec_long = -1 * $dec_long; } if ($dec_long != 0 && $dec_lat != 0) { sql_query("update resource set geo_long='" . escape_check($dec_long) . "',geo_lat='" . escape_check($dec_lat) . "' where ref='{$ref}'"); } } # Update portrait_landscape_field (when reverting metadata this was getting lost) update_portrait_landscape_field($ref); # now we lookup fields from the database to see if a corresponding value # exists in the uploaded file $exif_updated_fields = array(); for ($i = 0; $i < count($read_from); $i++) { $field = explode(",", $read_from[$i]['exiftool_field']); foreach ($field as $subfield) { $subfield = strtoupper($subfield); // convert to upper case for easier comparision if (in_array($subfield, array_keys($metadata)) && $metadata[$subfield] != "-" && trim($metadata[$subfield]) != "") { $read = true; $value = $metadata[$subfield]; # Dropdown box or checkbox list? if ($read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3) { # Check that the value is one of the options and only insert if it is an exact match. # The use of safe_file_name and strtolower ensures matching takes place on alphanumeric characters only and ignores case. # First fetch all options in all languages $options = trim_array(explode(",", strtolower($read_from[$i]["options"]))); for ($n = 0; $n < count($options); $n++) { $options[$n] = $options[$n]; } # If not in the options list, do not read this value $s = trim_array(explode(",", $value)); $value = ""; # blank value for ($n = 0; $n < count($s); $n++) { if (trim($s[0]) != "" && in_array(strtolower($s[$n]), $options)) { $value .= "," . $s[$n]; } } #echo($read_from[$i]["ref"] . " = " . $value . "<br>"); } # Read the data. if ($read) { $plugin = dirname(__FILE__) . "/../plugins/exiftool_filter_" . $read_from[$i]['name'] . ".php"; if ($read_from[$i]['exiftool_filter'] != "") { eval($read_from[$i]['exiftool_filter']); } if (file_exists($plugin)) { include $plugin; } # Field 8 is used in a special way for staticsync; don't overwrite field 8 in this case if (!($omit_title_for_staticsync && $read_from[$i]['ref'] == 8)) { $exiffieldoption = $exifoption; if ($exifoption == "custom" || isset($embedded_data_user_select_fields) && in_array($read_from[$i]['ref'], $embedded_data_user_select_fields)) { debug("EXIF - custom option for field " . $read_from[$i]['ref'] . " : " . $exifoption); $exiffieldoption = getval("exif_option_" . $read_from[$i]['ref'], $exifoption); } debug("EXIF - option for field " . $read_from[$i]['ref'] . " : " . $exiffieldoption); if ($exiffieldoption == "no") { continue; } elseif ($exiffieldoption == "append") { $spacechar = $read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3 ? ", " : " "; $oldval = get_data_by_field($ref, $read_from[$i]['ref']); if (strpos($oldval, $value) !== false) { continue; } $newval = $oldval . $spacechar . iptc_return_utf8($value); } elseif ($exiffieldoption == "prepend") { $spacechar = $read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3 ? ", " : " "; $oldval = get_data_by_field($ref, $read_from[$i]['ref']); if (strpos($oldval, $value) !== false) { continue; } $newval = iptc_return_utf8($value) . $spacechar . $oldval; } else { $newval = iptc_return_utf8($value); } 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); } $oldval = get_data_by_field($ref, $read_from[$i]['ref']); if (strpos($oldval, $value) !== 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); $exif_updated_fields[] = $read_from[$i]['ref']; hook("metadata_extract_addition", "all", array($ref, $newval, $read_from, $i)); } } } else { // Process if no embedded title is found: global $merge_filename_with_title, $lang; if ($merge_filename_with_title && $read_from[$i]['ref'] == 8) { $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); } $oldval = get_data_by_field($ref, $read_from[$i]['ref']); if (strpos($oldval, $value) !== 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); $exif_updated_fields[] = $read_from[$i]['ref']; } } } } if (!in_array($filename_field, $exif_updated_fields)) { $exiffilenameoption = getval("exif_option_" . $filename_field, $exifoption); debug("EXIF - custom option for filename field " . $filename_field . " : " . $exiffilenameoption); if ($exiffilenameoption != "yes") { $uploadedfilename = isset($_REQUEST['name']) ? $_REQUEST['name'] : $processfile['name']; global $userref, $amended_filename; $entered_filename = get_data_by_field(-$userref, $filename_field); debug("EXIF - got entered file name " . $entered_filename); if ($exiffilenameoption == "no") { $amended_filename = $entered_filename; if (trim($amended_filename) == '') { $amended_filename = $uploadedfilename; } if (strpos($amended_filename, $extension) === FALSE) { $amended_filename .= '.' . $extension; } } elseif ($exiffilenameoption == "append") { $amended_filename = $entered_filename . $uploadedfilename; } elseif ($exiffilenameoption == "prepend") { $amended_filename = strip_extension($uploadedfilename) . $entered_filename . "." . $extension; } debug("EXIF - created new file name " . $amended_filename); } } } elseif (isset($exif_comment)) { # # Exiftool is not installed. As a fallback we grab some predefined basic fields using the PHP function # exif_read_data() # if (function_exists("exif_read_data")) { $data = @exif_read_data($image); } else { $data = false; } if ($data !== false) { $comment = ""; #echo "<pre>EXIF\n";print_r($data);exit(); if (isset($data["ImageDescription"])) { $comment = $data["ImageDescription"]; } if ($comment == "" && isset($data["COMPUTED"]["UserComment"])) { $comment = $data["COMPUTED"]["UserComment"]; } if ($comment != "") { # Convert to UTF-8 $comment = iptc_return_utf8($comment); # Save comment global $exif_comment; update_field($ref, $exif_comment, $comment); } if (isset($data["Model"])) { # Save camera make/model global $exif_model; update_field($ref, $exif_model, $data["Model"]); } if (isset($data["DateTimeOriginal"])) { # Save camera date/time global $exif_date; $date = $data["DateTimeOriginal"]; # Reformat date to ISO standard $date = substr($date, 0, 4) . "-" . substr($date, 5, 2) . "-" . substr($date, 8, 11); update_field($ref, $exif_date, $date); } } # Try IPTC headers $size = getimagesize($image, $info); if (isset($info["APP13"])) { $iptc = iptcparse($info["APP13"]); #echo "<pre>IPTC\n";print_r($iptc);exit(); # Look for iptc fields, and insert. $fields = sql_query("select * from resource_type_field where length(iptc_equiv)>0"); for ($n = 0; $n < count($fields); $n++) { $iptc_equiv = $fields[$n]["iptc_equiv"]; if (isset($iptc[$iptc_equiv][0])) { # Found the field if (count($iptc[$iptc_equiv]) > 1) { # Multiple values (keywords) $value = ""; for ($m = 0; $m < count($iptc[$iptc_equiv]); $m++) { if ($m > 0) { $value .= ", "; } $value .= $iptc[$iptc_equiv][$m]; } } else { $value = $iptc[$iptc_equiv][0]; } $value = iptc_return_utf8($value); # Date parsing if ($fields[$n]["type"] == 4) { $value = substr($value, 0, 4) . "-" . substr($value, 4, 2) . "-" . substr($value, 6, 2); } if (trim($value) != "") { update_field($ref, $fields[$n]["ref"], $value); } } } } } # Update the XML metadata dump file. update_xml_metadump($ref); # Auto fill any blank fields. autocomplete_blank_fields($ref); }