public function testStringHandling() { $this->assertEquals('"1"', WMUtility::jsEscape("1")); $this->assertEquals('"2\\\\2"', WMUtility::jsEscape("2\\2")); $this->assertEquals('"\\"a quote\\""', WMUtility::jsEscape('"a quote"')); $this->assertEquals('xxx xxx is 127.0.0.1 xxxxx', WMUtility::stringAnonymise("the DNS is 8.8.8.8 right")); $this->assertEquals('xxx xxx is 127.0.0.1', WMUtility::stringAnonymise("the DNS is 8.8.8.8")); $this->assertEquals('127.0.0.1 is xxx xxx xxx 127.0.0.1', WMUtility::stringAnonymise("8.8.8.8 is the DNS not 8.8.4.4")); $this->assertEquals('127.0.0.1', WMUtility::stringAnonymise("8.8.8.8")); $this->assertEquals('a bb xxx xxxx xxxxx', WMUtility::stringAnonymise("a bb ccc dddd eeeee")); }
function asJSCore() { $output = ""; $output .= "\"id\":" . $this->id . ", "; if (isset($this->a)) { $output .= "a:'" . $this->a->name . "', "; $output .= "b:'" . $this->b->name . "', "; } $output .= "width:'" . $this->width . "', "; $output .= "target:"; $tgt = ''; $i = 0; foreach ($this->targets as $target) { if ($i > 0) { print " "; } $tgt .= $target->asConfig(); $i++; } $output .= WMUtility::jsEscape(trim($tgt)); $output .= ","; $output .= "bw_in:" . WMUtility::jsEscape($this->max_bandwidth_in_cfg) . ", "; $output .= "bw_out:" . WMUtility::jsEscape($this->max_bandwidth_out_cfg) . ", "; $output .= "name:" . WMUtility::jsEscape($this->name) . ", "; $output .= "overlibwidth:'" . $this->overlibheight . "', "; $output .= "overlibheight:'" . $this->overlibwidth . "', "; $output .= "overlibcaption:" . WMUtility::jsEscape($this->overlibcaption[IN]) . ", "; $output .= "commentin:" . WMUtility::jsEscape($this->comments[IN]) . ", "; $output .= "commentposin:" . intval($this->commentoffset_in) . ", "; $output .= "commentout:" . WMUtility::jsEscape($this->comments[OUT]) . ", "; $output .= "commentposout:" . intval($this->commentoffset_out) . ", "; $output .= "infourl:" . WMUtility::jsEscape($this->infourl[IN]) . ", "; $output .= "overliburl:" . WMUtility::jsEscape(join(" ", $this->overliburl[IN])) . ", "; $output .= "via: ["; $nItem = 0; foreach ($this->vialist as $via) { if ($nItem > 0) { $output .= ", "; } $output .= sprintf("[%d,%d", $via[0], $via[1]); if (isset($via[2])) { $output .= "," . WMUtility::jsEscape($via[2]); } $output .= "]"; $nItem++; } $output .= "]"; return $output; }
function asJSCore() { $output = ""; $output .= "x:" . (is_null($this->x) ? "'null'" : $this->x) . ", "; $output .= "y:" . (is_null($this->y) ? "'null'" : $this->y) . ", "; $output .= "\"id\":" . $this->id . ", "; $output .= "ox:" . $this->original_x . ", "; $output .= "oy:" . $this->original_y . ", "; $output .= "relative_to:" . WMUtility::jsEscape($this->relative_to) . ", "; $output .= "label:" . WMUtility::jsEscape($this->label) . ", "; $output .= "name:" . WMUtility::jsEscape($this->name) . ", "; $output .= "infourl:" . WMUtility::jsEscape($this->infourl[IN]) . ", "; $output .= "overlibcaption:" . WMUtility::jsEscape($this->overlibcaption[IN]) . ", "; $output .= "overliburl:" . WMUtility::jsEscape(join(" ", $this->overliburl[IN])) . ", "; $output .= "overlibwidth:" . $this->overlibheight . ", "; $output .= "overlibheight:" . $this->overlibwidth . ", "; if (sizeof($this->boundingboxes) > 0) { $output .= sprintf("bbox:[%d,%d, %d,%d], ", $this->boundingboxes[0][0], $this->boundingboxes[0][1], $this->boundingboxes[0][2], $this->boundingboxes[0][3]); } else { $output .= "bbox: [], "; } if (preg_match("/^(none|nink|inpie|outpie|box|rbox|gauge|round)\$/", $this->iconfile)) { $output .= "iconfile:" . WMUtility::jsEscape("::" . $this->iconfile); } else { $output .= "iconfile:" . WMUtility::jsEscape($this->iconfile); } return $output; }
protected function asJS($type = "Thing", $prefix = "T") { $output = ''; $output .= $type . "s[" . WMUtility::jsEscape($this->name) . "] = {"; $output .= $this->asJSCore(); $output .= "};\n"; $output .= $type . "IDs[\"" . $prefix . $this->id . "\"] = " . WMUtility::jsEscape($this->name) . ";\n"; return $output; }
function asJS() { $javascript = ''; $javascript .= "var Links = new Array();\n"; $javascript .= "var LinkIDs = new Array();\n"; foreach ($this->links as $link) { $javascript .= $link->asJS(); } $javascript .= "var Nodes = new Array();\n"; $javascript .= "var NodeIDs = new Array();\n"; foreach ($this->nodes as $node) { $javascript .= $node->asJS(); } $mapName = array_pop(explode("/", $this->configfile)); $javascript .= "var Map = {\n"; $javascript .= sprintf(' "file": %s,', WMUtility::jsEscape($mapName)); $javascript .= sprintf(' "width": %s,', WMUtility::jsEscape($this->width)); $javascript .= sprintf(' "height": %s,', WMUtility::jsEscape($this->height)); $javascript .= sprintf(' "title": %s,', WMUtility::jsEscape($this->title)); $javascript .= "\n};\n"; return $javascript; }