Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed conflicts

Why were there conflicts merging into master?
  • Loading branch information...
commit 686ff126762c0923556036a3cf73abb9390a7e67 2 parents 918eaef + cef5bda
Phil Sturgeon authored June 11, 2012
4  .travis.yml
... ...
@@ -0,0 +1,4 @@
  1
+branches:
  2
+  except:
  3
+    - 2.1-stable
  4
+    - master
135  system/core/Input.php
@@ -365,18 +365,70 @@ function ip_address()
365 365
 	/**
366 366
 	* Validate IP Address
367 367
 	*
  368
+	* @access	public
  369
+	* @param	string
  370
+	* @param	string	ipv4 or ipv6
  371
+	* @return	bool
  372
+	*/
  373
+	public function valid_ip($ip, $which = '')
  374
+	{
  375
+		$which = strtolower($which);
  376
+
  377
+		// First check if filter_var is available
  378
+		if (is_callable('filter_var'))
  379
+		{
  380
+			switch ($which) {
  381
+				case 'ipv4':
  382
+					$flag = FILTER_FLAG_IPV4;
  383
+					break;
  384
+				case 'ipv6':
  385
+					$flag = FILTER_FLAG_IPV6;
  386
+					break;
  387
+				default:
  388
+					$flag = '';
  389
+					break;
  390
+			}
  391
+
  392
+			return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
  393
+		}
  394
+
  395
+		if ($which !== 'ipv6' && $which !== 'ipv4')
  396
+		{
  397
+			if (strpos($ip, ':') !== FALSE)
  398
+			{
  399
+				$which = 'ipv6';
  400
+			}
  401
+			elseif (strpos($ip, '.') !== FALSE)
  402
+			{
  403
+				$which = 'ipv4';
  404
+			}
  405
+			else
  406
+			{
  407
+				return FALSE;
  408
+			}
  409
+		}
  410
+
  411
+		$func = '_valid_'.$which;
  412
+		return $this->$func($ip);
  413
+	}
  414
+
  415
+	// --------------------------------------------------------------------
  416
+
  417
+	/**
  418
+	* Validate IPv4 Address
  419
+	*
368 420
 	* Updated version suggested by Geert De Deckere
369 421
 	*
370  
-	* @access	public
  422
+	* @access	protected
371 423
 	* @param	string
372  
-	* @return	string
  424
+	* @return	bool
373 425
 	*/
374  
-	function valid_ip($ip)
  426
