GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( e54387...b62a26 )
by Lonnie
10s
created
application/database/seeds/FlatAuthorizationSeeder.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 
11 11
 	public function run()
12 12
 	{
13
-	    $flat = new \Myth\Auth\FlatAuthorization();
13
+		$flat = new \Myth\Auth\FlatAuthorization();
14 14
 
15 15
 		$flat->createPermission('viewPosts', 'View the blog posts.');
16 16
 		$flat->createPermission('managePosts', 'Manage the blog posts.');
Please login to merge, or discard this patch.
application/database/seeds/TestSeeder.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class TestSeeder extends Seeder {
10 10
     
11
-    public function run()
12
-    {
13
-        /*
11
+	public function run()
12
+	{
13
+		/*
14 14
             Here, you can do anything you need to do to get your
15 15
             database in the desired state. The following tools are ready for you:
16 16
 
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 
24 24
                 $this->call('UserSeeder');
25 25
          */
26
-    }
26
+	}
27 27
     
28
-    //--------------------------------------------------------------------
28
+	//--------------------------------------------------------------------
29 29
     
30 30
 }
Please login to merge, or discard this patch.
application/libraries/MY_Form_validation.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -3,117 +3,117 @@
 block discarded – undo
3 3
 if (! class_exists('MY_Form_validation'))
4 4
 {
5 5
 
6
-    class MY_Form_validation extends CI_Form_validation {
7
-        /**
8
-         * @var object The CodeIgniter core object.
9
-         */
10
-        public $CI;
11
-
12
-        //--------------------------------------------------------------------
13
-
14
-        /**
15
-         * Check if the field has an error associated with it.
16
-         *
17
-         * @param string $field The name of the field
18
-         *
19
-         * @return bool
20
-         */
21
-        public function has_error( $field = NULL )
22
-        {
23
-            if ( empty( $field ) )
24
-            {
25
-                return FALSE;
26
-            }
27
-
28
-            return ! empty( $this->_field_data[ $field ]['error'] );
29
-        }
30
-
31
-        //--------------------------------------------------------------------
32
-
33
-        /**
34
-         * Performs the actual form validation
35
-         *
36
-         * @param string $module Name of the module
37
-         * @param string $group Name of the group array containing the rules
38
-         *
39
-         * @return bool Success or Failure
40
-         */
41
-        public function run($group = '', $module = '')
42
-        {
43
-            is_object($module) && $this->CI =& $module;
44
-            return parent::run($group);
45
-        }
46
-
47
-        //--------------------------------------------------------------------
48
-
49
-        //--------------------------------------------------------------------
50
-        // Validation Rules
51
-        //--------------------------------------------------------------------
52
-
53
-        /**
54
-         * Checks that a value is unique in the database.
55
-         *
56
-         * i.e. '…|required|unique[users.name,users.id]|trim…'
57
-         *
58
-         * <code>
59
-         * "unique[tablename.fieldname,tablename.(primaryKey-used-for-updates)]"
60
-         * </code>
61
-         *
62
-         * @author Adapted from Burak Guzel <http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/>
63
-         *
64
-         * @param mixed $value The value to be checked.
65
-         * @param mixed $params The table and field to check against, if a second
66
-         * field is passed in this is used as "AND NOT EQUAL".
67
-         *
68
-         * @return bool True if the value is unique for that field, else false.
69
-         */
70
-        public function is_unique( $value, $params )
71
-        {
72
-            if ( empty( $this->CI->db ) )
73
-            {
74
-                $this->CI->load->database();
75
-            }
76
-
77
-            // Allow for more than 1 parameter.
78
-            $fields = explode( ",", $params );
79
-
80
-            // Extract the table and field from the first parameter.
81
-            list( $table, $field ) = explode( '.', $fields[0], 2 );
82
-
83
-            // Setup the db request.
84
-            $this->CI->db->select( $field )
85
-                         ->from( $table )
86
-                         ->where( $field, $value )
87
-                         ->limit( 1 );
88
-
89
-            // Check whether a second parameter was passed to be used as an
90
-            // "AND NOT EQUAL" where clause
91
-            // eg "select * from users where users.name='test' AND users.id != 4
92
-            if ( isset( $fields[1] ) )
93
-            {
94
-                // Extract the table and field from the second parameter
95
-                list( $where_table, $where_field ) = explode( '.', $fields[1], 2 );
96
-
97
-                // Get the value from the post's $where_field. If the value is set,
98
-                // add "AND NOT EQUAL" where clause.
99
-                $where_value = $this->CI->input->post( $where_field );
100
-                if ( isset( $where_value ) )
101
-                {
102
-                    $this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value );
103
-                }
104
-            }
105
-
106
-            // If any rows are returned from the database, validation fails
107
-            $query = $this->CI->db->get();
108
-            if ( $query->row() )
109
-            {
110
-                $this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' );
111
-
112
-                return FALSE;
113
-            }
114
-
115
-            return TRUE;
116
-        }
117
-    }
6
+	class MY_Form_validation extends CI_Form_validation {
7
+		/**
8
+		 * @var object The CodeIgniter core object.
9
+		 */
10
+		public $CI;
11
+
12
+		//--------------------------------------------------------------------
13
+
14
+		/**
15
+		 * Check if the field has an error associated with it.
16
+		 *
17
+		 * @param string $field The name of the field
18
+		 *
19
+		 * @return bool
20
+		 */
21
+		public function has_error( $field = NULL )
22
+		{
23
+			if ( empty( $field ) )
24
+			{
25
+				return FALSE;
26
+			}
27
+
28
+			return ! empty( $this->_field_data[ $field ]['error'] );
29
+		}
30
+
31
+		//--------------------------------------------------------------------
32
+
33
+		/**
34
+		 * Performs the actual form validation
35
+		 *
36
+		 * @param string $module Name of the module
37
+		 * @param string $group Name of the group array containing the rules
38
+		 *
39
+		 * @return bool Success or Failure
40
+		 */
41
+		public function run($group = '', $module = '')
42
+		{
43
+			is_object($module) && $this->CI =& $module;
44
+			return parent::run($group);
45
+		}
46
+
47
+		//--------------------------------------------------------------------
48
+
49
+		//--------------------------------------------------------------------
50
+		// Validation Rules
51
+		//--------------------------------------------------------------------
52
+
53
+		/**
54
+		 * Checks that a value is unique in the database.
55
+		 *
56
+		 * i.e. '…|required|unique[users.name,users.id]|trim…'
57
+		 *
58
+		 * <code>
59
+		 * "unique[tablename.fieldname,tablename.(primaryKey-used-for-updates)]"
60
+		 * </code>
61
+		 *
62
+		 * @author Adapted from Burak Guzel <http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/>
63
+		 *
64
+		 * @param mixed $value The value to be checked.
65
+		 * @param mixed $params The table and field to check against, if a second
66
+		 * field is passed in this is used as "AND NOT EQUAL".
67
+		 *
68
+		 * @return bool True if the value is unique for that field, else false.
69
+		 */
70
+		public function is_unique( $value, $params )
71
+		{
72
+			if ( empty( $this->CI->db ) )
73
+			{
74
+				$this->CI->load->database();
75
+			}
76
+
77
+			// Allow for more than 1 parameter.
78
+			$fields = explode( ",", $params );
79
+
80
+			// Extract the table and field from the first parameter.
81
+			list( $table, $field ) = explode( '.', $fields[0], 2 );
82
+
83
+			// Setup the db request.
84
+			$this->CI->db->select( $field )
85
+						 ->from( $table )
86
+						 ->where( $field, $value )
87
+						 ->limit( 1 );
88
+
89
+			// Check whether a second parameter was passed to be used as an
90
+			// "AND NOT EQUAL" where clause
91
+			// eg "select * from users where users.name='test' AND users.id != 4
92
+			if ( isset( $fields[1] ) )
93
+			{
94
+				// Extract the table and field from the second parameter
95
+				list( $where_table, $where_field ) = explode( '.', $fields[1], 2 );
96
+
97
+				// Get the value from the post's $where_field. If the value is set,
98
+				// add "AND NOT EQUAL" where clause.
99
+				$where_value = $this->CI->input->post( $where_field );
100
+				if ( isset( $where_value ) )
101
+				{
102
+					$this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value );
103
+				}
104
+			}
105
+
106
+			// If any rows are returned from the database, validation fails
107
+			$query = $this->CI->db->get();
108
+			if ( $query->row() )
109
+			{
110
+				$this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' );
111
+
112
+				return FALSE;
113
+			}
114
+
115
+			return TRUE;
116
+		}
117
+	}
118 118
 
119 119
 }
Please login to merge, or discard this patch.
application/libraries/Migration.php 1 patch
Indentation   +508 added lines, -508 removed lines patch added patch discarded remove patch
@@ -51,415 +51,415 @@  discard block
 block discarded – undo
51 51
  */
