@@ -2,33 +2,33 @@ |
||
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 | } |
@@ -2,85 +2,85 @@ |
||
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 | ||
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 | ||
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 | } |
@@ -4,363 +4,363 @@ |
||
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 | } |
@@ -30,506 +30,506 @@ |
||
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 | } |
@@ -1,310 +1,310 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @name CodeIgniter HMVC Modules |
|
4 | - * @author Jens Segers |
|
5 | - * @link http://www.jenssegers.be |
|
6 | - * @license MIT License Copyright (c) 2012 Jens Segers |
|
7 | - * |
|
8 | - * @author hArpanet |
|
9 | - * @link http://harpanet.com |
|
10 | - * Updated for CI 3.0-dev. |
|
11 | - * Added _set_default_controller() to allow default_controller |
|
12 | - * (specified in config/routes.php) to reside in a module of the same name. |
|
13 | - * |
|
14 | - * Inspired by wiredesignz's HMVC Router. |
|
15 | - * https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/ |
|
16 | - * |
|
17 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
18 | - * of this software and associated documentation files (the "Software"), to deal |
|
19 | - * in the Software without restriction, including without limitation the rights |
|
20 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
21 | - * copies of the Software, and to permit persons to whom the Software is |
|
22 | - * furnished to do so, subject to the following conditions: |
|
23 | - * |
|
24 | - * The above copyright notice and this permission notice shall be included in |
|
25 | - * all copies or substantial portions of the Software. |
|
26 | - * |
|
27 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
28 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
29 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
30 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
31 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
32 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
33 | - * THE SOFTWARE. |
|
34 | - */ |
|
3 | + * @name CodeIgniter HMVC Modules |
|
4 | + * @author Jens Segers |
|
5 | + * @link http://www.jenssegers.be |
|
6 | + * @license MIT License Copyright (c) 2012 Jens Segers |
|
7 | + * |
|
8 | + * @author hArpanet |
|
9 | + * @link http://harpanet.com |
|
10 | + * Updated for CI 3.0-dev. |
|
11 | + * Added _set_default_controller() to allow default_controller |
|
12 | + * (specified in config/routes.php) to reside in a module of the same name. |
|
13 | + * |
|
14 | + * Inspired by wiredesignz's HMVC Router. |
|
15 | + * https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/ |
|
16 | + * |
|
17 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
18 | + * of this software and associated documentation files (the "Software"), to deal |
|
19 | + * in the Software without restriction, including without limitation the rights |
|
20 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
21 | + * copies of the Software, and to permit persons to whom the Software is |
|
22 | + * furnished to do so, subject to the following conditions: |
|
23 | + * |
|
24 | + * The above copyright notice and this permission notice shall be included in |
|
25 | + * all copies or substantial portions of the Software. |
|
26 | + * |
|
27 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
28 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
29 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
30 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
31 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
32 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
33 | + * THE SOFTWARE. |
|
34 | + */ |
|
35 | 35 | |
36 | 36 | if (!defined("BASEPATH")) |
37 | - exit("No direct script access allowed"); |
|
37 | + exit("No direct script access allowed"); |
|
38 | 38 | |
39 | 39 | class HMVC_Router extends CI_Router { |
40 | 40 | |
41 | - /** |
|
42 | - * Current module name |
|
43 | - * |
|
44 | - * @var string |
|
45 | - * @access public |
|
46 | - */ |
|
47 | - var $module = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * Constructor |
|
51 | - * |
|
52 | - * Runs the route mapping function. |
|
53 | - */ |
|
54 | - function __construct() { |
|
55 | - |
|
56 | - $this->config =& load_class('Config', 'core'); |
|
57 | - |
|
58 | - // Process 'modules_locations' from config |
|
59 | - $locations = $this->config->item('modules_locations'); |
|
60 | - |
|
61 | - if (!$locations) { |
|
62 | - $locations = array(APPPATH . 'modules/'); |
|
63 | - } else if (!is_array($locations)) { |
|
64 | - $locations = array($locations); |
|
65 | - } |
|
66 | - |
|
67 | - // Make sure all paths are the same format |
|
68 | - foreach ($locations as &$location) { |
|
69 | - $location = realpath($location); |
|
70 | - $location = str_replace('\\', '/', $location); |
|
71 | - $location = rtrim($location, '/') . '/'; |
|
72 | - } |
|
73 | - |
|
74 | - $this->config->set_item('modules_locations', $locations); |
|
75 | - |
|
76 | - |
|
77 | - parent::__construct(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Validates the supplied segments. Attempts to determine the path to |
|
82 | - * the controller. |
|
83 | - * |
|
84 | - * @access private |
|
85 | - * @param array |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - function _validate_request($segments) { |
|
89 | - if (count($segments) == 0) { |
|
90 | - return $segments; |
|
91 | - } |
|
92 | - |
|
93 | - // Locate the controller with modules support |
|
94 | - if ($located = $this->locate($segments)) { |
|
95 | - return $located; |
|
96 | - } |
|
97 | - |
|
98 | - // Is there a 404 override? |
|
99 | - if (!empty($this->routes['404_override'])) { |
|
100 | - $segments = explode('/', $this->routes['404_override']); |
|
101 | - if ($located = $this->locate($segments)) { |
|
102 | - return $located; |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - // Nothing else to do at this point but show a 404 |
|
107 | - show_404($segments[0]); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Parse Routes |
|
112 | - * |
|
113 | - * This function matches any routes that may exist in |
|
114 | - * the config/routes.php file against the URI to |
|
115 | - * determine if the class/method need to be remapped. |
|
116 | - * |
|
117 | - * NOTE: The first segment must stay the name of the |
|
118 | - * module, otherwise it is impossible to detect |
|
119 | - * the current module in this method. |
|
120 | - * |
|
121 | - * @access private |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - function _parse_routes() { |
|
125 | - // Apply the current module's routing config |
|
126 | - |
|
127 | - // CI v3.x has URI starting at segment 1 |
|
128 | - $segstart = (intval(substr(CI_VERSION,0,1)) > 2) ? 1 : 0; |
|
129 | - |
|
130 | - if ($module = $this->uri->segment($segstart)) { |
|
131 | - foreach ($this->config->item('modules_locations') as $location) { |
|
132 | - if (is_file($file = $location . $module . '/config/routes.php')) { |
|
133 | - include ($file); |
|
134 | - |
|
135 | - $route = (!isset($route) or !is_array($route)) ? array() : $route; |
|
136 | - $this->routes = array_merge($this->routes, $route); |
|
137 | - unset($route); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - // Let parent do the heavy routing |
|
143 | - return parent::_parse_routes(); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * The logic of locating a controller is grouped in this function |
|
148 | - * |
|
149 | - * @param array |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - function locate($segments) { |
|
153 | - // anon function to ucfirst a string if CI ver > 2 (for backwards compatibility) |
|
154 | - $_ucfirst = function($cn) {return (intval(substr(CI_VERSION,0,1)) > 2) ? ucfirst($cn) : $cn;}; |
|
155 | - |
|
156 | - list($module, $directory, $controller) = array_pad($segments, 3, NULL); |
|
157 | - |
|
158 | - // Look for it in the standar APPPATH/controllers first so that it can override modules. |
|
159 | - $c = count($segments); |
|
160 | - $s = $segments; |
|
161 | - // Loop through our segments and return as soon as a controller |
|
162 | - // is found or when such a directory doesn't exist |
|
163 | - while ($c-- > 0) |
|
164 | - { |
|
165 | - $test = $this->directory |
|
166 | - .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $s[0]) : $s[0]); |
|
167 | - |
|
168 | - if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$s[0])) |
|
169 | - { |
|
170 | - $this->set_directory(array_shift($s), TRUE); |
|
171 | - continue; |
|
172 | - } |
|
173 | - elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
174 | - { |
|
175 | - return $s; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - unset($s); |
|
180 | - |
|
181 | - // Now look for it in all of our modules. |
|
182 | - foreach ($this->config->item('modules_locations') as $location) { |
|
183 | - $relative = $location; |
|
184 | - |
|
185 | - // Make path relative to controllers directory |
|
186 | - $start = rtrim(realpath(APPPATH), '/'); |
|
187 | - $parts = explode('/', str_replace('\\', '/', $start)); |
|
188 | - |
|
189 | - // Iterate all parts and replace absolute part with relative part |
|
190 | - for ($i = 1; $i <= count($parts); $i++) { |
|
191 | - $relative = str_replace(implode('/', $parts) . '/', str_repeat('../', $i), $relative, $count); |
|
192 | - array_pop($parts); |
|
193 | - |
|
194 | - // Stop iteration if found |
|
195 | - if ($count) |
|
196 | - break; |
|
197 | - } |
|
198 | - |
|
199 | - // Does a module exist? (/modules/xyz/controllers/) |
|
200 | - if (is_dir($source = $location . $module . '/controllers/')) { |
|
201 | - $this->module = $module; |
|
202 | - $this->directory = $relative . $module . '/controllers/'; |
|
203 | - |
|
204 | - // Module root controller? |
|
205 | - if ($directory && is_file($source . $_ucfirst($directory) . '.php')) { |
|
206 | - $this->class = $directory; |
|
207 | - return array_slice($segments, 1); |
|
208 | - } |
|
209 | - |
|
210 | - // Module sub-directory? |
|
211 | - if ($directory && is_dir($source . $directory . '/')) { |
|
212 | - $source = $source . $directory . '/'; |
|
213 | - $this->directory .= $directory . '/'; |
|
214 | - |
|
215 | - // Module sub-directory controller? |
|
216 | - if (is_file($source . $_ucfirst($directory) . '.php')) { |
|
217 | - return array_slice($segments, 1); |
|
218 | - } |
|
219 | - |
|
220 | - // Module sub-directory default controller? |
|
221 | - if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
222 | - $segments[1] = $this->default_controller; |
|
223 | - return array_slice($segments, 1); |
|
224 | - } |
|
225 | - |
|
226 | - // Module sub-directory sub-controller? |
|
227 | - if ($controller && is_file($source . $_ucfirst($controller) . '.php')) { |
|
228 | - return array_slice($segments, 2); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - // Module controller? |
|
233 | - if (is_file($source . $_ucfirst($module) . '.php')) { |
|
234 | - return $segments; |
|
235 | - } |
|
236 | - |
|
237 | - // Module default controller? |
|
238 | - if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
239 | - $segments[0] = $this->default_controller; |
|
240 | - return $segments; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - // Default controller? |
|
246 | - if (is_file(APPPATH . 'controllers/' . $module . '/' . $_ucfirst($this->default_controller) . '.php')) { |
|
247 | - $segments[0] = $this->default_controller; |
|
248 | - return $segments; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Set the module name |
|
254 | - * |
|
255 | - * @param string |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - function set_module($module) { |
|
259 | - $this->module = $module; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Set default controller |
|
264 | - * |
|
265 | - * First we check in normal APPPATH/controller's location, |
|
266 | - * then in Modules named after the default_controller |
|
267 | - * @author hArpanet - based on system/core/Router.php |
|
268 | - * |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - protected function _set_default_controller() |
|
272 | - { |
|
273 | - // controller in APPPATH/controllers takes priority over module with same name |
|
274 | - parent::_set_default_controller(); |
|
275 | - |
|
276 | - // see if parent found a controller |
|
277 | - $class = $this->fetch_class(); |
|
278 | - |
|
279 | - if (empty($class)) { |
|
280 | - |
|
281 | - // no 'normal' controller found, |
|
282 | - // get the class/method from the default_controller route |
|
283 | - if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) |
|
284 | - { |
|
285 | - $method = 'index'; |
|
286 | - } |
|
287 | - |
|
288 | - // try to locate default controller in modules |
|
289 | - if ($located = $this->locate(array($class, $class, $method))) { |
|
290 | - |
|
291 | - log_message('debug', 'No URI present. Default module controller set.'); |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - // Nothing found - this will trigger 404 later |
|
296 | - } |
|
297 | - |
|
298 | - // -------------------------------------------------------------------- |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Fetch the module |
|
303 | - * |
|
304 | - * @access public |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - function fetch_module() { |
|
308 | - return $this->module; |
|
309 | - } |
|
41 | + /** |
|
42 | + * Current module name |
|
43 | + * |
|
44 | + * @var string |
|
45 | + * @access public |
|
46 | + */ |
|
47 | + var $module = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * Constructor |
|
51 | + * |
|
52 | + * Runs the route mapping function. |
|
53 | + */ |
|
54 | + function __construct() { |
|
55 | + |
|
56 | + $this->config =& load_class('Config', 'core'); |
|
57 | + |
|
58 | + // Process 'modules_locations' from config |
|
59 | + $locations = $this->config->item('modules_locations'); |
|
60 | + |
|
61 | + if (!$locations) { |
|
62 | + $locations = array(APPPATH . 'modules/'); |
|
63 | + } else if (!is_array($locations)) { |
|
64 | + $locations = array($locations); |
|
65 | + } |
|
66 | + |
|
67 | + // Make sure all paths are the same format |
|
68 | + foreach ($locations as &$location) { |
|
69 | + $location = realpath($location); |
|
70 | + $location = str_replace('\\', '/', $location); |
|
71 | + $location = rtrim($location, '/') . '/'; |
|
72 | + } |
|
73 | + |
|
74 | + $this->config->set_item('modules_locations', $locations); |
|
75 | + |
|
76 | + |
|
77 | + parent::__construct(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Validates the supplied segments. Attempts to determine the path to |
|
82 | + * the controller. |
|
83 | + * |
|
84 | + * @access private |
|
85 | + * @param array |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + function _validate_request($segments) { |
|
89 | + if (count($segments) == 0) { |
|
90 | + return $segments; |
|
91 | + } |
|
92 | + |
|
93 | + // Locate the controller with modules support |
|
94 | + if ($located = $this->locate($segments)) { |
|
95 | + return $located; |
|
96 | + } |
|
97 | + |
|
98 | + // Is there a 404 override? |
|
99 | + if (!empty($this->routes['404_override'])) { |
|
100 | + $segments = explode('/', $this->routes['404_override']); |
|
101 | + if ($located = $this->locate($segments)) { |
|
102 | + return $located; |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + // Nothing else to do at this point but show a 404 |
|
107 | + show_404($segments[0]); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Parse Routes |
|
112 | + * |
|
113 | + * This function matches any routes that may exist in |
|
114 | + * the config/routes.php file against the URI to |
|
115 | + * determine if the class/method need to be remapped. |
|
116 | + * |
|
117 | + * NOTE: The first segment must stay the name of the |
|
118 | + * module, otherwise it is impossible to detect |
|
119 | + * the current module in this method. |
|
120 | + * |
|
121 | + * @access private |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + function _parse_routes() { |
|
125 | + // Apply the current module's routing config |
|
126 | + |
|
127 | + // CI v3.x has URI starting at segment 1 |
|
128 | + $segstart = (intval(substr(CI_VERSION,0,1)) > 2) ? 1 : 0; |
|
129 | + |
|
130 | + if ($module = $this->uri->segment($segstart)) { |
|
131 | + foreach ($this->config->item('modules_locations') as $location) { |
|
132 | + if (is_file($file = $location . $module . '/config/routes.php')) { |
|
133 | + include ($file); |
|
134 | + |
|
135 | + $route = (!isset($route) or !is_array($route)) ? array() : $route; |
|
136 | + $this->routes = array_merge($this->routes, $route); |
|
137 | + unset($route); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + // Let parent do the heavy routing |
|
143 | + return parent::_parse_routes(); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * The logic of locating a controller is grouped in this function |
|
148 | + * |
|
149 | + * @param array |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + function locate($segments) { |
|
153 | + // anon function to ucfirst a string if CI ver > 2 (for backwards compatibility) |
|
154 | + $_ucfirst = function($cn) {return (intval(substr(CI_VERSION,0,1)) > 2) ? ucfirst($cn) : $cn;}; |
|
155 | + |
|
156 | + list($module, $directory, $controller) = array_pad($segments, 3, NULL); |
|
157 | + |
|
158 | + // Look for it in the standar APPPATH/controllers first so that it can override modules. |
|
159 | + $c = count($segments); |
|
160 | + $s = $segments; |
|
161 | + // Loop through our segments and return as soon as a controller |
|
162 | + // is found or when such a directory doesn't exist |
|
163 | + while ($c-- > 0) |
|
164 | + { |
|
165 | + $test = $this->directory |
|
166 | + .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $s[0]) : $s[0]); |
|
167 | + |
|
168 | + if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$s[0])) |
|
169 | + { |
|
170 | + $this->set_directory(array_shift($s), TRUE); |
|
171 | + continue; |
|
172 | + } |
|
173 | + elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
174 | + { |
|
175 | + return $s; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + unset($s); |
|
180 | + |
|
181 | + // Now look for it in all of our modules. |
|
182 | + foreach ($this->config->item('modules_locations') as $location) { |
|
183 | + $relative = $location; |
|
184 | + |
|
185 | + // Make path relative to controllers directory |
|
186 | + $start = rtrim(realpath(APPPATH), '/'); |
|
187 | + $parts = explode('/', str_replace('\\', '/', $start)); |
|
188 | + |
|
189 | + // Iterate all parts and replace absolute part with relative part |
|
190 | + for ($i = 1; $i <= count($parts); $i++) { |
|
191 | + $relative = str_replace(implode('/', $parts) . '/', str_repeat('../', $i), $relative, $count); |
|
192 | + array_pop($parts); |
|
193 | + |
|
194 | + // Stop iteration if found |
|
195 | + if ($count) |
|
196 | + break; |
|
197 | + } |
|
198 | + |
|
199 | + // Does a module exist? (/modules/xyz/controllers/) |
|
200 | + if (is_dir($source = $location . $module . '/controllers/')) { |
|
201 | + $this->module = $module; |
|
202 | + $this->directory = $relative . $module . '/controllers/'; |
|
203 | + |
|
204 | + // Module root controller? |
|
205 | + if ($directory && is_file($source . $_ucfirst($directory) . '.php')) { |
|
206 | + $this->class = $directory; |
|
207 | + return array_slice($segments, 1); |
|
208 | + } |
|
209 | + |
|
210 | + // Module sub-directory? |
|
211 | + if ($directory && is_dir($source . $directory . '/')) { |
|
212 | + $source = $source . $directory . '/'; |
|
213 | + $this->directory .= $directory . '/'; |
|
214 | + |
|
215 | + // Module sub-directory controller? |
|
216 | + if (is_file($source . $_ucfirst($directory) . '.php')) { |
|
217 | + return array_slice($segments, 1); |
|
218 | + } |
|
219 | + |
|
220 | + // Module sub-directory default controller? |
|
221 | + if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
222 | + $segments[1] = $this->default_controller; |
|
223 | + return array_slice($segments, 1); |
|
224 | + } |
|
225 | + |
|
226 | + // Module sub-directory sub-controller? |
|
227 | + if ($controller && is_file($source . $_ucfirst($controller) . '.php')) { |
|
228 | + return array_slice($segments, 2); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + // Module controller? |
|
233 | + if (is_file($source . $_ucfirst($module) . '.php')) { |
|
234 | + return $segments; |
|
235 | + } |
|
236 | + |
|
237 | + // Module default controller? |
|
238 | + if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
239 | + $segments[0] = $this->default_controller; |
|
240 | + return $segments; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + // Default controller? |
|
246 | + if (is_file(APPPATH . 'controllers/' . $module . '/' . $_ucfirst($this->default_controller) . '.php')) { |
|
247 | + $segments[0] = $this->default_controller; |
|
248 | + return $segments; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Set the module name |
|
254 | + * |
|
255 | + * @param string |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + function set_module($module) { |
|
259 | + $this->module = $module; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Set default controller |
|
264 | + * |
|
265 | + * First we check in normal APPPATH/controller's location, |
|
266 | + * then in Modules named after the default_controller |
|
267 | + * @author hArpanet - based on system/core/Router.php |
|
268 | + * |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + protected function _set_default_controller() |
|
272 | + { |
|
273 | + // controller in APPPATH/controllers takes priority over module with same name |
|
274 | + parent::_set_default_controller(); |
|
275 | + |
|
276 | + // see if parent found a controller |
|
277 | + $class = $this->fetch_class(); |
|
278 | + |
|
279 | + if (empty($class)) { |
|
280 | + |
|
281 | + // no 'normal' controller found, |
|
282 | + // get the class/method from the default_controller route |
|
283 | + if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) |
|
284 | + { |
|
285 | + $method = 'index'; |
|
286 | + } |
|
287 | + |
|
288 | + // try to locate default controller in modules |
|
289 | + if ($located = $this->locate(array($class, $class, $method))) { |
|
290 | + |
|
291 | + log_message('debug', 'No URI present. Default module controller set.'); |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + // Nothing found - this will trigger 404 later |
|
296 | + } |
|
297 | + |
|
298 | + // -------------------------------------------------------------------- |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Fetch the module |
|
303 | + * |
|
304 | + * @access public |
|
305 | + * @return string |
|
306 | + */ |
|
307 | + function fetch_module() { |
|
308 | + return $this->module; |
|
309 | + } |
|
310 | 310 | } |
@@ -10,15 +10,15 @@ |
||
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(); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | |
6 | 6 | <?= $uikit->row([], function() use($uikit) { |
7 | 7 | |
8 | - echo $uikit->column(['sizes' => ['l'=>6]], function() use($uikit) { ?> |
|
8 | + echo $uikit->column(['sizes' => ['l'=>6]], function() use($uikit) { ?> |
|
9 | 9 | <h3>What Is Sprint?</h3> |
10 | 10 | |
11 | 11 | <p>SprintPHP is a souped-up version of <a href="http://codeigniter.com">CodeIgniter <?= CI_VERSION ?></a>. And soon to be the heart and soul |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - echo $uikit->column(['sizes' => ['l'=>6]], function() use($uikit) { ?> |
|
28 | + echo $uikit->column(['sizes' => ['l'=>6]], function() use($uikit) { ?> |
|
29 | 29 | <h3>Get To Know Sprint</h3> |
30 | 30 | |
31 | 31 | <p>The following resources will help you as you explore the power and flexibility that SprintPHP provides. Feel free to dig into source code of the controllers and views |
@@ -39,6 +39,6 @@ discard block |
||
39 | 39 | |
40 | 40 | <?php }); |
41 | 41 | |
42 | - }); ?> |
|
42 | + }); ?> |
|
43 | 43 | |
44 | 44 | </div> |
@@ -1,34 +1,34 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Sprint |
|
4 | - * |
|
5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | - * |
|
7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | - * of this software and associated documentation files (the "Software"), to deal |
|
9 | - * in the Software without restriction, including without limitation the rights |
|
10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | - * copies of the Software, and to permit persons to whom the Software is |
|
12 | - * furnished to do so, subject to the following conditions: |
|
13 | - * |
|
14 | - * The above copyright notice and this permission notice shall be included in |
|
15 | - * all copies or substantial portions of the Software. |
|
16 | - * |
|
17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | - * THE SOFTWARE. |
|
24 | - * |
|
25 | - * @package Sprint |
|
26 | - * @author Lonnie Ezell |
|
27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | - * @link http://sprintphp.com |
|
30 | - * @since Version 1.0 |
|
31 | - */ |
|
3 | + * Sprint |
|
4 | + * |
|
5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | + * |
|
7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | + * of this software and associated documentation files (the "Software"), to deal |
|
9 | + * in the Software without restriction, including without limitation the rights |
|
10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | + * copies of the Software, and to permit persons to whom the Software is |
|
12 | + * furnished to do so, subject to the following conditions: |
|
13 | + * |
|
14 | + * The above copyright notice and this permission notice shall be included in |
|
15 | + * all copies or substantial portions of the Software. |
|
16 | + * |
|
17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | + * THE SOFTWARE. |
|
24 | + * |
|
25 | + * @package Sprint |
|
26 | + * @author Lonnie Ezell |
|
27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | + * @link http://sprintphp.com |
|
30 | + * @since Version 1.0 |
|
31 | + */ |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * BUILD TOOL |
@@ -11,7 +11,7 @@ |
||
11 | 11 | $config['builds'] = [ |
12 | 12 | 'release' => 'SprintRelease', |
13 | 13 | 'postCreateProject' => 'InitialCleanup', |
14 | - 'publishSubTrees' => 'SubTreeSplit' |
|
14 | + 'publishSubTrees' => 'SubTreeSplit' |
|
15 | 15 | ]; |
16 | 16 | |
17 | 17 | //-------------------------------------------------------------------- |