[ Index ]
 

Code source de PHP NUKE 7.9

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/includes/ -> sql_parse.php (source)

   1  <?php
   2  /***************************************************************************
   3  *                             sql_parse.php
   4  *                              -------------------
   5  *     begin                : Thu May 31, 2001
   6  *     copyright            : (C) 2001 The phpBB Group
   7  *     email                : support@phpbb.com
   8  *
   9  *     $Id: sql_parse.php,v 1.8 2002/03/18 23:53:12 psotfx Exp $
  10  *
  11  ****************************************************************************/
  12  /***************************************************************************
  13  * phpbb2 forums port version 2.0.5 (c) 2003 - Nuke Cops (http://nukecops.com)
  14  *
  15  * Ported by Nuke Cops to phpbb2 standalone 2.0.5 Test
  16  * and debugging completed by the Elite Nukers and site members.
  17  *
  18  * You run this package at your sole risk. Nuke Cops and affiliates cannot
  19  * be held liable if anything goes wrong. You are advised to test this
  20  * package on a development system. Backup everything before implementing
  21  * in a production environment. If something goes wrong, you can always
  22  * backout and restore your backups.
  23  *
  24  * Installing and running this also means you agree to the terms of the AUP
  25  * found at Nuke Cops.
  26  *
  27  * This is version 2.0.5 of the phpbb2 forum port for PHP-Nuke. Work is based
  28  * on Tom Nitzschner's forum port version 2.0.6. Tom's 2.0.6 port was based
  29  * on the phpbb2 standalone version 2.0.3. Our version 2.0.5 from Nuke Cops is
  30  * now reflecting phpbb2 standalone 2.0.5 that fixes some bugs and the
  31  * invalid_session error message.
  32  ***************************************************************************/
  33  /***************************************************************************
  34   *   This file is part of the phpBB2 port to Nuke 6.0 (c) copyright 2002
  35   *   by Tom Nitzschner (tom@toms-home.com)
  36   *   http://bbtonuke.sourceforge.net (or http://www.toms-home.com)
  37   *
  38   *   As always, make a backup before messing with anything. All code
  39   *   release by me is considered sample code only. It may be fully
  40   *   functual, but you use it at your own risk, if you break it,
  41   *   you get to fix it too. No waranty is given or implied.
  42   *
  43   *   Please post all questions/request about this port on http://bbtonuke.sourceforge.net first,
  44   *   then on my site. All original header code and copyright messages will be maintained
  45   *   to give credit where credit is due. If you modify this, the only requirement is
  46   *   that you also maintain all original copyright messages. All my work is released
  47   *   under the GNU GENERAL PUBLIC LICENSE. Please see the README for more information.
  48   *
  49   ***************************************************************************/
  50  /***************************************************************************
  51   *
  52   *   This program is free software; you can redistribute it and/or modify
  53   *   it under the terms of the GNU General Public License as published by
  54   *   the Free Software Foundation; either version 2 of the License, or
  55   *   (at your option) any later version.
  56   *
  57   ***************************************************************************/
  58  
  59  /***************************************************************************
  60  *
  61  *        These functions are mainly for use in the db_utilities under the admin
  62  *        however in order to make these functions available elsewhere, specifically
  63  *        in the installation phase of phpBB I have seperated out a couple of
  64  *        functions into this file.  JLH
  65  *
  66  \***************************************************************************/
  67  
  68  //
  69  // remove_comments will strip the sql comment lines out of an uploaded sql file
  70  // specifically for mssql and postgres type files in the install....
  71  //
  72  function remove_comments(&$output)
  73  {
  74          $lines = explode("\n", $output);
  75          $output = "";
  76  
  77          // try to keep mem. use down
  78          $linecount = count($lines);
  79  
  80          $in_comment = false;
  81          for($i = 0; $i < $linecount; $i++)
  82          {
  83                  if( preg_match("/^\/\*/", preg_quote($lines[$i])) )
  84                  {
  85                          $in_comment = true;
  86                  }
  87  
  88                  if( !$in_comment )
  89                  {
  90                          $output .= $lines[$i] . "\n";
  91                  }
  92  
  93                  if( preg_match("/\*\/$/", preg_quote($lines[$i])) )
  94                  {
  95                          $in_comment = false;
  96                  }
  97          }
  98  
  99          unset($lines);
 100          return $output;
 101  }
 102  
 103  //
 104  // remove_remarks will strip the sql comment lines out of an uploaded sql file
 105  //
 106  function remove_remarks($sql)
 107  {
 108          $lines = explode("\n", $sql);
 109  
 110          // try to keep mem. use down
 111          $sql = "";
 112  
 113          $linecount = count($lines);
 114          $output = "";
 115  
 116          for ($i = 0; $i < $linecount; $i++)
 117          {
 118                  if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0))
 119                  {
 120                          if ($lines[$i][0] != "#")
 121                          {
 122                                  $output .= $lines[$i] . "\n";
 123                          }
 124                          else
 125                          {
 126                                  $output .= "\n";
 127                          }
 128                          // Trading a bit of speed for lower mem. use here.
 129                          $lines[$i] = "";
 130                  }
 131          }
 132  
 133          return $output;
 134  
 135  }
 136  
 137  //
 138  // split_sql_file will split an uploaded sql file into single sql statements.
 139  // Note: expects trim() to have already been run on $sql.
 140  //
 141  function split_sql_file($sql, $delimiter)
 142  {
 143          // Split up our string into "possible" SQL statements.
 144          $tokens = explode($delimiter, $sql);
 145  
 146          // try to save mem.
 147          $sql = "";
 148          $output = array();
 149  
 150          // we don't actually care about the matches preg gives us.
 151          $matches = array();
 152  
 153          // this is faster than calling count($oktens) every time thru the loop.
 154          $token_count = count($tokens);
 155          for ($i = 0; $i < $token_count; $i++)
 156          {
 157                  // Don't wanna add an empty string as the last thing in the array.
 158                  if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0)))
 159                  {
 160                          // This is the total number of single quotes in the token.
 161                          $total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
 162                          // Counts single quotes that are preceded by an odd number of backslashes,
 163                          // which means they're escaped quotes.
 164                          $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
 165  
 166                          $unescaped_quotes = $total_quotes - $escaped_quotes;
 167  
 168                          // If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
 169                          if (($unescaped_quotes % 2) == 0)
 170                          {
 171                                  // It's a complete sql statement.
 172                                  $output[] = $tokens[$i];
 173                                  // save memory.
 174                                  $tokens[$i] = "";
 175                          }
 176                          else
 177                          {
 178                                  // incomplete sql statement. keep adding tokens until we have a complete one.
 179                                  // $temp will hold what we have so far.
 180                                  $temp = $tokens[$i] . $delimiter;
 181                                  // save memory..
 182                                  $tokens[$i] = "";
 183  
 184                                  // Do we have a complete statement yet?
 185                                  $complete_stmt = false;
 186  
 187                                  for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)
 188                                  {
 189                                          // This is the total number of single quotes in the token.
 190                                          $total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
 191                                          // Counts single quotes that are preceded by an odd number of backslashes,
 192                                          // which means they're escaped quotes.
 193                                          $escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
 194  
 195                                          $unescaped_quotes = $total_quotes - $escaped_quotes;
 196  
 197                                          if (($unescaped_quotes % 2) == 1)
 198                                          {
 199                                                  // odd number of unescaped quotes. In combination with the previous incomplete
 200                                                  // statement(s), we now have a complete statement. (2 odds always make an even)
 201                                                  $output[] = $temp . $tokens[$j];
 202  
 203                                                  // save memory.
 204                                                  $tokens[$j] = "";
 205                                                  $temp = "";
 206  
 207                                                  // exit the loop.
 208                                                  $complete_stmt = true;
 209                                                  // make sure the outer loop continues at the right point.
 210                                                  $i = $j;
 211                                          }
 212                                          else
 213                                          {
 214                                                  // even number of unescaped quotes. We still don't have a complete statement.
 215                                                  // (1 odd and 1 even always make an odd)
 216                                                  $temp .= $tokens[$j] . $delimiter;
 217                                                  // save memory.
 218                                                  $tokens[$j] = "";
 219                                          }
 220  
 221                                  } // for..
 222                          } // else
 223                  }
 224          }
 225  
 226          return $output;
 227  }
 228  
 229  ?>


Généré le : Sun Apr 1 11:11:59 2007 par Balluche grâce à PHPXref 0.7