SimplePortal

Development => Bugs => Fixed or Bogus Bugs => Topic started by: ???1031 on August 27, 2008, 02:49:09 PM

Title: Checkup Blocks of Mod Related Code Block, so that this blocks are not selectable
Post by: ???1031 on August 27, 2008, 02:49:09 PM
So i think this is not a bug but i think this is error that can be prevented  ::). (It's more a feature request, after i thought about it ;D)

For example:
If you have not installed the Arcade Mod than the Block should not include the "ArcadeStats.php", i think it should first test if the file exists and if not, than output something like, Sorry this Add On is not installed on your forum or anything like that Wink. This can be done before the Admin user can select this block (So that this block never will be selected as long the mod is not installed).

And for the Shop and Gallery Mod is the same, there you can load the table names and check if the exists if they not exist than do not allow a select of this block Wink.

Only ideas to make it more user friendly.
I know it's a simple portal, but this checkup need not much time and can be done on the select Wink.

Example for a Database Table Checkup Function ;)
Code: [Select]
<?php
/*
bool loadDatabaseTables ()
- Preload database Tables this will be only done once per script call
- Return false on error
- Mysql 3.x+ Compatible ;) for SMF 1.1.x
*/
function loadDatabaseTables() {
global $database_tables$db_name;

if(isset($database_tables))
return !empty($database_tables);
else
$database_tables = array();

//Prepare a Checkup ;D
$request db_query("SHOW TABLES FROM {$db_name}"__FILE____LINE__);
while ($row mysql_fetch_assoc($request))
$database_tables[] = strtolower(current($row));
mysql_free_result($request);
return !empty($database_tables);
}

/*
bool databaseTableExists (string tablename, bool $addprefix = true)
- Work only in SMF 1.1.x (SMF 2.0.x work diffrent, but it&#39;s possible to insert)
- Return true if the tablename exits
- $addprefix will automatic add the $db_prefix (Check also it this is allready done!)
*/
function databaseTableExists($tablename = &#39;&#39;, $addprefix = true) {
global $database_tables$db_prefix;

//Nothing to Serach for ;)
if(empty($tablename))
return false;

//Error ?_?
if(empty($database_tables) && !loadDatabaseTables())
return false;

//First thing i do.. i know normal i should not so this ;P But it&#39;s good enouph for smf ;)
$tablename strtolower($tablename);

//Table Prefix auto add? :D
if($addprefix === true && strpos($tablename$db_prefix) !== 0) {
//Looks not so nice ;) but it work trust me ;P
if(strpos($tablename, &#39;{$db_prefix}&#39;) !== false)
$tablename str_replace(&#39;{$db_prefix}&#39;, $db_prefix, $tablename);
elseif(strpos($tablename, &#39;$db_prefix&#39;) !== false)
$tablename str_replace(&#39;$db_prefix&#39;, $db_prefix, $tablename);
else
$tablename $db_prefix.$tablename;
}

return in_array($tablename$database_tables);
}

echo 
databaseTableExists(&#39;settings&#39;) ? &#39;Exists&#39; : &#39;Do Not Exists&#39;;
echo databaseTableExists(&#39;blubb_settings&#39;) ? &#39;Exists&#39; : &#39;Do Not Exists&#39;;
?>


Bye
DIN1031
Title: Re: Checkup Blocks of Mod Related Code Block, so that this blocks are not selectable
Post by: Nathaniel on August 29, 2008, 07:41:34 AM
I believe that this is a bug. At Simple Portal we don't like these sorts of bugs, even small potential bugs need to be quashed. ;)

I have added this to the bug-tracker. Thanks for reporting it. :)
SimplePortal 2.3.8 © 2008-2024, SimplePortal