예제 #1
0
파일: XMLUtil.php 프로젝트: spyre/emiral
function findProducts()
{
    //Header('Content-type: text/xml');
    // TEST
    $dao = new XMLUtil();
    $prod = new Produs();
    $prod->id = 123;
    $prod->nume = "Pizza";
    $prod->pret = 33.23;
    echo $dao->saveOne('produse', 'produs', $prod);
}
예제 #2
0
파일: Writer.php 프로젝트: mymizan/phreeze
 private function elementCreate($parent_node, $node_name, $content = '', $attributes = false, $return = true)
 {
     $content = XMLUtil::Escape($content);
     $element = $this->rss_dom->createElement($node_name, $content);
     if ($attributes) {
         foreach ($attributes as $key => $value) {
             $element->setAttribute($key, $value);
         }
     }
     $parent_node->appendChild($element);
     if ($return) {
         return $element;
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * Change XML to an array
  *
  * @param string $data
  * @return array
  */
 public static function XML2array($data)
 {
     $result = array();
     if (is_object($data) || is_array($data)) {
         if (is_object($data)) {
             $temp = get_object_vars($data);
         } else {
             $temp = $data;
         }
         if (!$temp) {
             return '';
         }
         foreach ($temp as $key => $value) {
             $result[$key] = XMLUtil::XML2array($value);
         }
     } else {
         return $data;
     }
     return $result;
 }
예제 #4
0
 /**
  * request
  * 01 查询单据轨迹 02 保存定单 03回写单据号 04 更改单据状态 
  * @param string $data
  * @return string 0 记录不存在 1 成功 -1 失败 -2 用户/密码错误 -3 无效机构号 -9 其他错误
  */
 public function request($data)
 {
     try {
         //$this->addLog("kenlong");
         if (C("DEBUG_MODE")) {
             $this->addLog("query::data:" . $data);
         }
         $xml = simplexml_load_string($data);
         $request = XMLUtil::XML2array($xml);
         //检查用户/密码是否正确
         if (!$this->check($request["head"], $result)) {
             return $result;
         }
         //开始请求处理
         switch ($request["head"]["type"]) {
             case '01':
                 $result = $this->track($request);
                 break;
             case '02':
                 $result = $this->order($request);
                 break;
             case '0200':
                 $result = $this->orderQuery($request);
                 break;
             case '03':
                 $result = $this->updatebillno($request);
                 break;
             case '04':
                 $result = $this->updatestatus($request);
                 break;
             default:
                 $result = $this->createResult('-9');
         }
     } catch (Exception $e) {
         $this->addLog("Not exception error from query:" . $e->getMessage());
         $result = $this->createResult($request["head"]["type"]);
     }
     return $result;
 }
예제 #5
0
 /**
  * control
  *
  * @param string $data
  * @param string $add
  * @return string
  */
 public function query($data)
 {
     if (C("DEBUG_MODE")) {
         $this->addLog("query::data:" . $data);
     }
     try {
         $xml = simplexml_load_string($data);
         $request = XMLUtil::XML2array($xml);
         //数据格式不正确
         if (!$request) {
             return $this->createResult($request["head"]["type"], '-3', 'what you request?');
         }
         //用户密码不正确
         if ($request["head"]["user"] != "user4soap" || $request["head"]["pass"] != 'pass4soap') {
             return $this->createResult($request["head"]["type"], '-2');
         }
         switch (substr($request["head"]["type"], 0, 2)) {
             case '01':
                 $rs = $this->billsQuery($request);
                 break;
             case '02':
                 $rs = $this->order($request);
                 break;
             case '03':
                 $rs = $this->uploadawb($request);
                 break;
             default:
                 $rs = $this->createResult($request["head"]["type"], '0', "not a valid action");
         }
         return $rs;
     } catch (Exception $e) {
         if (C("DEBUG_MODE")) {
             $this->addLog("query error:" . print_r($e, true));
         }
         return 'false';
     }
 }
예제 #6
0
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTTextStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('style:style', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open);
     } else {
         $open = XMLUtil::getElementOpenTag('style:default-style', $xmlCode);
         if (!empty($open)) {
             $style->setDefault(true);
             $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open);
         }
     }
     $open = XMLUtil::getElementOpenTag('style:text-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(self::$text_fields, $open);
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
예제 #7
0
 /**
  * Build the document from scratch.
  * (code taken from old function 'document_end_scratch')
  *
  * @param string      $doc
  * @param string      $autostyles
  * @param array       $commonstyles
  * @param string      $meta
  * @param string      $userfields
  * @param ODTStyleSet $styleset
  * @return mixed
  */
 public function build($doc = null, $meta = null, $userfields = null, $pagestyles = null)
 {
     // add defaults
     $this->ZIP->add_File('application/vnd.oasis.opendocument.text', 'mimetype', 0);
     $this->ZIP->add_File($meta, 'meta.xml');
     $this->ZIP->add_File($this->settings->getContent(), 'settings.xml');
     $autostyles = $this->styleset->export('office:automatic-styles');
     $commonstyles = $this->styleset->export('office:styles');
     $value = '<' . '?xml version="1.0" encoding="UTF-8"?' . ">\n";
     $value .= '<office:document-content ';
     $value .= 'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" ';
     $value .= 'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" ';
     $value .= 'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" ';
     $value .= 'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" ';
     $value .= 'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" ';
     $value .= 'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" ';
     $value .= 'xmlns:xlink="http://www.w3.org/1999/xlink" ';
     $value .= 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
     $value .= 'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" ';
     $value .= 'xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" ';
     $value .= 'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" ';
     $value .= 'xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" ';
     $value .= 'xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" ';
     $value .= 'xmlns:math="http://www.w3.org/1998/Math/MathML" ';
     $value .= 'xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" ';
     $value .= 'xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" ';
     $value .= 'xmlns:dom="http://www.w3.org/2001/xml-events" ';
     $value .= 'xmlns:xforms="http://www.w3.org/2002/xforms" ';
     $value .= 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ';
     $value .= 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
     $value .= 'office:version="1.0">';
     $value .= '<office:scripts/>';
     $value .= '<office:font-face-decls>';
     $value .= '<style:font-face style:name="Tahoma1" svg:font-family="Tahoma"/>';
     $value .= '<style:font-face style:name="Lucida Sans Unicode" svg:font-family="&apos;Lucida Sans Unicode&apos;" style:font-pitch="variable"/>';
     $value .= '<style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-pitch="variable"/>';
     $value .= '<style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/>';
     $value .= '</office:font-face-decls>';
     $value .= $autostyles;
     $value .= '<office:body>';
     $value .= '<office:text>';
     $value .= '<office:forms form:automatic-focus="false" form:apply-design-mode="false"/>';
     $value .= '<text:sequence-decls>';
     $value .= '<text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>';
     $value .= '<text:sequence-decl text:display-outline-level="0" text:name="Table"/>';
     $value .= '<text:sequence-decl text:display-outline-level="0" text:name="Text"/>';
     $value .= '<text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>';
     $value .= '</text:sequence-decls>';
     $value .= $userfields;
     $value .= $doc;
     $value .= '</office:text>';
     $value .= '</office:body>';
     $value .= '</office:document-content>';
     $this->ZIP->add_File($value, 'content.xml');
     // Edit 'styles.xml'
     $value = io_readFile(DOKU_PLUGIN . 'odt/styles.xml');
     // Add page styles
     $page = '';
     foreach ($pagestyles as $name => $layout_name) {
         $page .= '<style:master-page style:name="' . $name . '" style:page-layout-name="' . $layout_name . '"/>';
     }
     if (!empty($page)) {
         $value = str_replace('</office:master-styles>', $page . '</office:master-styles>', $value);
     }
     // Add common styles.
     $original = XMLUtil::getElement('office:styles', $value);
     $value = str_replace($original, $commonstyles, $value);
     // Add automatic styles.
     $value = str_replace('<office:automatic-styles/>', $autostyles, $value);
     $this->ZIP->add_File($value, 'styles.xml');
     // build final manifest
     $this->ZIP->add_File($this->manifest->getContent(), 'META-INF/manifest.xml');
 }
예제 #8
0
 /**
  * Helper function to find the next element and return its
  * complete definition including opening and closing tag.
  *
  * THIS FUNCTION DOES NOT HANDLE ELEMENTS WHICH CAN BE NESTED IN THEMSELVES!!!
  * 
  * @param  $element    On success $element carries the name of the found element
  * @param  $xmlCode    The XML code to search through
  * @return string      Found element or NULL
  */
 public static function getNextElement(&$element, $xmlCode, &$endPos = NULL)
 {
     if (empty($xmlCode)) {
         return NULL;
     }
     $pos = 0;
     $max = strlen($xmlCode);
     // Search the opening tag first.
     while ($pos < $max) {
         $start = strpos($xmlCode, '<', $pos);
         if ($start === false) {
             // Nothing found.
             return NULL;
         }
         if (XMLUtil::isValidXMLName($xmlCode[$start + 1])) {
             // Extract element name.
             $read = $start + 1;
             $found_element = '';
             while (XMLUtil::isValidXMLName($xmlCode[$read])) {
                 $found_element .= $xmlCode[$read];
                 $read++;
                 if ($read >= $max) {
                     return NULL;
                 }
             }
             $elementLength = strlen($found_element);
             $next = $xmlCode[$start + $elementLength + 1];
             if ($next == '/' || $next == '>' || ctype_space($next)) {
                 // Found it.
                 break;
             }
             $pos = $start + $elementLength;
         } else {
             // Skip this one.
             $pos = $start + 2;
         }
     }
     $pos = $start + $elementLength;
     // Search next '>'.
     $angle = strpos($xmlCode, '>', $pos);
     if ($angle === false) {
         // Opening tag is not terminated.
         return NULL;
     }
     $pos = $angle + 1;
     // Is this already the end?
     if ($xmlCode[$angle - 1] == '/') {
         // Yes.
         $endPos = $angle + 1;
         $element = $found_element;
         return substr($xmlCode, $start, $angle - $start + 1);
     }
     // Now, search closing tag.
     // (Simple solution which expects there are no child elements
     //  with the same name. This means we assume the element can not
     //  be nested in itself!)
     $end = strpos($xmlCode, '</' . $found_element . '>', $pos);
     if ($end === false) {
         return NULL;
     }
     $end += 3 + $elementLength;
     // Found closing tag.
     $endPos = $end;
     $element = $found_element;
     return substr($xmlCode, $start, $end - $start);
 }
 /**
  * Test function getAttributes()
  */
 public function test_getAttributes()
 {
     $xmlCode = '<test attr1="1" attr2="22" attr3="333" attr4="4444" attr5="55555"></test>';
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $xmlCode);
     $this->assertEquals(5, $found);
     $this->assertEquals('1', $attributes['attr1']);
     $this->assertEquals('22', $attributes['attr2']);
     $this->assertEquals('333', $attributes['attr3']);
     $this->assertEquals('4444', $attributes['attr4']);
     $this->assertEquals('55555', $attributes['attr5']);
 }
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTParagraphStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('style:style', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open, $style->style_properties);
     } else {
         $open = XMLUtil::getElementOpenTag('style:default-style', $xmlCode);
         if (!empty($open)) {
             $style->setDefault(true);
             $attrs += $style->importODTStyleInternal(ODTStyleStyle::getStyleProperties(), $open, $style->style_properties);
         }
     }
     $open = XMLUtil::getElementOpenTag('style:paragraph-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(self::$paragraph_fields, $xmlCode);
     }
     $open = XMLUtil::getElementOpenTag('style:text-properties', $xmlCode);
     if (!empty($open)) {
         $attrs += $style->importODTStyleInternal(ODTTextStyle::getTextProperties(), $open, $style->text_properties);
     }
     // Get all tab-stops.
     $tabs = XMLUtil::getElementContent('style:tab-stops', $xmlCode);
     if ($tabs != NULL) {
         $max = strlen($tabs);
         $pos = 0;
         $index = 0;
         $tab = XMLUtil::getElement('style:tab-stop', $tabs, $end);
         $pos = $end;
         while ($tab != NULL) {
             $style->tab_stops[$index] = array();
             $attrs += $style->importODTStyleInternal(self::$tab_stop_fields, $tab, $style->tab_stops[$index]);
             $index++;
             $tab = XMLUtil::getElement('style:tab-stop', substr($tabs, $pos), $end);
             $pos += $end;
         }
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
예제 #11
0
파일: api.php 프로젝트: spyre/emiral
 private function findProducts()
 {
     // Header('Content-type: text/xml');
     require_once 'EmiralXML/XMLUtil.php';
     require_once 'EmiralXML/Produs.php';
     // TEST
     $this->lemn->scrie('START');
     $dao = new XMLUtil();
     $prod = new Produs();
     $prod->id = 123;
     $prod->nume = "Pizza";
     $prod->pret = 33.23;
     $this->lemn->scrie(XMLUtil::saveOne('produse', 'produs', $prod));
     $this->response(XMLUtil::saveOne('produse', 'produs', $prod), 200);
 }
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTTextListStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('text:list-style', $xmlCode);
     if (!empty($open)) {
         // This properties are stored in the properties of ODTStyle
         $attrs += $style->importODTStyleInternal(self::$list_fields, $open);
         $content = XMLUtil::getElementContent('text:list-style', $xmlCode);
     }
     $pos = 0;
     $end = 0;
     $max = strlen($content);
     $text_fields = ODTTextStyle::getTextProperties();
     while ($pos < $max) {
         // Get XML code for next level.
         $level = XMLUtil::getNextElement($element, substr($content, $pos), $end);
         $level_content = XMLUtil::getNextElementContent($element, $level, $ignore);
         if (!empty($level)) {
             $list_style_properties = array();
             $list_level_properties = array();
             $label_properties = array();
             $text_properties = array();
             $properties = array();
             switch ($element) {
                 case 'text:list-level-style-number':
                     $attrs += $style->importODTStyleInternal(self::$style_number_fields, $level, $list_style_properties);
                     $list_level_style = 'number';
                     break;
                 case 'text:list-level-style-bullet':
                     $attrs += $style->importODTStyleInternal(self::$style_bullet_fields, $level, $list_style_properties);
                     $list_level_style = 'bullet';
                     break;
                 case 'text:list-level-style-image':
                     $attrs += $style->importODTStyleInternal(self::$style_image_fields, $level, $list_style_properties);
                     $list_level_style = 'image';
                     break;
             }
             $temp_content = XMLUtil::getElement('style:text-properties', $level_content);
             $attrs += $style->importODTStyleInternal($text_fields, $temp_content, $text_properties);
             $temp_content = XMLUtil::getElementOpenTag('style:list-level-properties', $level_content);
             $attrs += $style->importODTStyleInternal(self::$list_level_props_fields, $temp_content, $list_level_properties);
             $temp_content = XMLUtil::getElement('style:list-level-label-alignment', $level_content);
             $attrs += $style->importODTStyleInternal(self::$label_align_fields, $temp_content, $label_properties);
             // Assign properties array to our level array
             $level_number = $style->getPropertyInternal('level', $list_style_properties);
             $properties['list-style'] = $list_style_properties;
             $properties['list-level'] = $list_level_properties;
             $properties['label'] = $label_properties;
             $properties['text'] = $text_properties;
             $style->list_level_styles[$level_number] = $properties;
             // Set special property 'list-level-style' to remember element to encode
             // on call to toString()!
             $style->setPropertyForLevel($level_number, 'list-level-style', $list_level_style);
         }
         $pos += $end;
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
 /**
  * This function checks the rendering of deleted text.
  */
 public function test_deleted_text()
 {
     $files = array();
     $ok = ODTTestUtils::getRenderedODTDocument($files, '<del>This is strike-through text.</del>');
     $this->assertFalse($ok == false, 'Error rendering, creating, unpacking, reading ODT doc!');
     // Examine ODT XML content.
     // Get office:text
     $office_text = XMLUtil::getElementContent('office:text', $files['content-xml']);
     $this->assertFalse($office_text == NULL, 'Element "office:text" not found!');
     // Get first paragraph
     $paragraph = XMLUtil::getElementContent('text:p', $office_text);
     $this->assertFalse($paragraph == NULL, 'Element "text:p" not found!');
     // The paragraph shouild have a text span.
     $span_attrs = XMLUtil::getElementOpenTag('text:span', $office_text);
     $span_content = XMLUtil::getElementContent('text:span', $office_text);
     $this->assertFalse($span_content == NULL, 'Element "text:p" not found!');
     // The span should have our text content and the style for bold text
     $this->assertEquals($span_content, 'This is strike-through text.');
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $span_attrs);
     $this->assertEquals(1, $found);
     $this->assertEquals('del', $attributes['text:style-name']);
 }
예제 #14
0
 /**
  * 下载订单
  * 
  */
 public function ReadFromSPL()
 {
     $this->create();
     try {
         //call
         //$result = unserialize(base64_decode(file_get_contents("d:/result.log")));
         $result = $this->service->call("setTmsShipment", array('tmsShipment' => $this->authname), '', '');
         if (DEBUG) {
             $this->debug("resultSerialize", base64_encode(serialize($result)));
         }
         if (!$result) {
             $this->addLog("the webservice was no result.");
             $this->addLog($this->service->error_str);
             return false;
         }
         if (!$result["item"]) {
             $this->addLog("the item as empty.");
             return false;
         }
         if (DEBUG) {
             $this->debug("readdata", print_r($result["item"], true));
         }
         $readItem = array();
         if (is_array($result["item"])) {
             $readItem = $result["item"];
         } else {
             $readItem[] = $result["item"];
         }
         foreach ($readItem as $data) {
             $xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
             $response = XMLUtil::XML2array($xml);
             $messagedetail = simplexml_load_string(trim($response['MESSAGEDETAIL']));
             $contentlist = array();
             $contentlist[] = $messagedetail->CONTENTLIST;
             if (DEBUG) {
                 $this->debug("contentlist", print_r($contentlist, true));
             }
             foreach ($contentlist as $tmp) {
                 if (DEBUG) {
                     $this->debug("temp", print_r($tmp, true));
                 }
                 $tmp = XMLUtil::XML2array($tmp);
                 $tmp = $tmp['CONTENT'];
                 $order = $tmp['HEADER'];
                 $details = array();
                 if (array_key_exists(0, $tmp['DETAIL'])) {
                     $details = $tmp['DETAIL'];
                 } else {
                     $details[] = $tmp['DETAIL'];
                 }
                 $succeed = 0;
                 if (DEBUG) {
                     $this->debug("details", print_r($details, true));
                 }
                 foreach ($details as $detail) {
                     if (DEBUG) {
                         $this->debug("detail", print_r($detail, true));
                     }
                     $order = array_merge($order, $detail);
                     $order['FILEFUNCTION'] = $response['MESSAGEHEAD']['FILEFUNCTION'];
                     if (!$this->saveOrder($order)) {
                         $this->addLog("saveOrder data error in function ReadFromSPL");
                         $succeed += 1;
                     }
                 }
                 // 如果都成功了,反馈信息
                 if ($succeed === 0) {
                     //回写已下载标记
                     $content = "<CONTENTLIST>" . "<CONTENT>" . "<HEADER></HEADER>" . "<DETAIL>" . "<ECNO>" . $this->orderno . "</ECNO>" . "<CECNO></CECNO>" . "<FLAG>1</FLAG>" . "</DETAIL>" . "</CONTENT>" . "</CONTENTLIST>";
                     $senddata = trim($this->createResult('DispatcFlag', $content));
                     if (DEBUG) {
                         $this->debug("response", htmlspecialchars_decode($senddata));
                     }
                     if (!$this->orderno) {
                         $this->addLog("ecno in setTmsShipmentType is empty, not good");
                         continue;
                     }
                     //call
                     if (in_array($this->orderno, $this->sendBack)) {
                         $this->addLog("bill was sendback");
                     } else {
                         $rs = $this->service->call("setTmsShipmentType", array('tmsShipmentTypeXml' => $senddata), '', '');
                         if (DEBUG) {
                             $this->debug("responseresult", print_r($rs, true));
                         }
                         $this->checkResult($rs);
                         // 休息一下
                         $this->sleep4awhile();
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $this->addLog("setTmsShipment Exception error" . $e->getMessage());
         return false;
     }
 }
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTMasterPageStyle();
     // Get attributes for element 'style:master-page'
     $open = XMLUtil::getElementOpenTag('style:master-page', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$master_fields, $open, $style->master_style);
     }
     // Get attributes for element 'style:header'
     $open = XMLUtil::getElementOpenTag('style:header', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_header);
         $content_header = XMLUtil::getElementContent('style:header', $xmlCode);
     }
     // Get attributes for element 'style:footer'
     $open = XMLUtil::getElementOpenTag('style:footer', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_footer);
         $content_footer = XMLUtil::getElementContent('style:footer', $xmlCode);
     }
     // Get attributes for element 'style:header-left'
     $open = XMLUtil::getElementOpenTag('style:header-left', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_header_left);
         $content_header_left = XMLUtil::getElementContent('style:header-left', $xmlCode);
     }
     // Get attributes for element 'style:footer-left'
     $open = XMLUtil::getElementOpenTag('style:footer-left', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$header_footer_fields, $open, $style->style_footer_left);
         $content_footer_left = XMLUtil::getElementContent('style:footer-left', $xmlCode);
     }
     return $style;
 }
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTTextOutlineStyle();
     $attrs = 0;
     $open = XMLUtil::getElementOpenTag('text:outline-style', $xmlCode);
     if (!empty($open)) {
         // This properties are stored in the properties of ODTStyle
         $attrs += $style->importODTStyleInternal(self::$outline_fields, $open);
     }
     $pos = 0;
     $end = 0;
     $max = strlen($xmlCode);
     $level = XMLUtil::getElement('text:outline-level-style', substr($xmlCode, $pos), $end);
     $pos += $end;
     $text_fields = ODTTextStyle::getTextProperties();
     $check = 0;
     while ($level != NULL) {
         // We can have multiple level definitons with all the same properties.
         // So we store this in our own array. The "text:level" is the array key.
         if (!empty($level)) {
             $properties = array();
             $attrs += $style->importODTStyleInternal($text_fields, $level, $properties);
             $attrs += $style->importODTStyleInternal(self::$outline_fields, $level, $properties);
             // Assign properties array to our level array
             $level_number = $style->getPropertyInternal('level', $properties);
             $style->outline_level_styles[$level_number] = $properties;
         }
         // Get XML code for next level.
         $level = XMLUtil::getElement('text:outline-level-style', substr($xmlCode, $pos), $end);
         $pos += $end;
         if ($pos >= $max) {
             break;
         }
     }
     // If style has no meaningfull content then throw it away
     if ($attrs == 0) {
         return NULL;
     }
     return $style;
 }
 /**
  * Create new style by importing ODT style definition.
  *
  * @param  $xmlCode Style definition in ODT XML format
  * @return ODTStyle New specific style
  */
 public static function importODTStyle($xmlCode)
 {
     $style = new ODTPageLayoutStyle();
     // Get attributes for element 'style:master-page'
     $open = XMLUtil::getElementOpenTag('style:page-layout', $xmlCode);
     if (!empty($open)) {
         $style->importODTStyleInternal(self::$page_layout_fields, $open, $style->page_layout_style);
         $childs = XMLUtil::getElementContent('style:page-layout', $xmlCode);
         if (!empty($childs)) {
             // Get attributes for element 'style:page-layout-properties'
             $open = XMLUtil::getElementOpenTag('style:page-layout-properties', $childs);
             $style->content_header = XMLUtil::getElement('style:header-style', $childs);
             $style->content_footer = XMLUtil::getElement('style:footer-style', $childs);
             if (!empty($open)) {
                 $style->importODTStyleInternal(self::$layout_props_fields, $open, $style->layout_props);
                 $childs = XMLUtil::getElementContent('style:page-layout-properties', $xmlCode);
                 if (!empty($childs)) {
                     // Get 'style:background-image'
                     $open = XMLUtil::getElementOpenTag('style:background-image', $childs);
                     if (!empty($open)) {
                         $style->importODTStyleInternal(self::$bgi_fields, $open, $style->bgi_props);
                         $style->content_bgi = XMLUtil::getElementContent('style:background-image', $childs);
                     }
                     // Get 'style:columns'
                     $open = XMLUtil::getElementOpenTag('style:columns', $childs);
                     if (!empty($open)) {
                         $style->importODTStyleInternal(self::$columns_fields, $open, $style->columns_props);
                         $style->content_columns = XMLUtil::getElementContent('style:columns', $childs);
                     }
                     // Get 'style:footnote-sep'
                     $open = XMLUtil::getElementOpenTag('style:footnote-sep', $childs);
                     if (!empty($open)) {
                         $style->importODTStyleInternal(self::$footnote_fields, $open, $style->footnote_props);
                     }
                 }
             }
         }
     }
     return $style;
 }
 /**
  * Test setProperty() and toString().
  * This is a test case for issue #120.
  */
 public function test_set_and_to_string()
 {
     $properties = array();
     $properties['style-name'] = 'Heading';
     $properties['style-parent'] = 'Standard';
     $properties['style-class'] = 'text';
     $properties['style-next'] = 'Text_20_body';
     $properties['margin-top'] = '0.423cm';
     $properties['margin-bottom'] = '0.212cm';
     $properties['keep-with-next'] = 'always';
     $properties['font-size'] = '14pt';
     $properties['font-size-asian'] = '14pt';
     $properties['font-size-complex'] = '14pt';
     $properties['font-name'] = 'Bitstream Vera Sans1';
     $properties['font-name-asian'] = 'Bitstream Vera Sans2';
     $properties['font-name-complex'] = 'Bitstream Vera Sans2';
     $expected = '<style:style style:name="Heading" style:parent-style-name="Standard" style:class="text" style:next-style-name="Text_20_body" style:family="paragraph" >' . "\n";
     $expected .= '<style:paragraph-properties fo:margin-top="0.423cm" fo:margin-bottom="0.212cm" fo:keep-with-next="always" />' . "\n";
     $expected .= '<style:text-properties fo:font-size="14pt" style:font-size-asian="14pt" style:font-size-complex="14pt" style:font-name="Bitstream Vera Sans1" style:font-name-asian="Bitstream Vera Sans2" style:font-name-complex="Bitstream Vera Sans2" />' . "\n";
     $expected .= '</style:style>' . "\n";
     $style = new ODTParagraphStyle();
     $this->assertNotNull($style);
     foreach ($properties as $key => $value) {
         $style->setProperty($key, $value);
     }
     $style_string = $style->toString();
     // We should have the following elements:
     // style:style, style:paragraph-properties, style:text-properties
     $style_style = XMLUtil::getElementOpenTag('style:style', $style_string);
     $this->assertNotNull($style_style);
     $paragraph_props = XMLUtil::getElementOpenTag('style:paragraph-properties', $style_string);
     $this->assertNotNull($paragraph_props);
     $text_props = XMLUtil::getElementOpenTag('style:text-properties', $style_string);
     $this->assertNotNull($text_props);
     // Check attribute values of element "style:style", see $expected
     // Remark: attribute 'style:family' must always be present even if it was not set
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $style_style);
     $this->assertEquals(5, $found);
     $this->assertEquals('Heading', $attributes['style:name']);
     $this->assertEquals('Standard', $attributes['style:parent-style-name']);
     $this->assertEquals('text', $attributes['style:class']);
     $this->assertEquals('Text_20_body', $attributes['style:next-style-name']);
     $this->assertEquals('paragraph', $attributes['style:family']);
     // Check attribute values of element "style:paragraph-properties", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $paragraph_props);
     $this->assertEquals(3, $found);
     $this->assertEquals('0.423cm', $attributes['fo:margin-top']);
     $this->assertEquals('0.212cm', $attributes['fo:margin-bottom']);
     $this->assertEquals('always', $attributes['fo:keep-with-next']);
     // Check attribute values of element "style:text-properties", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $text_props);
     $this->assertEquals(6, $found);
     $this->assertEquals('14pt', $attributes['fo:font-size']);
     $this->assertEquals('14pt', $attributes['style:font-size-asian']);
     $this->assertEquals('14pt', $attributes['style:font-size-complex']);
     $this->assertEquals('Bitstream Vera Sans1', $attributes['style:font-name']);
     $this->assertEquals('Bitstream Vera Sans2', $attributes['style:font-name-asian']);
     $this->assertEquals('Bitstream Vera Sans2', $attributes['style:font-name-complex']);
 }
 /**
  * This function checks that the document does not include extra
  * paragraphs if the wiki page starts with a table.
  * 
  * Extra paragraphs without text content would cause the document to
  * start with an empty line(s).
  */
 public function test_start_table()
 {
     // Render document with one table only.
     $files = array();
     $page = "^ Heading 1      ^ Heading 2       ^ Heading 3          ^\n";
     $page .= "| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |\n";
     $ok = ODTTestUtils::getRenderedODTDocument($files, $page);
     $this->assertFalse($ok == false, 'Error rendering, creating, unpacking, reading ODT doc!');
     // Examine ODT XML content.
     // Get office:text
     $office_text = XMLUtil::getElementContent('office:text', $files['content-xml']);
     $this->assertFalse($office_text == NULL, 'Element "office:text" not found!');
     // Get first paragraph
     $paragraph = XMLUtil::getElementContent('text:p', $office_text);
     // Get first table and first table paragraph
     $table = XMLUtil::getElementContent('table:table', $office_text);
     $table_paragraph = XMLUtil::getElementContent('text:p', $table);
     $found = preg_match('/Heading 1/', $table_paragraph);
     $this->assertFalse($found != 1, "First table paragraph does not include first heading!");
     $this->assertFalse($table_paragraph != $paragraph, "First table paragraph is not the first paragraph!");
 }
