From 2f1f2139b518d8e18257137c2a8be2bfbe0cc1e6 Mon Sep 17 00:00:00 2001 From: botanic Date: Sun, 7 Sep 2014 03:17:20 -0700 Subject: [PATCH] added initial domain_management plugin, also fixed potental conflicting hook names --- .../private_php/ams/autoload/plugincache.php | 9 +- .../API_key_management/API_key_management.php | 1 + .../ams/plugins/Achievements/Achievements.php | 1 + .../ams/plugins/Domain_Management/.info | 8 + .../Domain_Management/Domain_Management.php | 201 ++++++++++++++++++ .../Domain_Management/templates/index.tpl | 54 +++++ .../public_php/ams/templates/layout_admin.tpl | 3 +- 7 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 code/web/private_php/ams/plugins/Domain_Management/.info create mode 100644 code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php create mode 100644 code/web/private_php/ams/plugins/Domain_Management/templates/index.tpl diff --git a/code/web/private_php/ams/autoload/plugincache.php b/code/web/private_php/ams/autoload/plugincache.php index 29a2172cb..20bbb0b25 100644 --- a/code/web/private_php/ams/autoload/plugincache.php +++ b/code/web/private_php/ams/autoload/plugincache.php @@ -261,8 +261,13 @@ class Plugincache { $arr = get_defined_functions(); foreach ($arr['user'] as $key => $value) { - if (stristr( $value, $plugin_name) == true) { - $content['hook_info'][$plugin_name] = call_user_func($value); + switch (strtolower($value)) { + case strtolower($plugin_name).'_hook_display': + case strtolower($plugin_name).'_hook_call_rest': + case strtolower($plugin_name).'_hook_get_db': + case strtolower($plugin_name).'_hook_return_global': + $content['hook_info'][$plugin_name] = call_user_func($value); + break; } } // path for the template diff --git a/code/web/private_php/ams/plugins/API_key_management/API_key_management.php b/code/web/private_php/ams/plugins/API_key_management/API_key_management.php index 8f2e6158b..09c895624 100644 --- a/code/web/private_php/ams/plugins/API_key_management/API_key_management.php +++ b/code/web/private_php/ams/plugins/API_key_management/API_key_management.php @@ -27,6 +27,7 @@ function api_key_management_hook_display() global $return_set; // to display plugin name in menu bar $return_set['menu_display'] = 'API Key Management'; + $return_set['icon'] = 'icon-download-alt'; } /** diff --git a/code/web/private_php/ams/plugins/Achievements/Achievements.php b/code/web/private_php/ams/plugins/Achievements/Achievements.php index 79c117893..47f39b9d8 100644 --- a/code/web/private_php/ams/plugins/Achievements/Achievements.php +++ b/code/web/private_php/ams/plugins/Achievements/Achievements.php @@ -31,6 +31,7 @@ function achievements_hook_display() global $return_set; // to display plugin name in menu bar $return_set['menu_display'] = 'Achievements'; + $return_set['icon'] = 'icon-certificate'; } /** diff --git a/code/web/private_php/ams/plugins/Domain_Management/.info b/code/web/private_php/ams/plugins/Domain_Management/.info new file mode 100644 index 000000000..502846e4f --- /dev/null +++ b/code/web/private_php/ams/plugins/Domain_Management/.info @@ -0,0 +1,8 @@ +PluginName = Domain_Management +Description = Plug-in for Domain Management. +Version = 1.0.0 +TemplatePath = ../../../private_php/ams/plugins/Domain_Management/templates/index.tpl +Type = Manual + + + diff --git a/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php b/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php new file mode 100644 index 000000000..4c8f44f54 --- /dev/null +++ b/code/web/private_php/ams/plugins/Domain_Management/Domain_Management.php @@ -0,0 +1,201 @@ + select( 'ams_api_keys', $data , 'User = :User AND UserCharacter = :UserCharacter' ); + $row = $sth -> fetchAll(); + 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 domain_management_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 domain_management_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; + } + +/** + * Local Hook to set variables which contains + * the content to use during the plugin functionality. + */ +function domain_management_variable_set() + { + global $return_set; + global $var_set; + if ( isset( $_POST['Character'] ) && !empty( $_POST['Character'] ) ) + { + $var_set['character'] = $_POST['Character']; + + // get char id from ring_open table + if ( $var_set['character'] != 'All Characters' ) + { + $var_set['char_id'] = domain_management_get_char_id( $var_set['character'] ); + + } + + // get db content for variable set + $row = domain_management_get_db_content( array( 'User' => $_SESSION['user'], 'UserCharacter' => $var_set['character'] ) ); + + // access key automatically taken from the database wrt user and character + @$var_set['app_key'] = $row['AccessToken']; + + // here you can set the host where this plugin is set + $var_set['host'] = 'localhost'; + + // here we get the stats of the character + $ref_set = domain_management_get_player_stat( $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 domain_management + // it sends get parameter search(what to search) and format(in which format data exchange takes place) + $var_set['url'] = 'http://localhost6/?search=domain_management&&format=json'; + } + else + { + $return_set['no_char'] = "Please Generate key for a character before requesting for domain_management"; + } + } + +/** + * Global Hook to interact with the REST api + * Pass the variables in the REST object to + * make request + * + * variables REST object expects + * url --> on which request is to be made + * appkey --> app key for authentication + * host --> host from which request have been sent + * + * @return $return_set global array returns the template data + */ +function domain_management_hook_call_rest() + { + // defined the variables + global $var_set; + global $return_set; + + if ( isset( $_POST['get_data'] ) ) + { + domain_management_variable_set(); + // here we make the REST connection + $rest_api = new Rest_Api(); + $ach_data = $rest_api -> request( $var_set['url'], $var_set['app_key'], $var_set['host'], $var_set['items'] ); + // here we store the response we get from the server + $return_set['char_domain_management'] = $ach_data ; + } + } + +/** + * Global Hook to return global variables which contains + * the content to use in the smarty templates extracted from + * the database + * + * @return $return_set global array returns the template data + */ +function domain_management_hook_get_db() + { + global $return_set; + + if ( isset( $_SESSION['user'] ) ) + { + $db = new DBLayer( 'lib' ); + + // getting content for selecting characters + $sth = $db -> selectWithParameter( 'UserCharacter', 'ams_api_keys', array( 'User' => $_SESSION['user'] ) , 'User = :User' ); + $row = $sth -> fetch(); + $return_set['Character'] = $row; + } + } + +/** + * Global Hook to return global variables which contains + * the content to use in the smarty templates + * + * @return $return_set global array returns the template data + */ +function domain_management_hook_return_global() + { + global $return_set; + return $return_set; + } diff --git a/code/web/private_php/ams/plugins/Domain_Management/templates/index.tpl b/code/web/private_php/ams/plugins/Domain_Management/templates/index.tpl new file mode 100644 index 000000000..eb0c770da --- /dev/null +++ b/code/web/private_php/ams/plugins/Domain_Management/templates/index.tpl @@ -0,0 +1,54 @@ +{block name=content} + +{if isset($smarty.get.plugin_action) and $smarty.get.plugin_action eq 'get_domain_management'} +
+
+
+
+

Domain_Management

+
+
+ {if isset($hook_info.Domain_Management.no_char)}

{$hook_info.Domain_Management.no_char}

{/if} +
+ {$hook_info.Domain_Management.char_domain_management} +
+
+
+
+
+{else} +
+
+
+
+

Select your Character

+
+
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+
+
+{/if} +{/block} diff --git a/code/web/public_php/ams/templates/layout_admin.tpl b/code/web/public_php/ams/templates/layout_admin.tpl index 54307b5bc..12ff65c40 100644 --- a/code/web/public_php/ams/templates/layout_admin.tpl +++ b/code/web/public_php/ams/templates/layout_admin.tpl @@ -4,11 +4,12 @@
  • Dashboard
  • Profile
  • Settings
  • - {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}
  • {$element.menu_display}
  • {/foreach}{/if} + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}{if isset($element.menu_display)}
  • {$element.menu_display}
  • {/if}{/foreach}{/if}
  • Users
  • Queues
  • Support Groups
  • + {if isset($hook_info)} {foreach from=$hook_info key=arrkey item=element}{if isset($element.admin_menu_display)}
  • {$element.admin_menu_display}
  • {/if}{/foreach}{/if}
  • Plugins
  • Syncing