function generate_thumbnail($sURL, $needConnect) { if (!is_logged_in()) { return getError("no logged-in user"); } $res = array(); //get picture from service //"http://www.sitepoint.com/forums/image.php?u=106816&dateline=1312480118"; $remote_path = str_replace("[URL]", $sURL, WEBSITE_THUMBNAIL_SERVICE); $heurist_path = tempnam(HEURIST_FILESTORE_DIR, "_temp_"); // . $file_id; $filesize = saveURLasFile($remote_path, $heurist_path); if ($filesize > 0) { //check the dimension of returned thumbanil in case it less than 50 - consider it as error if (strpos($remote_path, substr(WEBSITE_THUMBNAIL_SERVICE, 0, 24)) == 0) { $image_info = getimagesize($heurist_path); if ($image_info[1] < 50) { //remove temp file unlink($heurist_path); return getError("Thumbnail generator service can't create the image for specified URL"); } } $fileID = upload_file("snapshot.jpg", "jpg", $heurist_path, null, $filesize, $sURL, $needConnect); if (is_numeric($fileID)) { $res = get_uploaded_file_info($fileID, $needConnect); } else { $res = getError("File upload was interrupted. " . $fileID); } } else { $res = getError("Cannot download image"); } return $res; }
} if (!is_logged_in()) { jsonError("no logged-in user"); } if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0) { jsonError("File is too large. " . $_SERVER['CONTENT_LENGTH'] . " bytes exceeds the limit of " . ini_get('post_max_size') . ". Please get system administrator to increase the file size limits or load your large files on a video server or other suitable web service and use the URL to reference the file here"); } else { $upload = @$_FILES["file"]; if ($upload) { mysql_connection_overwrite(DATABASE); mysql_query("start transaction"); //POST Content-Length of 103399974 bytes exceeds the limit of 29360128 bytes in Unknown on line //$upload["type"] $fileID = upload_file($upload["name"], null, $upload["tmp_name"], $upload["error"], $upload["size"], $_REQUEST["description"], false); if (is_numeric($fileID)) { $file = get_uploaded_file_info($fileID, false); print json_format($file); mysql_query("commit"); } else { if ($fileID) { jsonError($fileID); } else { if ($_FILES["file"]["error"]) { jsonError("uploaded file was too large"); } else { jsonError("file upload was interrupted"); } } } } else { jsonError("File data are not posted to server side");
/** * description * Get all recDetails entries for this record, * as an array. * File entries have file data associated, * geo entries have geo data associated, * record references have title data associated. * here we want list of detail values for this record grouped by detail Type * recordType can contain pseudoDetailTypes that are structural only information (relmarker, separator and fieldsetmarker) * since these will never be instantiated to a detail (data value) we don't need to worry about them here. Any detail will * will be of valid type and might not be in the definition of the rec type (Heurist separates data storage for type definition). * * @param int $recID record ID * @return object array of details index by local detailID * @uses get_uploaded_file_info() to get the file info */ function getAllRecordDetails($recID) { $res = mysql_query("select dtl_ID, dtl_DetailTypeID, dtl_Value, rec_Title, dtl_UploadedFileID, trm_Label,\n\t if(dtl_Geo is not null, astext(envelope(dtl_Geo)), null) as envelope,\n\t if(dtl_Geo is not null, astext(dtl_Geo), null) as dtl_Geo\n\t from recDetails\n\t left join defDetailTypes on dty_ID=dtl_DetailTypeID\n\t left join Records on rec_ID=dtl_Value and dty_Type='resource'\n\t left join defTerms on trm_ID = dtl_Value\n\t where dtl_RecID = {$recID} order by dtl_DetailTypeID, dtl_ID"); $recDetails = array(); while ($row = mysql_fetch_assoc($res)) { $detail = array(); $detail["id"] = $row["dtl_ID"]; $detail["value"] = $row["dtl_Value"]; if (array_key_exists('trm_Label', $row) && $row['trm_Label']) { $detail["enumValue"] = $row["trm_Label"]; } if ($row["rec_Title"]) { $detail["title"] = $row["rec_Title"]; } if ($row["dtl_UploadedFileID"]) { $fileres = get_uploaded_file_info($row["dtl_UploadedFileID"], false); if ($fileres) { $detail["file"] = $fileres["file"]; } } else { if ($row["envelope"] && preg_match("/^POLYGON[(][(]([^ ]+) ([^ ]+),[^,]*,([^ ]+) ([^,]+)/", $row["envelope"], $poly)) { list($match, $minX, $minY, $maxX, $maxY) = $poly; /*****DEBUG****/ //error_log($match); $x = 0.5 * ($minX + $maxX); $y = 0.5 * ($minY + $maxY); // This is a bit ugly ... but it is useful. // Do things differently for a path -- set minX,minY to the first point in the path, maxX,maxY to the last point if ($row["dtl_Value"] == "l" && preg_match("/^LINESTRING[(]([^ ]+) ([^ ]+),.*,([^ ]+) ([^ ]+)[)]\$/", $row["dtl_Geo"], $matches)) { list($dummy, $minX, $minY, $maxX, $maxY) = $matches; } switch ($row["dtl_Value"]) { case "p": $type = "point"; break; case "pl": $type = "polygon"; break; case "c": $type = "circle"; break; case "r": $type = "rectangle"; break; case "l": $type = "path"; break; default: $type = "unknown"; } $wkt = $row["dtl_Value"] . " " . $row["dtl_Geo"]; // well-known text value $detail["geo"] = array("minX" => $minX, "minY" => $minY, "maxX" => $maxX, "maxY" => $maxY, "x" => $x, "y" => $y, "type" => $type, "value" => $wkt); } } if (!@$recDetails[$row["dtl_DetailTypeID"]]) { $recDetails[$row["dtl_DetailTypeID"]] = array(); } array_push($recDetails[$row["dtl_DetailTypeID"]], $detail); } return $recDetails; }
function loadRecordDetails(&$record) { $recID = $record["rec_ID"]; $squery = "select dtl_ID,\n\t\tdtl_DetailTypeID,\n\t\tdtl_Value,\n\t\tAsWKT(dtl_Geo) as dtl_Geo,\n\t\tdtl_UploadedFileID,\n\t\tdty_Type,\n\t\trec_ID,\n\t\trec_Title,\n\t\trec_RecTypeID,\n\t\trec_Hash\n\t\tfrom recDetails\n\t\tleft join defDetailTypes on dty_ID = dtl_DetailTypeID\n\t\tleft join Records on rec_ID = dtl_Value and dty_Type = 'resource'\n\t\twhere dtl_RecID = {$recID}"; $res = mysql_query($squery); $details = array(); while ($rd = mysql_fetch_assoc($res)) { // skip all invalid value if (!$rd["dty_Type"] === "file" && $rd["dtl_Value"] === null || ($rd["dty_Type"] === "enum" || $rd["dty_Type"] === "relationtype") && !$rd["dtl_Value"]) { continue; } if (!@$details[$rd["dtl_DetailTypeID"]]) { $details[$rd["dtl_DetailTypeID"]] = array(); } $detailValue = null; switch ($rd["dty_Type"]) { case "freetext": case "blocktext": case "float": case "date": case "enum": case "relationtype": case "integer": case "boolean": case "year": case "urlinclude": // these shoudl no logner exist, retained for backward compatibility $detailValue = $rd["dtl_Value"]; break; case "file": $detailValue = get_uploaded_file_info($rd["dtl_UploadedFileID"], false); break; case "resource": $detailValue = array("id" => $rd["rec_ID"], "type" => $rd["rec_RecTypeID"], "title" => $rd["rec_Title"], "hhash" => $rd["rec_Hash"]); break; case "geo": if ($rd["dtl_Value"] && $rd["dtl_Geo"]) { $detailValue = array("geo" => array("type" => $rd["dtl_Value"], "wkt" => $rd["dtl_Geo"])); } break; case "separator": // this should never happen since separators are not saved as details, skip if it does // this should never happen since separators are not saved as details, skip if it does case "relmarker": // relmarkers are places holders for display of relationships constrained in some way // relmarkers are places holders for display of relationships constrained in some way default: continue; } if ($detailValue) { $details[$rd["dtl_DetailTypeID"]][$rd["dtl_ID"]] = $detailValue; } } $record["details"] = $details; }
function print_public_details($bib) { global $terms, $is_map_popup; $bds_res = mysql_query('select dty_ID, ifnull(rdr.rst_DisplayName, dty_Name) as name, dtl_Value as val, dtl_UploadedFileID, dty_Type, if(dtl_Geo is not null, AsWKT(dtl_Geo), null) as dtl_Geo, if(dtl_Geo is not null, AsWKT(envelope(dtl_Geo)), null) as bd_geo_envelope from recDetails left join defDetailTypes on dty_ID = dtl_DetailTypeID left join defRecStructure rdr on rdr.rst_DetailTypeID = dtl_DetailTypeID and rdr.rst_RecTypeID = ' . $bib['rec_RecTypeID'] . ' where dtl_RecID = ' . $bib['rec_ID'] . ' order by rdr.rst_DisplayOrder is null, rdr.rst_DisplayOrder, dty_ID, dtl_ID'); $bds = array(); $thumbs = array(); if ($bds_res) { while ($bd = mysql_fetch_assoc($bds_res)) { if ($bd['dty_ID'] == 603) { //DT_FULL_IMAG_URL array_push($thumbs, array('url' => $bd['val'], 'thumb' => HEURIST_BASE_URL . 'common/php/resizeImage.php?db=' . HEURIST_DBNAME . '&file_url=' . $bd['val'])); } if ($bd['dty_Type'] == 'enum') { if (array_key_exists($bd['val'], $terms['termsByDomainLookup']['enum'])) { $term = $terms['termsByDomainLookup']['enum'][$bd['val']]; $bd['val'] = output_chunker(getFullTermLabel($terms, $term, 'enum', false)); //$bd['val'] = output_chunker($terms['termsByDomainLookup']['enum'][$bd['val']][0]); } else { $bd['val'] = ""; } } else { if ($bd['dty_Type'] == 'relationtype') { $term = $terms['termsByDomainLookup']['relation'][$bd['val']]; $bd['val'] = output_chunker(getFullTermLabel($terms, $term, 'relation', false)); //$bd['val'] = output_chunker($terms['termsByDomainLookup']['relation'][$bd['val']][0]); } else { if ($bd['dty_Type'] == 'date') { $bd['val'] = temporalToHumanReadableString($bd['val'], true); $bd['val'] = output_chunker($bd['val']); } else { if ($bd['dty_Type'] == 'resource') { $res = mysql_query('select rec_Title from Records where rec_ID=' . intval($bd['val'])); $row = mysql_fetch_row($res); $bd['val'] = '<a target="_new" href="' . HEURIST_BASE_URL . 'records/view/renderRecordData.php?db=' . HEURIST_DBNAME . '&recID=' . $bd['val'] . (defined('use_alt_db') ? '&alt' : '') . '" onclick="return link_open(this);">' . htmlspecialchars($row[0]) . '</a>'; } else { if ($bd['dty_Type'] == 'file' && $bd['dtl_UploadedFileID']) { //All works with recUploadedFiles MUST be centralized in uploadFile.php $filedata = get_uploaded_file_info($bd['dtl_UploadedFileID'], false); if ($filedata) { $filedata = $filedata['file']; $remoteSrc = $filedata['remoteSource']; //add to thumbnail list $isplayer = array_key_exists('playerURL', $filedata) && $filedata['playerURL']; if (is_image($filedata) || $isplayer) { if ($isplayer && is_image($filedata) && is_logged_in()) { $filedata['playerURL'] .= "&annedit=yes"; } array_push($thumbs, array('id' => $filedata['id'], 'url' => $filedata['URL'], 'thumb' => $filedata['thumbURL'], 'player' => $isplayer ? $filedata['playerURL'] . ($remoteSrc == 'youtube' || $remoteSrc == 'gdrive' ? "" : "&height=60%") : null)); } if ($filedata['URL'] == $filedata['remoteURL']) { //remote resource $bd['val'] = '<a target="_surf" class="external-link" href="' . htmlspecialchars($filedata['URL']) . '">' . htmlspecialchars($filedata['URL']) . '</a>'; } else { $bd['val'] = '<a target="_surf" class="external-link" href="' . htmlspecialchars($filedata['URL']) . '">' . htmlspecialchars($filedata['origName']) . '</a> ' . ($filedata['fileSize'] > 0 ? '[' . htmlspecialchars($filedata['fileSize']) . 'kB]' : ''); } } } else { if (preg_match('/^https?:/', $bd['val'])) { if (strlen($bd['val']) > 100) { $trim_url = preg_replace('/^(.{70}).*?(.{20})$/', '\\1...\\2', $bd['val']); } else { $trim_url = $bd['val']; } $bd['val'] = '<a href="' . $bd['val'] . '" target="_new">' . htmlspecialchars($trim_url) . '</a>'; } else { if ($bd['dtl_Geo'] && preg_match("/^POLYGON\\s?[(][(]([^ ]+) ([^ ]+),[^,]*,([^ ]+) ([^,]+)/", $bd["bd_geo_envelope"], $poly)) { list($match, $minX, $minY, $maxX, $maxY) = $poly; if ($bd["val"] == "l" && preg_match("/^LINESTRING\\s?[(]([^ ]+) ([^ ]+),.*,([^ ]+) ([^ ]+)[)]\$/", $bd["dtl_Geo"], $matches)) { list($dummy, $minX, $minY, $maxX, $maxY) = $matches; } /* redundant $minX = intval($minX*10)/10; $minY = intval($minY*10)/10; $maxX = intval($maxX*10)/10; $maxY = intval($maxY*10)/10; */ switch ($bd["val"]) { case "p": $type = "Point"; break; case "pl": $type = "Polygon"; break; case "c": $type = "Circle"; break; case "r": $type = "Rectangle"; break; case "l": $type = "Path"; break; default: $type = "Unknown"; } if ($type == "Point") { $bd["val"] = "<b>Point</b> " . round($minX, 7) . ", " . round($minY, 7); } else { $bd['val'] = "<b>{$type}</b> X " . round($minX, 7) . ", " . round($maxX, 7) . " Y " . round($minY, 7) . ", " . round($maxY, 7); } $geoimage = "<img class='geo-image' src='" . HEURIST_BASE_URL . "common/images/geo.gif' onmouseout='{if(mapViewer){mapViewer.hide();}}' " . "onmouseover='{if(mapViewer){mapViewer.showAtStatic(event, " . $bib['rec_ID'] . ");}}'> "; $bd['val'] = $geoimage . $bd['val']; } else { $bd['val'] = output_chunker($bd['val']); } } } } } } } array_push($bds, $bd); } } if ($is_map_popup) { echo '<div>'; } else { echo '<div class=detailRowHeader>Shared'; } ?> <div class=thumbnail> <?php foreach ($thumbs as $thumb) { print '<div class=thumb_image>'; if ($thumb['player'] && !$is_map_popup) { print '<img id="img' . $thumb['id'] . '" src="' . htmlspecialchars($thumb['thumb']) . '" onClick="showPlayer(this,' . $thumb['id'] . ',\'' . htmlspecialchars($thumb['player']) . '\')">'; print '<div id="player' . $thumb['id'] . '" style="min-height:240px;min-width:320px;display:none;"></div>'; } else { //for usual image print '<img src="' . htmlspecialchars($thumb['thumb']) . '" onClick="zoomInOut(this,\'' . htmlspecialchars($thumb['thumb']) . '\',\'' . htmlspecialchars($thumb['url']) . '\')">'; } print '<br/><div class="download_link">'; if ($thumb['player'] && !$is_map_popup) { print '<a id="lnk' . $thumb['id'] . '" href="#" style="display:none;" onclick="hidePlayer(' . $thumb['id'] . ')">CLOSE</a> '; } print '<a href="' . htmlspecialchars($thumb['url']) . '" target=_surf class="image_tool">DOWNLOAD</a></div>'; print '</div>'; if ($is_map_popup) { print '<br>'; break; //in map popup show the only thumbnail } } ?> </div> <?php $always_visible_dt = array(defined('DT_NAME') ? DT_SHORT_SUMMARY : 0, defined('DT_NAME') ? DT_GEO_OBJECT : 0); $prevLbl = null; foreach ($bds as $bd) { print '<div class="detailRow" style="width:100%;border:none 1px #00ff00;' . ($is_map_popup && !in_array($bd['dty_ID'], $always_visible_dt) ? 'display:none' : '') . '"><div class=detailType>' . ($prevLbl == $bd['name'] ? "" : htmlspecialchars($bd['name'])) . '</div><div class="detail' . ($is_map_popup && $bd['dty_ID'] != DT_SHORT_SUMMARY ? ' truncate' : '') . '">' . $bd['val'] . '</div></div>'; $prevLbl = $bd['name']; } ?> <div class=detailRow <?php echo $is_map_popup ? 'style="display:none"' : ''; ?> > <div class=detailType>Updated</div><div class=detail><?php echo $bib['rec_Modified']; ?> </div> </div> <div class=detailRow <?php echo $is_map_popup ? 'style="display:none"' : ''; ?> > <div class=detailType>Cite as</div><div class="detail<?php echo $is_map_popup ? ' truncate' : ''; ?> "><a target=_blank class="external-link" href="<?php echo HEURIST_BASE_URL; ?> ?recID=<?php echo $bib['rec_ID'] . "&db=" . HEURIST_DBNAME; ?> "> <?php echo HEURIST_BASE_URL; ?> ?recID=<?php echo $bib['rec_ID'] . "&db=" . HEURIST_DBNAME; ?> </a></div> </div> <?php // </div> if ($is_map_popup) { echo '<div class=detailRow><div class=detailType><a href="#" onClick="$(\'.detailRow\').show();$(event.target).hide()">more ...</a></div></div>'; echo '<div class=detailRow> </div>'; } echo '</div>'; }