Skin -> Image Macro functions
| > Module written by Matt Mecham
| > Date started: 4th April 2002
|
| > Module Version Number: 1.0.0
| > DBA Checked: Tue 25th 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_imagemacros {
var $base_url;
function auto_run()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Kill globals - globals bad, Homer good.
//-----------------------------------------
$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
foreach ( $tmp_in as $k => $v )
{
unset($$k);
}
//-----------------------------------------
switch($ibforums->input['code'])
{
case 'edit':
$this->show_macros();
break;
case 'doedit':
$this->edit_set_name();
break;
case 'macroremove':
$this->macro_remove();
break;
case 'doeditmacro':
$this->macro_edit();
break;
case 'doaddmacro':
$this->macro_add();
break;
default:
print "No action"; exit();
break;
}
}
//-----------------------------------------
// Remove macro
//-----------------------------------------
function macro_remove()
{
global $ibforums, $DB, $std, $HTTP_POST_VARS;
if ($ibforums->input['mid'] == "")
{
$ibforums->admin->error("You must specify an existing macro ID, go back and try again");
}
$id = intval($ibforums->input['id']);
$p = intval($ibforums->input['p']);
$DB->simple_exec_query( array( 'delete' => 'skin_macro', 'where' => "macro_id='".$ibforums->input['mid']."'" ) );
//-----------------------------------------
// Recache macros
//-----------------------------------------
$ibforums->cache_func->_recache_macros($id, $p);
//-----------------------------------------
// Bounce back
//-----------------------------------------
$ibforums->input['id'] = $id;
$ibforums->main_msg = "Macro removed!";
$this->show_macros();
}
//-----------------------------------------
// Apply the edit to the DB
//-----------------------------------------
function macro_edit()
{
global $ibforums, $DB, $std;
if ($ibforums->input['mid'] == "")
{
$ibforums->admin->error("You must specify an existing image set ID, go back and try again");
}
$id = intval($ibforums->input['id']);
$p = intval($ibforums->input['p']);
$key = $DB->add_slashes( $std->txt_safeslashes($_POST['variable']) );
$val = $DB->add_slashes( $std->txt_UNhtmlspecialchars($std->txt_safeslashes($_POST['replacement']) ) );
//-----------------------------------------
// Get macro for examination..
//-----------------------------------------
$DB->simple_construct( array( 'select' => '*', 'from' => 'skin_macro', 'where' => "macro_id='".$ibforums->input['mid']."'" ) );
$DB->simple_exec();
if ( ! $row = $DB->fetch_row() )
{
$ibforums->admin->error("Could not retrieve the record from the DB");
}
//-----------------------------------------
// Is this our macro set?
//-----------------------------------------
if ( $row['macro_set'] == $id )
{
//-----------------------------------------
// Okay, update...
//-----------------------------------------
$DB->simple_construct( array( 'update' => 'skin_macro', 'set' => "macro_value='$key', macro_replace='$val'", 'where' => "macro_id=".$ibforums->input['mid'] ) );
$DB->simple_exec();
}
else
{
//-----------------------------------------
// No? OK - best add it as a 'new' macro
//-----------------------------------------
$DB->manual_addslashes = 1;
$DB->do_insert( 'skin_macro', array (
'macro_value' => $key,
'macro_replace' => $val,
'macro_can_remove' => 1,
'macro_set' => $id
) );
$DB->manual_addslashes = 0;
}
//-----------------------------------------
// Recache macros
//-----------------------------------------
$ibforums->cache_func->_recache_macros($id, $p);
//-----------------------------------------
// Bounce back
//-----------------------------------------
$ibforums->input['id'] = $id;
$this->show_macros();
}
//-----------------------------------------
// ADD MACRO
//-----------------------------------------
function macro_add()
{
global $ibforums, $DB, $std;
if ($ibforums->input['mid'] == "")
{
$ibforums->admin->error("You must specify an existing macro set ID, go back and try again");
}
$id = intval($ibforums->input['id']);
$p = intval($ibforums->input['p']);
$DB->do_insert( 'skin_macro', array (
'macro_value' => $std->txt_safeslashes($_POST['variable']),
'macro_replace' => $std->txt_UNhtmlspecialchars($std->txt_safeslashes($_POST['replacement'])),
'macro_can_remove' => 1,
'macro_set' => $id
) );
//-----------------------------------------
// Recache macros
//-----------------------------------------
$ibforums->cache_func->_recache_macros($id, $p);
//-----------------------------------------
// Bounce back
//-----------------------------------------
$ibforums->input['id'] = $id;
$this->show_macros();
}
//-----------------------------------------
// Show macros
//-----------------------------------------
function show_macros()
{
global $ibforums, $DB, $std;
//-----------------------------------------
if ($ibforums->input['id'] == "")
{
$ibforums->admin->error("You must specify an existing macro set ID, go back and try again");
}
//-----------------------------------------
// check tree...
//-----------------------------------------
$this_set = "";
if ( $ibforums->input['p'] > 0 )
{
$in = ','.$ibforums->input['p'];
}
//-----------------------------------------
// Get macros
//-----------------------------------------
$macros = $ibforums->cache_func->_get_macros($ibforums->input['id'], $ibforums->input['p']);
//-----------------------------------------
// Get img_dir this set is using...
//-----------------------------------------
$DB->simple_construct( array( 'select' => '*', 'from' => 'skin_sets', 'where' => "set_skin_set_id='".$ibforums->input['id']."'" ) );
$DB->simple_exec();
$skin = $DB->fetch_row();
$ibforums->admin->page_detail = "To edit a macro, simply click on the 'edit' link of the appropriate macro.";
$ibforums->admin->page_title = "Manage Replacement Macros in Set: {$skin['set_name']}";
//-----------------------------------------
// Start output
//-----------------------------------------
$ibforums->html .= $ibforums->adskin->js_no_specialchars();
$ibforums->html .= $ibforums->adskin->js_checkdelete();
$ibforums->html .= "
";
$ibforums->html .= "";
$ibforums->html .= $ibforums->adskin->skin_jump_menu_wrap();
//-----------------------------------------
// Show altered / unaltered
// legend
//-----------------------------------------
$ibforums->html .= "
Replace Macro Example
If you added a key of 'green_font' and a replacement of '<font color='green'>', each instance of <{green_font}> would be converted to <font color='green'>
<#IMG_DIR#> is available to any macro, this is automatically replaced with the name of the image directory you choose when using this macro set in a skin
Replacement Macro Legend:
{$this->altered} This item has been customized for this skin set.
{$this->unaltered} This item has not been customized from the master skin set.
{$this->inherited} This item has inherited customizations from the parent skin set.
";
$ibforums->admin->nav[] = array( 'act=sets' ,'Skin Manager Home' );
$ibforums->admin->nav[] = array( '' ,'Editing Replacement Macros in Set '.$skin['set_name'] );
$ibforums->admin->output();
}
}
?>