52 52
 class CI_Migration {
53 53
 
54
-    /**
55
-     * Whether the library is enabled
56
-     *
57
-     * @var bool
58
-     */
59
-    protected $_migration_enabled = FALSE;
60
-
61
-    /**
62
-     * Migration numbering type
63
-     *
64
-     * @var	bool
65
-     */
66
-    protected $_migration_type = 'sequential';
67
-
68
-    /**
69
-     * Path to migration classes
70
-     *
71
-     * @var string
72
-     */
73
-    protected  $_migration_paths = NULL;
74
-
75
-    /**
76
-     * Current migration version
77
-     *
78
-     * @var mixed
79
-     */
80
-    protected $_migration_version = 0;
81
-
82
-    /**
83
-     * Database table with migration info
84
-     *
85
-     * @var string
86
-     */
87
-    protected $_migration_table = 'migrations';
88
-
89
-    /**
90
-     * Whether to automatically run migrations
91
-     *
92
-     * @var	bool
93
-     */
94
-    protected $_migration_auto_latest = FALSE;
95
-
96
-    /**
97
-     * Migration basename regex
98
-     *
99
-     * @var bool
100
-     */
101
-    protected $_migration_regex = NULL;
102
-
103
-    /**
104
-     * Error message
105
-     *
106
-     * @var string
107
-     */
108
-    protected $_error_string = '';
109
-
110
-    /**
111
-     * Initialize Migration Class
112
-     *
113
-     * @param	array	$config
114
-     * @return	void
115
-     */
116
-    public function __construct($config = array())
117
-    {
118
-        // Only run this constructor on main library load
119
-        if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE))
120
-        {
121
-            return;
122
-        }
123
-
124
-        foreach ($config as $key => $val)
125
-        {
126
-            $this->{'_'.$key} = $val;
127
-        }
128
-
129
-        log_message('debug', 'Migrations class initialized');
130
-
131
-        // Are they trying to use migrations while it is disabled?
132
-        if ($this->_migration_enabled !== TRUE)
133
-        {
134
-            show_error('Migrations has been loaded but is disabled or set up incorrectly.');
135
-        }
136
-
137
-        // If not set, set it
138
-        count($this->_migration_paths) OR $this->_migration_paths = array(APPPATH.'database/migrations/');
139
-
140
-        // Add trailing slash if not set
141
-        foreach ($this->_migration_paths as $alias => $path) {
142
-            $this->_migration_paths[$alias] = rtrim($this->_migration_paths[$alias], '/') . '/';
143
-        }
144
-
145
-        // Load migration language
146
-        $this->lang->load('migration');
147
-
148
-        // They'll probably be using dbforge
149
-        $this->load->dbforge();
150
-
151
-        // Make sure the migration table name was set.
152
-        if (empty($this->_migration_table))
153
-        {
154
-            show_error('Migrations configuration file (migration.php) must have "migration_table" set.');
155
-        }
156
-
157
-        // Migration basename regex
158
-        $this->_migration_regex = ($this->_migration_type === 'timestamp')
159
-            ? '/^\d{14}_(\w+)$/'
160
-            : '/^\d{3}_(\w+)$/';
161
-
162
-        // Make sure a valid migration numbering type was set.
163
-        if ( ! in_array($this->_migration_type, array('sequential', 'timestamp')))
164
-        {
165
-            show_error('An invalid migration numbering type was specified: '.$this->_migration_type);
166
-        }
167
-
168
-        // If the migrations table is missing, make it
169
-        if ( ! $this->db->table_exists($this->_migration_table))
170
-        {
171
-            $this->dbforge->add_field(array(
172
-                'version' => array('type' => 'BIGINT', 'constraint' => 20),
173
-                'alias' => array('type' => 'VARCHAR', 'constraint' => 255),
174
-                'ondate'  => array('type' => 'DATETIME')
175
-            ));
176
-
177
-            $this->dbforge->add_key('alias');
178
-
179
-            $this->dbforge->create_table($this->_migration_table, TRUE);
180
-        }
181
-
182
-        // Do we auto migrate to the latest migration?
183
-        if ($this->_migration_auto_latest === TRUE && ! $this->latest())
184
-        {
185
-            show_error($this->error_string());
186
-        }
187
-
188
-    }
189
-
190
-    // --------------------------------------------------------------------
191
-
192
-    /**
193
-     * Migrate to a schema version
194
-     *
195
-     * Calls each migration step required to get to the schema version of
196
-     * choice
197
-     *
198
-     * @param string $type  Any key from _migration_paths, or {module_name}
199
-     * @param	string	$target_version	Target schema version
200
-     *
201
-     * @return	mixed	TRUE if already latest, FALSE if failed, string if upgraded
202
-     */
203
-    public function version($type='all', $target_version)
204
-    {
205
-        // Note: We use strings, so that timestamp versions work on 32-bit systems
206
-        $current_version = $this->get_version($type);
207
-
208
-        if ($this->_migration_type === 'sequential')
209
-        {
210
-            $target_version = sprintf('%03d', $target_version);
211
-        }
212
-        else
213
-        {
214
-            $target_version = (string) $target_version;
215
-        }
216
-
217
-        $migrations = $this->find_migrations($type);
218
-
219
-        if ($target_version > 0 && ! isset($migrations[$target_version]))
220
-        {
221
-            $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version);
222
-            return FALSE;
223
-        }
224
-
225
-        if ($target_version > $current_version)
226
-        {
227
-            // Moving Up
228
-            $method = 'up';
229
-        }
230
-        else
231
-        {
232
-            // Moving Down, apply in reverse order
233
-            $method = 'down';
234
-            krsort($migrations);
235
-        }
236
-
237
-        if (empty($migrations))
238
-        {
239
-            return TRUE;
240
-        }
241
-
242
-        $previous = FALSE;
243
-
244
-        // Validate all available migrations, and run the ones within our target range
245
-        foreach ($migrations as $number => $file)
246
-        {
247
-            // Check for sequence gaps
248
-            if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1)
249
-            {
250
-                $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number);
251
-                return FALSE;
252
-            }
253
-
254
-            include_once($file);
255
-            $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php'))));
256
-
257
-            // Validate the migration file structure
258
-            if ( ! class_exists($class, FALSE))
259
-            {
260
-                $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class);
261
-                return FALSE;
262
-            }
263
-
264
-            $previous = $number;
265
-
266
-            // Run migrations that are inside the target range
267
-            if (
268
-                ($method === 'up'   && $number > $current_version && $number <= $target_version) OR
269
-                ($method === 'down' && $number <= $current_version && $number > $target_version)
270
-            )
271
-            {
272
-                $instance = new $class();
273
-                if ( ! is_callable(array($instance, $method)))
274
-                {
275
-                    $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class);
276
-                    return FALSE;
277
-                }
278
-
279
-                log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number);
280
-                call_user_func(array($instance, $method));
281
-                $current_version = $number;
282
-                $this->_update_version($type, $current_version);
283
-            }
284
-        }
285
-
286
-        // This is necessary when moving down, since the the last migration applied
287
-        // will be the down() method for the next migration up from the target
288
-        if ($current_version <> $target_version)
289
-        {
290
-            $current_version = $target_version;
291
-            $this->_update_version($type, $current_version);
292
-        }
293
-
294
-        log_message('debug', 'Finished migrating to '.$current_version);
295
-
296
-        return $current_version;
297
-    }
298
-
299
-    // --------------------------------------------------------------------
300
-
301
-    /**
302
-     * Sets the schema to the latest migration
303
-     *
304
-     * @param string $type  Any key from _migration_paths, or {module_name}
305
-     *
306
-     * @return	mixed	TRUE if already latest, FALSE if failed, string if upgraded
307
-     */
308
-    public function latest($type='app')
309
-    {
310
-        $last_migration = $this->get_latest($type);
311
-
312
-        // Calculate the last migration step from existing migration
313
-        // filenames and proceed to the standard version migration
314
-        return $this->version($type, $this->_get_migration_number($last_migration));
315
-    }
316
-
317
-    // --------------------------------------------------------------------
318
-
319
-    /**
320
-     * Retrieves the latest migration version available.
321
-     *
322
-     * @param string $type  Any key from _migration_paths, or {module_name}
323
-     *
324
-     * @return bool|string
325
-     */
326
-    public function get_latest($type='app')
327
-    {
328
-        $migrations = $this->find_migrations($type);
329
-
330
-        if (empty($migrations))
331
-        {
332
-            $this->_error_string = $this->lang->line('migration_none_found');
333
-            return FALSE;
334
-        }
335
-
336
-        return basename(end($migrations));
337
-    }
338
-
339
-    //--------------------------------------------------------------------
340
-
341
-
342
-
343
-    /**
344
-     * Sets the schema to the migration version set in config
345
-     *
346
-     * @return	mixed	TRUE if already current, FALSE if failed, string if upgraded
347
-     */
348
-    public function current()
349
-    {
350
-        return $this->version($this->_migration_version);
351
-    }
352
-
353
-    // --------------------------------------------------------------------
354
-
355
-    /**
356
-     * Error string
357
-     *
358
-     * @return	string	Error message returned as a string
359
-     */
360
-    public function error_string()
361
-    {
362
-        return $this->_error_string;
363
-    }
364
-
365
-    // --------------------------------------------------------------------
366
-
367
-    /**
368
-     * Retrieves list of available migration scripts
369
-     *
370
-     * @return	array	list of migration file paths sorted by version
371
-     */
372
-    public function find_migrations($type='app')
373
-    {
374
-        $migrations = array();
375
-
376
-        $path = $this->determine_migration_path($type);
377
-
378
-        // Load all *_*.php files in the migrations path
379
-        foreach (glob($path.'*_*.php') as $file)
380
-        {
381
-            $name = basename($file, '.php');
382
-
383
-            // Filter out non-migration files
384
-            if (preg_match($this->_migration_regex, $name))
385
-            {
386
-                $number = $this->_get_migration_number($name);
387
-
388
-                // There cannot be duplicate migration numbers
389
-                if (isset($migrations[$number]))
390
-                {
391
-                    $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number);
392
-                    show_error($this->_error_string);
393
-                }
394
-
395
-                $migrations[$number] = $file;
396
-            }
397
-        }
398
-
399
-        ksort($migrations);
400
-        return $migrations;
401
-    }
402
-
403
-    // --------------------------------------------------------------------
404
-
405
-    /**
406
-     * Retrieves current schema version
407
-     *
408
-     * @return	string	Current migration version
409
-     */
410
-    public function get_version($type='app')
411
-    {
412
-        $row = $this->db->select('version')
413
-                        ->where('alias', $type)
414
-                        ->get($this->_migration_table)
415
-                        ->row();
416
-
417
-        return $row ? $row->version : '0';
418
-    }
419
-
420
-    // --------------------------------------------------------------------
421
-
422
-    /**
423
-     * Given the string for the name of the file, will
424
-     * generate the rest of the filename based on the current
425
-     * $config['migration_type'] setting.
426
-     *
427
-     * @param $name
428
-     * @return string The final name (with extension)
429
-     */
430
-    public function make_name($name)
431
-    {
432
-        if (empty($name))
433
-        {
434
-            return null;
435
-        }
436
-
437
-        if ($this->_migration_type == 'timestamp')
438
-        {
439
-            $prefix = date('YmdHis');
440
-        }
441
-        else
442
-        {
443
-            $prefix = str_pad($this->get_version() + 1, 3, '0', STR_PAD_LEFT);
444
-        }
445
-
446
-        return $prefix .'_'. ucfirst(strtolower($name)) .'.php';
447
-    }
448
-
449
-    //--------------------------------------------------------------------
450
-
451
-    /**
452
-     * Enable the use of CI super-global
453
-     *
454
-     * @param	string	$var
455
-     * @return	mixed
456
-     */
457
-    public function __get($var)
458
-    {
459
-        return get_instance()->$var;
460
-    }
461
-
462
-    //--------------------------------------------------------------------
54
+	/**
55
+	 * Whether the library is enabled
56
+	 *
57
+	 * @var bool
58
+	 */
59
+	protected $_migration_enabled = FALSE;
60
+
61
+	/**
62
+	 * Migration numbering type
63
+	 *
64
+	 * @var	bool
65
+	 */
66
+	protected $_migration_type = 'sequential';
67
+
68
+	/**
69
+	 * Path to migration classes
70
+	 *
71
+	 * @var string
72
+	 */
73
+	protected  $_migration_paths = NULL;
74
+
75
+	/**
76
+	 * Current migration version
77
+	 *
78
+	 * @var mixed
79
+	 */
80
+	protected $_migration_version = 0;
81
+
82
+	/**
83
+	 * Database table with migration info
84
+	 *
85
+	 * @var string
86
+	 */
87
+	protected $_migration_table = 'migrations';
88
+
89
+	/**
90
+	 * Whether to automatically run migrations
91
+	 *
92
+	 * @var	bool
93
+	 */
94
+	protected $_migration_auto_latest = FALSE;
95
+
96
+	/**
97
+	 * Migration basename regex
98
+	 *
99
+	 * @var bool
100
+	 */
101
+	protected $_migration_regex = NULL;
102
+
103
+	/**
104
+	 * Error message
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $_error_string = '';
109
+
110
+	/**
111
+	 * Initialize Migration Class
112
+	 *
113
+	 * @param	array	$config
114
+	 * @return	void
115
+	 */
116
+	public function __construct($config = array())
117
+	{
118
+		// Only run this constructor on main library load
119
+		if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE))
120
+		{
121
+			return;
122
+		}
123
+
124
+		foreach ($config as $key => $val)
125
+		{
126
+			$this->{'_'.$key} = $val;
127
+		}
128
+
129
+		log_message('debug', 'Migrations class initialized');
130
+
131
+		// Are they trying to use migrations while it is disabled?
132
+		if ($this->_migration_enabled !== TRUE)
133
+		{
134
+			show_error('Migrations has been loaded but is disabled or set up incorrectly.');
135
+		}
136
+
137
+		// If not set, set it
138
+		count($this->_migration_paths) OR $this->_migration_paths = array(APPPATH.'database/migrations/');
139
+
140
+		// Add trailing slash if not set
141
+		foreach ($this->_migration_paths as $alias => $path) {
142
+			$this->_migration_paths[$alias] = rtrim($this->_migration_paths[$alias], '/') . '/';
143
+		}
144
+
145
+		// Load migration language
146
+		$this->lang->load('migration');
147
+
148
+		// They'll probably be using dbforge
149
+		$this->load->dbforge();
150
+
151
+		// Make sure the migration table name was set.
152
+		if (empty($this->_migration_table))
153
+		{
154
+			show_error('Migrations configuration file (migration.php) must have "migration_table" set.');
155
+		}
156
+
157
+		// Migration basename regex
158
+		$this->_migration_regex = ($this->_migration_type === 'timestamp')
159
+			? '/^\d{14}_(\w+)$/'
160
+			: '/^\d{3}_(\w+)$/';
161
+
162
+		// Make sure a valid migration numbering type was set.
163
+		if ( ! in_array($this->_migration_type, array('sequential', 'timestamp')))
164
+		{
165
+			show_error('An invalid migration numbering type was specified: '.$this->_migration_type);
166
+		}
167
+
168
+		// If the migrations table is missing, make it
169
+		if ( ! $this->db->table_exists($this->_migration_table))
170
+		{
171
+			$this->dbforge->add_field(array(
172
+				'version' => array('type' => 'BIGINT', 'constraint' => 20),
173
+				'alias' => array('type' => 'VARCHAR', 'constraint' => 255),
174
+				'ondate'  => array('type' => 'DATETIME')
175
+			));
176
+
177
+			$this->dbforge->add_key('alias');
178
+
179
+			$this->dbforge->create_table($this->_migration_table, TRUE);
180
+		}
181
+
182
+		// Do we auto migrate to the latest migration?
183
+		if ($this->_migration_auto_latest === TRUE && ! $this->latest())
184
+		{
185
+			show_error($this->error_string());
186
+		}
187
+
188
+	}
189
+
190
+	// --------------------------------------------------------------------
191
+
192
+	/**
193
+	 * Migrate to a schema version
194
+	 *
195
+	 * Calls each migration step required to get to the schema version of
196
+	 * choice
197
+	 *
198
+	 * @param string $type  Any key from _migration_paths, or {module_name}
199
+	 * @param	string	$target_version	Target schema version
200
+	 *
201
+	 * @return	mixed	TRUE if already latest, FALSE if failed, string if upgraded
202
+	 */
203
+	public function version($type='all', $target_version)
204
+	{
205
+		// Note: We use strings, so that timestamp versions work on 32-bit systems
206
+		$current_version = $this->get_version($type);
207
+
208
+		if ($this->_migration_type === 'sequential')
209
+		{
210
+			$target_version = sprintf('%03d', $target_version);
211
+		}
212
+		else
213
+		{
214
+			$target_version = (string) $target_version;
215
+		}
216
+
217
+		$migrations = $this->find_migrations($type);
218
+
219
+		if ($target_version > 0 && ! isset($migrations[$target_version]))
220
+		{
221
+			$this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version);
222
+			return FALSE;
223
+		}
224
+
225
+		if ($target_version > $current_version)
226
+		{
227
+			// Moving Up
228
+			$method = 'up';
229
+		}
230
+		else
231
+		{
232
+			// Moving Down, apply in reverse order
233
+			$method = 'down';
234
+			krsort($migrations);
235
+		}
236
+
237
+		if (empty($migrations))
238
+		{
239
+			return TRUE;
240
+		}
241
+
242
+		$previous = FALSE;
243
+
244
+		// Validate all available migrations, and run the ones within our target range
245
+		foreach ($migrations as $number => $file)
246
+		{
247
+			// Check for sequence gaps
248
+			if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1)
249
+			{
250
+				$this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number);
251
+				return FALSE;
252
+			}
253
+
254
+			include_once($file);
255
+			$class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php'))));
256
+
257
+			// Validate the migration file structure
258
+			if ( ! class_exists($class, FALSE))
259
+			{
260
+				$this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class);
261
+				return FALSE;
262
+			}
263
+
264
+			$previous = $number;
265
+
266
+			// Run migrations that are inside the target range
267
+			if (
268
+				($method === 'up'   && $number > $current_version && $number <= $target_version) OR
269
+				($method === 'down' && $number <= $current_version && $number > $target_version)
270
+			)
271
+			{
272
+				$instance = new $class();
273
+				if ( ! is_callable(array($instance, $method)))
274
+				{
275
+					$this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class);
276
+					return FALSE;
277
+				}
278
+
279
+				log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number);
280
+				call_user_func(array($instance, $method));
281
+				$current_version = $number;
282
+				$this->_update_version($type, $current_version);
283
+			}
284
+		}
285
+
286
+		// This is necessary when moving down, since the the last migration applied
287
+		// will be the down() method for the next migration up from the target
288
+		if ($current_version <> $target_version)
289
+		{
290
+			$current_version = $target_version;
291
+			$this->_update_version($type, $current_version);
292
+		}
293
+
294
+		log_message('debug', 'Finished migrating to '.$current_version);
295
+
296
+		return $current_version;
297
+	}
298
+
299
+	// --------------------------------------------------------------------
300
+
301
+	/**
302
+	 * Sets the schema to the latest migration
303
+	 *
304
+	 * @param string $type  Any key from _migration_paths, or {module_name}
305
+	 *
306
+	 * @return	mixed	TRUE if already latest, FALSE if failed, string if upgraded
307
+	 */
308
+	public function latest($type='app')
309
+	{
310
+		$last_migration = $this->get_latest($type);
311
+
312
+		// Calculate the last migration step from existing migration
313
+		// filenames and proceed to the standard version migration
314
+		return $this->version($type, $this->_get_migration_number($last_migration));
315
+	}
316
+
317
+	// --------------------------------------------------------------------
318
+
319
+	/**
320
+	 * Retrieves the latest migration version available.
321
+	 *
322
+	 * @param string $type  Any key from _migration_paths, or {module_name}
323
+	 *
324
+	 * @return bool|string
325
+	 */
326
+	public function get_latest($type='app')
327
+	{
328
+		$migrations = $this->find_migrations($type);
329
+
330
+		if (empty($migrations))
331
+		{
332
+			$this->_error_string = $this->lang->line('migration_none_found');
333
+			return FALSE;
334
+		}
335
+
336
+		return basename(end($migrations));
337
+	}
338
+
339
+	//--------------------------------------------------------------------
340
+
341
+
342
+
343
+	/**
344
+	 * Sets the schema to the migration version set in config
345
+	 *
346
+	 * @return	mixed	TRUE if already current, FALSE if failed, string if upgraded
347
+	 */
348
+	public function current()
349
+	{
350
+		return $this->version($this->_migration_version);
351
+	}
352
+
353
+	// --------------------------------------------------------------------
354
+
355
+	/**
356
+	 * Error string
357
+	 *
358
+	 * @return	string	Error message returned as a string
359
+	 */
360
+	public function error_string()
361
+	{
362
+		return $this->_error_string;
363
+	}
364
+
365
+	// --------------------------------------------------------------------
366
+
367
+	/**
368
+	 * Retrieves list of available migration scripts
369
+	 *
370
+	 * @return	array	list of migration file paths sorted by version
371
+	 */
372
+	public function find_migrations($type='app')
373
+	{
374
+		$migrations = array();
375
+
376
+		$path = $this->determine_migration_path($type);
377
+
378
+		// Load all *_*.php files in the migrations path
379
+		foreach (glob($path.'*_*.php') as $file)
380
+		{
381
+			$name = basename($file, '.php');
382
+
383
+			// Filter out non-migration files
384
+			if (preg_match($this->_migration_regex, $name))
385
+			{
386
+				$number = $this->_get_migration_number($name);
387
+
388
+				// There cannot be duplicate migration numbers
389
+				if (isset($migrations[$number]))
390
+				{
391
+					$this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number);
392
+					show_error($this->_error_string);
393
+				}
394
+
395
+				$migrations[$number] = $file;
396
+			}
397
+		}
398
+
399
+		ksort($migrations);
400
+		return $migrations;
401
+	}
402
+
403
+	// --------------------------------------------------------------------
404
+
405
+	/**
406
+	 * Retrieves current schema version
407
+	 *
408
+	 * @return	string	Current migration version
409
+	 */
410
+	public function get_version($type='app')
411
+	{
412
+		$row = $this->db->select('version')
413
+						->where('alias', $type)
414
+						->get($this->_migration_table)
415
+						->row();
416
+
417
+		return $row ? $row->version : '0';
418
+	}
419
+
420
+	// --------------------------------------------------------------------
421
+
422
+	/**
423
+	 * Given the string for the name of the file, will
424
+	 * generate the rest of the filename based on the current
425
+	 * $config['migration_type'] setting.
426
+	 *
427
+	 * @param $name
428
+	 * @return string The final name (with extension)
429
+	 */
430
+	public function make_name($name)
431
+	{
432
+		if (empty($name))
433
+		{
434
+			return null;
435
+		}
436
+
437
+		if ($this->_migration_type == 'timestamp')
438
+		{
439
+			$prefix = date('YmdHis');
440
+		}
441
+		else
442
+		{
443
+			$prefix = str_pad($this->get_version() + 1, 3, '0', STR_PAD_LEFT);
444
+		}
445
+
446
+		return $prefix .'_'. ucfirst(strtolower($name)) .'.php';
447
+	}
448
+
449
+	//--------------------------------------------------------------------
450
+
451
+	/**
452
+	 * Enable the use of CI super-global
453
+	 *
454
+	 * @param	string	$var
455
+	 * @return	mixed
456
+	 */
457
+	public function __get($var)
458
+	{
459
+		return get_instance()->$var;
460
+	}
461
+
462
+	//--------------------------------------------------------------------
463 463
 
