/** * Method send * * @param string $raw_text * * @return string $return_text */ public function send($raw_text) { if (!empty($raw_text)) { $this->raw_text = $raw_text; $xw = new xmlWriter(); $xw->openMemory(); $xw->startDocument('1.0'); $xw->startElement('wordsegmentation'); $xw->writeAttribute('version', '0.1'); $xw->startElement('option'); $xw->writeAttribute('showcategory', '1'); $xw->endElement(); $xw->startElement('authentication'); $xw->writeAttribute('username', $this->username); $xw->writeAttribute('password', $this->password); $xw->endElement(); $xw->startElement('text'); $xw->writeRaw($this->raw_text); $xw->endElement(); $xw->endElement(); $message = iconv("utf-8", "big5", $xw->outputMemory(true)); //send message to CKIP server set_time_limit(60); $protocol = getprotobyname("tcp"); $socket = socket_create(AF_INET, SOCK_STREAM, $protocol); socket_connect($socket, $this->server_ip, $this->server_port); socket_write($socket, $message); $this->return_text = iconv("big5", "utf-8", socket_read($socket, strlen($message) * 3)); socket_shutdown($socket); socket_close($socket); } return $this->return_text; }
/** * Serializes an NimbleResult Collection to XML * @return string XML */ public function build_collection_xml() { $x = new xmlWriter(); $x->openMemory(); $x->startDocument('1.0', 'UTF-8'); if ($this->single) { $x->startElement(strtolower(get_class($this->collection))); $x->writeRaw($this->build_record_xml($this->collection)); } else { $x->startElement(Inflector::pluralize(strtolower(get_class($this->collection->first())))); foreach ($this->collection as $obj) { $x->startElement(strtolower(get_class($this->collection->first()))); $x->writeRaw($this->build_record_xml($obj)); $x->endElement(); } } $x->endElement(); $xml = $x->outputMemory(true); unset($x); return $xml; }
public function to_xml($options = array()) { $klass = $this->array[0]->class_name(); $plural = \Inflector::pluralize($klass); $xw = new \xmlWriter(); $xw->openMemory(); $xw->startDocument('1.0', 'UTF-8'); $xw->startElement(strtolower($plural)); foreach ($this->array as $value) { $xw->startElement(strtolower($klass)); $xw->writeRaw($value->to_xml(false)); $xw->endElement(); } $xw->endElement(); $xw->endDtd(); return $xw->outputMemory(true); }
/** * Construye un tag xhtml * * @param string $tag nombre de etiqueta * @param array $attrs atributos para la etiqueta * * content: contenido, este parametro con nombre es incluido debido a que * el argumento $content puede ser confundido con un parametro con nombre, * si este llegase a poseer la sintaxis de los parametros con nombre. * * Nota: el parametro con nombre content nunca es utilizado como un atributo * para el tag, a menos de que este se pase en el array de atributos. * * @return string **/ function xhtml_tag($tag, $attrs = null) { $params = is_array($tag) ? $tag : Util::getParams(func_get_args()); $xw = new xmlWriter(); $xw->openMemory(); if (APP_CHARSET != 'UTF-8' && APP_CHARSET != 'ISO-8859-1') { $params = utf8_encode($params); } /** * Pueden tener cierre corto **/ $short_close = array('input', 'link', 'img'); /** * Necesitan estar entre CDATA **/ $need_cdata = array('script', 'style', 'a'); $tag = $params[0]; unset($params[0]); /** * Cargo el contenido interno para el tag */ if (isset($params['content'])) { $content = $params['content']; unset($params['content']); } else { $content = ''; } if (isset($params[1]) && is_array($params[1])) { $attrs = $params[1]; unset($params[1]); $attrs = array_merge($attrs, $params); } else { $attrs = $params; } $xw->startElement($tag); foreach ($attrs as $k => $v) { if (!is_numeric($k)) { @$xw->writeAttribute($k, $v); } } if ($content || !in_array($tag, $short_close)) { if ($tag == 'select' || in_array($tag, $need_cdata)) { $xw->writeRaw($content); } else { $xw->text($content); } } $xw->endElement(); return $xw->outputMemory(true); }
function send() { //test_msg('send ckip', $this->rawText); $xw = new xmlWriter(); $xw->openMemory(); $xw->startDocument('1.0'); $xw->startElement('wordsegmentation'); $xw->writeAttribute('version', '0.1'); $xw->startElement('option'); $xw->writeAttribute('showcategory', '1'); $xw->endElement(); $xw->startElement('authentication'); $xw->writeAttribute('username', $this->username); $xw->writeAttribute('password', $this->password); $xw->endElement(); $xw->startElement('text'); $xw->writeRaw($this->rawText); $xw->endElement(); $xw->endElement(); @($message = iconv("utf-8", "big5", $xw->outputMemory(true))); //send message to CKIP server set_time_limit(60); try { $protocol = getprotobyname("tcp"); $socket = socket_create(AF_INET, SOCK_STREAM, $protocol); @socket_connect($socket, $this->serverIP, $this->serverPort); @socket_write($socket, $message); //$this->returnText = socket_read($socket,strlen($message)*3); @($this->returnText = iconv("big5", "utf-8", socket_read($socket, strlen($message) * 3))); @socket_shutdown($socket); @socket_close($socket); } catch (Exception $e) { //大不了就不斷詞嘛,跩什麼 } }
public function getRoutersClients() { header('Content-type: text/xml'); $xw = new xmlWriter(); $xw->openMemory(); $xw->startDocument('1.0', 'UTF-8'); $xw->startElement('kml'); $xw->writeAttribute('xmlns', 'http://earth.google.com/kml/2.1'); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_client-pushpin-1'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>1.0</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_1.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_client-pushpin-2'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>1.0</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_2.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_client-pushpin-3'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>1.0</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_3.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_client-pushpin-4'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>1.0</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_4.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_client-pushpin-5'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>1.0</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_5.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_client-pushpin-6'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>1.0</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/clients_2_6.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_blue-pushpin'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>0.5</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_highlighted.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('ListStyle'); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_ip_online_highlighted_pushpin'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>0.5</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_online_highlighted_1.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('ListStyle'); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_red-pushpin'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>0.5</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_offline.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('ListStyle'); $xw->endElement(); $xw->startElement('Style'); $xw->writeAttribute('id', 'sh_yellow-pushpin'); $xw->startElement('IconStyle'); $xw->writeRaw('<scale>0.5</scale>'); $xw->startElement('Icon'); $xw->writeRaw('<href>' . $GLOBALS['url_to_netmon'] . '/templates/' . $GLOBALS['template'] . '/img/ffmap/ip_unknown.png</href>'); $xw->endElement(); $xw->endElement(); $xw->endElement(); $xw->startElement('ListStyle'); $xw->endElement(); $xw->startElement('Folder'); $xw->startElement('name'); $xw->writeRaw('create'); $xw->endElement(); $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle(); $crawl_routers = Router_old::getCrawlRoutersByCrawlCycleId($last_endet_crawl_cycle['id']); foreach ($crawl_routers as $crawl_router) { $router_data = Router_old::getRouterInfo($crawl_router['router_id']); $crawl_interfaces = Interfaces::getInterfacesCrawlByCrawlCycle($last_endet_crawl_cycle['id'], $crawl_router['router_id']); $row['traffic'] = 0; foreach ($crawl_interfaces as $interface) { $traffic = $traffic + $interface['traffic_rx_avg'] + $interface['traffic_tx_avg']; } $traffic = round($traffic / 1024, 2); //Make coordinates and location information if (!empty($crawl_router['longitude']) and !empty($crawl_router['latitude'])) { $longitude = $crawl_router['longitude']; $latitude = $crawl_router['latitude']; $location = $crawl_router['location']; $do = true; } elseif (!empty($router_data['longitude']) and !empty($router_data['latitude'])) { $longitude = $router_data['longitude']; $latitude = $router_data['latitude']; $location = $router_data['location']; $do = true; } else { $do = false; } if ($do) { $xw->startElement('Placemark'); $xw->startElement('name'); $xw->writeRaw("<![CDATA[Router <a href='" . $GLOBALS['url_to_netmon'] . "/router.php?router_id=" . $router_data['router_id'] . "'>" . $router_data['hostname'] . "</a>]]>"); $xw->endElement(); $xw->startElement('description'); $box_inhalt = "Clients"; $xw->writeRaw("<![CDATA[{$box_inhalt}]]>"); $xw->endElement(); $xw->startElement('styleUrl'); if ($crawl_router['client_count'] == 0) { $xw->writeRaw('#sh_client-pushpin-0'); } elseif ($crawl_router['client_count'] == 1) { $xw->writeRaw('#sh_client-pushpin-1'); } elseif ($crawl_router['client_count'] == 2) { $xw->writeRaw('#sh_client-pushpin-2'); } elseif ($crawl_router['client_count'] == 3) { $xw->writeRaw('#sh_client-pushpin-3'); } elseif ($crawl_router['client_count'] == 4) { $xw->writeRaw('#sh_client-pushpin-4'); } elseif ($crawl_router['client_count'] == 5) { $xw->writeRaw('#sh_client-pushpin-5'); } elseif ($crawl_router['client_count'] >= 6) { $xw->writeRaw('#sh_client-pushpin-6'); } $xw->endElement(); $xw->startElement('Point'); $xw->startElement('coordinates'); $xw->writeRaw("{$longitude},{$latitude},0"); $xw->endElement(); $xw->endElement(); $xw->endElement(); } } $xw->endElement(); $xw->endElement(); $xw->endDocument(); print $xw->outputMemory(true); return true; }
function buildXML() { $xml = new xmlWriter(); $xml->openMemory(); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement("feed"); $xml->writeAttribute("xmlns", "http://www.w3.org/2005/Atom"); $xml->writeAttribute("xmlns:jangle", "http://jangle.org/vocab/"); $xml->startElement("link"); $xml->writeAttribute("href", $this->uri); $xml->writeAttribute("type", "application/atom+xml"); $xml->endElement(); $xml->writeElement("id", $this->uri); $xml->writeElement("updated", $this->time); $xml->startElement("link"); $xml->writeAttribute("rel", "self"); $xml->writeAttribute("href", $this->uri); $xml->writeAttribute("type", "application/atom+xml"); if (count($this->formats) == 1 && $this->formats[0] != NULL) { $xml->writeAttribute("jangle:format", $this->formats[0]); } $xml->endElement(); $pages = $this->pager(); if (count($pages) > 0) { foreach (array_keys($pages) as $page) { $xml->startElement("link"); $xml->writeAttribute("rel", $page); $xml->writeAttribute("href", $pages[$page]); $xml->writeAttribute("type", "application/atom+xml"); $xml->endElement(); } } if (count($this->alternateFormats)) { foreach (array_keys($this->alternateFormats) as $alt) { $xml->startElement("link"); $xml->writeAttribute("rel", $alt); $xml->writeAttribute("href", $this->alternateFormats[$alt]); $xml->writeAttribute("type", "application/atom+xml"); $xml->endElement(); } } for ($i = 0; $i < count($this->data); $i++) { $xml->startElement("entry"); $xml->startElement("link"); $xml->writeAttribute("href", $this->data[$i]->id); $xml->writeAttribute("jangle:format", $this->data[$i]->format); $xml->endElement(); $xml->writeElement("id", $this->data[$i]->id); $xml->writeElement("title", $this->data[$i]->title); $xml->writeElement("updated", $this->data[$i]->updated); $xml->startElement("author"); $xml->writeElement("name", $this->data[$i]->author); $xml->endElement(); if ($this->data[$i]->content) { $xml->startElement("content"); $xml->writeAttribute("type", $this->data[$i]->contentType); if ($this->data[$i]->stylesheet) { $content = $this->transformer($this->data[$i]->content, $this->data[$i]->stylesheet); } else { $content = $this->data[$i]->content; } if (preg_match("/xml/", $this->data[$i]->contentType)) { $xml->writeRaw($content); } else { $xml->text($content); } $xml->endElement(); } if ($this->data[$i]->description) { $xml->writeElement("summary", $this->data[$i]->description); } if ($this->data[$i]->created) { $xml->writeElement("created", $this->data[$i]->created); } if (count($this->data[$i]->alternateFormats)) { foreach (array_keys($this->data[$i]->alternateFormats) as $alt) { $xml->startElement("link"); $xml->writeAttribute("rel", $alt); $xml->writeAttribute("type", "application/atom+xml"); $xml->writeAttribute("href", $this->data[$i]->alternateFormats[$alt]); $xml->endElement(); } } if (count($this->data[$i]->relationships)) { foreach (array_keys($this->data[$i]->relationships) as $relation) { $xml->startElement("link"); $xml->writeAttribute("rel", "related"); $xml->writeAttribute("type", "application/atom+xml"); $xml->writeAttribute("href", $this->data[$i]->relationships[$relation]); $xml->writeAttribute("jangle:relationship", $relation); $xml->endElement(); } } if (count($this->data[$i]->categories)) { foreach ($this->data[$i]->categories as $cat) { $xml->startElement("category"); $xml->writeAttribute("term", $cat); $xml->endElement(); } } if (count($this->data[$i]->links)) { foreach ($this->data[$i]->links as $link) { $xml->startElement("link"); $xml->writeAttribute("rel", array_search($link, $this->data[$i]->links)); $xml->writeAttribute("href", $link[0]->href); if ($link["type"]) { $xml->writeAttribute("type", $link[0]->type); } $xml->endElement(); } } $xml->endElement(); } $xml->endElement(); return $xml; }