diff options
author | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-08-12 01:47:32 +0000 |
---|---|---|
committer | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-08-12 01:47:32 +0000 |
commit | ec4e122032b9535c3355cc398ee424d16f5603aa (patch) | |
tree | 8a4875f346d5a4de4daf30a4838668cd9ff11493 /phpBB/adm/admin_styles.php | |
parent | a4ac56c7985d0091215d2488233ec20cc6bb20a8 (diff) | |
download | forums-ec4e122032b9535c3355cc398ee424d16f5603aa.tar forums-ec4e122032b9535c3355cc398ee424d16f5603aa.tar.gz forums-ec4e122032b9535c3355cc398ee424d16f5603aa.tar.bz2 forums-ec4e122032b9535c3355cc398ee424d16f5603aa.tar.xz forums-ec4e122032b9535c3355cc398ee424d16f5603aa.zip |
Temp workaround for lack of style create/import/upload prob, fix improper setting of element ids when editing style
git-svn-id: file:///svn/phpbb/trunk@4382 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/adm/admin_styles.php')
-rw-r--r-- | phpBB/adm/admin_styles.php | 186 |
1 files changed, 137 insertions, 49 deletions
diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index 05832204ca..d91dc0ef03 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -2508,14 +2508,15 @@ function install($type, $action, $id) if (($action == 'install' && $install_path) || (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file']))) { $root_path = ($action == 'install') ? "{$phpbb_root_path}styles/$install_path/" : "$tmp_path"; + $cfg_path = ($type == 'style') ? "$root_path$type.cfg" : "$root_path$type/$type.cfg"; - if (!($fp = @fopen("$root_path$type/$type.cfg", 'rb'))) + if (!($fp = @fopen($cfg_path, 'rb'))) { $error[] = $user->lang[$l_type . '_ERR_NOT_' . $l_type]; } else { - $installcfg = explode("\n", fread($fp, filesize("$root_path$type/$type.cfg"))); + $installcfg = explode("\n", fread($fp, filesize($cfg_path))); } fclose($fp); } @@ -2575,7 +2576,7 @@ function install($type, $action, $id) switch ($type) { case 'style': - $sql_select = 'style_name, template_id, theme_id, imageset_id'; + $sql_select = ($action != 'details') ? 'style_name, template_id, theme_id, imageset_id' : 'style_name'; break; case 'template': $sql_select = 'template_id, template_name, template_path, template_storedb'; @@ -2584,7 +2585,7 @@ function install($type, $action, $id) $sql_select = 'theme_id, theme_name, theme_path, theme_data, theme_storedb'; break; case 'imageset': - $sql_select = 'imageset_name, imageset_path, imageset_id'; + $sql_select = 'imageset_id, imageset_name, imageset_path'; break; } @@ -2655,7 +2656,7 @@ function install($type, $action, $id) // and do the install if necessary if (!${$element . '_id'}) { - $error += install_element($element, $action, $root_path, ${$element . '_id'}, $name, $copyright); + $error = install_element($element, $action, $root_path, ${$element . '_id'}, $name, $copyright); } } @@ -2730,68 +2731,155 @@ function install($type, $action, $id) } else if ($action == 'add') { - // Create path if it doesn't exist - if ($type != 'style') + if ($type == 'style') { - $storedb = 1; + if (empty($style_name)) + { + $error[] = $user->lang['STYLE_ERR_STYLE_NAME']; + } - umask(0); - if (file_exists("{$phpbb_root_path}styles/$path") || @mkdir("{$phpbb_root_path}styles/$path", 0777)) + if (strlen($style_name) > 30) { - if (@chmod("{$phpbb_root_path}styles/$path", 0777)) + $error[] = $user->lang['STYLE_ERR_NAME_LONG']; + } + + if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $style_name)) + { + $error[] = $user->lang['STYLE_ERR_NAME_CHARS']; + } + + if (strlen($style_copyright) > 60) + { + $error[] = $user->lang['STYLE_ERR_COPY_LONG']; + } + + $sql = 'SELECT style_name + FROM ' . STYLES_TABLE . " + WHERE style_name = '" . $db->sql_escape($style_name) . "'"; + $result = $db->sql_query($sql); + + if (extract($db->sql_fetchrow($result))) + { + $error[] = $user->lang['STYLE_ERR_NAME_EXIST']; + } + $db->sql_freeresult($result); + + foreach ($element_ary as $element => $table) + { + // Zero id value ... need to install element ... run usual checks + // and do the install if necessary + if (!${$element . '_id'}) { - $storedb = 0; + $error = install_element($element, $action, $root_path, ${$element . '_id'}, $name, $copyright); } } - } - if ($basis && ($template_storedb || $theme_storedb)) - { - $tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; - if (!@mkdir($tmp_path, 0777)) + if (!$template_id || !$theme_id || !$imageset_id) { - trigger_error("Cannot create $tmp_path", E_USER_ERROR); + $error[] = $user->lang['STYLE_ERR_NO_IDS']; } - @chmod($tmp_path, 0777); - if (!@mkdir("$tmp_path$type", 0777)) + if (!sizeof($error)) { - trigger_error("Cannot create $tmp_path$type", E_USER_ERROR); + $db->sql_transaction('begin'); + + $sql_ary += array( + $type . '_name' => $name, + $type . '_copyright' => $copyright, + ); + if ($type == 'style') + { + $sql_ary += array( + 'style_active' => $style_active, + 'template_id' => $template_id, + 'theme_id' => $theme_id, + 'imageset_id' => $imageset_id, + ); + } + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' + ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + $id = $db->sql_nextid(); + + if ($type == 'style' && $style_default) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_style = $id + WHERE user_style = " . $config['default_style']; + $db->sql_query($sql); + + set_config('default_style', $id); + } + + $db->sql_transaction('commit'); + + add_log('admin', 'LOG_ADD_STYLE', $style_name); } - @chmod("$tmp_path$type", 0777); + } + else + { + // Create path if it doesn't exist + $storedb = 1; - switch ($type) + umask(0); + if (file_exists("{$phpbb_root_path}styles/$path") || @mkdir("{$phpbb_root_path}styles/$path", 0777)) { - case 'theme': - copyfiles("{$phpbb_root_path}styles/$path/theme/", filelist("{$phpbb_root_path}styles/$path/theme/", '', '*'), "$tmp_path$type/"); + if (@chmod("{$phpbb_root_path}styles/$path", 0777)) + { + $storedb = 0; + } + } - $fp = fopen("$tmp_path$type/stylesheet.css", 'wb'); - fwrite($fp, $theme_data); - fclose($theme_data); - break; + if ($basis && ($template_storedb || $theme_storedb)) + { + $tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; + if (!@mkdir($tmp_path, 0777)) + { + trigger_error("Cannot create $tmp_path", E_USER_ERROR); + } + @chmod($tmp_path, 0777); - case 'template': - copyfiles("{$phpbb_root_path}styles/$path/$type/", filelist("{$phpbb_root_path}styles/$path/$type/", '', '*'), "$tmp_path$type/"); - - $sql = 'SELECT template_filename, template_mtime, template_data - FROM ' . STYLES_TPLDATA_TABLE . " - WHERE template_id = $basis"; - $result = $db->sql_fetchrow($result); + if (!@mkdir("$tmp_path$type", 0777)) + { + trigger_error("Cannot create $tmp_path$type", E_USER_ERROR); + } + @chmod("$tmp_path$type", 0777); - while ($row = $db->sql_fetchrow($result)) - { - $fp = fopen("$tmp_path$type/" . $row['template_filename'], 'wb'); - fwrite($fp, $row['template_data']); - fclose($fp); - } - $db->sql_freeresult($result); - break; + switch ($type) + { + case 'theme': + copyfiles("{$phpbb_root_path}styles/$path/theme/", filelist("{$phpbb_root_path}styles/$path/theme/", '', '*'), "$tmp_path$type/"); + + $fp = fopen("$tmp_path$type/stylesheet.css", 'wb'); + fwrite($fp, $theme_data); + fclose($theme_data); + break; + + case 'template': + copyfiles("{$phpbb_root_path}styles/$path/$type/", filelist("{$phpbb_root_path}styles/$path/$type/", '', '*'), "$tmp_path$type/"); + + $sql = 'SELECT template_filename, template_mtime, template_data + FROM ' . STYLES_TPLDATA_TABLE . " + WHERE template_id = $basis"; + $result = $db->sql_fetchrow($result); + + while ($row = $db->sql_fetchrow($result)) + { + $fp = fopen("$tmp_path$type/" . $row['template_filename'], 'wb'); + fwrite($fp, $row['template_data']); + fclose($fp); + } + $db->sql_freeresult($result); + break; + } } - } - $root_path = ($tmp_path) ? $tmp_path : (($basis) ? $phpbb_root_path . 'styles/' . ${$type . '_path'} . '/' : ''); + $root_path = ($tmp_path) ? $tmp_path : (($basis) ? $phpbb_root_path . 'styles/' . ${$type . '_path'} . '/' : ''); - $error = install_element($type, $action, $root_path, $id, $name, $copyright, $storedb); + $error = install_element($type, $action, $root_path, $id, $name, $copyright, $storedb); + } if ($tmp_path) { @@ -2885,7 +2973,7 @@ function install($type, $action, $id) if ($type != 'imageset' && sizeof($sql_ary)) { - $sql = "UPDATE $sql_from + echo $sql = "UPDATE $sql_from SET " . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE {$type}_id = $id"; $db->sql_query($sql); @@ -2904,7 +2992,7 @@ function install($type, $action, $id) // Something went wrong ... so we'll clean up any decompressed uploaded/imported archives. if ($tmp_path) { -// cleanup_folder($tmp_path); + cleanup_folder($tmp_path); } // Either an error occured or the user has just entered the form |