Administration Module
| > Module written by Matt Mecham
| > Date started: 27th January 2004
|
| > Module Version Number: 1.0.0
| > DBA Checked: Mon 24th May 2004
+--------------------------------------------------------------------------
*/
if ( ! defined( 'IN_ACP' ) )
{
print "
Incorrect access
You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";
exit();
}
class ad_administration {
var $functions = "";
function auto_run()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Require and RUN !! THERES A BOMB
//-----------------------------------------
$ibforums->admin->page_detail = "The cache manager allows you to view the contents of your cache and update them.";
$ibforums->admin->page_title = "Cache Manager";
//-----------------------------------------
// Kill globals - globals bad, Homer good.
//-----------------------------------------
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
foreach ( $tmp_in as $k => $v )
{
unset($$k);
}
//-----------------------------------------
// What to do...
//-----------------------------------------
switch($ibforums->input['code'])
{
case 'cacheend':
$this->cache_end();
break;
case 'viewcache':
$this->view_cache();
break;
case 'bbcode':
$this->bbcode_start();
break;
case 'bbcode_add':
$this->bbcode_form('add');
break;
case 'bbcode_doadd':
$this->bbcode_save('add');
break;
case 'bbcode_edit':
$this->bbcode_form('edit');
break;
case 'bbcode_doedit':
$this->bbcode_save('edit');
break;
case 'bbcode_test':
$this->bbcode_test();
break;
case 'bbcode_delete':
$this->bbcode_delete();
break;
case 'bbcode_export':
$this->bbcode_export();
break;
case 'bbcode_import':
$this->bbcode_import();
break;
//-----------------------------------------
// Emu?
//-----------------------------------------
case 'emo':
$this->emoticon_start();
break;
case 'emo_packsplash':
$this->emoticon_pack_splash();
break;
case 'emo_packexport':
$this->emoticon_pack_export();
break;
case 'emo_packimport':
$this->emoticon_pack_import();
break;
case 'emo_manage':
$this->emoticon_manage();
break;
case 'emo_doedit':
$this->emoticon_edit();
break;
case 'emo_doadd':
$this->emoticon_add();
break;
case 'emo_remove':
$this->emoticon_remove();
break;
case 'emo_setadd':
$this->emoticon_setalter($type='add');
break;
case 'emo_setedit':
$this->emoticon_setalter($type='edit');
break;
case 'emo_setremove':
$this->emoticon_setremove();
break;
case 'emo_upload':
$this->emoticon_upload();
//-----------------------------------------
// Badword
//-----------------------------------------
case 'badword':
$this->badword_start();
break;
case 'badword_add':
$this->badword_add();
break;
case 'badword_remove':
$this->badword_remove();
break;
case 'badword_edit':
$this->badword_edit();
break;
case 'badword_doedit':
$this->badword_doedit();
break;
case 'badword_export':
$this->badword_export();
break;
case 'badword_import':
$this->badword_import();
break;
//-----------------------------------------
// BAN (d-aid)
//-----------------------------------------
case 'ban':
$this->ban_start();
break;
case 'ban_add':
$this->ban_add();
break;
case 'ban_delete':
$this->ban_delete();
break;
default:
$this->cache_start();
break;
}
}
//-----------------------------------------
// BAN: Rebuild cache
//-----------------------------------------
function ban_rebuildcache()
{
global $ibforums, $std, $DB;
$ibforums->cache['banfilters'] = array();
$DB->simple_construct( array( 'select' => 'ban_content', 'from' => 'banfilters', 'where' => "ban_type='ip'" ) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$ibforums->cache['banfilters'][] = $r['ban_content'];
}
$std->update_cache( array( 'name' => 'banfilters', 'array' => 1, 'deletefirst' => 1 ) );
}
//-----------------------------------------
// BAN: DELETE
//-----------------------------------------
function ban_delete()
{
global $ibforums, $DB, $std;
$ids = array();
foreach ($ibforums->input as $key => $value)
{
if ( preg_match( "/^id_(\d+)$/", $key, $match ) )
{
if ( $ibforums->input[$match[0]] )
{
$ids[] = $match[1];
}
}
}
if ( count( $ids ) )
{
$DB->simple_construct( array( 'delete' => 'banfilters', 'where' => 'ban_id IN('.implode( ",",$ids ).')' ) );
$DB->simple_exec();
}
$this->ban_rebuildcache();
$ibforums->main_msg = "Ban filters removed";
$this->ban_start();
}
//-----------------------------------------
// BAN: ADD
//-----------------------------------------
function ban_add()
{
global $ibforums, $DB, $std;
if ( ! $ibforums->input['bantext'] )
{
$ibforums->main_msg = "You must enter something to add to the ban filters!";
$this->ban_start();
}
//-----------------------------------------
// Check for existing entry
//-----------------------------------------
$result = $DB->simple_exec_query( array( 'select' => '*', 'from' => 'banfilters', 'where' => "ban_content='{$ibforums->input['bantext']}' and ban_type='{$ibforums->input['bantype']}'" ) );
if ( $result['ban_id'] )
{
$ibforums->main_msg = "Duplicate entry, entry not added to the ban filters database.";
$this->ban_start();
}
$DB->do_insert( 'banfilters', array( 'ban_type' => $ibforums->input['bantype'], 'ban_content' => $ibforums->input['bantext'], 'ban_date' => time() ) );
$this->ban_rebuildcache();
$ibforums->main_msg = "Ban filter added";
$this->ban_start();
}
//-----------------------------------------
// BAN: START
//-----------------------------------------
function ban_start()
{
global $ibforums, $DB, $std;
$ibforums->admin->page_title = "Ban Control";
$ibforums->admin->page_detail = "This section allows you to modify, delete or add IP addresses, email addresses and reserved names to the ban filters.
You can use * as a wildcard in any IP or email filter. (Example: 127.0.*, *@yahoo.com)";
//-----------------------------------------
// Get things
//-----------------------------------------
$ban = array();
$DB->simple_construct( array( 'select' => '*', 'from' => 'banfilters', 'order' => 'ban_date desc' ) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$ban[ $r['ban_type'] ][ $r['ban_id'] ] = $r;
}
//-----------------------------------------
// SHOW THEM!
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'ban_delete'),
2 => array( 'act' , 'admin' ),
) );
$ibforums->adskin->td_header[] = array( " " , "1%" );
$ibforums->adskin->td_header[] = array( "Entry" , "80%" );
$ibforums->adskin->td_header[] = array( "Date Added" , "20%" );
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->start_table( "Ban Control" );
//-----------------------------------------
// Banned IP Addresses
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->add_td_basic("Banned IP Addresses", "left", "pformstrip");
if ( is_array( $ban['ip'] ) and count( $ban['ip'] ) )
{
foreach ( $ban['ip'] as $id => $entry )
{
$ibforums->html .= $ibforums->adskin->add_td_row( array( "",
$entry['ban_content'],
$std->get_date( $entry['ban_date'], 'SHORT' ),
) );
}
}
else
{
$ibforums->html .= $ibforums->adskin->add_td_basic("No Entered Banned IP Addresses", "left", "tdrow1");
}
//-----------------------------------------
// Banned Email Addresses
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->add_td_basic("Banned Email Addresses", "left", "pformstrip");
if ( is_array( $ban['email'] ) and count( $ban['email'] ) )
{
foreach ( $ban['email'] as $id => $entry )
{
$ibforums->html .= $ibforums->adskin->add_td_row( array( "",
$entry['ban_content'],
$std->get_date( $entry['ban_date'], 'SHORT' ),
) );
}
}
else
{
$ibforums->html .= $ibforums->adskin->add_td_basic("No Entered Banned Email Addresses", "left", "tdrow1");
}
//-----------------------------------------
// Banned Names
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->add_td_basic("Non-Registerable Names", "left", "pformstrip");
if ( is_array( $ban['name'] ) and count( $ban['name'] ) )
{
foreach ( $ban['name'] as $id => $entry )
{
$ibforums->html .= $ibforums->adskin->add_td_row( array( "",
$entry['ban_content'],
$std->get_date( $entry['ban_date'], 'SHORT' ),
) );
}
}
else
{
$ibforums->html .= $ibforums->adskin->add_td_basic("No Entered Names", "left", "tdrow1");
}
$end_it_now = "
";
$ibforums->html .= $ibforums->adskin->add_td_basic( $end_it_now, "center", "pformstrip");
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->output();
}
//-----------------------------------------
// BADWORDS: Import
//-----------------------------------------
function badword_import()
{
global $ibforums, $DB, $std;
$content = $ibforums->admin->import_xml( 'ipb_badwords.xml' );
//-----------------------------------------
// Got anything?
//-----------------------------------------
if ( ! $content )
{
$ibforums->main_msg = "Upload failed, ipb_badwords.xml was either missing or empty";
$this->emoticon_pack_splash();
}
//-----------------------------------------
// Get xml mah-do-dah
//-----------------------------------------
require( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
//-----------------------------------------
// Unpack the datafile
//-----------------------------------------
$xml->xml_parse_document( $content );
//-----------------------------------------
// Get current badwords
//-----------------------------------------
$words = array();
$DB->simple_construct( array( 'select' => '*', 'from' => 'badwords', 'order' => 'type' ) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$words[ $r['type'] ] = 1;
}
//-----------------------------------------
// pArse
//-----------------------------------------
foreach( $xml->xml_array['badwordexport']['badwordgroup']['badword'] as $idx => $entry )
{
$type = $entry['type']['VALUE'];
$swop = $entry['swop']['VALUE'];
$m_exact = $entry['m_exact']['VALUE'];
if ( $words[ $type ] )
{
continue;
}
if ( $type )
{
$DB->do_insert( 'badwords', array( 'type' => $type, 'swop' => $swop, 'm_exact' => $m_exact ) );
}
}
$this->badword_rebuildcache();
$ibforums->main_msg = "Badword XML file import completed";
$this->badword_start();
}
//-----------------------------------------
// BADWORD: Export
//-----------------------------------------
function badword_export()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Get xml mah-do-dah
//-----------------------------------------
require( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
//-----------------------------------------
// Start...
//-----------------------------------------
$xml->xml_set_root( 'badwordexport', array( 'exported' => time() ) );
//-----------------------------------------
// Get emo group
//-----------------------------------------
$xml->xml_add_group( 'badwordgroup' );
$DB->simple_construct( array( 'select' => 'type, swop, m_exact', 'from' => 'badwords', 'order' => 'type' ) );
$DB->simple_exec();
while ( $r = $DB->fetch_row() )
{
$content = array();
foreach ( $r as $k => $v )
{
$content[] = $xml->xml_build_simple_tag( $k, $v );
}
$entry[] = $xml->xml_build_entry( 'badword', $content );
}
$xml->xml_add_entry_to_group( 'badwordgroup', $entry );
$xml->xml_format_document();
//-----------------------------------------
// Send to browser.
//-----------------------------------------
$ibforums->admin->show_download( $xml->xml_document, 'ipb_badwords.xml' );
}
//-----------------------------------------
// BADWORD: Start
//-----------------------------------------
function badword_start()
{
global $ibforums, $DB, $std;
$ibforums->admin->page_detail = "You can add/edit and remove bad word filters in this section. The badword filter allows you to globally replace words from a members post, signature and topic title.
Loose matching: If you entered 'hell' as a bad word, it will replace 'hell' and 'hello' with either your replacement if entered or 6 hashes (case insensitive)
Exact matching: If you entered 'hell' as a bad word, it will replace 'hell' only with either your replacement if entered or 6 hashes (case insensitive)";
$ibforums->admin->page_title = "Bad Word Filter";
//-----------------------------------------
// Start form
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->start_form( array( 1 => array( 'code' , 'badword_add' ),
2 => array( 'act' , 'admin' ),
) );
$ibforums->adskin->td_header[] = array( "Before" , "30%" );
$ibforums->adskin->td_header[] = array( "After" , "30%" );
$ibforums->adskin->td_header[] = array( "Method" , "20%" );
$ibforums->adskin->td_header[] = array( "Edit" , "10%" );
$ibforums->adskin->td_header[] = array( "Remove" , "10%" );
//-----------------------------------------
// Start table
//-----------------------------------------
$export_button = $ibforums->adskin->js_make_button("Export Filters", $ibforums->base_url."&act=admin&code=badword_export");
$table = "
An IPB Emoticon Pack is an XMLarchive of the images and activation words (i.e. :smile:)
",
$ibforums->adskin->form_dropdown( 'emo_set', $emodd )
) );
$ibforums->html .= $ibforums->adskin->add_td_row( array(
"OR Import into a new group named:
Browse your computer for 'ipb_emoticons.xml' or 'ipb_emoticons.xml.gz'
",
$ibforums->adskin->form_upload( )
) );
$ibforums->html .= $ibforums->adskin->end_form("Import");
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->output();
}
//-----------------------------------------
// EMOTICON EXPORT! EXPORT! EX... oh, that's abort isn't it?
//-----------------------------------------
function emoticon_pack_export()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Get xml mah-do-dah
//-----------------------------------------
require( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
require( KERNEL_PATH.'class_xmlarchive.php' );
$xmlarchive = new class_xmlarchive();
//-----------------------------------------
// Checkdamoonah
//-----------------------------------------
if ( ! $ibforums->input['emo_set'] )
{
$this->ibforums->msg = "You must specify which emoticon group you wish to export";
}
//-----------------------------------------
// Get emowticuns
//-----------------------------------------
$emo_db = array();
$DB->simple_construct( array( 'select' => '*', 'from' => 'emoticons', 'where' => "emo_set='".$ibforums->input['emo_set']."'" ) );
$DB->simple_exec();
while( $r = $DB->fetch_row() )
{
$emo_db[ $r['image'] ] = $r;
}
//-----------------------------------------
// Get ;) :D folders
//-----------------------------------------
$emodirs = array();
$emodd = array();
$dh = opendir( CACHE_PATH.'style_emoticons/'.$ibforums->input['emo_set'] );
while ( $file = readdir( $dh ) )
{
if (($file != ".") && ($file != ".."))
{
if ( $emo_db[ $file ] != "" )
{
$files_to_add[] = CACHE_PATH.'style_emoticons/'.$ibforums->input['emo_set'].'/'.$file;
}
}
}
closedir( $dh );
//-----------------------------------------
// Add um into the ark-hive
//-----------------------------------------
foreach( $files_to_add as $f )
{
$xmlarchive->xml_add_file( $f );
}
//-----------------------------------------
// Create the database archive...
//-----------------------------------------
$xml->xml_set_root( 'emoticonexport', array( 'exported' => time(), 'name' => $ibforums->input['emo_set'] ) );
//-----------------------------------------
// Get emo group
//-----------------------------------------
$xml->xml_add_group( 'emogroup' );
foreach( $emo_db as $i => $r )
{
$content = array();
$content[] = $xml->xml_build_simple_tag( 'typed' , $r['typed'] );
$content[] = $xml->xml_build_simple_tag( 'image' , $r['image'] );
$content[] = $xml->xml_build_simple_tag( 'clickable', $r['clickable'] );
$entry[] = $xml->xml_build_entry( 'emoticon', $content );
}
$xml->xml_add_entry_to_group( 'emogroup', $entry );
$xml->xml_format_document();
//-----------------------------------------
// Add in emoticons doc to archive
//-----------------------------------------
$xmlarchive->xml_add_file_contents( $xml->xml_document, 'emoticon_data.xml' );
$xmlarchive->xml_create_archive();
//-----------------------------------------
// Create archive and send to
// browser.
//-----------------------------------------
$imagearchive = $xmlarchive->xml_get_contents();
$ibforums->admin->show_download( $imagearchive, 'ipb_emoticons.xml' );
}
//-----------------------------------------
// IMPORT THE EMOTICONS
//-----------------------------------------
function emoticon_pack_import()
{
global $ibforums, $DB, $std;
$content = $ibforums->admin->import_xml( 'ipb_emoticons.xml' );
//-----------------------------------------
// Got anything?
//-----------------------------------------
if ( ! $content )
{
$ibforums->main_msg = "Upload failed, ipb_emoticons.xml was either missing or empty";
$this->emoticon_pack_splash();
}
//-----------------------------------------
// Get xml mah-do-dah
//-----------------------------------------
require( KERNEL_PATH.'class_xml.php' );
$xml = new class_xml();
require( KERNEL_PATH.'class_xmlarchive.php' );
$xmlarchive = new class_xmlarchive();
$xmlarchive->xml_read_archive_data( $content );
//-----------------------------------------
// Get the datafile
//-----------------------------------------
$emoticons = array();
$emoticon_data = array();
foreach( $xmlarchive->file_array as $f )
{
if ( $f['filename'] == 'emoticon_data.xml' )
{
$emoticon_data = $f['content'];
}
else
{
$emoticons[ $f['filename'] ] = $f['content'];
}
}
//-----------------------------------------
// Unpack the datafile
//-----------------------------------------
$xml->xml_parse_document( $emoticon_data );
//-----------------------------------------
// New set, old set - we're set!
//-----------------------------------------
if ( ! $ibforums->input['emo_set'] and ! $ibforums->input['new_emo_set'] )
{
$this->ibforums->msg = "You must specify which emoticon group you wish to import into";
}
$emo_set_dir = $ibforums->input['emo_set'];
$ibforums->input['new_emo_set'] = preg_replace( "/[^a-zA-Z0-9\-_]/", "",$ibforums->input['new_emo_set'] );
if ( $ibforums->input['new_emo_set'] )
{
$emo_set_dir = $ibforums->input['new_emo_set'];
//-----------------------------------------
// Directory exists?
//-----------------------------------------
if ( file_exists( CACHE_PATH.'style_emoticons/'.$emo_set_dir ) )
{
$ibforums->main_msg = "'style_emoticons/$emo_set_dir' already exists, please choose another name.";
$this->emoticon_pack_splash();
}
//-----------------------------------------
// Create directory?
//-----------------------------------------
if ( @mkdir( CACHE_PATH.'style_emoticons/'.$emo_set_dir, 0777 ) )
{
@chmod( CACHE_PATH.'style_emoticons/'.$emo_set_dir, 0777 );
}
else
{
$ibforums->main_msg = "IPB cannot create a new folder for you, please create the folder manually using FTP in 'style_emoticons'";
$this->emoticon_pack_splash();
}
}
//-----------------------------------------
// Are we over writing?
//-----------------------------------------
$emo_image = array();
$emo_typed = array();
if ( $ibforums->input['overwrite'] != 1 )
{
$DB->simple_construct( array( 'select' => '*', 'from' => 'emoticons', 'where' => "emo_set='".$emo_set_dir."'" ) );
$DB->simple_exec();
while( $r = $DB->fetch_row() )
{
$emo_image[ $r['image'] ] = 1;
$emo_typed[ $r['typed'] ] = 1;
}
}
foreach( $xml->xml_array['emoticonexport']['emogroup']['emoticon'] as $idx => $entry )
{
$image = $entry['image']['VALUE'];
$typed = $entry['typed']['VALUE'];
$click = $entry['clickable']['VALUE'];
if ( $emo_image[ $image ] or $emo_typed[ $typed ] )
{
continue;
}
@unlink( CACHE_PATH.'style_emoticons/'.$emo_set_dir.'/'.$image );
$DB->simple_exec_query( array( 'delete' => 'emoticons', 'where' => "typed='$typed' and image='$image' and emo_set='$emo_set_dir'" ) );
if ( $FH = fopen( CACHE_PATH.'style_emoticons/'.$emo_set_dir.'/'.$image, 'wb' ) )
{
if ( fwrite( $FH, $emoticons[ $image ] ) )
{
fclose( $FH );
$DB->do_insert( 'emoticons', array( 'typed' => $typed, 'image' => $image, 'clickable' => $click, 'emo_set' => $emo_set_dir ) );
}
}
}
$this->emoticon_rebuildcache();
$ibforums->main_msg = "Emoticon XMLarchive import completed";
$this->emoticon_start();
}
//-----------------------------------------
// EMOTICON Manage
//-----------------------------------------
function emoticon_manage()
{
global $ibforums, $DB, $std;
$ibforums->input['id'] = trim($ibforums->input['id']);
$ibforums->admin->nav[] = array( 'act=admin&code=emo', 'Emoticons Manager' );
$ibforums->admin->nav[] = array( '', 'Managing Set '.$ibforums->input['id'] );
$ibforums->admin->page_detail = "You may add/edit or remove emoticons in this section. Clickable refers to emoticons that are in the posting screens 'Clickable Emoticons' table.";
$ibforums->admin->page_title = "Emoticon Control";
//-----------------------------------------
// Get emoticons for this group
//-----------------------------------------
$emo_db = array();
$emo_file = array();
$DB->simple_construct( array( 'select' => '*', 'from' => 'emoticons', 'where' => "emo_set='".$ibforums->input['id']."'", 'order' => 'clickable DESC' ) );
$DB->simple_exec();
while( $r = $DB->fetch_row() )
{
$emo_db[ $r['image'] ] = $r;
}
$emo_file = array();
$emo_rfile = $this->emoticon_get_folder_contents( $ibforums->input['id'] );
foreach( $emo_rfile as $ef )
{
$emo_file[ $ef ] = $ef;
}
//-----------------------------------------
// Start output
//-----------------------------------------
$per_row = 5;
$td_width = 100 / $per_row;
$ibforums->html .= "
Assigned Emoticons in set '{$ibforums->input['id']}'
";
//-----------------------------------------
// Images left in the dir?
//-----------------------------------------
if ( count( $emo_file ) )
{
$ibforums->html .= "
Unassigned images in folder '{$ibforums->input['id']}'
More Information When adding the BBCode replacement, don't forget to add the {content} block where you wish the tag content to go when parsed.
If you are using an option [tag=option][/tag] tag, don't forget to add in {option} in the BBCode replacement where you want the option to go.
";
//-----------------------------------------
$ibforums->admin->output();
}
//-----------------------------------------
// BBCODE Splash
//-----------------------------------------
function bbcode_start()
{
global $ibforums, $DB, $std;
$ibforums->admin->page_detail = "The BBCode manager allows you to add new custom BBCode.";
$ibforums->admin->page_title = "BBCode Manager";
//-----------------------------------------
// Show the codes mahn!
//-----------------------------------------
$ibforums->adskin->td_header[] = array( "Title" , "30%" );
$ibforums->adskin->td_header[] = array( "Tag" , "40%" );
$ibforums->adskin->td_header[] = array( "Options" , "30%" );
$export_button = $ibforums->adskin->js_make_button("Export BBCode", $ibforums->base_url."&act=admin&code=bbcode_export");
$table = "