%PDF- %PDF-
| Direktori : /www/varak.net/www.varak.net/sig/ |
| Current File : /www/varak.net/www.varak.net/sig/sig.php |
<?
/*******************************************************************************
Copyright (c) 2007, Chris Heald. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the Author nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.
* You are free to use this software in any commercial or non-commercial capacity
you wish, provided that the following conditions are met:
1) The original author and any contributors are given visible credit for this
tool any place it is used. The retention of the "http://wow.tachyonsix.com/armory"
credit on generated images is appreciated, but not required.
2) You make a good-faith effort to contribute modifications, contributions, and
changes to this tool back to the community by releasing them under a license
similar to this one. This is non-binding, but is greatly appreciated.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************/
$options = parseIni("sig_config.ini", true);
$mainFont = $options["General"]["MainFont"];
$plainFont = $options["General"]["PlainFont"];
if($options["General"]["Disable"] == "true")
die_image("Sigs offline due to server load. Will return shortly. See http://armory.mmo-champion.com for updates.");
// We'd like to disable hotlinking from our site to encourage people to use the Coral proxy. This saves our machine from fiery death.
// if(@$_SERVER["HTTP_REFERER"] && !preg_match("/CoralWebPrx/i", $_SERVER["HTTP_USER_AGENT"]) && !preg_match("/" . $options["General"]["OKReferer"] . "/i", $_SERVER["HTTP_REFERER"])) die_image("Direct hotlinking isn't allowed. Use provided .nyud.net:8080 links at http://armory.mmo-champion.com");
include_once("_armory.php");
include("_guild_stat_paths.php");
ini_set("user_agent", "Mozilla/5.0 Gecko/20070219 Firefox/2.0.0.2");
$PARAMETERS = getSigParameters();
$base_url = $options["General"]["US_URL"];
if(@$PARAMETERS["EU"] == "EU")
$base_url = $options["General"]["EU_URL"];
logReferer("SigEngine");
$CHARACTER = $PARAMETERS["char"];
$REALM = $PARAMETERS["realm"];
$img = ImageCreateTrueColor(450, 64);
$charData = getCharacterData($base_url, $REALM, $CHARACTER);
$char = $charData->xpath("/page/characterInfo/character");
$ranks = $charData->xpath("/page/characterInfo/characterTab/knownTitles/title");
$titleImg = "";
foreach($ranks as $rank) {
$a = attribs($rank);
if($options["Ranks"][$a["value"]]) {
$titleImg = $options["Ranks"][$a["value"]];
break;
}
}
$attr = attribs($char[0]);
$gender = $attr["genderId"];
$class = $attr["classId"];
$race = $attr["raceId"];
$portrait = false;
if($PARAMETERS["sig_image"])
$portrait = getPortraitImage($PARAMETERS["sig_image"], $_SERVER["HTTP_USER_AGENT"]);
if(!$portrait)
$portrait = ImageCreateFromGif("static/portraits/wow70/$gender-$race-$class.gif");
$white = ImageColorAllocate($img, 255, 255, 255);
$whitea = ImageColorAllocateAlpha($img, 255, 255, 255, 80);
$black = ImageColorAllocate($img, 0, 0, 0);
$blacka = ImageColorAllocateAlpha($img, 0, 0, 0, 100);
$text_r = 255;
$text_g = 210;
$text_b = 0;
$s_text_r = 255;
$s_text_g = 255;
$s_text_b = 255;
if($PARAMETERS["text_color_1"]) {
list($text_r, $text_g, $text_b) = getHexColors($PARAMETERS["text_color_1"]);
}
if($PARAMETERS["text_color_2"]) {
list($s_text_r, $s_text_g, $s_text_b) = getHexColors($PARAMETERS["text_color_2"]);
}
$textcolor = ImageColorAllocate($img, $text_r, $text_g, $text_b);
$secondaryTextColor = ImageColorAllocate($img, $s_text_r, $s_text_g, $s_text_b);
ImageFill($img, 0, 0, $black);
$base_r = 0;
$base_g = 0;
$base_b = 0;
$dest_r = 0;
$dest_g = 120;
$dest_b = 255;
if($PARAMETERS["color_1"]) list($base_r, $base_g, $base_b) = getHexColors($PARAMETERS["color_1"]);
if($PARAMETERS["color_2"]) list($dest_r, $dest_g, $dest_b) = getHexColors($PARAMETERS["color_2"]);
for($i=0; $i<ImageSY($img); $i++) {
$r = min($base_r + (($dest_r - $base_r) / ImageSY($img) * $i) ,255);
$g = min($base_g + (($dest_g - $base_g) / ImageSY($img) * $i) ,255);
$b = min($base_b + (($dest_b - $base_b) / ImageSY($img) * $i) ,255);
$c = ImageColorAllocate($img, $r, $g, $b);
ImageLine($img, 0, $i, ImageSX($img), $i, $c);
ImageColorDeallocate($img, $c);
}
$url = $options["General"]["SiteCredits"];
ImageTTFText($img, 6.5, 0, ImageSX($img) - width($url, 6.5, $plainFont) - 5, ImageSY($img) - 4, $whitea, $plainFont, $url);
$offset = 3;
ImageFilledRectangle($img, $offset, $offset, ImageSX($img) - $offset - 1, ImageSY($img) - $offset - 1, $blacka);
ImageRectangle($img, $offset, $offset, ImageSX($img) - $offset - 1, ImageSY($img) - $offset - 1, $blacka);
ImageCopyResampled($img, $portrait, 0, 0, 0, 0, 64, 64, ImageSX($portrait), ImageSY($portrait));
ImageRectangle($img, 0, 0, ImageSX($img) - 1, ImageSY($img) - 1, $black);
$left = 0;
$RIGHT_EDGE = 0;
$fontSize = 21;
if(strlen($attr["name"]) >= 10)
$fontSize = 18;
if($titleImg) {
$rank = ImageCreateFromPNG("static/ranks/$titleImg");
ImageCopyResampled($img, $rank, 70, 9, 0, 0, 20, 20, ImageSX($rank), ImageSY($rank));
ImageTTFText($img, $fontSize, 0, 95, 27, $textcolor, $mainFont, $attr["name"]);
$left = width($attr["name"], $fontSize, $mainFont) + 90;
} else {
ImageTTFText($img, $fontSize, 0, 75, 27, $textcolor, $mainFont, $attr["name"]);
$left = width($attr["name"], $fontSize, $mainFont) + 70;
}
$textLeft = min($left + 150, 335);
$lineWidth = $textLeft - 120;
// Write spec
$spec = getFirstAttrib($charData, "/page/characterInfo/characterTab/talentSpec", "treeOne") . " / " .
getFirstAttrib($charData, "/page/characterInfo/characterTab/talentSpec", "treeTwo") . " / " .
getFirstAttrib($charData, "/page/characterInfo/characterTab/talentSpec", "treeThree");
ImageTTFText($img, 7, 0, $textLeft - width($spec, 7, $plainFont), 13, $textcolor, $plainFont, "$spec");
// Write professions
for($i=1; $i<=2; $i++) {
$profs = $charData->xpath("/page/characterInfo/skillTab/skillCategory[@key='professions']/skill[$i]");
if($profs && sizeof($profs) > 0) {
$prof = attribs($profs[0]);
$name = $prof["name"];
$v = $prof["value"];
$txt = $v . " " . $name;
ImageTTFText($img, 7, 0, $textLeft - width($txt, 7, $plainFont), 22 + (($i-1) * 9), $textcolor, $plainFont, $txt);
}
}
$midWidth = $lineWidth;
$y = 33;
ImageLine($img, 100, $y, 100+$midWidth, $y, $textcolor);
for($i=0; $i<30; $i++) {
$c = ImageColorAllocateAlpha($img, $text_r, $text_g, $text_b, floor(87 / 30 * $i)+40);
ImageLine($img, 100+$midWidth+$i, $y, 100+$midWidth+$i+1, $y, $c);
ImageLine($img, 100-$i, $y, 99-$i, $y, $c);
ImageColorDeallocate($img, $c);
}
$lvl = $attr["level"];
$race = $attr["race"];
$class = $attr["class"];
ImageTTFText($img, 10, 0, 70, 46, $textcolor, $mainFont, "Level $lvl $race $class");
$eu = "";
if($PARAMETERS["EU"])
$eu = "EU";
if($attr["guildName"])
ImageTTFText($img, 9, 0, 70, 59, $textcolor, $mainFont, "<" . $attr["guildName"] . "> of $attr[realm] $eu");
else
ImageTTFText($img, 9, 0, 70, 59, $textcolor, $mainFont, "$attr[realm] $eu");
$class = $options["ClassLookup"][$attr["classId"]];
$i = 1;
for($i=1; $i<=5; $i++) {
// Handle both s#/stat# - this is for shorter URLs while maintaining backwards compatibility with older versions
if(@$PARAMETERS["stat$i"]) {
$name = $PARAMETERS["stat$i"];
if(@!$options["Stats"][$name]) {
$name = $options["Lookups"][$name];
}
if($options["Stats"][$name]) {
$v = getDocumentValue($charData, $options["Stats"][$name]);
if(preg_match("/(\d)v\d Rating/", $name)) {
$t = $name;
$name = $v;
$v = $t . ": ";
}
if($name == "Parry" && $class == "Druid")
$v = "[X]";
elseif(preg_match("/percent/i", $options["Stats"][$name]))
$v .= "%";
} else {
$v = "";
$name = "(invalid - fix)";
}
$text = $v . " " . $name;
$bbox = ImageTTFBBox(8, 0, $mainFont, $text);
ImageTTFText($img, 8, 0, ImageSX($img) - $bbox[2] - 8, 3 + ($i*10), $secondaryTextColor, $mainFont, $text);
}
}
if($options["General"]["SaveBandwidth"] == "true")
imageTrueColorToPalette2($img, true, 512);
$filename = preg_replace("/[^a-z0-9]/i", "_", "$CHARACTER-$REALM");
$ext = "png";
header("Content-disposition: inline; filename=$filename.$ext");
header("content-type: image/$ext");
header("cache-control: max-age=86400");
ImagePNG($img);
//ImageJPEG($img, false, 90);
function ImageTrueColorToPalette2( $image, $dither, $ncolors )
{
$width = imagesx( $image );
$height = imagesy( $image );
$colors_handle = ImageCreateTrueColor( $width, $height );
ImageCopyMerge( $colors_handle, $image, 0, 0, 0, 0, $width, $height, 100 );
ImageTrueColorToPalette( $image, $dither, $ncolors );
ImageColorMatch( $colors_handle, $image );
ImageDestroy( $colors_handle );
}
function getFirstAttrib($x, $p, $a) {
$hps = @$x->xpath($p);
if(!$hps) return 0;
$hpa = attribs($hps[0]);
return $hpa[$a];
}
function getHexColors($c) {
$c = preg_replace("/[^a-f0-9]/i", "", $c);
return array(
hexdec(substr($c, 0, 2)),
hexdec(substr($c, 2, 2)),
hexdec(substr($c, 4, 2))
);
}
function width($txt, $size, $font) {
$b = ImageTTFBBox($size, 0, $font, $txt);
return $b[2];
}
function getPortraitImage($img, $replace = false) {
if(!preg_match("/(png|jpg|gif)$/i", $img)) return false;
$local_filename = preg_replace("/[^a-zA-Z0-9_.-]/", "_", $img);
$f = "uploads/$local_filename";
if(!file_exists($f) || $replace) {
file_put_contents($f, file_get_contents($img));
}
$portrait = false;
if(preg_match("/png$/i", $f))
@$portrait = ImageCreateFromPNG($f);
elseif(preg_match("/jpg$/i", $f))
@$portrait = ImageCreateFromJPEG($f);
elseif(preg_match("/gif$/i", $f))
@$portrait = ImageCreateFromGIF($f);
return $portrait;
}
function getSigParameters() {
$PARAMETERS = array();
if(@!$_SERVER["QUERY_STRING"]) {
$query = explode(basename($_SERVER["SCRIPT_FILENAME"]) . "/", $_SERVER["REQUEST_URI"]);
if(preg_match("/^[0-9]+[a-zA-Z]+\.png$/", $query[1])) {
$id = explode(".", $query[1]);
$db = getDBConnection();
$id = mysql_real_escape_string($id[0]);
$row = mysql_fetch_array(mysql_query("select * from sigs where idstr = '$id'"));
if(!$row) die_image("Unable to find that sig. Visit http://armory.mmo-champion.com to create a new sig.");
mysql_query("update sigs set last_access = NOW() where id = $row[id]", $db);
$p = unserialize($row["params"]);
$PARAMETERS = array(
"EU" => $p["loc"] == "EU",
"char" => $p["c"],
"realm" => $p["r"],
"sig_image" => $p["si"],
"text_color_1" => $p["tc1"],
"text_color_2" => $p["tc2"],
"color_1" => $p["c1"],
"color_2" => $p["c2"],
"stat1" => $p["s1"],
"stat2" => $p["s2"],
"stat3" => $p["s3"],
"stat4" => $p["s4"],
"stat5" => $p["s5"],
);
} else {
$bits = explode("!", $query[1]);
$r = array();
foreach($bits as $bit) {
list($k, $v) = explode("$", $bit, 2);
$r[$k] = urldecode($v);
}
$PARAMETERS = array(
"EU" => $r["loc"] == "EU",
"char" => $r["c"] ? $r["c"] : $r["char"],
"realm" => $r["r"] ? $r["r"] : $r["realm"],
"sig_image" => $r["si"],
"text_color_1" => $r["tc1"],
"text_color_2" => $r["tc2"],
"color_1" => $r["c1"] ? $r["c1"] : $r["bgcolor1"],
"color_2" => $r["c2"] ? $r["c2"] : $r["bgcolor2"],
"stat1" => $r["s1"] ? $r["s1"] : $r["stat1"],
"stat2" => $r["s2"] ? $r["s2"] : $r["stat2"],
"stat3" => $r["s3"] ? $r["s3"] : $r["stat3"],
"stat4" => $r["s4"] ? $r["s4"] : $r["stat4"],
"stat5" => $r["s5"] ? $r["s5"] : $r["stat5"]
);
}
} else {
$r = @$_REQUEST;
$PARAMETERS = array(
"EU" => $r["loc"] == "EU",
"char" => $r["c"] ? $r["c"] : $r["char"],
"realm" => $r["r"] ? $r["r"] : $r["realm"],
"sig_image" => $r["si"],
"text_color_1" => $r["tc1"],
"text_color_2" => $r["tc2"],
"color_1" => $r["c1"] ? $r["c1"] : $r["bgcolor1"],
"color_2" => $r["c2"] ? $r["c2"] : $r["bgcolor2"],
"stat1" => $r["s1"] ? $r["s1"] : $r["stat1"],
"stat2" => $r["s2"] ? $r["s2"] : $r["stat2"],
"stat3" => $r["s3"] ? $r["s3"] : $r["stat3"],
"stat4" => $r["s4"] ? $r["s4"] : $r["stat4"],
"stat5" => $r["s5"] ? $r["s5"] : $r["stat5"]
);
}
return $PARAMETERS;
}
function die_image($msg) {
$x = ImageFontWidth(2) * strlen($msg);
$i = ImageCreate($x+10, 17);
$w = ImageColorAllocate($i, 255, 255, 255);
$b = ImageColorAllocate($i, 0,0,0);
ImageString($i, 2, 5, 0, $msg, $b);
header("content-type: image/png");
ImagePNG($i);
exit();
}
function getDocumentValue($doc, $path) {
$value = -1;
preg_match("/\{(.*)\}(.*)/", $path, $matches);
if(sizeof($matches) > 2) {
$func = $matches[1];
if($func == "MIN") $value = xmin($doc, $matches[2]);
if($func == "MAX") $value = xmax($doc, $matches[2]);
if($func == "SUM") $value = xsum($doc, $matches[2]);
if($func == "AVOID") $value = xavoidance($doc, $matches[2]);
} else {
$func = $matches[1];
if($func == "AVOID") $value = xavoidance($doc, $matches[2]);
else $value = xsum($doc, $path);
}
return $value;
}
function xavoidance($doc, $path) {
$dodgeblock = xsum($doc, "/page/characterInfo/characterTab/defenses/parry/@percent | /page/characterInfo/characterTab/defenses/dodge/@percent");
$defense = xsum($doc, "/page/characterInfo/characterTab/defenses/defense/@plusDefense | /page/characterInfo/characterTab/defenses/defense/@value");
$total = $dodgeblock + ((($defense - 350) / 5) / 5) + 5;
return $total . "%";
}
function xsum($doc, $path) {
$x = $doc->xpath($path);
if(!$x) return 0;
$s = 0;
foreach($x as $xv) {
$s += (float)$xv;
}
if((int)$s == $s) return (int)$s;
return $s;
}
function xmax($doc, $path) {
$x = $doc->xpath($path);
$s = 0;
foreach($x as $xv) {
$s = max((float)$xv, $s);
}
if((int)$s == $s) return (int)$s;
return $s;
}
function xmin($doc, $path) {
$x = $doc->xpath($path);
$s = 99999999999999999999999999;
foreach($x as $xv) {
$s = min((float)$xv, $s);
}
if((int)$s == $s) return (int)$s;
return $s;
}
function parseIni($file) {
$f = file($file);
$sections = array();
$curSection = false;
foreach($f as $fl) {
if(!trim($fl)) continue;
if(preg_match("/^\[(.*?)\]$/", trim($fl), $matches)) {
$curSection = $matches[1];
} else {
list($k, $v) = explode("=", trim($fl), 2);
$sections[$curSection][$k] = $v;
}
}
return $sections;
}
?>