464 464
 
465 465
 	/**
@@ -470,109 +470,109 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @return null|string
472 472
 	 */
473
-    public function determine_migration_path($type, $create=false)
474
-    {
475
-        $type = strtolower($type);
473
+	public function determine_migration_path($type, $create=false)
474
+	{
475
+		$type = strtolower($type);
476 476
 
477
-        // Is it a module?
478
-        if (strpos($type, 'mod:') === 0)
479
-        {
480
-            $module = str_replace('mod:', '', $type);
477
+		// Is it a module?
478
+		if (strpos($type, 'mod:') === 0)
479
+		{
480
+			$module = str_replace('mod:', '', $type);
481 481
 
482
-            $path = \Myth\Modules::path($module, 'migrations');
482
+			$path = \Myth\Modules::path($module, 'migrations');
483 483
 
484
-	        // Should we return a 'created' module?
485
-	        // Use the first module path.
486
-	        if (empty($path) && $create === true)
487
-	        {
484
+			// Should we return a 'created' module?
485
+			// Use the first module path.
486
+			if (empty($path) && $create === true)
487
+			{
488 488
 				$folders = config_item('modules_locations');
489 489
 
490
-		        if (is_array($folders) && count($folders))
491
-		        {
492
-			        $path = $folders[0] . $module .'/migrations';
493
-		        }
494
-	        }
495
-
496
-            return rtrim($path, '/') .'/';
497
-        }
498
-
499
-        // Look in our predefined groups.
500
-        if (! empty($this->_migration_paths[$type]))
501
-        {
502
-            return rtrim($this->_migration_paths[$type], '/') .'/';
503
-        }
504
-
505
-        return null;
506
-    }
507
-
508
-    //--------------------------------------------------------------------
509
-
510
-    /**
511
-     * Returns the default migration path. This is basically the first
512
-     * path in the migration_paths array.
513
-     *
514
-     * @return string
515
-     */
516
-    public function default_migration_path()
517
-    {
518
-        return key($this->_migration_paths);
519
-    }
520
-
521
-    //--------------------------------------------------------------------
522
-
523
-
524
-    //--------------------------------------------------------------------
525
-    // Protected Methods
526
-    //--------------------------------------------------------------------
527
-
528
-    /**
529
-     * Extracts the migration number from a filename
530
-     *
531
-     * @param	string	$migration
532
-     * @return	string	Numeric portion of a migration filename
533
-     */
534
-    protected function _get_migration_number($migration)
535
-    {
536
-        return sscanf($migration, '%[0-9]+', $number)
537
-            ? $number : '0';
538
-    }
539
-
540
-    // --------------------------------------------------------------------
541
-
542
-    /**
543
-     * Extracts the migration class name from a filename
544
-     *
545
-     * @param	string	$migration
546
-     * @return	string	text portion of a migration filename
547
-     */
548
-    protected function _get_migration_name($migration)
549
-    {
550
-        $parts = explode('_', $migration);
551
-        array_shift($parts);
552
-        return implode('_', $parts);
553
-    }
554
-
555
-    // --------------------------------------------------------------------
556
-
557
-    /**
558
-     * Stores the current schema version
559
-     *
560
-     * @param   string  $type  Any key from _migration_paths, or {module_name}
561
-     * @param	string	$migration	Migration reached
562
-     * @return	mixed	Outputs a report of the migration
563
-     */
564
-    protected function _update_version($type='all', $migration)
565
-    {
566
-        $this->db->where('alias', $type)
567
-                 ->delete($this->_migration_table);
568
-
569
-        return $this->db->insert($this->_migration_table, array(
570
-            'version'   => $migration,
571
-            'alias'     => $type,
572
-            'ondate'    => date('Y-m-d H:i:s')
573
-        ));
574
-    }
575
-
576
-    // --------------------------------------------------------------------
490
+				if (is_array($folders) && count($folders))
491
+				{
492
+					$path = $folders[0] . $module .'/migrations';
493
+				}
494
+			}
495
+
496
+			return rtrim($path, '/') .'/';
497
+		}
498
+
499
+		// Look in our predefined groups.
500
+		if (! empty($this->_migration_paths[$type]))
501
+		{
502
+			return rtrim($this->_migration_paths[$type], '/') .'/';
503
+		}
504
+
505
+		return null;
506
+	}
507
+
508
+	//--------------------------------------------------------------------
509
+
510
+	/**
511
+	 * Returns the default migration path. This is basically the first
512
+	 * path in the migration_paths array.
513
+	 *
514
+	 * @return string
515
+	 */
516
+	public function default_migration_path()
517
+	{
518
+		return key($this->_migration_paths);
519
+	}
520
+
521
+	//--------------------------------------------------------------------
522
+
523
+
524
+	//--------------------------------------------------------------------
525
+	// Protected Methods
526
+	//--------------------------------------------------------------------
527
+
528
+	/**
529
+	 * Extracts the migration number from a filename
530
+	 *
531
+	 * @param	string	$migration
532
+	 * @return	string	Numeric portion of a migration filename
533
+	 */
534
+	protected function _get_migration_number($migration)
535
+	{
536
+		return sscanf($migration, '%[0-9]+', $number)
537
+			? $number : '0';
538
+	}
539
+
540
+	// --------------------------------------------------------------------
541
+
542
+	/**
543
+	 * Extracts the migration class name from a filename
544
+	 *
545
+	 * @param	string	$migration
546
+	 * @return	string	text portion of a migration filename
547
+	 */
548
+	protected function _get_migration_name($migration)
549
+	{
550
+		$parts = explode('_', $migration);
551
+		array_shift($parts);
552
+		return implode('_', $parts);
553
+	}
554
+
555
+	// --------------------------------------------------------------------
556
+
557
+	/**
558
+	 * Stores the current schema version
559
+	 *
560
+	 * @param   string  $type  Any key from _migration_paths, or {module_name}
561
+	 * @param	string	$migration	Migration reached
562
+	 * @return	mixed	Outputs a report of the migration
563
+	 */
564
+	protected function _update_version($type='all', $migration)
565
+	{
566
+		$this->db->where('alias', $type)
567
+				 ->delete($this->_migration_table);
568
+
569
+		return $this->db->insert($this->_migration_table, array(
570
+			'version'   => $migration,
571
+			'alias'     => $type,
572
+			'ondate'    => date('Y-m-d H:i:s')
573
+		));
574
+	}
575
+
576
+	// --------------------------------------------------------------------
577 577
 
