Skip to content

Commit

Permalink
Fix Quotes in SQL Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
darknoon29 committed Mar 25, 2024
1 parent 8296530 commit b5d0593
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 486 deletions.
134 changes: 67 additions & 67 deletions includes/CallbackHandler.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
<?php
/**
* @package Xtense 2
* @author Unibozu
* @licence GNU
*/

if (!defined('IN_SPYOGAME')) exit;

/**
* Gestion des fonctions de callback des plugins OGSpyw
*
*/
class CallbackHandler {
private $list = array();
private $calls = array();
private $types = array();
private $included = array();
public $currentCallback = false;

/**
* @param $type
* @param $params
*/
public function add($type, $params) {
if (empty($params)) return;
$this->calls[$type][] = $params;
if (!in_array($type, $this->types)) {
$this->types[] = $type;
}
}

/**
* Appels des fonctions des mods
*
*/
public function apply() {
global $io, $db, $get_dev, $server_config;
if (empty($this->calls)) return;
$success = array();
$errors = array();
$query = $db->sql_query('SELECT c.id, c.function, c.type, c.mod_id, m.root, m.title FROM '.TABLE_XTENSE_CALLBACKS.' c LEFT JOIN '.TABLE_MOD.' m ON c.mod_id = m.id WHERE c.active = 1 AND m.active = 1 AND c.type IN ("'.implode('", "', $this->types).'")');
while ($call = $db->sql_fetch_assoc($query)) {
foreach ($this->calls[$call['type']] as $params) {
$this->currentCallback = $call;
try {
$instance = Callback::load($call['root']);
if (!method_exists($instance, $call['function']) || !is_callable(array($instance, $call['function']))) throw new Exception('Invalid method "'.$call['function'].'"');
$execReturn = $instance->{$call['function']}($params);
$io->append_call($call, $execReturn);
} catch (mysqli_sql_exception $e) {
$io->append_call_error($call, 'Erreur MySQL lors de l\'execution'."\n".$e->getFile().' @ '.$e->getLine()."\n".$e->getMessage());
} catch (Exception $e) {
$io->append_call_error($call, $e->getMessage(), $e);
}
$this->currentCallback = false;
} // Foreach
} // while
} // Method "apply"
}
<?php
/**
* @package Xtense 2
* @author Unibozu
* @licence GNU
*/

if (!defined('IN_SPYOGAME')) exit;

/**
* Gestion des fonctions de callback des plugins OGSpyw
*
*/
class CallbackHandler {
private $list = array();
private $calls = array();
private $types = array();
private $included = array();
public $currentCallback = false;

/**
* @param $type
* @param $params
*/
public function add($type, $params) {
if (empty($params)) return;
$this->calls[$type][] = $params;
if (!in_array($type, $this->types)) {
$this->types[] = $type;
}
}

/**
* Appels des fonctions des mods
*
*/
public function apply() {
global $io, $db, $get_dev, $server_config;
if (empty($this->calls)) return;
$success = array();
$errors = array();

$query = $db->sql_query('SELECT c.`id`, c.`function`, c.`type`, c.`mod_id`, m.`root`, m.`title` FROM '.TABLE_XTENSE_CALLBACKS.' c LEFT JOIN '.TABLE_MOD.' m ON c.`mod_id` = m.`id` WHERE c.`active` = 1 AND m.`active` = 1 AND c.`type` IN ("'.implode('", "', $this->types).'")');
while ($call = $db->sql_fetch_assoc($query)) {
foreach ($this->calls[$call['type']] as $params) {
$this->currentCallback = $call;

try {
$instance = Callback::load($call['root']);

if (!method_exists($instance, $call['function']) || !is_callable(array($instance, $call['function']))) throw new Exception('Invalid method "'.$call['function'].'"');

$execReturn = $instance->{$call['function']}($params);

$io->append_call($call, $execReturn);
} catch (mysqli_sql_exception $e) {
$io->append_call_error($call, 'Erreur MySQL lors de l\'execution'."\n".$e->getFile().' @ '.$e->getLine()."\n".$e->getMessage());
} catch (Exception $e) {
$io->append_call_error($call, $e->getMessage(), $e);
}

$this->currentCallback = false;
} // Foreach
} // while

} // Method "apply"
}
98 changes: 49 additions & 49 deletions includes/check_callbacks.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
<?php

