| 1 | 85 | simandl | <?php |
| 2 | | | // PHP Weathermap 0.97a |
| 3 | | | // Copyright Howard Jones, 2005-2010 howie@thingy.com |
| 4 | | | // http://www.network-weathermap.com/ |
| 5 | | | // Released under the GNU Public License |
| 6 | | | |
| 7 | | | require_once "HTML_ImageMap.class.php"; |
| 8 | | | |
| 9 | | | class WeatherMapNode extends WeatherMapItem |
| 10 | | | { |
| 11 | | | var $owner; |
| 12 | | | var $id; |
| 13 | | | var $x, $y; |
| 14 | | | var $original_x, $original_y,$relative_resolved; |
| 15 | | | var $width, $height; |
| 16 | | | var $label, $proclabel, $labelfont; |
| 17 | | | var $labelangle; |
| 18 | | | var $name; |
| 19 | | | var $infourl = array(); |
| 20 | | | var $notes; |
| 21 | | | var $colours = array(); |
| 22 | | | var $overliburl; |
| 23 | | | var $overlibwidth, $overlibheight; |
| 24 | | | var $overlibcaption = array(); |
| 25 | | | var $maphtml; |
| 26 | | | var $selected = 0; |
| 27 | | | var $iconfile, $iconscalew, $iconscaleh; |
| 28 | | | var $targets = array(); |
| 29 | | | var $bandwidth_in, $bandwidth_out; |
| 30 | | | var $inpercent, $outpercent; |
| 31 | | | var $max_bandwidth_in, $max_bandwidth_out; |
| 32 | | | var $max_bandwidth_in_cfg, $max_bandwidth_out_cfg; |
| 33 | | | var $labeloffset, $labeloffsetx, $labeloffsety; |
| 34 | | | |
| 35 | | | var $inherit_fieldlist; |
| 36 | | | |
| 37 | | | var $labelbgcolour; |
| 38 | | | var $labeloutlinecolour; |
| 39 | | | var $labelfontcolour; |
| 40 | | | var $labelfontshadowcolour; |
| 41 | | | var $cachefile; |
| 42 | | | var $usescale; |
| 43 | | | var $useiconscale; |
| 44 | | | var $scaletype, $iconscaletype; |
| 45 | | | var $inscalekey,$outscalekey; |
| 46 | | | var $inscaletag, $outscaletag; |
| 47 | | | # var $incolour,$outcolour; |
| 48 | | | var $scalevar, $iconscalevar; |
| 49 | | | var $notestext = array(); |
| 50 | | | var $image; |
| 51 | | | var $centre_x, $centre_y; |
| 52 | | | var $relative_to; |
| 53 | | | var $zorder; |
| 54 | | | var $template; |
| 55 | | | var $polar; |
| 56 | | | var $boundingboxes=array(); |
| 57 | | | |
| 58 | | | function WeatherMapNode() |
| 59 | | | { |
| 60 | | | $this->inherit_fieldlist=array |
| 61 | | | ( |
| 62 | | | 'boundingboxes'=>array(), |
| 63 | | | 'my_default' => NULL, |
| 64 | | | 'label' => '', |
| 65 | | | 'proclabel' => '', |
| 66 | | | 'usescale' => 'DEFAULT', |
| 67 | | | 'scaletype' => 'percent', |
| 68 | | | 'iconscaletype' => 'percent', |
| 69 | | | 'useiconscale' => 'none', |
| 70 | | | 'scalevar' => 'in', |
| 71 | | | 'template' => ':: DEFAULT ::', |
| 72 | | | 'iconscalevar' => 'in', |
| 73 | | | 'labelfont' => 3, |
| 74 | | | 'relative_to' => '', |
| 75 | | | 'relative_resolved' => FALSE, |
| 76 | | | 'x' => NULL, |
| 77 | | | 'y' => NULL, |
| 78 | | | 'inscalekey'=>'', 'outscalekey'=>'', |
| 79 | | | #'incolour'=>-1,'outcolour'=>-1, |
| 80 | | | 'original_x' => 0, |
| 81 | | | 'original_y' => 0, |
| 82 | | | 'inpercent'=>0, |
| 83 | | | 'outpercent'=>0, |
| 84 | | | 'labelangle'=>0, |
| 85 | | | 'iconfile' => '', |
| 86 | | | 'iconscalew' => 0, |
| 87 | | | 'iconscaleh' => 0, |
| 88 | | | 'targets' => array(), |
| 89 | | | 'infourl' => array(IN=>'',OUT=>''), |
| 90 | | | 'notestext' => array(IN=>'',OUT=>''), |
| 91 | | | 'notes' => array(), |
| 92 | | | 'hints' => array(), |
| 93 | | | 'overliburl' => array(IN=>array(),OUT=>array()), |
| 94 | | | 'overlibwidth' => 0, |
| 95 | | | 'overlibheight' => 0, |
| 96 | | | 'overlibcaption' => array(IN=>'',OUT=>''), |
| 97 | | | 'labeloutlinecolour' => array(0, 0, 0), |
| 98 | | | 'labelbgcolour' => array(255, 255, 255), |
| 99 | | | 'labelfontcolour' => array(0, 0, 0), |
| 100 | | | 'labelfontshadowcolour' => array(-1, -1, -1), |
| 101 | | | 'aiconoutlinecolour' => array(0,0,0), |
| 102 | | | 'aiconfillcolour' => array(-2,-2,-2), // copy from the node label |
| 103 | | | 'labeloffset' => '', |
| 104 | | | 'labeloffsetx' => 0, |
| 105 | | | 'labeloffsety' => 0, |
| 106 | | | 'zorder' => 600, |
| 107 | | | 'max_bandwidth_in' => 100, |
| 108 | | | 'max_bandwidth_out' => 100, |
| 109 | | | 'max_bandwidth_in_cfg' => '100', |
| 110 | | | 'max_bandwidth_out_cfg' => '100' |
| 111 | | | ); |
| 112 | | | |
| 113 | | | $this->width = 0; |
| 114 | | | $this->height = 0; |
| 115 | | | $this->centre_x = 0; |
| 116 | | | $this->centre_y = 0; |
| 117 | | | $this->polar = FALSE; |
| 118 | | | $this->image = NULL; |
| 119 | | | } |
| 120 | | | |
| 121 | | | function my_type() { return "NODE"; } |
| 122 | | | |
| 123 | | | // make a mini-image, containing this node and nothing else |
| 124 | | | // figure out where the real NODE centre is, relative to the top-left corner. |
| 125 | | | function pre_render($im, &$map) |
| 126 | | | { |
| 127 | | | // don't bother drawing if there's no position - it's a template |
| 128 | | | if( is_null($this->x) ) return; |
| 129 | | | if( is_null($this->y) ) return; |
| 130 | | | |
| 131 | | | // apparently, some versions of the gd extension will crash |
| 132 | | | // if we continue... |
| 133 | | | if($this->label == '' && $this->iconfile=='') return; |
| 134 | | | |
| 135 | | | // start these off with sensible values, so that bbox |
| 136 | | | // calculations are easier. |
| 137 | | | $icon_x1 = $this->x; $icon_x2 = $this->x; |
| 138 | | | $icon_y1 = $this->y; $icon_y2 = $this->y; |
| 139 | | | $label_x1 = $this->x; $label_x2 = $this->x; |
| 140 | | | $label_y1 = $this->y; $label_y2 = $this->y; |
| 141 | | | $boxwidth = 0; $boxheight = 0; |
| 142 | | | $icon_w = 0; |
| 143 | | | $icon_h = 0; |
| 144 | | | |
| 145 | | | $col = new Colour(-1,-1,-1); |
| 146 | | | # print $col->as_string(); |
| 147 | | | |
| 148 | | | // if a target is specified, and you haven't forced no background, then the background will |
| 149 | | | // come from the SCALE in USESCALE |
| 150 | | | if( !empty($this->targets) && $this->usescale != 'none' ) |
| 151 | | | { |
| 152 | | | $pc = 0; |
| 153 | | | |
| 154 | | | if($this->scalevar == 'in') |
| 155 | | | { |
| 156 | | | $pc = $this->inpercent; |
| 157 | | | $col = $this->colours[IN]; |
| 158 | | | |
| 159 | | | } |
| 160 | | | |
| 161 | | | if($this->scalevar == 'out') |
| 162 | | | { |
| 163 | | | $pc = $this->outpercent; |
| 164 | | | $col = $this->colours[OUT]; |
| 165 | | | |
| 166 | | | } |
| 167 | | | } |
| 168 | | | elseif($this->labelbgcolour != array(-1,-1,-1)) |
| 169 | | | { |
| 170 | | | // $col=myimagecolorallocate($node_im, $this->labelbgcolour[0], $this->labelbgcolour[1], $this->labelbgcolour[2]); |
| 171 | | | $col = new Colour($this->labelbgcolour); |
| 172 | | | } |
| 173 | | | |
| 174 | | | $colicon = null; |
| 175 | | | if ( !empty($this->targets) && $this->useiconscale != 'none' ) |
| 176 | | | { |
| 177 | | | debug("Colorising the icon\n"); |
| 178 | | | $pc = 0; |
| 179 | | | $val = 0; |
| 180 | | | |
| 181 | | | if($this->iconscalevar == 'in') |
| 182 | | | { |
| 183 | | | $pc = $this->inpercent; |
| 184 | | | $col = $this->colours[IN]; |
| 185 | | | $val = $this->bandwidth_in; |
| 186 | | | } |
| 187 | | | if($this->iconscalevar == 'out') |
| 188 | | | { |
| 189 | | | $pc = $this->outpercent; |
| 190 | | | $col = $this->colours[OUT]; |
| 191 | | | $val = $this->bandwidth_out; |
| 192 | | | } |
| 193 | | | |
| 194 | | | if($this->iconscaletype=='percent') |
| 195 | | | { |
| 196 | | | list($colicon,$node_iconscalekey,$icontag) = |
| 197 | | | $map->NewColourFromPercent($pc, $this->useiconscale,$this->name ); |
| 198 | | | } |
| 199 | | | else |
| 200 | | | { |
| 201 | | | // use the absolute value if we aren't doing percentage scales. |
| 202 | | | list($colicon,$node_iconscalekey,$icontag) = |
| 203 | | | $map->NewColourFromPercent($val, $this->useiconscale,$this->name, FALSE ); |
| 204 | | | } |
| 205 | | | } |
| 206 | | | |
| 207 | | | // figure out a bounding rectangle for the label |
| 208 | | | if ($this->label != '') |
| 209 | | | { |
| 210 | | | $padding = 4.0; |
| 211 | | | $padfactor = 1.0; |
| 212 | | | |
| 213 | | | $this->proclabel = $map->ProcessString($this->label,$this,TRUE,TRUE); |
| 214 | | | |
| 215 | | | // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 |
| 216 | | | // hopefully that will preserve enough information to show cool stuff without leaking info |
| 217 | | | if($map->get_hint('screenshot_mode')==1) $this->proclabel = screenshotify($this->proclabel); |
| 218 | | | |
| 219 | | | list($strwidth, $strheight) = $map->myimagestringsize($this->labelfont, $this->proclabel); |
| 220 | | | |
| 221 | | | if($this->labelangle==90 || $this->labelangle==270) |
| 222 | | | { |
| 223 | | | $boxwidth = ($strheight * $padfactor) + $padding; |
| 224 | | | $boxheight = ($strwidth * $padfactor) + $padding; |
| 225 | | | debug ("Node->pre_render: ".$this->name." Label Metrics are: $strwidth x $strheight -> $boxwidth x $boxheight\n"); |
| 226 | | | |
| 227 | | | $label_x1 = $this->x - ($boxwidth / 2); |
| 228 | | | $label_y1 = $this->y - ($boxheight / 2); |
| 229 | | | |
| 230 | | | $label_x2 = $this->x + ($boxwidth / 2); |
| 231 | | | $label_y2 = $this->y + ($boxheight / 2); |
| 232 | | | |
| 233 | | | if($this->labelangle==90) |
| 234 | | | { |
| 235 | | | $txt_x = $this->x + ($strheight / 2); |
| 236 | | | $txt_y = $this->y + ($strwidth / 2); |
| 237 | | | } |
| 238 | | | if($this->labelangle==270) |
| 239 | | | { |
| 240 | | | $txt_x = $this->x - ($strheight / 2); |
| 241 | | | $txt_y = $this->y - ($strwidth / 2); |
| 242 | | | } |
| 243 | | | } |
| 244 | | | |
| 245 | | | if($this->labelangle==0 || $this->labelangle==180) |
| 246 | | | { |
| 247 | | | $boxwidth = ($strwidth * $padfactor) + $padding; |
| 248 | | | $boxheight = ($strheight * $padfactor) + $padding; |
| 249 | | | debug ("Node->pre_render: ".$this->name." Label Metrics are: $strwidth x $strheight -> $boxwidth x $boxheight\n"); |
| 250 | | | |
| 251 | | | $label_x1 = $this->x - ($boxwidth / 2); |
| 252 | | | $label_y1 = $this->y - ($boxheight / 2); |
| 253 | | | |
| 254 | | | $label_x2 = $this->x + ($boxwidth / 2); |
| 255 | | | $label_y2 = $this->y + ($boxheight / 2); |
| 256 | | | |
| 257 | | | $txt_x = $this->x - ($strwidth / 2); |
| 258 | | | $txt_y = $this->y + ($strheight / 2); |
| 259 | | | |
| 260 | | | if($this->labelangle==180) |
| 261 | | | { |
| 262 | | | $txt_x = $this->x + ($strwidth / 2); |
| 263 | | | $txt_y = $this->y - ($strheight / 2); |
| 264 | | | } |
| 265 | | | |
| 266 | | | # $this->width = $boxwidth; |
| 267 | | | # $this->height = $boxheight; |
| 268 | | | } |
| 269 | | | $map->nodes[$this->name]->width = $boxwidth; |
| 270 | | | $map->nodes[$this->name]->height = $boxheight; |
| 271 | | | |
| 272 | | | # print "TEXT at $txt_x , $txt_y\n"; |
| 273 | | | } |
| 274 | | | |
| 275 | | | // figure out a bounding rectangle for the icon |
| 276 | | | if ($this->iconfile != '') |
| 277 | | | { |
| 278 | | | $icon_im = NULL; |
| 279 | | | $icon_w = 0; |
| 280 | | | $icon_h = 0; |
| 281 | | | |
| 282 | | | if($this->iconfile == 'rbox' || $this->iconfile == 'box' || $this->iconfile == 'round' || $this->iconfile == 'inpie' || $this->iconfile == 'outpie' || $this->iconfile == 'gauge' || $this->iconfile == 'nink') |
| 283 | | | { |
| 284 | | | debug("Artificial Icon type " .$this->iconfile. " for $this->name\n"); |
| 285 | | | // this is an artificial icon - we don't load a file for it |
| 286 | | | |
| 287 | | | $icon_im = imagecreatetruecolor($this->iconscalew,$this->iconscaleh); |
| 288 | | | imageSaveAlpha($icon_im, TRUE); |
| 289 | | | |
| 290 | | | $nothing=imagecolorallocatealpha($icon_im,128,0,0,127); |
| 291 | | | imagefill($icon_im, 0, 0, $nothing); |
| 292 | | | |
| 293 | | | $fill = NULL; |
| 294 | | | $ink = NULL; |
| 295 | | | |
| 296 | | | $aifill = new Colour($this->aiconfillcolour); |
| 297 | | | $aiink = new Colour($this->aiconoutlinecolour); |
| 298 | | | |
| 299 | | | if ( $aifill->is_copy() && !$col->is_none() ) |
| 300 | | | { |
| 301 | | | $fill = $col; |
| 302 | | | } |
| 303 | | | else |
| 304 | | | { |
| 305 | | | if($aifill->is_real()) |
| 306 | | | { |
| 307 | | | $fill = $aifill; |
| 308 | | | } |
| 309 | | | } |
| 310 | | | |
| 311 | | | if ($this->aiconoutlinecolour != array(-1,-1,-1)) |
| 312 | | | { |
| 313 | | | $ink=$aiink; |
| 314 | | | } |
| 315 | | | |
| 316 | | | if($this->iconfile=='box') |
| 317 | | | { |
| 318 | | | if($fill !== NULL && !$fill->is_none()) |
| 319 | | | { |
| 320 | | | imagefilledrectangle($icon_im, 0, 0, $this->iconscalew-1, $this->iconscaleh-1, $fill->gdallocate($icon_im) ); |
| 321 | | | } |
| 322 | | | |
| 323 | | | if($ink !== NULL && !$ink->is_none()) |
| 324 | | | { |
| 325 | | | imagerectangle($icon_im, 0, 0, $this->iconscalew-1, $this->iconscaleh-1, $ink->gdallocate($icon_im) ); |
| 326 | | | } |
| 327 | | | } |
| 328 | | | |
| 329 | | | if($this->iconfile=='rbox') |
| 330 | | | { |
| 331 | | | if($fill !== NULL && !$fill->is_none()) |
| 332 | | | { |
| 333 | | | imagefilledroundedrectangle($icon_im, 0, 0, $this->iconscalew-1, $this->iconscaleh-1, 4, $fill->gdallocate($icon_im) ); |
| 334 | | | } |
| 335 | | | |
| 336 | | | if($ink !== NULL && !$ink->is_none()) |
| 337 | | | { |
| 338 | | | imageroundedrectangle($icon_im, 0, 0, $this->iconscalew-1, $this->iconscaleh-1, 4, $ink->gdallocate($icon_im) ); |
| 339 | | | } |
| 340 | | | } |
| 341 | | | |
| 342 | | | if($this->iconfile=='round') |
| 343 | | | { |
| 344 | | | $rx = $this->iconscalew/2-1; |
| 345 | | | $ry = $this->iconscaleh/2-1; |
| 346 | | | |
| 347 | | | if($fill !== NULL && !$fill->is_none() ) |
| 348 | | | { |
| 349 | | | imagefilledellipse($icon_im,$rx,$ry,$rx*2,$ry*2,$fill->gdallocate($icon_im) ); |
| 350 | | | } |
| 351 | | | |
| 352 | | | if($ink !== NULL && !$ink->is_none()) |
| 353 | | | { |
| 354 | | | imageellipse($icon_im,$rx,$ry,$rx*2,$ry*2,$ink->gdallocate($icon_im) ); |
| 355 | | | } |
| 356 | | | } |
| 357 | | | |
| 358 | | | if($this->iconfile=='nink') |
| 359 | | | { |
| 360 | | | // print "NINK **************************************************************\n"; |
| 361 | | | $rx = $this->iconscalew/2-1; |
| 362 | | | $ry = $this->iconscaleh/2-1; |
| 363 | | | $size = $this->iconscalew; |
| 364 | | | $quarter = $size/4; |
| 365 | | | |
| 366 | | | $col1 = $this->colours[IN]; |
| 367 | | | $col2 = $this->colours[OUT]; |
| 368 | | | |
| 369 | | | assert('!is_null($col1)'); |
| 370 | | | assert('!is_null($col2)'); |
| 371 | | | |
| 372 | | | imagefilledarc($icon_im, $rx-1, $ry, $size, $size, 270,90, $col1->gdallocate($icon_im), IMG_ARC_PIE); |
| 373 | | | imagefilledarc($icon_im, $rx+1, $ry, $size, $size, 90,270, $col2->gdallocate($icon_im), IMG_ARC_PIE); |
| 374 | | | |
| 375 | | | imagefilledarc($icon_im, $rx-1, $ry+$quarter, $quarter*2, $quarter*2, 0,360, $col1->gdallocate($icon_im), IMG_ARC_PIE); |
| 376 | | | imagefilledarc($icon_im, $rx+1, $ry-$quarter, $quarter*2, $quarter*2, 0,360, $col2->gdallocate($icon_im), IMG_ARC_PIE); |
| 377 | | | |
| 378 | | | if($ink !== NULL && !$ink->is_none()) |
| 379 | | | { |
| 380 | | | // XXX - need a font definition from somewhere for NINK text |
| 381 | | | $font = 1; |
| 382 | | | |
| 383 | | | $instr = $map->ProcessString("{node:this:bandwidth_in:%.1k}",$this); |
| 384 | | | $outstr = $map->ProcessString("{node:this:bandwidth_out:%.1k}",$this); |
| 385 | | | |
| 386 | | | list($twid,$thgt) = $map->myimagestringsize($font,$instr); |
| 387 | | | $map->myimagestring($icon_im, $font, $rx - $twid/2, $ry- $quarter + ($thgt/2),$instr,$ink->gdallocate($icon_im)); |
| 388 | | | |
| 389 | | | list($twid,$thgt) = $map->myimagestringsize($font,$outstr); |
| 390 | | | $map->myimagestring($icon_im, $font, $rx - $twid/2, $ry + $quarter + ($thgt/2),$outstr,$ink->gdallocate($icon_im)); |
| 391 | | | |
| 392 | | | imageellipse($icon_im,$rx,$ry,$rx*2,$ry*2,$ink->gdallocate($icon_im) ); |
| 393 | | | // imagearc($icon_im, $rx,$ry,$quarter*4,$quarter*4, 0,360, $ink->gdallocate($icon_im)); |
| 394 | | | } |
| 395 | | | // print "NINK ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; |
| 396 | | | } |
| 397 | | | |
| 398 | | | // XXX - needs proper colours |
| 399 | | | if($this->iconfile=='inpie' || $this->iconfile=='outpie') |
| 400 | | | { |
| 401 | | | # list($colpie,$node_iconscalekey,$icontag) = $map->NewColourFromPercent($pc, $this->useiconscale,$this->name); |
| 402 | | | |
| 403 | | | if($this->iconfile=='inpie') $segment_angle = (($this->inpercent)/100) * 360; |
| 404 | | | if($this->iconfile=='outpie') $segment_angle = (($this->outpercent)/100) * 360; |
| 405 | | | |
| 406 | | | $rx = $this->iconscalew/2-1; |
| 407 | | | $ry = $this->iconscaleh/2-1; |
| 408 | | | |
| 409 | | | if($fill !== NULL && !$fill->is_none() ) |
| 410 | | | { |
| 411 | | | imagefilledellipse($icon_im, $rx, $ry, $rx*2, $ry*2, $fill->gdallocate($icon_im) ); |
| 412 | | | } |
| 413 | | | |
| 414 | | | if($ink !== NULL && !$ink->is_none()) |
| 415 | | | { |
| 416 | | | // imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style ) |
| 417 | | | imagefilledarc($icon_im, $rx, $ry, $rx*2,$ry*2, 0, $segment_angle, $ink->gdallocate($icon_im) , IMG_ARC_PIE); |
| 418 | | | } |
| 419 | | | |
| 420 | | | if($fill !== NULL && !$fill->is_none() ) |
| 421 | | | { |
| 422 | | | imageellipse($icon_im, $rx, $ry, $rx*2, $ry*2, $fill->gdallocate($icon_im) ); |
| 423 | | | } |
| 424 | | | |
| 425 | | | // warn('inpie AICON not implemented yet [WMWARN99]'); |
| 426 | | | } |
| 427 | | | |
| 428 | | | // if($this->iconfile=='outpie') { warn('outpie AICON not implemented yet [WMWARN99]'); } |
| 429 | | | if($this->iconfile=='gauge') { warn('gauge AICON not implemented yet [WMWARN99]'); } |
| 430 | | | |
| 431 | | | } |
| 432 | | | else |
| 433 | | | { |
| 434 | | | $this->iconfile = $map->ProcessString($this->iconfile ,$this); |
| 435 | | | if (is_readable($this->iconfile)) |
| 436 | | | { |
| 437 | | | imagealphablending($im, true); |
| 438 | | | // draw the supplied icon, instead of the labelled box |
| 439 | | | |
| 440 | | | $icon_im = imagecreatefromfile($this->iconfile); |
| 441 | | | # $icon_im = imagecreatefrompng($this->iconfile); |
| 442 | | | if(function_exists("imagefilter") && isset($colicon) && $this->get_hint("use_imagefilter")==1) |
| 443 | | | { |
| 444 | | | imagefilter($icon_im, IMG_FILTER_COLORIZE, $colicon->r, $colicon->g, $colicon->b); |
| 445 | | | } |
| 446 | | | else |
| 447 | | | { |
| 448 | | | if(isset($colicon)) |
| 449 | | | { |
| 450 | | | // debug("Skipping unavailable imagefilter() call.\n"); |
| 451 | | | imagecolorize($icon_im, $colicon->r, $colicon->g, $colicon->b); |
| 452 | | | } |
| 453 | | | } |
| 454 | | | |
| 455 | | | debug("If this is the last thing in your logs, you probably have a buggy GD library. Get > 2.0.33 or use PHP builtin.\n"); |
| 456 | | | if ($icon_im) |
| 457 | | | { |
| 458 | | | $icon_w = imagesx($icon_im); |
| 459 | | | $icon_h = imagesy($icon_im); |
| 460 | | | |
| 461 | | | if(($this->iconscalew * $this->iconscaleh) > 0) |
| 462 | | | { |
| 463 | | | imagealphablending($icon_im, true); |
| 464 | | | |
| 465 | | | debug("SCALING ICON here\n"); |
| 466 | | | if($icon_w > $icon_h) |
| 467 | | | { |
| 468 | | | $scalefactor = $icon_w/$this->iconscalew; |
| 469 | | | } |
| 470 | | | else |
| 471 | | | { |
| 472 | | | $scalefactor = $icon_h/$this->iconscaleh; |
| 473 | | | } |
| 474 | | | $new_width = $icon_w / $scalefactor; |
| 475 | | | $new_height = $icon_h / $scalefactor; |
| 476 | | | $scaled = imagecreatetruecolor($new_width, $new_height); |
| 477 | | | imagealphablending($scaled,false); |
| 478 | | | imagecopyresampled($scaled, $icon_im, 0, 0, 0, 0, $new_width, $new_height, $icon_w, $icon_h); |
| 479 | | | imagedestroy($icon_im); |
| 480 | | | $icon_im = $scaled; |
| 481 | | | |
| 482 | | | } |
| 483 | | | } |
| 484 | | | else { warn ("Couldn't open ICON: '" . $this->iconfile . "' - is it a PNG, JPEG or GIF? [WMWARN37]\n"); } |
| 485 | | | } |
| 486 | | | else |
| 487 | | | { |
| 488 | | | if($this->iconfile != 'none') |
| 489 | | | { |
| 490 | | | warn ("ICON '" . $this->iconfile . "' does not exist, or is not readable. Check path and permissions. [WMARN38]\n"); |
| 491 | | | } |
| 492 | | | } |
| 493 | | | } |
| 494 | | | |
| 495 | | | if($icon_im) |
| 496 | | | { |
| 497 | | | $icon_w = imagesx($icon_im); |
| 498 | | | $icon_h = imagesy($icon_im); |
| 499 | | | |
| 500 | | | $icon_x1 = $this->x - $icon_w / 2; |
| 501 | | | $icon_y1 = $this->y - $icon_h / 2; |
| 502 | | | $icon_x2 = $this->x + $icon_w / 2; |
| 503 | | | $icon_y2 = $this->y + $icon_h / 2; |
| 504 | | | |
| 505 | | | $map->nodes[$this->name]->width = imagesx($icon_im); |
| 506 | | | $map->nodes[$this->name]->height = imagesy($icon_im); |
| 507 | | | |
| 508 | | | // $map->imap->addArea("Rectangle", "NODE:" . $this->name . ':0', '', array($icon_x1, $icon_y1, $icon_x2, $icon_y2)); |
| 509 | | | $map->nodes[$this->name]->boundingboxes[] = array($icon_x1, $icon_y1, $icon_x2, $icon_y2); |
| 510 | | | } |
| 511 | | | |
| 512 | | | } |
| 513 | | | |
| 514 | | | |
| 515 | | | |
| 516 | | | // do any offset calculations |
| 517 | | | $dx=0; |
| 518 | | | $dy=0; |
| 519 | | | if ( ($this->labeloffset != '') && (($this->iconfile != '')) ) |
| 520 | | | { |
| 521 | | | $this->labeloffsetx = 0; |
| 522 | | | $this->labeloffsety = 0; |
| 523 | | | |
| 524 | | | list($dx, $dy) = calc_offset($this->labeloffset, |
| 525 | | | ($icon_w + $boxwidth -1), |
| 526 | | | ($icon_h + $boxheight) |
| 527 | | | ); |
| 528 | | | |
| 529 | | | #$this->labeloffsetx = $dx; |
| 530 | | | #$this->labeloffsety = $dy; |
| 531 | | | |
| 532 | | | } |
| 533 | | | |
| 534 | | | $label_x1 += ($this->labeloffsetx + $dx); |
| 535 | | | $label_x2 += ($this->labeloffsetx + $dx); |
| 536 | | | $label_y1 += ($this->labeloffsety + $dy); |
| 537 | | | $label_y2 += ($this->labeloffsety + $dy); |
| 538 | | | |
| 539 | | | if($this->label != '') |
| 540 | | | { |
| 541 | | | // $map->imap->addArea("Rectangle", "NODE:" . $this->name .':1', '', array($label_x1, $label_y1, $label_x2, $label_y2)); |
| 542 | | | $map->nodes[$this->name]->boundingboxes[] = array($label_x1, $label_y1, $label_x2, $label_y2); |
| 543 | | | } |
| 544 | | | |
| 545 | | | // work out the bounding box of the whole thing |
| 546 | | | |
| 547 | | | $bbox_x1 = min($label_x1,$icon_x1); |
| 548 | | | $bbox_x2 = max($label_x2,$icon_x2)+1; |
| 549 | | | $bbox_y1 = min($label_y1,$icon_y1); |
| 550 | | | $bbox_y2 = max($label_y2,$icon_y2)+1; |
| 551 | | | |
| 552 | | | # imagerectangle($im,$bbox_x1,$bbox_y1,$bbox_x2,$bbox_y2,$map->selected); |
| 553 | | | # imagerectangle($im,$label_x1,$label_y1,$label_x2,$label_y2,$map->black); |
| 554 | | | # imagerectangle($im,$icon_x1,$icon_y1,$icon_x2,$icon_y2,$map->black); |
| 555 | | | |
| 556 | | | // create TWO imagemap entries - one for the label and one for the icon |
| 557 | | | // (so we can have close-spaced icons better) |
| 558 | | | |
| 559 | | | |
| 560 | | | $temp_width = $bbox_x2-$bbox_x1; |
| 561 | | | $temp_height = $bbox_y2-$bbox_y1; |
| 562 | | | // create an image of that size and draw into it |
| 563 | | | $node_im=imagecreatetruecolor($temp_width,$temp_height ); |
| 564 | | | // ImageAlphaBlending($node_im, FALSE); |
| 565 | | | imageSaveAlpha($node_im, TRUE); |
| 566 | | | |
| 567 | | | $nothing=imagecolorallocatealpha($node_im,128,0,0,127); |
| 568 | | | imagefill($node_im, 0, 0, $nothing); |
| 569 | | | |
| 570 | | | #$col = $col->gdallocate($node_im); |
| 571 | | | |
| 572 | | | // imagefilledrectangle($node_im,0,0,$temp_width,$temp_height, $nothing); |
| 573 | | | |
| 574 | | | $label_x1 -= $bbox_x1; |
| 575 | | | $label_x2 -= $bbox_x1; |
| 576 | | | $label_y1 -= $bbox_y1; |
| 577 | | | $label_y2 -= $bbox_y1; |
| 578 | | | |
| 579 | | | $icon_x1 -= $bbox_x1; |
| 580 | | | $icon_x2 -= $bbox_x1; |
| 581 | | | $icon_y1 -= $bbox_y1; |
| 582 | | | $icon_y2 -= $bbox_y1; |
| 583 | | | |
| 584 | | | |
| 585 | | | // Draw the icon, if any |
| 586 | | | if(isset($icon_im)) |
| 587 | | | { |
| 588 | | | imagecopy($node_im, $icon_im, $icon_x1, $icon_y1, 0, 0, imagesx($icon_im), imagesy($icon_im)); |
| 589 | | | imagedestroy($icon_im); |
| 590 | | | } |
| 591 | | | |
| 592 | | | // Draw the label, if any |
| 593 | | | if ($this->label != '') |
| 594 | | | { |
| 595 | | | $txt_x -= $bbox_x1; |
| 596 | | | $txt_x += ($this->labeloffsetx + $dx); |
| 597 | | | $txt_y -= $bbox_y1; |
| 598 | | | $txt_y += ($this->labeloffsety + $dy); |
| 599 | | | |
| 600 | | | # print "FINAL TEXT at $txt_x , $txt_y\n"; |
| 601 | | | |
| 602 | | | // if there's an icon, then you can choose to have no background |
| 603 | | | |
| 604 | | | if(! $col->is_none() ) |
| 605 | | | { |
| 606 | | | imagefilledrectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $col->gdallocate($node_im)); |
| 607 | | | } |
| 608 | | | |
| 609 | | | if ($this->selected) |
| 610 | | | { |
| 611 | | | imagerectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $map->selected); |
| 612 | | | // would be nice if it was thicker, too... |
| 613 | | | wimagerectangle($node_im, $label_x1 + 1, $label_y1 + 1, $label_x2 - 1, $label_y2 - 1, $map->selected); |
| 614 | | | } |
| 615 | | | else |
| 616 | | | { |
| 617 | | | $olcol = new Colour($this->labeloutlinecolour); |
| 618 | | | if ($olcol->is_real()) |
| 619 | | | { |
| 620 | | | imagerectangle($node_im, $label_x1, $label_y1, $label_x2, $label_y2, $olcol->gdallocate($node_im)); |
| 621 | | | } |
| 622 | | | } |
| 623 | | | #} |
| 624 | | | |
| 625 | | | $shcol = new Colour($this->labelfontshadowcolour); |
| 626 | | | if ($shcol->is_real()) |
| 627 | | | { |
| 628 | | | $map->myimagestring($node_im, $this->labelfont, $txt_x + 1, $txt_y + 1, $this->proclabel, $shcol->gdallocate($node_im),$this->labelangle); |
| 629 | | | } |
| 630 | | | |
| 631 | | | $txcol = new Colour($this->labelfontcolour[0],$this->labelfontcolour[1],$this->labelfontcolour[2]); |
| 632 | | | #$col=myimagecolorallocate($node_im, $this->labelfontcolour[0], $this->labelfontcolour[1], |
| 633 | | | # $this->labelfontcolour[2]); |
| 634 | | | if($txcol->is_contrast()) |
| 635 | | | { |
| 636 | | | if($col->is_real()) |
| 637 | | | { |
| 638 | | | $txcol = $col->contrast(); |
| 639 | | | } |
| 640 | | | else |
| 641 | | | { |
| 642 | | | warn("You can't make a contrast with 'none'. [WMWARN43]\n"); |
| 643 | | | $txcol = new Colour(0,0,0); |
| 644 | | | } |
| 645 | | | } |
| 646 | | | $map->myimagestring($node_im, $this->labelfont, $txt_x, $txt_y, $this->proclabel, $txcol->gdallocate($node_im),$this->labelangle); |
| 647 | | | //$map->myimagestring($node_im, $this->labelfont, $txt_x, $txt_y, $this->proclabel, $txcol->gdallocate($node_im),90); |
| 648 | | | } |
| 649 | | | |
| 650 | | | # imagerectangle($node_im,$label_x1,$label_y1,$label_x2,$label_y2,$map->black); |
| 651 | | | # imagerectangle($node_im,$icon_x1,$icon_y1,$icon_x2,$icon_y2,$map->black); |
| 652 | | | |
| 653 | | | $map->nodes[$this->name]->centre_x = $this->x - $bbox_x1; |
| 654 | | | $map->nodes[$this->name]->centre_y = $this->y - $bbox_y1; |
| 655 | | | |
| 656 | | | if(1==0) |
| 657 | | | { |
| 658 | | | |
| 659 | | | imageellipse($node_im, $this->centre_x, $this->centre_y, 8, 8, $map->selected); |
| 660 | | | |
| 661 | | | foreach (array("N","S","E","W","NE","NW","SE","SW") as $corner) |
| 662 | | | { |
| 663 | | | list($dx, $dy)=calc_offset($corner, $this->width, $this->height); |
| 664 | | | imageellipse($node_im, $this->centre_x + $dx, $this->centre_y + $dy, 5, 5, $map->selected); |
| 665 | | | } |
| 666 | | | } |
| 667 | | | |
| 668 | | | # $this->image = $node_im; |
| 669 | | | $map->nodes[$this->name]->image = $node_im; |
| 670 | | | } |
| 671 | | | |
| 672 | | | function update_cache($cachedir,$mapname) |
| 673 | | | { |
| 674 | | | $cachename = $cachedir."/node_".md5($mapname."/".$this->name).".png"; |
| 675 | | | // save this image to a cache, for the editor |
| 676 | | | imagepng($this->image,$cachename); |
| 677 | | | } |
| 678 | | | |
| 679 | | | // draw the node, using the pre_render() output |
| 680 | | | function NewDraw($im, &$map) |
| 681 | | | { |
| 682 | | | // take the offset we figured out earlier, and just blit |
| 683 | | | // the image on. Who says "blit" anymore? |
| 684 | | | |
| 685 | | | // it's possible that there is no image, so better check. |
| 686 | | | if(isset($this->image)) |
| 687 | | | { |
| 688 | | | imagealphablending($im, true); |
| 689 | | | imagecopy ( $im, $this->image, $this->x - $this->centre_x, $this->y - $this->centre_y, 0, 0, imagesx($this->image), imagesy($this->image) ); |
| 690 | | | } |
| 691 | | | |
| 692 | | | } |
| 693 | | | |
| 694 | | | // take the pre-rendered node and write it to a file so that |
| 695 | | | // the editor can get at it. |
| 696 | | | function WriteToCache() |
| 697 | | | { |
| 698 | | | } |
| 699 | | | |
| 700 | | | function Reset(&$newowner) |
| 701 | | | { |
| 702 | | | $this->owner=$newowner; |
| 703 | | | $template = $this->template; |
| 704 | | | |
| 705 | | | if($template == '') $template = "DEFAULT"; |
| 706 | | | |
| 707 | | | debug("Resetting $this->name with $template\n"); |
| 708 | | | |
| 709 | | | // the internal default-default gets it's values from inherit_fieldlist |
| 710 | | | // everything else comes from a node object - the template. |
| 711 | | | if($this->name==':: DEFAULT ::') |
| 712 | | | { |
| 713 | | | foreach (array_keys($this->inherit_fieldlist)as |
| 714 | | | $fld) { $this->$fld=$this->inherit_fieldlist[$fld]; } |
| 715 | | | } |
| 716 | | | else |
| 717 | | | { |
| 718 | | | $this->CopyFrom($this->owner->nodes[$template]); |
| 719 | | | } |
| 720 | | | $this->template = $template; |
| 721 | | | |
| 722 | | | // to stop the editor tanking, now that colours are decided earlier in ReadData |
| 723 | | | $this->colours[IN] = new Colour(192,192,192); |
| 724 | | | $this->colours[OUT] = new Colour(192,192,192); |
| 725 | | | |
| 726 | | | $this->id = $newowner->next_id++; |
| 727 | | | } |
| 728 | | | |
| 729 | | | function CopyFrom(&$source) |
| 730 | | | { |
| 731 | | | debug("Initialising NODE $this->name from $source->name\n"); |
| 732 | | | assert('is_object($source)'); |
| 733 | | | |
| 734 | | | foreach (array_keys($this->inherit_fieldlist)as $fld) { |
| 735 | | | if($fld != 'template') $this->$fld=$source->$fld; |
| 736 | | | } |
| 737 | | | } |
| 738 | | | |
| 739 | | | function WriteConfig() |
| 740 | | | { |
| 741 | | | $output=''; |
| 742 | | | |
| 743 | | | # $output .= "# ID ".$this->id." - first seen in ".$this->defined_in."\n"; |
| 744 | | | |
| 745 | | | // This allows the editor to wholesale-replace a single node's configuration |
| 746 | | | // at write-time - it should include the leading NODE xyz line (to allow for renaming) |
| 747 | | | if($this->config_override != '') |
| 748 | | | { |
| 749 | | | $output = $this->config_override."\n"; |
| 750 | | | } |
| 751 | | | else |
| 752 | | | { |
| 753 | | | # $defdef = $this->owner->defaultnode; |
| 754 | | | $dd = $this->owner->nodes[$this->template]; |
| 755 | | | |
| 756 | | | debug("Writing config for NODE $this->name against $this->template\n"); |
| 757 | | | |
| 758 | | | # $field = 'zorder'; $keyword = 'ZORDER'; |
| 759 | | | $basic_params = array( |
| 760 | | | # array('template','TEMPLATE',CONFIG_TYPE_LITERAL), |
| 761 | | | array('label','LABEL',CONFIG_TYPE_LITERAL), |
| 762 | | | array('zorder','ZORDER',CONFIG_TYPE_LITERAL), |
| 763 | | | array('labeloffset','LABELOFFSET',CONFIG_TYPE_LITERAL), |
| 764 | | | array('labelfont','LABELFONT',CONFIG_TYPE_LITERAL), |
| 765 | | | array('labelangle','LABELANGLE',CONFIG_TYPE_LITERAL), |
| 766 | | | array('overlibwidth','OVERLIBWIDTH',CONFIG_TYPE_LITERAL), |
| 767 | | | array('overlibheight','OVERLIBHEIGHT',CONFIG_TYPE_LITERAL), |
| 768 | | | |
| 769 | | | array('aiconoutlinecolour','AICONOUTLINECOLOR',CONFIG_TYPE_COLOR), |
| 770 | | | array('aiconfillcolour','AICONFILLCOLOR',CONFIG_TYPE_COLOR), |
| 771 | | | array('labeloutlinecolour','LABELOUTLINECOLOR',CONFIG_TYPE_COLOR), |
| 772 | | | array('labelfontshadowcolour','LABELFONTSHADOWCOLOR',CONFIG_TYPE_COLOR), |
| 773 | | | array('labelbgcolour','LABELBGCOLOR',CONFIG_TYPE_COLOR), |
| 774 | | | array('labelfontcolour','LABELFONTCOLOR',CONFIG_TYPE_COLOR) |
| 775 | | | ); |
| 776 | | | |
| 777 | | | # TEMPLATE must come first. DEFAULT |
| 778 | | | if($this->template != 'DEFAULT' && $this->template != ':: DEFAULT ::') |
| 779 | | | { |
| 780 | | | $output.="\tTEMPLATE " . $this->template . "\n"; |
| 781 | | | } |
| 782 | | | |
| 783 | | | foreach ($basic_params as $param) |
| 784 | | | { |
| 785 | | | $field = $param[0]; |
| 786 | | | $keyword = $param[1]; |
| 787 | | | |
| 788 | | | # $comparison=($this->name == 'DEFAULT' ? $this->inherit_fieldlist[$field] : $defdef->$field); |
| 789 | | | if ($this->$field != $dd->$field) |
| 790 | | | { |
| 791 | | | if($param[2] == CONFIG_TYPE_COLOR) $output.="\t$keyword " . render_colour($this->$field) . "\n"; |
| 792 | | | if($param[2] == CONFIG_TYPE_LITERAL) $output.="\t$keyword " . $this->$field . "\n"; |
| 793 | | | } |
| 794 | | | } |
| 795 | | | |
| 796 | | | // IN/OUT are the same, so we can use the simpler form here |
| 797 | | | # print_r($this->infourl); |
| 798 | | | #$comparison=($this->name == 'DEFAULT' |
| 799 | | | #? $this->inherit_fieldlist['infourl'][IN] : $defdef->infourl[IN]); |
| 800 | | | if ($this->infourl[IN] != $dd->infourl[IN]) { $output.="\tINFOURL " . $this->infourl[IN] . "\n"; } |
| 801 | | | |
| 802 | | | #$comparison=($this->name == 'DEFAULT' |
| 803 | | | #? $this->inherit_fieldlist['overlibcaption'][IN] : $defdef->overlibcaption[IN]); |
| 804 | | | if ($this->overlibcaption[IN] != $dd->overlibcaption[IN]) { $output.="\tOVERLIBCAPTION " . $this->overlibcaption[IN] . "\n"; } |
| 805 | | | |
| 806 | | | // IN/OUT are the same, so we can use the simpler form here |
| 807 | | | # $comparison=($this->name == 'DEFAULT' |
| 808 | | | # ? $this->inherit_fieldlist['notestext'][IN] : $defdef->notestext[IN]); |
| 809 | | | if ($this->notestext[IN] != $dd->notestext[IN]) { $output.="\tNOTES " . $this->notestext[IN] . "\n"; } |
| 810 | | | |
| 811 | | | # $comparison=($this->name == 'DEFAULT' |
| 812 | | | # ? $this->inherit_fieldlist['overliburl'][IN] : $defdef->overliburl[IN]); |
| 813 | | | if ($this->overliburl[IN] != $dd->overliburl[IN]) { $output.="\tOVERLIBGRAPH " . join(" ",$this->overliburl[IN]) . "\n"; } |
| 814 | | | |
| 815 | | | $val = $this->iconscalew. " " . $this->iconscaleh. " " .$this->iconfile; |
| 816 | | | |
| 817 | | | $comparison = $dd->iconscalew. " " . $dd->iconscaleh . " " . $dd->iconfile; |
| 818 | | | |
| 819 | | | if ($val != $comparison) { |
| 820 | | | $output.="\tICON "; |
| 821 | | | if($this->iconscalew > 0) { |
| 822 | | | $output .= $this->iconscalew." ".$this->iconscaleh." "; |
| 823 | | | } |
| 824 | | | $output .= ($this->iconfile=='' ? 'none' : $this->iconfile) . "\n"; |
| 825 | | | } |
| 826 | | | |
| 827 | | | # $comparison=($this->name == 'DEFAULT' |
| 828 | | | # ? $this->inherit_fieldlist['targets'] : $defdef->targets); |
| 829 | | | |
| 830 | | | if ($this->targets != $dd->targets) |
| 831 | | | { |
| 832 | | | $output.="\tTARGET"; |
| 833 | | | |
| 834 | | | foreach ($this->targets as $target) { |
| 835 | | | if(strpos($target[4]," ") == FALSE) |
| 836 | | | { |
| 837 | | | $output.=" " . $target[4]; |
| 838 | | | } |
| 839 | | | else |
| 840 | | | { |
| 841 | | | $output.=' "' . $target[4].'"'; |
| 842 | | | } |
| 843 | | | } |
| 844 | | | |
| 845 | | | |
| 846 | | | $output.="\n"; |
| 847 | | | } |
| 848 | | | |
| 849 | | | # $comparison = ($this->name == 'DEFAULT' ? $this->inherit_fieldlist['usescale'] : $defdef->usescale) . " " . |
| 850 | | | # ($this->name == 'DEFAULT' ? $this->inherit_fieldlist['scalevar'] : $defdef->scalevar); |
| 851 | | | $val = $this->usescale . " " . $this->scalevar; |
| 852 | | | $comparison = $dd->usescale . " " . $dd->scalevar; |
| 853 | | | |
| 854 | | | if ( ($val != $comparison) ) { $output.="\tUSESCALE " . $val . "\n"; } |
| 855 | | | |
| 856 | | | # $comparison = ($this->name == 'DEFAULT' |
| 857 | | | # ? $this->inherit_fieldlist['useiconscale'] : $defdef->useiconscale) . " " . |
| 858 | | | # ($this->name == 'DEFAULT' ? $this->inherit_fieldlist['iconscalevar'] : $defdef->iconscalevar); |
| 859 | | | $val = $this->useiconscale . " " . $this->iconscalevar; |
| 860 | | | $comparison= $dd->useiconscale . " " . $dd->iconscalevar; |
| 861 | | | |
| 862 | | | if ( $val != $comparison) { $output.="\tUSEICONSCALE " .$val . "\n"; } |
| 863 | | | |
| 864 | | | #$comparison = ($this->name == 'DEFAULT' |
| 865 | | | #? $this->inherit_fieldlist['labeloffsetx'] : $defdef->labeloffsetx) . " " . ($this->name == 'DEFAULT' |
| 866 | | | # ? $this->inherit_fieldlist['labeloffsety'] : $defdef->labeloffsety); |
| 867 | | | $val = $this->labeloffsetx . " " . $this->labeloffsety; |
| 868 | | | $comparison = $dd->labeloffsetx . " " . $dd->labeloffsety; |
| 869 | | | |
| 870 | | | if ($comparison != $val ) { $output.="\tLABELOFFSET " . $val . "\n"; } |
| 871 | | | |
| 872 | | | #$comparison=($this->name == 'DEFAULT' ? $this->inherit_fieldlist['x'] : $defdef->x) . " " . |
| 873 | | | # ($this->name == 'DEFAULT' ? $this->inherit_fieldlist['y'] : $defdef->y); |
| 874 | | | $val = $this->x . " " . $this->y; |
| 875 | | | $comparison = $dd->x . " " . $dd->y; |
| 876 | | | |
| 877 | | | if ($val != $comparison) |
| 878 | | | { |
| 879 | | | if($this->relative_to == '') |
| 880 | | | { $output.="\tPOSITION " . $val . "\n"; } |
| 881 | | | else |
| 882 | | | { |
| 883 | | | if($this->polar) |
| 884 | | | { |
| 885 | | | $output .= "\tPOSITION ".$this->relative_to . " " . $this->original_x . "r" . $this->original_y . "\n"; |
| 886 | | | } |
| 887 | | | else |
| 888 | | | { |
| 889 | | | $output.="\tPOSITION " . $this->relative_to . " " . $this->original_x . " " . $this->original_y . "\n"; |
| 890 | | | } |
| 891 | | | } |
| 892 | | | } |
| 893 | | | |
| 894 | | | if (($this->max_bandwidth_in != $dd->max_bandwidth_in) |
| 895 | | | || ($this->max_bandwidth_out != $dd->max_bandwidth_out) |
| 896 | | | || ($this->name == 'DEFAULT')) |
| 897 | | | { |
| 898 | | | if ($this->max_bandwidth_in == $this->max_bandwidth_out) |
| 899 | | | { $output.="\tMAXVALUE " . $this->max_bandwidth_in_cfg . "\n"; } |
| 900 | | | else { $output |
| 901 | | | .="\tMAXVALUE " . $this->max_bandwidth_in_cfg . " " . $this->max_bandwidth_out_cfg . "\n"; } |
| 902 | | | } |
| 903 | | | |
| 904 | | | foreach ($this->hints as $hintname=>$hint) |
| 905 | | | { |
| 906 | | | // all hints for DEFAULT node are for writing |
| 907 | | | // only changed ones, or unique ones, otherwise |
| 908 | | | if( |
| 909 | | | ($this->name == 'DEFAULT') |
| 910 | | | || |
| 911 | | | (isset($dd->hints[$hintname]) |
| 912 | | | && |
| 913 | | | $dd->hints[$hintname] != $hint) |
| 914 | | | || |
| 915 | | | (!isset($dd->hints[$hintname])) |
| 916 | | | ) |
| 917 | | | { |
| 918 | | | $output .= "\tSET $hintname $hint\n"; |
| 919 | | | } |
| 920 | | | } |
| 921 | | | if ($output != '') |
| 922 | | | { |
| 923 | | | $output = "NODE " . $this->name . "\n$output\n"; |
| 924 | | | } |
| 925 | | | } |
| 926 | | | return ($output); |
| 927 | | | } |
| 928 | | | |
| 929 | | | function asJS() |
| 930 | | | { |
| 931 | | | $js = ''; |
| 932 | | | $js .= "Nodes[" . js_escape($this->name) . "] = {"; |
| 933 | | | $js .= "x:" . (is_null($this->x)? "'null'" : $this->x) . ", "; |
| 934 | | | $js .= "y:" . (is_null($this->y)? "'null'" : $this->y) . ", "; |
| 935 | | | $js .= "\"id\":" . $this->id. ", "; |
| 936 | | | // $js.="y:" . $this->y . ", "; |
| 937 | | | $js.="ox:" . $this->original_x . ", "; |
| 938 | | | $js.="oy:" . $this->original_y . ", "; |
| 939 | | | $js.="relative_to:" . js_escape($this->relative_to) . ", "; |
| 940 | | | $js.="label:" . js_escape($this->label) . ", "; |
| 941 | | | $js.="name:" . js_escape($this->name) . ", "; |
| 942 | | | $js.="infourl:" . js_escape($this->infourl[IN]) . ", "; |
| 943 | | | $js.="overlibcaption:" . js_escape($this->overlibcaption[IN]) . ", "; |
| 944 | | | $js.="overliburl:" . js_escape(join(" ",$this->overliburl[IN])) . ", "; |
| 945 | | | $js.="overlibwidth:" . $this->overlibheight . ", "; |
| 946 | | | $js.="overlibheight:" . $this->overlibwidth . ", "; |
| 947 | | | if(preg_match("/^(none|nink|inpie|outpie|box|rbox|gauge|round)$/",$this->iconfile)) |
| 948 | | | { |
| 949 | | | $js.="iconfile:" . js_escape("::".$this->iconfile); |
| 950 | | | } |
| 951 | | | else |
| 952 | | | { |
| 953 | | | $js.="iconfile:" . js_escape($this->iconfile); |
| 954 | | | } |
| 955 | | | |
| 956 | | | $js .= "};\n"; |
| 957 | | | $js .= "NodeIDs[\"N" . $this->id . "\"] = ". js_escape($this->name) . ";\n"; |
| 958 | | | return $js; |
| 959 | | | } |
| 960 | | | |
| 961 | | | function asJSON($complete=TRUE) |
| 962 | | | { |
| 963 | | | $js = ''; |
| 964 | | | $js .= "" . js_escape($this->name) . ": {"; |
| 965 | | | $js .= "\"id\":" . $this->id. ", "; |
| 966 | | | $js .= "\"x\":" . ($this->x - $this->centre_x). ", "; |
| 967 | | | $js .= "\"y\":" . ($this->y - $this->centre_y) . ", "; |
| 968 | | | $js .= "\"cx\":" . $this->centre_x. ", "; |
| 969 | | | $js .= "\"cy\":" . $this->centre_y . ", "; |
| 970 | | | $js .= "\"ox\":" . $this->original_x . ", "; |
| 971 | | | $js .= "\"oy\":" . $this->original_y . ", "; |
| 972 | | | $js .= "\"relative_to\":" . js_escape($this->relative_to) . ", "; |
| 973 | | | $js .= "\"name\":" . js_escape($this->name) . ", "; |
| 974 | | | if($complete) |
| 975 | | | { |
| 976 | | | $js .= "\"label\":" . js_escape($this->label) . ", "; |
| 977 | | | $js .= "\"infourl\":" . js_escape($this->infourl) . ", "; |
| 978 | | | $js .= "\"overliburl\":" . js_escape($this->overliburl) . ", "; |
| 979 | | | $js .= "\"overlibcaption\":" . js_escape($this->overlibcaption) . ", "; |
| 980 | | | |
| 981 | | | $js .= "\"overlibwidth\":" . $this->overlibheight . ", "; |
| 982 | | | $js .= "\"overlibheight\":" . $this->overlibwidth . ", "; |
| 983 | | | $js .= "\"iconfile\":" . js_escape($this->iconfile). ", "; |
| 984 | | | } |
| 985 | | | $js .= "\"iconcachefile\":" . js_escape($this->cachefile); |
| 986 | | | $js .= "},\n"; |
| 987 | | | return $js; |
| 988 | | | } |
| 989 | | | }; |
| 990 | | | |
| 991 | | | // vim:ts=4:sw=4: |
| 992 | | | ?> |