0)
{
$module[$module_name][$lang['xs_config_shownav'][$i]] = 'xs_frameset.'.$phpEx.'?action=' . $xs_shownav_action[$i];
}
}
// add menu for style configuration
foreach($board_config as $var => $value)
{
if(substr($var, 0, 9) === 'xs_style_')
{
$str = substr($var, 9);
$module['Template_Config'][$str] = 'xs_frameset.'.$phpEx.'?action=style_config&tpl='.urlencode($str);
}
}
}
if(!empty($setmodules))
{
if(@function_exists('jr_admin_get_module_list'))
{
$tmp_mod = $module;
global $module;
$module = $tmp_mod;
xs_admin_override(true);
}
return;
}
//
// Global defines for eXtreme Styles mod administration panel
//
define('STYLE_HEADER_START', 'xs_style_01');
define('STYLE_HEADER_END', '');
define('STYLE_HEADER_VERSION', '1');
define('STYLE_EXTENSION', '.style');
define('TAR_HEADER_PACK', 'a100A8A8A8A12A12A8A1A100A6A2A32A32A8A8a155a12');
define('TAR_HEADER_UNPACK', 'a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix/a12extra');
define('XS_MAX_ITEMS_PER_STYLE', 32);
define('XS_TEMP_DIR', '../cache/');
define('XS_FTP_LOCAL', 'no_ftp');
define('XS_UPDATE_STYLE', 1);
define('XS_UPDATE_MOD', 2);
define('XS_UPDATE_PHPBB', 3);
define('XS_TPL_PATH', '../../xs_mod/tpl/');
define('XS_BACKUP_PREFIX', 'backup.');
define('XS_BACKUP_EXT', '.backup');
define('XS_MAX_TIMEOUT', 600); // maximum timeout for downloads/import/installation
$xs_row_class = array('row1', 'row2');
$template_dir = 'templates/';
$template->assign_vars(array(
'XS_PATH' => '../xs_mod/',
'XS_UL' => '
',
'XS_LI' => ' | ',
'XS_LI2' => ' |
',
'S_HIDDEN_FIELDS' => '',
));
if(!defined('NO_XS_HEADER'))
{
$template->set_filenames(array(
'xs_header' => XS_TPL_PATH . 'xs_header.tpl',
'xs_footer' => XS_TPL_PATH . 'xs_footer.tpl',
));
$template->preparse = 'xs_header';
$template->postparse = 'xs_footer';
$template->assign_block_vars('nav_left',array('ITEM' => '' . $lang['xs_menu'] . ''));
}
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//
// Check compatibility with mods
//
if(isset($config->data) && $config->data === $board_config && isset($config->data['mod_cat_hierarchy']))
{
define('XS_MODS_CATEGORY_HIERARCHY210', true);
}
elseif(defined('CACHE_THEMES') && @function_exists('cache_themes'))
{
define('XS_MODS_CATEGORY_HIERARCHY', true);
}
if(isset($theme['theme_public']))
{
define('XS_MODS_ADMIN_TEMPLATES', true);
}
//
// Get FTP configuration
//
function get_ftp_config($action, $post = array(), $allow_local = false, $show_error = '')
{
global $template, $board_config, $db, $lang, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
$board_config['xs_ftp_local'] = false;
// check if ftp can be used
if(!@function_exists('ftp_connect'))
{
if($allow_local && xs_dir_writable('../templates/'))
{
$board_config['xs_ftp_local'] = true;
return true;
}
xs_error($lang['xs_ftp_error_fatal']);
}
// check if we have configuration
if(!empty($HTTP_POST_VARS['get_ftp_config']))
{
$vars = array('xs_ftp_host', 'xs_ftp_login', 'xs_ftp_path');
for($i=0; $isql_query($sql);
}
}
$board_config['xs_ftp_pass'] = stripslashes($HTTP_POST_VARS['xs_ftp_pass']);
$board_config['xs_ftp_local'] = empty($HTTP_POST_VARS['xs_ftp_local']) ? false : true;
// recache config table
if(defined('XS_MODS_CATEGORY_HIERARCHY210'))
{
global $config;
if ( !empty($config) )
{
$config->read(true);
}
}
return true;
}
// check ftp configuration
$xs_ftp_host = $board_config['xs_ftp_host'];
if(empty($xs_ftp_host))
{
$str = $HTTP_SERVER_VARS['HTTP_HOST'];
$template->assign_vars(array(
'HOST_GUESS' => str_replace(array('{HOST}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_host.value=\''.$str.'\''), $lang['xs_ftp_host_guess'])
));
}
$dir = getcwd();
$xs_ftp_login = $board_config['xs_ftp_login'];
if(empty($xs_ftp_login))
{
if(substr($dir, 0, 6) === '/home/')
{
$str = substr($dir, 6);
$pos = strpos($str, '/');
if($pos)
{
$str = substr($str, 0, $pos);
$template->assign_vars(array(
'LOGIN_GUESS' => str_replace(array('{LOGIN}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_login.value=\''.$str.'\''), $lang['xs_ftp_login_guess'])
));
}
}
}
$xs_ftp_path = $board_config['xs_ftp_path'];
if(empty($xs_ftp_path))
{
if(substr($dir, 0, 6) === '/home/');
$str = substr($dir, 6);
$pos = strpos($str, '/');
if($pos)
{
$str = substr($str, $pos + 1);
$pos = strrpos($str, 'admin');
if($pos)
{
$str = substr($str, 0, $pos-1);
$template->assign_vars(array(
'PATH_GUESS' => str_replace(array('{PATH}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_path.value=\''.$str.'\''), $lang['xs_ftp_path_guess'])
));
}
}
}
if($allow_local && xs_dir_writable('../templates/'))
{
$template->assign_block_vars('xs_ftp_local', array());
}
else
{
$template->assign_block_vars('xs_ftp_nolocal', array());
}
$str = '';
foreach($post as $var => $value)
{
$str .= '';
}
$template->assign_vars(array(
'FORM_ACTION' => $action,
'S_EXTRA_FIELDS' => $str,
'XS_FTP_HOST' => $xs_ftp_host,
'XS_FTP_LOGIN' => $xs_ftp_login,
'XS_FTP_PATH' => $xs_ftp_path,
));
if($show_error)
{
$template->assign_block_vars('error', array('MSG' => $show_error));
}
$template->set_filenames(array('config' => XS_TPL_PATH . 'ftp.tpl'));
$template->pparse('config');
return false;
}
// connect ftp
function xs_ftp_connect($action, $post = array(), $allow_local = false)
{
global $ftp, $board_config, $HTTP_POST_VARS, $phpEx, $lang, $template;
$HTTP_POST_VARS['get_ftp_config'] = '';
if($allow_local && !empty($board_config['xs_ftp_local']))
{
$ftp = XS_FTP_LOCAL;
return true;
}
$ftp = @ftp_connect($board_config['xs_ftp_host']);
if(!$ftp)
{
get_ftp_config($action, $post, $allow_local, str_replace('{HOST}', $board_config['xs_ftp_host'], $lang['xs_ftp_error_connect']));
}
$res = @ftp_login($ftp, $board_config['xs_ftp_login'], $board_config['xs_ftp_pass']);
if(!$res)
{
get_ftp_config($action, $post, $allow_local, $lang['xs_ftp_error_login']);
}
$res = @ftp_chdir($ftp, $board_config['xs_ftp_path']);
if(!$res)
{
get_ftp_config($action, $post, $allow_local, str_replace('{DIR}', $board_config['xs_ftp_path'], $lang['xs_ftp_error_chdir']));
}
// check current directory
$current_dir = @ftp_pwd($ftp);
$list = @ftp_nlist($ftp, $current_dir);
for($i=0; $i
' . $lang['xs_style_header_error_server'] . substr($str, 7);
}
else
{
$xs_header_error = $lang['xs_style_header_error_invalid'];
}
return false;
}
$start = strlen(STYLE_HEADER_START);
$str1 = substr($str, $start, 8);
$data = unpack('Nvar1/Nvar2', $str1);
$start += 8;
$header_size = $data['var1'];
$filesize = $data['var2'];
$total = ord($str{$start});
$start ++;
if($total < 3)
{
$xs_header_error = $lang['xs_style_header_error_invalid'];
return false;
}
$items_len = array();
for($i=0; $i<$total; $i++)
{
$items_len[$i] = ord($str{$i+$start});
}
$start += $total;
$items = array();
$tpl = '';
for($i=0; $i<$total; $i++)
{
$str1 = substr($str, $start, $items_len[$i]);
if($i == 0) $tpl = $str1;
elseif($i == 1) $comment = $str1;
else $items[] = $str1;
$start += $items_len[$i];
}
if(substr($str, $start, strlen(STYLE_HEADER_END)) !== STYLE_HEADER_END)
{
$xs_header_error = $lang['xs_style_header_error_invalid'];
return false;
}
return array(
'template' => $tpl,
'styles' => $items,
'date' => @filemtime($filename),
'comment' => $comment,
'offset' => $header_size,
'filename' => $filename,
'filesize' => $filesize,
);
}
// check if cache is writable
function xs_check_cache($filename)
{
// check if filename is valid
global $str, $template, $lang;
if(substr($filename, 0, strlen($template->cachedir)) !== $template->cachedir)
{
$str .= $lang['xs_check_filename'] . "
\n";
return false;
}
else
{
// try to open file
$file = @fopen($filename, 'w');
if(!$file)
{
$str .= sprintf($lang['xs_check_openfile1'], $filename) . "
\n";
// try to create directories
$dir = substr($filename, strlen($template->cachedir), strlen($filename));
$dirs = explode('/', $dir);
$path = $template->cachedir;
@umask(0);
if(!@is_dir($path))
{
$str .= sprintf($lang['xs_check_nodir'], $path) . "
\n";
if(!@mkdir($path))
{
$str .= sprintf($lang['xs_check_nodir2'], $path) . "
\n";
return false;
}
else
{
$str .= sprintf($lang['xs_check_createddir'], $path) . "
\n";
@chmod($path, 0777);
}
}
else
{
$str .= sprintf($lang['xs_check_dir'] , $path) . "
\n";
}
if(count($dirs) > 0)
for($i=0; $i0)
{
$path .= '/';
}
$path .= $dirs[$i];
if(!@is_dir($path))
{
$str .= sprintf($lang['xs_check_nodir'], $path) . "
\n";
if(!@mkdir($path))
{
$str .= sprintf($lang['xs_check_nodir2'], $path) . "
\n";
return false;
}
else
{
$str .= sprintf($lang['xs_check_createddir'], $path) . "
\n";
@chmod($path, 0777);
}
}
else
{
$str .= sprintf($lang['xs_check_dir'] , $path) . "
\n";
}
}
// try to open file again after directories were created
$file = @fopen($filename, 'w');
}
if(!$file)
{
$str .= sprintf($lang['xs_check_openfile2'], $filename) . "
\n";
return false;
}
$str .= sprintf($lang['xs_check_ok'], $filename) . "
\n";
fputs($file, ' ');
fclose($file);
@chmod($filename, 0777);
return true;
}
}
// run ftp commands
function ftp_myexec($list)
{
global $ftp, $ftp_error, $ftp_log, $ftp_host, $ftp_login, $ftp_pass, $lang;
$ftp_error = '';
$ftp_log = array();
if(empty($ftp))
{
// checking ftp extensions
if(!@function_exists('ftp_connect'))
{
$ftp_log[] = $ftp_error = $lang['xs_ftp_log_disabled'];
return false;
}
// connect to server
$ftp_log[] = str_replace('{HOST}', "{$ftp_login}:*@{$ftp_host}", $lang['xs_ftp_log_connecting']);
$ftp = @ftp_connect($ftp_host);
if(!$ftp)
{
$ftp_log[] = $ftp_error = str_replace('{HOST}', $ftp_host, $lang['xs_ftp_log_noconnect']);
return false;
}
$ftp_log[] = $lang['xs_ftp_log_connected'];
// logging in
$logged_in = @ftp_login($ftp, $ftp_login, $ftp_pass);
if(!$logged_in)
{
$ftp_log[] = $ftp_error = str_replace('{USER}', $ftp_login, $lang['xs_ftp_log_nologin']);
@ftp_close($ftp);
return false;
}
$ftp_log[] = $lang['xs_ftp_log_loggedin'];
}
if(!ftp_myexec2($ftp, $list))
{
@ftp_close($ftp);
return false;
}
@ftp_close($ftp);
$ftp_log[] = $lang['xs_ftp_log_end'];
return true;
}
// remove all files via ftp
function ftp_remove_all($ftp)
{
// get current directory
$root_dir = @ftp_pwd($ftp);
// get list of files
$files = @ftp_nlist($ftp, $root_dir);
// remove files/directories
for($i=0; $isql_query($sql))
{
return false;
}
$row = $db->sql_fetchrow($result);
if(!empty($row['themes_id']))
{
return false;
}
$vars = array();
$values = array();
foreach($data as $var => $value)
{
$vars[] = xs_sql($var);
$values[] = xs_sql(stripslashes($value));
}
$sql = "INSERT INTO " . THEMES_TABLE . " (" . implode(', ', $vars) . ") VALUES ('" . implode("', '", $values) . "')";
if(!$result = $db->sql_query($sql))
{
return false;
}
// recache themes table
if(defined('XS_MODS_CATEGORY_HIERARCHY210'))
{
global $themes;
if ( empty($themes) )
{
$themes = new themes();
}
if ( !empty($themes) )
{
$themes->read(true);
}
}
// add configuration
global $template;
if($template->add_config($tpl))
{
define('REFRESH_NAVBAR', true);
}
return true;
}
// generate theme_info.cfg for template
function xs_generate_themeinfo($theme_rowset, $export, $exportas, $total)
{
global $HTTP_POST_VARS;
$vars = array('template_name', 'style_name', 'head_stylesheet', 'body_background', 'body_bgcolor', 'body_text', 'body_link', 'body_vlink', 'body_alink', 'body_hlink', 'tr_color1', 'tr_color2', 'tr_color3', 'tr_class1', 'tr_class2', 'tr_class3', 'th_color1', 'th_color2', 'th_color3', 'th_class1', 'th_class2', 'th_class3', 'td_color1', 'td_color2', 'td_color3', 'td_class1', 'td_class2', 'td_class3', 'fontface1', 'fontface2', 'fontface3', 'fontsize1', 'fontsize2', 'fontsize3', 'fontcolor1', 'fontcolor2', 'fontcolor3', 'span_class1', 'span_class2', 'span_class3', 'img_size_poll', 'img_size_privmsg');
$theme_data = ''; // Done this to prevent highlighting editors getting confused!
return $theme_data;
}
// Checks if directory is writable
function xs_dir_writable($dir)
{
$filename = 'tmp_' . time();
$f = @fopen($dir . $filename, 'wb');
if($f)
{
fclose($f);
@unlink($dir . $filename);
return true;
}
return false;
}
// Write to file. Create directory if necessary
function xs_write_file($filename, $data)
{
$f = @fopen($filename, 'wb');
if(!$f)
{
// try to create directories
$pos = strrpos($filename, '/');
if(!$pos)
{
return false;
}
$dir = substr($filename, 0, $pos);
xs_create_dir($dir);
$f = @fopen($filename, 'wb');
if(!$f)
{
return false;
}
}
fwrite($f, $data);
fclose($f);
@chmod($filename, 0777);
return true;
}
// Create local directory
function xs_create_dir($dir)
{
if(!$dir)
{
return false;
}
// remove trailing /
if(substr($dir, strlen($dir) - 1) === '/')
{
$dir = substr($dir, 0, strlen($dir) - 1);
if(!$dir)
{
return false;
}
}
if($dir === '.' || $dir === '..')
{
return false;
}
$res = @mkdir($dir, 0777);
if($res)
{
return true;
}
// try to create previous directory
$pos = strrpos($dir, '/');
if(!$pos)
{
return false;
}
$dir1 = substr($dir, 0, $pos);
$dir2 = substr($dir, $pos+1);
if($dir2 === '.' || $dir2 === '..')
{
return false;
}
if(!xs_create_dir($dir1))
{
return false;
}
$res = @mkdir($dir2, 0777);
return $res ? true : false;
}
// replacement for in_array() (because of compatibility problems)
function xs_in_array($needle, $haystack)
{
for($i=0; $iset_filenames(array('errormsg' => XS_TPL_PATH . 'message.tpl'));
$template->assign_vars(array(
'MESSAGE_TITLE' => $lang['Error'],
'MESSAGE_TEXT' => $error
));
$template->pparse('errormsg');
xs_exit();
}
// show message and exit
function xs_message($title, $message)
{
global $template;
$template->set_filenames(array('msg' => XS_TPL_PATH . 'message.tpl'));
$template->assign_vars(array(
'MESSAGE_TITLE' => $title,
'MESSAGE_TEXT' => $message
));
$template->pparse('msg');
xs_exit();
}
// pack style to .style
function pack_style($name, $newname, $themes, $comment)
{
/*
header format (v0.01):
- header
- header size (4 bytes)
- file size (4 bytes)
- number of entries (1 byte)
- entries sizes (number_of_entries bytes)
- entries
- footer
- gzcompressed tar of style (no crc check in tar)
entries:
- template name
- comment
- style names
*/
global $phpbb_root_path, $template_dir;
$data = gzcompress(pack_dir($phpbb_root_path . $template_dir . $name, '', $name, $newname));
$items_data = chr(strlen($newname)) . chr(strlen($comment));
$items_str = $newname . $comment;
for($i=0; $i $base_dir,
'mode' => '40777',
'uid' => '0',
'gid' => '0',
'size' => decoct(0),
'mtime' => decoct(@filemtime($dir)),
'checksum' => '0', // ignore checksum
'typeflag' => '5',
'link' => '',
'magic' => "ustar",
'version' => '',
'uname' => 'user',
'gname' => 'group',
'devmajor' => '',
'devminor' => '',
'prefix' => '',
'extra' => ''
);
$header_str = pack(TAR_HEADER_PACK, $header['filename'], $header['mode'], $header['uid'], $header['gid'], $header['size'], $header['mtime'], $header['checksum'], $header['typeflag'], $header['linkname'], $header['magic'], $header['version'], $header['uname'], $header['gname'], $header['devmajor'], $header['devminor'], $header['prefix'], $header['extra']);
$file_str = '';
$extra_str = '';
$str .= $header_str . $file_str . $extra_str;
// add all files
for($i=0; $i';
if($header['filename'] === './overall_header.tpl')
{
echo 'overall_header.tpl:
', nl2br(htmlspecialchars($file_str)), '
';
}*/
$size = strlen($file_str);
$header['size'] = decoct($size);
$header['typeflag'] = '0';
$header['mode'] = '100666';
$full_size = floor(($size + 511) / 512) * 512;
$extra_str = $full_size > $size ? str_repeat("\0", $full_size - $size) : '';
$header_str = pack(TAR_HEADER_PACK, $header['filename'], $header['mode'], $header['uid'], $header['gid'], $header['size'], $header['mtime'], $header['checksum'], $header['typeflag'], $header['linkname'], $header['magic'], $header['version'], $header['uname'], $header['gname'], $header['devmajor'], $header['devminor'], $header['prefix'], $header['extra']);
$str .= $header_str . $file_str . $extra_str;
}
// add all directories
for($i=0; $isql_query($sql);
}
// send file
function xs_download_file($filename, $content, $content_type = '')
{
if(empty($content_type))
{
$content_type = 'application/unknown';
}
header('Content-Type: ' . $content_type);
header('Content-Length: ' . strlen($content));
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
if($filename)
{
header('Content-Disposition: inline; filename="' . $filename . '"');
}
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo $content;
}
// strip slashes for sql
function xs_sql($sql, $strip = false)
{
if($strip)
{
$sql = stripslashes($sql);
}
return str_replace('\\\'', '\'\'', addslashes($sql));
}
// clean template name
function xs_tpl_name($name)
{
return str_replace(array('\\', '/', "'", '"'), array('','','',''), $name);
}
// close database and maybe do some other stuff
function xs_exit()
{
global $db;
if(isset($db))
{
$db->sql_close();
}
exit;
}
// check directory name/filename
function xs_fix_dir($dir)
{
$dir = str_replace('\\', '/', $dir);
$dir = str_replace('../', './', $dir);
while(strlen($dir > 1) && substr($dir, strlen($dir) - 2) === '..')
{
$dir = substr($dir, 0, strlen($dir) - 1);
}
return $dir;
}
?>