From 7ff695eb5ec316152eca645cb1be196ac60062c7 Mon Sep 17 00:00:00 2001 From: Nicolas Kniebihler Date: Wed, 22 Oct 2014 12:30:35 +0200 Subject: [PATCH] Update to Elgg 1.9 (replace $CONFIG by elgg_get_config()) --- actions/apiadmin/generate.php | 4 +--- actions/apiadmin/regenerate.php | 6 ++---- activate.php | 4 ++-- deactivate.php | 5 ++--- languages/en.php | 3 +-- manifest.xml | 2 +- start.php | 12 ++++-------- .../admin/administer_utilities/apiadmin.php | 3 ++- views/default/object/api_key.php | 14 +++++++------- 9 files changed, 22 insertions(+), 31 deletions(-) diff --git a/actions/apiadmin/generate.php b/actions/apiadmin/generate.php index bd91375..d6f1fd3 100644 --- a/actions/apiadmin/generate.php +++ b/actions/apiadmin/generate.php @@ -11,14 +11,12 @@ * @link http://www.elgg.org */ -global $CONFIG; - admin_gatekeeper(); $ref = get_input('ref'); if ( $ref ) { - $keypair = create_api_user($CONFIG->site_id); + $keypair = create_api_user(elgg_get_config('site_id')); if ( $keypair ) { diff --git a/actions/apiadmin/regenerate.php b/actions/apiadmin/regenerate.php index 13bead9..4112719 100644 --- a/actions/apiadmin/regenerate.php +++ b/actions/apiadmin/regenerate.php @@ -11,8 +11,6 @@ * @link http://www.elgg.org */ -global $CONFIG; - admin_gatekeeper(); $key = (int)get_input('keyid'); @@ -20,8 +18,8 @@ $obj = get_entity($key); if ( $obj && ($obj instanceof ElggObject) && ($obj->subtype == get_subtype_id('object', 'api_key')) ) { - if ( remove_api_user($CONFIG->site_id, $obj->public) ) { - $keypair = create_api_user($CONFIG->site_id); + if ( remove_api_user(elgg_get_config('site_id'), $obj->public) ) { + $keypair = create_api_user(elgg_get_config('site_id')); if ( $keypair ) { $obj->public = $keypair->api_key; } else { diff --git a/activate.php b/activate.php index 7d5006d..8aec86c 100644 --- a/activate.php +++ b/activate.php @@ -1,8 +1,8 @@ path}mod/apiadmin/schema/mysql.sql"); +run_sql_script("{$path}mod/apiadmin/schema/mysql.sql"); if ( !file_exists($browscapdir = elgg_get_data_path() . 'phpbrowscap') ) { mkdir($browscapdir); diff --git a/deactivate.php b/deactivate.php index 0aa0510..8c182ed 100644 --- a/deactivate.php +++ b/deactivate.php @@ -1,6 +1,4 @@ path}mod/apiadmin/schema/mysql_undo.sql"); + run_sql_script("{$path}mod/apiadmin/schema/mysql_undo.sql"); } if ( is_dir($browscapdir = elgg_get_data_path() . 'phpbrowscap') ) { diff --git a/languages/en.php b/languages/en.php index 06ab887..22b1f27 100644 --- a/languages/en.php +++ b/languages/en.php @@ -11,7 +11,7 @@ * @link http://www.elgg.org */ -$english = array( +return array( 'admin:administer_utilities:apiadmin' => 'API Key Admin', 'admin:statistics:apilog' => 'API Access Log', @@ -57,4 +57,3 @@ 'apiadmin:no_result' => 'There are no API access log entries at the moment', 'apiadmin:no_version_check' => 'The Version Check plugin is either not installed or not active. You will not be able to receive notifications of new API Admin releases.', ); -add_translation('en', $english); diff --git a/manifest.xml b/manifest.xml index be76d39..6588c62 100644 --- a/manifest.xml +++ b/manifest.xml @@ -11,7 +11,7 @@ GNU General Public License version 2 elgg_release - 1.8 + 1.9 plugin diff --git a/start.php b/start.php index 31d6a6f..07918c0 100644 --- a/start.php +++ b/start.php @@ -68,18 +68,15 @@ function apiadmin_init($event, $object_type, $object = null) { * @param unknown_type $object */ function apiadmin_delete_key($event, $object_type, $object = null) { - global $CONFIG; - if ( ($object) && ($object->subtype === get_subtype_id('object', 'api_key')) ) { // Delete secret key - return remove_api_user($CONFIG->site_id, $object->public); + return remove_api_user(elgg_get_config('site_id'), $object->public); } return true; } function apiadmin_apikey_use($hook, $type, $returnvalue, $params) { - global $CONFIG; $handler = sanitise_string($_GET['handler']); $request = sanitise_string($_GET['request']); $method = sanitise_string($_GET['method']); @@ -87,7 +84,7 @@ function apiadmin_apikey_use($hook, $type, $returnvalue, $params) { $remote_address = sanitise_string($_SERVER['REMOTE_ADDR']); $user_agent = sanitise_string($_SERVER['HTTP_USER_AGENT']); // `id` bigint(20) `timestamp` int(11) `api_key` varchar(40) `handler` varchar(256) `request` varchar(256) `method` varchar(256) - $sql = sprintf("INSERT INTO %s VALUES(NULL, %d, '%s', '%s', '%s', '%s', '%s', '%s')", $CONFIG->dbprefix . 'apiadmin_log', + $sql = sprintf("INSERT INTO %s VALUES(NULL, %d, '%s', '%s', '%s', '%s', '%s', '%s')", elgg_get_config('dbprefix') . 'apiadmin_log', time(), $api_key, $handler, @@ -124,8 +121,6 @@ function apiadmin_get_usage_log($by_key = '', $handler = '', $request = '', $met $limit = 10, $offset = 0, $count = false, $timebefore = 0, $timeafter = 0, $object_id = 0 ) { - global $CONFIG; - $limit = (int)$limit; $offset = (int)$offset; @@ -185,7 +180,8 @@ function apiadmin_get_usage_log($by_key = '', $handler = '', $request = '', $met if ( $count ) { $select = 'count(*) as count'; } - $query = "SELECT $select FROM {$CONFIG->dbprefix}apiadmin_log WHERE 1 "; + $dbprefix = elgg_get_config('dbprefix'); + $query = "SELECT $select FROM {$dbprefix}apiadmin_log WHERE 1 "; foreach ( $where as $w ) { $query .= " AND $w"; } diff --git a/views/default/admin/administer_utilities/apiadmin.php b/views/default/admin/administer_utilities/apiadmin.php index ab568bf..166134a 100644 --- a/views/default/admin/administer_utilities/apiadmin.php +++ b/views/default/admin/administer_utilities/apiadmin.php @@ -27,7 +27,8 @@ if ( $list ) { $log_label = elgg_echo('apiadmin:log:all'); - echo "

