mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-27 11:00:54 +00:00
BugFixes: achievements and API key management plugins
This commit is contained in:
parent
43959ab55d
commit
d865f2932b
5 changed files with 134 additions and 71 deletions
|
@ -11,11 +11,13 @@
|
||||||
* @author shubham meena mentored by Matthew Lagoe
|
* @author shubham meena mentored by Matthew Lagoe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Global variable to store the data which is
|
||||||
// Global variables to store the data
|
// returned to the templates
|
||||||
$return_set = array();
|
$return_set = array();
|
||||||
$var_set = array();
|
|
||||||
|
|
||||||
|
// Local variable to store data during
|
||||||
|
// functionalities of the hooks
|
||||||
|
$var_set = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display hook for api key management
|
* Display hook for api key management
|
||||||
|
@ -28,7 +30,7 @@ function api_key_management_hook_display()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to validate the posted data
|
* Local Hook to validate the posted data
|
||||||
*/
|
*/
|
||||||
function hook_validate( $var )
|
function hook_validate( $var )
|
||||||
{
|
{
|
||||||
|
@ -70,9 +72,9 @@ function hook_variables()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global Hook to create table of the API_key_management
|
* Global Hook to create table of the API_key_management
|
||||||
* if not created.Contains the sql code
|
* if not created.
|
||||||
|
* Contains the sql code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function api_key_management_hook_create_tb()
|
function api_key_management_hook_create_tb()
|
||||||
{
|
{
|
||||||
$dbl = new DBLayer( "lib" );
|
$dbl = new DBLayer( "lib" );
|
||||||
|
@ -157,17 +159,24 @@ function api_key_management_hook_load_db()
|
||||||
|
|
||||||
$db = new DBLayer( 'lib' );
|
$db = new DBLayer( 'lib' );
|
||||||
|
|
||||||
// returns the regestered keys
|
if ( isset( $_SESSION['user'] ) )
|
||||||
|
{
|
||||||
|
// returns the registered keys
|
||||||
$sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' );
|
$sth = $db -> select( 'ams_api_keys', array( 'user' => $_SESSION['user'] ), 'User = :user' );
|
||||||
$row = $sth -> fetchAll();
|
$row = $sth -> fetchAll();
|
||||||
$return_set['api_keys'] = $row;
|
$return_set['api_keys'] = $row;
|
||||||
|
|
||||||
|
// fetch the character from the array to compare
|
||||||
|
$com = array_column( $return_set['api_keys'], 'UserCharacter' );
|
||||||
|
|
||||||
// returns the characters with respect to the user id in the ring_tool->characters
|
// returns the characters with respect to the user id in the ring_tool->characters
|
||||||
$db = new DBLayer( 'ring' );
|
$db = new DBLayer( 'ring' );
|
||||||
$sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' );
|
$sth = $db -> selectWithParameter( 'char_name', 'characters' , array(), '1' );
|
||||||
$row = $sth -> fetchAll();
|
$row = $sth -> fetch();
|
||||||
$return_set['characters'] = $row;
|
|
||||||
|
|
||||||
|
// loop through the character list and remove the character if already have an api key
|
||||||
|
$return_set['characters'] = array_diff( $row, $com );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,7 +198,6 @@ function api_key_management_hook_update_db()
|
||||||
header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" );
|
header( "Location: index.php?page=layout_plugin&&name=API_key_management&&success=2" );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,5 +210,4 @@ function api_key_management_hook_return_global()
|
||||||
{
|
{
|
||||||
global $return_set;
|
global $return_set;
|
||||||
return $return_set;
|
return $return_set;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<select name="character_name">
|
<select name="character_name">
|
||||||
{foreach from=$hook_info.API_key_management.characters item=element}
|
{foreach from=$hook_info.API_key_management.characters item=element}
|
||||||
<option value="{$element.char_name}">{$element.char_name}</option>
|
<option value="{$element}">{$element}</option>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,10 +15,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Global variables to store the data
|
// Global variable to store the data which is
|
||||||
|
// returned to the templates
|
||||||
$return_set = array();
|
$return_set = array();
|
||||||
$var_set = array();
|
|
||||||
|
|
||||||
|
// Local variable to store data during
|
||||||
|
// functionalities of the hooks
|
||||||
|
$var_set = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display hook for Achievements plugin
|
* Display hook for Achievements plugin
|
||||||
|
@ -35,19 +38,57 @@ function achievements_hook_display()
|
||||||
* which is called by the global hook
|
* which is called by the global hook
|
||||||
* by passing a parameter
|
* by passing a parameter
|
||||||
*
|
*
|
||||||
|
* This hook returns the api keys registerd with
|
||||||
|
* the logged in user
|
||||||
|
*
|
||||||
* @param $data array with respective information
|
* @param $data array with respective information
|
||||||
* @return $row extracted db content wrt $data
|
* @return $row extracted db content wrt $data
|
||||||
*/
|
*/
|
||||||
function hook_get_db_content( $data )
|
function hook_get_db_content( $data )
|
||||||
{
|
{
|
||||||
|
|
||||||
$db = new DBLayer( 'lib' );
|
$db = new DBLayer( 'lib' );
|
||||||
|
|
||||||
$sth = $db -> select( 'ams_api_keys', $data , 'User = :User AND UserCharacter = :UserCharacter' );
|
$sth = $db -> select( 'ams_api_keys', $data , 'User = :User AND UserCharacter = :UserCharacter' );
|
||||||
$row = $sth -> fetchAll();
|
$row = $sth -> fetchAll();
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Hook to get database content
|
||||||
|
* which is called by the global hook
|
||||||
|
* by passing a parameter
|
||||||
|
*
|
||||||
|
* This hook returns the id of the character
|
||||||
|
* whose achivements we have to get
|
||||||
|
*
|
||||||
|
* @param $data array with respective information
|
||||||
|
* @return $row extracted db content wrt $data
|
||||||
|
*/
|
||||||
|
function hook_get_char_id( $data )
|
||||||
|
{
|
||||||
|
// returns the character id with respect to the character name in the ring_tool->characters
|
||||||
|
$db = new DBLayer( 'ring' );
|
||||||
|
$sth = $db -> selectWithParameter( 'char_id', 'characters' , array( 'char_name' => $data ), 'char_name=:char_name' );
|
||||||
|
$row = $sth -> fetch();
|
||||||
|
return $row['char_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Hook to get database content
|
||||||
|
* which is called by the global hook
|
||||||
|
* by passing a parameter
|
||||||
|
*
|
||||||
|
* Hook to get the player stats of the character
|
||||||
|
*
|
||||||
|
* @param $data array with respective information
|
||||||
|
* @return $row extracted db content wrt $data
|
||||||
|
*/
|
||||||
|
function hook_get_player_stat( $data )
|
||||||
|
{
|
||||||
|
// returns the character id with respect to the character name in the ring_tool->characters
|
||||||
|
$db = new DBLayer( 'webig' );
|
||||||
|
$sth = $db -> select( 'players' , array( 'name' => $data ), 'name=:name' );
|
||||||
|
$row = $sth -> fetch();
|
||||||
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,9 +97,19 @@ function hook_get_db_content( $data )
|
||||||
*/
|
*/
|
||||||
function hook_variable_set()
|
function hook_variable_set()
|
||||||
{
|
{
|
||||||
|
global $return_set;
|
||||||
global $var_set;
|
global $var_set;
|
||||||
|
if ( isset( $_POST['Character'] ) && !empty( $_POST['Character'] ) )
|
||||||
|
{
|
||||||
$var_set['character'] = $_POST['Character'];
|
$var_set['character'] = $_POST['Character'];
|
||||||
|
|
||||||
|
// get char id from ring_open table
|
||||||
|
if ( $var_set['character'] != 'All Characters' )
|
||||||
|
{
|
||||||
|
$var_set['char_id'] = hook_get_char_id( $var_set['character'] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// get db content for variable set
|
// get db content for variable set
|
||||||
$row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) );
|
$row = hook_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) );
|
||||||
|
|
||||||
|
@ -68,14 +119,21 @@ function hook_variable_set()
|
||||||
// here you can set the host where this plugin is set
|
// here you can set the host where this plugin is set
|
||||||
$var_set['host'] = 'localhost';
|
$var_set['host'] = 'localhost';
|
||||||
|
|
||||||
// here you can set what you are looking for
|
// here we get the stats of the character
|
||||||
// when you are requesting encoded in json
|
$ref_set = hook_get_player_stat( $var_set['character'] );
|
||||||
@$var_set['items'] = json_encode( array( 'Task' => 'Achievements', 'Character' => $var_set['character'] ) );
|
|
||||||
|
// here we have set items that are required to get the achivements
|
||||||
|
// these are player stats from webig->players table
|
||||||
|
@$var_set['items'] = json_encode( array( 'dev_shard' => $ref_set['dev_shard'] , 'name' => $ref_set['name'] , 'cid' => $ref_set['cid'] , 'lang' => 'en' , 'translater_mode' => '', 'last_played_date' => $ref_set['last_login'] ) );
|
||||||
|
|
||||||
// url where we have to make request for achievements
|
// url where we have to make request for achievements
|
||||||
// it sends get parameter search(what to search) and format(in which format data exchange takes place)
|
// it sends get parameter search(what to search) and format(in which format data exchange takes place)
|
||||||
$var_set['url'] = 'app.domain.org?search=' . $var_set['items'] . '&&format=json';
|
$var_set['url'] = 'http://localhost6/?search=achievements&&format=json';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$return_set['no_char'] = "Please Generate key for a character before requesting for achievements";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,12 +157,11 @@ function achievements_hook_call_rest()
|
||||||
if ( isset( $_POST['get_data'] ) )
|
if ( isset( $_POST['get_data'] ) )
|
||||||
{
|
{
|
||||||
hook_variable_set();
|
hook_variable_set();
|
||||||
|
// here we make the REST connection
|
||||||
$rest_api = new Rest_Api();
|
$rest_api = new Rest_Api();
|
||||||
$ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'] );
|
$ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'], $var_set['items'] );
|
||||||
print_r( $ach_data );
|
// here we store the response we get from the server
|
||||||
|
$return_set['char_achievements'] = $ach_data ;
|
||||||
$return_set['char_achievements'] = json_decode( $ach_data );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,13 +176,15 @@ function achievements_hook_get_db()
|
||||||
{
|
{
|
||||||
global $return_set;
|
global $return_set;
|
||||||
|
|
||||||
|
if ( isset( $_SESSION['user'] ) )
|
||||||
|
{
|
||||||
$db = new DBLayer( 'lib' );
|
$db = new DBLayer( 'lib' );
|
||||||
|
|
||||||
// getting content for selecting characters
|
// getting content for selecting characters
|
||||||
$sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' );
|
$sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' );
|
||||||
$row = $sth -> fetchAll();
|
$row = $sth -> fetch();
|
||||||
$retur_set['Character'] = $row;
|
$return_set['Character'] = $row;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,5 +197,4 @@ function achievements_hook_return_global()
|
||||||
{
|
{
|
||||||
global $return_set;
|
global $return_set;
|
||||||
return $return_set;
|
return $return_set;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,8 @@
|
||||||
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
|
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{if isset($smarty.get.success) and $smarty.get.success eq '1'}<div class="alert alert-error"><p>Key added successfully</p></div>{/if}
|
|
||||||
{if isset($smarty.get.success) and $smarty.get.success eq '2'}<div class="alert alert-error"><p>Key deleted successfully</p></div>{/if}
|
|
||||||
<div class="box-content">
|
<div class="box-content">
|
||||||
|
{if isset($hook_info.Achievements.no_char)}<div class="alert alert-error"><p>{$hook_info.Achievements.no_char}</p></div>{/if}
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
{$hook_info.Achievements.char_achievements}
|
{$hook_info.Achievements.char_achievements}
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,8 +47,8 @@
|
||||||
<label class="control-label">Character:</label>
|
<label class="control-label">Character:</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<select name="Character">
|
<select name="Character">
|
||||||
{foreach from=$hook_info.Achievements.characters item=element}
|
{foreach from=$hook_info.Achievements.Character item=element}
|
||||||
<option value="{$element.char_name}">{$element.char_name}</option>
|
<option value="{$element}">{$element}</option>
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -198,7 +198,7 @@
|
||||||
|
|
||||||
INSERT INTO `plugins` (`Id`, `FileName`, `Name`, `Type`, `Owner`, `Permission`, `Status`, `Weight`, `Info`) VALUES
|
INSERT INTO `plugins` (`Id`, `FileName`, `Name`, `Type`, `Owner`, `Permission`, `Status`, `Weight`, `Info`) VALUES
|
||||||
(1, '../../ams_lib/plugins/API_key_management', 'API_key_management', 'automatic', '', 'admin', 1, 0, '{\"PluginName\":\"API Key Management\",\"Description\":\"Provides public access to the API''s by generating access tokens.\",\"Version\":\"1.0.0\",\"Type\":\"automatic\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/API_key_management\\/templates\\/index.tpl\",\"\":null}'),
|
(1, '../../ams_lib/plugins/API_key_management', 'API_key_management', 'automatic', '', 'admin', 1, 0, '{\"PluginName\":\"API Key Management\",\"Description\":\"Provides public access to the API''s by generating access tokens.\",\"Version\":\"1.0.0\",\"Type\":\"automatic\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/API_key_management\\/templates\\/index.tpl\",\"\":null}'),
|
||||||
(2, '../../ams_lib/plugins/Achievements', 'Achievements', 'Manual', '', 'admin', 1, 0, '{\"PluginName\":\"Achievements\",\"Description\":\"Returns the achivements of a user with respect to the character =.\",\"Version\":\"1.0.0\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/Achievements\\/templates\\/index.tpl\",\"Type\":\"Manual\",\"\":null}');
|
(2, '../../ams_lib/plugins/Achievements', 'Achievements', 'Manual', '', 'admin', 0, 0, '{\"PluginName\":\"Achievements\",\"Description\":\"Returns the achivements of a user with respect to the character =.\",\"Version\":\"1.0.0\",\"TemplatePath\":\"..\\/..\\/..\\/ams_lib\\/plugins\\/Achievements\\/templates\\/index.tpl\",\"Type\":\"Manual\",\"\":null}');
|
||||||
|
|
||||||
|
|
||||||
-- -----------------------------------------------------
|
-- -----------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue