function pleio_api_use_api_key($hook, $type, $returnvalue, $params) { $site = elgg_get_site_entity(); if ($site && $site->guid != 1) { $license_key = elgg_get_plugin_setting("license_key", "pleio_api"); $last_check = intval(elgg_get_plugin_setting("last_license_check", "pleio_api")); $hash = hash_hmac("SHA256", $site->url, $site->guid); if (!$license_key || $hash != $license_key || !$last_check || $last_check < time() - 86400) { elgg_set_plugin_setting("last_license_check", time(), "pleio_api"); if (!empty($params) && is_string($params)) { $api_user = get_api_user($site->getGUID(), $params); if ($api_user) { $app = ws_pack_get_application_from_api_user_id($api_user->id); if ($app) { if ($app->application_id == "pleio_app") { $data = array("id" => $site->guid, "name" => $site->name, "url" => $site->url, "email" => $site->email, "members" => $site->member_count); $url = "http://appstaat.funil.nl/overheidsplein-app/license.php?" . http_build_query($data); try { $response = file_get_contents($url); if ($response) { $response = json_decode($response); $license_key = $response->key; elgg_set_plugin_setting("license_key", $license_key, "pleio_api"); } } catch (Exception $ex) { } } } } } } if (!$license_key) { return false; } } }
/** * Store the used API application for future use * * @param string $hook name of the hook * @param string $type type of the hook * @param string $returnvalue current return value * @param array $params hook parameters * * @return void */ function ws_pack_api_key_use_hook_handler($hook, $type, $returnvalue, $params) { if (!empty($params) && is_string($params)) { $site = elgg_get_site_entity(); // get the current api user if ($api_user = get_api_user($site->getGUID(), $params)) { // check if we're using our API application if ($api_application = ws_pack_get_application_from_api_user_id($api_user->id)) { // store the API application for later use ws_pack_set_current_api_application($api_application); } } } }