home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / export / xml.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  4.6 KB  |  181 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * Set of functions used to build XML dumps of tables
  5.  *
  6.  * @version $Id: xml.php 11326 2008-06-17 21:32:48Z lem9 $
  7.  */
  8. if (! defined('PHPMYADMIN')) {
  9.     exit;
  10. }
  11.  
  12. /**
  13.  *
  14.  */
  15. if (strlen($GLOBALS['db'])) { /* Can't do server export */
  16.  
  17. if (isset($plugin_list)) {
  18.     $plugin_list['xml'] = array(
  19.         'text' => 'strXML',
  20.         'extension' => 'xml',
  21.         'mime_type' => 'text/xml',
  22.         'options' => array(
  23.             array('type' => 'hidden', 'name' => 'data'),
  24.             ),
  25.         'options_text' => 'strOptions',
  26.         );
  27. } else {
  28.  
  29. /**
  30.  * Outputs comment
  31.  *
  32.  * @param   string      Text of comment
  33.  *
  34.  * @return  bool        Whether it suceeded
  35.  */
  36. function PMA_exportComment($text) {
  37.     return PMA_exportOutputHandler('<!-- ' . $text . ' -->' . $GLOBALS['crlf']);
  38. }
  39.  
  40. /**
  41.  * Outputs export footer
  42.  *
  43.  * @return  bool        Whether it suceeded
  44.  *
  45.  * @access  public
  46.  */
  47. function PMA_exportFooter() {
  48.     return TRUE;
  49. }
  50.  
  51. /**
  52.  * Outputs export header
  53.  *
  54.  * @return  bool        Whether it suceeded
  55.  *
  56.  * @access  public
  57.  */
  58. function PMA_exportHeader() {
  59.     global $crlf;
  60.     global $cfg;
  61.  
  62.     if ($GLOBALS['output_charset_conversion']) {
  63.         $charset = $GLOBALS['charset_of_file'];
  64.     } else {
  65.         $charset = $GLOBALS['charset'];
  66.     }
  67.  
  68.     $head  =  '<?xml version="1.0" encoding="' . $charset . '" ?>' . $crlf
  69.            .  '<!--' . $crlf
  70.            .  '-' . $crlf
  71.            .  '- phpMyAdmin XML Dump' . $crlf
  72.            .  '- version ' . PMA_VERSION . $crlf
  73.            .  '- http://www.phpmyadmin.net' . $crlf
  74.            .  '-' . $crlf
  75.            .  '- ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
  76.     if (!empty($cfg['Server']['port'])) {
  77.          $head .= ':' . $cfg['Server']['port'];
  78.     }
  79.     $head .= $crlf
  80.            .  '- ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
  81.            .  '- ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
  82.            .  '- ' . $GLOBALS['strPHPVersion'] . ': ' . phpversion() . $crlf
  83.            .  '-->' . $crlf . $crlf;
  84.     return PMA_exportOutputHandler($head);
  85. }
  86.  
  87. /**
  88.  * Outputs database header
  89.  *
  90.  * @param   string      Database name
  91.  *
  92.  * @return  bool        Whether it suceeded
  93.  *
  94.  * @access  public
  95.  */
  96. function PMA_exportDBHeader($db) {
  97.     global $crlf;
  98.     $head = '<!--' . $crlf
  99.           . '- ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
  100.           . '-->' . $crlf
  101.           . '<' . $db . '>' . $crlf;
  102.     return PMA_exportOutputHandler($head);
  103. }
  104.  
  105. /**
  106.  * Outputs database footer
  107.  *
  108.  * @param   string      Database name
  109.  *
  110.  * @return  bool        Whether it suceeded
  111.  *
  112.  * @access  public
  113.  */
  114. function PMA_exportDBFooter($db) {
  115.     global $crlf;
  116.     return PMA_exportOutputHandler('</' . $db . '>' . $crlf);
  117. }
  118.  
  119. /**
  120.  * Outputs create database database
  121.  *
  122.  * @param   string      Database name
  123.  *
  124.  * @return  bool        Whether it suceeded
  125.  *
  126.  * @access  public
  127.  */
  128. function PMA_exportDBCreate($db) {
  129.     return TRUE;
  130. }
  131.  
  132.  
  133. /**
  134.  * Outputs the content of a table
  135.  *
  136.  * @param   string      the database name
  137.  * @param   string      the table name
  138.  * @param   string      the end of line sequence
  139.  * @param   string      the url to go back in case of error
  140.  * @param   string      SQL query for obtaining data
  141.  *
  142.  * @return  bool        Whether it suceeded
  143.  *
  144.  * @access  public
  145.  */
  146. function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
  147.     $result      = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
  148.  
  149.     $columns_cnt = PMA_DBI_num_fields($result);
  150.     for ($i = 0; $i < $columns_cnt; $i++) {
  151.         $columns[$i] = stripslashes(PMA_DBI_field_name($result, $i));
  152.     }
  153.     unset($i);
  154.  
  155.     $buffer      = '  <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf;
  156.     if (!PMA_exportOutputHandler($buffer)) {
  157.         return FALSE;
  158.     }
  159.  
  160.     while ($record = PMA_DBI_fetch_row($result)) {
  161.         $buffer         = '    <' . $table . '>' . $crlf;
  162.         for ($i = 0; $i < $columns_cnt; $i++) {
  163.             if (isset($record[$i]) && !is_null($record[$i])) {
  164.                 $buffer .= '        <' . $columns[$i] . '>' . htmlspecialchars($record[$i])
  165.                         .  '</' . $columns[$i] . '>' . $crlf;
  166.             }
  167.         }
  168.         $buffer         .= '    </' . $table . '>' . $crlf;
  169.  
  170.         if (!PMA_exportOutputHandler($buffer)) {
  171.             return FALSE;
  172.         }
  173.     }
  174.     PMA_DBI_free_result($result);
  175.  
  176.     return TRUE;
  177. } // end of the 'PMA_getTableXML()' function
  178. }
  179. }
  180. ?>
  181.