Skin -> Templates functions
| > Module written by Matt Mecham
| > Date started: 15th April 2002
|
| > Module Version Number: 1.0.0
+--------------------------------------------------------------------------
*/
$idx = new ad_settings();
class ad_settings {
var $base_url;
function ad_settings() {
global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
switch($IN['code'])
{
case 'add':
$this->add_splash();
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, $root_path, $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 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, $root_path, $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, $root_path, $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, $root_path, $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, $root_path, $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, $root_path, $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 .= "";
$ADMIN->html .= $SKIN->start_table("Template: ".$row['skname']);
while ( $group = $DB->fetch_row($all_cats) )
{
$name = "".$group['group_name']."";
$desc = "";
$expand = 'Expand to Edit';
$eid = $group['suid'];
$exp_content = "";
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 Board installation and no description is available";
}
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 | |||
| # Characters | Edit | Preview Options | |