Skin -> Templates functions | > Module written by Matt Mecham | > Date started: 15th April 2002 | | > Module Version Number: 1.0.0 +-------------------------------------------------------------------------- */ 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(); } $idx = new ad_settings(); class ad_settings { var $base_url; function ad_settings() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP; //--------------------------------------- // Kill globals - globals bad, Homer good. //--------------------------------------- $tmp_in = array_merge( $_GET, $_POST, $_COOKIE ); foreach ( $tmp_in as $k => $v ) { unset($$k); } //--------------------------------------- switch($IN['code']) { case 'add': $this->add_splash(); break; case 'find_pop': $this->find_popular(); break; case 'edit': $this->show_cats(); break; case 'dedit': $this->do_form(); break; case 'doedit': $this->do_edit(); break; case 'remove': $this->remove(); break; case 'tools': $this->tools(); break; case 'editinfo': $this->edit_info(); break; case 'export': $this->export(); break; case 'edit_bit': $this->edit_bit(); break; case 'download': $this->download_group(); break; case 'upload': $this->upload_form(); break; case 'do_upload': $this->upload_single(); break; //------------------------- default: $this->list_current(); break; } } //------------------------------------------------------ function add_splash() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_FILES; $FILE_NAME = $HTTP_POST_FILES['FILE_UPLOAD']['name']; $FILE_SIZE = $HTTP_POST_FILES['FILE_UPLOAD']['size']; $FILE_TYPE = $HTTP_POST_FILES['FILE_UPLOAD']['type']; // Naughty Opera adds the filename on the end of the // mime type - we don't want this. $FILE_TYPE = preg_replace( "/^(.+?);.*$/", "\\1", $FILE_TYPE ); // Naughty Mozilla likes to use "none" to indicate an empty upload field. // I love universal languages that aren't universal. if ($HTTP_POST_FILES['FILE_UPLOAD']['name'] == "" or !$HTTP_POST_FILES['FILE_UPLOAD']['name'] or ($HTTP_POST_FILES['FILE_UPLOAD']['name'] == "none") ) { // We're adding new templates based on another set $this->add_templates(); exit(); } if (! is_dir($INFO['upload_dir']) ) { $ADMIN->error("Could not locate the uploads directory - make sure the 'uploads' path is set correctly"); } //------------------------------------------------- // Copy the upload to the uploads directory //------------------------------------------------- if (! @move_uploaded_file( $HTTP_POST_FILES['FILE_UPLOAD']['tmp_name'], $INFO['upload_dir']."/".$FILE_NAME) ) { $ADMIN->error("The upload failed"); } else { @chmod( $INFO['upload_dir']."/".$FILE_NAME, 0777 ); } //------------------------------------------------- // Attempt to open the file.. //------------------------------------------------- $filename = $INFO['upload_dir']."/".$FILE_NAME; if ( $FH = @fopen( $filename, 'r' ) ) { $data = @fread( $FH, filesize($filename) ); @fclose($FH); @unlink($filename); } else { $ADMIN->error("Could not open the uploaded file for reading!"); } //------------------------------------------------- // If we're here, we'll assume that we've read the // file and the contents are in $data // So, lets make sure its the correct template file.. //------------------------------------------------- if ( ! preg_match( "//", $data, $matches ) ) { $ADMIN->error("This file does not appear to be a valid Invision Power Board Template Set file"); } list($pack_name,$author,$email,$url) = explode( ",", trim($matches[1]) ); //------------------------------------------------- // Find the new set ID by inserting the data for the // template names, we can always remove it later if // we get an error //------------------------------------------------- $pack_name .= "(Upload ID: ".substr( time(), -6 ).")"; $pack_name = str_replace( "'", "", $pack_name ); $author = str_replace( "'", "", $author ); $email = str_replace( "'", "", $email ); $url = str_replace( "'", "", $url ); $DB->query("INSERT INTO ibf_tmpl_names (skname, author, email, url) VALUES('$pack_name', '$author', '$email', '$url')"); $setid = $DB->get_insert_id(); //------------------------------------------------- // Divide the file up into different sections //------------------------------------------------- preg_match_all( "/(.+?)/s", $data, $match ); for ($i=0; $i < count($match[0]); $i++) { $match[1][$i] = trim($match[1][$i]); $match[2][$i] = trim($match[2][$i]); // Pass it on to our handler.. $this->process_upload($match[2][$i], $setid, $match[1][$i], 1 ); } // Insert this new data into the template names thingy $ADMIN->done_screen("Template set import complete", "Manage Template Sets", "act=templ" ); } //------------------------------------------------------ function upload_single() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_FILES; $FILE_NAME = $HTTP_POST_FILES['FILE_UPLOAD']['name']; $FILE_SIZE = $HTTP_POST_FILES['FILE_UPLOAD']['size']; $FILE_TYPE = $HTTP_POST_FILES['FILE_UPLOAD']['type']; // Naughty Opera adds the filename on the end of the // mime type - we don't want this. $FILE_TYPE = preg_replace( "/^(.+?);.*$/", "\\1", $FILE_TYPE ); if (! is_dir($INFO['upload_dir']) ) { $ADMIN->error("Could not locate the uploads directory - make sure the 'uploads' path is set correctly"); } // Naughty Mozilla likes to use "none" to indicate an empty upload field. // I love universal languages that aren't universal. if ($HTTP_POST_FILES['FILE_UPLOAD']['name'] == "" or !$HTTP_POST_FILES['FILE_UPLOAD']['name'] or ($HTTP_POST_FILES['FILE_UPLOAD']['name'] == "none") ) { $ADMIN->error("No file was chosen to upload!"); } //------------------------------------------------- // Copy the upload to the uploads directory //------------------------------------------------- if (! @move_uploaded_file( $HTTP_POST_FILES['FILE_UPLOAD']['tmp_name'], $INFO['upload_dir']."/".$FILE_NAME) ) { $ADMIN->error("The upload failed"); } else { @chmod( $INFO['upload_dir']."/".$FILE_NAME, 0777 ); } //------------------------------------------------- // Attempt to open the file.. //------------------------------------------------- $filename = $INFO['upload_dir']."/".$FILE_NAME; if ( $FH = @fopen( $filename, 'r' ) ) { $data = @fread( $FH, filesize($filename) ); @fclose($FH); @unlink($filename); } else { $ADMIN->error("Could not open the uploaded file for reading!"); } //------------------------------------------------- // If we're here, we'll assume that we've read the // file and the contents are in $data // So, lets make sure its the correct template file.. //------------------------------------------------- preg_match( "//", $data, $matches ); $found_group = trim($matches[1]); if ($found_group != $IN['group']) { $ADMIN->error("The uploaded file does not appear to be the correct type for this template group. Looking for template group '{$IN['group']}', found '$found_group'"); } //------------------------------------------------- // If we're here, then lets proceed, first lets // remove the END GROUP statement. //------------------------------------------------- $data = preg_replace( "//", "", $data ); // Pass it on to our handler.. $this->process_upload($data, $IN['setid'], $IN['group'] ); $ADMIN->done_screen("Template set update complete", "Manage Template Sets", "act=templ" ); } //------------------------------------------------------ function upload_form() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP; require './sources/Admin/skin_info.php'; if ($IN['setid'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } if ($IN['group'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } //----------------------------------- // Get the info from the DB //----------------------------------- $DB->query("SELECT * FROM ibf_skin_templates WHERE set_id='".$IN['setid']."' AND group_name='".$IN['group']."'"); if ( ! $DB->get_num_rows() ) { $ADMIN->error("Can't query the information from the database"); } $DB->query("SELECT skname FROM ibf_tmpl_names WHERE skid='".$IN['setid']."'"); $row = $DB->fetch_row(); //+------------------------------- $ADMIN->page_detail = "Please check all the information carefully before continuing."; $ADMIN->page_title = "Upload a template file for template set: {$row['skname']}"; //+------------------------------- $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code' , 'do_upload' ), 2 => array( 'act' , 'templ' ), 3 => array( 'MAX_FILE_SIZE', '10000000000' ), 4 => array( 'setid' , $IN['setid'] ), 5 => array( 'group' , $IN['group'] ), ) , "uploadform", " enctype='multipart/form-data'" ); $SKIN->td_header[] = array( " " , "40%" ); $SKIN->td_header[] = array( " " , "60%" ); $ADMIN->html .= $SKIN->start_table("Upload template file to replace: ".$skin_names[ $IN['group'] ][0]); $ADMIN->html .= $SKIN->add_td_row( array( "Choose a file from your computer to upload
Note: Uploading this file will replace all data currently held, there is no undo!.", $SKIN->form_upload(), ) ); $ADMIN->html .= $SKIN->end_form('Upload File'); $ADMIN->html .= $SKIN->end_table(); $ADMIN->nav[] = array( 'act=templ' ,'Template Control Home' ); $ADMIN->nav[] = array( "act=templ&code=edit&id={$IN['setid']}" ,$row['skname'] ); $ADMIN->output(); } //------------------------------------------------------ function export() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP; if ($IN['id'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } $DB->query("SELECT * FROM ibf_tmpl_names WHERE skid='".$IN['id']."'"); if ( ! $set = $DB->fetch_row() ) { $ADMIN->error("Could not find a template set with that ID in the database, please try again"); } //----------------------------------- // Get the info from the DB //----------------------------------- $groups = $DB->query("SELECT DISTINCT(group_name) FROM ibf_skin_templates WHERE set_id='".$IN['id']."'"); if ( ! $DB->get_num_rows($groups) ) { $ADMIN->error("Can't query the information from the database"); } // Loop and pass it to the download compiler $author = str_replace( ",", "-", $set['author'] ); $email = str_replace( ",", "-", $set['email'] ); $url = str_replace( ",", "-", $set['url'] ); $skname = str_replace( ",", "-", $set['skname'] ); $output .= "\n\n"; while ( $row = $DB->fetch_row($groups) ) { $output .= $this->download_group(1, $IN['id'], $row['group_name'] ); } $name = str_replace( " ", "_", $set['skname'] ); @header("Content-type: unknown/unknown"); @header("Content-Disposition: attachment; filename={$name}.SET.html"); print $output; exit(); } //------------------------------------------------------ //------------------------------------------------------ function download_group($return=0, $setid="", $group="") { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP; if ($setid != "") { $IN['setid'] = $setid; } if ($group != "") { $IN['group'] = $group; } if ($IN['setid'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } if ($IN['group'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } //----------------------------------- // Get the info from the DB //----------------------------------- $aq = $DB->query("SELECT * FROM ibf_skin_templates WHERE set_id='".$IN['setid']."' AND group_name='".$IN['group']."'"); if ( ! $DB->get_num_rows($aq) ) { $ADMIN->error("Can't query the information from the database"); } $output = "\n\n\n"; while ( $row = $DB->fetch_row($aq) ) { $text = $this->convert_tags($row['section_content']); $output .= "\n\n"; $output .= $text."\n"; $output .= "\n\n"; } $output .= "\n\n"; if ($return == 0) { $DB->query("SELECT skname FROM ibf_tmpl_names WHERE skid='".$IN['setid']."'"); $set = $DB->fetch_row(); $name = str_replace( " ", "_", $set['skname'] ); @header("Content-type: unknown/unknown"); @header("Content-Disposition: attachment; filename={$name}.{$IN['group']}.html"); print $output; exit(); } else { return $output; } } //------------------------------------------------------ function show_cats() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP; if ($IN['id'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } //+------------------------------- $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'"); if ( ! $row = $DB->fetch_row() ) { $ADMIN->error("Could not query the information from the database"); } // Get $skin_names stuff require './sources/Admin/skin_info.php'; if ($row['author'] and $row['email']) { $author = "

This template set '{$row['skname']}' was created by {$row['author']}"; } else if ($row['author']) { $author = "

This template set '{$row['skname']}' was created by {$row['author']}"; } if ($row['url']) { $url = " (website: {$row['url']})"; } //+------------------------------- $ADMIN->page_detail = "Please choose which section you wish to edit below.

Download this HTML section This option allows you to download all of the HTML for this template section for offline editing.
Upload HTML for this section This option allows you to upload a saved HTML file to replace this template section.$author $url"; $ADMIN->page_title = "Edit Template sets"; //+------------------------------- $ADMIN->html .= $SKIN->js_checkdelete(); $all_cats = $DB->query("select group_name, set_id, suid, count(group_name) as number_secs, group_name FROM ibf_skin_templates WHERE set_id='".$IN['id']."' group by group_name"); $SKIN->td_header[] = array( "Skin Category Title" , "40%" ); $SKIN->td_header[] = array( "View Options" , "20%" ); $SKIN->td_header[] = array( "Manage" , "30%" ); $SKIN->td_header[] = array( "# Bits" , "10%" ); //+------------------------------- $ADMIN->html .= ""; $qc = $SKIN->form_dropdown( 'entry', array( 0 => array( 'boardheader', 'Edit Board Header' ), 1 => array( 'catforum' , 'Edit Category & Forum Table' ), 2 => array( 'topiclist' , 'Edit Topic List Entry & Table' ), 3 => array( 'postlist' , 'Edit Post View & Table' ), ) ); $quick_click = "
Quick Clicks  {$qc} 
"; $ADMIN->html .= $SKIN->start_table("Template: ".$row['skname'], $quick_click); while ( $group = $DB->fetch_row($all_cats) ) { $name = "".$group['group_name'].""; $desc = ""; $expand = 'Expand to Edit'; $eid = $group['suid']; $exp_content = ""; // If available, change group name to easy name if ( isset($skin_names[ $group['group_name'] ]) ) { $name = "".$skin_names[ $group['group_name'] ][0].""; $desc = "
".$skin_names[ $group['group_name'] ][1].""; } else { $name .= " (Non-Default Group)"; $desc = "
This group is not part of the standard Invision Power Board installation and no description is available"; } // Is this section expanded? if ($IN['expand'] == $group['suid']) { $expand = 'Collapse'; $eid = ''; $new_q = $DB->query("SELECT func_name, LENGTH(section_content) as sec_length, suid FROM ibf_skin_templates WHERE set_id='{$IN['id']}' AND group_name='{$group['group_name']}'"); //---------------------------- if ( $DB->get_num_rows($new_q) ) { $exp_content .= $SKIN->add_td_basic( "
$name  
Edit all the sections below # Characters Edit Preview Options
", "left", "tdrow2" ); $temp = ""; $sec_arry = array(); // Stuff array to sort on name while ( $i = $DB->fetch_row($new_q) ) { $sec_arry[ $i['suid'] ] = $i; $sec_arry[ $i['suid'] ]['easy_name'] = $i['func_name']; // If easy name is available, use it if ($bit_names[ $group['group_name'] ][ $i['func_name'] ] != "") { $sec_arry[ $i['suid'] ]['easy_name'] = $bit_names[ $group['group_name'] ][ $i['func_name'] ]; } } // Sort by easy_name usort($sec_arry, array( 'ad_settings', 'perly_word_sort' ) ); // Loop and print foreach( $sec_arry as $id => $sec ) { $sec['easy_name'] = preg_replace( "/^(\d+)\:\s+?/", "", $sec['easy_name'] ); $temp .= " {$sec['easy_name']} {$sec['sec_length']}
Edit Single (HTML | Text | With CSS) "; } $exp_content = str_replace( "", $temp, $exp_content ); $desc = ""; } //---------------------------- } else { $ADMIN->html .= $SKIN->add_td_row( array( "".$name."".$desc, "
$expand
", "
Download | Upload
", "
".$group['number_secs']."
", ) ); } $ADMIN->html .= $exp_content; } $ADMIN->html .= $SKIN->end_table(); //+------------------------------- //+------------------------------- $ADMIN->nav[] = array( 'act=templ' ,'Template Control Home' ); $ADMIN->nav[] = array( '' ,'Managing Template Set "'.$row['skname'].'"' ); $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); } //+-------------------------------------------------------------------------------- //+-------------------------------------------------------------------------------- function edit_info() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS; if ($IN['id'] == "") { $ADMIN->error("You must specify an existing template set ID, go back and try again"); } //+------------------------------- $DB->query("SELECT * from ibf_tmpl_names WHERE skid='".$IN['id']."'"); if ( ! $row = $DB->fetch_row() ) { $ADMIN->error("Could not query the information from the database"); } $final['skname'] = stripslashes($HTTP_POST_VARS['skname']); if (isset($HTTP_POST_VARS['author'])) { $final['author'] = str_replace( ",", "", stripslashes($HTTP_POST_VARS['author']) ); $final['email'] = str_replace( ",", "", stripslashes($HTTP_POST_VARS['email']) ); $final['url'] = str_replace( ",", "", stripslashes($HTTP_POST_VARS['url']) ); } $db_string = $DB->compile_db_update_string( $final ); $DB->query("UPDATE ibf_tmpl_names SET $db_string WHERE skid='".$IN['id']."'"); $ADMIN->done_screen("Template information updated", "Manage Template sets", "act=templ" ); } //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ function tools() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS; if ($IN['id'] == "") { $ADMIN->error("You must choose a valid skin file to perform this operation on"); } if ($IN['tool'] == 'tmpl') { $this->tools_build_tmpl(); } else { $this->tools_rebuildphp(); } } //------------------------------------------------------------------------------------ function tools_build_tmpl() { global $IN, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS; $insert = 1; // Rebuilds the data editable files from the PHP source files $skin_dir = ROOT_PATH."Skin/s".$IN['id']; /*$curr_groups = array(); // Are we updating or inserting? $DB->query("SELECT group_name, func_name FROM ibf_skin_templates WHERE set_id='".$IN['id']."'"); if ( $DB->get_num_rows() ) { $insert = 0; while ( $gname = $DB->fetch_row() ) { $curr_group[ $gname['group_name'] ][ $gname['func_name'] ] = 1; } }*/ $errors = array(); $flag = 0; //------------------------------------------------ // Is this a safe mode only skinny poos? //------------------------------------------------ if ( ! file_exists( $skin_dir ) ) { $ADMIN->error("This template set is a safe mode only skin and no PHP skin files exist, there is no need to run this tool on this template set."); } if ( ! is_readable($skin_dir) ) { $ADMIN->error("Cannot write into '$skin_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you."); } if ( is_dir($skin_dir) ) { if ( $handle = opendir($skin_dir) ) { while (($filename = readdir($handle)) !== false) { if (($filename != ".") && ($filename != "..")) { if ( preg_match( "/\.php$/", $filename ) ) { $name = preg_replace( "/^(\S+)\.(\S+)$/", "\\1", $filename ); if ($FH = fopen($skin_dir."/".$filename, 'r') ) { $fdata = fread( $FH, filesize($skin_dir."/".$filename) ); fclose($FH); } else { $errors[] = "Could not open $filename for reading, skipping file..."; continue; } $fdata = str_replace( "\r", "\n", $fdata ); $fdata = str_replace( "\n\n", "\n", $fdata ); if ( ! preg_match( "/\n/", $fdata ) ) { $errors[] = "Could not find any line endings in $filename, skipping file..."; continue; } $farray = explode( "\n", $fdata ); //---------------------------------------------------- $functions = array(); foreach($farray as $f) { // Skip javascript functions... if ( preg_match( "/