mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-17 21:11:39 +00:00
hook functionality
--HG-- branch : Gsoc14-ryzomAppImprovements
This commit is contained in:
parent
e7e4b88747
commit
1ef330b076
7 changed files with 322 additions and 207 deletions
|
@ -237,7 +237,7 @@ class DBLayer {
|
|||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$this -> rollBack();
|
||||
$this -> PDO -> rollBack();
|
||||
throw new Exception( "error in deleting" );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper class for more site specific functions.
|
||||
* @author Daan Janssens, mentored by Matthew Lagoe
|
||||
*
|
||||
* @author Daan Janssens, mentored by Matthew Lagoe
|
||||
*/
|
||||
class Helpers {
|
||||
|
||||
|
@ -10,6 +10,7 @@ class Helpers{
|
|||
* workhorse of the website, it loads the template and shows it or returns th html.
|
||||
* it uses smarty to load the $template, but before displaying the template it will pass the $vars to smarty. Also based on your language settings a matching
|
||||
* array of words & sentences for that page will be loaded. In case the $returnHTML parameter is set to true, it will return the html instead of displaying the template.
|
||||
*
|
||||
* @param $template the name of the template(page) that we want to load.
|
||||
* @param $vars an array of variables that should be loaded by smarty before displaying or returning the html.
|
||||
* @param $returnHTML (default=false) if set to true, the html that should have been displayed, will be returned.
|
||||
|
@ -58,9 +59,16 @@ class Helpers{
|
|||
|
||||
// load page specific variables that are language dependent
|
||||
$variables = Helpers :: handle_language();
|
||||
if ( $template != 'layout_plugin' )
|
||||
{
|
||||
foreach ( $variables[$template] as $key => $value ) {
|
||||
$smarty -> assign( $key, $value );
|
||||
}
|
||||
}
|
||||
// load ams content variables that are language dependent
|
||||
foreach ( $variables['ams_content'] as $key => $value ) {
|
||||
$smarty -> assign( $key, $value );
|
||||
}
|
||||
|
||||
// smarty inheritance for loading the matching wrapper layout (with the matching menu bar)
|
||||
if ( isset( $vars['permission'] ) && $vars['permission'] == 3 ) {
|
||||
|
@ -84,6 +92,7 @@ class Helpers{
|
|||
|
||||
/**
|
||||
* creates the folders that are needed for smarty.
|
||||
*
|
||||
* @todo for the drupal module it might be possible that drupal_mkdir needs to be used instead of mkdir, also this should be in the install.php instead.
|
||||
*/
|
||||
static public function create_folders() {
|
||||
|
@ -110,6 +119,7 @@ class Helpers{
|
|||
|
||||
/**
|
||||
* check if the http request is sent ingame or not.
|
||||
*
|
||||
* @return returns true in case it's sent ingame, else false is returned.
|
||||
*/
|
||||
static public function check_if_game_client()
|
||||
|
@ -128,6 +138,7 @@ class Helpers{
|
|||
* Handles the language specific aspect.
|
||||
* The language can be changed by setting the $_GET['Language'] & $_GET['setLang'] together. This will also change the language entry of the user in the db.
|
||||
* Cookies are also being used in case the user isn't logged in.
|
||||
*
|
||||
* @return returns the parsed content of the language .ini file related to the users language setting.
|
||||
*/
|
||||
static public function handle_language() {
|
||||
|
@ -184,6 +195,7 @@ class Helpers{
|
|||
|
||||
/**
|
||||
* Time output function for handling the time display.
|
||||
*
|
||||
* @return returns the time in the format specified in the $TIME_FORMAT global variable.
|
||||
*/
|
||||
static public function outputTime( $time, $str = 1 ) {
|
||||
|
@ -199,6 +211,7 @@ class Helpers{
|
|||
* Auto login function for ingame use.
|
||||
* This function will allow users who access the website ingame, to log in without entering the username and password. It uses the COOKIE entry in the open_ring db.
|
||||
* it checks if the cookie sent by the http request matches the one in the db. This cookie in the db is changed everytime the user relogs.
|
||||
*
|
||||
* @return returns "FALSE" if the cookies didn't match, else it returns an array with the user's id and name.
|
||||
*/
|
||||
static public function check_login_ingame() {
|
||||
|
@ -206,7 +219,11 @@ class Helpers{
|
|||
$dbr = new DBLayer( "ring" );
|
||||
if ( isset( $_GET['UserId'] ) && isset( $_COOKIE['ryzomId'] ) ) {
|
||||
$id = $_GET['UserId'];
|
||||
|
||||
$statement = $dbr -> select( "ring_users", array( 'id' => $id, 'cookie' => $_COOKIE['ryzomId'] ), "user_id=:id AND cookie =:cookie" );
|
||||
|
||||
// $statement = $dbr->execute("SELECT * FROM ring_users WHERE user_id=:id AND cookie =:cookie", array('id' => $id, 'cookie' => $_COOKIE['ryzomId']));
|
||||
|
||||
if ( $statement -> rowCount() ) {
|
||||
$entry = $statement -> fetch();
|
||||
// print_r($entry);
|
||||
|
|
|
@ -156,13 +156,12 @@ class Plugincache {
|
|||
}
|
||||
|
||||
/**
|
||||
* get update info array attribute of the object.
|
||||
* get plugin info array attribute of the object.
|
||||
*/
|
||||
public function getUpdateInfo() {
|
||||
return $this -> update_info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* some more plugin function that requires during plugin operations
|
||||
*
|
||||
|
@ -187,4 +186,86 @@ class Plugincache {
|
|||
return rmdir( $dir );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function to unzip the zipped files
|
||||
*
|
||||
* @param $target_path path to the target zipped file
|
||||
* @param $destination path to the destination
|
||||
* @return boolean
|
||||
*/
|
||||
public static function zipExtraction( $target_path, $destination )
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
$x = $zip -> open( $target_path );
|
||||
if ( $x === true ) {
|
||||
if ( $zip -> extractTo( $destination ) )
|
||||
{
|
||||
$zip -> close();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$zip -> close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns plugin information with respect to the id
|
||||
*
|
||||
* @param id $ plugin id
|
||||
* @return field info for the plugin
|
||||
*/
|
||||
public static function pluginInfoUsingId( $id, $fieldName )
|
||||
{
|
||||
$db = new DBLayer( 'lib' );
|
||||
$sth = $db -> selectWithParameter( $fieldName, 'plugins', array( 'id' => $id ), 'Id=:id' );
|
||||
$row = $sth -> fetch();
|
||||
return $row[$fieldName];
|
||||
}
|
||||
|
||||
/**
|
||||
* function provides list of active plugins
|
||||
*
|
||||
* @return $ac_plugins list of active plugins
|
||||
*/
|
||||
public static function activePlugins()
|
||||
{
|
||||
$db = new DBLayer( 'lib' );
|
||||
$sth = $db -> selectWithParameter( 'Id', 'plugins', array( 'status' => 1 ), 'Status=:status' );
|
||||
$row = $sth -> fetchAll();
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* function to load hooks for the active plugins
|
||||
* and return the contents in the hooks in an array
|
||||
*
|
||||
* @return $content content available in hooks
|
||||
*/
|
||||
public static function loadHooks()
|
||||
{
|
||||
$content = array();
|
||||
$ac_arr = Plugincache :: activePlugins();
|
||||
foreach( $ac_arr as $key => $value )
|
||||
{
|
||||
$plugin_path = Plugincache :: pluginInfoUsingId( $value['Id'], 'FileName' );
|
||||
$pluginName = Plugincache :: pluginInfoUsingId( $value['Id'], 'Name' );
|
||||
|
||||
// calling hooks in the $pluginName.php
|
||||
include $plugin_path . '/' . strtolower( $pluginName ) . '.php';
|
||||
$arr = get_defined_functions();
|
||||
|
||||
foreach( $arr['user'] as $key => $value )
|
||||
{
|
||||
if ( stristr( $value, strtolower( $pluginName ) ) == true )
|
||||
{
|
||||
$content['hook_info'][$pluginName] = call_user_func( $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ function update_plugin() {
|
|||
$db = new DBLayer( 'lib' );
|
||||
$sth = $db -> executeWithoutParams( "SELECT * FROM plugins INNER JOIN updates ON plugins.Id=updates.PluginId Where plugins.Id=$id" );
|
||||
$row = $sth -> fetch();
|
||||
print_r( $row );
|
||||
|
||||
// replacing update in the database
|
||||
Plugincache :: rrmdir( $row['FileName'] );
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
// load required pages and turn error reporting on/off
|
||||
error_reporting( E_ALL );
|
||||
ini_set( 'display_errors', 'on' );
|
||||
require_once( '../../ams_lib/libinclude.php' );
|
||||
if ( !file_exists( '../is_installed' ) ) {
|
||||
// if is_installed doesnt exist run setup
|
||||
require( 'installer/libsetup.php' );
|
||||
|
@ -25,9 +24,10 @@ if ( !file_exists( '../is_installed' ) ) {
|
|||
// if config exists then include it
|
||||
require( '../config.php' );
|
||||
}
|
||||
require_once( $AMS_LIB . '/libinclude.php' );
|
||||
session_start();
|
||||
|
||||
// Running Cron?
|
||||
// Running Cron
|
||||
if ( isset( $_GET["cron"] ) ) {
|
||||
if ( $_GET["cron"] == "true" ) {
|
||||
Sync :: syncdata( false );
|
||||
|
@ -39,6 +39,7 @@ Sync :: syncdata( false );
|
|||
|
||||
// Decide what page to load
|
||||
if ( ! isset( $_GET["page"] ) ) {
|
||||
|
||||
if ( isset( $_SESSION['user'] ) ) {
|
||||
if ( Ticket_User :: isMod( unserialize( $_SESSION['ticket_user'] ) ) ) {
|
||||
$page = 'dashboard';
|
||||
|
@ -101,9 +102,6 @@ if ( isset( $_SESSION['user'] ) ) {
|
|||
$return['username'] = $_SESSION['user'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Set permission
|
||||
if ( isset( $_SESSION['ticket_user'] ) ) {
|
||||
$return['permission'] = unserialize( $_SESSION['ticket_user'] ) -> getPermission();
|
||||
|
@ -112,7 +110,6 @@ if ( isset( $_SESSION['ticket_user'] ) ) {
|
|||
$return['permission'] = 0;
|
||||
}
|
||||
|
||||
|
||||
// hide sidebar + topbar in case of login/register
|
||||
if ( $page == 'login' || $page == 'register' || $page == 'logout' || $page == 'forgot_password' || $page == 'reset_password' ) {
|
||||
$return['no_visible_elements'] = 'TRUE';
|
||||
|
@ -126,5 +123,12 @@ if ( $page == 'error' ) {
|
|||
$return['no_visible_elements'] = 'FALSE';
|
||||
}
|
||||
|
||||
// call to load hooks for the active plugins
|
||||
$hook_content = Plugincache :: loadHooks();
|
||||
foreach( $hook_content as $key => $value )
|
||||
{
|
||||
$return[$key] = $value;
|
||||
}
|
||||
|
||||
// load the template with the variables in the $return array
|
||||
helpers :: loadTemplate( $page , $return );
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=show_queue&get=todo"><i class="icon-th-list"></i><span class="hidden-tablet"> Queues</span></a></li>
|
||||
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=sgroup_list"><i class="icon-briefcase"></i><span class="hidden-tablet"> Support Groups</span></a></li>
|
||||
<li class="nav-header hidden-tablet">Actions</li>
|
||||
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=plugins"><i class="icon-th-list"></i><span class="hidden-tablet"> Plugins</span></a></li>
|
||||
{if isset($hook_info)} {foreach from=$hook_info item=element}<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=layout_plugin&&name={$element.menu_display}"><i class="icon-th-list"></i><span class="hidden-tablet"> {$element.menu_display}</span></a></li>{/foreach}{/if}
|
||||
<li style="margin-left: -2px;"><a class="ajax-link" href="index.php?page=syncing"><i class="icon-th-list"></i><span class="hidden-tablet"> Syncing</span></a></li>
|
||||
<li style="margin-left: -2px;"><a href="?page=logout"><i class="icon-off"></i><span class="hidden-tablet"> Logout </span></a></li>
|
||||
{/block}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{block name=content}
|
||||
<div class="row-fluid">
|
||||
{if isset($hook_info)}
|
||||
{foreach from=$hook_info item=element}
|
||||
{if $element.menu_display eq $smarty.get.name}
|
||||
{include file=$element.template_path}
|
||||
{/if}
|
||||
{/foreach}
|
||||
{/if}
|
||||
</div>
|
||||
{/block}
|
||||
|
Loading…
Reference in a new issue