예제 #20
0
<?php

Header('Content-type: text/xml');
require_once 'XMLUtil.php';
// TEST
$dao = new XMLUtil();
$prod = new Produs();
$prod->id = 123;
$prod->nume = "Pizza";
$prod->pret = 33.23;
echo $dao->saveOne($prod);
예제 #21
0
 /**
  * 同步员工
  *
  * @param string $data
  * @return boolean
  */
 private function synMember($data)
 {
     //id或表明为空,则返回失败
     if (!$data["ObjectId"] || !$data["ObjectName"]) {
         return false;
     }
     //删除
     if ($data["MethodName"] == '3') {
         $result = $this->memberDelete($data["ObjectId"]);
         if ($result) {
             return true;
         } else {
             return false;
         }
     }
     //获取信息
     $params = array("userid" => $data["ObjectId"]);
     $result = $this->client->call("GetUsersInfoById", array('parameters' => $params), '', '');
     $result = $result["GetUsersInfoByIdResult"];
     if ($result == '-2') {
         $this->addLog("access denied in synMember!");
         return false;
     }
     //将GBK替换成UTF-8,否则simplexml_load_string会失败
     $result = str_replace("GBK", "utf-8", $result);
     $xml = simplexml_load_string($result);
     $rs = XMLUtil::XML2array($xml);
     if (!$rs) {
         return false;
     }
     $info = $this->getLogInfo($rs["Node"]["property"]);
     //返回值无id,则返回失败
     if (!$info["DeptId"]) {
         return false;
     }
     //添加
     if ($data["MethodName"] == '1') {
         $result = $this->memberAdd($info);
     } else {
         $result = $this->memberUpdate($info);
     }
     //返回值
     if ($result) {
         return true;
     } else {
         return false;
     }
 }