+	protected function _valid_ipv4($ip)
375 427
 	{
376 428
 		$ip_segments = explode('.', $ip);
377 429
 
378 430
 		// Always 4 segments needed
379  
-		if (count($ip_segments) != 4)
  431
+		if (count($ip_segments) !== 4)
380 432
 		{
381 433
 			return FALSE;
382 434
 		}
@@ -385,6 +437,7 @@ function valid_ip($ip)
385 437
 		{
386 438
 			return FALSE;
387 439
 		}
  440
+
388 441
 		// Check each segment
389 442
 		foreach ($ip_segments as $segment)
390 443
 		{
@@ -402,6 +455,80 @@ function valid_ip($ip)
402 455
 	// --------------------------------------------------------------------
403 456
 
404 457
 	/**
  458
+	* Validate IPv6 Address
  459
+	*
  460
+	* @access	protected
  461
+	* @param	string
  462
+	* @return	bool
  463
+	*/
  464
+	protected function _valid_ipv6($str)
  465
+	{
  466
+		// 8 groups, separated by :
  467
+		// 0-ffff per group
  468
+		// one set of consecutive 0 groups can be collapsed to ::
  469
+
  470
+		$groups = 8;
  471
+		$collapsed = FALSE;
  472
+
  473
+		$chunks = array_filter(
  474
+			preg_split('/(:{1,2})/', $str, NULL, PREG_SPLIT_DELIM_CAPTURE)
  475
+		);
  476
+
  477
+		// Rule out easy nonsense
  478
+		if (current($chunks) == ':' OR end($chunks) == ':')
  479
+		{
  480
+			return FALSE;
  481
+		}
  482
+
  483
+		// PHP supports IPv4-mapped IPv6 addresses, so we'll expect those as well
  484
+		if (strpos(end($chunks), '.') !== FALSE)
  485
+		{
  486
+			$ipv4 = array_pop($chunks);
  487
+
  488
+			if ( ! $this->_valid_ipv4($ipv4))
  489
+			{
  490
+				return FALSE;
  491
+			}
  492
+
  493
+			$groups--;
  494
+		}
  495
+
  496
+		while ($seg = array_pop($chunks))
  497
+		{
  498
+			if ($seg[0] == ':')
  499
+			{
  500
+				if (--$groups == 0)
  501
+				{
  502
+					return FALSE;	// too many groups
  503
+				}
  504
+
  505
+				if (strlen($seg) > 2)
  506
+				{
  507
+					return FALSE;	// long separator
  508
+				}
  509
+
  510
+				if ($seg == '::')
  511
+				{
  512
+					if ($collapsed)
  513
+					{
  514
+						return FALSE;	// multiple collapsed
  515
+					}
  516
+
  517
+					$collapsed = TRUE;
  518
+				}
  519
+			}
  520
+			elseif (preg_match("/[^0-9a-f]/i", $seg) OR strlen($seg) > 4)
  521
+			{
  522
+				return FALSE; // invalid segment
  523
+			}
  524
+		}
  525
+
  526
+		return $collapsed OR $groups == 1;
  527
+	}
  528
+
  529
+	// --------------------------------------------------------------------
  530
+
  531
+	/**
405 532
 	* User Agent
406 533
 	*
407 534
 	* @access	public
12  system/database/DB_active_rec.php
@@ -255,7 +255,7 @@ public function distinct($val = TRUE)
255 255
 	 */
256 256
 	public function from($from)
257 257
 	{
258  
-		foreach ((array)$from as $val)
  258
+		foreach ((array) $from as $val)
259 259
 		{
260 260
 			if (strpos($val, ',') !== FALSE)
261 261
 			{
@@ -660,8 +660,12 @@ protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $n
660 660
 			$prefix = (count($this->ar_like) == 0) ? '' : $type;
661 661
 
662 662
 			$v = $this->escape_like_str($v);
663  
-
664  
-			if ($side == 'before')
  663
+			
  664
+			if ($side == 'none')
  665
+			{
  666
+				$like_statement = $prefix." $k $not LIKE '{$v}'";
  667
+			}
  668
+			elseif ($side == 'before')
665 669
 			{
666 670
 				$like_statement = $prefix." $k $not LIKE '%{$v}'";
667 671
 			}
@@ -1643,7 +1647,7 @@ protected function _track_aliases($table)
1643 1647
 		if (strpos($table, " ") !== FALSE)
1644 1648
 		{
1645 1649
 			// if the alias is written with the AS keyword, remove it
1646  
-			$table = preg_replace('/ AS /i', ' ', $table);
  1650
+			$table = preg_replace('/\s+AS\s+/i', ' ', $table);
1647 1651
 
1648 1652
 			// Grab the alias
1649 1653
 			$table = trim(strrchr($table, " "));
22  system/database/DB_driver.php
@@ -1263,15 +1263,20 @@ function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifier
1263 1263
 		}
1264 1264
 
1265 1265
 		// Convert tabs or multiple spaces into single spaces
1266  
-		$item = preg_replace('/[\t ]+/', ' ', $item);
  1266
+		$item = preg_replace('/\s+/', ' ', $item);
1267 1267
 
1268 1268
 		// If the item has an alias declaration we remove it and set it aside.
1269 1269
 		// Basically we remove everything to the right of the first space
1270  
-		$alias = '';
1271  
-		if (strpos($item, ' ') !== FALSE)
  1270
+		if (preg_match('/^([^\s]+) (AS )*(.+)$/i', $item, $matches))
1272 1271
 		{
1273  
-			$alias = strstr($item, " ");
1274  
-			$item = substr($item, 0, - strlen($alias));
  1272
+			$item = $matches[1];
  1273
+
  1274
+			// Escape the alias
  1275
+			$alias = ' '.$matches[2].$this->_escape_identifiers($matches[3]);
  1276
+		}
  1277
+		else
  1278
+		{
  1279
+			$alias = '';
1275 1280
 		}
1276 1281
 
1277 1282
 		// This is basically a bug fix for queries that use MAX, MIN, etc.
@@ -1387,7 +1392,7 @@ function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifier
1387 1392
 
1388 1393
 		return $item.$alias;
1389 1394
 	}
1390  
-	
  1395
+
1391 1396
 	// --------------------------------------------------------------------
1392 1397
 
1393 1398
 	/**
@@ -1395,16 +1400,13 @@ function _protect_identifiers($item, $prefix_single = FALSE, $protect_identifier
1395 1400
 	 *
1396 1401
 	 * This function is used extensively by every db driver.
1397 1402
 	 *
1398  
-	 * @access	private
1399 1403
 	 * @return	void
1400 1404
 	 */
1401 1405
 	protected function _reset_select()
1402 1406
 	{
1403  
-	
1404 1407
 	}
1405 1408
 
1406 1409
 }
1407 1410
 
1408  
-
1409 1411
 /* End of file DB_driver.php */
1410  
-/* Location: ./system/database/DB_driver.php */
  1412
+/* Location: ./system/database/DB_driver.php */
29  system/database/drivers/pdo/pdo_driver.php
@@ -51,23 +51,23 @@ class CI_DB_pdo_driver extends CI_DB {
51 51
 	function __construct($params)
52 52
 	{
53 53
 		parent::__construct($params);
54  
-		
  54
+
55 55
 		// clause and character used for LIKE escape sequences
56 56
 		if (strpos($this->hostname, 'mysql') !== FALSE)
57 57
 		{
58 58
 			$this->_like_escape_str = '';
59 59
 			$this->_like_escape_chr = '';
60  
-			
  60
+
61 61
 			//Prior to this version, the charset can't be set in the dsn
62 62
 			if(is_php('5.3.6'))
63 63
 			{
64 64
 				$this->hostname .= ";charset={$this->char_set}";
65 65
 			}
66  
-			
  66
+
67 67
 			//Set the charset with the connection options
68 68
 			$this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
69 69
 		}
70  
-		else if (strpos($this->hostname, 'odbc') !== FALSE)
  70
+		elseif (strpos($this->hostname, 'odbc') !== FALSE)
71 71
 		{
72 72
 			$this->_like_escape_str = " {escape '%s'} ";
73 73
 			$this->_like_escape_chr = '!';
@@ -77,9 +77,9 @@ function __construct($params)
77 77
 			$this->_like_escape_str = " ESCAPE '%s' ";
78 78
 			$this->_like_escape_chr = '!';
79 79
 		}
80  
-		
81  
-		$this->hostname .= ";dbname=".$this->database;
82  
-		
  80
+
  81
+		empty($this->database) OR $this->hostname .= ';dbname='.$this->database;
  82
+
83 83
 		$this->trans_enabled = FALSE;
84 84
 
85 85
 		$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
@@ -94,7 +94,7 @@ function __construct($params)
94 94
 	function db_connect()
95 95
 	{
96 96
 		$this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
97  
-		
  97
+
98 98
 		return new PDO($this->hostname, $this->username, $this->password, $this->options);
99 99
 	}
100 100
 
@@ -189,11 +189,20 @@ function _version()
189 189
 	function _execute($sql)
190 190
 	{
191 191
 		$sql = $this->_prep_query($sql);
192  
-		$result_id = $this->conn_id->query($sql);
  192
+		$result_id = $this->conn_id->prepare($sql);
  193
+		$result_id->execute();
193 194
 		
194 195
 		if (is_object($result_id))
195 196
 		{
196  
-			$this->affect_rows = $result_id->rowCount();
  197
+			if (is_numeric(stripos($sql, 'SELECT')))
  198
+			{
  199
+				$this->affect_rows = count($result_id->fetchAll());
  200
+				$result_id->execute();
  201
+			}
  202
+			else
  203
+			{
  204
+				$this->affect_rows = $result_id->rowCount();
  205
+			}
197 206
 		}
198 207
 		else
199 208
 		{
13  system/database/drivers/pdo/pdo_result.php
@@ -34,7 +34,18 @@ class CI_DB_pdo_result extends CI_DB_result {
34 34
 	 */
35 35
 	function num_rows()
36 36
 	{
37  
-		return $this->result_id->rowCount();
  37
+		if (is_numeric(stripos($this->result_id->queryString, 'SELECT')))
  38
+		{
  39
+			$dbh = $this->conn_id;
  40
+			$query = $dbh->query($this->result_id->queryString);
  41
+			$result = $query->fetchAll();
  42
+			unset($dbh, $query);
  43
+			return count($result);
  44
+		}
  45
+		else
  46
+		{
  47
+			return $this->result_id->rowCount();	
  48
+		}
38 49
 	}
39 50
 
40 51
 	// --------------------------------------------------------------------
2  system/libraries/Driver.php
@@ -30,7 +30,7 @@
30 30
 class CI_Driver_Library {
31 31
 
32 32
 	protected $valid_drivers	= array();
33  
-	protected static $lib_name;
  33
+	protected $lib_name;
34 34
 
35 35
 	// The first time a child is used it won't exist, so we instantiate it
36 36
 	// subsequents calls will go straight to the proper child.
5  system/libraries/Form_validation.php
@@ -1079,11 +1079,12 @@ public function valid_emails($str)
1079 1079
 	 *
1080 1080
 	 * @access	public
1081 1081
 	 * @param	string
  1082
+	 * @param	string "ipv4" or "ipv6" to validate a specific ip format
1082 1083
 	 * @return	string
1083 1084
 	 */
1084  
-	public function valid_ip($ip)
  1085
+	public function valid_ip($ip, $which = '')
1085 1086
 	{
1086  
-		return $this->CI->input->valid_ip($ip);
  1087
+		return $this->CI->input->valid_ip($ip, $which);
1087 1088
 	}
1088 1089
 
1089 1090
 	// --------------------------------------------------------------------
2  system/libraries/Image_lib.php
@@ -104,7 +104,7 @@ public function __construct($props = array())
104 104
 	 */
105 105
 	function clear()
106 106
 	{
107  
-		$props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');
  107
+		$props = array('source_folder', 'dest_folder', 'source_image', 'full_src_path', 'full_dst_path', 'new_image', 'image_type', 'size_str', 'quality', 'orig_width', 'orig_height', 'width', 'height', 'rotation_angle', 'x_axis', 'y_axis', 'create_fnc', 'copy_fnc', 'wm_overlay_path', 'wm_use_truetype', 'dynamic_output', 'wm_font_size', 'wm_text', 'wm_vrt_alignment', 'wm_hor_alignment', 'wm_padding', 'wm_hor_offset', 'wm_vrt_offset', 'wm_font_color', 'wm_use_drop_shadow', 'wm_shadow_color', 'wm_shadow_distance', 'wm_opacity');
108 108
 
109 109
 		foreach ($props as $val)
110 110
 		{
6  user_guide/changelog.html
@@ -69,6 +69,8 @@
69 69
 	<li>Libraries
70 70
 		<ul>
71 71
 			<li>Further improved MIME type detection in the <a href="libraries/file_uploading.html">File Uploading Library</a>.</li>
  72
+			<li>Added support for IPv6 to the <a href="libraries/input.html">Input Library</a>.</li>
  73
+			<li>Added support for the IP format parameter to the <a href="libraries/form_validation.html">Form Validation Library</a>.</li>
72 74
 		</ul>
73 75
 	</li>
74 76
 	<li>Helpers
@@ -86,6 +88,10 @@
86 88
 	<li>Fixed a bug (#538) - Windows paths were ignored when using the <a href="libraries/image_lib.html">Image Manipulation Class</a> to create a new file.</li>
87 89
 	<li>Fixed a bug - When database caching was enabled, $this->db->query() checked the cache before binding variables which resulted in cached queries never being found.</li>
88 90
 	<li>Fixed a bug - CSRF cookie value was allowed to be any (non-empty) string before being written to the output, making code injection a risk.</li>
  91
+	<li>Fixed a bug (#726) - PDO put a 'dbname' argument in it's connection string regardless of the database platform in use, which made it impossible to use SQLite.</li>
  92
+	<li>Fixed a bug - CI_DB_pdo_result::num_rows() was not returning properly value with SELECT queries, cause it was relying on PDOStatement::rowCount().</li>
  93
+	<li>Fixed a bug (#1059) - CI_Image_lib::clear() was not correctly clearing all necessary object properties, namely width and height.</li>
  94
+	<li>Fixed a bug (#1387) - Active Record's <samp>from()</samp> method didn't escape table aliases.</li>
89 95
 </ul>
90 96
 
91 97
 
7  user_guide/installation/upgrade_211.html
@@ -3,7 +3,7 @@
3 3
 <head>
4 4
 
5 5
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6  
-<title>Upgrading from 2.0.3 to 2.1.0 : CodeIgniter User Guide</title>
  6
+<title>Upgrading from 2.1.0 to 2.1.1 : CodeIgniter User Guide</title>
7 7
 
8 8
 <style type='text/css' media='all'>@import url('../userguide.css');</style>
9 9
 <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
@@ -69,6 +69,11 @@
69 69
 
70 70
 <p>This config file has been updated to contain more user mime-types, please copy it to <kbd>application/config/mimes.php</kbd>.</p>
71 71
 
  72
+<h2>Step 3: Update your IP address tables:</h2>
  73
+
  74
+<p>This upgrade adds support for IPv6 IP addresses. In order to store them, you need to enlarge your <var>ip_address</var> columns to 45 characters. For example, CodeIgniter's session table will need to change:</p>
  75
+
  76
+<code>ALTER TABLE ci_sessions CHANGE ip_address ip_address varchar(45) default '0' NOT NULL</code>
72 77
 
73 78
 </div>
74 79
 <!-- END CONTENT -->
2  user_guide/libraries/form_validation.html
@@ -1058,7 +1058,7 @@
1058 1058
 	<tr>
1059 1059
 		<td class="td"><strong>valid_ip</strong></td>
1060 1060
 		<td class="td">No</td>
1061  
-		<td class="td">Returns FALSE if the supplied IP is not valid.</td>
  1061
+		<td class="td">Returns FALSE if the supplied IP is not valid. Accepts an optional parameter of "IPv4" or "IPv6" to specify an IP format.</td>
1062 1062
 		<td class="td">&nbsp;</td>
1063 1063
 	</tr>
1064 1064
 
2  user_guide/libraries/input.html
@@ -248,7 +248,7 @@
248 248
 {<br />
249 249
 &nbsp;&nbsp;&nbsp;&nbsp; echo 'Valid';<br />
250 250
 }</code>
251  
-
  251
+<p>Accepts an optional second string parameter of "IPv4" or "IPv6" to specify an IP format. The default checks for both formats.</p> 
252 252
 
253 253
 <h2>$this->input->user_agent()</h2>
254 254
 <p>Returns the user agent (web browser) being used by the current user. Returns FALSE if it's not available.</p>
2  user_guide/libraries/sessions.html
@@ -221,7 +221,7 @@
221 221
 <textarea class="textarea" style="width:100%" cols="50" rows="10">
222 222
 CREATE TABLE IF NOT EXISTS  `ci_sessions` (
223 223
 	session_id varchar(40) DEFAULT '0' NOT NULL,
224  
-	ip_address varchar(16) DEFAULT '0' NOT NULL,
  224
+	ip_address varchar(45) DEFAULT '0' NOT NULL,
225 225
 	user_agent varchar(120) NOT NULL,
226 226
 	last_activity int(10) unsigned DEFAULT 0 NOT NULL,
227 227
 	user_data text NOT NULL,
2  user_guide/libraries/uri.html
@@ -191,7 +191,7 @@
191 191
 
192 192
 <p>The function would return this:</p>
193 193
 
194  
-<code>/news/local/345</code>
  194
+<code>news/local/345</code>
195 195
 
196 196
 
197 197
 <h2>$this->uri->ruri_string()</h2>

0 notes on commit 686ff12

Please sign in to comment.
Something went wrong with that request. Please try again.