Benutzer:Antonsusi/newskyhack
aus Wikipedia, der freien Enzyklopädie
Angaben zum Skript befinden sich auf der D-Seite.
<?PHP
ob_start("ob_gzhandler");
# error_reporting( E_ALL );
# ini_set("display_errors",1);
/**
skyhack by user:kolossos@wikipedia Released under GPL
based on geohack (c) by
Magnus Manske (2006)
Released under GPL
geo_param.php is (c) 2005, Egil Kvaleberg <egil@kvaleberg.no>, also GPL
*/
# include "../common.php" ;
# ini_set('user_agent','MSIE 4\.0b2;'); # Fake user agent
ini_set('user_agent','skyhack'); # Fake user agent
# include "geo_param.php" ;
# include "mapsources.php" ;
function fix_language_code ( $lang , $default = "en" ) {
$lang = trim ( strtolower ( $lang ) ) ;
if ( preg_match ( "/^([\-a-z]+)/" , $lang , $l ) ) {
$lang = $l[0] ;
} else $lang = $default ; // Fallback
return $lang ;
}
function get_request ( $key , $default = "" ) {
global $prefilled_requests ;
if ( isset ( $prefilled_requests[$key] ) ) return $prefilled_requests[$key] ;
if ( isset ( $_REQUEST[$key] ) ) return str_replace ( "\'" , "'" , $_REQUEST[$key] ) ;
return $default ;
}
set_time_limit ( 20 ) ; # 20 sec should be enough for everyone!
$name=addslashes($_GET[name]);
$object=addslashes($_GET[object]);
if ($object=="") {$object=$name; }
$name_url=str_replace(" ","",$name);
# right ascension hh mm ss
$ra_h=addslashes($_GET[rah]); # hours
$ra_m=addslashes($_GET[ram]); # min
$ra_s=addslashes($_GET[ras]); # sec
# declination +/-ddd mm ss
$de_v=addslashes($_GET[dev]); # +/-
$de_d=addslashes($_GET[ded]); # deg
$de_h=addslashes($_GET[dem]); # arcmin
$de_s=addslashes($_GET[des]); # arcsec
$radius=addslashes($_GET[radius]); # radius
$ra= $ra_h + $ra_m / 60 + $ra_s / 3600 ;
$de= $de_d + $de_m / 60 + $de_s / 3600 ;
if ($de_v =='-'){ $de= -1*$de ; }
$longoogle= 15 * $ra - 180 ;
$londegdec= 15 * $ra ;
$latdegdec= $de ;
$size=addslashes($_GET[size]); #App-dim in degrees (beta)
if ( $size==''){$size=0.01;}
$size_minute=$size*60;
$beta=0.0087266*$size;
$range = 6378000 *(1.1917536 * sin($beta) - cos($beta) + 1);
$z=floor(-log($size/90,2));
if ( $radius=='' ) {$radius= 1.2 * $size_minute;}
if ( $radius < 10 ) {$radius = 10;}
if ( $radius > 600 ) {$radius = 600;}
$lang = fix_language_code ( get_request ( 'language' , 'en' ) , '' ) ;
if ( $lang == '' ) {
print "No language given!" ;
exit ;
}
$test = isset ( $_REQUEST['test'] ) ;
# Read template
$pagename = "Template:SkyhackTool" ;
$page = @file_get_contents ( "http://meta.wikimedia.org/wiki/http://meta.wikipedia.org/wiki/$pagename?action=render" ) ;
if ( false === $page || '' == $page ) {
print "Failed to open template. Please try again in a moment." ;
exit ;
}
$page = str_replace ( ' href="/w' , " href=\"http://{$lang}.wikipedia.org/w" , $page ) ;
# Separate content
# $page = array_pop ( explode ( '<!-- start skyhack -->' , $page , 2 ) ) ;
# $page = array_shift ( explode ( '<!-- end skyhack -->' , $page , 2 ) ) ;
# Remove edit links
do {
$op = $page ;
$p = explode ( '<span class="editsection"' , $page , 2 ) ;
if ( count ( $p ) == 1 ) continue ;
$page = array_shift ( $p ) ;
$p = explode ( '</span>' , array_pop ( $p ) , 2 ) ;
$page .= array_pop ( $p ) ;
} while ( $op != $page ) ;
# Replace text
$page = str_replace ( '{rah}' ,$ra_h, $page ) ;
$page = str_replace ( '{ram}' ,$ra_m, $page ) ;
$page = str_replace ( '{ras}' ,$ra_s, $page ) ;
$page = str_replace ( '{dev}' ,$de_v, $page ) ;
$page = str_replace ( '{ded}' ,$de_d, $page ) ;
$page = str_replace ( '{dem}' ,$de_m, $page ) ;
$page = str_replace ( '{des}' ,$de_s, $page ) ;
$page = str_replace ( '{longoogle}' ,$longoogle, $page ) ;
$page = str_replace ( '{londegdec}' ,$londegdec, $page ) ;
$page = str_replace ( '{latdegdec}' ,$latdegdec, $page ) ;
$page = str_replace ( '{name}' ,$name, $page ) ;
$page = str_replace ( '{name_url}' ,$name_url, $page ) ;
$page = str_replace ( '{title}' ,$name, $page ) ;
$page = str_replace ( '{object}' ,$object, $page ) ;
$page = str_replace ( '{size}' ,$size, $page ) ;
$page = str_replace ( '{size_minute}' ,$size_minute, $page ) ;
$page = str_replace ( '{z}' ,$z, $page ) ;
$page = str_replace ( '{range}' ,$range, $page ) ;
$page = str_replace ( '{radius}' ,$radius, $page ) ;
for ( $a = 1 ; $a <= 5 ; $a++ ) {
$k = 'viz' . $a ;
$k2 = '{' . $k . '}' ;
$k3 = '{' . $k . 'text}' ;
if ( isset ( $_REQUEST[$k] ) ) {
$page = str_replace ( $k2 , urlencode ( $_REQUEST[$k] ) , $page ) ;
$page = str_replace ( $k3 , $_REQUEST[$k] , $page ) ;
} else {
$p = explode ( $k2 , $page , 2 ) ;
if ( count ( $p ) != 2 ) continue ;
$p1 = explode ( '<li>' , $p[0] ) ;
$p2 = explode ( '</li>' , $p[1]) ;
array_pop ( $p1 ) ;
array_shift ( $p2 ) ;
$page = implode ( '<li>' , $p1 ) ;
$page .= implode ( '</li>' , $p2 ) ;
$page = str_replace ( $k2 , urlencode ( $_REQUEST[$k] ) , $page ) ;
}
}
# Output
print "<html><head><title>Mapsources for the sky</title>" ;
print "<html><head><title>Mapsources for the sky</title>" ;
print "<meta http-equiv='content-type' content='text/html; charset=utf-8'>" ;
print '<link rel="stylesheet" type="text/css" media="screen" href="http://en.wikipedia.org/skins-1.5/monobook/main.css" >' ;
print $stylesheets ;
print '</head><body style="margin-left:5px; margin-right:5px;">' ;
print '
<div style="float:right">
<a href="http://toolserver.org">
<img style="vertical-align:top" border=0 src="http://tools.wikimedia.de/images/wikimedia-toolserver-button.png" />
</a>
</div>
<span style="left:5px;top:2px;position:relative;border:2px solid red;display:inline;float:left;padding:2px;font-size:150%;background-color:white"><a target="_blank" href="http://wikimediafoundation.org/wiki/Fundraising">Donate to Wikimedia!</a></span>
<center style="width:100%; border-bottom:1px solid #AAAAAA;margin-bottom:3px;padding:2px;background-color:#AAFFAA">
This is based on the ''mapsources'' extension by <a href="http://en.wikipedia.org/wiki/User:Egil">en:User:Egil</a>, extended by <a href="http://en.wikipedia.org/wiki/User:Magnus_Manske">Magnus Manske</a> and <a href="http://de.wikipedia.org/wiki/Benutzer:Kolossos">User:Kolossos</a>.
<br/>
For the source of this script, see
<a href="./skyhack-source.php">skyhack-source.php</a>.
</center>
' ;
print '
<div id="globalWrapper">
<div>
<div style="float:left">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/0/07/Orion_Nebula_-_Hubble_2006_mosaic.jpg/140px-Orion_Nebula_-_Hubble_2006_mosaic.jpg" />
</div>
<div id="content" style="margin-top:0px;margin-left:145px">
<div id="bodyContent">
= Map sources/SkyHack =
' ;
print $page ;
print '
</div>
</div>
</div>
</div>
</body>
</html>
' ;
?>
</php>