-1) { $items[6] = substr($items[6],0,strrpos($items[6],".")); } $collection_stamp = $items[1]; $image_md5 = $items[6]; if (strlen($image_md5) != 32) { header("HTTP/1.1 400 Bad Request"); exit; } $first_dir = substr($image_md5,0,4); $second_dir = substr($image_md5,4,4); $third_dir = substr($image_md5,8,4); $imagefilepath= "ressources/Image/" . $first_dir . "/" . $second_dir . "/" . $third_dir . "/" . $image_md5; /* MySQL and endpoint configuration */ $config = array( /* db */ 'db_host' => 'localhost', /* optional, default is localhost */ 'db_name' => 'sparql', 'db_user' => 'sparql', 'db_pwd' => '58d9da1555cc2467b6bd134ae13761a9', /* store name */ 'store_name' => 'Muninn WW1 Sparql Store, data@muninn-project.org', 'store_name' => 'Muninn', /* endpoint */ 'endpoint_features' => array( 'select', 'construct', 'ask', 'describe', 'load', 'insert', 'delete', 'dump' /* dump is a special command for streaming SPOG export */ ), 'endpoint_timeout' => 60, /* not implemented in ARC2 preview */ 'endpoint_read_key' => '', /* optional */ 'endpoint_write_key' => '4w5y25y265y2y6', /* optional */ 'endpoint_max_limit' => 2500, /* optional */ ); //print "original req " . $_SERVER["REQUEST_URI"]; $content_url = "http://rdf.muninn-project.org/" . $collection_stamp . "/2011/11/11/Image/" . $image_md5; //print "TRying to get " . $content_url . " \n"; //print "For file " . $imagefilepath . "\n"; $accept = array(); foreach ( explode(',', strtolower(str_replace(' ', '', $_SERVER['HTTP_ACCEPT']))) as $singlea) { $itemsnow = explode(';', $singlea); $accept[] = $itemsnow[0]; } if (($Content_Type=="application/rdf+xml") || in_array("application/rdf+xml",$accept) !== FALSE ) { header("HTTP/1.1 303 See Other"); $new_url="http://rdf.muninn-project.org/sparql?query=DESCRIBE+<" . urlencode($content_url) .">"; header("Location: " . $new_url); exit; } error_log("don't know what to do with content-type: [" . $Content_Type."]"); if (($Content_Type=="*/*") || ($Content_Type=="text/html") || ( ($Content_Type=="") && (in_array("*/*",$accept) ||in_array("text/html",$accept) || in_array("application/xhtml+xml",$accept))) ) { //print $Content_Type; header("HTTP/1.1 303 See Other"); $new_url="http://rdf.muninn-project.org/browser.php?uri=" . urlencode($content_url); header("Location: " . $new_url); //print $accept; exit; } /* Activate SPARQL Endpoint */ //$ep = ARC2::getStoreEndpoint($config); //$q = 'DESCRIBE <' . $content_url . '>'; //print "Query " . $q . "\n"; //$rows = $ep->query($q,'raw'); //if ($errs = $ep->getErrors()) { // print "Erroro"; //} //print_r($rows); $store = ARC2::getStore($config); $res = ARC2::getResource(); $res->setStore($store); $res->setURI($content_url); //print "Try2"; $res->getProps(); $labels = $res->getPropValues("http://rdf.muninn-project.org/ontologies/documents#accessRights"); $original_content_type = $res->getPropValues("http://rdf.muninn-project.org/ontologies/documents#format"); $original_source = $res->getPropValues("http://rdf.muninn-project.org/ontologies/documents#source"); $extension=""; error_log($original_content_type[0]); if ($original_content_type[0]=="image/jpeg") { $extension="jpg"; } else if ($original_content_type[0]=="image/png") { $extension="png"; } else if ($original_content_type[0]=="image/svg+xml") { $extension="svg"; } else if ($original_content_type[0]=="image/gif") { $extension="gif"; } #print $SERVER[REMOTE_ADDR]; $imagefilepath = $imagefilepath . "." . $extension; if ((count($labels)==0) || ($labels[0] == null) || ($_SERVER['REMOTE_ADDR'] =="127.0.0.1") || ($_SERVER['REMOTE_ADDR'] =="129.97.186.10") ) { $labels[0]="http://rdf.muninn-project.org/ww1/2011/11/11/Permission/PublicDomain"; } if ((in_array("http://rdf.muninn-project.org/ww1/2011/11/11/Permission/ForwardToOriginal", $labels)) && ($left_top_x == -1)){ if (strpos($original_source[0],"http://")>-1) { header("HTTP/1.1 303 See Other"); header("Location: " . $original_source[0]); exit ; } else { header("HTTP/1.1 403 Forbidden"); exit ; } } //http://rdf.muninn-project.org/ww1/2011/11/11/Permission/ForwardToPublisher if (in_array("http://rdf.muninn-project.org/ww1/2011/11/11/Permission/Restricted",$labels)) { header("HTTP/1.1 403 Forbidden"); exit ; } $image_size_x = $res->getPropValues("http://rdf.muninn-project.org/ontologies/documents#x_pixels"); $image_size_y = $res->getPropValues("http://rdf.muninn-project.org/ontologies/documents#y_pixels"); error_log("Trying to cut from [ $left_top_x, $left_top_y to $right_bottom_x, $right_bottom_y ]"); if ( !(($left_top_y < $right_bottom_y) && ($left_top_x < $right_bottom_x) && ($left_top_y >= 0) && ($left_top_x >= 0) && (! is_null($image_size_y[0])) && (! is_null($image_size_x[0])) && ($right_bottom_y <= $image_size_y[0]) && ($right_bottom_x <= $image_size_x[0])) ) { error_log("Cutting from $left_top_x, $left_top_y to $right_bottom_x, $right_bottom_y failed."); $left_top_y=-1; $left_top_x=-1; $right_bottom_y=-1; $right_bottom_x=-1; } if (($Content_Type=="image/jpeg") || in_array("image/jpeg",$accept)){ $im = new Imagick(); $im->readImage($imagefilepath); $im->setImageFormat( "jpg" ); // Cut o if ( ($left_top_y>-1) && ($left_top_x>-1) && ($right_bottom_y>-1) && ($right_bottom_x>-1) ) { error_log("Cutting from $left_top_x, $left_top_y to $right_bottom_x, $right_bottom_y"); $im->cropImage(($right_bottom_x-$left_top_x),($right_bottom_y-$left_top_y) , $left_top_x, $left_top_y); }//if if (($size_x>0) || ($size_y>0)) { $im->scaleImage($size_x,$size_y, false); error_log("Change to $size_x,$size_y"); } error_log("Sending jpeg"); $im->setImageFormat('jpeg'); $output = $im->getimageblob(); $outputtype = $im->getFormat(); header("Content-type: $outputtype"); header("HTTP/1.1 200 OK"); echo $output; //$new_url="http://rdf.muninn-project.org/browser.php?uri=" . urlencode("DESCRIBE <" . $content_url . ">"); //header("Location: http://rdf.muninn-project.org/sparql?query=" . $new_url); exit; } if (($Content_Type=="image/png") || in_array("image/png",$accept)){ $im = new Imagick(); $im->readImage($imagefilepath); $im->setImageFormat( "png" ); // Cut o if ( ($left_top_y>-1) && ($left_top_x>-1) && ($right_bottom_y>-1) && ($right_bottom_x>-1) ) { error_log("Cutting from $left_top_x, $left_top_y to $right_bottom_x, $right_bottom_y"); $im->cropImage(($right_bottom_x-$left_top_x),($right_bottom_y-$left_top_y) , $left_top_x, $left_top_y); }//if // size if (($size_x>0) || ($size_y>0)) { $im->scaleImage($size_x,$size_y, false); error_log("Change to $size_x,$size_y"); } error_log("Sending png"); $im->setImageFormat('png'); $output = $im->getimageblob(); $outputtype = $im->getFormat(); header("Content-type: $outputtype"); header("HTTP/1.1 200 OK"); echo $output; //$new_url="http://rdf.muninn-project.org/browser.php?uri=" . urlencode("DESCRIBE <" . $content_url . ">"); //header("Location: http://rdf.muninn-project.org/sparql?query=" . $new_url); exit; } if (($Content_Type=="image/gif") || in_array("image/gif",$accept)){ $im = new Imagick(); $im->readImage($imagefilepath); $im->setImageFormat( "gif" ); // Cut o if ( ($left_top_y>-1) && ($left_top_x>-1) && ($right_bottom_y>-1) && ($right_bottom_x>-1) ) { error_log("Cutting from $left_top_x, $left_top_y to $right_bottom_x, $right_bottom_y"); $im->cropImage(($right_bottom_x-$left_top_x),($right_bottom_y-$left_top_y) , $left_top_x, $left_top_y); }//if if (($size_x>0) || ($size_y>0)) { $im->scaleImage($size_x,$size_y, false); error_log("Change to $size_x,$size_y"); } error_log("Sending gif"); $im->setImageFormat('gif'); $output = $im->getimageblob(); $outputtype = $im->getFormat(); header("Content-type: $outputtype"); header("HTTP/1.1 200 OK"); echo $output; //$new_url="http://rdf.muninn-project.org/browser.php?uri=" . urlencode("DESCRIBE <" . $content_url . ">"); //header("Location: http://rdf.muninn-project.org/sparql?query=" . $new_url); exit; } header("HTTP/1.1 500 Server gone to lunch."); //header("HTTP/1.1 200 OK"); print "File $imagefilepath \n"; foreach($accept as $id) { error_log("don't know what to do with: " . $id); } ///"Content Type : $Content_Type \n"; exit; function process_url( $url ) { $a_query_string=""; $query_new = parse_url( $url ); if (array_key_exists('query',$query_new )) { $a_query_string = $query_new[ 'query' ]; } # split into arguments and values $query_string = explode( '&', $a_query_string ); $args = array( ); // return array foreach( $query_string as $chunk ) { $chunk = explode( '=', $chunk ); // it's only really worth keeping if the parameter // has an argument. if ( count( $chunk ) == 2 ) { list( $key, $val ) = $chunk; $args[ $key ] = urldecode( $val ); } } return $args; } //http://jrgns.net/parse_http_accept_header function endswith($string, $test) { $strlen = strlen($string); $testlen = strlen($test); if ($testlen > $strlen) return false; return substr_compare($string, $test, -$testlen) === 0; } function accept_header($header = false) { $toret = null; $header = $header ? $header : (array_key_exists('HTTP_ACCEPT', $_SERVER) ? $_SERVER['HTTP_ACCEPT']: false); if ($header) { $types = explode(',', $header); $types = array_map('trim', $types); foreach ($types as $one_type) { $one_type = explode(';', $one_type); $type = array_shift($one_type); if ($type) { list($precedence, $tokens) = accept_header_options($one_type); list($main_type, $sub_type) = array_map('trim', explode('/', $type)); $toret[] = array('main_type' => $main_type, 'sub_type' => $sub_type, 'precedence' => (float)$precedence, 'tokens' => $tokens); } } usort($toret, array('Parser', 'compare_media_ranges')); } return $toret; } function accept_header_options($type_options) { $precedence = 1; $tokens = array(); if (is_string($type_options)) { $type_options = explode(';', $type_options); } $type_options = array_map('trim', $type_options); foreach ($type_options as $option) { $option = explode('=', $option); $option = array_map('trim', $option); if ($option[0] == 'q') { $precedence = $option[1]; } else { $tokens[$option[0]] = $option[1]; } } $tokens = count ($tokens) ? $tokens : false; return array($precedence, $tokens); } function lastIndexOf($haystack, $needle) { $index = strpos(strrev($haystack), strrev($needle)); $index = strlen($haystack) - strlen(index) - $index; return $index; } ?>