예제 #22
0
 protected function importFromODT($styles_xml_content, $root_element)
 {
     if (empty($styles_xml_content) || empty($root_element)) {
         return false;
     }
     // Only import known style elements
     switch ($root_element) {
         case 'office:styles':
         case 'office:automatic-styles':
             $style_elements = XMLUtil::getElementContent($root_element, $styles_xml_content, $end);
             break;
         default:
             return false;
     }
     $pos = 0;
     $max = strlen($style_elements);
     while ($pos < $max) {
         $xml_code = XMLUtil::getNextElement($element, substr($style_elements, $pos), $end);
         if ($xml_code == NULL) {
             break;
         }
         $pos += $end + 1;
         // Create new ODTStyle
         $object = ODTStyle::importODTStyle($xml_code);
         if ($object != NULL) {
             // Success, add it
             switch ($root_element) {
                 case 'office:styles':
                     $this->addStyle($object);
                     break;
                 case 'office:automatic-styles':
                     $this->addAutomaticStyle($object);
                     break;
             }
         }
     }
     return true;
 }
 /**
  * Test function getNextElement()
  */
 public function test_getNextElementContent_1()
 {
     $xmlCode = '</peng><unknown peng="5"><b>Hallo</b></unknown><anotherOne></anotherOne>';
     $found = XMLUtil::getNextElementContent($element, $xmlCode, $end);
     $this->assertNotNull($found);
     $this->assertEquals('<b>Hallo</b>', $found);
     $this->assertEquals(strlen($xmlCode) - strlen('<anotherOne></anotherOne>'), $end);
     $this->assertEquals('unknown', $element);
 }