578 578
 }
Please login to merge, or discard this patch.
application/mailers/CronMailer.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -2,33 +2,33 @@
 block discarded – undo
2 2
 
3 3
 class CronMailer extends \Myth\Mail\BaseMailer {
4 4
 
5
-    protected $from     = null;
6
-    protected $to       = null;
7
-
8
-    public function __construct()
9
-    {
10
-        $this->from = [ config_item('site.auth_email'), config_item('site.name') ];
11
-        $this->to   = config_item('site.auth_email');
12
-    }
13
-
14
-    //--------------------------------------------------------------------
15
-
16
-    /**
17
-     * Sends the output from the cronjob to the admin.
18
-     *
19
-     * @param $output
20
-     */
21
-    public function results($output=null)
22
-    {
23
-        $data = [
24
-            'output' => $output,
25
-            'site_name' => config_item('site.name')
26
-        ];
27
-
28
-        // Send it immediately - don't queue.
29
-        return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data);
30
-    }
31
-
32
-    //--------------------------------------------------------------------
5
+	protected $from     = null;
6
+	protected $to       = null;
7
+
8
+	public function __construct()
9
+	{
10
+		$this->from = [ config_item('site.auth_email'), config_item('site.name') ];
11
+		$this->to   = config_item('site.auth_email');
12
+	}
13
+
14
+	//--------------------------------------------------------------------
15
+
16
+	/**
17
+	 * Sends the output from the cronjob to the admin.
18
+	 *
19
+	 * @param $output
20
+	 */
21
+	public function results($output=null)
22
+	{
23
+		$data = [
24
+			'output' => $output,
25
+			'site_name' => config_item('site.name')
26
+		];
27
+
28
+		// Send it immediately - don't queue.
29
+		return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data);
30
+	}
31
+
32
+	//--------------------------------------------------------------------
33 33
 
34 34
 }
Please login to merge, or discard this patch.
application/mailers/UserMailer.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -2,85 +2,85 @@
 block discarded – undo
2 2
 
3 3
 class UserMailer extends \Myth\Mail\BaseMailer {
4 4
 
5
-    protected $from     = null;
6
-    protected $to       = null;
5
+	protected $from     = null;
6
+	protected $to       = null;
7 7
 
8
-    public function __construct()
9
-    {
10
-        $this->from = [ config_item('site.auth_email'), config_item('site.name') ];
11
-    }
8
+	public function __construct()
9
+	{
10
+		$this->from = [ config_item('site.auth_email'), config_item('site.name') ];
11
+	}
12 12
 
13
-    //--------------------------------------------------------------------
13
+	//--------------------------------------------------------------------
14 14
 
15
-    /**
16
-     * Sends the output from the cronjob to the admin.
17
-     *
18
-     * The params array contains:
19
-     *  - user_id
20
-     *  - email
21
-     *  - token
22
-     *
23
-     * @param $params
24
-     * @return bool
25
-     */
26
-    public function didRegister($params=null)
27
-    {
28
-        $data = [
29
-            'user_id'   => $params['user_id'],
30
-            'email'     => $params['email'],
31
-            'link'      => site_url( \Myth\Route::named('activate_user') ),
32
-            'token'     => $params['token'],
33
-            'site_name' => config_item('site.name'),
34
-            'site_link' => site_url()
35
-        ];
15
+	/**
16
+	 * Sends the output from the cronjob to the admin.
17
+	 *
18
+	 * The params array contains:
19
+	 *  - user_id
20
+	 *  - email
21
+	 *  - token
22
+	 *
23
+	 * @param $params
24
+	 * @return bool
25
+	 */
26
+	public function didRegister($params=null)
27
+	{
28
+		$data = [
29
+			'user_id'   => $params['user_id'],
30
+			'email'     => $params['email'],
31
+			'link'      => site_url( \Myth\Route::named('activate_user') ),
32
+			'token'     => $params['token'],
33
+			'site_name' => config_item('site.name'),
34
+			'site_link' => site_url()
35
+		];
36 36
 
37
-        // Send it immediately - don't queue.
38
-        return $this->send($params['email'], lang('auth.register_subject'), $data);
39
-    }
37
+		// Send it immediately - don't queue.
38
+		return $this->send($params['email'], lang('auth.register_subject'), $data);
39
+	}
40 40
 
41
-    //--------------------------------------------------------------------
41
+	//--------------------------------------------------------------------
42 42
 
43
-    /**
44
-     * Sends the Password Reset Instructions email.
45
-     *
46
-     * @param array  $user
47
-     * @param string $token
48
-     * @return bool
49
-     */
50
-    public function remindUser($user, $token)
51
-    {
52
-        $data = [
53
-            'email' => $user['email'],
54
-            'code'  => $token,
55
-            'link'  => site_url( \Myth\Route::named('reset_pass') ),
56
-            'site_name' => config_item('site.name'),
57
-            'site_link' => site_url()
58
-        ];
43
+	/**
44
+	 * Sends the Password Reset Instructions email.
45
+	 *
46
+	 * @param array  $user
47
+	 * @param string $token
48
+	 * @return bool
49
+	 */
50
+	public function remindUser($user, $token)
51
+	{
52
+		$data = [
53
+			'email' => $user['email'],
54
+			'code'  => $token,
55
+			'link'  => site_url( \Myth\Route::named('reset_pass') ),
56
+			'site_name' => config_item('site.name'),
57
+			'site_link' => site_url()
58
+		];
59 59
 
60
-        // Send it immediately - don't queue.
61
-        return $this->send($user['email'], lang('auth.remind_subject'), $data);
62
-    }
60
+		// Send it immediately - don't queue.
61
+		return $this->send($user['email'], lang('auth.remind_subject'), $data);
62
+	}
63 63
 
64
-    //--------------------------------------------------------------------
64
+	//--------------------------------------------------------------------
65 65
 
66
-    /**
67
-     * Sends the Password Reset Confirmation email.
68
-     *
69
-     * @param array  $user
70
-     * @return bool
71
-     */
72
-    public function resetPassword($user)
73
-    {
74
-        $data = [
75
-            'email' => $user['email'],
76
-            'link'  => site_url( \Myth\Route::named('forgot_pass') ),
77
-            'site_name' => config_item('site.name'),
78
-            'site_link' => site_url()
79
-        ];
66
+	/**
67
+	 * Sends the Password Reset Confirmation email.
68
+	 *
69
+	 * @param array  $user
70
+	 * @return bool
71
+	 */
72
+	public function resetPassword($user)
73
+	{
74
+		$data = [
75
+			'email' => $user['email'],
76
+			'link'  => site_url( \Myth\Route::named('forgot_pass') ),
77
+			'site_name' => config_item('site.name'),
78
+			'site_link' => site_url()
79
+		];
80 80
 
81
-        // Send it immediately - don't queue.
82
-        return $this->send($user['email'], lang('auth.reset_subject'), $data);
83
-    }
81
+		// Send it immediately - don't queue.
82
+		return $this->send($user['email'], lang('auth.reset_subject'), $data);
83
+	}
84 84
 
85
-    //--------------------------------------------------------------------
85
+	//--------------------------------------------------------------------
86 86
 }
Please login to merge, or discard this patch.
application/models/User_model.php 1 patch
Indentation   +356 added lines, -356 removed lines patch added patch discarded remove patch
@@ -4,363 +4,363 @@
 block discarded – undo
4 4
 
