[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - wiki - XML Import & Export * 4 * http://www.egroupware.org * 5 * Written and (c) by Ralf Becker <RalfBecker@outdoor-training.de> * 6 * -------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: class.xmlwiki.inc.php 19336 2005-10-10 14:20:26Z ralfbecker $ */ 14 15 if (!function_exists('var2xml')) 16 { 17 if (file_exists(EGW_API_INC.'class.xmltool.inc.php')) 18 { 19 include_once (EGW_API_INC.'class.xmltool.inc.php'); 20 } 21 else 22 { 23 include_once (EGW_INCLUDE_ROOT.'/etemplate/inc/class.xmltool.inc.php'); 24 } 25 } 26 27 include_once (EGW_INCLUDE_ROOT.'/wiki/inc/class.bowiki.inc.php'); 28 29 class xmlwiki extends bowiki 30 { 31 var $public_functions = array( 32 'export' => True, 33 ); 34 35 function xmlwiki($wiki_id=0) 36 { 37 $this->bowiki($wiki_id); // call the constructor of the extended class 38 } 39 40 function export($name='',$lang='',$modified=0) 41 { 42 if (!$name) $name = $_GET['page']; 43 if (!$lang) $lang = $_GET['lang']; 44 if (!is_array($lang)) 45 { 46 $lang = $lang ? explode(',',$lang) : False; 47 } 48 if (!$modified) $modified = (int) $_GET['modified']; 49 50 header('Content-Type: text/xml; charset=utf-8'); 51 52 $xml_doc =& new xmldoc(); 53 $xml_doc->add_comment('$'.'Id$'); // to be able to comit the file 54 $xml_doc->add_comment("eGroupWare wiki-pages matching '$name%'". 55 ($lang ? " and lang in(".implode(',',$lang).')':''). 56 ($modified ? " modified since ".date('Y-m-d H:m:i',$modified):''). 57 ", exported ".date('Y-m-d H:m:i',$exported=time())." from $_SERVER[HTTP_HOST]"); 58 59 $xml_wiki =& new xmlnode('wiki'); 60 61 foreach($this->find($name.'%','wiki_name') as $page) 62 { 63 if ($lang && !in_array($page['lang'],$lang)) 64 { 65 //echo "continue as page[lang]=$page[lang] not in ".print_r($lang,True)."<br>\n"; 66 continue; // wrong language or not modified since $modified 67 } 68 $page = $this->page($page); // read the complete page 69 $page->read(); 70 $page = $page->as_array(); 71 unset($page['wiki_id']); // we dont export the wiki-id 72 73 if ($modified && $modified > $page['time']) 74 { 75 //echo "continue as page[time]=$page[time] < $modified<br>\n"; 76 continue; // not modified since $modified 77 } 78 79 $page = $GLOBALS['egw']->translation->convert($page,$GLOBALS['egw']->translation->charset(),'utf-8'); 80 81 $xml_page =& new xmlnode('page'); 82 foreach($page as $attr => $val) 83 { 84 if ($attr != 'text') 85 { 86 $xml_page->set_attribute($attr,$val); 87 } 88 else 89 { 90 $xml_page->set_value($val); 91 } 92 } 93 $xml_wiki->add_node($xml_page); 94 } 95 $xml_wiki->set_attribute('exported',$exported); 96 if ($lang) 97 { 98 $xml_wiki->set_attribute('languages',implode(',',$lang)); 99 } 100 if ($name) 101 { 102 $xml_wiki->set_attribute('matching',$name.'%'); 103 } 104 if ($modified) 105 { 106 $xml_wiki->set_attribute('modified',$modified); 107 } 108 $xml_doc->add_root($xml_wiki); 109 $xml = $xml_doc->export_xml(); 110 111 //if ($this->debug) 112 { 113 //echo "<pre>\n" . htmlentities($xml) . "\n</pre>\n"; 114 echo $xml; 115 } 116 return $xml; 117 } 118 119 function import($url,$debug_messages=False) 120 { 121 if (substr($url,0,4) == 'http') 122 { 123 // use our network class, as it deals with proxies and the proxy-config in admin->configuration 124 $network =& CreateObject('phpgwapi.network'); 125 $xmldata = $network->gethttpsocketfile($url); 126 $xmldata = strstr(implode('',$xmldata),'<?xml'); // discard everything before the start of the xml-file 127 } 128 else 129 { 130 if (function_exists('file_get_contents')) 131 { 132 $xmldata = file_get_contents($url); 133 } 134 elseif (($xmldata = file($url)) !== False) 135 { 136 $xmldata = implode('',$xmldata); 137 } 138 } 139 //echo '<pre>'.htmlspecialchars($xmldata)."</pre>\n"; 140 if (!$xmldata) 141 { 142 return False; 143 } 144 $parser = xml_parser_create(); 145 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); 146 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); // need to be off, else it eats our newlines 147 xml_parse_into_struct($parser, $xmldata, $vals); 148 xml_parser_free($parser); 149 150 $imported = array(); 151 foreach($vals as $val) 152 { 153 if ($val['tag'] == 'wiki') // wiki meta-data: eg. exported=Y-m-d h:m:i or export data 154 { 155 if ($val['type'] == 'open' || $val['type'] == 'complete') 156 { 157 $meta = $val['attributes']; 158 } 159 continue; 160 } 161 switch ($val['type']) 162 { 163 case 'open': 164 $wiki_page = $val['attributes']; 165 break; 166 case 'complete': 167 $wiki_page = $val['attributes']; 168 // fall through 169 case 'cdata': 170 $wiki_page['text'] = trim($val['value']); 171 $wiki_page = $GLOBALS['egw']->translation->convert($wiki_page,'utf-8'); 172 if ($this->write($wiki_page,False)) 173 { 174 if ($debug_messages) 175 { 176 echo str_pad("<b>$wiki_page[name]:$wiki_page[lang]: $wiki_page[title]</b><pre>$wiki_page[text]</pre>\n",4096); 177 } 178 $imported[] = $wiki_page['name'].':'.$wiki_page['lang']; 179 } 180 break; 181 case 'closed': 182 break; 183 } 184 } 185 return array( 186 'meta' => $meta, 187 'imported' => $imported, 188 ); 189 } 190 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |