$Date: 2007-06-29 15:38:25 -0400 (Fri, 29 Jun 2007) $ | > $Revision: 1078 $ | > $Author: bfarber $ +--------------------------------------------------------------------------- | | > Skin -> Templates functions | > Module written by Matt Mecham | > Date started: 15th April 2002 | | > Module Version Number: 1.0.0 | > DBA Checked: Tue 25th May 2004 +-------------------------------------------------------------------------- */ if ( ! defined( 'IN_ACP' ) ) { print "
";
$this->altered = "
";
$this->inherited = "
";
//-----------------------------------------
switch($this->ipsclass->input['code'])
{
case 'template-sections-list':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->template_sections_list();
break;
case 'template-bits-list':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->template_bits_list();
break;
case 'template-edit-bit-complete':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->template_edit_bit_complete();
break;
case 'template_remove_bit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );
$this->template_revert_bit();
break;
case 'template-edit-bit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->template_edit_bit();
break;
case 'floateditor':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );
$this->functions->build_editor_area_floated();
break;
case 'addbit':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->add_bit();
break;
case 'doadd':
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );
$this->do_add_bit();
break;
default:
$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );
$this->template_sections_list();
break;
}
}
//-----------------------------------------
// Show template bits for a group
//-----------------------------------------
function template_bits_list( $type='' )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$groups = array();
$group_bits = array();
$content = "";
$master_names = array();
$group_name = trim( $this->ipsclass->input['group_name'] );
$id = intval( $this->ipsclass->input['id'] );
$p = intval( $this->ipsclass->input['p'] );
$type = $type != '' ? $type : ( isset($this->ipsclass->input['type']) ? trim( $this->ipsclass->input['type'] ) : '' );
$linked_bits = array();
//-----------------------------------------
// Get $skin_names stuff
//-----------------------------------------
require_once( ROOT_PATH.'sources/lib/skin_info.php' );
//-----------------------------------------
// Get skin set
//-----------------------------------------
$this_set = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'skin_sets', 'where' => "set_skin_set_id=".$id ) );
//-----------------------------------------
// Check
//-----------------------------------------
if ( ! $id )
{
$this->ipsclass->admin->error("You must specify an existing template set ID, go back and try again");
}
//-----------------------------------------
// Parent?
//-----------------------------------------
if ( ! $p )
{
if ( $this_set['set_skin_set_parent'] )
{
$p = $this_set['set_skin_set_parent'];
}
}
if ( $p > 0 )
{
$in = ','.$p;
}
//-----------------------------------------
// Get template bits master names..
//-----------------------------------------
$this->ipsclass->DB->simple_construct( array( 'select' => 'func_name', 'from' => 'skin_templates', 'where' => "group_name='{$group_name}' AND set_id=1" ) );
$this->ipsclass->DB->simple_exec();
//-----------------------------------------
// Compile...
//-----------------------------------------
while ( $m = $this->ipsclass->DB->fetch_row() )
{
$master_names[ $m['func_name'] ] = $m['func_name'];
}
$group['easy_name'] = $skin_names[ $group_name ][0];
$group['group_name'] = $group_name;
//-----------------------------------------
// Get linked bits
//-----------------------------------------
$this->ipsclass->DB->build_query( array( 'select' => '*',
'from' => 'skin_template_links',
'where' => "link_set_id IN( 1, " . $id . ") AND link_used_in='". $group_name ."'" ) );
$this->ipsclass->DB->exec_query();
while( $row = $this->ipsclass->DB->fetch_row() )
{
$linked_bits[ $row['link_template_name'] ] = $row['link_template_name'];
}
//-----------------------------------------
// Get group bits
//-----------------------------------------
$group_bits = $this->ipsclass->cache_func->_get_templates($id, $p, 'groups', $group_name );
$add_button = "";
//-----------------------------------------
// Add to HTML
//-----------------------------------------
$temp = "";
$sec_arry = array();
//-----------------------------------------
// Stuff array to sort on name
//-----------------------------------------
foreach( $group_bits as $i )
{
//-----------------------------------------
// Linked bit?
//-----------------------------------------
if ( in_array( $i['func_name'], $linked_bits ) )
{
continue;
}
$sec_arry[ $i['suid'] ] = $i;
$sec_arry[ $i['suid'] ]['easy_name'] = $i['func_name'];
}
//-----------------------------------------
// Sort by easy_name
//-----------------------------------------
usort($sec_arry, array( 'ad_skin_template_bits', 'perly_alpha_sort' ) );
//-----------------------------------------
// Loop and print main display
//-----------------------------------------
foreach( $sec_arry as $sec )
{
$custom_bit = "";
$sec['_p'] = intval( $p );
$sec['_id'] = intval( $this->ipsclass->input['id'] );
//-----------------------------------------
// Altered?
//-----------------------------------------
if ( $sec['set_id'] == $id )
{
$altered_image = $this->html->template_bits_bit_row_image( $sec['suid'], 'skin_item_altered.gif' );
}
else if ( $sec['set_id'] == 1 )
{
$altered_image = $this->html->template_bits_bit_row_image( $sec['suid'], 'skin_item_unaltered.gif' );
}
else
{
$altered_image = $this->html->template_bits_bit_row_image( $sec['suid'], 'skin_item_inherited.gif' );
}
$remove_button = "ipsclass->base_url}&{$this->ipsclass->form_code}&code=template_remove_bit&bitname={$sec['func_name']}&id={$this->ipsclass->input['id']}&p={$this->ipsclass->input['p']}&group_name={$sec['group_name']}&type=frame')\">
";
}
}
$content .= $this->html->template_bits_bit_row( $sec, $custom_bit, $remove_button, $altered_image );
}
//-----------------------------------------
// Just showing the XML?
//-----------------------------------------
if ( $type == 'xml' )
{
@header("Content-Type: text/plain");
print $content;
exit();
}
else
{
$this->ipsclass->html = $this->html->template_bits_bit_overview( $group, $content, $add_button );
$this->ipsclass->admin->print_popup();
}
}
//-----------------------------------------
// Show template groups/categories
//-----------------------------------------
function template_sections_list()
{
//-----------------------------------------
// INIT
//-----------------------------------------
$groups = array();
$group_bits = array();
$content = "";
$javascript = '';
$js_groups = '';
$js_bits = '';
$js_matches = '';
$this->ipsclass->input['id'] = intval( $this->ipsclass->input['id'] );
$this->ipsclass->input['p'] = intval( $this->ipsclass->input['p'] );
//-----------------------------------------
// Get $skin_names stuff
//-----------------------------------------
require_once( ROOT_PATH.'sources/lib/skin_info.php' );
//-----------------------------------------
// Get skin set
//-----------------------------------------
$this_set = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'skin_sets', 'where' => "set_skin_set_id=".$this->ipsclass->input['id'] ) );
//-----------------------------------------
// Check
//-----------------------------------------
if ( $this->ipsclass->input['id'] == "")
{
$this->ipsclass->admin->error("You must specify an existing template set ID, go back and try again");
}
//-----------------------------------------
// Parent?
//-----------------------------------------
if ( ! $this->ipsclass->input['p'] )
{
if ( $this_set['set_skin_set_parent'] )
{
$this->ipsclass->input['p'] = $this_set['set_skin_set_parent'];
}
}
if ( $this->ipsclass->input['p'] > 0 )
{
$in = ','.$this->ipsclass->input['p'];
}
$this->ipsclass->admin->page_detail = "Please choose which section you wish to edit below.";
$this->ipsclass->admin->page_title = "Edit Template sets";
//-----------------------------------------
// Generate inline JS
//-----------------------------------------
if ( is_array( $this->search_bits ) and count( $this->search_bits ) )
{
foreach( $this->search_bits as $group => $idx )
{
$js_matches .= "\t'$group' : ". count( $this->search_bits[ $group ] ).",\n";
$js_groups .= "\t'$group' : 1,\n";
foreach( $this->search_bits[ $group ] as $data )
{
$js_bits .= "\t'{$group}_{$data['func_name']}' : 1,\n";
}
}
//-----------------------------------------
// Trim off trailing commas
//-----------------------------------------
$js_matches = preg_replace( "#,\n?$#", "", $js_matches );
$js_groups = preg_replace( "#,\n?$#", "", $js_groups );
$js_bits = preg_replace( "#,\n?$#", "", $js_bits );
$javascript = "var template_search = 1;\n".
"var search_template_sections = {\n". $js_groups ."\n};\n".
"var search_template_bits = {\n" . $js_bits ."\n};\n".
"var search_template_matches = {\n" . $js_matches."\n};\n";
}
else
{
$javascript = "var template_search = 0;\nvar search_template_sections = {};\nvar search_template_bits = {};\nvar search_template_matches = {};\n";
}
//-----------------------------------------
// Get the groups...
//-----------------------------------------
$group_titles = $this->ipsclass->cache_func->_get_templates($this->ipsclass->input['id'], $this->ipsclass->input['p'], 'groups');
foreach( $group_titles as $g )
{
//-----------------------------------------
// Fix up names
//-----------------------------------------
$g['easy_name'] = "".$g['group_name']."";
$g['easy_desc'] = "";
//-----------------------------------------
// If available, change group name to easy name
//-----------------------------------------
if ( isset($skin_names[ $g['group_name'] ]) )
{
$g['easy_name'] = "".$skin_names[ $g['group_name'] ][0]."";
$g['easy_desc'] = str_replace( '"', '"', $skin_names[ $g['group_name'] ][1] );
}
else
{
$g['easy_name'] = "".$g['group_name']." (Non-Default Group)";
$g['easy_desc'] = "This group is not part of the standard Invision Power Board installation and no description is available";
}
if ( isset($skin_names[ $g['group_name'] ][2]) )
{
$g['easy_preview'] = "ipsclass->vars['php_ext']}?{$skin_names[ $g['group_name'] ][2]}' target='_blank'>
";
}
else
{
$g['easy_preview'] = "
";
}
$groups[] = $g;
}
//-----------------------------------------
// Sort by easy_name
//-----------------------------------------
usort($groups, array( 'ad_skin_template_bits', 'perly_alpha_sort' ) );
//-----------------------------------------
// Loop and print
//-----------------------------------------
foreach( $groups as $group )
{
$eid = $group['suid'];
$exp_content = "";
$this->ipsclass->cache_func->template_count[$this->ipsclass->input['p']][ $group['group_name'] ]['count'] =
isset($this->ipsclass->cache_func->template_count[$this->ipsclass->input['p']][ $group['group_name'] ]['count']) ?
$this->ipsclass->cache_func->template_count[$this->ipsclass->input['p']][ $group['group_name'] ]['count'] : 0;
$this->ipsclass->cache_func->template_count[$this->ipsclass->input['id']][ $group['group_name'] ]['count'] =
isset($this->ipsclass->cache_func->template_count[$this->ipsclass->input['id']][ $group['group_name'] ]['count']) ?
$this->ipsclass->cache_func->template_count[$this->ipsclass->input['id']][ $group['group_name'] ]['count'] : 0;
$altered = sprintf( '%02d', intval($this->ipsclass->cache_func->template_count[$this->ipsclass->input['id']][ $group['group_name'] ]['count']) );
$original = sprintf( '%02d', intval($this->ipsclass->cache_func->template_count[1][ $group['group_name'] ]['count']) );
$inherited = sprintf( '%02d', intval($this->ipsclass->cache_func->template_count[$this->ipsclass->input['p']][ $group['group_name'] ]['count']) );
$count_string = "";
if ( $this->ipsclass->input['p'] > 0 )
{
$count_string = "$original {$this->unaltered} $inherited {$this->inherited} $altered {$this->altered}";
}
else
{
$count_string = "$original {$this->unaltered} $altered {$this->altered}";
}
//-----------------------------------------
// Folder blob
//-----------------------------------------
if ( $altered > 0 )
{
$folder_blob = $this->altered;
}
else if ( $this->ipsclass->input['p'] > 0 and $inherited > 0 )
{
$folder_blob = $this->inherited;
}
else
{
$folder_blob = $this->unaltered;
}
$group['_p'] = intval( $this->ipsclass->input['p'] );
$group['_id'] = intval( $this->ipsclass->input['id'] );
//-----------------------------------------
// Print normal rows
//-----------------------------------------
$content .= $this->html->template_bits_overview_row_normal( $group, $folder_blob, $count_string );
}
$this->ipsclass->html .= $this->html->template_bits_overview( $content, $javascript );
$this->ipsclass->html .= $this->ipsclass->adskin->skin_jump_menu_wrap();
$this->ipsclass->admin->nav[] = array( 'section='.$this->ipsclass->section_code.'&act=sets' ,'Skin Manager Home' );
$this->ipsclass->admin->nav[] = array( '' ,'Managing Template Set "'.$this_set['set_name'].'"' );
$this->ipsclass->admin->output();
}
//-----------------------------------------
// Sneaky sorting.
// We use the format "1: name". without this hack
// 1: name, 2: other name, 11: other name
// will sort as 1: name, 11: other name, 2: other name
// There is natsort and such in PHP, but it causes some
// problems on older PHP installs, this is hackish but works
// by simply adding '0' to a number less than 2 characters long.
// of course, this won't work with three numerics in the hundreds
// but we don't have to worry about more that 99 bits in a template
// at this stage.
//-----------------------------------------
function perly_word_sort($a, $b)
{
$nat_a = intval( $a['easy_name'] );
$nat_b = intval( $b['easy_name'] );
if (strlen($nat_a) < 2)
{
$nat_a = '0'.$nat_a;
}
if (strlen($nat_b) < 2)
{
$nat_b = '0'.$nat_b;
}
return strcmp($nat_a, $nat_b);
}
//-----------------------------------------
// Sort by group name
//-----------------------------------------
function perly_alpha_sort($a, $b)
{
return strcmp( strtolower($a['easy_name']), strtolower($b['easy_name']) );
}
//-----------------------------------------
// ADD TEMPLATE BIT
//-----------------------------------------
function add_bit()
{
$this->ipsclass->admin->page_detail = "You may add a template bit using this section.";
$this->ipsclass->admin->page_title = "Template Editing";
$groupname = $this->ipsclass->input['expand'];
$this_set = $this->ipsclass->DB->simple_exec_query( array( 'select' => '*', 'from' => 'skin_sets', 'where' => "set_skin_set_id=".intval($this->ipsclass->input['id']) ) );
//-----------------------------------------
// Sort out group titles
//-----------------------------------------
$group_titles = $this->ipsclass->cache_func->_get_templates( $this->ipsclass->input['id'], $this->ipsclass->input['p'], 'groups' );
$formatted_groups = array();
foreach ( $group_titles as $d )
{
$formatted_groups[] = array( $d['group_name'], $d['group_name'] );
}
//-----------------------------------------
// Good form old boy
//-----------------------------------------
$this->ipsclass->html .= $this->ipsclass->adskin->start_form( array( 1 => array( 'code' , 'doadd' ),
2 => array( 'act' , 'templ' ),
3 => array( 'id' , $this->ipsclass->input['id'] ),
4 => array( 'p' , $this->ipsclass->input['p'] ),
5 => array( 'expand', $this->ipsclass->input['expand'] ),
6 => array( 'section', $this->ipsclass->section_code ),
) , "theform" );
//-----------------------------------------
// Editor prefs strip
//-----------------------------------------
$options .= "| New Template Bit Name Alphanumerics and underscores only, no spaces. |
".$this->ipsclass->adskin->form_input('func_name', $this->ipsclass->txt_stripslashes($_POST['func_name']))." |
| New Template Bit Incoming Data Variables Define the variables passed to this template bit. |
".$this->ipsclass->adskin->form_input('func_data', str_replace( "'", ''', $this->ipsclass->txt_stripslashes($_POST['func_data']) ) )." |
| New Template Bit Group... | ".$this->ipsclass->adskin->form_dropdown('group_name', $formatted_groups, $this->ipsclass->input['group_name'] ? $this->ipsclass->input['group_name'] : $this->ipsclass->input['expand'] )." |
| Or Create New Group... Leave empty to use above group. Alphanumerics and underscores only, no spaces |
skin_".$this->ipsclass->adskin->form_input('new_group_name', $this->ipsclass->txt_stripslashes($_POST['new_group_name']))." |