예제 #24
0
 /**
  * Build the document from the template.
  * (code taken from old function 'document_end_scratch')
  *
  * @param string      $doc
  * @param string      $autostyles
  * @param array       $commonstyles
  * @param string      $meta
  * @param string      $userfields
  * @param ODTDefaultStyles $styleset
  * @return mixed
  */
 public function build($doc = null, $meta = null, $userfields = null, $pagestyles = null)
 {
     // for the temp dir
     global $ID;
     // Temp dir
     if (is_dir($this->config->getParam('tmpdir'))) {
         // version > 20070626
         $temp_dir = $this->config->getParam('tmpdir');
     } else {
         // version <= 20070626
         $temp_dir = $this->config->getParam('savedir') . '/cache/tmp';
     }
     $temp_dir = $temp_dir . "/odt/" . str_replace(':', '-', $ID);
     if (is_dir($temp_dir)) {
         io_rmdir($temp_dir, true);
     }
     io_mkdir_p($temp_dir);
     // Extract template
     $template_path = $this->config->getParam('mediadir') . '/' . $this->directory . "/" . $this->template;
     $ok = $this->ZIP->Extract($template_path, $temp_dir);
     if ($ok == -1) {
         throw new Exception(' Error extracting the zip archive:' . $template_path . ' to ' . $temp_dir);
     }
     // Import styles from ODT template
     //$this->styleset->importFromODTFile($temp_dir.'/content.xml', 'office:automatic-styles');
     //$this->styleset->importFromODTFile($temp_dir.'/styles.xml', 'office:styles');
     $autostyles = $this->styleset->export('office:automatic-styles');
     $commonstyles = $this->styleset->export('office:styles');
     // Prepare content
     $missingfonts = $this->styleset->getMissingFonts($temp_dir . '/styles.xml');
     // Insert content
     $old_content = io_readFile($temp_dir . '/content.xml');
     if (strpos($old_content, 'DOKUWIKI-ODT-INSERT') !== FALSE) {
         // Replace the mark
         $this->_odtReplaceInFile('/<text:p[^>]*>DOKUWIKI-ODT-INSERT<\\/text:p>/', $doc, $temp_dir . '/content.xml', true);
     } else {
         // Append to the template
         $this->_odtReplaceInFile('</office:text>', $doc . '</office:text>', $temp_dir . '/content.xml');
     }
     // Cut off unwanted content
     if (strpos($old_content, 'DOKUWIKI-ODT-CUT-START') !== FALSE && strpos($old_content, 'DOKUWIKI-ODT-CUT-STOP') !== FALSE) {
         $this->_odtReplaceInFile('/DOKUWIKI-ODT-CUT-START.*DOKUWIKI-ODT-CUT-STOP/', '', $temp_dir . '/content.xml', true);
     }
     // Insert userfields
     if (strpos($old_content, "text:user-field-decls") === FALSE) {
         // no existing userfields
         $this->_odtReplaceInFile('/<office:text([^>]*)>/U', '<office:text\\1>' . $userfields, $temp_dir . '/content.xml', TRUE);
     } else {
         $this->_odtReplaceInFile('</text:user-field-decls>', substr($userfields, 23), $temp_dir . '/content.xml');
     }
     // Insert styles & fonts
     $value = io_readFile($temp_dir . '/content.xml');
     $original = XMLUtil::getElement('office:automatic-styles', $value);
     $this->_odtReplaceInFile($original, $autostyles, $temp_dir . '/content.xml');
     $value = io_readFile($temp_dir . '/styles.xml');
     $original = XMLUtil::getElement('office:automatic-styles', $value);
     $this->_odtReplaceInFile($original, $autostyles, $temp_dir . '/styles.xml');
     $value = io_readFile($temp_dir . '/styles.xml');
     $original = XMLUtil::getElement('office:styles', $value);
     $this->_odtReplaceInFile($original, $commonstyles, $temp_dir . '/styles.xml');
     $this->_odtReplaceInFile('</office:font-face-decls>', $missingfonts . '</office:font-face-decls>', $temp_dir . '/styles.xml');
     // Insert page styles
     $page = '';
     foreach ($pagestyles as $name => $layout_name) {
         $page .= '<style:master-page style:name="' . $name . '" style:page-layout-name="' . $layout_name . '"/>';
     }
     if (!empty($page)) {
         $this->_odtReplaceInFile('</office:master-styles>', $page . '</office:master-styles>', $temp_dir . '/styles.xml');
     }
     // Add manifest data
     $this->_odtReplaceInFile('</manifest:manifest>', $this->manifest->getExtraContent() . '</manifest:manifest>', $temp_dir . '/META-INF/manifest.xml');
     // Build the Zip
     $this->ZIP->Compress(null, $temp_dir, null);
     io_rmdir($temp_dir, true);
 }
 /**
  * Test setProperty() and toString(), including tab-stops.
  * This is a test case for issue #123.
  */
 public function test_set_toc_paragraph()
 {
     $indent = 2;
     $properties = array();
     $properties['style-name'] = 'TOC-Test';
     $properties['style-parent'] = 'Index';
     $properties['style-class'] = 'index';
     $properties['style-position'] = 17 - $indent . 'cm';
     $properties['style-type'] = 'right';
     $properties['style-leader-style'] = 'dotted';
     $properties['style-leader-text'] = '.';
     $properties['margin-left'] = $indent . 'cm';
     $properties['margin-right'] = '0cm';
     $properties['text-indent'] = '0cm';
     // This variable is just used to show the expected result but is not used for test comparsion.
     // We explicitly parse the exported XML code to be independent from attributes position.
     // The attrbitues positions might change in the future if ODTParagraphStyle.php is changed.
     $expected = '<style:style style:name="TOC-Test" style:parent-style-name="Index" style:class="index" style:family="paragraph" >';
     $expected .= '<style:paragraph-properties fo:margin-left="2cm" fo:margin-right="0cm" fo:text-indent="0cm" >';
     $expected .= '<style:tab-stops>';
     $expected .= '<style:tab-stop style:position="15cm" style:type="right" style:leader-style="dotted" style:leader-text="." />';
     $expected .= '</style:tab-stops>';
     $expected .= '</style:paragraph-properties>';
     $expected .= '</style:style>';
     // Create style, set all properties and get XML code of the style
     $style = new ODTParagraphStyle();
     $this->assertNotNull($style);
     foreach ($properties as $key => $value) {
         $style->setProperty($key, $value);
     }
     $style_string = $style->toString();
     // We should have the following elements:
     // style:style, style:paragraph-properties, style:text-properties, style:tab-stops
     $style_style = XMLUtil::getElementOpenTag('style:style', $style_string);
     $this->assertNotNull($style_style);
     $paragraph_props = XMLUtil::getElementOpenTag('style:paragraph-properties', $style_string);
     $paragraph = XMLUtil::getElement('style:paragraph-properties', $style_string);
     $this->assertNotNull($paragraph_props);
     $tab_stops_props = XMLUtil::getElement('style:tab-stops', $paragraph);
     $this->assertNotNull($tab_stops_props);
     $tab_stop_props = XMLUtil::getElementOpenTag('style:tab-stop', $tab_stops_props);
     $this->assertNotNull($tab_stop_props);
     // Check attribute values of element "style:style", see $expected
     // Remark: attribute 'style:family' must always be present even if it was not set
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $style_style);
     $this->assertEquals(4, $found);
     $this->assertEquals('TOC-Test', $attributes['style:name']);
     $this->assertEquals('Index', $attributes['style:parent-style-name']);
     $this->assertEquals('index', $attributes['style:class']);
     $this->assertEquals('paragraph', $attributes['style:family']);
     // Check attribute values of element "style:paragraph-properties", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $paragraph_props);
     $this->assertEquals(3, $found);
     $this->assertEquals('2cm', $attributes['fo:margin-left']);
     $this->assertEquals('0cm', $attributes['fo:margin-right']);
     $this->assertEquals('0cm', $attributes['fo:text-indent']);
     // Check attribute values of element "style:tab-stop", see $expected
     $attributes = array();
     $found = XMLUtil::getAttributes($attributes, $tab_stop_props);
     $this->assertEquals(4, $found);
     $this->assertEquals('15cm', $attributes['style:position']);
     $this->assertEquals('right', $attributes['style:type']);
     $this->assertEquals('dotted', $attributes['style:leader-style']);
     $this->assertEquals('.', $attributes['style:leader-text']);
 }
