+++ /dev/null
-<?php\r
-\r
-/***************************************************************************\r
- * xs_include.php\r
- * --------------\r
- * copyright : (C) 2003 - 2005 CyberAlien\r
- * support : http://www.phpbbstyles.com\r
- *\r
- * version : 2.3.1\r
- *\r
- * file revision : 77\r
- * project revision : 78\r
- * last modified : 05 Dec 2005 13:54:54\r
- *\r
- ***************************************************************************/\r
-\r
-/***************************************************************************\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- ***************************************************************************/\r
-\r
-if (!defined('IN_PHPBB') || !defined('IN_XS'))\r
-{\r
- die('Hacking attempt');\r
-}\r
-\r
-if(defined('XS_INCLUDED'))\r
-{\r
- return;\r
-}\r
-define('XS_INCLUDED', true);\r
-\r
-\r
-//\r
-// include language file\r
-//\r
-\r
-if(!defined('XS_LANG_INCLUDED'))\r
-{\r
- global $phpbb_root_path, $board_config, $phpEx, $lang;\r
- $xs_lang_file = $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_xs.'.$phpEx;\r
- if( !@file_exists($xs_lang_file) )\r
- { // load english version if there is no translation to current language\r
- $xs_lang_file = $phpbb_root_path . 'language/lang_english/lang_xs.'.$phpEx;\r
- }\r
- include($xs_lang_file);\r
- define('XS_LANG_INCLUDED', true);\r
-}\r
-\r
-\r
-define('XS_SHOWNAV_CONFIG', 0);\r
-define('XS_SHOWNAV_INSTALL', 1);\r
-define('XS_SHOWNAV_UNINSTALL', 2);\r
-define('XS_SHOWNAV_DEFAULT', 3);\r
-define('XS_SHOWNAV_CACHE', 4);\r
-define('XS_SHOWNAV_IMPORT', 5);\r
-define('XS_SHOWNAV_EXPORT', 6);\r
-define('XS_SHOWNAV_CLONE', 7);\r
-define('XS_SHOWNAV_DOWNLOAD', 8);\r
-define('XS_SHOWNAV_EDITTPL', 9);\r
-define('XS_SHOWNAV_EDITDB', 10);\r
-define('XS_SHOWNAV_EXPORTDB', 11);\r
-define('XS_SHOWNAV_UPDATES', 12);\r
-define('XS_SHOWNAV_MAX', 13);\r
-\r
-global $xs_shownav_action;\r
-$xs_shownav_action = array(\r
- 'config',\r
- 'install',\r
- 'uninstall',\r
- 'default',\r
- 'cache',\r
- 'import',\r
- 'export',\r
- 'clone',\r
- 'download',\r
- 'edittpl',\r
- 'editdb',\r
- 'exportdb',\r
- 'updates',\r
- );\r
-\r
-\r
-// override styles management in admin navigation\r
-function xs_admin_override($modded = false)\r
-{\r
- if(defined('XS_ADMIN_OVERRIDE_FINISHED'))\r
- {\r
- return;\r
- }\r
- define('XS_ADMIN_OVERRIDE_FINISHED', true);\r
- global $module, $phpEx, $xs_shownav_action, $board_config, $lang;\r
- // remove default phpBB styles management\r
- if(isset($module['Styles']))\r
- {\r
- $unset = array('Add_new', 'Create_new', 'Manage', 'Export');\r
- for($i=0; $i<count($unset); $i++)\r
- {\r
- if(isset($module['Styles'][$unset[$i]]))\r
- {\r
- unset($module['Styles'][$unset[$i]]);\r
- }\r
- }\r
- $module['Styles']['Menu'] = 'xs_frameset.'.$phpEx.'?action=menu&showwarning=1';\r
- }\r
- // add new menu\r
- $module_name = 'Extreme_Styles';\r
- $module[$module_name]['Styles_Management'] = 'xs_frameset.'.$phpEx.'?action=menu';\r
- for($i=0; $i<XS_SHOWNAV_MAX; $i++)\r
- {\r
- $num = pow(2, $i);\r
- if($i != XS_SHOWNAV_DOWNLOAD && ($board_config['xs_shownav'] & $num) > 0)\r
- {\r
- $module[$module_name][$lang['xs_config_shownav'][$i]] = 'xs_frameset.'.$phpEx.'?action=' . $xs_shownav_action[$i];\r
- }\r
- }\r
- // add menu for style configuration\r
- foreach($board_config as $var => $value)\r
- {\r
- if(substr($var, 0, 9) === 'xs_style_')\r
- {\r
- $str = substr($var, 9);\r
- $module['Template_Config'][$str] = 'xs_frameset.'.$phpEx.'?action=style_config&tpl='.urlencode($str);\r
- }\r
- }\r
-}\r
-\r
-\r
-if(!empty($setmodules))\r
-{\r
- if(@function_exists('jr_admin_get_module_list'))\r
- {\r
- $tmp_mod = $module;\r
- global $module;\r
- $module = $tmp_mod;\r
- xs_admin_override(true);\r
- }\r
- return;\r
-}\r
-\r
-//\r
-// Global defines for eXtreme Styles mod administration panel\r
-//\r
-define('STYLE_HEADER_START', 'xs_style_01<xs>');\r
-define('STYLE_HEADER_END', '</xs>');\r
-define('STYLE_HEADER_VERSION', '1');\r
-define('STYLE_EXTENSION', '.style');\r
-define('TAR_HEADER_PACK', 'a100A8A8A8A12A12A8A1A100A6A2A32A32A8A8a155a12');\r
-define('TAR_HEADER_UNPACK', 'a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix/a12extra');\r
-define('XS_MAX_ITEMS_PER_STYLE', 32);\r
-define('XS_TEMP_DIR', '../cache/');\r
-define('XS_FTP_LOCAL', 'no_ftp');\r
-define('XS_UPDATE_STYLE', 1);\r
-define('XS_UPDATE_MOD', 2);\r
-define('XS_UPDATE_PHPBB', 3);\r
-define('XS_TPL_PATH', '../../xs_mod/tpl/');\r
-define('XS_BACKUP_PREFIX', 'backup.');\r
-define('XS_BACKUP_EXT', '.backup');\r
-define('XS_MAX_TIMEOUT', 600); // maximum timeout for downloads/import/installation\r
-\r
-$xs_row_class = array('row1', 'row2');\r
-\r
-$template_dir = 'templates/';\r
-\r
-$template->assign_vars(array(\r
- 'XS_PATH' => '../xs_mod/',\r
- 'XS_UL' => '<table width="100%" cellspacing="0" cellpadding="2" border="0">',\r
- 'XS_UL2' => '</table>',\r
- 'XS_LI' => '<tr><td width="20" align="center" valign="middle"><img src="../xs_mod/images/dot.gif" border="0" alt="" /></td><td align="left" valign="middle" width="100%"><span class="gen">',\r
- 'XS_LI2' => '</span></td></tr>',\r
- 'S_HIDDEN_FIELDS' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" />',\r
- ));\r
-\r
-if(!defined('NO_XS_HEADER'))\r
-{\r
- $template->set_filenames(array(\r
- 'xs_header' => XS_TPL_PATH . 'xs_header.tpl',\r
- 'xs_footer' => XS_TPL_PATH . 'xs_footer.tpl',\r
- ));\r
- $template->preparse = 'xs_header';\r
- $template->postparse = 'xs_footer';\r
- $template->assign_block_vars('nav_left',array('ITEM' => '<a href="' . append_sid('xs_index.'.$phpEx) . '">' . $lang['xs_menu'] . '</a>'));\r
-}\r
-\r
-\r
-header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');\r
-header('Cache-Control: must-revalidate, post-check=0, pre-check=0');\r
-\r
-//\r
-// Check compatibility with mods\r
-//\r
-if(isset($config->data) && $config->data === $board_config && isset($config->data['mod_cat_hierarchy']))\r
-{\r
- define('XS_MODS_CATEGORY_HIERARCHY210', true);\r
-}\r
-elseif(defined('CACHE_THEMES') && @function_exists('cache_themes'))\r
-{\r
- define('XS_MODS_CATEGORY_HIERARCHY', true);\r
-}\r
-if(isset($theme['theme_public']))\r
-{\r
- define('XS_MODS_ADMIN_TEMPLATES', true);\r
-}\r
-\r
-\r
-//\r
-// Get FTP configuration\r
-//\r
-function get_ftp_config($action, $post = array(), $allow_local = false, $show_error = '')\r
-{\r
- global $template, $board_config, $db, $lang, $HTTP_POST_VARS, $HTTP_SERVER_VARS;\r
- $board_config['xs_ftp_local'] = false;\r
- // check if ftp can be used\r
- if(!@function_exists('ftp_connect'))\r
- {\r
- if($allow_local && xs_dir_writable('../templates/'))\r
- {\r
- $board_config['xs_ftp_local'] = true;\r
- return true;\r
- }\r
- xs_error($lang['xs_ftp_error_fatal']);\r
- }\r
- // check if we have configuration\r
- if(!empty($HTTP_POST_VARS['get_ftp_config']))\r
- {\r
- $vars = array('xs_ftp_host', 'xs_ftp_login', 'xs_ftp_path');\r
- for($i=0; $i<count($vars); $i++)\r
- {\r
- $var = $vars[$i];\r
- if($board_config[$var] !== $HTTP_POST_VARS[$var])\r
- {\r
- $board_config[$var] = stripslashes($HTTP_POST_VARS[$var]);\r
- $sql = "UPDATE " . CONFIG_TABLE . " SET config_value = '" . xs_sql($board_config[$var]) . "' WHERE config_name = '{$var}'";\r
- $db->sql_query($sql);\r
- }\r
- }\r
- $board_config['xs_ftp_pass'] = stripslashes($HTTP_POST_VARS['xs_ftp_pass']);\r
- $board_config['xs_ftp_local'] = empty($HTTP_POST_VARS['xs_ftp_local']) ? false : true;\r
- // recache config table\r
- if(defined('XS_MODS_CATEGORY_HIERARCHY210'))\r
- {\r
- global $config;\r
- if ( !empty($config) )\r
- {\r
- $config->read(true);\r
- }\r
- }\r
- return true;\r
- }\r
- // check ftp configuration\r
- $xs_ftp_host = $board_config['xs_ftp_host'];\r
- if(empty($xs_ftp_host))\r
- {\r
- $str = $HTTP_SERVER_VARS['HTTP_HOST'];\r
- $template->assign_vars(array(\r
- 'HOST_GUESS' => str_replace(array('{HOST}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_host.value=\''.$str.'\''), $lang['xs_ftp_host_guess'])\r
- ));\r
- }\r
- $dir = getcwd();\r
- $xs_ftp_login = $board_config['xs_ftp_login'];\r
- if(empty($xs_ftp_login))\r
- {\r
- if(substr($dir, 0, 6) === '/home/')\r
- {\r
- $str = substr($dir, 6);\r
- $pos = strpos($str, '/');\r
- if($pos)\r
- {\r
- $str = substr($str, 0, $pos);\r
- $template->assign_vars(array(\r
- 'LOGIN_GUESS' => str_replace(array('{LOGIN}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_login.value=\''.$str.'\''), $lang['xs_ftp_login_guess'])\r
- ));\r
- }\r
- }\r
- }\r
- $xs_ftp_path = $board_config['xs_ftp_path'];\r
- if(empty($xs_ftp_path))\r
- {\r
- if(substr($dir, 0, 6) === '/home/');\r
- $str = substr($dir, 6);\r
- $pos = strpos($str, '/');\r
- if($pos)\r
- {\r
- $str = substr($str, $pos + 1);\r
- $pos = strrpos($str, 'admin');\r
- if($pos)\r
- {\r
- $str = substr($str, 0, $pos-1);\r
- $template->assign_vars(array(\r
- 'PATH_GUESS' => str_replace(array('{PATH}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_path.value=\''.$str.'\''), $lang['xs_ftp_path_guess'])\r
- ));\r
- }\r
- }\r
- }\r
- if($allow_local && xs_dir_writable('../templates/'))\r
- {\r
- $template->assign_block_vars('xs_ftp_local', array());\r
- }\r
- else\r
- {\r
- $template->assign_block_vars('xs_ftp_nolocal', array());\r
- }\r
- $str = '<input type="hidden" name="get_ftp_config" value="1" />';\r
- foreach($post as $var => $value)\r
- {\r
- $str .= '<input type="hidden" name="' . htmlspecialchars($var) . '" value="' . htmlspecialchars($value) . '" />';\r
- }\r
- $template->assign_vars(array(\r
- 'FORM_ACTION' => $action,\r
- 'S_EXTRA_FIELDS' => $str,\r
- 'XS_FTP_HOST' => $xs_ftp_host,\r
- 'XS_FTP_LOGIN' => $xs_ftp_login,\r
- 'XS_FTP_PATH' => $xs_ftp_path,\r
- ));\r
- if($show_error)\r
- {\r
- $template->assign_block_vars('error', array('MSG' => $show_error));\r
- }\r
- $template->set_filenames(array('config' => XS_TPL_PATH . 'ftp.tpl'));\r
- $template->pparse('config');\r
- return false;\r
-}\r
-\r
-// connect ftp\r
-function xs_ftp_connect($action, $post = array(), $allow_local = false)\r
-{\r
- global $ftp, $board_config, $HTTP_POST_VARS, $phpEx, $lang, $template;\r
- $HTTP_POST_VARS['get_ftp_config'] = '';\r
- if($allow_local && !empty($board_config['xs_ftp_local']))\r
- {\r
- $ftp = XS_FTP_LOCAL;\r
- return true;\r
- }\r
- $ftp = @ftp_connect($board_config['xs_ftp_host']);\r
- if(!$ftp)\r
- {\r
- get_ftp_config($action, $post, $allow_local, str_replace('{HOST}', $board_config['xs_ftp_host'], $lang['xs_ftp_error_connect']));\r
- }\r
- $res = @ftp_login($ftp, $board_config['xs_ftp_login'], $board_config['xs_ftp_pass']);\r
- if(!$res)\r
- {\r
- get_ftp_config($action, $post, $allow_local, $lang['xs_ftp_error_login']);\r
- }\r
- $res = @ftp_chdir($ftp, $board_config['xs_ftp_path']);\r
- if(!$res)\r
- {\r
- get_ftp_config($action, $post, $allow_local, str_replace('{DIR}', $board_config['xs_ftp_path'], $lang['xs_ftp_error_chdir']));\r
- }\r
- // check current directory\r
- $current_dir = @ftp_pwd($ftp);\r
- $list = @ftp_nlist($ftp, $current_dir);\r
- for($i=0; $i<count($list); $i++)\r
- {\r
- $list[$i] = strtolower(basename($list[$i]));\r
- }\r
- // check few files\r
- $check = array('extension.inc', 'templates', 'xs_mod');\r
- $found = array(false, false, false);\r
- for($i=0; $i<count($list); $i++)\r
- {\r
- for($j=0; $j<count($check); $j++)\r
- {\r
- if($list[$i] === $check[$j])\r
- {\r
- $found[$j] = true;\r
- }\r
- }\r
- }\r
- $error = false;\r
- for($i=0; $i<count($check); $i++)\r
- {\r
- if(!$found[$i])\r
- {\r
- $error = true;\r
- }\r
- }\r
- if($error)\r
- {\r
- get_ftp_config($action, $post, $allow_local, $lang['xs_ftp_error_nonphpbbdir']);\r
- }\r
- $HTTP_POST_VARS['get_ftp_config'] = '1';\r
-}\r
-\r
-// get .style file header\r
-function xs_get_style_header($filename, $str = '')\r
-{\r
- /*\r
- header format (v0.01):\r
- - header\r
- - header size (4 bytes)\r
- - file size (4 bytes)\r
- - number of entries (1 byte)\r
- - entries sizes (number_of_entries bytes)\r
- - entries\r
- - footer\r
- - gzcompressed tar of style (no crc check in tar)\r
-\r
- entries:\r
- - template name\r
- - comment\r
- - style names\r
- */\r
- global $xs_header_error, $lang;\r
- $xs_header_error = '';\r
- if(!$str)\r
- {\r
- $f = @fopen($filename, 'rb');\r
- if(!$f)\r
- {\r
- $xs_header_error = $lang['xs_style_header_error_file'];\r
- return false;\r
- }\r
- $str = fread($f, 10240);\r
- fclose($f);\r
- }\r
- if(substr($str, 0, strlen(STYLE_HEADER_START)) !== STYLE_HEADER_START)\r
- {\r
- if(substr($str, 0, 7) === 'error: ')\r
- {\r
- $xs_header_error = '<br /><br />' . $lang['xs_style_header_error_server'] . substr($str, 7);\r
- }\r
- else\r
- {\r
- $xs_header_error = $lang['xs_style_header_error_invalid'];\r
- }\r
- return false;\r
- }\r
- $start = strlen(STYLE_HEADER_START);\r
- $str1 = substr($str, $start, 8);\r
- $data = unpack('Nvar1/Nvar2', $str1);\r
- $start += 8;\r
- $header_size = $data['var1'];\r
- $filesize = $data['var2'];\r
- $total = ord($str{$start});\r
- $start ++;\r
- if($total < 3)\r
- {\r
- $xs_header_error = $lang['xs_style_header_error_invalid'];\r
- return false;\r
- }\r
- $items_len = array();\r
- for($i=0; $i<$total; $i++)\r
- {\r
- $items_len[$i] = ord($str{$i+$start});\r
- }\r
- $start += $total;\r
- $items = array();\r
- $tpl = '';\r
- for($i=0; $i<$total; $i++)\r
- {\r
- $str1 = substr($str, $start, $items_len[$i]);\r
- if($i == 0) $tpl = $str1;\r
- elseif($i == 1) $comment = $str1;\r
- else $items[] = $str1;\r
- $start += $items_len[$i];\r
- }\r
- if(substr($str, $start, strlen(STYLE_HEADER_END)) !== STYLE_HEADER_END)\r
- {\r
- $xs_header_error = $lang['xs_style_header_error_invalid'];\r
- return false;\r
- }\r
- return array(\r
- 'template' => $tpl,\r
- 'styles' => $items,\r
- 'date' => @filemtime($filename),\r
- 'comment' => $comment,\r
- 'offset' => $header_size,\r
- 'filename' => $filename,\r
- 'filesize' => $filesize,\r
- );\r
-}\r
-\r
-\r
-// check if cache is writable\r
-function xs_check_cache($filename)\r
-{\r
- // check if filename is valid\r
- global $str, $template, $lang;\r
- if(substr($filename, 0, strlen($template->cachedir)) !== $template->cachedir)\r
- {\r
- $str .= $lang['xs_check_filename'] . "<br />\n";\r
- return false;\r
- }\r
- else\r
- {\r
- // try to open file\r
- $file = @fopen($filename, 'w');\r
- if(!$file)\r
- {\r
- $str .= sprintf($lang['xs_check_openfile1'], $filename) . "<br />\n";\r
- // try to create directories\r
- $dir = substr($filename, strlen($template->cachedir), strlen($filename));\r
- $dirs = explode('/', $dir);\r
- $path = $template->cachedir; \r
- @umask(0);\r
- if(!@is_dir($path))\r
- {\r
- $str .= sprintf($lang['xs_check_nodir'], $path) . "<br />\n";\r
- if(!@mkdir($path))\r
- {\r
- $str .= sprintf($lang['xs_check_nodir2'], $path) . "<br />\n";\r
- return false;\r
- }\r
- else\r
- {\r
- $str .= sprintf($lang['xs_check_createddir'], $path) . "<br />\n";\r
- @chmod($path, 0777);\r
- }\r
- }\r
- else\r
- {\r
- $str .= sprintf($lang['xs_check_dir'] , $path) . "<br />\n";\r
- }\r
- if(count($dirs) > 0)\r
- for($i=0; $i<count($dirs)-1; $i++)\r
- {\r
- if($i>0)\r
- {\r
- $path .= '/';\r
- }\r
- $path .= $dirs[$i];\r
- if(!@is_dir($path))\r
- {\r
- $str .= sprintf($lang['xs_check_nodir'], $path) . "<br />\n";\r
- if(!@mkdir($path))\r
- {\r
- $str .= sprintf($lang['xs_check_nodir2'], $path) . "<br />\n";\r
- return false;\r
- }\r
- else\r
- {\r
- $str .= sprintf($lang['xs_check_createddir'], $path) . "<br />\n";\r
- @chmod($path, 0777);\r
- }\r
- }\r
- else\r
- {\r
- $str .= sprintf($lang['xs_check_dir'] , $path) . "<br />\n";\r
- }\r
- }\r
- // try to open file again after directories were created\r
- $file = @fopen($filename, 'w');\r
- }\r
- if(!$file)\r
- {\r
- $str .= sprintf($lang['xs_check_openfile2'], $filename) . "<br />\n";\r
- return false;\r
- }\r
- $str .= sprintf($lang['xs_check_ok'], $filename) . "<br />\n";\r
- fputs($file, ' ');\r
- fclose($file);\r
- @chmod($filename, 0777);\r
- return true;\r
- }\r
-}\r
-\r
-// run ftp commands\r
-function ftp_myexec($list)\r
-{\r
- global $ftp, $ftp_error, $ftp_log, $ftp_host, $ftp_login, $ftp_pass, $lang;\r
- $ftp_error = '';\r
- $ftp_log = array();\r
- if(empty($ftp))\r
- {\r
- // checking ftp extensions\r
- if(!@function_exists('ftp_connect'))\r
- {\r
- $ftp_log[] = $ftp_error = $lang['xs_ftp_log_disabled'];\r
- return false;\r
- }\r
- // connect to server\r
- $ftp_log[] = str_replace('{HOST}', "{$ftp_login}:*@{$ftp_host}", $lang['xs_ftp_log_connecting']);\r
- $ftp = @ftp_connect($ftp_host);\r
- if(!$ftp)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{HOST}', $ftp_host, $lang['xs_ftp_log_noconnect']);\r
- return false;\r
- }\r
- $ftp_log[] = $lang['xs_ftp_log_connected'];\r
- // logging in\r
- $logged_in = @ftp_login($ftp, $ftp_login, $ftp_pass);\r
- if(!$logged_in)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{USER}', $ftp_login, $lang['xs_ftp_log_nologin']);\r
- @ftp_close($ftp);\r
- return false;\r
- }\r
- $ftp_log[] = $lang['xs_ftp_log_loggedin'];\r
- }\r
- if(!ftp_myexec2($ftp, $list))\r
- {\r
- @ftp_close($ftp);\r
- return false;\r
- }\r
- @ftp_close($ftp);\r
- $ftp_log[] = $lang['xs_ftp_log_end'];\r
- return true;\r
-}\r
-\r
-// remove all files via ftp\r
-function ftp_remove_all($ftp)\r
-{\r
- // get current directory\r
- $root_dir = @ftp_pwd($ftp);\r
- // get list of files\r
- $files = @ftp_nlist($ftp, $root_dir);\r
- // remove files/directories\r
- for($i=0; $i<count($files); $i++)\r
- {\r
- $res = @ftp_chdir($ftp, $files[$i]);\r
- if($res)\r
- {\r
- ftp_remove_all($ftp);\r
- @ftp_chdir($ftp, $root_dir);\r
- @ftp_rmdir($ftp, $files[$i]);\r
- }\r
- else\r
- {\r
- if(!@ftp_delete($ftp, $files[$i]))\r
- {\r
- @ftp_rmdir($ftp, $files[$i]);\r
- }\r
- }\r
- }\r
- // change directory back\r
- @ftp_chdir($ftp, $root_dir);\r
-}\r
-\r
-// execute ftp command. recursive.\r
-function ftp_myexec2($ftp, $list)\r
-{\r
- global $ftp_log, $ftp_error, $lang;\r
- // getting current directory\r
- $root_dir = @ftp_pwd($ftp);\r
- if($root_dir === false)\r
- {\r
- $ftp_log[] = $ftp_error = $lang['xs_ftp_log_nopwd'];\r
- return false;\r
- }\r
- $current_dir = strlen($root_dir) ? $root_dir . '/' : '';\r
- // run commands\r
- for($i=0; $i<count($list); $i++)\r
- {\r
- $item=$list[$i];\r
- if($item['command'] == 'mkdir')\r
- {\r
- // create new directory\r
- $res = @ftp_mkdir($ftp, $item['dir']);\r
- if(!$res)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_nomkdir']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_mkdir']);\r
- }\r
- }\r
- elseif($item['command'] == 'chdir')\r
- {\r
- // change current directory\r
- $res = @ftp_chdir($ftp, $item['dir']);\r
- if(!$res)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_nochdir']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_chdir']);\r
- }\r
- }\r
- elseif($item['command'] == 'cdup')\r
- {\r
- // change current directory\r
- $res = @ftp_cdup($ftp);\r
- if(!$res)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{DIR}', '..', $lang['xs_ftp_log_nochdir']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace('{DIR}', '..', $lang['xs_ftp_log_chdir']);\r
- }\r
- }\r
- elseif($item['command'] == 'rmdir')\r
- {\r
- // remove directory\r
- $res = @ftp_rmdir($ftp, $item['dir']);\r
- if(!$res)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_normdir']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_rmdir']);\r
- }\r
- }\r
- elseif($item['command'] == 'upload')\r
- {\r
- // upload file\r
- $res = @ftp_put($ftp, $current_dir . $item['remote'], $item['local'], FTP_BINARY);\r
- if(!$res)\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{FILE}', $item['remote'], $lang['xs_ftp_log_noupload']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace('{FILE}', $item['remote'], $lang['xs_ftp_log_upload']);\r
- }\r
- }\r
- elseif($item['command'] == 'chmod')\r
- {\r
- // upload file\r
- $res = @ftp_chmod($ftp, $item['mode'], $current_dir . $item['file']);\r
- if(!$res)\r
- {\r
- $ftp_log[] = str_replace('{FILE}', $item['file'], $lang['xs_ftp_log_nochmod']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace(array('{FILE}', '{MODE}'), array($item['file'], $item['mode']), $lang['xs_ftp_log_chmod']);\r
- }\r
- }\r
- elseif($item['command'] == 'exec')\r
- {\r
- $res = ftp_myexec2($ftp, $item['list']);\r
- if(!$res)\r
- {\r
- return false;\r
- }\r
- }\r
- elseif($item['command'] == 'removeall')\r
- {\r
- ftp_remove_all($ftp);\r
- }\r
- else\r
- {\r
- $ftp_log[] = str_replace('{COMMAND}', $item['command'], $lang['xs_ftp_log_invalidcommand']);\r
- if(empty($item['ignore']))\r
- {\r
- return false;\r
- }\r
- }\r
- }\r
- // changing current directory back\r
- $ftp_log[] = str_replace('{DIR}', $root_dir, $lang['xs_ftp_log_chdir2']);\r
- if(!@ftp_chdir($ftp, $root_dir))\r
- {\r
- $ftp_log[] = $ftp_error = str_replace('{DIR}', $root_dir, $lang['xs_ftp_log_nochdir2']);\r
- return false;\r
- }\r
- return true;\r
-}\r
-\r
-// return data from theme_info.cfg\r
-function xs_get_themeinfo($tpl)\r
-{\r
- // Get contents of theme_info.cfg\r
- // Run inside function to avoid theme_info.cfg accessing global variables\r
- $tpl = str_replace(array('/', '\\'), array('', ''), $tpl);\r
- include('../templates/' . $tpl . '/theme_info.cfg');\r
- return isset($$tpl) ? $$tpl : array();\r
-}\r
-\r
-// install style\r
-function xs_install_style($tpl, $num)\r
-{\r
- global $db;\r
- $data = xs_get_themeinfo($tpl);\r
- if(empty($data[$num]))\r
- {\r
- return false;\r
- }\r
- $data = $data[$num];\r
- if(empty($data['style_name']))\r
- {\r
- return false;\r
- }\r
- $sql = "SELECT themes_id FROM " . THEMES_TABLE . " WHERE style_name='" . xs_sql($data['style_name']) . "'";\r
- if(!$result = $db->sql_query($sql))\r
- {\r
- return false;\r
- }\r
- $row = $db->sql_fetchrow($result);\r
- if(!empty($row['themes_id']))\r
- {\r
- return false;\r
- }\r
- $vars = array();\r
- $values = array();\r
- foreach($data as $var => $value)\r
- {\r
- $vars[] = xs_sql($var);\r
- $values[] = xs_sql(stripslashes($value));\r
- }\r
- $sql = "INSERT INTO " . THEMES_TABLE . " (" . implode(', ', $vars) . ") VALUES ('" . implode("', '", $values) . "')";\r
- if(!$result = $db->sql_query($sql))\r
- {\r
- return false;\r
- }\r
- // recache themes table\r
- if(defined('XS_MODS_CATEGORY_HIERARCHY210'))\r
- {\r
- global $themes;\r
- if ( empty($themes) )\r
- {\r
- $themes = new themes();\r
- }\r
- if ( !empty($themes) )\r
- {\r
- $themes->read(true);\r
- }\r
- }\r
- // add configuration\r
- global $template;\r
- if($template->add_config($tpl))\r
- {\r
- define('REFRESH_NAVBAR', true);\r
- }\r
- return true;\r
-}\r
-\r
-// generate theme_info.cfg for template\r
-function xs_generate_themeinfo($theme_rowset, $export, $exportas, $total)\r
-{\r
- global $HTTP_POST_VARS;\r
- $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');\r
- $theme_data = '<?php'."\n\n";\r
- $theme_data .= "//\n// eXtreme Styles mod (compatible with phpBB 2.0.x) auto-generated theme config file for $exportas\n// Do not change anything in this file unless you know exactly what you are doing!\n//\n\n";\r
- for($i = 0; $i < count($theme_rowset); $i++)\r
- {\r
- $id = $theme_rowset[$i]['themes_id'];\r
- $theme_name = $theme_rowset[$i]['style_name'];\r
- for($j=0; $j<$total; $j++)\r
- {\r
- if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)\r
- {\r
- $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);\r
- $theme_rowset[$i]['style_name'] = $theme_name;\r
- }\r
- }\r
- for($j=0; $j<count($vars); $j++)\r
- {\r
- $key = $vars[$j];\r
- $val = $theme_rowset[$i][$key];\r
- if($key === 'style_name')\r
- {\r
- $theme_data .= '${\'' . $exportas . "'}[$i]['$key'] = \"" . str_replace(array("'", '"'), array("\'", "\\\""), $theme_name) . "\";\n";\r
- }\r
- elseif($key === 'template_name')\r
- {\r
- $theme_data .= '${\'' . $exportas . "'}[$i]['$key'] = \"" . str_replace(array("'", '"'), array("\'", "\\\""), $exportas) . "\";\n";\r
- }\r
- else\r
- {\r
- $theme_data .= '${\'' . $exportas . "'}[$i]['$key'] = \"" . str_replace(array("'", '"'), array("\'", "\\\""), str_replace($export, $exportas, $val)) . "\";\n";\r
- }\r
- }\r
- $theme_data .= "\n";\r
- }\r
- $theme_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!\r
- return $theme_data;\r
-}\r
-\r
-// Checks if directory is writable\r
-function xs_dir_writable($dir)\r
-{\r
- $filename = 'tmp_' . time();\r
- $f = @fopen($dir . $filename, 'wb');\r
- if($f)\r
- {\r
- fclose($f);\r
- @unlink($dir . $filename);\r
- return true;\r
- }\r
- return false;\r
-}\r
-\r
-// Write to file. Create directory if necessary\r
-function xs_write_file($filename, $data)\r
-{\r
- $f = @fopen($filename, 'wb');\r
- if(!$f)\r
- {\r
- // try to create directories\r
- $pos = strrpos($filename, '/');\r
- if(!$pos)\r
- {\r
- return false;\r
- }\r
- $dir = substr($filename, 0, $pos);\r
- xs_create_dir($dir);\r
- $f = @fopen($filename, 'wb');\r
- if(!$f)\r
- {\r
- return false;\r
- }\r
- }\r
- fwrite($f, $data);\r
- fclose($f);\r
- @chmod($filename, 0777);\r
- return true;\r
-}\r
-\r
-// Create local directory\r
-function xs_create_dir($dir)\r
-{\r
- if(!$dir)\r
- {\r
- return false;\r
- }\r
- // remove trailing /\r
- if(substr($dir, strlen($dir) - 1) === '/')\r
- {\r
- $dir = substr($dir, 0, strlen($dir) - 1);\r
- if(!$dir)\r
- {\r
- return false;\r
- }\r
- }\r
- if($dir === '.' || $dir === '..')\r
- {\r
- return false;\r
- }\r
- $res = @mkdir($dir, 0777);\r
- if($res)\r
- {\r
- return true;\r
- }\r
- // try to create previous directory\r
- $pos = strrpos($dir, '/');\r
- if(!$pos)\r
- {\r
- return false;\r
- }\r
- $dir1 = substr($dir, 0, $pos);\r
- $dir2 = substr($dir, $pos+1);\r
- if($dir2 === '.' || $dir2 === '..')\r
- {\r
- return false;\r
- }\r
- if(!xs_create_dir($dir1))\r
- {\r
- return false;\r
- }\r
- $res = @mkdir($dir2, 0777);\r
- return $res ? true : false;\r
-}\r
-\r
-// replacement for in_array() (because of compatibility problems)\r
-function xs_in_array($needle, $haystack)\r
-{\r
- for($i=0; $i<sizeof($haystack); $i++)\r
- {\r
- if($haystack[$i] == $needle)\r
- {\r
- return true;\r
- }\r
- }\r
- return false;\r
-}\r
-\r
-// show error and exit\r
-function xs_error($error, $line = 0, $file = '')\r
-{\r
- global $template, $lang;\r
- if($line || $file)\r
- {\r
- $error = basename($file) . '(' . $line . '): ' . $error;\r
- }\r
- $template->set_filenames(array('errormsg' => XS_TPL_PATH . 'message.tpl'));\r
- $template->assign_vars(array(\r
- 'MESSAGE_TITLE' => $lang['Error'],\r
- 'MESSAGE_TEXT' => $error\r
- ));\r
- $template->pparse('errormsg');\r
- xs_exit();\r
-}\r
-\r
-// show message and exit\r
-function xs_message($title, $message)\r
-{\r
- global $template;\r
- $template->set_filenames(array('msg' => XS_TPL_PATH . 'message.tpl'));\r
- $template->assign_vars(array(\r
- 'MESSAGE_TITLE' => $title,\r
- 'MESSAGE_TEXT' => $message\r
- ));\r
- $template->pparse('msg');\r
- xs_exit();\r
-}\r
-\r
-// pack style to .style\r
-function pack_style($name, $newname, $themes, $comment)\r
-{\r
- /*\r
- header format (v0.01):\r
- - header\r
- - header size (4 bytes)\r
- - file size (4 bytes)\r
- - number of entries (1 byte)\r
- - entries sizes (number_of_entries bytes)\r
- - entries\r
- - footer\r
- - gzcompressed tar of style (no crc check in tar)\r
-\r
- entries:\r
- - template name\r
- - comment\r
- - style names\r
- */\r
- global $phpbb_root_path, $template_dir;\r
- $data = gzcompress(pack_dir($phpbb_root_path . $template_dir . $name, '', $name, $newname));\r
- $items_data = chr(strlen($newname)) . chr(strlen($comment));\r
- $items_str = $newname . $comment;\r
- for($i=0; $i<count($themes); $i++)\r
- {\r
- $str = $themes[$i]['style_name'];\r
- $items_data .= chr(strlen($str));\r
- $items_str .= $str;\r
- }\r
- $header_size = strlen(STYLE_HEADER_START) + 8 + 1 + strlen($items_data) + strlen($items_str) + strlen(STYLE_HEADER_END);\r
- $filesize = $header_size + strlen($data);\r
- $header = STYLE_HEADER_START . pack('NN', $header_size, $filesize) . chr(strlen($items_data)) . $items_data . $items_str . STYLE_HEADER_END;\r
- return $header . $data;\r
-}\r
-\r
-// pack directory\r
-function pack_dir($dir1, $dir2, $search, $replace)\r
-{\r
- global $pack_error, $pack_list, $pack_replace, $lang;\r
- // replacements in content\r
- $search2 = array('templates/'.$search.'/'.$search, 'templates/'.$search);\r
- $replace2 = array('templates/'.$replace.'/'.$replace, 'templates/'.$replace);\r
- // replacements in filename\r
- $search3 = './'.$search;\r
- $replace3 = './'.$replace;\r
- if($pack_error)\r
- {\r
- return '';\r
- }\r
- $dir = $dir1 . '/' . $dir2;\r
- $res = @opendir($dir);\r
- $str = '';\r
- if(!$res)\r
- {\r
- $pack_error = str_replace('{DIR}', $lang['xs_export_no_open_dir'], $dir);\r
- return '';\r
- }\r
- // get list of files/directories\r
- $files = array();\r
- $subdir = array();\r
- while(($file = readdir($res)) !== false)\r
- {\r
- if($file !== '.' && $file !== '..')\r
- {\r
- if(@is_dir($dir . '/' . $file))\r
- {\r
- $subdir[] = $file;\r
- }\r
- elseif(@is_file($dir . '/' . $file))\r
- {\r
- $files[] = $file;\r
- }\r
- }\r
- }\r
- closedir($res);\r
- // add current directory\r
- $base_dir = ($dir2 ? $dir2 : '.') . '/';\r
- $header = array(\r
- 'filename' => $base_dir,\r
- 'mode' => '40777',\r
- 'uid' => '0',\r
- 'gid' => '0',\r
- 'size' => decoct(0),\r
- 'mtime' => decoct(@filemtime($dir)),\r
- 'checksum' => '0', // ignore checksum\r
- 'typeflag' => '5',\r
- 'link' => '',\r
- 'magic' => "ustar",\r
- 'version' => '',\r
- 'uname' => 'user',\r
- 'gname' => 'group',\r
- 'devmajor' => '',\r
- 'devminor' => '',\r
- 'prefix' => '',\r
- 'extra' => ''\r
- );\r
- $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']);\r
- $file_str = '';\r
- $extra_str = '';\r
- $str .= $header_str . $file_str . $extra_str;\r
- // add all files\r
- for($i=0; $i<count($files); $i++)\r
- {\r
- $file = $files[$i];\r
- $header['filename'] = $base_dir . $file;\r
- $pack_list[] = $header['filename'];\r
- if(isset($pack_replace[$header['filename']]))\r
- {\r
- $file_str = $pack_replace[$header['filename']];\r
- $file_size = strlen($file_str);\r
- }\r
- else\r
- {\r
- $f = @fopen($dir . '/' . $file, 'rb');\r
- if(!$f)\r
- {\r
- $pack_error = str_replace('{FILE}', $dir . '/' . $file, $lang['xs_export_no_open_file']);\r
- return '';\r
- }\r
- $file_size = @filesize($dir . '/' . $file);\r
- if($file_size)\r
- {\r
- $file_str = fread($f, $file_size);\r
- }\r
- else\r
- {\r
- $file_str = '';\r
- }\r
- if(strlen($file_str) != $file_size)\r
- {\r
- $pack_error = str_replace('{FILE}', $dir . '/' . $file, $lang['xs_export_no_read_file']);\r
- return '';\r
- }\r
- fclose($f);\r
- if($search !== $replace)\r
- {\r
- $file_str = str_replace($search2, $replace2, $file_str);\r
- }\r
- }\r
- if($search !== $replace && substr($header['filename'], strlen($header['filename']) - 4) !== '.tpl')\r
- {\r
- if(substr($header['filename'], 0, strlen($search)) === $search)\r
- { \r
- $header['filename'] = $replace . substr($header['filename'], strlen($search));\r
- }\r
- elseif(substr($header['filename'], 0, strlen($search3)) === $search3)\r
- { \r
- $header['filename'] = $replace3 . substr($header['filename'], strlen($search3));\r
- }\r
- }\r
-/* echo 'filename: ', $header['filename'], '<br />';\r
- if($header['filename'] === './overall_header.tpl')\r
- {\r
- echo 'overall_header.tpl:<br /><hr />', nl2br(htmlspecialchars($file_str)), '<br /><hr /><br />';\r
- }*/\r
- $size = strlen($file_str);\r
- $header['size'] = decoct($size);\r
- $header['typeflag'] = '0';\r
- $header['mode'] = '100666';\r
- $full_size = floor(($size + 511) / 512) * 512;\r
- $extra_str = $full_size > $size ? str_repeat("\0", $full_size - $size) : '';\r
- $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']);\r
- $str .= $header_str . $file_str . $extra_str;\r
- }\r
- // add all directories\r
- for($i=0; $i<count($subdir); $i++)\r
- {\r
- $str .= pack_dir($dir1, $dir2 ? $dir2 . '/' . $subdir[$i] : $subdir[$i], $search, $replace);\r
- }\r
- if(!$dir2)\r
- {\r
- $str .= str_repeat("\0", 1024);\r
- }\r
- return $str;\r
-}\r
-\r
-// save export configuration\r
-function set_export_method($method, $data)\r
-{\r
- global $db, $board_config;\r
- $data['method'] = $method;\r
- $str = xs_sql(serialize($data));\r
- $sql = isset($board_config['xs_export_data']) ? "UPDATE " . CONFIG_TABLE . " SET config_value='{$str}' WHERE config_name='xs_export_data'" : "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('xs_export_data', '{$str}')";\r
- $db->sql_query($sql);\r
-}\r
-\r
-// send file\r
-function xs_download_file($filename, $content, $content_type = '')\r
-{\r
- if(empty($content_type))\r
- {\r
- $content_type = 'application/unknown';\r
- }\r
- header('Content-Type: ' . $content_type);\r
- header('Content-Length: ' . strlen($content));\r
- header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');\r
- if($filename)\r
- {\r
- header('Content-Disposition: inline; filename="' . $filename . '"');\r
- }\r
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');\r
- header('Pragma: public');\r
- echo $content;\r
-}\r
-\r
-// strip slashes for sql\r
-function xs_sql($sql, $strip = false)\r
-{\r
- if($strip)\r
- {\r
- $sql = stripslashes($sql);\r
- }\r
- return str_replace('\\\'', '\'\'', addslashes($sql));\r
-}\r
-\r
-// clean template name\r
-function xs_tpl_name($name)\r
-{\r
- return str_replace(array('\\', '/', "'", '"'), array('','','',''), $name);\r
-}\r
-\r
-// close database and maybe do some other stuff\r
-function xs_exit()\r
-{\r
- global $db;\r
- if(isset($db))\r
- {\r
- $db->sql_close();\r
- }\r
- exit;\r
-}\r
-\r
-// check directory name/filename\r
-function xs_fix_dir($dir)\r
-{\r
- $dir = str_replace('\\', '/', $dir);\r
- $dir = str_replace('../', './', $dir);\r
- while(strlen($dir > 1) && substr($dir, strlen($dir) - 2) === '..')\r
- {\r
- $dir = substr($dir, 0, strlen($dir) - 1);\r
- }\r
- return $dir;\r
-}\r
-\r
-?>
\ No newline at end of file