$Date: 2006-10-05 12:04:08 -0400 (Thu, 05 Oct 2006) $ | > $Revision: 609 $ | > $Author: matt $ +--------------------------------------------------------------------------- | | > 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_skin_macros { var $base_url; /** * Section title name * * @var string */ var $perm_main = "lookandfeel"; /** * Section title name * * @var string */ var $perm_child = "image"; function auto_run() { //----------------------------------------- switch($this->ipsclass->input['code']) { case 'edit': $this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' ); $this->show_macros(); break; case 'doedit': $this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' ); $this->edit_set_name(); break; case 'macroremove': $this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' ); $this->macro_remove(); break; case 'doeditmacro': $this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' ); $this->macro_edit(); break; case 'doaddmacro': $this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' ); $this->macro_add(); break; default: print "No action"; exit(); break; } } //----------------------------------------- // Remove macro //----------------------------------------- function macro_remove() { if ($this->ipsclass->input['mid'] == "") { $this->ipsclass->admin->error("You must specify an existing macro ID, go back and try again"); } $id = intval($this->ipsclass->input['id']); $p = intval($this->ipsclass->input['p']); $this->ipsclass->DB->simple_exec_query( array( 'delete' => 'skin_macro', 'where' => "macro_id=".intval($this->ipsclass->input['mid']) ) ); //----------------------------------------- // Recache macros //----------------------------------------- $this->ipsclass->cache_func->_recache_macros($id, $p); //----------------------------------------- // Bounce back //----------------------------------------- $this->ipsclass->input['id'] = $id; $this->ipsclass->main_msg = "Macro removed!"; $this->show_macros(); } //----------------------------------------- // Apply the edit to the DB //----------------------------------------- function macro_edit() { if ($this->ipsclass->input['mid'] == "") { $this->ipsclass->admin->error("You must specify an existing image set ID, go back and try again"); } $id = intval($this->ipsclass->input['id']); $p = intval($this->ipsclass->input['p']); $key = $this->ipsclass->DB->add_slashes( $this->ipsclass->txt_safeslashes($_POST['variable']) ); $val = $this->ipsclass->DB->add_slashes( $this->ipsclass->txt_safeslashes($_POST['replacement']) ); //----------------------------------------- // Get macro for examination.. //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'skin_macro', 'where' => "macro_id=".intval($this->ipsclass->input['mid']) ) ); $this->ipsclass->DB->simple_exec(); if ( ! $row = $this->ipsclass->DB->fetch_row() ) { $this->ipsclass->admin->error("Could not retrieve the record from the DB"); } //----------------------------------------- // Is this our macro set? //----------------------------------------- if ( $row['macro_set'] == $id ) { //----------------------------------------- // Okay, update... //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'update' => 'skin_macro', 'set' => "macro_value='$key', macro_replace='$val'", 'where' => "macro_id=".intval($this->ipsclass->input['mid']) ) ); $this->ipsclass->DB->simple_exec(); } else { //----------------------------------------- // No? OK - best add it as a 'new' macro //----------------------------------------- $this->ipsclass->DB->manual_addslashes = 1; $this->ipsclass->DB->do_insert( 'skin_macro', array ( 'macro_value' => $key, 'macro_replace' => $val, 'macro_can_remove' => 1, 'macro_set' => $id ) ); $this->ipsclass->DB->manual_addslashes = 0; } //----------------------------------------- // Recache macros //----------------------------------------- $this->ipsclass->cache_func->_recache_macros($id, $p); //----------------------------------------- // Bounce back //----------------------------------------- $this->ipsclass->input['id'] = $id; $this->show_macros(); } //----------------------------------------- // ADD MACRO //----------------------------------------- function macro_add() { if ($this->ipsclass->input['mid'] == "") { $this->ipsclass->admin->error("You must specify an existing macro set ID, go back and try again"); } $id = intval($this->ipsclass->input['id']); $p = intval($this->ipsclass->input['p']); $this->ipsclass->DB->do_insert( 'skin_macro', array ( 'macro_value' => $this->ipsclass->txt_safeslashes($_POST['variable']), 'macro_replace' => $this->ipsclass->txt_safeslashes($_POST['replacement']), 'macro_can_remove' => 1, 'macro_set' => $id ) ); //----------------------------------------- // Recache macros //----------------------------------------- $this->ipsclass->cache_func->_recache_macros($id, $p); //----------------------------------------- // Bounce back //----------------------------------------- $this->ipsclass->input['id'] = $id; $this->show_macros(); } //----------------------------------------- // Show macros //----------------------------------------- function show_macros() { //----------------------------------------- if ($this->ipsclass->input['id'] == "") { $this->ipsclass->admin->error("You must specify an existing macro set ID, go back and try again"); } //----------------------------------------- // check tree... //----------------------------------------- $this_set = ""; if ( $this->ipsclass->input['p'] > 0 ) { $in = ','.$this->ipsclass->input['p']; } //----------------------------------------- // Get macros //----------------------------------------- $macros = $this->ipsclass->cache_func->_get_macros($this->ipsclass->input['id'], $this->ipsclass->input['p']); //----------------------------------------- // Get img_dir this set is using... //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'skin_sets', 'where' => "set_skin_set_id=".intval($this->ipsclass->input['id']) ) ); $this->ipsclass->DB->simple_exec(); $skin = $this->ipsclass->DB->fetch_row(); $this->ipsclass->admin->page_detail = "To edit a macro, simply click on the 'edit' link of the appropriate macro."; $this->ipsclass->admin->page_title = "Manage Replacement Macros in Set: {$skin['set_name']}"; //----------------------------------------- // Start output //----------------------------------------- $this->ipsclass->html .= "
Manage Replacement Macros ipsclass->input['id']}');\" />
"; $this->ipsclass->html .= "
\n
\n"; $this->unaltered = "- "; $this->altered = "+ "; $this->inherited = "| "; //----------------------------------------- // Loop and print //----------------------------------------- foreach( $macros as $row ) { $real = $this->ipsclass->txt_htmlspecialchars( $row['macro_replace'] ); $real = str_replace("\n", '\n', str_replace( "\r", '\r', $real) ); //----------------------------------------- // Altered? //----------------------------------------- if ( $row['macro_set'] == $this->ipsclass->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 = '"'; } if( $in_quote == '"' ) { $real = str_replace( """, '\"', $real ); } if( $in_quote == "'" ) { $real = str_replace( "'", "\\'", $real ); } $preview = str_replace( "<#IMG_DIR#>", $skin['set_image_dir'], $row['macro_replace'] ); if ( $row['macro_set'] > 1 and $row['macro_set'] == $this->ipsclass->input['id'] ) { $remove_button = "ipsclass->form_code_js}&code=macroremove&mid={$row['macro_id']}&id={$this->ipsclass->input['id']}&p={$this->ipsclass->input['p']}');\" />"; } else { $remove_button = ""; } //----------------------------------------- // Not an image? //----------------------------------------- if ( ! preg_match( "#img\s{1,}src=#i", $row['macro_replace'] ) ) { $preview = substr( $real, 0, 200 ); } else { $preview = preg_replace( "#style_images#", $this->ipsclass->vars['board_url'].'/style_images', $preview ); } $edit_button = ""; //----------------------------------------- // Render row //----------------------------------------- $style = "padding:4px;border-bottom:1px solid #DDD;background:{$css_info}"; $this->ipsclass->html .= " "; } $this->ipsclass->html .= "
$altered_image  <{{$row['macro_value']}}> $preview $remove_button $edit_button
ipsclass->input['id']}');\" />
"; $this->ipsclass->html .= $this->ipsclass->adskin->skin_jump_menu_wrap(); //----------------------------------------- // Show altered / unaltered // legend //----------------------------------------- $this->ipsclass->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.
"; $this->ipsclass->admin->nav[] = array( 'section='.$this->ipsclass->section_code.'&act=sets' ,'Skin Manager Home' ); $this->ipsclass->admin->nav[] = array( '' ,'Editing Replacement Macros in Set '.$skin['set_name'] ); $this->ipsclass->admin->output(); } } ?>