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 .= "
Manage Replacement Macros input['id']}');\" />
"; $ibforums->html .= "
\n
\n"; $this->unaltered = "- "; $this->altered = "+ "; $this->inherited = "| "; //----------------------------------------- // Loop and print //----------------------------------------- foreach( $macros as $name => $row ) { $real = $std->txt_htmlspecialchars( $row['macro_replace'] ); //----------------------------------------- // Altered? //----------------------------------------- if ( $row['macro_set'] == $ibforums->input['id'] ) { $altered_image = $this->altered; $css_info = '#FFDCD8'; } else if ( $row['macro_set'] == 1 ) { $altered_image = $this->unaltered; $css_info = '#EEE'; } else { $altered_image = $this->inherited; $css_info = '#FFF2D3'; } //----------------------------------------- // Figure out quotes //----------------------------------------- $out_quote = '"'; $in_quote = "'"; if ( preg_match( "/'/", $real ) ) { $out_quote = "'"; $in_quote = '"'; } $preview = str_replace( "<#IMG_DIR#>", $skin['set_image_dir'], $row['macro_replace'] ); if ( $row['macro_set'] > 1 and $row['macro_set'] == $ibforums->input['id'] ) { $remove_button = "input['id']}&p={$ibforums->input['p']}');\" />"; } else { $remove_button = ""; } //----------------------------------------- // Not an image? //----------------------------------------- if ( ! preg_match( "#img\s{1,}src=#i", $row['macro_replace'] ) ) { $preview = substr( $real, 0, 200 ); } $edit_button = ""; //----------------------------------------- // Render row //----------------------------------------- $style = "padding:4px;border-bottom:1px solid #DDD;background:{$css_info}"; $ibforums->html .= " "; } $ibforums->html .= "
$altered_image  <{{$row['macro_value']}}> $preview $remove_button $edit_button
input['id']}');\" />
"; $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(); } } ?>