url}admin/administer_utilities/apilog\">$log_label

"; + $url = elgg_get_config('url'); + echo "

$log_label

"; echo $list; } else { $nokeys_label = elgg_echo('apiadmin:nokeys'); diff --git a/views/default/object/api_key.php b/views/default/object/api_key.php index 1d936d0..b3c7fe2 100644 --- a/views/default/object/api_key.php +++ b/views/default/object/api_key.php @@ -12,29 +12,29 @@ * @link http://www.elgg.org */ -global $CONFIG; - $entity = $vars['entity']; $ts = time(); $token = generate_action_token($ts); +$url = elgg_get_config('url'); + ?> @@ -58,13 +58,13 @@ $info .= "   [guid}();\">$revoke_label]"; $info .= "   [guid}();\">$rename_label]"; $info .= "   [guid}();\">$regenerate_label]"; -//$info .= "   [url}admin/statistics/apilog?keyid={$entity->guid}\">$log_label]"; +//$info .= "   [guid}\">$log_label]"; $info .= "

"; $info .= "

$public_label: {$entity->public}
"; // Only show secret portion to admins if ( elgg_is_admin_logged_in() ) { // Fetch key and show it - $keypair = get_api_user($CONFIG->site_id, $entity->public); + $keypair = get_api_user(elgg_get_config('site_id'), $entity->public); $info .= "$private_label: {$keypair->secret}"; } $info .= "

";