5 5
 class User_model extends \Myth\Models\CIDbModel {
6 6
 
7
-    protected $table_name = 'users';
8
-
9
-    protected $soft_deletes = true;
10
-
11
-    protected $set_created = true;
12
-
13
-    protected $set_modified = false;
14
-
15
-    protected $protected_attributes = ['id', 'submit'];
16
-
17
-    protected $validation_rules = [
18
-        [
19
-            'field' => 'first_name',
20
-            'label' => 'lang:auth.first_name',
21
-            'rules' => 'trim|alpha|max_length[255]'
22
-        ],
23
-        [
24
-            'field' => 'last_name',
25
-            'label' => 'lang:auth.last_name',
26
-            'rules' => 'trim|alpha|max_length[255]'
27
-        ],
28
-        [
29
-            'field' => 'email',
30
-            'label' => 'lang:auth.email',
31
-            'rules' => 'trim|valid_email|max_length[255]'
32
-        ],
33
-        [
34
-            'field' => 'username',
35
-            'label' => 'lang:auth.username',
36
-            'rules' => 'trim|alpha_numeric|max_length[255]'
37
-        ],
38
-        [
39
-            'field' => 'password',
40
-            'label' => 'lang:auth.password',
41
-            'rules' => 'trim|max_length[255]|isStrongPassword'
42
-        ],
43
-        [
44
-            'field' => 'pass_confirm',
45
-            'label' => 'lang:auth.pass_confirm',
46
-            'rules' => 'trim|matches[password]'
47
-        ],
48
-    ];
49
-
50
-    protected $insert_validate_rules = [
51
-        'email'        => 'required|is_unique[users.email]',
52
-        'username'     => 'required|is_unique[users.username]',
53
-        'password'     => 'required',
54
-        'pass_confirm' => 'required'
55
-    ];
56
-
57
-    protected $before_insert = ['hashPassword'];
58
-    protected $before_update = ['hashPassword'];
59
-    protected $after_insert  = ['updateMeta'];
60
-    protected $after_update  = ['updateMeta'];
61
-
62
-    // The columns in the 'users_meta' table - for auto updating of profile information.
63
-    protected $meta_fields = ['first_name', 'last_name'];
64
-
65
-    protected $fields = ['id', 'email', 'username', 'password_hash', 'reset_hash', 'activate_hash', 'created_on', 'status', 'status_message', 'active', 'deleted', 'force_pass_reset'];
66
-
67
-    //--------------------------------------------------------------------
68
-
69
-    public function __construct()
70
-    {
71
-        parent::__construct();
72
-
73
-        $this->load->helper('auth/password');
74
-    }
75
-
76
-    //--------------------------------------------------------------------
77
-
78
-    /**
79
-     * Works with any find queries to return user_meta information.
80
-     *
81
-     * @return $this
82
-     */
83
-    public function withMeta()
84
-    {
85
-        $this->after_find[] = 'grabMeta';
86
-
87
-        return $this;
88
-    }
89
-
90
-    //--------------------------------------------------------------------
91
-
92
-    /**
93
-     * If exists, will take our password out of the data array, and
94
-     * create a new hash for it, which is inserted back into the
95
-     * data array to be saved to the database.
96
-     *
97
-     * @param array $data
98
-     *
99
-     * @return array
100
-     */
101
-    protected function hashPassword($data)
102
-    {
103
-        if (isset($data['fields']))
104
-        {
105
-            $data = $data['fields'];
106
-        }
107
-
108
-        if (isset($data['password']))
109
-        {
110
-            $data['password_hash'] = \Myth\Auth\Password::hashPassword($data['password']);
111
-
112
-            unset($data['password'], $data['pass_confirm']);
113
-        }
114
-
115
-        return $data;
116
-    }
117
-
118
-    //--------------------------------------------------------------------
119
-
120
-    /**
121
-     * A callback designed to work with Digest Authentication to create
122
-     * and store the $A1 value since we'll never have access to the
123
-     * password except during inserts or updates.
124
-     *
125
-     * This assumes that this is working as part of an API and that
126
-     * the api config file is already loaded into memory.
127
-     *
128
-     * @param $data
129
-     *
130
-     * @return $data
131
-     */
132
-    public function createDigestKey($data)
133
-    {
134
-        $field = config_item('api.auth_field');
135
-        $value = null;
136
-
137
-        // If it's an update, we probably won't have the username/email
138
-        // so grab it so that we can use it.
139
-        if (! empty($data[ $this->primary_key ]))
140
-        {
141
-            if (! isset($data[$field]) )
142
-            {
143
-                $value = $this->get_field( $data['id'], $field );
144
-            }
145
-        }
146
-        // However, if it's an insert, then we should have it, If we don't, leave.
147
-        else
148
-        {
149
-            if (empty($data[$field]))
150
-            {
151
-                return $data;
152
-            }
153
-
154
-            $value = $data[$field];
155
-        }
156
-
157
-        // Still here? then create the hash based on the current realm.
158
-        if (! empty($data['password']) )
159
-        {
160
-            $key = md5($value .':'. config_item('api.realm') .':'. $data['password']);
161
-            $data['api_key'] = $key;
162
-        }
163
-
164
-        return $data;
165
-    }
166
-
167
-    //--------------------------------------------------------------------
168
-
169
-
170
-    /**
171
-     * A callback method intended to hook into the after_insert and after_udpate
172
-     * methods.
173
-     *
174
-     * NOTE: Will only work for insert and update methods.
175
-     *
176
-     * @param array $data
177
-     * @return mixed
178
-     */
179
-    public function updateMeta($data)
180
-    {
181
-        // If no 'id' is in the $data array, then
182
-        // we don't have successful insert, get out of here
183
-        if (empty($data['id']) || ($data['method'] != 'insert' && $data['method'] != 'update'))
184
-        {
185
-            return $data;
186
-        }
187
-
188
-        // Collect any meta fields
189
-        foreach ($data['fields'] as $key => $value)
190
-        {
191
-            if (in_array($key, $this->meta_fields))
192
-            {
193
-                $this->db->where('user_id', $data['id']);
194
-                $this->db->where('meta_key', $key);
195
-                $query = $this->db->get('user_meta');
196
-
197
-                $obj = [
198
-                    'user_id'    => $data['id'],
199
-                    'meta_key'   => $key,
200
-                    'meta_value' => $value
201
-                ];
202
-
203
-                if ($query->num_rows() == 0)
204
-                {
205
-                    $this->db->insert('user_meta', $obj);
206
-                }
207
-                else if ($query->num_rows() > 0)
208
-                {
209
-                    $this->db->where('user_id', $data['id'])
210
-                             ->where('meta_key', $key)
211
-                             ->set('meta_value', $value)
212
-                             ->update('user_meta', $obj);
213
-                }
214
-            }
215
-        }
216
-
217
-        return $data;
218
-    }
219
-
220
-    //--------------------------------------------------------------------
221
-
222
-    /**
223
-     * Adds a single piece of meta information to a user.
224
-     *
225
-     * @param $user_id
226
-     * @param $key
227
-     * @param null $value
228
-     *
229
-     * @return object
230
-     */
231
-    public function saveMetaToUser($user_id, $key, $value=null)
232
-    {
233
-        if (! Events::trigger('beforeAddMetaToUser', [$user_id, $key]))
234
-        {
235
-            return false;
236
-        }
237
-
238
-        $user_id = (int)$user_id;
239
-
240
-        // Does this key already exist?
241
-        $test = $this->db->where([ 'user_id' => $user_id, 'meta_key' => $key ])->get('user_meta');
242
-
243
-        // Doesn't exist, so insert it.
244
-        if (! $test->num_rows())
245
-        {
246
-            $data = [
247
-                'user_id'       => $user_id,
248
-                'meta_key'      => $key,
249
-                'meta_value'    => $value
250
-            ];
251
-
252
-            return $this->db->insert('user_meta', $data);
253
-        }
254
-
255
-        // Otherwise, we need to update the existing.
256
-        return $this->db->where('user_id', $user_id)
257
-                        ->where('meta_key', $key)
258
-                        ->set('meta_value', $value)
259
-                        ->update('user_meta');
260
-    }
7
+	protected $table_name = 'users';
8
+
9
+	protected $soft_deletes = true;
10
+
11
+	protected $set_created = true;
12
+
13
+	protected $set_modified = false;
14
+
15
+	protected $protected_attributes = ['id', 'submit'];
16
+
17
+	protected $validation_rules = [
18
+		[
19
+			'field' => 'first_name',
20
+			'label' => 'lang:auth.first_name',
21
+			'rules' => 'trim|alpha|max_length[255]'
22
+		],
23
+		[
24
+			'field' => 'last_name',
25
+			'label' => 'lang:auth.last_name',
26
+			'rules' => 'trim|alpha|max_length[255]'
27
+		],
28
+		[
29
+			'field' => 'email',
30
+			'label' => 'lang:auth.email',
31
+			'rules' => 'trim|valid_email|max_length[255]'
32
+		],
33
+		[
34
+			'field' => 'username',
35
+			'label' => 'lang:auth.username',
36
+			'rules' => 'trim|alpha_numeric|max_length[255]'
37
+		],
38
+		[
39
+			'field' => 'password',
40
+			'label' => 'lang:auth.password',
41
+			'rules' => 'trim|max_length[255]|isStrongPassword'
42
+		],
43
+		[
44
+			'field' => 'pass_confirm',
45
+			'label' => 'lang:auth.pass_confirm',
46
+			'rules' => 'trim|matches[password]'
47
+		],
48
+	];
49
+
50
+	protected $insert_validate_rules = [
51
+		'email'        => 'required|is_unique[users.email]',
52
+		'username'     => 'required|is_unique[users.username]',
53
+		'password'     => 'required',
54
+		'pass_confirm' => 'required'
55
+	];
56
+
57
+	protected $before_insert = ['hashPassword'];
58
+	protected $before_update = ['hashPassword'];
59
+	protected $after_insert  = ['updateMeta'];
60
+	protected $after_update  = ['updateMeta'];
61
+
62
+	// The columns in the 'users_meta' table - for auto updating of profile information.
63
+	protected $meta_fields = ['first_name', 'last_name'];
64
+
65
+	protected $fields = ['id', 'email', 'username', 'password_hash', 'reset_hash', 'activate_hash', 'created_on', 'status', 'status_message', 'active', 'deleted', 'force_pass_reset'];
66
+
67
+	//--------------------------------------------------------------------
68
+
69
+	public function __construct()
70
+	{
71
+		parent::__construct();
72
+
73
+		$this->load->helper('auth/password');
74
+	}
75
+
76
+	//--------------------------------------------------------------------
77
+
78
+	/**
79
+	 * Works with any find queries to return user_meta information.
80
+	 *
81
+	 * @return $this
82
+	 */
83
+	public function withMeta()
84
+	{
85
+		$this->after_find[] = 'grabMeta';
86
+
87
+		return $this;
88
+	}
89
+
90
+	//--------------------------------------------------------------------
91
+
92
+	/**
93
+	 * If exists, will take our password out of the data array, and
94
+	 * create a new hash for it, which is inserted back into the
95
+	 * data array to be saved to the database.
96
+	 *
97
+	 * @param array $data
98
+	 *
99
+	 * @return array
100
+	 */
101
+	protected function hashPassword($data)
102
+	{
103
+		if (isset($data['fields']))
104
+		{
105
+			$data = $data['fields'];
106
+		}
107
+
108
+		if (isset($data['password']))
109
+		{
110
+			$data['password_hash'] = \Myth\Auth\Password::hashPassword($data['password']);
111
+
112
+			unset($data['password'], $data['pass_confirm']);
113
+		}
114
+
115
+		return $data;
116
+	}
117
+
118
+	//--------------------------------------------------------------------
119
+
120
+	/**
121
+	 * A callback designed to work with Digest Authentication to create
122
+	 * and store the $A1 value since we'll never have access to the
123
+	 * password except during inserts or updates.
124
+	 *
125
+	 * This assumes that this is working as part of an API and that
126
+	 * the api config file is already loaded into memory.
127
+	 *
128
+	 * @param $data
129
+	 *
130
+	 * @return $data
131
+	 */
132
+	public function createDigestKey($data)
133
+	{
134
+		$field = config_item('api.auth_field');
135
+		$value = null;
136
+
137
+		// If it's an update, we probably won't have the username/email
138
+		// so grab it so that we can use it.
139
+		if (! empty($data[ $this->primary_key ]))
140
+		{
141
+			if (! isset($data[$field]) )
142
+			{
143
+				$value = $this->get_field( $data['id'], $field );
144
+			}
145
+		}
146
+		// However, if it's an insert, then we should have it, If we don't, leave.
147
+		else
148
+		{
149
+			if (empty($data[$field]))
150
+			{
151
+				return $data;
152
+			}
153
+
154
+			$value = $data[$field];
155
+		}
156
+
157
+		// Still here? then create the hash based on the current realm.
158
+		if (! empty($data['password']) )
159
+		{
160
+			$key = md5($value .':'. config_item('api.realm') .':'. $data['password']);
161
+			$data['api_key'] = $key;
162
+		}
163
+
164
+		return $data;
165
+	}
166
+
167
+	//--------------------------------------------------------------------
168
+
169
+
170
+	/**
171
+	 * A callback method intended to hook into the after_insert and after_udpate
172
+	 * methods.
173
+	 *
174
+	 * NOTE: Will only work for insert and update methods.
175
+	 *
176
+	 * @param array $data
177
+	 * @return mixed
178
+	 */
179
+	public function updateMeta($data)
180
+	{
181
+		// If no 'id' is in the $data array, then
182
+		// we don't have successful insert, get out of here
183
+		if (empty($data['id']) || ($data['method'] != 'insert' && $data['method'] != 'update'))
184
+		{
185
+			return $data;
186
+		}
187
+
188
+		// Collect any meta fields
189
+		foreach ($data['fields'] as $key => $value)
190
+		{
191
+			if (in_array($key, $this->meta_fields))
192
+			{
193
+				$this->db->where('user_id', $data['id']);
194
+				$this->db->where('meta_key', $key);
195
+				$query = $this->db->get('user_meta');
196
+
197
+				$obj = [
198
+					'user_id'    => $data['id'],
199
+					'meta_key'   => $key,
200
+					'meta_value' => $value
201
+				];
202
+
203
+				if ($query->num_rows() == 0)
204
+				{
205
+					$this->db->insert('user_meta', $obj);
206
+				}
207
+				else if ($query->num_rows() > 0)
208
+				{
209
+					$this->db->where('user_id', $data['id'])
210
+							 ->where('meta_key', $key)
211
+							 ->set('meta_value', $value)
212
+							 ->update('user_meta', $obj);
213
+				}
214
+			}
215
+		}
216
+
217
+		return $data;
218
+	}
219
+
220
+	//--------------------------------------------------------------------
221
+
222
+	/**
223
+	 * Adds a single piece of meta information to a user.
224
+	 *
225
+	 * @param $user_id
226
+	 * @param $key
227
+	 * @param null $value
228
+	 *
229
+	 * @return object
230
+	 */
231
+	public function saveMetaToUser($user_id, $key, $value=null)
232
+	{
233
+		if (! Events::trigger('beforeAddMetaToUser', [$user_id, $key]))
234
+		{
235
+			return false;
236
+		}
237
+
238
+		$user_id = (int)$user_id;
239
+
240
+		// Does this key already exist?
241
+		$test = $this->db->where([ 'user_id' => $user_id, 'meta_key' => $key ])->get('user_meta');
242
+
243
+		// Doesn't exist, so insert it.
244
+		if (! $test->num_rows())
245
+		{
246
+			$data = [
247
+				'user_id'       => $user_id,
248
+				'meta_key'      => $key,
249
+				'meta_value'    => $value
250
+			];
251
+
252
+			return $this->db->insert('user_meta', $data);
253
+		}
254
+
255
+		// Otherwise, we need to update the existing.
256
+		return $this->db->where('user_id', $user_id)
257
+						->where('meta_key', $key)
258
+						->set('meta_value', $value)
259
+						->update('user_meta');
260
+	}
261 261
     
262
-    //--------------------------------------------------------------------
263
-
264
-    /**
265
-     * Gets the value of a single Meta item from a user.
266
-     *
267
-     * @param $user_id
268
-     * @param $key
269
-     *
270
-     * @return mixed
271
-     */
272
-    public function getMetaItem($user_id, $key)
273
-    {
274
-        $query = $this->db->where('user_id', (int)$user_id)
275
-                          ->where('meta_key', $key)
276
-                          ->select('meta_value')
277
-                          ->get('user_meta');
278
-
279
-        if (! $query->num_rows())
280
-        {
281
-            return null;
282
-        }
283
-
284
-        return $query->row()->meta_value;
285
-    }
286
-
287
-    //--------------------------------------------------------------------
288
-
289
-    /**
290
-     * Deletes one or more meta values from a user.
291
-     *
292
-     * @param $user_id
293
-     * @param $key
294
-     *
295
-     * @return bool
296
-     */
297
-    public function removeMetaFromUser($user_id, $key)
298
-    {
299
-        if (! Events::trigger('beforeRemoveMetaFromUser', [$user_id, $key]))
300
-        {
301
-            return false;
302
-        }
303
-
304
-	    if (is_array($key))
305
-	    {
306
-		    $this->db->where_in('meta_key', $key);
307
-	    }
308
-	    else
309
-	    {
310
-		    $this->db->where('meta_key', $key);
311
-	    }
312
-
313
-        $this->db->where('user_id', (int)$user_id)
314
-                 ->delete('user_meta');
315
-    }
316
-
317
-    //--------------------------------------------------------------------
318
-
319
-    public function getMetaForUser($user_id)
320
-    {
321
-        $query = $this->db->where('user_id', (int)$user_id)
322
-                          ->select('meta_key, meta_value')
323
-                          ->get('user_meta');
324
-
325
-        $rows = $query->result();
326
-
327
-        $meta = [];
328
-
329
-        if (count($rows))
330
-        {
331
-            array_walk( $rows, function ( $row ) use ( &$meta )
332
-            {
333
-                $meta[ $row->meta_key ] = $row->meta_value;
334
-            } );
335
-        }
336
-
337
-        return $meta;
338
-    }
339
-
340
-    //--------------------------------------------------------------------
341
-
342
-    protected function grabMeta($data)
343
-    {
344
-        if (strpos($data['method'], 'find') === false)
345
-        {
346
-            return $data;
347
-        }
348
-
349
-        $meta = $this->getMetaForUser($data['fields']->id);
350
-
351
-        if (is_object($data['fields']))
352
-        {
353
-            $data['fields']->meta = (object)$meta;
354
-        }
355
-        else
356
-        {
357
-            $data['fields']['meta']= $meta;
358
-        }
359
-
360
-        return $data;
361
-    }
362
-
363
-    //--------------------------------------------------------------------
262
+	//--------------------------------------------------------------------
263
+
264
+	/**
265
+	 * Gets the value of a single Meta item from a user.
266
+	 *
267
+	 * @param $user_id
268
+	 * @param $key
269
+	 *
270
+	 * @return mixed
271
+	 */
272
+	public function getMetaItem($user_id, $key)
273
+	{
274
+		$query = $this->db->where('user_id', (int)$user_id)
275
+						  ->where('meta_key', $key)
276
+						  ->select('meta_value')
277
+						  ->get('user_meta');
278
+
279
+		if (! $query->num_rows())
280
+		{
281
+			return null;
282
+		}
283
+
284
+		return $query->row()->meta_value;
285
+	}
286
+
287
+	//--------------------------------------------------------------------
288
+
289
+	/**
290
+	 * Deletes one or more meta values from a user.
291
+	 *
292
+	 * @param $user_id
293
+	 * @param $key
294
+	 *
295
+	 * @return bool
296
+	 */
297
+	public function removeMetaFromUser($user_id, $key)
298
+	{
299
+		if (! Events::trigger('beforeRemoveMetaFromUser', [$user_id, $key]))
300
+		{
301
+			return false;
302
+		}
303
+
304
+		if (is_array($key))
305
+		{
306
+			$this->db->where_in('meta_key', $key);
307
+		}
308
+		else
309
+		{
310
+			$this->db->where('meta_key', $key);
311
+		}
312
+
313
+		$this->db->where('user_id', (int)$user_id)
314
+				 ->delete('user_meta');
315
+	}
316
+
317
+	//--------------------------------------------------------------------
318
+
319
+	public function getMetaForUser($user_id)
320
+	{
321
+		$query = $this->db->where('user_id', (int)$user_id)
322
+						  ->select('meta_key, meta_value')
323
+						  ->get('user_meta');
324
+
325
+		$rows = $query->result();
326
+
327
+		$meta = [];
328
+
329
+		if (count($rows))
330
+		{
331
+			array_walk( $rows, function ( $row ) use ( &$meta )
332
+			{
333
+				$meta[ $row->meta_key ] = $row->meta_value;
334
+			} );
335
+		}
336
+
337
+		return $meta;
338
+	}
339
+
340
+	//--------------------------------------------------------------------
341
+
342
+	protected function grabMeta($data)
343
+	{
344
+		if (strpos($data['method'], 'find') === false)
345
+		{
346
+			return $data;
347
+		}
348
+
349
+		$meta = $this->getMetaForUser($data['fields']->id);
350
+
351
+		if (is_object($data['fields']))
352
+		{
353
+			$data['fields']->meta = (object)$meta;
354
+		}
355
+		else
356
+		{
357
+			$data['fields']['meta']= $meta;
358
+		}
359
+
360
+		return $data;
361
+	}
362
+
363
+	//--------------------------------------------------------------------
364 364
 
365 365
 
366 366
 }
