Fix Skin Functions
| > Module written by Matt Mecham
| > Date started: 21st September 2003
|
| > 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();
}
class ad_skinfix {
var $base_url;
var $db_html_files = "";
var $ff_html_files = "";
var $skin_id = "";
var $ff_fixes = array();
var $log = array();
function auto_run()
{
global $ibforums, $DB, $std;
$ibforums->admin->page_detail = "This will allow you to update any old skins with the very latest skin files from the latest IPB release to ensure compatibility.
Simply download the latest skin lists from our master server to your install and then run these lists to compare and update any skins you have installed.";
$ibforums->admin->page_title = "Skin Version Control";
//-----------------------------------------
// 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 'importurl':
$this->import_ipb_file();
break;
case 'runtool':
$this->run_tool();
break;
case 'delete':
$this->delete_list();
break;
//-----------------------------------------
default:
$this->list_current();
break;
}
}
//-----------------------------------------
// Delete local list-y-poooos
//-----------------------------------------
function delete_list()
{
global $ibforums, $DB, $std;
if ( ! $ibforums->input['id'] )
{
$this->list_current("No ID passed, no deletion completed");
}
if ( @unlink( ROOT_PATH . 'cache/'. $ibforums->input['id'] ) )
{
$this->list_current("Cache file removed");
}
else
{
$this->list_current("Cache file could not be removed. Insufficient write permissions");
}
}
//-----------------------------------------
// RUN THE TOOL:UPDATE MINOR: Update all bug fixes, etc
//-----------------------------------------
function tool_update_updates()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Find missing template bits
//-----------------------------------------
$affected = array();
foreach( $this->ff_fixes as $skin_file => $data )
{
foreach( $this->ff_fixes[ $skin_file ] as $section => $desc )
{
if ( $desc['isnew'] == 1 )
{
//-----------------------------------------
// Check to see if it's still missing...
//-----------------------------------------
if ( $this->db_html_files[ $skin_file ][ $section ] )
{
//-----------------------------------------
// It's not, so fu.. continue
//-----------------------------------------
continue;
}
}
$data = $this->ff_html_files[ $skin_file ][ $section ][ 'func_data' ];
$content = $this->ff_html_files[ $skin_file ][ $section ][ 'section_content' ];
$this->_update_section($skin_file, $section, $data, $content);
$affected[$skin_file] = $skin_file;
}
}
if ( count($affected) < 1 )
{
$this->log[] = "Could not update the template files, no updates taken place";
}
else
{
foreach( $affected as $sk )
{
$this->_update_php_file($sk);
}
}
$this->write_log("Results of updating all bug fixed sections");
}
//-----------------------------------------
// RUN THE TOOL:UPDATE MAJOR: Update all missing templates
//-----------------------------------------
function tool_updatemajor()
{
global $ibforums, $DB, $std;
//-----------------------------------------
// Find missing template bits
//-----------------------------------------
$affected = array();
foreach( $this->ff_html_files as $skin_file => $data )
{
foreach( $this->ff_html_files[ $skin_file ] as $id => $ndata )
{
if ( ! $this->db_html_files[ $skin_file ][ $ndata['func_name'] ] )
{
$this->_update_section($skin_file, $ndata['func_name'], $ndata['func_data'], $ndata['section_content']);
$affected[$skin_file] = $skin_file;
}
}
}
if ( count($affected) < 1 )
{
$this->log[] = "Could not update the template files, no updates taken place";
}
else
{
foreach( $affected as $sk )
{
$this->_update_php_file($sk);
}
}
$this->write_log("Results of updating all missing sections");
}
//-----------------------------------------
// RUN THE TOOL:VIEW CODE, View the code changes
//-----------------------------------------
function tool_view_code()
{
global $ibforums, $DB, $std;
$code = $this->ff_html_files[ $ibforums->input['skinfile'] ][ $ibforums->input['func'] ]['section_content'];
if ( $code == "" )
{
$ibforums->admin->error("No code to show, please check the skin file, function name and skin ID");
}
$code = str_replace( "\n\n", "\n", str_replace( "\r", "\n", $code ) );
if ( $ibforums->input['type'] == 'php' )
{
$code = 'function '.$ibforums->input['func'].'('.$this->ff_html_files[ $ibforums->input['skinfile'] ][ $ibforums->input['func'] ]['func_data'].') {'."\rglobal \$ibforums;\r".'return <<convert_tags($code);
}
if ( phpversion() >= '4.2.0' )
{
@error_reporting(0);
$buffer = highlight_string( "", TRUE );
$buffer = preg_replace( "#(?:<|<)\?php\r?(.*)\r?\?(?:>|>)#s", "\\1", $buffer );
}
else
{
$buffer = htmlentities($code);
}
$ibforums->adskin->td_header[] = array( " ", "100%" );
$ibforums->html .= $ibforums->adskin->start_table( "{$ibforums->input['skinfile']} -> {$ibforums->input['func']}" );
$ibforums->html .= $ibforums->adskin->add_td_basic( "
".$buffer."
", "left");
$ibforums->html .= $ibforums->adskin->end_table();
$ibforums->admin->print_popup();
}
//-----------------------------------------
// RUN THE TOOL:COMPARE, Show changes - do nothing
//-----------------------------------------
function tool_compare()
{
global $ibforums, $DB, $std;
$ibforums->admin->page_detail .= "
Please note: Updating template bits WILL overwrite your current template bits completely. If you have a heavily modified skin you may wish to use manually
update the template bit to ensure that the changes integrate with your skin. If you have a heavily customized skin, export a copy first for safety.";
$ibforums->admin->page_detail .= "
There are $cnt missing sections, this could mean a very out of date template set and updating it may not be successful.";
}
$ibforums->adskin->td_header[] = array( "Skin Name" , "25%" );
$ibforums->adskin->td_header[] = array( "Function" , "30%" );
$ibforums->adskin->td_header[] = array( "Reason" , "20%" );
$ibforums->adskin->td_header[] = array( "View Code" , "25%" );
$ibforums->html .= $ibforums->adskin->start_table( "Missing sections in {$this->db_skin['skname']}" );
if ( count($changes) > 0 )
{
foreach( $changes as $skin_file => $data )
{
foreach( $changes[ $skin_file ] as $fun )
{
$ibforums->html .= $ibforums->adskin->add_td_row( array( "{$skin_file}",
$fun,
"Missing in local template",
"
"
) );
}
}
$ibforums->html .= $ibforums->adskin->add_td_basic( "input['list']}' class='fauxbutton'>Update New Release Changes", "center");
$ibforums->html .= $ibforums->adskin->end_table();
//-----------------------------------------
// PARSE IN UPDATE TIME
//-----------------------------------------
if ( count($look_up_func) > 0 )
{
$DB->query("SELECT updated, suid, group_name, func_name, section_content FROM ibf_skin_templates WHERE group_name IN('".implode( "','", $look_up_group )."') AND
func_name IN('".implode( "','", $look_up_func )."') AND set_id={$this->skin_id}");
while ( $r = $DB->fetch_row() )
{
$ibforums->html = str_replace( "", " Local version matches remote version?: ".$this->_is_it_or_isnt_it($r['section_content'], $this->ff_html_files[$r['group_name']][$r['func_name']]['section_content'])."", $ibforums->html );
$ibforums->html = str_replace( "", " Local version last updated: ".$std->get_date( $r['updated'], 'SHORT' )."", $ibforums->html );
}
}
$ibforums->admin->output();
}
//-----------------------------------------
// RUN THE TOOL
//-----------------------------------------
function run_tool()
{
global $ibforums, $DB, $std;
$tool = trim($ibforums->input['tool']);
$skin = intval(trim($ibforums->input['skin']));
$list = trim($ibforums->input['list']);
//-----------------------------------------
// GET DB STUFF
//-----------------------------------------
$DB->query("SELECT * FROM ibf_skin_templates WHERE set_id=$skin");
while ( $t = $DB->fetch_row() )
{
$this->db_html_files[ $t['group_name'] ][ $t['func_name'] ] = array( 'func_name' => $t['func_name'],
'func_data' => $t['func_data'],
'section_content' => $t['section_content']
);
}
$DB->query("SELECT * FROM ibf_tmpl_names WHERE skid=$skin");
$this->db_skin = $DB->fetch_row();
//-----------------------------------------
// LOAD CACHE FILE
//-----------------------------------------
$file = ROOT_PATH . 'cache/'.$list;
if ( ! file_exists( $file ) )
{
$ibforums->admin->error("Cannot find $list in the directory, 'cache'");
}
$fh = fopen( $file, 'r' );
$raw = @fread( $fh, filesize( $file ) );
@fclose($fh);
//-----------------------------------------
// GET FIRST LINE CONF
//-----------------------------------------
preg_match( "#(.+?)#is", $raw, $match );
$first_cut = explode( '|||', $match[1] );
foreach( $first_cut as $d )
{
list( $skin_file, $section_desc ) = explode( '&', $d );
list( $section, $desc2 ) = explode( '|~|', $section_desc );
list( $desc, $isnew ) = explode( '|^|', $desc2 );
$this->ff_fixes[ str_replace( '.php', '', $skin_file ) ][ $section ] = array( 'desc' => $desc, 'isnew' => $isnew );
}
//-----------------------------------------
// PARSE FLAT FILE
//-----------------------------------------
preg_match_all( "/(.+?)/s", $raw, $match );
for ($i=0; $i < count($match[0]); $i++)
{
$skin_file = trim($match[1][$i]);
$raw = trim($match[2][$i]);
//-----------------------------------------
// Remove everything up until the
// first \s*/", $line, $matches) )
{
$func = trim($matches[1]);
$data = trim($matches[2]);
if ($func != "")
{
$flag = $func;
$master[$func] = array( 'func_name' => $func,
'func_data' => $data,
'section_content' => ""
);
}
continue;
}
}
if ( preg_match("/\s*?\s*?/", $line) )
{
// We have found the end of the subbie..
// Reset the flag and feed the next line.
$flag = 0;
continue;
}
else
{
// Carry on feeding the HTML...
if ( isset($master[$flag]['section_content']) )
{
$master[$flag]['section_content'] .= $line."\n";
continue;
}
}
}
$this->ff_html_files[ $skin_file ] = $master;
}
$this->skin_id = $skin;
//-----------------------------------------
// Do summink
//-----------------------------------------
switch( $tool )
{
case 'updatemajor':
$this->tool_updatemajor();
break;
case 'updateall':
$this->tool_updateall();
break;
case 'updateupdates':
$this->tool_update_updates();
break;
case 'viewcode':
$this->tool_view_code();
break;
default:
$this->tool_compare();
break;
}
}
//-----------------------------------------
// IMPORT IPB PLIST FILE
//-----------------------------------------
function import_ipb_file()
{
global $ibforums, $DB, $std;
$file = preg_replace( "/[^a-zA-Z0-9\-\_\.]/", "" , str_replace( "..", "", $ibforums->input['id'] ) );
if ( ! preg_match( "/\.plist$/", $file ) )
{
$file = "";
}
if ( $file == "" )
{
$ibforums->admin->error("No file passed or the file contained illegal characters, unable to proceed.");
}
//-----------------------------------------
// Grab it you pervert!
//-----------------------------------------
$grab_meh_bits = "http://www.invisionboard.com/download/skinlist.php?dl=".$file;
$data = array();
$contents = "";
if ( ! $data = @file( $grab_meh_bits ) )
{
$ibforums->admin->error("There seems to be an error fetching the list from the Invision Power Board master server. This is either because the server is
unavailable or because your installation of PHP prohibits remote file reading.
Try going to our manual listing to download the files directly.");
}
if ( count($data) < 1 )
{
$ibforums->admin->error("There seems to be an error fetching the list from the Invision Power Board master server. This is either because the server is
unavailable or because your installation of PHP prohibits remote file reading.
Try going to our manual listing to download the files directly.");
}
$contents = implode( '', $data );
//-----------------------------------------
// Write it to the local directory
//-----------------------------------------
if ( $FH = fopen( ROOT_PATH . 'cache/' . $file, 'w' ) )
{
fwrite( $FH, $contents );
fclose( $FH );
}
@chmod( ROOT_PATH . 'cache/' . $file, 0777 );
//-----------------------------------------
// Pass back with thanks :D
//-----------------------------------------
$this->list_current( "
$file imported successfully");
}
//-----------------------------------------
// SHOW MAIN SCREEN
//-----------------------------------------
function list_current($msg="")
{
global $ibforums, $DB, $std;
$form_array = array();
//-----------------------------------------
// Get PLIST from invisionboard.com server
//-----------------------------------------
$file = 'http://www.invisionboard.com/download/skinlist.php';
$emsg = "
There seems to be an error fetching the list from the Invision Power Board master server. This is either because the server is
unavailable or because your installation of PHP prohibits remote file reading.
Try going to our manual listing to download the files directly.";
$err = 0;
$nocache = 0;
$data = array();
if ( $data = @file( $file ) )
{
if ( count($data) < 1 )
{
$err = 1;
}
else
{
$list = implode( '' , $data );
//-----------------------------------------
// Divide the file up into different sections
//-----------------------------------------
preg_match_all( "#(.+?)#is", $list, $match );
$master = array();
for ($i=0; $i < count($match[0]); $i++)
{
$main = trim($match[1][$i]);
preg_match( "#(.+?)#is", $main, $m2 );
$name = trim($m2[1]);
preg_match( "#(.+?)#is", $main, $m2 );
$updatefile = trim($m2[1]);
preg_match( "##is", $main, $m2 );
$time = trim($m2[1]);
$master[ $updatefile ] = array(
'name' => $name,
'updatefile' => $updatefile,
'time' => $time
);
}
if ( count( $master ) < 1 )
{
$err = 1;
}
}
}
else
{
$err = 1;
}
//-----------------------------------------
// Cache directory present and writeable?
//-----------------------------------------
if ( $err )
{
$msg .= $emsg;
}
if ( ! file_exists( ROOT_PATH . 'cache' ) )
{
$msg .= "
Cannot find ./cache. Make sure this directory exists in your root IPB directory.";
$nocache = 1;
}
if ( ! is_writeable( ROOT_PATH . 'cache' ) )
{
$msg .= "
Cannot write ./cache. To automatically download into this directory, please make sure IPB has suitable permissions via CHMOD.";
}
if ( $msg )
{
$ibforums->adskin->td_header[] = array( " " , "100%" );
$ibforums->html .= $ibforums->adskin->start_table( "Message" );
$ibforums->html .= $ibforums->adskin->add_td_row( array( "