Skip to content

Update to Elgg 1.9 (replace $CONFIG by elgg_get_config()) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions actions/apiadmin/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {

Expand Down
6 changes: 2 additions & 4 deletions actions/apiadmin/regenerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
* @link http://www.elgg.org
*/

global $CONFIG;

admin_gatekeeper();

$key = (int)get_input('keyid');

$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 {
Expand Down
4 changes: 2 additions & 2 deletions activate.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
global $CONFIG;
$path = elgg_get_config('path');

// create the tables for API stats
run_sql_script("{$CONFIG->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);
Expand Down
5 changes: 2 additions & 3 deletions deactivate.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
global $CONFIG;

function apiadmin_deltree($dirname) {
// Sanity check
if ( !file_exists($dirname) ) { return false; }
Expand All @@ -25,8 +23,9 @@ function apiadmin_deltree($dirname) {

// if user doesn't need stats tables to be kept
if ( elgg_get_plugin_setting('keep_tables', 'apiadmin') != 'on' ) {
$path = elgg_get_config('path');
// delete stats tables
run_sql_script("{$CONFIG->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') ) {
Expand Down
3 changes: 1 addition & 2 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down Expand Up @@ -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);
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<license>GNU General Public License version 2</license>
<requires>
<type>elgg_release</type>
<version>1.8</version>
<version>1.9</version>
</requires>
<suggests>
<type>plugin</type>
Expand Down
12 changes: 4 additions & 8 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,23 @@ 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']);
$api_key = sanitise_string($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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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";
}
Expand Down
3 changes: 2 additions & 1 deletion views/default/admin/administer_utilities/apiadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

if ( $list ) {
$log_label = elgg_echo('apiadmin:log:all');
echo "<p><a href=\"{$CONFIG->url}admin/administer_utilities/apilog\">$log_label</a></p>";
$url = elgg_get_config('url');
echo "<p><a href=\"{$url}admin/administer_utilities/apilog\">$log_label</a></p>";
echo $list;
} else {
$nokeys_label = elgg_echo('apiadmin:nokeys');
Expand Down
14 changes: 7 additions & 7 deletions views/default/object/api_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

?>
<script>
elgg.apiadmin_revoke<?php echo $entity->guid; ?> = function() {
if ( confirm(elgg.echo('apiadmin:revoke_prompt')) ) {
document.location.href = '<?php echo "{$CONFIG->url}action/apiadmin/revokekey?keyid={$entity->guid}&__elgg_token=$token&__elgg_ts=$ts" ?>';
document.location.href = '<?php echo "{$url}action/apiadmin/revokekey?keyid={$entity->guid}&__elgg_token=$token&__elgg_ts=$ts" ?>';
}
}
elgg.apiadmin_rename<?php echo $entity->guid; ?> = function() {
var newRef = prompt(elgg.echo('apiadmin:rename_prompt'), '<?php echo $entity->title; ?>');
if ( newRef ) {
var url = '<?php echo "{$CONFIG->url}action/apiadmin/renamekey?keyid={$entity->guid}&__elgg_token=$token&__elgg_ts=$ts" ?>';
var url = '<?php echo "{$url}action/apiadmin/renamekey?keyid={$entity->guid}&__elgg_token=$token&__elgg_ts=$ts" ?>';
document.location.href = url + '&newref=' + encodeURIComponent(newRef);
}
}
elgg.apiadmin_regen<?php echo $entity->guid; ?> = function() {
if ( confirm(elgg.echo('apiadmin:regenerate_prompt')) ) {
document.location.href = '<?php echo "{$CONFIG->url}action/apiadmin/regenerate?keyid={$entity->guid}&__elgg_token=$token&__elgg_ts=$ts" ?>';
document.location.href = '<?php echo "{$url}action/apiadmin/regenerate?keyid={$entity->guid}&__elgg_token=$token&__elgg_ts=$ts" ?>';
}
}
</script>
Expand All @@ -58,13 +58,13 @@
$info .= " &nbsp; [<a href=\"#\" onclick=\"elgg.apiadmin_revoke{$entity->guid}();\">$revoke_label</a>]";
$info .= " &nbsp; [<a href=\"#\" onclick=\"elgg.apiadmin_rename{$entity->guid}();\">$rename_label</a>]";
$info .= " &nbsp; [<a href=\"#\" onclick=\"elgg.apiadmin_regen{$entity->guid}();\">$regenerate_label</a>]";
//$info .= " &nbsp; [<a href=\"{$CONFIG->url}admin/statistics/apilog?keyid={$entity->guid}\">$log_label</a>]";
//$info .= " &nbsp; [<a href=\"{$url}admin/statistics/apilog?keyid={$entity->guid}\">$log_label</a>]";
$info .= "</p></div>";
$info .= "<div><p><b>$public_label:</b> {$entity->public}<br />";
// 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 .= "<b>$private_label:</b> {$keypair->secret}";
}
$info .= "</p></div>";
Expand Down