/** * Constructor * Load the list with available plugins and assign them in the correct category */ public function __construct(\phpbb\titania\controller\helper $controller_helper) { $this->controller_helper = $controller_helper; $this->phpbb_root_path = \phpbb::$root_path; $this->php_ext = \phpbb::$php_ext; // Set the path $this->tool_box_path = $this->phpbb_root_path . 'ext/phpbb/titania/includes/manage_tools/'; // Load functions_admin.php if required if (!function_exists('filelist')) { include $this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext; } // Create a list with tools $filelist = filelist($this->tool_box_path, '', $this->php_ext); // Need to do some sanitization on the result of filelist foreach ($filelist as $tools) { // Don't want the extension foreach ($tools as $tool) { if (in_array($tool, $this->ignore_tools)) { continue; } $this->plugin_list[] = ($pos = strpos($tool, '.' . $this->php_ext)) !== false ? substr($tool, 0, $pos) : $tool; } } // Get the requested cat and tool $this->tool_id = phpbb::$request->variable('t', ''); // Check if they want to use a tool or not, make sure that the tool name is legal, and make sure the tool exists if (!$this->tool_id || preg_match('#([^a-zA-Z0-9_])#', $this->tool_id) || !file_exists($this->tool_box_path . $this->tool_id . '.' . $this->php_ext)) { $this->tool_id = ''; } // Make sure the form_key is set add_form_key($this->tool_id); // Assign the two menus to the template $this->gen_left_nav(); }
/** * Constructor * Load the list with available plugins and assign them in the correct category */ function manage_plugin() { // Set the path $this->tool_box_path = TITANIA_ROOT . 'includes/manage_tools/'; // Create a list with tools $filelist = filelist($this->tool_box_path, '', PHP_EXT); // Need to do some sanitization on the result of filelist foreach ($filelist as $tools) { // Don't want the extension foreach ($tools as $tool) { if (in_array($tool, $this->ignore_tools)) { continue; } $this->plugin_list[] = ($pos = strpos($tool, '.' . PHP_EXT)) !== false ? substr($tool, 0, $pos) : $tool; } } // Get the requested cat and tool $this->tool_id = request_var('t', ''); // Check if they want to use a tool or not, make sure that the tool name is legal, and make sure the tool exists if (!$this->tool_id || preg_match('#([^a-zA-Z0-9_])#', $this->tool_id) || !file_exists($this->tool_box_path . $this->tool_id . '.' . PHP_EXT)) { $this->tool_id = ''; } // Make sure the form_key is set add_form_key($this->tool_id); // Assign the two menus to the template $this->gen_left_nav(); }
protected function marker_image_select($marker, $path) { $path = $this->phpbb_extension_manager->get_extension_path('tas2580/usermap', true) . $path; if (!function_exists('filelist')) { include $this->phpbb_root_path . '/includes/functions_admin.' . $this->php_ext; } $imglist = filelist($path); $edit_img = $filename_list = ''; foreach ($imglist as $path => $img_ary) { sort($img_ary); foreach ($img_ary as $img) { $img = $path . $img; if ($img == $marker) { $selected = ' selected="selected"'; $edit_img = $img; } else { $selected = ''; } if (strlen($img) > 255) { continue; } $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>'; } } return '<option value=""' . ($edit_img == '' ? ' selected="selected"' : '') . '>----------</option>' . $filename_list; }
/** * Add file to archive */ function add_file($src, $src_rm_prefix = '', $src_add_prefix = '', $skip_files = '') { global $phpbb_root_path; $skip_files = explode(',', $skip_files); // Remove rm prefix from src path $src_path = ($src_rm_prefix) ? preg_replace('#^(' . preg_quote($src_rm_prefix, '#') . ')#', '', $src) : $src; // Add src prefix $src_path = ($src_add_prefix) ? ($src_add_prefix . ((substr($src_add_prefix, -1) != '/') ? '/' : '') . $src_path) : $src_path; // Remove initial "/" if present $src_path = (substr($src_path, 0, 1) == '/') ? substr($src_path, 1) : $src_path; if (is_file($phpbb_root_path . $src)) { $this->data($src_path, file_get_contents("$phpbb_root_path$src"), false, stat("$phpbb_root_path$src")); } else if (is_dir($phpbb_root_path . $src)) { // Clean up path, add closing / if not present $src_path = ($src_path && substr($src_path, -1) != '/') ? $src_path . '/' : $src_path; $filelist = array(); $filelist = filelist("$phpbb_root_path$src", '', '*'); krsort($filelist); if ($src_path) { $this->data($src_path, '', true, stat("$phpbb_root_path$src")); } foreach ($filelist as $path => $file_ary) { if ($path) { // Same as for src_path $path = (substr($path, 0, 1) == '/') ? substr($path, 1) : $path; $path = ($path && substr($path, -1) != '/') ? $path . '/' : $path; $this->data("$src_path$path", '', true, stat("$phpbb_root_path$src$path")); } foreach ($file_ary as $file) { if (in_array($path . $file, $skip_files)) { continue; } $this->data("$src_path$path$file", file_get_contents("$phpbb_root_path$src$path$file"), false, stat("$phpbb_root_path$src$path$file")); } } } return true; }
/** * Add file to archive */ function add_file($src, $src_rm_prefix = '', $src_add_prefix = '', $skip_files = '') { global $phpbb_root_path; $skip_files = explode(',', $skip_files); // Remove rm prefix from src path $src_path = $src_rm_prefix ? preg_replace('#^(' . preg_quote($src_rm_prefix, '#') . ')#', '', $src) : $src; // Add src prefix $src_path = $src_add_prefix ? $src_add_prefix . (substr($src_add_prefix, -1) != '/' ? '/' : '') . $src_path : $src_path; // Remove initial "/" if present $src_path = substr($src_path, 0, 1) == '/' ? substr($src_path, 1) : $src_path; if (is_file($phpbb_root_path . $src)) { $this->data($src_path, file_get_contents("{$phpbb_root_path}{$src}"), false, stat("{$phpbb_root_path}{$src}")); } else { if (is_dir($phpbb_root_path . $src)) { // Clean up path, add closing / if not present $src_path = $src_path && substr($src_path, -1) != '/' ? $src_path . '/' : $src_path; $filelist = array(); $filelist = filelist("{$phpbb_root_path}{$src}", '', '*'); krsort($filelist); /** * Commented out, as adding the folders produces corrupted archives if ($src_path) { $this->data($src_path, '', true, stat("$phpbb_root_path$src")); } */ foreach ($filelist as $path => $file_ary) { /** * Commented out, as adding the folders produces corrupted archives if ($path) { // Same as for src_path $path = (substr($path, 0, 1) == '/') ? substr($path, 1) : $path; $path = ($path && substr($path, -1) != '/') ? $path . '/' : $path; $this->data("$src_path$path", '', true, stat("$phpbb_root_path$src$path")); } */ foreach ($file_ary as $file) { if (in_array($path . $file, $skip_files)) { continue; } $this->data("{$src_path}{$path}{$file}", file_get_contents("{$phpbb_root_path}{$src}{$path}{$file}"), false, stat("{$phpbb_root_path}{$src}{$path}{$file}")); } } } else { // $src does not exist return false; } } return true; }
function repair() { global $db; $stylelist = filelist(PHPBB_ROOT_PATH . 'styles/', '', 'cfg'); ksort($stylelist); // Loop throught the files and try to find a style we can use. // To be usable the directory name in the style.cfg is the same as the directory. foreach (array_keys($stylelist) as $styledirname) { if (!in_array('style.cfg', $stylelist[$styledirname])) { continue; } // Read the cfg, should always be index 0 $items = parse_cfg_file(PHPBB_ROOT_PATH . 'styles/' . $styledirname . 'style.cfg'); // Unify the name in the cfg to something used as a directory // Spaces -> '_' // All lowercase $stylename = utf8_clean_string(str_replace(' ', '_', $items['name'])); // Clean up the dirname $dirname = substr($styledirname, -1) == '/' ? substr($styledirname, 0, -1) : $styledirname; // If not the same switch to the next one if ($dirname != $stylename) { continue; } // If this style isn't installed we will install the style at this point. $sql = 'SELECT style_id FROM ' . STYLES_TABLE . "\n\t\t\t\tWHERE style_name = '" . $db->sql_escape($items['name']) . "'"; $result = $db->sql_query($sql); $this->sid = $db->sql_fetchfield('style_id', false, $result); $db->sql_freeresult($result); if (empty($this->sid)) { // Nasty, but the style installer fetches these in the method o_0 $GLOBALS['_REQUEST']['path'] = $stylename; $GLOBALS['_POST']['update'] = true; // Call the style installer $this->ac->install('style'); // Fetch the id $sql = 'SELECT style_id FROM ' . STYLES_TABLE . "\n\t\t\t\t\tWHERE style_name = '" . $db->sql_escape($items['name']) . "'"; $result = $db->sql_query($sql); $this->sid = $db->sql_fetchfield('style_id', false, $result); $db->sql_freeresult($result); } // Set this style as the active style set_config('default_style', $this->sid); set_config('override_user_style', 1); // Overriding the style should enable the board for everyone return; } echo 'The support toolkit couldn\'t find an available style. Please seek further assistance in the support forums on <a href="http://www.phpbb.com/community/viewforum.php?f=46" title="phpBB.com Support forum">phpbb.com</a>'; garbage_collection(); exit_handler(); }
/** * Constructor * Load the list with available plugins and assign them in the correct category */ function plugin() { // Set the path $this->tool_box_path = STK_ROOT_PATH . 'tools/'; // Create a list with tools $filelist = filelist($this->tool_box_path, '', PHP_EXT); // Need to do some sanitization on the result of filelist foreach ($filelist as $cat => $tools) { // Don't need those if (empty($cat)) { continue; } $cat = substr($cat, -1) == '/' ? substr($cat, 0, -1) : $cat; if (!isset($this->plugin_list[$cat])) { $this->plugin_list[$cat] = array(); } // Don't want the extension foreach ($tools as $key => $tool) { $tools[$key] = ($pos = strpos($tool, '.' . PHP_EXT)) !== false ? substr($tool, 0, $pos) : $tool; } $this->plugin_list[$cat] = $tools; } // Get the requested cat and tool $this->_parts['c'] = request_var('c', $this->_parts['c']); $this->_parts['t'] = request_var('t', $this->_parts['t']); // We shouldn't rely on the given category request, unless there really is a tool with that name in the given category if ($this->_parts['t'] && (!isset($this->plugin_list[$this->_parts['c']]) || !in_array($this->_parts['t'], $this->plugin_list[$this->_parts['c']]))) { foreach ($this->plugin_list as $cat => $tools) { foreach ($tools as $tool) { if ($tool == $this->_parts['t']) { $this->_parts['c'] = $cat; } } } } // Check if they want to use a tool or not, make sure that the tool name is legal, and make sure the tool exists if (!$this->_parts['t'] || preg_match('#([^a-zA-Z0-9_])#', $this->_parts['t']) || !file_exists(STK_ROOT_PATH . 'tools/' . $this->_parts['c'] . '/' . $this->_parts['t'] . '.' . PHP_EXT)) { $this->_parts['t'] = ''; } // Make sure the form_key is set add_form_key($this->_parts['t']); // Assign the two menus to the template $this->gen_top_nav(); $this->gen_left_nav(); }
function filelist($folderRoot, $folder = '') { $handle = opendir($folderRoot . '/' . $folder); while ($file = readdir($handle)) { if (is_dir($folderRoot . '/' . $folder . '/' . $file)) { if ($file == '.' || $file == '..') { } else { $p = $file; if ($folder > '') { $p = $folder . '/' . $p; } filelist($folderRoot, $p); } } else { $filehex = $folder . '/' . $file . "\t" . crc32_file3($folderRoot . '/' . $folder . '/' . $file); $GLOBALS['filehexlist'] .= $filehex . "\r\n"; } } }
function filelist() { //返回主题文件路径 $dir = APP_ROOT . "/User/Home/View"; //主题目录 $list = scandir($dir); foreach ($list as $file) { //遍历 $path = $dir . "/" . $file; if (is_dir($path) && $file != "." && $file != "..") { //判断是否是路径 filelist($path); } else { if ($this->extend($file) == "html") { $rs[] = array("file" => $file, "path" => $path); } } } return $rs; }
function filelist($folderRoot,$folder=''){ $handle=opendir($folderRoot.'/'.$folder); while($file=readdir($handle)){ //if($folder=='.'){ // $path=$file; //}else{ $path=$folderRoot.'/'.$folder.'/'.$file; //} if(is_dir($path)){ if($file=='.'||$file=='..'){ }else{ filelist($folderRoot,$path); } }else{ $pathx=$folder.'/'.$file; $filehex=$pathx."\t".crc32_file3($path); $GLOBALS['filehexlist'].=$filehex."\r\n"; } } }
function filelist($startdir = "./", $searchSubdirs = 0, $directoriesonly = 1, $maxlevel = "1", $level = 1) { //list the directory/file names that you want to ignore $ignoredDirectory[] = "."; $ignoredDirectory[] = ".."; $ignoredDirectory[] = "_vti_cnf"; global $directorylist; //initialize global array if (is_dir($startdir)) { if ($dh = opendir($startdir)) { while (($file = readdir($dh)) !== false) { if (!(array_search($file, $ignoredDirectory) > -1)) { if (filetype($startdir . $file) == "dir") { //build your directory array however you choose; //add other file details that you want. $directorylist[$startdir . $file]['level'] = $level; $directorylist[$startdir . $file]['dir'] = 1; $directorylist[$startdir . $file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir; if ($searchSubdirs) { if ($maxlevel == "all" or $maxlevel > $level) { filelist($startdir . $file . "/", $searchSubdirs, $directoriesonly, $maxlevel, $level + 1); } } } else { if (!$directoriesonly) { //if you want to include files; build your file array //however you choose; add other file details that you want. $directorylist[$startdir . $file]['level'] = $level; $directorylist[$startdir . $file]['dir'] = 0; $directorylist[$startdir . $file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir; } } } } closedir($dh); } } return $directorylist; }
/** * Construct critical repair. * This method loads all critical repair tools * @return void */ function critical_repair() { $this->tool_path = STK_ROOT_PATH . 'includes/critical_repair/'; $filelist = filelist($this->tool_path, '', PHP_EXT); foreach ($filelist as $directory => $tools) { if ($directory != 'autorun/') { if (sizeof($tools)) { foreach ($tools as $tool) { $this->manual_tools[] = substr($tool, 0, strpos($tool, '.')); } } } else { if (sizeof($tools)) { foreach ($tools as $tool) { $this->autorun_tools[] = substr($tool, 0, strpos($tool, '.')); } } } } return true; }
/** * Moves a template set to the database * * @access private * @param string $mode The component to move - only template is supported * @param int $id The template id * @param string $path TThe path to the template files */ function _store_in_db($mode, $id, $path) { global $phpbb_root_path, $db; $filelist = filelist("{$phpbb_root_path}styles/{$path}/template", '', 'html'); $this->store_templates('insert', $id, $path, $filelist); // Okay, we do the query here -shouldn't be triggered often. $sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . ' SET template_storedb = 1 WHERE template_id = ' . $id; $db->sql_query($sql); }
} //file letoltes vege /** * ha a listat mutatjuk */ if ($act == "lst") { include_once $include_dir . '/function.downloads.php'; if (isset($_REQUEST['parent'])) { $parent = intval($_REQUEST['parent']); } else { $parent = 0; } //kiszamoljuk, hogy hany mappa van a rendszerben $query = "\n\t\tSELECT *\n\t\tFROM iShark_Downloads \n\t\tWHERE type = 'D' AND is_active = 1\n\t"; $result = $mdb2->query($query); $cdir = $result->numRows(); //kiszamoljuk, hogy hany file van a rendszerben $query = "\n\t\tSELECT *\n\t\tFROM iShark_Downloads \n\t\tWHERE type = 'F' AND is_active = 1\n\t"; $result = $mdb2->query($query); $cfile = $result->numRows(); $dir = get_aktdir($parent); //atadjuk a smarty-nak a valtozokat $tpl->assign('dirlist', filelist($dir['dir'], 'name', $parent, 1)); $tpl->assign('menu_id', $menu_id); $tpl->assign('act_dir', $dir['dir']); $tpl->assign('cdir', $cdir); $tpl->assign('cfile', $cfile); $tpl->assign('dirsumsize', get_dirsumsize()); //megadjuk a tpl file nevet, amit atadunk az admin.php-nek $acttpl = 'download_list'; }
if ($merken != DATABASE) { $db->selectDB(DATABASE, ""); } $where = ""; foreach ($array as $value) { if ($where != "") { $where .= " OR "; } $where .= "fid = '" . $value . "'"; } $sql = "SELECT *\n FROM site_file\n WHERE " . $where . "\n ORDER BY ffname, funder"; $result = $db->query($sql); if ($merken != DATABASE) { $db->selectDB($merken, ""); } filelist($result, "contented"); } if (is_array($_SESSION["compilation_memo"])) { foreach ($_SESSION["compilation_memo"] as $compid => $value) { $pics = implode(":", $value); $dataloop["selection"][] = array("id" => $compid, "pics" => $pics, "onclick" => "ebInsertSelNG(ebCanvas, '" . $compid . "', '" . $cfg["contented"]["sel_tag"][0] . "', '" . $cfg["contented"]["sel_tag"][1] . "', '" . $pics . "', '" . $cfg["contented"]["sel_tag"][2] . "', '" . $cfg["contented"]["sel_tag"][3] . "');"); } if (count($dataloop["selection"]) > 0) { $hidedata["selection"] = array(); } } // template version $art = ""; } // referer im form mit hidden element mitschleppen if ($HTTP_GET_VARS["referer"] != "") {
/** * Run the tool * This tool will run through the files and all files that are new, or of * which the last change date has been changed will be checked for invalid * characters. */ function run() { global $critical_repair, $stk_config; // Get all the files $filelist = filelist(PHPBB_ROOT_PATH, '', PHP_EXT); foreach ($filelist as $directory => $files) { // As the install dir can be renamed, we need to check here whether this // is an install directory if (in_array('convert_phpbb20.' . PHP_EXT, $files) || in_array('new_normalizer.' . PHP_EXT, $files) || in_array('database_update.' . PHP_EXT, $files)) { // It is and we're not forcing a full scan, skip it if (!$stk_config['bom_sniffer_force_full_scan']) { continue; } } // Step into the files if (!empty($files)) { // Test whether we're sniffing a language directory (any) $lang_test_dir = ''; $lang_matches = array(); if (preg_match('#language/([a-zA-Z\\-_]+)/#ise', $directory, $lang_matches)) { $lang_test_dir = str_replace($lang_matches[1], '..', $directory); } foreach ($files as $file) { // If this is inside a language directory we need to check whether this file is // in the whitelist and adjust the whitelist to include it $sniff_lang_file = false; if (!empty($lang_test_dir)) { $sniff_lang_file = in_array($lang_test_dir . $file, $this->whitelist) ? true : false; } // Test this file against the whitelist if (!$stk_config['bom_sniffer_force_full_scan'] && (!in_array($directory . $file, $this->whitelist) && $sniff_lang_file === false)) { continue; } else { if (!isset($this->cache->cache_data[$directory . $file]) || filectime(PHPBB_ROOT_PATH . $directory . $file) != $this->cache->cache_data[$directory . $file] || !$stk_config['bom_sniffer_force_full_scan']) { $this->sniff($directory, $file); } } } } } // Once finished always write the new data back to the cache file $this->cache->storedata(); // Inform the user what to do if we've created files if (is_dir(PHPBB_ROOT_PATH . 'store/bom_sniffer')) { $critical_repair->trigger_error($this->messages['issue_found']); } }
function BuildContentPage() { global $groupmode, $phpvars, $page, $logpage, $postlogpage, $GroupModeRefreshInterval, $FileModeRefreshInterval, $FileModeLog, $historymode, $hasusermenu; if ($groupmode) { currently_downloading($phpvars); queued_downloading($phpvars, $page); currently_processing($phpvars, $postlogpage); queued_processing($phpvars); historymain($phpvars); logging($phpvars, $logpage); } elseif ($historymode) { history($phpvars, $page); } else { filelist($phpvars, $page); if ($FileModeLog) { echo '<br>'; logging($phpvars, $logpage); } } serverinfobox($phpvars); servercommandbox($phpvars); if ($hasusermenu) { usermenu($phpvars); } echo '<div style="display: none" id="updateinterval">' . ($groupmode ? $GroupModeRefreshInterval : $FileModeRefreshInterval) . '</div>'; echo '<div style="display: none" id="downloadlimit">' . $phpvars['status']['DownloadLimit'] / 1024 . '</div>'; if (isset($_COOKIE['upload_status'])) { echo '<div style="display: none" id="uploadstatushidden">' . $_COOKIE['upload_status'] . '</div>'; } if (isset($_COOKIE['newzbin_status'])) { echo '<div style="display: none" id="newzbinstatushidden">' . $_COOKIE['newzbin_status'] . '</div>'; } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $safe_mode, $file_uploads; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; $this->default_variables(); // Check and set some common vars $action = request_var('action', ''); $action = isset($_POST['update_details']) ? 'update_details' : $action; $action = isset($_POST['download_file']) ? 'download_file' : $action; $action = isset($_POST['upload_file']) ? 'upload_file' : $action; $action = isset($_POST['upload_data']) ? 'upload_data' : $action; $action = isset($_POST['submit_file']) ? 'submit_file' : $action; $action = isset($_POST['remove_store']) ? 'details' : $action; $lang_id = request_var('id', 0); if (isset($_POST['missing_file'])) { $missing_file = request_var('missing_file', array('' => 0)); list($_REQUEST['language_file'], ) = array_keys($missing_file); } list($this->language_directory, $this->language_file) = explode('|', request_var('language_file', '|common.' . $phpEx)); $this->language_directory = basename($this->language_directory); $this->language_file = basename($this->language_file); $user->add_lang('acp/language'); $this->tpl_name = 'acp_language'; $this->page_title = 'ACP_LANGUAGE_PACKS'; if ($action == 'upload_data' && request_var('test_connection', '')) { $test_connection = false; $action = 'upload_file'; $method = request_var('method', ''); include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; switch ($method) { case 'ftp': $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; default: trigger_error($user->lang['INVALID_UPLOAD_METHOD']); } $test_connection = $transfer->open_session(); $transfer->close_session(); } switch ($action) { case 'upload_file': include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; $method = request_var('method', ''); $requested_data = call_user_func(array($method, 'data')); foreach ($requested_data as $data => $default) { $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default)); } $entry = $_POST['entry']; foreach ($entry as $key => $value) { if (is_array($value)) { foreach ($value as $key2 => $data) { $entry[$key][$key2] = htmlentities($data); } } else { $entry[$key] = htmlentities($value); } } $hidden_data = build_hidden_fields(array('file' => $this->language_file, 'dir' => $this->language_directory, 'method' => $method, 'entry' => $entry)); $template->assign_vars(array('S_UPLOAD' => true, 'NAME' => $method, 'U_ACTION' => $this->u_action . "&id={$lang_id}&action=upload_data", 'HIDDEN' => $hidden_data, 'S_CONNECTION_SUCCESS' => request_var('test_connection', '') && $test_connection === true ? true : false, 'S_CONNECTION_FAILED' => request_var('test_connection', '') && $test_connection !== true ? true : false)); break; case 'update_details': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action)); } $sql = 'SELECT * FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_id = {$lang_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $sql_ary = array('lang_english_name' => request_var('lang_english_name', $row['lang_english_name']), 'lang_local_name' => request_var('lang_local_name', $row['lang_local_name'], true), 'lang_author' => request_var('lang_author', $row['lang_author'], true)); $db->sql_query('UPDATE ' . LANG_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE lang_id = ' . $lang_id); add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']); trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action)); break; case 'submit_file': case 'download_file': case 'upload_data': if (!$lang_id || !isset($_POST['entry']) || !is_array($_POST['entry'])) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action)); } if (!$this->language_file || !$this->language_directory && !in_array($this->language_file, $this->main_files)) { trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action)); } $sql = 'SELECT * FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_id = {$lang_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$safe_mode) { $mkdir_ary = array('language', 'language/' . $row['lang_iso']); if ($this->language_directory) { $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory; } foreach ($mkdir_ary as $dir) { $dir = $phpbb_root_path . 'store/' . $dir; if (!is_dir($dir)) { if (!@mkdir($dir, 0777)) { trigger_error("Could not create directory {$dir}"); } @chmod($dir, 0777); } } } // Get target filename for storage folder $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true); $fp = fopen($phpbb_root_path . $filename, 'wb'); if (!$fp) { trigger_error($user->lang['UNABLE_TO_WRITE_FILE']); } if ($this->language_directory == 'email') { // Email Template $entry = STRIP ? stripslashes($_POST['entry']) : $_POST['entry']; $entry = preg_replace('#&(\\#[0-9]+;)#', '&\\1', $entry); fwrite($fp, $entry); } else { $name = ($this->language_directory ? $this->language_directory . '_' : '') . $this->language_file; $header = str_replace(array('{FILENAME}', '{LANG_NAME}', '{CHANGED}', '{AUTHOR}'), array($name, $row['lang_english_name'], date('Y-m-d', time()), $row['lang_author']), $this->language_file_header); if (strpos($this->language_file, 'help_') === 0) { // Help File $header .= '$help = array(' . "\n"; fwrite($fp, $header); foreach ($_POST['entry'] as $key => $value) { if (!is_array($value)) { } else { $entry = "\tarray(\n"; foreach ($value as $_key => $_value) { $_value = STRIP ? stripslashes($_value) : $_value; $_value = preg_replace('#&(\\#[0-9]+;)#', '&\\1', $_value); $entry .= "\t\t" . (int) $_key . "\t=> '" . str_replace("'", "\\'", $_value) . "',\n"; } $entry .= "\t),\n"; } fwrite($fp, $entry); } } else { // Language File $header .= $this->lang_header; fwrite($fp, $header); foreach ($_POST['entry'] as $key => $value) { if (!is_array($value)) { $value = STRIP ? stripslashes($value) : $value; $value = preg_replace('#&(\\#[0-9]+;)#', '&\\1', $value); $entry = "\t'" . $key . "'\t=> '" . str_replace("'", "\\'", $value) . "',\n"; } else { $entry = "\n\t'" . $key . "'\t=> array(\n"; foreach ($value as $_key => $_value) { $_value = STRIP ? stripslashes($_value) : $_value; $_value = preg_replace('#&(\\#[0-9]+;)#', '&\\1', $_value); $entry .= "\t\t'" . $_key . "'\t=> '" . str_replace("'", "\\'", $_value) . "',\n"; } $entry .= "\t),\n\n"; } fwrite($fp, $entry); } } $footer = "));\n\n?>"; fwrite($fp, $footer); } fclose($fp); if ($action == 'download_file') { header('Pragma: no-cache'); header('Content-Type: application/octetstream; name="' . $this->language_file . '"'); header('Content-disposition: attachment; filename=' . $this->language_file); $fp = fopen($phpbb_root_path . $filename, 'rb'); while ($buffer = fread($fp, 1024)) { echo $buffer; } fclose($fp); exit; } else { if ($action == 'upload_data') { $sql = 'SELECT lang_iso FROM ' . LANG_TABLE . "\n\t\t\t\t\t\tWHERE lang_id = {$lang_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $file = request_var('file', ''); $dir = request_var('dir', ''); $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true); $lang_path = 'language/' . $row['lang_iso'] . '/' . ($dir ? $dir . '/' : ''); include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; $method = request_var('method', ''); switch ($method) { case 'ftp': $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; default: trigger_error($user->lang['INVALID_UPLOAD_METHOD']); } if (($result = $transfer->open_session()) !== true) { trigger_error($user->lang[$result] . adm_back_link($this->u_action)); } $transfer->rename($lang_path . $file, $lang_path . $file . '.bak'); $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file); $transfer->close_session(); add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file); trigger_error($user->lang['UPLOAD_COMPLETED']); } } $action = 'details'; // no break; // no break; case 'details': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action)); } $this->page_title = 'LANGUAGE_PACK_DETAILS'; $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $result = $db->sql_query($sql); $lang_entries = $db->sql_fetchrow($result); $db->sql_freeresult($result); $lang_iso = $lang_entries['lang_iso']; $missing_vars = $missing_files = array(); // Get email templates $email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt'); $email_files = $email_files['email/']; // Get acp files $acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx); $acp_files = $acp_files['acp/']; // Get mod files $mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx); $mods_files = isset($mods_files['mods/']) ? $mods_files['mods/'] : array(); // Check if our current filename matches the files switch ($this->language_directory) { case 'email': if (!in_array($this->language_file, $email_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id)); } break; case 'acp': if (!in_array($this->language_file, $acp_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id)); } break; case 'mods': if (!in_array($this->language_file, $mods_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id)); } break; default: if (!in_array($this->language_file, $this->main_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id)); } } if (isset($_POST['remove_store'])) { $store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true); @unlink($phpbb_root_path . $store_filename); } include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; $methods = transfer::methods(); foreach ($methods as $method) { $template->assign_block_vars('buttons', array('VALUE' => $method)); } $template->assign_vars(array('S_DETAILS' => true, 'U_ACTION' => $this->u_action . "&action=details&id={$lang_id}", 'U_BACK' => $this->u_action, 'LANG_LOCAL_NAME' => $lang_entries['lang_local_name'], 'LANG_ENGLISH_NAME' => $lang_entries['lang_english_name'], 'LANG_ISO' => $lang_entries['lang_iso'], 'LANG_AUTHOR' => $lang_entries['lang_author'], 'ALLOW_UPLOAD' => sizeof($methods))); // If current lang is different from the default lang, then first try to grab missing/additional vars if ($lang_iso != $config['default_lang']) { $is_missing_var = false; foreach ($this->main_files as $file) { if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file))) { $missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file); if (sizeof($missing_vars[$file])) { $is_missing_var = true; } } else { $missing_files[] = $this->get_filename($lang_iso, '', $file); } } // Now go through acp/mods directories foreach ($acp_files as $file) { if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file))) { $missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file); if (sizeof($missing_vars['acp/' . $file])) { $is_missing_var = true; } } else { $missing_files[] = $this->get_filename($lang_iso, 'acp', $file); } } if (sizeof($mods_files)) { foreach ($mods_files as $file) { if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file))) { $missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file); if (sizeof($missing_vars['mods/' . $file])) { $is_missing_var = true; } } else { $missing_files[] = $this->get_filename($lang_iso, 'mods', $file); } } } // More missing files... for example email templates? foreach ($email_files as $file) { if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file))) { $missing_files[] = $this->get_filename($lang_iso, 'email', $file); } } if (sizeof($missing_files)) { $template->assign_vars(array('S_MISSING_FILES' => true, 'L_MISSING_FILES' => sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']), 'MISSING_FILES' => implode('<br />', $missing_files))); } if ($is_missing_var) { $template->assign_vars(array('S_MISSING_VARS' => true, 'L_MISSING_VARS_EXPLAIN' => sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']), 'U_MISSING_ACTION' => $this->u_action . "&action={$action}&id={$lang_id}")); foreach ($missing_vars as $file => $vars) { if (!sizeof($vars)) { continue; } $template->assign_block_vars('missing', array('FILE' => $file, 'TPL' => $this->print_language_entries($vars, '', false), 'KEY' => strpos($file, '/') === false ? '|' . $file : str_replace('/', '|', $file))); } } } // Main language files $s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>'; foreach ($this->main_files as $file) { if (strpos($file, 'help_') === 0) { continue; } $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true)) ? '* ' : ''; $selected = !$this->language_directory && $this->language_file == $file ? ' selected="selected"' : ''; $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>'; } // Help Files $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>'; foreach ($this->main_files as $file) { if (strpos($file, 'help_') !== 0) { continue; } $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true)) ? '* ' : ''; $selected = !$this->language_directory && $this->language_file == $file ? ' selected="selected"' : ''; $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>'; } // Now every other language directory $check_files = array('email', 'acp', 'mods'); foreach ($check_files as $check) { if (!sizeof(${$check . '_files'})) { continue; } $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>'; foreach (${$check . '_files'} as $file) { $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true)) ? '* ' : ''; $selected = $this->language_directory == $check && $this->language_file == $file ? ' selected="selected"' : ''; $s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>'; } } // Get Language Entries - if saved within store folder, we take this one (with the option to remove it) $lang = array(); $is_email_file = $this->language_directory == 'email' ? true : false; $is_help_file = strpos($this->language_file, 'help_') === 0 ? true : false; $file_from_store = file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true)) ? true : false; $no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file); if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename)) { $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename); } else { if ($is_email_file) { $lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store)); } else { $help = array(); include $phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store); if ($is_help_file) { $lang = $help; unset($help); } } $print_message = ($this->language_directory ? $this->language_directory . '/' : '') . $this->language_file; } // Normal language pack entries $template->assign_vars(array('U_ENTRY_ACTION' => $this->u_action . "&action=details&id={$lang_id}#entries", 'S_EMAIL_FILE' => $is_email_file, 'S_FROM_STORE' => $file_from_store, 'S_LANG_OPTIONS' => $s_lang_options, 'PRINT_MESSAGE' => $print_message)); if (!$is_email_file) { $method = $is_help_file ? 'print_help_entries' : 'print_language_entries'; $tpl = ''; $name = ($this->language_directory ? $this->language_directory . '/' : '') . $this->language_file; if (isset($missing_vars[$name]) && sizeof($missing_vars[$name])) { $tpl .= $this->{$method}($missing_vars[$name], '* '); } $tpl .= $this->{$method}($lang); $template->assign_var('TPL', $tpl); unset($tpl); } else { $template->assign_vars(array('LANG' => $lang)); unset($lang); } return; break; case 'delete': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action)); } $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row['lang_iso'] == $config['default_lang']) { trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action)); } $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id); $sql = 'UPDATE ' . USERS_TABLE . " \n\t\t\t\t\tSET user_lang = '{$config['default_lang']}'\n\t\t\t\t\tWHERE user_lang = '{$row['lang_iso']}'"; $db->sql_query($sql); add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']); trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action)); break; case 'install': $lang_iso = request_var('iso', ''); $lang_iso = basename($lang_iso); if (!$lang_iso || !file_exists("{$phpbb_root_path}language/{$lang_iso}/iso.txt")) { trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action)); } $file = file("{$phpbb_root_path}language/{$lang_iso}/iso.txt"); $lang_pack = array('iso' => $lang_iso, 'name' => trim(htmlspecialchars($file[0])), 'local_name' => trim(htmlspecialchars($file[1])), 'author' => trim(htmlspecialchars($file[2]))); unset($file); $sql = 'SELECT lang_iso FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action)); } $db->sql_freeresult($result); if (!$lang_pack['name'] || !$lang_pack['local_name']) { trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action)); } // Add language pack $sql_ary = array('lang_iso' => $lang_pack['iso'], 'lang_dir' => $lang_pack['iso'], 'lang_english_name' => $lang_pack['name'], 'lang_local_name' => $lang_pack['local_name'], 'lang_author' => $lang_pack['author']); $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']); trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']) . adm_back_link($this->u_action)); break; case 'download': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action)); } $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $use_method = request_var('use_method', ''); $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } // Let the user decide in which format he wants to have the pack if (!$use_method) { $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; $radio_buttons = ''; foreach ($methods as $method) { $radio_buttons .= '<input type="radio"' . (!$radio_buttons ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . ' '; } $template->assign_vars(array('S_SELECT_METHOD' => true, 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . "&action={$action}&id={$lang_id}", 'RADIO_BUTTONS' => $radio_buttons)); return; } if (!in_array($use_method, $methods)) { $use_method = '.tar'; } include_once $phpbb_root_path . 'includes/functions_compress.' . $phpEx; if ($use_method == 'zip') { $compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method); } else { $compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method); } // Get email templates $email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt'); $email_templates = $email_templates['email/']; // Get acp files $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx); $acp_files = $acp_files['acp/']; // Get mod files $mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx); $mod_files = isset($mod_files['mods/']) ? $mod_files['mods/'] : array(); // Add main files $this->add_to_archive($compress, $this->main_files, $row['lang_iso']); // Write files in folders $this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email'); $this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp'); $this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods'); // Write ISO File $iso_src = html_entity_decode($row['lang_english_name']) . "\n"; $iso_src .= html_entity_decode($row['lang_local_name']) . "\n"; $iso_src .= html_entity_decode($row['lang_author']); $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt'); // index.html files $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html'); $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html'); $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html'); if (sizeof($mod_files)) { $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html'); } $compress->close(); $compress->download('lang_' . $row['lang_iso']); @unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . '.' . $use_method); exit; break; } $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count FROM ' . USERS_TABLE . ' GROUP BY user_lang'; $result = $db->sql_query($sql); $lang_count = array(); while ($row = $db->sql_fetchrow($result)) { $lang_count[$row['user_lang']] = $row['lang_count']; } $db->sql_freeresult($result); $sql = 'SELECT * FROM ' . LANG_TABLE; $result = $db->sql_query($sql); $installed = array(); while ($row = $db->sql_fetchrow($result)) { $installed[] = $row['lang_iso']; $tagstyle = $row['lang_iso'] == $config['default_lang'] ? '*' : ''; $template->assign_block_vars('lang', array('U_DETAILS' => $this->u_action . "&action=details&id={$row['lang_id']}", 'U_DOWNLOAD' => $this->u_action . "&action=download&id={$row['lang_id']}", 'U_DELETE' => $this->u_action . "&action=delete&id={$row['lang_id']}", 'ENGLISH_NAME' => $row['lang_english_name'], 'TAG' => $tagstyle, 'LOCAL_NAME' => $row['lang_local_name'], 'ISO' => $row['lang_iso'], 'USED_BY' => isset($lang_count[$row['lang_iso']]) ? $lang_count[$row['lang_iso']] : 0)); } $db->sql_freeresult($result); $new_ary = $iso = array(); $dp = opendir("{$phpbb_root_path}language"); while (($file = readdir($dp)) !== false) { if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/{$file}/iso.txt")) { if (!in_array($file, $installed)) { if ($iso = file("{$phpbb_root_path}language/{$file}/iso.txt")) { if (sizeof($iso) == 3) { $new_ary[$file] = array('iso' => $file, 'name' => trim($iso[0]), 'local_name' => trim($iso[1]), 'author' => trim($iso[2])); } } } } } unset($installed); @closedir($dp); if (sizeof($new_ary)) { foreach ($new_ary as $iso => $lang_ary) { $template->assign_block_vars('notinst', array('ISO' => $lang_ary['iso'], 'LOCAL_NAME' => $lang_ary['local_name'], 'NAME' => $lang_ary['name'], 'U_INSTALL' => $this->u_action . '&action=install&iso=' . urlencode($lang_ary['iso']))); } } unset($new_ary); }
function main($id, $mode) { global $db, $user, $template, $cache; global $config, $phpbb_root_path; global $request, $phpbb_container; $user->add_lang('acp/posting'); // Set up general vars $action = $request->variable('action', ''); $action = isset($_POST['add']) ? 'add' : $action; $action = isset($_POST['edit']) ? 'edit' : $action; $action = isset($_POST['import']) ? 'import' : $action; $icon_id = $request->variable('id', 0); $submit = $request->is_set_post('submit', false); $form_key = 'acp_icons'; add_form_key($form_key); $mode = $mode == 'smilies' ? 'smilies' : 'icons'; $this->tpl_name = 'acp_icons'; // What are we working on? switch ($mode) { case 'smilies': $table = SMILIES_TABLE; $lang = 'SMILIES'; $fields = 'smiley'; $img_path = $config['smilies_path']; break; case 'icons': $table = ICONS_TABLE; $lang = 'ICONS'; $fields = 'icons'; $img_path = $config['icons_path']; break; } $this->page_title = 'ACP_' . $lang; // Clear some arrays $_images = $_paks = array(); $notice = ''; // Grab file list of paks and images if ($action == 'edit' || $action == 'add' || $action == 'import') { $imglist = filelist($phpbb_root_path . $img_path, ''); foreach ($imglist as $path => $img_ary) { if (empty($img_ary)) { continue; } asort($img_ary, SORT_STRING); foreach ($img_ary as $img) { $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $path . $img); if (!$img_size[0] || !$img_size[1] || strlen($img) > 255) { continue; } // adjust the width and height to be lower than 128px while perserving the aspect ratio (for icons) if ($mode == 'icons') { if ($img_size[0] > 127 && $img_size[0] > $img_size[1]) { $img_size[1] = (int) ($img_size[1] * (127 / $img_size[0])); $img_size[0] = 127; } else { if ($img_size[1] > 127) { $img_size[0] = (int) ($img_size[0] * (127 / $img_size[1])); $img_size[1] = 127; } } } $_images[$path . $img]['file'] = $path . $img; $_images[$path . $img]['width'] = $img_size[0]; $_images[$path . $img]['height'] = $img_size[1]; } } unset($imglist); if ($dir = @opendir($phpbb_root_path . $img_path)) { while (($file = readdir($dir)) !== false) { if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\\.pak$#i', $file)) { $_paks[] = $file; } } closedir($dir); if (!empty($_paks)) { asort($_paks, SORT_STRING); } } } // What shall we do today? Oops, I believe that's trademarked ... switch ($action) { case 'edit': unset($_images); $_images = array(); // no break; // no break; case 'add': $smilies = $default_row = array(); $smiley_options = $order_list = $add_order_list = ''; if ($action == 'add' && $mode == 'smilies') { $sql = 'SELECT * FROM ' . SMILIES_TABLE . ' ORDER BY smiley_order'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (empty($smilies[$row['smiley_url']])) { $smilies[$row['smiley_url']] = $row; } } $db->sql_freeresult($result); if (sizeof($smilies)) { foreach ($smilies as $row) { $selected = false; if (!$smiley_options) { $selected = true; $default_row = $row; } $smiley_options .= '<option value="' . $row['smiley_url'] . '"' . ($selected ? ' selected="selected"' : '') . '>' . $row['smiley_url'] . '</option>'; $template->assign_block_vars('smile', array('SMILEY_URL' => addslashes($row['smiley_url']), 'CODE' => addslashes($row['code']), 'EMOTION' => addslashes($row['emotion']), 'WIDTH' => $row['smiley_width'], 'HEIGHT' => $row['smiley_height'], 'ORDER' => $row['smiley_order'] + 1)); } } } $sql = "SELECT *\n\t\t\t\t\tFROM {$table}\n\t\t\t\t\tORDER BY {$fields}_order " . ($icon_id || $action == 'add' ? 'DESC' : 'ASC'); $result = $db->sql_query($sql); $data = array(); $after = false; $order_lists = array('', ''); $add_order_lists = array('', ''); $display_count = 0; while ($row = $db->sql_fetchrow($result)) { if ($action == 'add') { unset($_images[$row[$fields . '_url']]); } if ($row[$fields . '_id'] == $icon_id) { $after = true; $data[$row[$fields . '_url']] = $row; } else { if ($action == 'edit' && !$icon_id) { $data[$row[$fields . '_url']] = $row; } $selected = ''; if (!empty($after)) { $selected = ' selected="selected"'; $after = false; } if ($row['display_on_posting']) { $display_count++; } $after_txt = $mode == 'smilies' ? $row['code'] : $row['icons_url']; $order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . $selected . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . $after_txt) . '</option>' . $order_lists[$row['display_on_posting']]; if (!empty($default_row)) { $add_order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . ($row[$fields . '_id'] == $default_row['smiley_id'] ? ' selected="selected"' : '') . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . $after_txt) . '</option>' . $add_order_lists[$row['display_on_posting']]; } } } $db->sql_freeresult($result); $order_list = '<option value="1"' . (!isset($after) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>'; $add_order_list = '<option value="1">' . $user->lang['FIRST'] . '</option>'; if ($action == 'add') { $data = $_images; } $colspan = $mode == 'smilies' ? 7 : 6; $colspan += $icon_id ? 1 : 0; $colspan += $action == 'add' ? 2 : 0; $template->assign_vars(array('S_EDIT' => true, 'S_SMILIES' => $mode == 'smilies' ? true : false, 'S_ADD' => $action == 'add' ? true : false, 'S_ORDER_LIST_DISPLAY' => $order_list . $order_lists[1], 'S_ORDER_LIST_UNDISPLAY' => $order_list . $order_lists[0], 'S_ORDER_LIST_DISPLAY_COUNT' => $display_count + 1, 'L_TITLE' => $user->lang['ACP_' . $lang], 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 'L_CONFIG' => $user->lang[$lang . '_CONFIG'], 'L_URL' => $user->lang[$lang . '_URL'], 'L_LOCATION' => $user->lang[$lang . '_LOCATION'], 'L_WIDTH' => $user->lang[$lang . '_WIDTH'], 'L_HEIGHT' => $user->lang[$lang . '_HEIGHT'], 'L_ORDER' => $user->lang[$lang . '_ORDER'], 'L_NO_ICONS' => $user->lang['NO_' . $lang . '_' . strtoupper($action)], 'COLSPAN' => $colspan, 'ID' => $icon_id, 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=' . ($action == 'add' ? 'create' : 'modify'))); foreach ($data as $img => $img_row) { $template->assign_block_vars('items', array('IMG' => $img, 'A_IMG' => addslashes($img), 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $img, 'CODE' => $mode == 'smilies' && isset($img_row['code']) ? $img_row['code'] : '', 'EMOTION' => $mode == 'smilies' && isset($img_row['emotion']) ? $img_row['emotion'] : '', 'S_ID' => isset($img_row[$fields . '_id']) ? true : false, 'ID' => isset($img_row[$fields . '_id']) ? $img_row[$fields . '_id'] : 0, 'WIDTH' => !empty($img_row[$fields . '_width']) ? $img_row[$fields . '_width'] : $img_row['width'], 'HEIGHT' => !empty($img_row[$fields . '_height']) ? $img_row[$fields . '_height'] : $img_row['height'], 'TEXT_ALT' => $mode == 'icons' && !empty($img_row['icons_alt']) ? $img_row['icons_alt'] : $img, 'ALT' => $mode == 'icons' && !empty($img_row['icons_alt']) ? $img_row['icons_alt'] : '', 'POSTING_CHECKED' => !empty($img_row['display_on_posting']) || $action == 'add' ? ' checked="checked"' : '')); } // Ok, another row for adding an addition code for a pre-existing image... if ($action == 'add' && $mode == 'smilies' && sizeof($smilies)) { $template->assign_vars(array('S_ADD_CODE' => true, 'S_IMG_OPTIONS' => $smiley_options, 'S_ADD_ORDER_LIST_DISPLAY' => $add_order_list . $add_order_lists[1], 'S_ADD_ORDER_LIST_UNDISPLAY' => $add_order_list . $add_order_lists[0], 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $default_row['smiley_url'], 'IMG_PATH' => $img_path, 'CODE' => $default_row['code'], 'EMOTION' => $default_row['emotion'], 'WIDTH' => $default_row['smiley_width'], 'HEIGHT' => $default_row['smiley_height'])); } return; break; case 'create': case 'modify': if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Get items to create/modify $images = isset($_POST['image']) ? array_keys($request->variable('image', array('' => 0))) : array(); // Now really get the items $image_id = isset($_POST['id']) ? $request->variable('id', array('' => 0)) : array(); $image_order = isset($_POST['order']) ? $request->variable('order', array('' => 0)) : array(); $image_width = isset($_POST['width']) ? $request->variable('width', array('' => 0)) : array(); $image_height = isset($_POST['height']) ? $request->variable('height', array('' => 0)) : array(); $image_add = isset($_POST['add_img']) ? $request->variable('add_img', array('' => 0)) : array(); $image_emotion = $request->variable('emotion', array('' => ''), true); $image_code = $request->variable('code', array('' => ''), true); $image_alt = $request->is_set_post('alt') ? $request->variable('alt', array('' => ''), true) : array(); $image_display_on_posting = isset($_POST['display_on_posting']) ? $request->variable('display_on_posting', array('' => 0)) : array(); // Ok, add the relevant bits if we are adding new codes to existing emoticons... if ($request->variable('add_additional_code', false, false, \phpbb\request\request_interface::POST)) { $add_image = $request->variable('add_image', ''); $add_code = $request->variable('add_code', '', true); $add_emotion = $request->variable('add_emotion', '', true); if ($add_image && $add_emotion && $add_code) { $images[] = $add_image; $image_add[$add_image] = true; $image_code[$add_image] = $add_code; $image_emotion[$add_image] = $add_emotion; $image_width[$add_image] = $request->variable('add_width', 0); $image_height[$add_image] = $request->variable('add_height', 0); if ($request->variable('add_display_on_posting', false, false, \phpbb\request\request_interface::POST)) { $image_display_on_posting[$add_image] = 1; } $image_order[$add_image] = $request->variable('add_order', 0); } } if ($mode == 'smilies' && $action == 'create') { $smiley_count = $this->item_count($table); $addable_smileys_count = sizeof($images); foreach ($images as $image) { if (!isset($image_add[$image])) { --$addable_smileys_count; } } if ($smiley_count + $addable_smileys_count > SMILEY_LIMIT) { trigger_error($user->lang('TOO_MANY_SMILIES', SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING); } } $icons_updated = 0; $errors = array(); foreach ($images as $image) { if ($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == '')) { $errors[$image] = 'SMILIE_NO_' . ($image_emotion[$image] == '' ? 'EMOTION' : 'CODE'); } else { if ($action == 'create' && !isset($image_add[$image])) { // skip images where add wasn't checked } else { if (!file_exists($phpbb_root_path . $img_path . '/' . $image)) { $errors[$image] = 'SMILIE_NO_FILE'; } else { if ($image_width[$image] == 0 || $image_height[$image] == 0) { $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $image); $image_width[$image] = $img_size[0]; $image_height[$image] = $img_size[1]; } // Adjust image width/height for icons if ($mode == 'icons') { if ($image_width[$image] > 127 && $image_width[$image] > $image_height[$image]) { $image_height[$image] = (int) ($image_height[$image] * (127 / $image_width[$image])); $image_width[$image] = 127; } else { if ($image_height[$image] > 127) { $image_width[$image] = (int) ($image_width[$image] * (127 / $image_height[$image])); $image_height[$image] = 127; } } } $img_sql = array($fields . '_url' => $image, $fields . '_width' => $image_width[$image], $fields . '_height' => $image_height[$image], 'display_on_posting' => isset($image_display_on_posting[$image]) ? 1 : 0); if ($mode == 'smilies') { $img_sql = array_merge($img_sql, array('emotion' => $image_emotion[$image], 'code' => $image_code[$image])); } if ($mode == 'icons') { $img_sql = array_merge($img_sql, array('icons_alt' => $image_alt[$image])); } // Image_order holds the 'new' order value if (!empty($image_order[$image])) { $img_sql = array_merge($img_sql, array($fields . '_order' => $image_order[$image])); // Since we always add 'after' an item, we just need to increase all following + the current by one $sql = "UPDATE {$table}\n\t\t\t\t\t\t\t\tSET {$fields}_order = {$fields}_order + 1\n\t\t\t\t\t\t\t\tWHERE {$fields}_order >= {$image_order[$image]}"; $db->sql_query($sql); // If we adjust the order, we need to adjust all other orders too - they became inaccurate... foreach ($image_order as $_image => $_order) { if ($_image == $image) { continue; } if ($_order >= $image_order[$image]) { $image_order[$_image]++; } } } if ($action == 'modify' && !empty($image_id[$image])) { $sql = "UPDATE {$table}\n\t\t\t\t\t\t\t\tSET " . $db->sql_build_array('UPDATE', $img_sql) . "\n\t\t\t\t\t\t\t\tWHERE {$fields}_id = " . $image_id[$image]; $db->sql_query($sql); $icons_updated++; } else { if ($action !== 'modify') { $sql = "INSERT INTO {$table} " . $db->sql_build_array('INSERT', $img_sql); $db->sql_query($sql); $icons_updated++; } } } } } } $cache->destroy('_icons'); $cache->destroy('sql', $table); $phpbb_container->get('text_formatter.cache')->invalidate(); $level = $icons_updated ? E_USER_NOTICE : E_USER_WARNING; $errormsgs = ''; foreach ($errors as $img => $error) { $errormsgs .= '<br />' . sprintf($user->lang[$error], $img); } if ($action == 'modify') { trigger_error($user->lang($lang . '_EDITED', $icons_updated) . $errormsgs . adm_back_link($this->u_action), $level); } else { trigger_error($user->lang($lang . '_ADDED', $icons_updated) . $errormsgs . adm_back_link($this->u_action), $level); } break; case 'import': $pak = $request->variable('pak', ''); $current = $request->variable('current', ''); if ($pak != '') { $order = 0; if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak))) { trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } // Make sure the pak_ary is valid foreach ($pak_ary as $pak_entry) { if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data)) { if (sizeof($data[1]) != 4 && $mode == 'icons' || (sizeof($data[1]) != 6 || (empty($data[1][4]) || empty($data[1][5]))) && $mode == 'smilies') { trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } } else { trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } } // The user has already selected a smilies_pak file if ($current == 'delete') { switch ($db->get_sql_layer()) { case 'sqlite3': $db->sql_query('DELETE FROM ' . $table); break; default: $db->sql_query('TRUNCATE TABLE ' . $table); break; } switch ($mode) { case 'smilies': break; case 'icons': // Reset all icon_ids $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0'); $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0'); break; } } else { $cur_img = array(); $field_sql = $mode == 'smilies' ? 'code' : 'icons_url'; $sql = "SELECT {$field_sql}\n\t\t\t\t\t\t\tFROM {$table}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { ++$order; $cur_img[$row[$field_sql]] = 1; } $db->sql_freeresult($result); } if ($mode == 'smilies') { $smiley_count = $this->item_count($table); if ($smiley_count + sizeof($pak_ary) > SMILEY_LIMIT) { trigger_error($user->lang('TOO_MANY_SMILIES', SMILEY_LIMIT) . adm_back_link($this->u_action), E_USER_WARNING); } } foreach ($pak_ary as $pak_entry) { $data = array(); if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data)) { if (sizeof($data[1]) != 4 && $mode == 'icons' || sizeof($data[1]) != 6 && $mode == 'smilies') { trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } // Stripslash here because it got addslashed before... (on export) $img = stripslashes($data[1][0]); $width = stripslashes($data[1][1]); $height = stripslashes($data[1][2]); $display_on_posting = stripslashes($data[1][3]); if (isset($data[1][4]) && isset($data[1][5])) { $emotion = stripslashes($data[1][4]); $code = stripslashes($data[1][5]); } if ($current == 'replace' && ($mode == 'smilies' && !empty($cur_img[$code]) || $mode == 'icons' && !empty($cur_img[$img]))) { $replace_sql = $mode == 'smilies' ? $code : $img; $sql = array($fields . '_url' => $img, $fields . '_height' => (int) $height, $fields . '_width' => (int) $width, 'display_on_posting' => (int) $display_on_posting); if ($mode == 'smilies') { $sql = array_merge($sql, array('emotion' => $emotion)); } $sql = "UPDATE {$table} SET " . $db->sql_build_array('UPDATE', $sql) . "\n\t\t\t\t\t\t\t\t\tWHERE {$field_sql} = '" . $db->sql_escape($replace_sql) . "'"; $db->sql_query($sql); } else { ++$order; $sql = array($fields . '_url' => $img, $fields . '_height' => (int) $height, $fields . '_width' => (int) $width, $fields . '_order' => (int) $order, 'display_on_posting' => (int) $display_on_posting); if ($mode == 'smilies') { $sql = array_merge($sql, array('code' => $code, 'emotion' => $emotion)); } $db->sql_query("INSERT INTO {$table} " . $db->sql_build_array('INSERT', $sql)); } } } $cache->destroy('_icons'); $cache->destroy('sql', $table); $phpbb_container->get('text_formatter.cache')->invalidate(); trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action)); } else { $pak_options = ''; foreach ($_paks as $pak) { $pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>'; } $template->assign_vars(array('S_CHOOSE_PAK' => true, 'S_PAK_OPTIONS' => $pak_options, 'L_TITLE' => $user->lang['ACP_' . $lang], 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 'L_NO_PAK_OPTIONS' => $user->lang['NO_' . $lang . '_PAK'], 'L_CURRENT' => $user->lang['CURRENT_' . $lang], 'L_CURRENT_EXPLAIN' => $user->lang['CURRENT_' . $lang . '_EXPLAIN'], 'L_IMPORT_SUBMIT' => $user->lang['IMPORT_' . $lang], 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=import')); } break; case 'export': $this->page_title = 'EXPORT_' . $lang; $this->tpl_name = 'message_body'; $template->assign_vars(array('MESSAGE_TITLE' => $user->lang['EXPORT_' . $lang], 'MESSAGE_TEXT' => sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '<a href="' . $this->u_action . '&action=send&hash=' . generate_link_hash('acp_icons') . '">', '</a>'), 'S_USER_NOTICE' => true)); return; break; case 'send': if (!check_link_hash($request->variable('hash', ''), 'acp_icons')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = "SELECT *\n\t\t\t\t\tFROM {$table}\n\t\t\t\t\tORDER BY {$fields}_order"; $result = $db->sql_query($sql); $pak = ''; while ($row = $db->sql_fetchrow($result)) { $pak .= "'" . addslashes($row[$fields . '_url']) . "', "; $pak .= "'" . addslashes($row[$fields . '_width']) . "', "; $pak .= "'" . addslashes($row[$fields . '_height']) . "', "; $pak .= "'" . addslashes($row['display_on_posting']) . "', "; if ($mode == 'smilies') { $pak .= "'" . addslashes($row['emotion']) . "', "; $pak .= "'" . addslashes($row['code']) . "', "; } $pak .= "\n"; } $db->sql_freeresult($result); if ($pak != '') { garbage_collection(); header('Cache-Control: public'); // Send out the Headers header('Content-Type: text/x-delimtext; name="' . $mode . '.pak"'); header('Content-Disposition: inline; filename="' . $mode . '.pak"'); echo $pak; flush(); exit; } else { trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING); } break; case 'delete': if (confirm_box(true)) { $sql = "DELETE FROM {$table}\n\t\t\t\t\t\tWHERE {$fields}_id = {$icon_id}"; $db->sql_query($sql); switch ($mode) { case 'smilies': break; case 'icons': // Reset appropriate icon_ids $db->sql_query('UPDATE ' . TOPICS_TABLE . "\n\t\t\t\t\t\t\t\tSET icon_id = 0\n\t\t\t\t\t\t\t\tWHERE icon_id = {$icon_id}"); $db->sql_query('UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tSET icon_id = 0\n\t\t\t\t\t\t\t\tWHERE icon_id = {$icon_id}"); break; } $notice = $user->lang[$lang . '_DELETED']; $cache->destroy('_icons'); $cache->destroy('sql', $table); $phpbb_container->get('text_formatter.cache')->invalidate(); if ($request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $notice, 'REFRESH_DATA' => array('time' => 3))); } } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'id' => $icon_id, 'action' => 'delete'))); } break; case 'move_up': case 'move_down': if (!check_link_hash($request->variable('hash', ''), 'acp_icons')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Get current order id... $sql = "SELECT {$fields}_order as current_order\n\t\t\t\t\tFROM {$table}\n\t\t\t\t\tWHERE {$fields}_id = {$icon_id}"; $result = $db->sql_query($sql); $current_order = (int) $db->sql_fetchfield('current_order'); $db->sql_freeresult($result); if ($current_order == 0 && $action == 'move_up') { break; } // on move_down, switch position with next order_id... // on move_up, switch position with previous order_id... $switch_order_id = $action == 'move_down' ? $current_order + 1 : $current_order - 1; // $sql = "UPDATE {$table}\n\t\t\t\t\tSET {$fields}_order = {$current_order}\n\t\t\t\t\tWHERE {$fields}_order = {$switch_order_id}\n\t\t\t\t\t\tAND {$fields}_id <> {$icon_id}"; $db->sql_query($sql); $move_executed = (bool) $db->sql_affectedrows(); // Only update the other entry too if the previous entry got updated if ($move_executed) { $sql = "UPDATE {$table}\n\t\t\t\t\t\tSET {$fields}_order = {$switch_order_id}\n\t\t\t\t\t\tWHERE {$fields}_order = {$current_order}\n\t\t\t\t\t\t\tAND {$fields}_id = {$icon_id}"; $db->sql_query($sql); } $cache->destroy('_icons'); $cache->destroy('sql', $table); $phpbb_container->get('text_formatter.cache')->invalidate(); if ($request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('success' => $move_executed)); } break; } // By default, check that image_order is valid and fix it if necessary $sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order\n\t\t\tFROM {$table}\n\t\t\tORDER BY display_on_posting DESC, {$fields}_order"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $order = 0; do { ++$order; if ($row['fields_order'] != $order) { $db->sql_query("UPDATE {$table}\n\t\t\t\t\t\tSET {$fields}_order = {$order}\n\t\t\t\t\t\tWHERE {$fields}_id = " . $row['order_id']); } } while ($row = $db->sql_fetchrow($result)); } $db->sql_freeresult($result); $template->assign_vars(array('L_TITLE' => $user->lang['ACP_' . $lang], 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 'L_IMPORT' => $user->lang['IMPORT_' . $lang], 'L_EXPORT' => $user->lang['EXPORT_' . $lang], 'L_NOT_DISPLAYED' => $user->lang[$lang . '_NOT_DISPLAYED'], 'L_ICON_ADD' => $user->lang['ADD_' . $lang], 'L_ICON_EDIT' => $user->lang['EDIT_' . $lang], 'NOTICE' => $notice, 'COLSPAN' => $mode == 'smilies' ? 5 : 3, 'S_SMILIES' => $mode == 'smilies' ? true : false, 'U_ACTION' => $this->u_action, 'U_IMPORT' => $this->u_action . '&action=import', 'U_EXPORT' => $this->u_action . '&action=export')); /* @var $pagination \phpbb\pagination */ $pagination = $phpbb_container->get('pagination'); $pagination_start = $request->variable('start', 0); $spacer = false; $item_count = $this->item_count($table); $sql = "SELECT *\n\t\t\tFROM {$table}\n\t\t\tORDER BY {$fields}_order ASC"; $result = $db->sql_query_limit($sql, $config['smilies_per_page'], $pagination_start); while ($row = $db->sql_fetchrow($result)) { $alt_text = $mode == 'smilies' ? $row['code'] : ($mode == 'icons' && !empty($row['icons_alt']) ? $row['icons_alt'] : $row['icons_url']); $template->assign_block_vars('items', array('S_SPACER' => !$spacer && !$row['display_on_posting'] ? true : false, 'ALT_TEXT' => $alt_text, 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'], 'WIDTH' => $row[$fields . '_width'], 'HEIGHT' => $row[$fields . '_height'], 'CODE' => isset($row['code']) ? $row['code'] : '', 'EMOTION' => isset($row['emotion']) ? $row['emotion'] : '', 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row[$fields . '_id'], 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row[$fields . '_id'], 'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row[$fields . '_id'] . '&start=' . $pagination_start . '&hash=' . generate_link_hash('acp_icons'), 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row[$fields . '_id'] . '&start=' . $pagination_start . '&hash=' . generate_link_hash('acp_icons'))); if (!$spacer && !$row['display_on_posting']) { $spacer = true; } } $db->sql_freeresult($result); $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start); }
function getdirlist($dir) { $dirs = array(); if ($directory = @dir($dir)) { while ($file = $directory->read()) { if ($file != "." && $file != "..") { $fullpath = $dir . "/" . $file; if (!is_dir($fullpath)) { $dirs[$dir][] = $fullpath; } else { $list = array(); if (filelist($fullpath, $list)) { $dirs[$fullpath] = $list; } } } } $directory->close(); return $dirs; } else { return false; } }
} $used_title_text = ""; $used_title_show = "display:none;"; if ($value["name"] != "---") { $used_title_text = str_replace(";;", "<br />", $value["name"]); $used_title_show = ""; } $dataloop["compilation"][$id] = array("id" => $id, "count" => $num_pics, "used_on" => $used_on, "check" => $check, "edit" => $edit, "used_title_text" => $used_title_text, "used_title_show" => $used_title_show, "used_title" => ""); // bilder der compilation finden $sql = "SELECT *\n FROM site_file\n WHERE fhit\n LIKE '%#p" . $id . ",%'\n ORDER BY fid"; $list_item = "<li class=\"thumbs\">\n <a title=\"##title##\" class=\"pic\" rel=\"lightbox[##cid##]\" href=\"##src_lb##\"><img title=\"##title##\" alt=\"##title##\" src=\"##src##\"/></a>\n <input id=\"c##cid##p##pid##\" class=\"sel_pic_checkbox\" type=\"checkbox\" value=\"-1\" onclick=\"session_update(##cid##,##pid##);\"##check## />\n </li>"; $search = array('##title##', '##cid##', '##pid##', '##src_lb##', '##src##', '##check##'); $result = $db->query($sql); $pic_array = array(); $dataloop["list_images"] = array(); filelist($result, "fileed", $key); uasort($dataloop["list_images"], "pics_sort"); // anzahl der bilder $num_pics = count($dataloop["list_images"]); $dataloop["compilation"][$id]["count"] = $num_pics; // galerie bauen $i = 0; $lb_pics = ""; $pics = ""; foreach ($dataloop["list_images"] as $pic) { $check = ""; if ($_SESSION["compilation_memo"][$id][$pic["id"]] != "") { $check = " checked=\"true\""; } $replace = array($pic["under"], $id, $pic["id"], $pic["ohref_lb"], $pic["src"], $check); $pics .= str_replace($search, $replace, $list_item);
</script> </head> <body> <div id="main"> <h2>Create your monster</h2> <p>Drag and drop monster parts for fun.</p> <?php $folders = array('_eyes', '_mouth'); foreach ($folders as $folder) { $list_of_files = filelist($folder); foreach ($list_of_files as $file) { echo '<div class="img-wrap draggable"><img src="' . $folder . '/' . $file . '" class="resizable" /></div>'; } } /*$list_of_files = filelist('_eyes'); foreach ($list_of_files as $file) { echo '<img src="_eyes/'.$file. '" class="drag" />'; } $list_of_files = filelist('_eyes'); foreach ($list_of_files as $file) { echo '<img src="_eyes/'.$file. '" class="drag" />'; }*/ ?>
function main($id, $mode) { global $db, $user, $auth, $template, $cache; global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx; $user->add_lang(array('posting', 'viewtopic', 'acp/attachments')); $error = $notify = array(); $submit = isset($_POST['submit']) ? true : false; $action = request_var('action', ''); $form_key = 'acp_attach'; add_form_key($form_key); if ($submit && !check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } switch ($mode) { case 'attach': $l_title = 'ACP_ATTACHMENT_SETTINGS'; break; case 'extensions': $l_title = 'ACP_MANAGE_EXTENSIONS'; break; case 'ext_groups': $l_title = 'ACP_EXTENSION_GROUPS'; break; case 'orphan': $l_title = 'ACP_ORPHAN_ATTACHMENTS'; break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } $this->tpl_name = 'acp_attachments'; $this->page_title = $l_title; $template->assign_vars(array('L_TITLE' => $user->lang[$l_title], 'L_TITLE_EXPLAIN' => $user->lang[$l_title . '_EXPLAIN'], 'U_ACTION' => $this->u_action)); switch ($mode) { case 'attach': include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx; $sql = 'SELECT group_name, cat_id FROM ' . EXTENSION_GROUPS_TABLE . ' WHERE cat_id > 0 ORDER BY cat_id'; $result = $db->sql_query($sql); $s_assigned_groups = array(); while ($row = $db->sql_fetchrow($result)) { $s_assigned_groups[$row['cat_id']][] = $row['group_name']; } $db->sql_freeresult($result); $l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . (!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) ? implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']'; $display_vars = array('title' => 'ACP_ATTACHMENT_SETTINGS', 'vars' => array('legend1' => 'ACP_ATTACHMENT_SETTINGS', 'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true), 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true), 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false), 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false), 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true), 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend2' => $l_legend_cat_images, 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_max_thumb_width' => array('lang' => 'MAX_THUMB_WIDTH', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' px'), 'img_min_thumb_filesize' => array('lang' => 'MIN_THUMB_FILESIZE', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), 'img_imagick' => array('lang' => 'IMAGICK_PATH', 'validate' => 'string', 'type' => 'text:20:200', 'explain' => true, 'append' => ' <span>[ <a href="' . $this->u_action . '&action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'), 'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'), 'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'))); $this->new_config = $config; $cfg_array = isset($_REQUEST['config']) ? request_var('config', array('' => '')) : $this->new_config; $error = array(); // We validate the complete config if whished validate_config_vars($display_vars['vars'], $cfg_array, $error); // Do not write values if there is an error if (sizeof($error)) { $submit = false; } // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($display_vars['vars'] as $config_name => $null) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm'))) { $size_var = request_var($config_name, ''); $this->new_config[$config_name] = $config_value = $size_var == 'kb' ? round($config_value * 1024) : ($size_var == 'mb' ? round($config_value * 1048576) : $config_value); } if ($submit) { set_config($config_name, $config_value); } } $this->perform_site_list(); if ($submit) { add_log('admin', 'LOG_CONFIG_ATTACH'); // Check Settings $this->test_upload($error, $this->new_config['upload_path'], false); if (!sizeof($error)) { trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } } $template->assign_var('S_ATTACHMENT_SETTINGS', true); if ($action == 'imgmagick') { $this->new_config['img_imagick'] = $this->search_imagemagick(); } // We strip eventually manual added convert program, we only want the patch if ($this->new_config['img_imagick']) { // Change path separator $this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']); $this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']); // Check for trailing slash if (substr($this->new_config['img_imagick'], -1) !== '/') { $this->new_config['img_imagick'] .= '/'; } } $supported_types = get_supported_image_types(); // Check Thumbnail Support if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) { $this->new_config['img_create_thumbnail'] = 0; } $template->assign_vars(array('U_SEARCH_IMAGICK' => $this->u_action . '&action=imgmagick', 'S_THUMBNAIL_SUPPORT' => !$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])) ? false : true)); // Secure Download Options - Same procedure as with banning $allow_deny = $this->new_config['secure_allow_deny'] ? 'ALLOWED' : 'DISALLOWED'; $sql = 'SELECT * FROM ' . SITELIST_TABLE; $result = $db->sql_query($sql); $defined_ips = ''; $ips = array(); while ($row = $db->sql_fetchrow($result)) { $value = $row['site_ip'] ? $row['site_ip'] : $row['site_hostname']; if ($value) { $defined_ips .= '<option' . ($row['ip_exclude'] ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>'; $ips[$row['site_id']] = $value; } } $db->sql_freeresult($result); $template->assign_vars(array('S_SECURE_DOWNLOADS' => $this->new_config['secure_downloads'], 'S_DEFINED_IPS' => $defined_ips != '' ? true : false, 'S_WARNING' => sizeof($error) ? true : false, 'WARNING_MSG' => implode('<br />', $error), 'DEFINED_IPS' => $defined_ips, 'L_SECURE_TITLE' => $user->lang['DEFINE_' . $allow_deny . '_IPS'], 'L_IP_EXCLUDE' => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'], 'L_REMOVE_IPS' => $user->lang['REMOVE_' . $allow_deny . '_IPS'])); // Output relevant options foreach ($display_vars['vars'] as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars)); continue; } $type = explode(':', $vars['type']); $l_explain = ''; if ($vars['explain'] && isset($vars['lang_explain'])) { $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain']; } else { if ($vars['explain']) { $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } } $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { continue; } $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => $user->lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content)); unset($display_vars['vars'][$config_key]); } break; case 'extensions': if ($submit || isset($_POST['add_extension_check'])) { if ($submit) { // Change Extensions ? $extension_change_list = request_var('extension_change_list', array(0)); $group_select_list = request_var('group_select', array(0)); // Generate correct Change List $extensions = array(); for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++) { $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i]; } $sql = 'SELECT * FROM ' . EXTENSIONS_TABLE . ' ORDER BY extension_id'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($row['group_id'] != $extensions[$row['extension_id']]['group_id']) { $sql = 'UPDATE ' . EXTENSIONS_TABLE . ' SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . ' WHERE extension_id = ' . $row['extension_id']; $db->sql_query($sql); add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']); } } $db->sql_freeresult($result); // Delete Extension? $extension_id_list = request_var('extension_id_list', array(0)); if (sizeof($extension_id_list)) { $sql = 'SELECT extension FROM ' . EXTENSIONS_TABLE . ' WHERE ' . $db->sql_in_set('extension_id', $extension_id_list); $result = $db->sql_query($sql); $extension_list = ''; while ($row = $db->sql_fetchrow($result)) { $extension_list .= $extension_list == '' ? $row['extension'] : ', ' . $row['extension']; } $db->sql_freeresult($result); $sql = 'DELETE FROM ' . EXTENSIONS_TABLE . ' WHERE ' . $db->sql_in_set('extension_id', $extension_id_list); $db->sql_query($sql); add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list); } } // Add Extension? $add_extension = strtolower(request_var('add_extension', '')); $add_extension_group = request_var('add_group_select', 0); $add = isset($_POST['add_extension_check']) ? true : false; if ($add_extension && $add) { if (!sizeof($error)) { $sql = 'SELECT extension_id FROM ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE extension = '" . $db->sql_escape($add_extension) . "'"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension); } $db->sql_freeresult($result); if (!sizeof($error)) { $sql_ary = array('group_id' => $add_extension_group, 'extension' => $add_extension); $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension); } } } if (!sizeof($error)) { $notify[] = $user->lang['EXTENSIONS_UPDATED']; } $cache->destroy('_extensions'); } $template->assign_vars(array('S_EXTENSIONS' => true, 'ADD_EXTENSION' => isset($add_extension) ? $add_extension : '', 'GROUP_SELECT_OPTIONS' => isset($_POST['add_extension_check']) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group'))); $sql = 'SELECT * FROM ' . EXTENSIONS_TABLE . ' ORDER BY group_id, extension'; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $old_group_id = $row['group_id']; do { $s_spacer = false; $current_group_id = $row['group_id']; if ($old_group_id != $current_group_id) { $s_spacer = true; $old_group_id = $current_group_id; } $template->assign_block_vars('extensions', array('S_SPACER' => $s_spacer, 'EXTENSION_ID' => $row['extension_id'], 'EXTENSION' => $row['extension'], 'GROUP_OPTIONS' => $this->group_select('group_select[]', $row['group_id']))); } while ($row = $db->sql_fetchrow($result)); } $db->sql_freeresult($result); break; case 'ext_groups': $template->assign_var('S_EXTENSION_GROUPS', true); if ($submit) { $action = request_var('action', ''); $group_id = request_var('g', 0); if ($action != 'add' && $action != 'edit') { trigger_error('NO_MODE', E_USER_ERROR); } if (!$group_id && $action == 'edit') { trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($group_id) { $sql = 'SELECT * FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $ext_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$ext_row) { trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING); } } else { $ext_row = array(); } $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $new_group_name = $action == 'add' ? $group_name : ($ext_row['group_name'] != $group_name ? $group_name : ''); if (!$group_name) { $error[] = $user->lang['NO_EXT_GROUP_NAME']; } // Check New Group Name if ($new_group_name) { $sql = 'SELECT group_id FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'"; $result = $db->sql_query($sql); if ($db->sql_fetchrow($result)) { $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name); } $db->sql_freeresult($result); } if (!sizeof($error)) { // Ok, build the update/insert array $upload_icon = request_var('upload_icon', 'no_image'); $size_select = request_var('size_select', 'b'); $forum_select = request_var('forum_select', false); $allowed_forums = request_var('allowed_forums', array(0)); $allow_in_pm = isset($_POST['allow_in_pm']) ? true : false; $max_filesize = request_var('max_filesize', 0); $max_filesize = $size_select == 'kb' ? round($max_filesize * 1024) : ($size_select == 'mb' ? round($max_filesize * 1048576) : $max_filesize); $allow_group = isset($_POST['allow_group']) ? true : false; if ($max_filesize == $config['max_filesize']) { $max_filesize = 0; } if (!sizeof($allowed_forums)) { $forum_select = false; } $group_ary = array('group_name' => $group_name, 'cat_id' => request_var('special_category', ATTACHMENT_CATEGORY_NONE), 'allow_group' => $allow_group ? 1 : 0, 'upload_icon' => $upload_icon == 'no_image' ? '' : $upload_icon, 'max_filesize' => $max_filesize, 'allowed_forums' => $forum_select ? serialize($allowed_forums) : '', 'allow_in_pm' => $allow_in_pm ? 1 : 0); if ($action == 'add') { $group_ary['download_mode'] = INLINE_LINK; } $sql = $action == 'add' ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET '; $sql .= $db->sql_build_array($action == 'add' ? 'INSERT' : 'UPDATE', $group_ary); $sql .= $action == 'edit' ? " WHERE group_id = {$group_id}" : ''; $db->sql_query($sql); if ($action == 'add') { $group_id = $db->sql_nextid(); } add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name); } $extension_list = request_var('extensions', array(0)); if ($action == 'edit' && sizeof($extension_list)) { $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tSET group_id = 0\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}"; $db->sql_query($sql); } if (sizeof($extension_list)) { $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tSET group_id = {$group_id}\n\t\t\t\t\t\t\tWHERE " . $db->sql_in_set('extension_id', $extension_list); $db->sql_query($sql); } $cache->destroy('_extensions'); if (!sizeof($error)) { $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)]; } } $cat_lang = array(ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'], ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'], ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'], ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'], ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES']); $group_id = request_var('g', 0); $action = isset($_POST['add']) ? 'add' : $action; switch ($action) { case 'delete': if (confirm_box(true)) { $sql = 'SELECT group_name FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $group_name = (string) $db->sql_fetchfield('group_name'); $db->sql_freeresult($result); $sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}"; $db->sql_query($sql); // Set corresponding Extensions to a pending Group $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\t\tSET group_id = 0\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}"; $db->sql_query($sql); add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name); $cache->destroy('_extensions'); trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'group_id' => $group_id, 'action' => 'delete'))); } break; case 'edit': if (!$group_id) { trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT * FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $ext_group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $forum_ids = !$ext_group_row['allowed_forums'] ? array() : unserialize(trim($ext_group_row['allowed_forums'])); // no break; // no break; case 'add': if ($action == 'add') { $ext_group_row = array('group_name' => utf8_normalize_nfc(request_var('group_name', '', true)), 'cat_id' => 0, 'allow_group' => 1, 'allow_in_pm' => 1, 'upload_icon' => '', 'max_filesize' => 0); $forum_ids = array(); } $extensions = array(); $sql = 'SELECT * FROM ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tOR group_id = 0\n\t\t\t\t\t\t\tORDER BY extension"; $result = $db->sql_query($sql); $extensions = $db->sql_fetchrowset($result); $db->sql_freeresult($result); if ($ext_group_row['max_filesize'] == 0) { $ext_group_row['max_filesize'] = (int) $config['max_filesize']; } $size_format = $ext_group_row['max_filesize'] >= 1048576 ? 'mb' : ($ext_group_row['max_filesize'] >= 1024 ? 'kb' : 'b'); $ext_group_row['max_filesize'] = get_formatted_filesize($ext_group_row['max_filesize'], false); $img_path = $config['upload_icons_path']; $filename_list = ''; $no_image_select = false; $imglist = filelist($phpbb_root_path . $img_path); if (sizeof($imglist)) { $imglist = array_values($imglist); $imglist = $imglist[0]; foreach ($imglist as $key => $img) { if (!$ext_group_row['upload_icon']) { $no_image_select = true; $selected = ''; } else { $selected = $ext_group_row['upload_icon'] == $img ? ' selected="selected"' : ''; } if (strlen($img) > 255) { continue; } $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>'; } } $i = 0; $assigned_extensions = ''; foreach ($extensions as $num => $row) { if ($row['group_id'] == $group_id && $group_id) { $assigned_extensions .= $i ? ', ' . $row['extension'] : $row['extension']; $i++; } } $s_extension_options = ''; foreach ($extensions as $row) { $s_extension_options .= '<option' . (!$row['group_id'] ? ' class="disabled"' : '') . ' value="' . $row['extension_id'] . '"' . ($row['group_id'] == $group_id && $group_id ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>'; } $template->assign_vars(array('PHPBB_ROOT_PATH' => $phpbb_root_path, 'IMG_PATH' => $img_path, 'ACTION' => $action, 'GROUP_ID' => $group_id, 'GROUP_NAME' => $ext_group_row['group_name'], 'ALLOW_GROUP' => $ext_group_row['allow_group'], 'ALLOW_IN_PM' => $ext_group_row['allow_in_pm'], 'UPLOAD_ICON_SRC' => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'], 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'], 'ASSIGNED_EXTENSIONS' => $assigned_extensions, 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'), 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format), 'S_EXTENSION_OPTIONS' => $s_extension_options, 'S_FILENAME_LIST' => $filename_list, 'S_EDIT_GROUP' => true, 'S_NO_IMAGE' => $no_image_select, 'S_FORUM_IDS' => sizeof($forum_ids) ? true : false, 'U_EXTENSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&mode=extensions"), 'U_BACK' => $this->u_action, 'L_LEGEND' => $user->lang[strtoupper($action) . '_EXTENSION_GROUP'])); $s_forum_id_options = ''; /** @todo use in-built function **/ $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC'; $result = $db->sql_query($sql, 600); $right = $cat_right = $padding_inc = 0; $padding = $forum_list = $holding = ''; $padding_store = array('0' => ''); while ($row = $db->sql_fetchrow($result)) { if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) { // Non-postable forum with no subforums, don't display continue; } if (!$auth->acl_get('f_list', $row['forum_id'])) { // if the user does not have permissions to list this forum skip continue; } if ($row['left_id'] < $right) { $padding .= ' '; $padding_store[$row['parent_id']] = $padding; } else { if ($row['left_id'] > $right + 1) { $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']]; } } $right = $row['right_id']; $selected = in_array($row['forum_id'], $forum_ids) ? ' selected="selected"' : ''; if ($row['left_id'] > $cat_right) { // make sure we don't forget anything $s_forum_id_options .= $holding; $holding = ''; } if ($row['right_id'] - $row['left_id'] > 1) { $cat_right = max($cat_right, $row['right_id']); $holding .= '<option value="' . $row['forum_id'] . '"' . ($row['forum_type'] == FORUM_POST ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>'; } else { $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . ($row['forum_type'] == FORUM_POST ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>'; $holding = ''; } } if ($holding) { $s_forum_id_options .= $holding; } $db->sql_freeresult($result); unset($padding_store); $template->assign_vars(array('S_FORUM_ID_OPTIONS' => $s_forum_id_options)); break; } $sql = 'SELECT * FROM ' . EXTENSION_GROUPS_TABLE . ' ORDER BY allow_group DESC, allow_in_pm DESC, group_name'; $result = $db->sql_query($sql); $old_allow_group = $old_allow_pm = 1; while ($row = $db->sql_fetchrow($result)) { $s_add_spacer = $old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm'] ? true : false; $template->assign_block_vars('groups', array('S_ADD_SPACER' => $s_add_spacer, 'S_ALLOWED_IN_PM' => $row['allow_in_pm'] ? true : false, 'S_GROUP_ALLOWED' => $row['allow_group'] ? true : false, 'U_EDIT' => $this->u_action . "&action=edit&g={$row['group_id']}", 'U_DELETE' => $this->u_action . "&action=delete&g={$row['group_id']}", 'GROUP_NAME' => $row['group_name'], 'CATEGORY' => $cat_lang[$row['cat_id']])); $old_allow_group = $row['allow_group']; $old_allow_pm = $row['allow_in_pm']; } $db->sql_freeresult($result); break; case 'orphan': if ($submit) { $delete_files = isset($_POST['delete']) ? array_keys(request_var('delete', array('' => 0))) : array(); $add_files = isset($_POST['add']) ? array_keys(request_var('add', array('' => 0))) : array(); $post_ids = request_var('post_id', array('' => 0)); if (sizeof($delete_files)) { $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('attach_id', $delete_files) . ' AND is_orphan = 1'; $result = $db->sql_query($sql); $delete_files = array(); while ($row = $db->sql_fetchrow($result)) { phpbb_unlink($row['physical_filename'], 'file'); if ($row['thumbnail']) { phpbb_unlink($row['physical_filename'], 'thumbnail'); } $delete_files[$row['attach_id']] = $row['real_filename']; } $db->sql_freeresult($result); } if (sizeof($delete_files)) { $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files)); $db->sql_query($sql); add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files)); $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files)); } $upload_list = array(); foreach ($add_files as $attach_id) { if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id])) { $upload_list[$attach_id] = $post_ids[$attach_id]; } } unset($add_files); if (sizeof($upload_list)) { $template->assign_var('S_UPLOADING_FILES', true); $sql = 'SELECT forum_id, forum_name FROM ' . FORUMS_TABLE; $result = $db->sql_query($sql); $forum_names = array(); while ($row = $db->sql_fetchrow($result)) { $forum_names[$row['forum_id']] = $row['forum_name']; } $db->sql_freeresult($result); $sql = 'SELECT forum_id, topic_id, post_id, poster_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('post_id', $upload_list); $result = $db->sql_query($sql); $post_info = array(); while ($row = $db->sql_fetchrow($result)) { $post_info[$row['post_id']] = $row; } $db->sql_freeresult($result); // Select those attachments we want to change... $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . ' AND is_orphan = 1'; $result = $db->sql_query($sql); $files_added = $space_taken = 0; while ($row = $db->sql_fetchrow($result)) { $post_row = $post_info[$upload_list[$row['attach_id']]]; $template->assign_block_vars('upload', array('FILE_INFO' => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']), 'S_DENIED' => !$auth->acl_get('f_attach', $post_row['forum_id']) ? true : false, 'L_DENIED' => !$auth->acl_get('f_attach', $post_row['forum_id']) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : '')); if (!$auth->acl_get('f_attach', $post_row['forum_id'])) { continue; } // Adjust attachment entry $sql_ary = array('in_message' => 0, 'is_orphan' => 0, 'poster_id' => $post_row['poster_id'], 'post_msg_id' => $post_row['post_id'], 'topic_id' => $post_row['topic_id']); $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE attach_id = ' . $row['attach_id']; $db->sql_query($sql); $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_attachment = 1 WHERE post_id = ' . $post_row['post_id']; $db->sql_query($sql); $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_attachment = 1 WHERE topic_id = ' . $post_row['topic_id']; $db->sql_query($sql); $space_taken += $row['filesize']; $files_added++; add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']); } $db->sql_freeresult($result); if ($files_added) { set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true); set_config('num_files', $config['num_files'] + $files_added, true); } } } $template->assign_vars(array('S_ORPHAN' => true)); // Just get the files with is_orphan set and older than 3 hours $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 1 AND filetime < ' . (time() - 3 * 60 * 60) . ' ORDER BY filetime DESC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('orphan', array('FILESIZE' => get_formatted_filesize($row['filesize']), 'FILETIME' => $user->format_date($row['filetime']), 'REAL_FILENAME' => basename($row['real_filename']), 'PHYSICAL_FILENAME' => basename($row['physical_filename']), 'ATTACH_ID' => $row['attach_id'], 'POST_IDS' => !empty($post_ids[$row['attach_id']]) ? $post_ids[$row['attach_id']] : '', 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&id=' . $row['attach_id']))); } $db->sql_freeresult($result); break; } if (sizeof($error)) { $template->assign_vars(array('S_WARNING' => true, 'WARNING_MSG' => implode('<br />', $error))); } if (sizeof($notify)) { $template->assign_vars(array('S_NOTIFY' => true, 'NOTIFY_MSG' => implode('<br />', $notify))); } }
function main($id, $mode) { global $db, $user, $auth, $template, $cache, $request, $phpbb_dispatcher; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); // Set up general vars $action = request_var('action', ''); $action = isset($_POST['add']) ? 'add' : $action; $action = isset($_POST['save']) ? 'save' : $action; $rank_id = request_var('id', 0); $this->tpl_name = 'acp_ranks'; $this->page_title = 'ACP_MANAGE_RANKS'; $form_name = 'acp_ranks'; add_form_key($form_name); switch ($action) { case 'save': if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $rank_title = utf8_normalize_nfc(request_var('title', '', true)); $special_rank = request_var('special_rank', 0); $min_posts = $special_rank ? 0 : max(0, request_var('min_posts', 0)); $rank_image = request_var('rank_image', ''); // The rank image has to be a jpg, gif or png if ($rank_image != '' && !preg_match('#(\\.gif|\\.png|\\.jpg|\\.jpeg)$#i', $rank_image)) { $rank_image = ''; } if (!$rank_title) { trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_ary = array('rank_title' => $rank_title, 'rank_special' => $special_rank, 'rank_min' => $min_posts, 'rank_image' => htmlspecialchars_decode($rank_image)); /** * Modify the SQL array when saving a rank * * @event core.acp_ranks_save_modify_sql_ary * @var int rank_id The ID of the rank (if available) * @var array sql_ary Array with the rank's data * @since 3.1.0-RC3 */ $vars = array('rank_id', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.acp_ranks_save_modify_sql_ary', compact($vars))); if ($rank_id) { $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = {$rank_id}"; $message = $user->lang['RANK_UPDATED']; add_log('admin', 'LOG_RANK_UPDATED', $rank_title); } else { $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $message = $user->lang['RANK_ADDED']; add_log('admin', 'LOG_RANK_ADDED', $rank_title); } $db->sql_query($sql); $cache->destroy('_ranks'); trigger_error($message . adm_back_link($this->u_action)); break; case 'delete': if (!$rank_id) { trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING); } if (confirm_box(true)) { $sql = 'SELECT rank_title FROM ' . RANKS_TABLE . ' WHERE rank_id = ' . $rank_id; $result = $db->sql_query($sql); $rank_title = (string) $db->sql_fetchfield('rank_title'); $db->sql_freeresult($result); $sql = 'DELETE FROM ' . RANKS_TABLE . "\n\t\t\t\t\t\tWHERE rank_id = {$rank_id}"; $db->sql_query($sql); $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = 0\n\t\t\t\t\t\tWHERE user_rank = {$rank_id}"; $db->sql_query($sql); $cache->destroy('_ranks'); add_log('admin', 'LOG_RANK_REMOVED', $rank_title); if ($request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $user->lang['RANK_REMOVED'], 'REFRESH_DATA' => array('time' => 3))); } } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'rank_id' => $rank_id, 'action' => 'delete'))); } break; case 'edit': case 'add': $data = $ranks = $existing_imgs = array(); $sql = 'SELECT * FROM ' . RANKS_TABLE . ' ORDER BY rank_min ASC, rank_special ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $existing_imgs[] = $row['rank_image']; if ($action == 'edit' && $rank_id == $row['rank_id']) { $ranks = $row; } } $db->sql_freeresult($result); $imglist = filelist($phpbb_root_path . $config['ranks_path'], ''); $edit_img = $filename_list = ''; foreach ($imglist as $path => $img_ary) { sort($img_ary); foreach ($img_ary as $img) { $img = $path . $img; if ($ranks && $img == $ranks['rank_image']) { $selected = ' selected="selected"'; $edit_img = $img; } else { $selected = ''; } if (strlen($img) > 255) { continue; } $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . (in_array($img, $existing_imgs) ? ' ' . $user->lang['RANK_IMAGE_IN_USE'] : '') . '</option>'; } } $filename_list = '<option value=""' . ($edit_img == '' ? ' selected="selected"' : '') . '>----------</option>' . $filename_list; unset($existing_imgs, $imglist); $tpl_ary = array('S_EDIT' => true, 'U_BACK' => $this->u_action, 'RANKS_PATH' => $phpbb_root_path . $config['ranks_path'], 'U_ACTION' => $this->u_action . '&id=' . $rank_id, 'RANK_TITLE' => isset($ranks['rank_title']) ? $ranks['rank_title'] : '', 'S_FILENAME_LIST' => $filename_list, 'RANK_IMAGE' => $edit_img ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : htmlspecialchars($phpbb_admin_path) . 'images/spacer.gif', 'S_SPECIAL_RANK' => isset($ranks['rank_special']) && $ranks['rank_special'] ? true : false, 'MIN_POSTS' => isset($ranks['rank_min']) && !$ranks['rank_special'] ? $ranks['rank_min'] : 0); /** * Modify the template output array for editing/adding ranks * * @event core.acp_ranks_edit_modify_tpl_ary * @var array ranks Array with the rank's data * @var array tpl_ary Array with the rank's template data * @since 3.1.0-RC3 */ $vars = array('ranks', 'tpl_ary'); extract($phpbb_dispatcher->trigger_event('core.acp_ranks_edit_modify_tpl_ary', compact($vars))); $template->assign_vars($tpl_ary); return; break; } $template->assign_vars(array('U_ACTION' => $this->u_action)); $sql = 'SELECT * FROM ' . RANKS_TABLE . ' ORDER BY rank_special DESC, rank_min ASC, rank_title ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $rank_row = array('S_RANK_IMAGE' => $row['rank_image'] ? true : false, 'S_SPECIAL_RANK' => $row['rank_special'] ? true : false, 'RANK_IMAGE' => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'], 'RANK_TITLE' => $row['rank_title'], 'MIN_POSTS' => $row['rank_min'], 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['rank_id'], 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['rank_id']); /** * Modify the template output array for each listed rank * * @event core.acp_ranks_list_modify_rank_row * @var array row Array with the rank's data * @var array rank_row Array with the rank's template data * @since 3.1.0-RC3 */ $vars = array('row', 'rank_row'); extract($phpbb_dispatcher->trigger_event('core.acp_ranks_list_modify_rank_row', compact($vars))); $template->assign_block_vars('ranks', $rank_row); } $db->sql_freeresult($result); }
function main($id, $mode) { global $db, $user, $auth, $template, $cache; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); // Set up general vars $action = request_var('action', ''); $action = (isset($_POST['add'])) ? 'add' : $action; $action = (isset($_POST['edit'])) ? 'edit' : $action; $action = (isset($_POST['import'])) ? 'import' : $action; $icon_id = request_var('id', 0); $mode = ($mode == 'smilies') ? 'smilies' : 'icons'; $this->tpl_name = 'acp_icons'; // What are we working on? switch ($mode) { case 'smilies': $table = SMILIES_TABLE; $lang = 'SMILIES'; $fields = 'smiley'; $img_path = $config['smilies_path']; break; case 'icons': $table = ICONS_TABLE; $lang = 'ICONS'; $fields = 'icons'; $img_path = $config['icons_path']; break; } $this->page_title = 'ACP_' . $lang; // Clear some arrays $_images = $_paks = array(); $notice = ''; // Grab file list of paks and images if ($action == 'edit' || $action == 'add' || $action == 'import') { $imglist = filelist($phpbb_root_path . $img_path, ''); foreach ($imglist as $path => $img_ary) { foreach ($img_ary as $img) { $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $path . $img); if (!$img_size[0] || !$img_size[1] || strlen($img) > 255) { continue; } $_images[$path . $img]['file'] = $path . $img; $_images[$path . $img]['width'] = $img_size[0]; $_images[$path . $img]['height'] = $img_size[1]; } } unset($imglist); if ($dir = @opendir($phpbb_root_path . $img_path)) { while (($file = readdir($dir)) !== false) { if (is_file($phpbb_root_path . $img_path . '/' . $file) && preg_match('#\.pak$#i', $file)) { $_paks[] = $file; } } closedir($dir); } } // What shall we do today? Oops, I believe that's trademarked ... switch ($action) { case 'edit': unset($_images); $_images = array(); // no break; case 'add': $smilies = $default_row = array(); $smiley_options = $order_list = $add_order_list = ''; if ($action == 'add' && $mode == 'smilies') { $sql = 'SELECT * FROM ' . SMILIES_TABLE . ' ORDER BY smiley_order'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (empty($smilies[$row['smiley_url']])) { $smilies[$row['smiley_url']] = $row; } } $db->sql_freeresult($result); if (sizeof($smilies)) { foreach ($smilies as $row) { $selected = false; if (!$smiley_options) { $selected = true; $default_row = $row; } $smiley_options .= '<option value="' . $row['smiley_url'] . '"' . (($selected) ? ' selected="selected"' : '') . '>' . $row['smiley_url'] . '</option>'; $template->assign_block_vars('smile', array( 'SMILEY_URL' => addslashes($row['smiley_url']), 'CODE' => addslashes($row['code']), 'EMOTION' => addslashes($row['emotion']), 'WIDTH' => $row['smiley_width'], 'HEIGHT' => $row['smiley_height'], 'ORDER' => $row['smiley_order'] + 1, )); } } } $sql = "SELECT * FROM $table ORDER BY {$fields}_order " . (($icon_id || $action == 'add') ? 'DESC' : 'ASC'); $result = $db->sql_query($sql); $data = array(); $after = false; $display = 0; $order_lists = array('', ''); $add_order_lists = array('', ''); $display_count = 0; while ($row = $db->sql_fetchrow($result)) { if ($action == 'add') { unset($_images[$row[$fields . '_url']]); } if ($row[$fields . '_id'] == $icon_id) { $after = true; $display = $row['display_on_posting']; $data[$row[$fields . '_url']] = $row; } else { if ($action == 'edit' && !$icon_id) { $data[$row[$fields . '_url']] = $row; } $selected = ''; if (!empty($after)) { $selected = ' selected="selected"'; $after = false; } if ($row['display_on_posting']) { $display_count++; } $after_txt = ($mode == 'smilies') ? $row['code'] : $row['icons_url']; $order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . $selected . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . $after_txt) . '</option>' . $order_lists[$row['display_on_posting']]; if (!empty($default_row)) { $add_order_lists[$row['display_on_posting']] = '<option value="' . ($row[$fields . '_order'] + 1) . '"' . (($row[$fields . '_id'] == $default_row['smiley_id']) ? ' selected="selected"' : '') . '>' . sprintf($user->lang['AFTER_' . $lang], ' -> ' . $after_txt) . '</option>' . $add_order_lists[$row['display_on_posting']]; } } } $db->sql_freeresult($result); $order_list = '<option value="1"' . ((!isset($after)) ? ' selected="selected"' : '') . '>' . $user->lang['FIRST'] . '</option>'; $add_order_list = '<option value="1">' . $user->lang['FIRST'] . '</option>'; if ($action == 'add') { $data = $_images; } $colspan = (($mode == 'smilies') ? '7' : '5'); $colspan += ($icon_id) ? 1 : 0; $colspan += ($action == 'add') ? 2 : 0; $template->assign_vars(array( 'S_EDIT' => true, 'S_SMILIES' => ($mode == 'smilies') ? true : false, 'S_ADD' => ($action == 'add') ? true : false, 'S_ORDER_LIST_DISPLAY' => $order_list . $order_lists[1], 'S_ORDER_LIST_UNDISPLAY' => $order_list . $order_lists[0], 'S_ORDER_LIST_DISPLAY_COUNT' => $display_count + 1, 'L_TITLE' => $user->lang['ACP_' . $lang], 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 'L_CONFIG' => $user->lang[$lang . '_CONFIG'], 'L_URL' => $user->lang[$lang . '_URL'], 'L_LOCATION' => $user->lang[$lang . '_LOCATION'], 'L_WIDTH' => $user->lang[$lang . '_WIDTH'], 'L_HEIGHT' => $user->lang[$lang . '_HEIGHT'], 'L_ORDER' => $user->lang[$lang . '_ORDER'], 'L_NO_ICONS' => $user->lang['NO_' . $lang . '_' . strtoupper($action)], 'COLSPAN' => $colspan, 'ID' => $icon_id, 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=' . (($action == 'add') ? 'create' : 'modify'), )); foreach ($data as $img => $img_row) { $template->assign_block_vars('items', array( 'IMG' => $img, 'A_IMG' => addslashes($img), 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $img, 'CODE' => ($mode == 'smilies' && isset($img_row['code'])) ? $img_row['code'] : '', 'EMOTION' => ($mode == 'smilies' && isset($img_row['emotion'])) ? $img_row['emotion'] : '', 'S_ID' => (isset($img_row[$fields . '_id'])) ? true : false, 'ID' => (isset($img_row[$fields . '_id'])) ? $img_row[$fields . '_id'] : 0, 'WIDTH' => (!empty($img_row[$fields .'_width'])) ? $img_row[$fields .'_width'] : $img_row['width'], 'HEIGHT' => (!empty($img_row[$fields .'_height'])) ? $img_row[$fields .'_height'] : $img_row['height'], 'POSTING_CHECKED' => (!empty($img_row['display_on_posting']) || $action == 'add') ? ' checked="checked"' : '', )); } // Ok, another row for adding an addition code for a pre-existing image... if ($action == 'add' && $mode == 'smilies' && sizeof($smilies)) { $template->assign_vars(array( 'S_ADD_CODE' => true, 'S_IMG_OPTIONS' => $smiley_options, 'S_ADD_ORDER_LIST_DISPLAY' => $add_order_list . $add_order_lists[1], 'S_ADD_ORDER_LIST_UNDISPLAY' => $add_order_list . $add_order_lists[0], 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $default_row['smiley_url'], 'IMG_PATH' => $img_path, 'PHPBB_ROOT_PATH' => $phpbb_root_path, 'CODE' => $default_row['code'], 'EMOTION' => $default_row['emotion'], 'WIDTH' => $default_row['smiley_width'], 'HEIGHT' => $default_row['smiley_height'], )); } return; break; case 'create': case 'modify': // Get items to create/modify $images = (isset($_POST['image'])) ? array_keys(request_var('image', array('' => 0))) : array(); // Now really get the items $image_id = (isset($_POST['id'])) ? request_var('id', array('' => 0)) : array(); $image_order = (isset($_POST['order'])) ? request_var('order', array('' => 0)) : array(); $image_width = (isset($_POST['width'])) ? request_var('width', array('' => 0)) : array(); $image_height = (isset($_POST['height'])) ? request_var('height', array('' => 0)) : array(); $image_add = (isset($_POST['add_img'])) ? request_var('add_img', array('' => 0)) : array(); $image_emotion = utf8_normalize_nfc(request_var('emotion', array('' => ''), true)); $image_code = utf8_normalize_nfc(request_var('code', array('' => ''), true)); $image_display_on_posting = (isset($_POST['display_on_posting'])) ? request_var('display_on_posting', array('' => 0)) : array(); // Ok, add the relevant bits if we are adding new codes to existing emoticons... if (!empty($_POST['add_additional_code'])) { $add_image = request_var('add_image', ''); $add_code = utf8_normalize_nfc(request_var('add_code', '', true)); $add_emotion = utf8_normalize_nfc(request_var('add_emotion', '', true)); if ($add_image && $add_emotion && $add_code) { $images[] = $add_image; $image_add[$add_image] = true; $image_code[$add_image] = $add_code; $image_emotion[$add_image] = $add_emotion; $image_width[$add_image] = request_var('add_width', 0); $image_height[$add_image] = request_var('add_height', 0); if (!empty($_POST['add_display_on_posting'])) { $image_display_on_posting[$add_image] = 1; } $image_order[$add_image] = request_var('add_order', 0); } } $icons_updated = 0; foreach ($images as $image) { if (($mode == 'smilies' && ($image_emotion[$image] == '' || $image_code[$image] == '')) || ($action == 'create' && !isset($image_add[$image]))) { } else { if ($image_width[$image] == 0 || $image_height[$image] == 0) { $img_size = getimagesize($phpbb_root_path . $img_path . '/' . $image); $image_width[$image] = $img_size[0]; $image_height[$image] = $img_size[1]; } $img_sql = array( $fields . '_url' => $image, $fields . '_width' => $image_width[$image], $fields . '_height' => $image_height[$image], 'display_on_posting' => (isset($image_display_on_posting[$image])) ? 1 : 0, ); if ($mode == 'smilies') { $img_sql = array_merge($img_sql, array( 'emotion' => $image_emotion[$image], 'code' => $image_code[$image]) ); } // Image_order holds the 'new' order value if (!empty($image_order[$image])) { $img_sql = array_merge($img_sql, array( $fields . '_order' => $image_order[$image]) ); // Since we always add 'after' an item, we just need to increase all following + the current by one $sql = "UPDATE $table SET {$fields}_order = {$fields}_order + 1 WHERE {$fields}_order >= {$image_order[$image]}"; $db->sql_query($sql); // If we adjust the order, we need to adjust all other orders too - they became inaccurate... foreach ($image_order as $_image => $_order) { if ($_image == $image) { continue; } if ($_order >= $image_order[$image]) { $image_order[$_image]++; } } } if ($action == 'modify' && !empty($image_id[$image])) { $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $img_sql) . " WHERE {$fields}_id = " . $image_id[$image]; $db->sql_query($sql); $icons_updated++; } else if ($action !== 'modify') { $sql = "INSERT INTO $table " . $db->sql_build_array('INSERT', $img_sql); $db->sql_query($sql); $icons_updated++; } } } $cache->destroy('_icons'); $cache->destroy('sql', $table); $level = E_USER_NOTICE; switch ($icons_updated) { case 0: $suc_lang = "{$lang}_NONE"; $level = E_USER_WARNING; break; case 1: $suc_lang = "{$lang}_ONE"; break; default: $suc_lang = $lang; } if ($action == 'modify') { trigger_error($user->lang[$suc_lang . '_EDITED'] . adm_back_link($this->u_action), $level); } else { trigger_error($user->lang[$suc_lang . '_ADDED'] . adm_back_link($this->u_action), $level); } break; case 'import': $pak = request_var('pak', ''); $current = request_var('current', ''); if ($pak != '') { $order = 0; if (!($pak_ary = @file($phpbb_root_path . $img_path . '/' . $pak))) { trigger_error($user->lang['PAK_FILE_NOT_READABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } // Make sure the pak_ary is valid foreach ($pak_ary as $pak_entry) { if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data)) { if ((sizeof($data[1]) != 4 && $mode == 'icons') || (sizeof($data[1]) != 6 && $mode == 'smilies')) { trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } } else { trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } } // The user has already selected a smilies_pak file if ($current == 'delete') { switch ($db->sql_layer) { case 'sqlite': case 'firebird': $db->sql_query('DELETE FROM ' . $table); break; default: $db->sql_query('TRUNCATE TABLE ' . $table); break; } switch ($mode) { case 'smilies': break; case 'icons': // Reset all icon_ids $db->sql_query('UPDATE ' . TOPICS_TABLE . ' SET icon_id = 0'); $db->sql_query('UPDATE ' . POSTS_TABLE . ' SET icon_id = 0'); break; } } else { $cur_img = array(); $field_sql = ($mode == 'smilies') ? 'code' : 'icons_url'; $sql = "SELECT $field_sql FROM $table"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { ++$order; $cur_img[$row[$field_sql]] = 1; } $db->sql_freeresult($result); } foreach ($pak_ary as $pak_entry) { $data = array(); if (preg_match_all("#'(.*?)', ?#", $pak_entry, $data)) { if ((sizeof($data[1]) != 4 && $mode == 'icons') || (sizeof($data[1]) != 6 && $mode == 'smilies')) { trigger_error($user->lang['WRONG_PAK_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } // Stripslash here because it got addslashed before... (on export) $img = stripslashes($data[1][0]); $width = stripslashes($data[1][1]); $height = stripslashes($data[1][2]); $display_on_posting = stripslashes($data[1][3]); if (isset($data[1][4]) && isset($data[1][5])) { $emotion = stripslashes($data[1][4]); $code = stripslashes($data[1][5]); } if ($current == 'replace' && (($mode == 'smilies' && !empty($cur_img[$code])) || ($mode == 'icons' && !empty($cur_img[$img])))) { $replace_sql = ($mode == 'smilies') ? $code : $img; $sql = array( $fields . '_url' => $img, $fields . '_height' => (int) $height, $fields . '_width' => (int) $width, 'display_on_posting' => (int) $display_on_posting, ); if ($mode == 'smilies') { $sql = array_merge($sql, array( 'emotion' => $emotion, )); } $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql) . " WHERE $field_sql = '" . $db->sql_escape($replace_sql) . "'"; $db->sql_query($sql); } else { ++$order; $sql = array( $fields . '_url' => $img, $fields . '_height' => (int) $height, $fields . '_width' => (int) $width, $fields . '_order' => (int) $order, 'display_on_posting'=> (int) $display_on_posting, ); if ($mode == 'smilies') { $sql = array_merge($sql, array( 'code' => $code, 'emotion' => $emotion, )); } $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql)); } } } $cache->destroy('_icons'); $cache->destroy('sql', $table); trigger_error($user->lang[$lang . '_IMPORT_SUCCESS'] . adm_back_link($this->u_action)); } else { $pak_options = ''; foreach ($_paks as $pak) { $pak_options .= '<option value="' . $pak . '">' . htmlspecialchars($pak) . '</option>'; } $template->assign_vars(array( 'S_CHOOSE_PAK' => true, 'S_PAK_OPTIONS' => $pak_options, 'L_TITLE' => $user->lang['ACP_' . $lang], 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 'L_NO_PAK_OPTIONS' => $user->lang['NO_' . $lang . '_PAK'], 'L_CURRENT' => $user->lang['CURRENT_' . $lang], 'L_CURRENT_EXPLAIN' => $user->lang['CURRENT_' . $lang . '_EXPLAIN'], 'L_IMPORT_SUBMIT' => $user->lang['IMPORT_' . $lang], 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . '&action=import', ) ); } break; case 'export': $this->page_title = 'EXPORT_' . $lang; $this->tpl_name = 'message_body'; $template->assign_vars(array( 'MESSAGE_TITLE' => $user->lang['EXPORT_' . $lang], 'MESSAGE_TEXT' => sprintf($user->lang['EXPORT_' . $lang . '_EXPLAIN'], '<a href="' . $this->u_action . '&action=send">', '</a>'), 'S_USER_NOTICE' => true, ) ); return; break; case 'send': $sql = "SELECT * FROM $table ORDER BY {$fields}_order"; $result = $db->sql_query($sql); $pak = ''; while ($row = $db->sql_fetchrow($result)) { $pak .= "'" . addslashes($row[$fields . '_url']) . "', "; $pak .= "'" . addslashes($row[$fields . '_width']) . "', "; $pak .= "'" . addslashes($row[$fields . '_height']) . "', "; $pak .= "'" . addslashes($row['display_on_posting']) . "', "; if ($mode == 'smilies') { $pak .= "'" . addslashes($row['emotion']) . "', "; $pak .= "'" . addslashes($row['code']) . "', "; } $pak .= "\n"; } $db->sql_freeresult($result); if ($pak != '') { garbage_collection(); header('Pragma: public'); // Send out the Headers header('Content-Type: text/x-delimtext; name="' . $mode . '.pak"'); header('Content-Disposition: inline; filename="' . $mode . '.pak"'); echo $pak; flush(); exit; } else { trigger_error($user->lang['NO_' . strtoupper($fields) . '_EXPORT'] . adm_back_link($this->u_action), E_USER_WARNING); } break; case 'delete': if (confirm_box(true)) { $sql = "DELETE FROM $table WHERE {$fields}_id = $icon_id"; $db->sql_query($sql); switch ($mode) { case 'smilies': break; case 'icons': // Reset appropriate icon_ids $db->sql_query('UPDATE ' . TOPICS_TABLE . " SET icon_id = 0 WHERE icon_id = $icon_id"); $db->sql_query('UPDATE ' . POSTS_TABLE . " SET icon_id = 0 WHERE icon_id = $icon_id"); break; } $notice = $user->lang[$lang . '_DELETED']; $cache->destroy('_icons'); $cache->destroy('sql', $table); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( 'i' => $id, 'mode' => $mode, 'id' => $icon_id, 'action' => 'delete', ))); } break; case 'move_up': case 'move_down': // Get current order id... $sql = "SELECT {$fields}_order as current_order FROM $table WHERE {$fields}_id = $icon_id"; $result = $db->sql_query($sql); $current_order = (int) $db->sql_fetchfield('current_order'); $db->sql_freeresult($result); if ($current_order == 0 && $action == 'move_up') { break; } // on move_down, switch position with next order_id... // on move_up, switch position with previous order_id... $switch_order_id = ($action == 'move_down') ? $current_order + 1 : $current_order - 1; // $sql = "UPDATE $table SET {$fields}_order = $current_order WHERE {$fields}_order = $switch_order_id AND {$fields}_id <> $icon_id"; $db->sql_query($sql); // Only update the other entry too if the previous entry got updated if ($db->sql_affectedrows()) { $sql = "UPDATE $table SET {$fields}_order = $switch_order_id WHERE {$fields}_order = $current_order AND {$fields}_id = $icon_id"; $db->sql_query($sql); } $cache->destroy('_icons'); $cache->destroy('sql', $table); break; } // By default, check that image_order is valid and fix it if necessary $sql = "SELECT {$fields}_id AS order_id, {$fields}_order AS fields_order FROM $table ORDER BY display_on_posting DESC, {$fields}_order"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $order = 0; do { ++$order; if ($row['fields_order'] != $order) { $db->sql_query("UPDATE $table SET {$fields}_order = $order WHERE {$fields}_id = " . $row['order_id']); } } while ($row = $db->sql_fetchrow($result)); } $db->sql_freeresult($result); $template->assign_vars(array( 'L_TITLE' => $user->lang['ACP_' . $lang], 'L_EXPLAIN' => $user->lang['ACP_' . $lang . '_EXPLAIN'], 'L_IMPORT' => $user->lang['IMPORT_' . $lang], 'L_EXPORT' => $user->lang['EXPORT_' . $lang], 'L_NOT_DISPLAYED' => $user->lang[$lang . '_NOT_DISPLAYED'], 'L_ICON_ADD' => $user->lang['ADD_' . $lang], 'L_ICON_EDIT' => $user->lang['EDIT_' . $lang], 'NOTICE' => $notice, 'COLSPAN' => ($mode == 'smilies') ? 5 : 3, 'S_SMILIES' => ($mode == 'smilies') ? true : false, 'U_ACTION' => $this->u_action, 'U_IMPORT' => $this->u_action . '&action=import', 'U_EXPORT' => $this->u_action . '&action=export', ) ); $spacer = false; $sql = "SELECT * FROM $table ORDER BY {$fields}_order ASC"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $alt_text = ($mode == 'smilies') ? $row['code'] : ''; $template->assign_block_vars('items', array( 'S_SPACER' => (!$spacer && !$row['display_on_posting']) ? true : false, 'ALT_TEXT' => $alt_text, 'IMG_SRC' => $phpbb_root_path . $img_path . '/' . $row[$fields . '_url'], 'WIDTH' => $row[$fields . '_width'], 'HEIGHT' => $row[$fields . '_height'], 'CODE' => (isset($row['code'])) ? $row['code'] : '', 'EMOTION' => (isset($row['emotion'])) ? $row['emotion'] : '', 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row[$fields . '_id'], 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row[$fields . '_id'], 'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row[$fields . '_id'], 'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row[$fields . '_id']) ); if (!$spacer && !$row['display_on_posting']) { $spacer = true; } } $db->sql_freeresult($result); }
die("Please read the first lines of this script for instructions on how to enable it"); /** * @ignore */ define('IN_PHPBB', true); $phpbb_root_path = defined('PHPBB_ROOT_PATH') ? PHPBB_ROOT_PATH : './../../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include $phpbb_root_path . 'common.' . $phpEx; // Start session management $user->session_begin(); $auth->acl($user->data); $user->setup(); if (!function_exists('filelist')) { include $phpbb_root_path . 'includes/functions_admin.' . $phpEx; } $fl = filelist($phpbb_root_path, '', 'php'); $whitelist = array(); foreach ($fl as $d => $fs) { // Compensate for filelist weirdness if (empty($fl[$d])) { continue; } // Cache files are always ignored if ($d == 'cache/') { continue; } // Files in `develop/` and `store/` are always ignored if (preg_match('#^(stk/){0,1}(develop|store)/#i', $d)) { continue; } // Skip non-english
function galery($gal = "", $width = 0, $height = 0) { global $gallerymessage, $set, $prefix; if (file_exists("addons/gallery/lang/lang_" . $set['language'] . ".php")) { require_once "addons/gallery/lang/lang_" . $set['language'] . ".php"; } else { require_once "addons/gallery/lang/lang_en_US.php"; } require_once "addons/gallery/common.php"; if (file_exists("./addons/gallery/settings.php")) { require_once "./addons/gallery/settings.php"; } $out = ""; if ($gal != "") { $count = 1; $out .= "<h2>" . $gal . "</h2><br />\n"; $galeries[0] = $gal; } else { if (isset($_POST['gal'])) { $gal = sanitize($_POST['gal']); } $folder = "galeries"; $files = filelist('/./', $folder, 1); $folder = "galeries"; $count = 0; foreach ($files as $file) { if ($file != ".." && $file != "." && is_dir($folder . "/" . $file)) { $galeries[$count] = $file; $count++; } } } if ($count > 1) { $out .= "\n<form method=\"post\" name=\"galery\" action=\"\"><fieldset style=\"border: 0;\">\n"; $out .= "<select onchange=\"document.galery.submit();\" name=\"gal\" class=\"LNE_select\">\n"; for ($i = 0; $i < $count; $i++) { $out .= '<option value="' . $galeries[$i] . '"'; if ($gal == $galeries[$i]) { $out .= " selected"; } $out .= ">" . $galeries[$i] . " </option>\n"; if ($gal == "") { $gal = $galeries[$i]; } } $out .= "</select>\n"; $out .= "<input type=\"hidden\" name=\"showgalery\" value=\"{$gallerymessage['94']}\" />\n"; $out .= "</fieldset></form>\n"; $out .= "<br />\n"; } else { $gal = $galeries[0]; } //$gal contains the galery folder $gal = "galeries/" . $gal; $filez = filelist('/./', $gal); foreach ($filez as $file) { if ($file != "index.html") { if (intval($thumbnailwidth) == 0) { $thumbnailwidth = 100; } if ($row = fetch_array(dbquery("SELECT * FROM " . $prefix . "images WHERE file=\"" . basename($file) . "\""))) { $filename = decode($row['name']); } else { $filename = $file; } $out .= "<a href=\"{$gal}/{$file}\" rel=\"lytebox[" . $gal . "]\" title=\"{$filename}\" >"; $tname = createThumb($gal . "/" . $file, "thumbs/", $thumbnailwidth); $out .= "<img src=\"thumbs/" . $tname . "\" width=\"{$thumbnailwidth}\" alt=\"{$filename}\" class=\"bordered\" /></a>\n"; } } return $out; }
function setup() { global $langmessage, $set; $out .= "<form method=\"post\" action=\"\">\n"; $out .= "<h2>{$langmessage['130']}</h2>\n<fieldset><table id=\"LNE_setup\">\n"; $out .= "<tr><td align=\"right\">{$langmessage['6']}:</td>\n"; $out .= "<td><input type=\"text\" name=\"password\" value=\"\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['7']}:</td>\n"; $out .= "<td><input type=\"text\" name=\"admin\" value=\"" . $set['admin'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['8']}:</td>\n"; $out .= "<td><input type=\"text\" name=\"email\" value=\"" . $set['email'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['9']}:</td>\n"; $out .= "<td><input type=\"text\" name=\"wemail\" value=\"" . $set['wemail'] . "\" /></td></tr>\n"; $out .= "<input type=\"hidden\" name=\"restricted\" value=\"\" />"; $out .= "<tr><td align=\"right\">{$langmessage['10']}:</td>\n"; $out .= "<td><input type=\"text\" name=\"homepath\" value=\"" . $set['homepath'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['11']}:</td>\n<td><select name=\"template\">\n"; $folder = "templates"; $filez = filelist('/./', $folder, 1); foreach ($filez as $fil) { $out .= '<option value="' . $fil . '"'; if ($set['template'] == $fil) { $out .= " SELECTED"; } $out .= '>' . $fil . "</option>\n"; } $out .= "</select>\n</td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['12']}:</td><td><input type=\"text\" name=\"title\" value=\"" . $set['title'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['13']}:</td><td><input type=\"text\" name=\"subtitle\" value=\"" . $set['subtitle'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['14']}:</td><td><textarea name=\"keywords\">" . $set['keywords'] . "</textarea></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['15']}:</td><td><textarea name=\"description\">" . $set['description'] . "</textarea></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['16']}:</td><td><input type=\"text\" name=\"author\" value=\"" . $set['author'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['17']}:</td><td><input type=\"text\" name=\"footer\" value=\"" . $set['footer'] . "\" style=\"width: 450px;\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['145']}:</td><td><input type=\"text\" name=\"timeoffset\" value=\"" . $set['timeoffset'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['151']}:</td><td><input type=\"text\" name=\"dateformat\" value=\"" . $set['dateformat'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['19']}:</td>\n<td><input type=\"text\" name=\"indexfile\" value=\"" . $set['indexfile'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['57']}:</td>\n<td><input type=\"text\" name=\"restricted\" value=\"" . $set['restricted'] . "\" /></td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['20']}:</td>\n<td><select name=\"language\">\n"; $folder = "languages"; $filez = filelist('/./', $folder); foreach ($filez as $fil) { $out .= '<option value="' . substr($fil, 5, 5) . '"'; if (substr($fil, 5, 5) == $set['language']) { $out .= ' SELECTED'; } $out .= '>' . substr($fil, 0, 10) . "</option>\n"; } $out .= "</select>\n</td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['21']}:</td>\n<td><select name=\"langeditor\">\n"; $out .= "<option value=\"ZZ\">Default</option>\n"; $folder = "fckeditor/editor/lang"; $filez = filelist('/./', $folder); foreach ($filez as $fil) { if (strpos($fil, ".js")) { $out .= '<option value="' . substr($fil, 0, 2) . '"'; if (substr($fil, 0, 2) == $set['langeditor']) { $out .= ' SELECTED'; } $out .= '>' . $fil . "</option>\n"; } } $out .= "</select>\n</td></tr>\n"; $out .= "<tr><td align=\"right\">{$langmessage['18']}:</td>\n<td><select name=\"gzip\">\n"; $out .= "<option value=\"1\">{$langmessage['59']} </option>\n"; $out .= "<option value=\"0\""; if ($set['gzip'] == 0) { $out .= " SELECTED"; } $out .= ">{$langmessage['60']} </option>\n"; $out .= "</select></td>\n"; $out .= "<tr><td align=\"right\">{$langmessage['32']}:</td>\n<td><select name=\"extension\">\n"; $out .= "<OPTION VALUE=\"1\">{$langmessage['182']} </OPTION>\n"; $out .= "<OPTION VALUE=\"0\""; if ($set['extension'] == 0) { $out .= " SELECTED"; } $out .= ">{$langmessage['58']} </OPTION>\n"; $out .= "</select>\n</td></tr>\n"; $out .= "<tr><td><input type=\"hidden\" name=\"submit\" value=\"Save Setup\" />\n"; $out .= "</td><td><input type=\"submit\" name=\"\" value=\"{$langmessage['25']}\" /></td></tr>\n"; $out .= "</table>\n</fieldset></form>\n"; return $out; }
/** * Get physical file listing */ function filelist($rootdir, $dir = '', $type = 'gif|jpg|jpeg|png') { $matches = array($dir => array()); // Remove initial / if present $rootdir = substr($rootdir, 0, 1) == '/' ? substr($rootdir, 1) : $rootdir; // Add closing / if not present $rootdir = $rootdir && substr($rootdir, -1) != '/' ? $rootdir . '/' : $rootdir; // Remove initial / if present $dir = substr($dir, 0, 1) == '/' ? substr($dir, 1) : $dir; // Add closing / if not present $dir = $dir && substr($dir, -1) != '/' ? $dir . '/' : $dir; if (!is_dir($rootdir . $dir)) { return $matches; } $dh = @opendir($rootdir . $dir); if (!$dh) { return $matches; } while (($fname = readdir($dh)) !== false) { if (is_file("{$rootdir}{$dir}{$fname}")) { if (filesize("{$rootdir}{$dir}{$fname}") && preg_match('#\\.' . $type . '$#i', $fname)) { $matches[$dir][] = $fname; } } else { if ($fname[0] != '.' && is_dir("{$rootdir}{$dir}{$fname}")) { $matches += filelist($rootdir, "{$dir}{$fname}", $type); } } } closedir($dh); return $matches; }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $safe_mode, $file_uploads; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; $this->default_variables(); // Check and set some common vars $action = isset($_POST['update_details']) ? 'update_details' : ''; $action = isset($_POST['download_file']) ? 'download_file' : $action; $action = isset($_POST['upload_file']) ? 'upload_file' : $action; $action = isset($_POST['upload_data']) ? 'upload_data' : $action; $action = isset($_POST['submit_file']) ? 'submit_file' : $action; $action = isset($_POST['remove_store']) ? 'details' : $action; $submit = empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection']) ? false : true; $action = empty($action) ? request_var('action', '') : $action; $form_name = 'acp_lang'; add_form_key('acp_lang'); $lang_id = request_var('id', 0); if (isset($_POST['missing_file'])) { $missing_file = request_var('missing_file', array('' => 0)); list($_REQUEST['language_file'], ) = array_keys($missing_file); } $selected_lang_file = request_var('language_file', '|common.' . $phpEx); list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file); $this->language_directory = basename($this->language_directory); $this->language_file = basename($this->language_file); $user->add_lang('acp/language'); $this->tpl_name = 'acp_language'; $this->page_title = 'ACP_LANGUAGE_PACKS'; if ($submit && $action == 'upload_data' && request_var('test_connection', '')) { $test_connection = false; $action = 'upload_file'; $method = request_var('method', ''); include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; switch ($method) { case 'ftp': $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; case 'ftp_fsock': $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; default: trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); break; } $test_connection = $transfer->open_session(); $transfer->close_session(); } switch ($action) { case 'upload_file': include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; $method = request_var('method', ''); if (!class_exists($method)) { trigger_error('Method does not exist.', E_USER_ERROR); } $requested_data = call_user_func(array($method, 'data')); foreach ($requested_data as $data => $default) { $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default)); } $hidden_data = build_hidden_fields(array('file' => $this->language_file, 'dir' => $this->language_directory, 'language_file' => $selected_lang_file, 'method' => $method)); $hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP); $template->assign_vars(array('S_UPLOAD' => true, 'NAME' => $method, 'U_ACTION' => $this->u_action . "&id={$lang_id}&action=upload_data", 'U_BACK' => $this->u_action . "&id={$lang_id}&action=details&language_file=" . urlencode($selected_lang_file), 'HIDDEN' => $hidden_data, 'S_CONNECTION_SUCCESS' => request_var('test_connection', '') && $test_connection === true ? true : false, 'S_CONNECTION_FAILED' => request_var('test_connection', '') && $test_connection !== true ? true : false)); break; case 'update_details': if (!$submit || !check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT * FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_id = {$lang_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $sql_ary = array('lang_english_name' => request_var('lang_english_name', $row['lang_english_name']), 'lang_local_name' => utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)), 'lang_author' => utf8_normalize_nfc(request_var('lang_author', $row['lang_author'], true))); $db->sql_query('UPDATE ' . LANG_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE lang_id = ' . $lang_id); add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']); trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action)); break; case 'submit_file': case 'download_file': case 'upload_data': if (!$submit || !check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$lang_id || empty($_POST['entry'])) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($this->language_directory != 'email' && !is_array($_POST['entry'])) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$this->language_file || !$this->language_directory && !in_array($this->language_file, $this->main_files)) { trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT * FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_id = {$lang_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Before we attempt to write anything let's check if the admin really chose a correct filename switch ($this->language_directory) { case 'email': // Get email templates $email_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt'); $email_files = $email_files['email/']; if (!in_array($this->language_file, $email_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; case 'acp': // Get acp files $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx); $acp_files = $acp_files['acp/']; if (!in_array($this->language_file, $acp_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; case 'mods': // Get mod files $mods_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx); $mods_files = isset($mods_files['mods/']) ? $mods_files['mods/'] : array(); if (!in_array($this->language_file, $mods_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; default: if (!in_array($this->language_file, $this->main_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; } if (!$safe_mode) { $mkdir_ary = array('language', 'language/' . $row['lang_iso']); if ($this->language_directory) { $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory; } foreach ($mkdir_ary as $dir) { $dir = $phpbb_root_path . 'store/' . $dir; if (!is_dir($dir)) { if (!@mkdir($dir, 0777)) { trigger_error("Could not create directory {$dir}", E_USER_ERROR); } @chmod($dir, 0777); } } } // Get target filename for storage folder $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true); $fp = @fopen($phpbb_root_path . $filename, 'wb'); if (!$fp) { trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&id=' . $lang_id . '&action=details&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING); } if ($this->language_directory == 'email') { // Email Template $entry = $this->prepare_lang_entry($_POST['entry'], false); fwrite($fp, $entry); } else { $name = ($this->language_directory ? $this->language_directory . '_' : '') . $this->language_file; $header = str_replace(array('{FILENAME}', '{LANG_NAME}', '{CHANGED}', '{AUTHOR}'), array($name, $row['lang_english_name'], date('Y-m-d', time()), $row['lang_author']), $this->language_file_header); if (strpos($this->language_file, 'help_') === 0) { // Help File $header .= '$help = array(' . "\n"; fwrite($fp, $header); foreach ($_POST['entry'] as $key => $value) { if (!is_array($value)) { continue; } $entry = "\tarray(\n"; foreach ($value as $_key => $_value) { $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n"; } $entry .= "\t),\n"; fwrite($fp, $entry); } $footer = ");\n\n?>"; fwrite($fp, $footer); } else { // Language File $header .= $this->lang_header; fwrite($fp, $header); foreach ($_POST['entry'] as $key => $value) { $entry = $this->format_lang_array($key, $value); fwrite($fp, $entry); } $footer = "));\n\n?>"; fwrite($fp, $footer); } } fclose($fp); if ($action == 'download_file') { header('Pragma: no-cache'); header('Content-Type: application/octetstream; name="' . $this->language_file . '"'); header('Content-disposition: attachment; filename=' . $this->language_file); $fp = @fopen($phpbb_root_path . $filename, 'rb'); while ($buffer = fread($fp, 1024)) { echo $buffer; } fclose($fp); add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file); exit; } else { if ($action == 'upload_data') { $sql = 'SELECT lang_iso FROM ' . LANG_TABLE . "\n\t\t\t\t\t\tWHERE lang_id = {$lang_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $file = request_var('file', ''); $dir = request_var('dir', ''); $selected_lang_file = $dir . '|' . $file; $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true); $lang_path = 'language/' . $row['lang_iso'] . '/' . ($dir ? $dir . '/' : ''); include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; $method = request_var('method', ''); if ($method != 'ftp' && $method != 'ftp_fsock') { trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); } $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); if (($result = $transfer->open_session()) !== true) { trigger_error($user->lang[$result] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING); } $transfer->rename($lang_path . $file, $lang_path . $file . '.bak'); $result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file); if ($result === false) { // If failed, try to rename again and print error out... $transfer->delete_file($lang_path . $file); $transfer->rename($lang_path . $file . '.bak', $lang_path . $file); trigger_error($user->lang['UPLOAD_FAILED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file)), E_USER_WARNING); } $transfer->close_session(); // Remove from storage folder if (file_exists($phpbb_root_path . 'store/' . $lang_path . $file)) { @unlink($phpbb_root_path . 'store/' . $lang_path . $file); } add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file); trigger_error($user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id . '&language_file=' . urlencode($selected_lang_file))); } } add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file); $action = 'details'; // no break; // no break; case 'details': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->page_title = 'LANGUAGE_PACK_DETAILS'; $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $result = $db->sql_query($sql); $lang_entries = $db->sql_fetchrow($result); $db->sql_freeresult($result); $lang_iso = $lang_entries['lang_iso']; $missing_vars = $missing_files = array(); // Get email templates $email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt'); $email_files = $email_files['email/']; // Get acp files $acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx); $acp_files = $acp_files['acp/']; // Get mod files $mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx); $mods_files = isset($mods_files['mods/']) ? $mods_files['mods/'] : array(); // Check if our current filename matches the files switch ($this->language_directory) { case 'email': if (!in_array($this->language_file, $email_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; case 'acp': if (!in_array($this->language_file, $acp_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; case 'mods': if (!in_array($this->language_file, $mods_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } break; default: if (!in_array($this->language_file, $this->main_files)) { trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&action=details&id=' . $lang_id), E_USER_WARNING); } } if (isset($_POST['remove_store'])) { $store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true); if (file_exists($phpbb_root_path . $store_filename)) { @unlink($phpbb_root_path . $store_filename); } } include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx; $methods = transfer::methods(); foreach ($methods as $method) { $template->assign_block_vars('buttons', array('VALUE' => $method)); } $template->assign_vars(array('S_DETAILS' => true, 'U_ACTION' => $this->u_action . "&action=details&id={$lang_id}", 'U_BACK' => $this->u_action, 'LANG_LOCAL_NAME' => $lang_entries['lang_local_name'], 'LANG_ENGLISH_NAME' => $lang_entries['lang_english_name'], 'LANG_ISO' => $lang_entries['lang_iso'], 'LANG_AUTHOR' => $lang_entries['lang_author'], 'ALLOW_UPLOAD' => sizeof($methods))); // If current lang is different from the default lang, then first try to grab missing/additional vars if ($lang_iso != $config['default_lang']) { $is_missing_var = false; foreach ($this->main_files as $file) { if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file))) { $missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file); if (sizeof($missing_vars[$file])) { $is_missing_var = true; } } else { $missing_files[] = $this->get_filename($lang_iso, '', $file); } } // Now go through acp/mods directories foreach ($acp_files as $file) { if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file))) { $missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file); if (sizeof($missing_vars['acp/' . $file])) { $is_missing_var = true; } } else { $missing_files[] = $this->get_filename($lang_iso, 'acp', $file); } } if (sizeof($mods_files)) { foreach ($mods_files as $file) { if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file))) { $missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file); if (sizeof($missing_vars['mods/' . $file])) { $is_missing_var = true; } } else { $missing_files[] = $this->get_filename($lang_iso, 'mods', $file); } } } // More missing files... for example email templates? foreach ($email_files as $file) { if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file))) { $missing_files[] = $this->get_filename($lang_iso, 'email', $file); } } if (sizeof($missing_files)) { $template->assign_vars(array('S_MISSING_FILES' => true, 'L_MISSING_FILES' => sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']), 'MISSING_FILES' => implode('<br />', $missing_files))); } if ($is_missing_var) { $template->assign_vars(array('S_MISSING_VARS' => true, 'L_MISSING_VARS_EXPLAIN' => sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']), 'U_MISSING_ACTION' => $this->u_action . "&action={$action}&id={$lang_id}")); foreach ($missing_vars as $file => $vars) { if (!sizeof($vars)) { continue; } $template->assign_block_vars('missing', array('FILE' => $file, 'TPL' => $this->print_language_entries($vars, '', false), 'KEY' => strpos($file, '/') === false ? '|' . $file : str_replace('/', '|', $file))); } } } // Main language files $s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>'; foreach ($this->main_files as $file) { if (strpos($file, 'help_') === 0) { continue; } $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true)) ? '* ' : ''; $selected = !$this->language_directory && $this->language_file == $file ? ' selected="selected"' : ''; $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>'; } // Help Files $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>'; foreach ($this->main_files as $file) { if (strpos($file, 'help_') !== 0) { continue; } $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true)) ? '* ' : ''; $selected = !$this->language_directory && $this->language_file == $file ? ' selected="selected"' : ''; $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>'; } // Now every other language directory $check_files = array('email', 'acp', 'mods'); foreach ($check_files as $check) { if (!sizeof(${$check . '_files'})) { continue; } $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>'; foreach (${$check . '_files'} as $file) { $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true)) ? '* ' : ''; $selected = $this->language_directory == $check && $this->language_file == $file ? ' selected="selected"' : ''; $s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>'; } } // Get Language Entries - if saved within store folder, we take this one (with the option to remove it) $lang = array(); $is_email_file = $this->language_directory == 'email' ? true : false; $is_help_file = strpos($this->language_file, 'help_') === 0 ? true : false; $file_from_store = file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true)) ? true : false; $no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file); if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename)) { $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename); } else { if ($is_email_file) { $lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store)); } else { $help = array(); include $phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store); if ($is_help_file) { $lang = $help; unset($help); } } $print_message = ($this->language_directory ? $this->language_directory . '/' : '') . $this->language_file; } // Normal language pack entries $template->assign_vars(array('U_ENTRY_ACTION' => $this->u_action . "&action=details&id={$lang_id}#entries", 'S_EMAIL_FILE' => $is_email_file, 'S_FROM_STORE' => $file_from_store, 'S_LANG_OPTIONS' => $s_lang_options, 'PRINT_MESSAGE' => $print_message)); if (!$is_email_file) { $tpl = ''; $name = ($this->language_directory ? $this->language_directory . '/' : '') . $this->language_file; if (isset($missing_vars[$name]) && sizeof($missing_vars[$name])) { $tpl .= $this->print_language_entries($missing_vars[$name], '* '); } $tpl .= $this->print_language_entries($lang); $template->assign_var('TPL', $tpl); unset($tpl); } else { $template->assign_vars(array('LANG' => $lang)); unset($lang); } return; break; case 'delete': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row['lang_iso'] == $config['default_lang']) { trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING); } if (confirm_box(true)) { $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id); $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_lang = '" . $db->sql_escape($config['default_lang']) . "'\n\t\t\t\t\t\tWHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'"; $db->sql_query($sql); // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we? $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $db->sql_query($sql); $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $db->sql_query($sql); $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'"; $result = $db->sql_query($sql); $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']); trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action)); } else { $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'action' => $action, 'id' => $lang_id); confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); } break; case 'install': $lang_iso = request_var('iso', ''); $lang_iso = basename($lang_iso); if (!$lang_iso || !file_exists("{$phpbb_root_path}language/{$lang_iso}/iso.txt")) { trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING); } $file = file("{$phpbb_root_path}language/{$lang_iso}/iso.txt"); $lang_pack = array('iso' => $lang_iso, 'name' => trim(htmlspecialchars($file[0])), 'local_name' => trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')), 'author' => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))); unset($file); $sql = 'SELECT lang_iso FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$lang_pack['name'] || !$lang_pack['local_name']) { trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING); } // Add language pack $sql_ary = array('lang_iso' => $lang_pack['iso'], 'lang_dir' => $lang_pack['iso'], 'lang_english_name' => $lang_pack['name'], 'lang_local_name' => $lang_pack['local_name'], 'lang_author' => $lang_pack['author']); $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $lang_id = $db->sql_nextid(); $valid_localized = array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply'); $sql_ary = array(); $sql = 'SELECT * FROM ' . STYLES_IMAGESET_TABLE; $result = $db->sql_query($sql); while ($imageset_row = $db->sql_fetchrow($result)) { if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg")) { $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg"); foreach ($cfg_data_imageset_data as $image_name => $value) { if (strpos($value, '*') !== false) { if (substr($value, -1, 1) === '*') { list($image_filename, $image_height) = explode('*', $value); $image_width = 0; } else { list($image_filename, $image_height, $image_width) = explode('*', $value); } } else { $image_filename = $value; $image_height = $image_width = 0; } if (strpos($image_name, 'img_') === 0 && $image_filename) { $image_name = substr($image_name, 4); if (in_array($image_name, $valid_localized)) { $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $imageset_row['imageset_id'], 'image_lang' => (string) $lang_pack['iso']); } } } } } $db->sql_freeresult($result); if (sizeof($sql_ary)) { $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); } // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier. $sql = 'SELECT lang_id FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; $result = $db->sql_query($sql); $default_lang_id = (int) $db->sql_fetchfield('lang_id'); $db->sql_freeresult($result); // From the mysql documentation: // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. // Due to this we stay on the safe side if we do the insertion "the manual way" $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $default_lang_id; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $row['lang_id'] = $lang_id; $db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row)); } $db->sql_freeresult($result); $sql = 'SELECT field_id, option_id, field_type, lang_value FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $default_lang_id; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $row['lang_id'] = $lang_id; $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row)); } $db->sql_freeresult($result); add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']); trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']) . adm_back_link($this->u_action)); break; case 'download': if (!$lang_id) { trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT * FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $use_method = request_var('use_method', ''); $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } // Let the user decide in which format he wants to have the pack if (!$use_method) { $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; $radio_buttons = ''; foreach ($methods as $method) { $radio_buttons .= '<label><input type="radio"' . (!$radio_buttons ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; } $template->assign_vars(array('S_SELECT_METHOD' => true, 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . "&action={$action}&id={$lang_id}", 'RADIO_BUTTONS' => $radio_buttons)); return; } if (!in_array($use_method, $methods)) { $use_method = '.tar'; } include_once $phpbb_root_path . 'includes/functions_compress.' . $phpEx; if ($use_method == '.zip') { $compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method); } else { $compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method); } // Get email templates $email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt'); $email_templates = $email_templates['email/']; // Get acp files $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx); $acp_files = $acp_files['acp/']; // Get mod files $mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx); $mod_files = isset($mod_files['mods/']) ? $mod_files['mods/'] : array(); // Add main files $this->add_to_archive($compress, $this->main_files, $row['lang_iso']); // Add search files if they exist... if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx)) { $this->add_to_archive($compress, array("search_ignore_words.{$phpEx}"), $row['lang_iso']); } if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx)) { $this->add_to_archive($compress, array("search_synonyms.{$phpEx}"), $row['lang_iso']); } // Write files in folders $this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email'); $this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp'); $this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods'); // Write ISO File $iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n"; $iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n"; $iso_src .= htmlspecialchars_decode($row['lang_author']); $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt'); // index.html files $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html'); $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html'); $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html'); if (sizeof($mod_files)) { $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html'); } $compress->close(); $compress->download('lang_' . $row['lang_iso']); @unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method); exit; break; } $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count FROM ' . USERS_TABLE . ' GROUP BY user_lang'; $result = $db->sql_query($sql); $lang_count = array(); while ($row = $db->sql_fetchrow($result)) { $lang_count[$row['user_lang']] = $row['lang_count']; } $db->sql_freeresult($result); $sql = 'SELECT * FROM ' . LANG_TABLE . ' ORDER BY lang_english_name'; $result = $db->sql_query($sql); $installed = array(); while ($row = $db->sql_fetchrow($result)) { $installed[] = $row['lang_iso']; $tagstyle = $row['lang_iso'] == $config['default_lang'] ? '*' : ''; $template->assign_block_vars('lang', array('U_DETAILS' => $this->u_action . "&action=details&id={$row['lang_id']}", 'U_DOWNLOAD' => $this->u_action . "&action=download&id={$row['lang_id']}", 'U_DELETE' => $this->u_action . "&action=delete&id={$row['lang_id']}", 'ENGLISH_NAME' => $row['lang_english_name'], 'TAG' => $tagstyle, 'LOCAL_NAME' => $row['lang_local_name'], 'ISO' => $row['lang_iso'], 'USED_BY' => isset($lang_count[$row['lang_iso']]) ? $lang_count[$row['lang_iso']] : 0)); } $db->sql_freeresult($result); $new_ary = $iso = array(); $dp = @opendir("{$phpbb_root_path}language"); if ($dp) { while (($file = readdir($dp)) !== false) { if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/{$file}/iso.txt")) { if (!in_array($file, $installed)) { if ($iso = file("{$phpbb_root_path}language/{$file}/iso.txt")) { if (sizeof($iso) == 3) { $new_ary[$file] = array('iso' => $file, 'name' => trim($iso[0]), 'local_name' => trim($iso[1]), 'author' => trim($iso[2])); } } } } } closedir($dp); } unset($installed); if (sizeof($new_ary)) { foreach ($new_ary as $iso => $lang_ary) { $template->assign_block_vars('notinst', array('ISO' => htmlspecialchars($lang_ary['iso']), 'LOCAL_NAME' => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'), 'NAME' => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'), 'U_INSTALL' => $this->u_action . '&action=install&iso=' . urlencode($lang_ary['iso']))); } } unset($new_ary); }