예제 #26
0
 /**
  * Parses a WebDAV multistatus response body
  *
  * This method returns an array with the following structure
  *
  * array(
  *   'url/to/resource' => array(
  *     '200' => array(
  *        '{DAV:}property1' => 'value1',
  *        '{DAV:}property2' => 'value2',
  *     ),
  *     '404' => array(
  *        '{DAV:}property1' => null,
  *        '{DAV:}property2' => null,
  *     ),
  *   )
  *   'url/to/resource2' => array(
  *      .. etc ..
  *   )
  * )
  *
  *
  * @param string $body xml body
  * @return array
  */
 public function parseMultiStatus($body)
 {
     $body = XMLUtil::convertDAVNamespace($body);
     $responseXML = simplexml_load_string($body, null, LIBXML_NOBLANKS | LIBXML_NOCDATA);
     if ($responseXML === false) {
         throw new \InvalidArgumentException('The passed data is not valid XML');
     }
     $responseXML->registerXPathNamespace('d', 'urn:DAV');
     $propResult = array();
     foreach ($responseXML->xpath('d:response') as $response) {
         $response->registerXPathNamespace('d', 'urn:DAV');
         $href = $response->xpath('d:href');
         $href = (string) $href[0];
         $properties = array();
         foreach ($response->xpath('d:propstat') as $propStat) {
             $propStat->registerXPathNamespace('d', 'urn:DAV');
             $status = $propStat->xpath('d:status');
             list($httpVersion, $statusCode, $message) = explode(' ', (string) $status[0], 3);
             // Only using the propertymap for results with status 200.
             $propertyMap = $statusCode === '200' ? $this->propertyMap : array();
             $properties[$statusCode] = XMLUtil::parseProperties(dom_import_simplexml($propStat), $propertyMap);
         }
         $propResult[$href] = $properties;
     }
     return $propResult;
 }
예제 #27
0
 /**
  * @expectedException InvalidArgumentException
  */
 function testParseClarkNotationFail()
 {
     XMLUtil::parseClarkNotation('}foo');
 }