@@ -34,14 +34,14 @@ class Key extends REST_Controller {
3434 public function index_put ()
3535 {
3636 // Build a new key
37- $ key = self :: _generate_key ();
37+ $ key = $ this -> _generate_key ();
3838
3939 // If no key level provided, provide a generic key
4040 $ level = $ this ->put ('level ' ) ? $ this ->put ('level ' ) : 1 ;
4141 $ ignore_limits = ctype_digit ($ this ->put ('ignore_limits ' )) ? (int ) $ this ->put ('ignore_limits ' ) : 1 ;
4242
4343 // Insert the new key
44- if (self :: _insert_key ($ key , ['level ' => $ level , 'ignore_limits ' => $ ignore_limits ]))
44+ if ($ this -> _insert_key ($ key , ['level ' => $ level , 'ignore_limits ' => $ ignore_limits ]))
4545 {
4646 $ this ->response ([
4747 'status ' => TRUE ,
@@ -68,7 +68,7 @@ public function index_delete()
6868 $ key = $ this ->delete ('key ' );
6969
7070 // Does this key exist?
71- if (!self :: _key_exists ($ key ))
71+ if (!$ this -> _key_exists ($ key ))
7272 {
7373 // It doesn't appear the key exists
7474 $ this ->response ([
@@ -78,7 +78,7 @@ public function index_delete()
7878 }
7979
8080 // Destroy it
81- self :: _delete_key ($ key );
81+ $ this -> _delete_key ($ key );
8282
8383 // Respond that the key was destroyed
8484 $ this ->response ([
@@ -99,7 +99,7 @@ public function level_post()
9999 $ new_level = $ this ->post ('level ' );
100100
101101 // Does this key exist?
102- if (!self :: _key_exists ($ key ))
102+ if (!$ this -> _key_exists ($ key ))
103103 {
104104 // It doesn't appear the key exists
105105 $ this ->response ([
@@ -109,7 +109,7 @@ public function level_post()
109109 }
110110
111111 // Update the key level
112- if (self :: _update_key ($ key , ['level ' => $ new_level ]))
112+ if ($ this -> _update_key ($ key , ['level ' => $ new_level ]))
113113 {
114114 $ this ->response ([
115115 'status ' => TRUE ,
@@ -126,7 +126,7 @@ public function level_post()
126126 }
127127
128128 /**
129- * Change the level
129+ * Suspend a key
130130 *
131131 * @access public
132132 * @return void
@@ -136,7 +136,7 @@ public function suspend_post()
136136 $ key = $ this ->post ('key ' );
137137
138138 // Does this key exist?
139- if (!self :: _key_exists ($ key ))
139+ if (!$ this -> _key_exists ($ key ))
140140 {
141141 // It doesn't appear the key exists
142142 $ this ->response ([
@@ -146,7 +146,7 @@ public function suspend_post()
146146 }
147147
148148 // Update the key level
149- if (self :: _update_key ($ key , ['level ' => 0 ]))
149+ if ($ this -> _update_key ($ key , ['level ' => 0 ]))
150150 {
151151 $ this ->response ([
152152 'status ' => TRUE ,
@@ -163,15 +163,15 @@ public function suspend_post()
163163 }
164164
165165 /**
166- * Remove a key from the database to stop it working
166+ * Regenerate a key
167167 *
168168 * @access public
169169 * @return void
170170 */
171171 public function regenerate_post ()
172172 {
173173 $ old_key = $ this ->post ('key ' );
174- $ key_details = self :: _get_key ($ old_key );
174+ $ key_details = $ this -> _get_key ($ old_key );
175175
176176 // Does this key exist?
177177 if (!$ key_details )
@@ -184,13 +184,13 @@ public function regenerate_post()
184184 }
185185
186186 // Build a new key
187- $ new_key = self :: _generate_key ();
187+ $ new_key = $ this -> _generate_key ();
188188
189189 // Insert the new key
190- if (self :: _insert_key ($ new_key , ['level ' => $ key_details ->level , 'ignore_limits ' => $ key_details ->ignore_limits ]))
190+ if ($ this -> _insert_key ($ new_key , ['level ' => $ key_details ->level , 'ignore_limits ' => $ key_details ->ignore_limits ]))
191191 {
192192 // Suspend old key
193- self :: _update_key ($ old_key , ['level ' => 0 ]);
193+ $ this -> _update_key ($ old_key , ['level ' => 0 ]);
194194
195195 $ this ->response ([
196196 'status ' => TRUE ,
@@ -218,12 +218,12 @@ private function _generate_key()
218218 // If an error occurred, then fall back to the previous method
219219 if ($ salt === FALSE )
220220 {
221- $ salt = hash ('sha256 ' , time () . mt_rand ());
221+ $ salt = hash ('sha256 ' , time () . mt_rand ());
222222 }
223+
223224 $ new_key = substr ($ salt , 0 , config_item ('rest_key_length ' ));
224225 }
225- while (self ::_key_exists ($ new_key ));
226- // Already in the DB? Fail. Try again
226+ while ($ this ->_key_exists ($ new_key ));
227227
228228 return $ new_key ;
229229 }
@@ -233,16 +233,16 @@ private function _generate_key()
233233 private function _get_key ($ key )
234234 {
235235 return $ this ->db
236- ->where (config_item ('rest_key_column ' ), $ key )
237- ->get (config_item ('rest_keys_table ' ))
238- ->row ();
236+ ->where (config_item ('rest_key_column ' ), $ key )
237+ ->get (config_item ('rest_keys_table ' ))
238+ ->row ();
239239 }
240240
241241 private function _key_exists ($ key )
242242 {
243243 return $ this ->db
244- ->where (config_item ('rest_key_column ' ), $ key )
245- ->count_all_results (config_item ('rest_keys_table ' )) > 0 ;
244+ ->where (config_item ('rest_key_column ' ), $ key )
245+ ->count_all_results (config_item ('rest_keys_table ' )) > 0 ;
246246 }
247247
248248 private function _insert_key ($ key , $ data )
0 commit comments