/**
* @package Xtense 2
* @author Unibozu
* @licence GNU
*/
if (!defined('IN_SPYOGAME')) die("Hacking Attempt!");

require_once("mod/{$root}/includes/Callback.php");

// Vidange de la table
$db->sql_query('TRUNCATE TABLE `'.TABLE_XTENSE_CALLBACKS.'`');
$insert = array();
$callInstall = array('errors' => array(), 'success' => array());
$query = $db->sql_query('SELECT action, root, id, title FROM '.TABLE_MOD.' WHERE active = 1');
while ($data = $db->sql_fetch_assoc($query)) {
if (!file_exists('mod/'.$data['root'].'/_xtense.php')) continue;
try {
$call = Callback::load($data['root']);
$error = false;
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' (erreur lors du chargement du lien) : '.$e->getMessage();
$error = true;
}
if(!$error)
foreach ($call->getCallbacks() as $k => $c) {
try {
if (empty($c)) continue;
if (!isset($c['function'], $c['type'])) throw new Exception('Donn&eacute;es sur le lien invalides : '.$k);
if (!in_array($c['type'], $callbackTypesNames)) throw new Exception('Type de lien ('.$c['type'].') invalide');
if (!isset($c['active'])) $c['active'] = 1;
if (!method_exists($call, $c['function'])) throw new Exception('La m&eacute;thode "'.$c['function'].'" n&#039;existe pas');
$insert[] = '('.$data['id'].', "'.$c['function'].'", "'.$c['type'].'", '.$c['active'].')';
$callInstall['success'][] = $data['title'].' (#'.$k.') : '.$c['type'];
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' : '.$e->getMessage();
}
}
}
if (!empty($insert)) {
$db->sql_query('REPLACE INTO '.TABLE_XTENSE_CALLBACKS.' (mod_id, function, type, active) VALUES '.implode(', ', $insert));
}
return $callInstall;

<?php

/**
* @package Xtense 2
* @author Unibozu
* @licence GNU
*/
if (!defined('IN_SPYOGAME')) die("Hacking Attempt!");

require_once("mod/{$root}/includes/Callback.php");

// Vidange de la table
$db->sql_query('TRUNCATE TABLE `'.TABLE_XTENSE_CALLBACKS.'`');


$insert = array();
$callInstall = array('errors' => array(), 'success' => array());

$query = $db->sql_query('SELECT `action`, `root`, `id`, `title` FROM '.TABLE_MOD.' WHERE `active` = 1');
while ($data = $db->sql_fetch_assoc($query)) {
if (!file_exists('mod/'.$data['root'].'/_xtense.php')) continue;
try {
$call = Callback::load($data['root']);
$error = false;
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' (erreur lors du chargement du lien) : '.$e->getMessage();
$error = true;
}
if(!$error)
foreach ($call->getCallbacks() as $k => $c) {
try {
if (empty($c)) continue;
if (!isset($c['function'], $c['type'])) throw new Exception('Donn&eacute;es sur le lien invalides : '.$k);
if (!in_array($c['type'], $callbackTypesNames)) throw new Exception('Type de lien ('.$c['type'].') invalide');
if (!isset($c['active'])) $c['active'] = 1;
if (!method_exists($call, $c['function'])) throw new Exception('La m&eacute;thode "'.$c['function'].'" n&#039;existe pas');
$insert[] = '('.$data['id'].', "'.$c['function'].'", "'.$c['type'].'", '.$c['active'].')';
$callInstall['success'][] = $data['title'].' (#'.$k.') : '.$c['type'];
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' : '.$e->getMessage();
}
}
}

if (!empty($insert)) {
$db->sql_query('REPLACE INTO '.TABLE_XTENSE_CALLBACKS.' (`mod_id`, `function`, `type`, `active`) VALUES '.implode(', ', $insert));
}
return $callInstall;
Loading

0 comments on commit b5d0593

Please sign in to comment.