Please login to merge, or discard this patch.
application/third_party/HMVC/Loader.php 1 patch
Indentation   +499 added lines, -499 removed lines patch added patch discarded remove patch
@@ -30,506 +30,506 @@
 block discarded – undo
30 30
  */
31 31
 
32 32
 if (!defined("BASEPATH"))
33
-    exit("No direct script access allowed");
33
+	exit("No direct script access allowed");
34 34
 
35 35
 class HMVC_Loader extends CI_Loader {
36 36
 
37
-    /**
38
-     * List of loaded modules
39
-     *
40
-     * @var array
41
-     * @access protected
42
-     */
43
-    protected $_ci_modules = array();
44
-
45
-    /**
46
-     * List of loaded controllers
47
-     *
48
-     * @var array
49
-     * @access protected
50
-     */
51
-    protected $_ci_controllers = array();
52
-
53
-    /**
54
-     * Constructor
55
-     *
56
-     * Add the current module to all paths permanently
57
-     */
58
-    public function __construct() {
59
-        parent::__construct();
60
-
61
-        // Get current module from the router
62
-        $router = & $this->_ci_get_component('router');
63
-        if ($router->module) {
64
-            $this->add_module($router->module);
65
-        }
66
-    }
67
-
68
-    /**
69
-     * Controller Loader
70
-     *
71
-     * This function lets users load and hierarchical controllers to enable HMVC support
72
-     *
73
-     * @param	string	the uri to the controller
74
-     * @param	array	parameters for the requested method
75
-     * @param	boolean return the result instead of showing it
76
-     * @return	void
77
-     */
78
-    public function controller($uri, $params = array(), $return = FALSE) {
79
-        // No valid module detected, add current module to uri
80
-        list($module) = $this->detect_module($uri);
81
-        if (!isset($module)) {
82
-            $router = & $this->_ci_get_component('router');
83
-            if ($router->module) {
84
-                $module = $router->module;
85
-                $uri = $module . '/' . $uri;
86
-            }
87
-        }
88
-
89
-        // Add module
90
-        $this->add_module($module);
91
-
92
-        // Execute the controller method and capture output
93
-        $void = $this->_load_controller($uri, $params, $return);
94
-
95
-        // Remove module
96
-        $this->remove_module();
97
-
98
-        return $void;
99
-    }
100
-
101
-    /**
102
-     * Class Loader
103
-     *
104
-     * This function lets users load and instantiate classes.
105
-     * It is designed to be called from a user's app controllers.
106
-     *
107
-     * @param	string	the name of the class
108
-     * @param	mixed	the optional parameters
109
-     * @param	string	an optional object name
110
-     * @return	void
111
-     */
112
-    public function library($library = '', $params = NULL, $object_name = NULL) {
113
-        if (is_array($library)) {
114
-            foreach ($library as $class) {
115
-                $this->library($class, $params);
116
-            }
117
-            return;
118
-        }
119
-
120
-        // Detect module
121
-        if (list($module, $class) = $this->detect_module($library)) {
122
-            // Module already loaded
123
-            if (in_array($module, $this->_ci_modules)) {
124
-                return parent::library($class, $params, $object_name);
125
-            }
126
-
127
-            // Add module
128
-            $this->add_module($module);
129
-
130
-            // Let parent do the heavy work
131
-            $void = parent::library($class, $params, $object_name);
132
-
133
-            // Remove module
134
-            $this->remove_module();
135
-
136
-            return $void;
137
-        } else {
138
-            return parent::library($library, $params, $object_name);
139
-        }
140
-    }
141
-
142
-    /**
143
-     * Model Loader
144
-     *
145
-     * This function lets users load and instantiate models.
146
-     *
147
-     * @param	string	the name of the class
148
-     * @param	string	name for the model
149
-     * @param	bool	database connection
150
-     * @return	void
151
-     */
152
-    public function model($model, $name = '', $db_conn = FALSE) {
153
-        if (is_array($model)) {
154
-            foreach ($model as $babe) {
155
-                $this->model($babe);
156
-            }
157
-            return;
158
-        }
159
-
160
-        // Detect module
161
-        if (list($module, $class) = $this->detect_module($model)) {
162
-            // Module already loaded
163
-            if (in_array($module, $this->_ci_modules)) {
164
-                return parent::model($class, $name, $db_conn);
165
-            }
166
-
167
-            // Add module
168
-            $this->add_module($module);
169
-
170
-            // Let parent do the heavy work
171
-            $void = parent::model($class, $name, $db_conn);
172
-
173
-            // Remove module
174
-            $this->remove_module();
175
-
176
-            return $void;
177
-        } else {
178
-            return parent::model($model, $name, $db_conn);
179
-        }
180
-    }
181
-
182
-    /**
183
-     * Load View
184
-     *
185
-     * This function is used to load a "view" file.  It has three parameters:
186
-     *
187
-     * 1. The name of the "view" file to be included.
188
-     * 2. An associative array of data to be extracted for use in the view.
189
-     * 3. TRUE/FALSE - whether to return the data or load it.  In
190
-     * some cases it's advantageous to be able to return data so that
191
-     * a developer can process it in some way.
192
-     *
193
-     * @param	string
194
-     * @param	array
195
-     * @param	bool
196
-     * @return	void
197
-     */
198
-    public function view($view, $vars = array(), $return = FALSE)
199
-    {
200
-        // Allow application/views/* to override any module
201
-        // views for easier app customization.
202
-        if (file_exists(APPPATH .'views/'. $view .'.php'))
203
-        {
204
-            return parent::view($view, $vars, $return);
205
-        }
206
-
207
-        // Detect module
208
-        if (list($module, $class) = $this->detect_module($view)) {
209
-            // Module already loaded
210
-            if (in_array($module, $this->_ci_modules)) {
211
-                return parent::view($class, $vars, $return);
212
-            }
213
-
214
-            // Add module
215
-            $this->add_module($module);
216
-
217
-            // Let parent do the heavy work
218
-            $void = parent::view($class, $vars, $return);
219
-
220
-            // Remove module
221
-            $this->remove_module();
222
-
223
-            return $void;
224
-        } else {
225
-            return parent::view($view, $vars, $return);
226
-        }
227
-    }
228
-
229
-    /**
230
-     * Loads a config file
231
-     *
232
-     * @param	string
233
-     * @param	bool
234
-     * @param 	bool
235
-     * @return	void
236
-     */
237
-    public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) {
238
-        // Detect module
239
-        if (list($module, $class) = $this->detect_module($file)) {
240
-            // Module already loaded
241
-            if (in_array($module, $this->_ci_modules)) {
242
-                return parent::config($class, $use_sections, $fail_gracefully);
243
-            }
244
-
245
-            // Add module
246
-            $this->add_module($module);
247
-
248
-            // Let parent do the heavy work
249
-            $void = parent::config($class, $use_sections, $fail_gracefully);
250
-
251
-            // Remove module
252
-            $this->remove_module();
253
-
254
-            return $void;
255
-        } else {
256
-            parent::config($file, $use_sections, $fail_gracefully);
257
-        }
258
-    }
259
-
260
-    /**
261
-     * Load Helper
262
-     *
263
-     * This function loads the specified helper file.
264
-     *
265
-     * @param	mixed
266
-     * @return	void
267
-     */
268
-    public function helper($helper = array()) {
269
-        if (is_array($helper)) {
270
-            foreach ($helper as $help) {
271
-                $this->helper($help);
272
-            }
273
-            return;
274
-        }
275
-
276
-        // Detect module
277
-        if (list($module, $class) = $this->detect_module($helper)) {
278
-            // Module already loaded
279
-            if (in_array($module, $this->_ci_modules)) {
280
-                return parent::helper($class);
281
-            }
282
-
283
-            // Add module
284
-            $this->add_module($module);
285
-
286
-            // Let parent do the heavy work
287
-            $void = parent::helper($class);
288
-
289
-            // Remove module
290
-            $this->remove_module();
291
-
292
-            return $void;
293
-        } else {
294
-            return parent::helper($helper);
295
-        }
296
-    }
297
-
298
-    /**
299
-     * Loads a language file
300
-     *
301
-     * @param	array
302
-     * @param	string
303
-     * @return	void
304
-     */
305
-    public function language($file = array(), $lang = '') {
306
-        if (is_array($file)) {
307
-            foreach ($file as $langfile) {
308
-                $this->language($langfile, $lang);
309
-            }
310
-            return;
311
-        }
312
-
313
-        // Detect module
314
-        if (list($module, $class) = $this->detect_module($file)) {
315
-            // Module already loaded
316
-            if (in_array($module, $this->_ci_modules)) {
317
-                return parent::language($class, $lang);
318
-            }
319
-
320
-            // Add module
321
-            $this->add_module($module);
322
-
323
-            // Let parent do the heavy work
324
-            $void = parent::language($class, $lang);
325
-
326
-            // Remove module
327
-            $this->remove_module();
328
-
329
-            return $void;
330
-        } else {
331
-            return parent::language($file, $lang);
332
-        }
333
-    }
334
-
335
-    /**
336
-     * Load Widget
337
-     *
338
-     * This function provides support to Jens Segers Template Library for loading
339
-     * widget controllers within modules (place in module/widgets folder).
340
-     * @author  hArpanet - 23-Jun-2014
341
-     *
342
-     * @param   string $widget  Must contain Module name if widget within a module
343
-     *                          (eg. test/nav  where module name is 'test')
344
-     * @return  array|false
345
-     */
346
-    public function widget($widget) {
347
-
348
-        // Detect module
349
-        if (list($module, $widget) = $this->detect_module($widget)) {
350
-            // Module already loaded
351
-            if (in_array($module, $this->_ci_modules)) {
352
-                return array($module, $widget);
353
-            }
354
-
355
-            // Add module
356
-            $this->add_module($module);
357
-
358
-            // Look again now we've added new module path
359
-            $void = $this->widget($module.'/'.$widget);
360
-
361
-            // Remove module if widget not found within it
362
-            if (!$void) {
363
-                $this->remove_module();
364
-            }
365
-
366
-            return $void;
367
-
368
-        } else {
369
-            // widget not found in module
370
-            return FALSE;
371
-        }
372
-    }
373
-
374
-    /**
375
-     * Add Module
376
-     *
377
-     * Allow resources to be loaded from this module path
378
-     *
379
-     * @param	string
380
-     * @param 	boolean
381
-     */
382
-    public function add_module($module, $view_cascade = TRUE) {
383
-        if ($path = $this->find_module($module)) {
384
-            // Mark module as loaded
385
-            array_unshift($this->_ci_modules, $module);
386
-
387
-            // Add package path
388
-            parent::add_package_path($path, $view_cascade);
389
-        }
390
-    }
391
-
392
-    /**
393
-     * Remove Module
394
-     *
395
-     * Remove a module from the allowed module paths
396
-     *
397
-     * @param	type
398
-     * @param 	bool
399
-     */
400
-    public function remove_module($module = '', $remove_config = TRUE) {
401
-        if ($module == '') {
402
-            // Mark module as not loaded
403
-            array_shift($this->_ci_modules);
404
-
405
-            // Remove package path
406
-            parent::remove_package_path('', $remove_config);
407
-        } else if (($key = array_search($module, $this->_ci_modules)) !== FALSE) {
408
-            if ($path = $this->find_module($module)) {
409
-                // Mark module as not loaded
410
-                unset($this->_ci_modules[$key]);
411
-
412
-                // Remove package path
413
-                parent::remove_package_path($path, $remove_config);
414
-            }
415
-        }
416
-    }
417
-
418
-    /**
419
-     * Controller loader
420
-     *
421
-     * This function is used to load and instantiate controllers
422
-     *
423
-     * @param	string
424
-     * @param	array
425
-     * @param	boolean
426
-     * @return	object
427
-     */
428
-    private function _load_controller($uri = '', $params = array(), $return = FALSE) {
429
-        $router = & $this->_ci_get_component('router');
430
-
431
-        // Back up current router values (before loading new controller)
432
-        $backup = array();
433
-        foreach (array('directory', 'class', 'method', 'module') as $prop) {
434
-            $backup[$prop] = $router->{$prop};
435
-        }
436
-
437
-        // Locate the controller
438
-        $segments = $router->locate(explode('/', $uri));
439
-        $class = isset($segments[0]) ? $segments[0] : FALSE;
440
-        $method = isset($segments[1]) ? $segments[1] : "index";
441
-
442
-        // Controller not found
443
-        if (!$class) {
444
-            return;
445
-        }
446
-
447
-        if (!array_key_exists(strtolower($class), $this->_ci_controllers)) {
448
-            // Determine filepath
449
-            $filepath = APPPATH . 'controllers/' . $router->fetch_directory() . $class . '.php';
450
-
451
-            // Load the controller file
452
-            if (file_exists($filepath)) {
453
-                include_once ($filepath);
454
-            }
455
-
456
-            // Controller class not found, show 404
457
-            if (!class_exists($class)) {
458
-                show_404("{$class}/{$method}");
459
-            }
460
-
461
-            // Create a controller object
462
-            $this->_ci_controllers[strtolower($class)] = new $class();
463
-        }
464
-
465
-        $controller = $this->_ci_controllers[strtolower($class)];
466
-
467
-        // Method does not exists
468
-        if (!method_exists($controller, $method)) {
469
-            show_404("{$class}/{$method}");
470
-        }
471
-
472
-        // Restore router state
473
-        foreach ($backup as $prop => $value) {
474
-            $router->{$prop} = $value;
475
-        }
476
-
477
-        // Capture output and return
478
-        ob_start();
479
-        $result = call_user_func_array(array($controller, $method), $params);
480
-
481
-        // Return the buffered output
482
-        if ($return === TRUE) {
483
-            $buffer = ob_get_contents();
484
-            @ob_end_clean();
485
-            return $buffer;
486
-        }
487
-
488
-        // Close buffer and flush output to screen
489
-        ob_end_flush();
490
-
491
-        // Return controller return value
492
-        return $result;
493
-    }
494
-
495
-    /**
496
-     * Detects the module from a string. Returns the module name and class if found.
497
-     *
498
-     * @param	string
499
-     * @return	array|boolean
500
-     */
501
-    private function detect_module($class) {
502
-        $class = str_replace('.php', '', trim($class, '/'));
503
-        if (($first_slash = strpos($class, '/')) !== FALSE) {
504
-            $module = substr($class, 0, $first_slash);
505
-            $class = substr($class, $first_slash + 1);
506
-
507
-            // Check if module exists
508
-            if ($this->find_module($module)) {
509
-                return array($module, $class);
510
-            }
511
-        }
512
-
513
-        return FALSE;
514
-    }
515
-
516
-    /**
517
-     * Searches a given module name. Returns the path if found, FALSE otherwise
518
-     *
519
-     * @param string $module
520
-     * @return string|boolean
521
-     */
522
-    private function find_module($module) {
523
-        $config = & $this->_ci_get_component('config');
524
-
525
-        // Check all locations for this module
526
-        foreach ($config->item('modules_locations') as $location) {
527
-            $path = $location . rtrim($module, '/') . '/';
528
-            if (is_dir($path)) {
529
-                return $path;
530
-            }
531
-        }
532
-
533
-        return FALSE;
534
-    }
37
+	/**
38
+	 * List of loaded modules
39
+	 *
40
+	 * @var array
41
+	 * @access protected
42
+	 */
43
+	protected $_ci_modules = array();
44
+
45
+	/**
46
+	 * List of loaded controllers
47
+	 *
48
+	 * @var array
49
+	 * @access protected
50
+	 */
51
+	protected $_ci_controllers = array();
52
+
53
+	/**
54
+	 * Constructor
55
+	 *
56
+	 * Add the current module to all paths permanently
57
+	 */
58
+	public function __construct() {
59
+		parent::__construct();
60
+
61
+		// Get current module from the router
62
+		$router = & $this->_ci_get_component('router');
63
+		if ($router->module) {
64
+			$this->add_module($router->module);
65
+		}
66
+	}
67
+
68
+	/**
69
+	 * Controller Loader
70
+	 *
71
+	 * This function lets users load and hierarchical controllers to enable HMVC support
72
+	 *
73
+	 * @param	string	the uri to the controller
74
+	 * @param	array	parameters for the requested method
75
+	 * @param	boolean return the result instead of showing it
76
+	 * @return	void
77
+	 */
78
+	public function controller($uri, $params = array(), $return = FALSE) {
79
+		// No valid module detected, add current module to uri
80
+		list($module) = $this->detect_module($uri);
81
+		if (!isset($module)) {
82
+			$router = & $this->_ci_get_component('router');
83
+			if ($router->module) {
84
+				$module = $router->module;
85
+				$uri = $module . '/' . $uri;
86
+			}
87
+		}
88
+
89
+		// Add module
90
+		$this->add_module($module);
91
+
92
+		// Execute the controller method and capture output
93
+		$void = $this->_load_controller($uri, $params, $return);
94
+
95
+		// Remove module
96
+		$this->remove_module();
97
+
98
+		return $void;
99
+	}
100
+
101
+	/**
102
+	 * Class Loader
103
+	 *
104
+	 * This function lets users load and instantiate classes.
105
+	 * It is designed to be called from a user's app controllers.
106
+	 *
107
+	 * @param	string	the name of the class
108
+	 * @param	mixed	the optional parameters
109
+	 * @param	string	an optional object name
110
+	 * @return	void
111
+	 */
112
+	public function library($library = '', $params = NULL, $object_name = NULL) {
113
+		if (is_array($library)) {
114
+			foreach ($library as $class) {
115
+				$this->library($class, $params);
116
+			}
117
+			return;
118
+		}
119
+
120
+		// Detect module
121
+		if (list($module, $class) = $this->detect_module($library)) {
122
+			// Module already loaded
123
+			if (in_array($module, $this->_ci_modules)) {
124
+				return parent::library($class, $params, $object_name);
125
+			}
126
+
127
+			// Add module
128
+			$this->add_module($module);
129
+
130
+			// Let parent do the heavy work
131
+			$void = parent::library($class, $params, $object_name);
132
+
133
+			// Remove module
134
+			$this->remove_module();
135
+
136
+			return $void;
137
+		} else {
138
+			return parent::library($library, $params, $object_name);
139
+		}
140
+	}
141
+
142
+	/**
143
+	 * Model Loader
144
+	 *
145
+	 * This function lets users load and instantiate models.
146
+	 *
147
+	 * @param	string	the name of the class
148
+	 * @param	string	name for the model
149
+	 * @param	bool	database connection
150
+	 * @return	void
151
+	 */
152
+	public function model($model, $name = '', $db_conn = FALSE) {
153
+		if (is_array($model)) {
154
+			foreach ($model as $babe) {
155
+				$this->model($babe);
156
+			}
157
+			return;
158
+		}
159
+
160
+		// Detect module
161
+		if (list($module, $class) = $this->detect_module($model)) {
162
+			// Module already loaded
163
+			if (in_array($module, $this->_ci_modules)) {
164
+				return parent::model($class, $name, $db_conn);
165
+			}
166
+
167
+			// Add module
168
+			$this->add_module($module);
169
+
170
+			// Let parent do the heavy work
171
+			$void = parent::model($class, $name, $db_conn);
172
+
173
+			// Remove module
174
+			$this->remove_module();
175
+
176
+			return $void;
177
+		} else {
178
+			return parent::model($model, $name, $db_conn);
179
+		}
180
+	}
181
+
182
+	/**
183
+	 * Load View
184
+	 *
185
+	 * This function is used to load a "view" file.  It has three parameters:
186
+	 *
187
+	 * 1. The name of the "view" file to be included.
188
+	 * 2. An associative array of data to be extracted for use in the view.
189
+	 * 3. TRUE/FALSE - whether to return the data or load it.  In
190
+	 * some cases it's advantageous to be able to return data so that
191
+	 * a developer can process it in some way.
192
+	 *
193
+	 * @param	string
194
+	 * @param	array
195
+	 * @param	bool
196
+	 * @return	void
197
+	 */
198
+	public function view($view, $vars = array(), $return = FALSE)
199
+	{
200
+		// Allow application/views/* to override any module
201
+		// views for easier app customization.
202
+		if (file_exists(APPPATH .'views/'. $view .'.php'))
203
+		{
204
+			return parent::view($view, $vars, $return);
205
+		}
206
+
207
+		// Detect module
208
+		if (list($module, $class) = $this->detect_module($view)) {
209
+			// Module already loaded
210
+			if (in_array($module, $this->_ci_modules)) {
211
+				return parent::view($class, $vars, $return);
212
+			}
213
+
214
+			// Add module
215
+			$this->add_module($module);
216
+
217
+			// Let parent do the heavy work
218
+			$void = parent::view($class, $vars, $return);
219
+
220
+			// Remove module
221
+			$this->remove_module();
222
+
223
+			return $void;
224
+		} else {
225
+			return parent::view($view, $vars, $return);
226
+		}
227
+	}
228
+
229
+	/**
230
+	 * Loads a config file
231
+	 *
232
+	 * @param	string
233
+	 * @param	bool
234
+	 * @param 	bool
235
+	 * @return	void
236
+	 */
237
+	public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) {
238
+		// Detect module
239
+		if (list($module, $class) = $this->detect_module($file)) {
240
+			// Module already loaded
241
+			if (in_array($module, $this->_ci_modules)) {
242
+				return parent::config($class, $use_sections, $fail_gracefully);
243
+			}
244
+
245
+			// Add module
246
+			$this->add_module($module);
247
+
248
+			// Let parent do the heavy work
249
+			$void = parent::config($class, $use_sections, $fail_gracefully);
250
+
251
+			// Remove module
252
+			$this->remove_module();
253
+
254
+			return $void;
255
+		} else {
256
+			parent::config($file, $use_sections, $fail_gracefully);
257
+		}
258
+	}
259
+
260
+	/**
261
+	 * Load Helper
262
+	 *
263
+	 * This function loads the specified helper file.
264
+	 *
265
+	 * @param	mixed
266
+	 * @return	void
267
+	 */
268
+	public function helper($helper = array()) {
269
+		if (is_array($helper)) {
270
+			foreach ($helper as $help) {
271
+				$this->helper($help);
272
+			}
273
+			return;
274
+		}
275
+
276
+		// Detect module
277
+		if (list($module, $class) = $this->detect_module($helper)) {
278
+			// Module already loaded
279
+			if (in_array($module, $this->_ci_modules)) {
280
+				return parent::helper($class);
281
+			}
282
+
283
+			// Add module
284
+			$this->add_module($module);
285
+
286
+			// Let parent do the heavy work
287
+			$void = parent::helper($class);
288
+
289
+			// Remove module
290
+			$this->remove_module();
291
+
292
+			return $void;
293
+		} else {
294
+			return parent::helper($helper);
295
+		}
296
+	}
297
+
298
+	/**
299
+	 * Loads a language file
300
+	 *
301
+	 * @param	array
302
+	 * @param	string
303
+	 * @return	void
304
+	 */
305
+	public function language($file = array(), $lang = '') {
306
+		if (is_array($file)) {
307
+			foreach ($file as $langfile) {
308
+				$this->language($langfile, $lang);
309
+			}
310
+			return;
311
+		}
312
+
313
+		// Detect module
314
+		if (list($module, $class) = $this->detect_module($file)) {
315
+			// Module already loaded
316
+			if (in_array($module, $this->_ci_modules)) {
317
+				return parent::language($class, $lang);
318
+			}
319
+
320
+			// Add module
321
+			$this->add_module($module);
322
+
323
+			// Let parent do the heavy work
324
+			$void = parent::language($class, $lang);
325
+
326
+			// Remove module
327
+			$this->remove_module();
328
+
329
+			return $void;
330
+		} else {
331
+			return parent::language($file, $lang);
332
+		}
333
+	}
334
+
335
+	/**
336
+	 * Load Widget
337
+	 *
338
+	 * This function provides support to Jens Segers Template Library for loading
339
+	 * widget controllers within modules (place in module/widgets folder).
340
+	 * @author  hArpanet - 23-Jun-2014
341
+	 *
342
+	 * @param   string $widget  Must contain Module name if widget within a module
343
+	 *                          (eg. test/nav  where module name is 'test')
344
+	 * @return  array|false
345
+	 */
346
+	public function widget($widget) {
347
+
348
+		// Detect module
349
+		if (list($module, $widget) = $this->detect_module($widget)) {
350
+			// Module already loaded
351
+			if (in_array($module, $this->_ci_modules)) {
352
+				return array($module, $widget);
353
+			}
354
+
355
+			// Add module
356
+			$this->add_module($module);
357
+
358
+			// Look again now we've added new module path
359
+			$void = $this->widget($module.'/'.$widget);
360
+
361
+			// Remove module if widget not found within it
362
+			if (!$void) {
363
+				$this->remove_module();
364
+			}
365
+
366
+			return $void;
367
+
368
+		} else {
369
+			// widget not found in module
370
+			return FALSE;
371
+		}
372
+	}
373
+
374
+	/**
375
+	 * Add Module
376
+	 *
377
+	 * Allow resources to be loaded from this module path
378
+	 *
379
+	 * @param	string
380
+	 * @param 	boolean
381
+	 */
382
+	public function add_module($module, $view_cascade = TRUE) {
383
+		if ($path = $this->find_module($module)) {
384
+			// Mark module as loaded
385
+			array_unshift($this->_ci_modules, $module);
386
+
387
+			// Add package path
388
+			parent::add_package_path($path, $view_cascade);
389
+		}
390
+	}
391
+
392
+	/**
393
+	 * Remove Module
394
+	 *
395
+	 * Remove a module from the allowed module paths
396
+	 *
397
+	 * @param	type
398
+	 * @param 	bool
399
+	 */
400
+	public function remove_module($module = '', $remove_config = TRUE) {
401
+		if ($module == '') {
402
+			// Mark module as not loaded
403
+			array_shift($this->_ci_modules);
404
+
405
+			// Remove package path
406
+			parent::remove_package_path('', $remove_config);
407
+		} else if (($key = array_search($module, $this->_ci_modules)) !== FALSE) {
408
+			if ($path = $this->find_module($module)) {
409
+				// Mark module as not loaded
410
+				unset($this->_ci_modules[$key]);
411
+
412
+				// Remove package path
413
+				parent::remove_package_path($path, $remove_config);
414
+			}
415
+		}
416
+	}
417
+
418
+	/**
419
+	 * Controller loader
420
+	 *
421
+	 * This function is used to load and instantiate controllers
422
+	 *
423
+	 * @param	string
424
+	 * @param	array
425
+	 * @param	boolean
426
+	 * @return	object
427
+	 */
428
+	private function _load_controller($uri = '', $params = array(), $return = FALSE) {
429
+		$router = & $this->_ci_get_component('router');
430
+
431
+		// Back up current router values (before loading new controller)
432
+		$backup = array();
433
+		foreach (array('directory', 'class', 'method', 'module') as $prop) {
434
+			$backup[$prop] = $router->{$prop};
435
+		}
436
+
437
+		// Locate the controller
438
+		$segments = $router->locate(explode('/', $uri));
439
+		$class = isset($segments[0]) ? $segments[0] : FALSE;
440
+		$method = isset($segments[1]) ? $segments[1] : "index";
441
+
442
+		// Controller not found
443
+		if (!$class) {
444
+			return;
445
+		}
446
+
447
+		if (!array_key_exists(strtolower($class), $this->_ci_controllers)) {
448
+			// Determine filepath
449
+			$filepath = APPPATH . 'controllers/' . $router->fetch_directory() . $class . '.php';
450
+
451
+			// Load the controller file
452
+			if (file_exists($filepath)) {
453
+				include_once ($filepath);
454
+			}
455
+
456
+			// Controller class not found, show 404
457
+			if (!class_exists($class)) {
458
+				show_404("{$class}/{$method}");
459
+			}
460
+
461
+			// Create a controller object
462
+			$this->_ci_controllers[strtolower($class)] = new $class();
463
+		}
464
+
465
+		$controller = $this->_ci_controllers[strtolower($class)];
466
+
467
+		// Method does not exists
468
+		if (!method_exists($controller, $method)) {
469
+			show_404("{$class}/{$method}");
470
+		}
471
+
472
+		// Restore router state
473
+		foreach ($backup as $prop => $value) {
474
+			$router->{$prop} = $value;
475
+		}
476
+
477
+		// Capture output and return
478
+		ob_start();
479
+		$result = call_user_func_array(array($controller, $method), $params);
480
+
481
+		// Return the buffered output
482
+		if ($return === TRUE) {
483
+			$buffer = ob_get_contents();
484
+			@ob_end_clean();
485
+			return $buffer;
486
+		}
487
+
488
+		// Close buffer and flush output to screen
489
+		ob_end_flush();
490
+
491
+		// Return controller return value
492
+		return $result;
493
+	}
494
+
495
+	/**
496
+	 * Detects the module from a string. Returns the module name and class if found.
497
+	 *
498
+	 * @param	string
499
+	 * @return	array|boolean
500
+	 */
501
+	private function detect_module($class) {
502
+		$class = str_replace('.php', '', trim($class, '/'));
503
+		if (($first_slash = strpos($class, '/')) !== FALSE) {
504
+			$module = substr($class, 0, $first_slash);
505
+			$class = substr($class, $first_slash + 1);
506
+
507
+			// Check if module exists
508
+			if ($this->find_module($module)) {
509
+				return array($module, $class);
510
+			}
511
+		}
512
+
513
+		return FALSE;
514
+	}
515
+
516
+	/**
517
+	 * Searches a given module name. Returns the path if found, FALSE otherwise
518
+	 *
519
+	 * @param string $module
520
+	 * @return string|boolean
521
+	 */
522
+	private function find_module($module) {
523
+		$config = & $this->_ci_get_component('config');
524
+
525
+		// Check all locations for this module
526
+		foreach ($config->item('modules_locations') as $location) {
527
+			$path = $location . rtrim($module, '/') . '/';
528
+			if (is_dir($path)) {
529
+				return $path;
530
+			}
531
+		}
532
+
533
+		return FALSE;
534
+	}
535 535
 }
Please login to merge, or discard this patch.
application/views/errors/cli/error_php.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,15 +10,15 @@
 block discarded – undo
10 10
 <?php echo \Myth\CLI::write("\tLine Number: {$line}"); ?>
11 11
 
12 12
 <?php
13
-    if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE) {
13
+	if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === TRUE) {
14 14
 
15
-        echo \Myth\CLI::write("\n\tBacktrace");
15
+		echo \Myth\CLI::write("\n\tBacktrace");
16 16
 
17
-        foreach (debug_backtrace() as $error) {
18
-            if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0) {
19
-                echo \Myth\CLI::write("\t\t- {$error['function']}() - Line {$error['line']} in {$error['file']}");
20
-            }
21
-        }
17
+		foreach (debug_backtrace() as $error) {
18
+			if (isset($error['file']) && strpos($error['file'], realpath(BASEPATH)) !== 0) {
19
+				echo \Myth\CLI::write("\t\t- {$error['function']}() - Line {$error['line']} in {$error['file']}");
20
+			}
21
+		}
22 22
 }
23 23
 
24 24
 echo \Myth\CLI::new_line();
Please login to merge, or discard this patch.