|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
* @version $Id: acp_styles.php 9152 2008-12-02 16:49:59Z acydburn $
|
|
|
4c79b5 |
* @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
if (!defined('IN_PHPBB'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @package acp
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
class acp_styles
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
var $u_action;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
var $style_cfg;
|
|
|
4c79b5 |
var $template_cfg;
|
|
|
4c79b5 |
var $theme_cfg;
|
|
|
4c79b5 |
var $imageset_cfg;
|
|
|
4c79b5 |
var $imageset_keys;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function main($id, $mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $auth, $template, $cache;
|
|
|
4c79b5 |
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Hardcoded template bitfield to add for new templates
|
|
|
4c79b5 |
$bitfield = new bitfield();
|
|
|
4c79b5 |
$bitfield->set(0);
|
|
|
4c79b5 |
$bitfield->set(3);
|
|
|
4c79b5 |
$bitfield->set(8);
|
|
|
4c79b5 |
$bitfield->set(9);
|
|
|
4c79b5 |
$bitfield->set(11);
|
|
|
4c79b5 |
$bitfield->set(12);
|
|
|
4c79b5 |
define('TEMPLATE_BITFIELD', $bitfield->get_base64());
|
|
|
4c79b5 |
unset($bitfield);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user->add_lang('acp/styles');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->tpl_name = 'acp_styles';
|
|
|
4c79b5 |
$this->page_title = 'ACP_CAT_STYLES';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$action = request_var('action', '');
|
|
|
4c79b5 |
$action = (isset($_POST['add'])) ? 'add' : $action;
|
|
|
4c79b5 |
$style_id = request_var('id', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Fill the configuration variables
|
|
|
4c79b5 |
$this->style_cfg = $this->template_cfg = $this->theme_cfg = $this->imageset_cfg = '
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# phpBB {MODE} configuration file
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# @package phpBB3
|
|
|
4c79b5 |
# @copyright (c) 2005 phpBB Group
|
|
|
4c79b5 |
# @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# At the left is the name, please do not change this
|
|
|
4c79b5 |
# At the right the value is entered
|
|
|
4c79b5 |
# For on/off options the valid values are on, off, 1, 0, true and false
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# Values get trimmed, if you want to add a space in front or at the end of
|
|
|
4c79b5 |
# the value, then enclose the value with single or double quotes.
|
|
|
4c79b5 |
# Single and double quotes do not need to be escaped.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# General Information about this {MODE}
|
|
|
4c79b5 |
name = {NAME}
|
|
|
4c79b5 |
copyright = {COPYRIGHT}
|
|
|
4c79b5 |
version = {VERSION}
|
|
|
4c79b5 |
';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->theme_cfg .= '
|
|
|
4c79b5 |
# Some configuration options
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# You have to turn this option on if you want to use the
|
|
|
4c79b5 |
# path template variables ({T_IMAGESET_PATH} for example) within
|
|
|
4c79b5 |
# your css file.
|
|
|
4c79b5 |
# This is mostly the case if you want to use language specific
|
|
|
4c79b5 |
# images within your css file.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
parse_css_file = {PARSE_CSS_FILE}
|
|
|
4c79b5 |
';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->template_cfg .= '
|
|
|
4c79b5 |
# Some configuration options
|
|
|
4c79b5 |
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# You can use this function to inherit templates from another template.
|
|
|
4c79b5 |
# The template of the given name has to be installed.
|
|
|
4c79b5 |
# Templates cannot inherit from inheriting templates.
|
|
|
4c79b5 |
#';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->imageset_keys = array(
|
|
|
4c79b5 |
'logos' => array(
|
|
|
4c79b5 |
'site_logo',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'buttons' => array(
|
|
|
4c79b5 |
'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',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'icons' => array(
|
|
|
4c79b5 |
'icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'forums' => array(
|
|
|
4c79b5 |
'forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread'
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'folders' => array(
|
|
|
4c79b5 |
'topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'polls' => array(
|
|
|
4c79b5 |
'poll_left', 'poll_center', 'poll_right',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'ui' => array(
|
|
|
4c79b5 |
'upload_bar',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'user' => array(
|
|
|
4c79b5 |
'user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Execute overall actions
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'delete':
|
|
|
4c79b5 |
if ($style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->remove($mode, $style_id);
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'export':
|
|
|
4c79b5 |
if ($style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->export($mode, $style_id);
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'install':
|
|
|
4c79b5 |
$this->install($mode);
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'add':
|
|
|
4c79b5 |
$this->add($mode);
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'details':
|
|
|
4c79b5 |
if ($style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->details($mode, $style_id);
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'edit':
|
|
|
4c79b5 |
if ($style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
return $this->edit_imageset($style_id);
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
return $this->edit_template($style_id);
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
return $this->edit_theme($style_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'cache':
|
|
|
4c79b5 |
if ($style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
return $this->template_cache($style_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'activate':
|
|
|
4c79b5 |
case 'deactivate':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($style_id == $config['default_style'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_TABLE . '
|
|
|
4c79b5 |
SET style_active = ' . (($action == 'activate') ? 1 : 0) . '
|
|
|
4c79b5 |
WHERE style_id = ' . $style_id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set style to default for any member using deactivated style
|
|
|
4c79b5 |
if ($action == 'deactivate')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
|
4c79b5 |
SET user_style = ' . $config['default_style'] . "
|
|
|
4c79b5 |
WHERE user_style = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
|
|
4c79b5 |
SET forum_style = 0
|
|
|
4c79b5 |
WHERE forum_style = ' . $style_id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->frontend('style', array('details'), array('export', 'delete'));
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Refresh template data stored in db and clear cache
|
|
|
4c79b5 |
case 'refresh':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$template_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$template_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (confirm_box(true))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template_refreshed = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Only refresh database if the template is stored in the database
|
|
|
4c79b5 |
if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist = array('' => array());
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT template_filename, template_mtime
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime'])
|
|
|
4c79b5 |
// {
|
|
|
4c79b5 |
// get folder info from the filename
|
|
|
4c79b5 |
if (($slash_pos = strrpos($row['template_filename'], '/')) === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist[''][] = $row['template_filename'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// }
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->store_templates('update', $style_id, $template_row['template_path'], $filelist);
|
|
|
4c79b5 |
unset($filelist);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template_refreshed = $user->lang['TEMPLATE_REFRESHED'] . ' ';
|
|
|
4c79b5 |
add_log('admin', 'LOG_TEMPLATE_REFRESHED', $template_row['template_name']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->clear_template_cache($template_row);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error($template_refreshed . $user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
confirm_box(false, ($template_row['template_storedb']) ? $user->lang['CONFIRM_TEMPLATE_REFRESH'] : $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array(
|
|
|
4c79b5 |
'i' => $id,
|
|
|
4c79b5 |
'mode' => $mode,
|
|
|
4c79b5 |
'action' => $action,
|
|
|
4c79b5 |
'id' => $style_id
|
|
|
4c79b5 |
)));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->frontend('template', array('edit', 'cache', 'details'), array('refresh', 'export', 'delete'));
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Refresh theme data stored in the database
|
|
|
4c79b5 |
case 'refresh':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_THEME_TABLE . "
|
|
|
4c79b5 |
WHERE theme_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$theme_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$theme_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$theme_row['theme_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['THEME_ERR_REFRESH_FS'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (confirm_box(true))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Save CSS contents
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"),
|
|
|
4c79b5 |
'theme_data' => $this->db_theme_data($theme_row)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
|
|
|
4c79b5 |
WHERE theme_id = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_THEME_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_THEME_REFRESHED', $theme_row['theme_name']);
|
|
|
4c79b5 |
trigger_error($user->lang['THEME_REFRESHED'] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
confirm_box(false, $user->lang['CONFIRM_THEME_REFRESH'], build_hidden_fields(array(
|
|
|
4c79b5 |
'i' => $id,
|
|
|
4c79b5 |
'mode' => $mode,
|
|
|
4c79b5 |
'action' => $action,
|
|
|
4c79b5 |
'id' => $style_id
|
|
|
4c79b5 |
)));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->frontend('theme', array('edit', 'details'), array('refresh', 'export', 'delete'));
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($action)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'refresh':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_TABLE . "
|
|
|
4c79b5 |
WHERE imageset_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$imageset_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$imageset_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (confirm_box(true))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imageset_definitions = array();
|
|
|
4c79b5 |
foreach ($this->imageset_keys as $topic => $key_array)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_definitions = array_merge($imageset_definitions, $key_array);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
|
|
|
4c79b5 |
WHERE imageset_id = ' . $style_id;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($cfg_data_imageset as $image_name => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strpos($value, '*') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (substr($value, -1, 1) === '*')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height) = explode('*', $value);
|
|
|
4c79b5 |
$image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height, $image_width) = explode('*', $value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_filename = $value;
|
|
|
4c79b5 |
$image_height = $image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strpos($image_name, 'img_') === 0 && $image_filename)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_name = substr($image_name, 4);
|
|
|
4c79b5 |
if (in_array($image_name, $imageset_definitions))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary[] = array(
|
|
|
4c79b5 |
'image_name' => (string) $image_name,
|
|
|
4c79b5 |
'image_filename' => (string) $image_filename,
|
|
|
4c79b5 |
'image_height' => (int) $image_height,
|
|
|
4c79b5 |
'image_width' => (int) $image_width,
|
|
|
4c79b5 |
'imageset_id' => (int) $style_id,
|
|
|
4c79b5 |
'image_lang' => '',
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT lang_dir
|
|
|
4c79b5 |
FROM ' . LANG_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg");
|
|
|
4c79b5 |
foreach ($cfg_data_imageset_data as $image_name => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strpos($value, '*') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (substr($value, -1, 1) === '*')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height) = explode('*', $value);
|
|
|
4c79b5 |
$image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height, $image_width) = explode('*', $value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_filename = $value;
|
|
|
4c79b5 |
$image_height = $image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strpos($image_name, 'img_') === 0 && $image_filename)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_name = substr($image_name, 4);
|
|
|
4c79b5 |
if (in_array($image_name, $imageset_definitions))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary[] = array(
|
|
|
4c79b5 |
'image_name' => (string) $image_name,
|
|
|
4c79b5 |
'image_filename' => (string) $image_filename,
|
|
|
4c79b5 |
'image_height' => (int) $image_height,
|
|
|
4c79b5 |
'image_width' => (int) $image_width,
|
|
|
4c79b5 |
'imageset_id' => (int) $style_id,
|
|
|
4c79b5 |
'image_lang' => (string) $row['lang_dir'],
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']);
|
|
|
4c79b5 |
trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
confirm_box(false, $user->lang['CONFIRM_IMAGESET_REFRESH'], build_hidden_fields(array(
|
|
|
4c79b5 |
'i' => $id,
|
|
|
4c79b5 |
'mode' => $mode,
|
|
|
4c79b5 |
'action' => $action,
|
|
|
4c79b5 |
'id' => $style_id
|
|
|
4c79b5 |
)));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->frontend('imageset', array('edit', 'details'), array('refresh', 'export', 'delete'));
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Build Frontend with supplied options
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function frontend($mode, $options, $actions)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $user, $template, $db, $config, $phpbb_root_path, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_from = '';
|
|
|
4c79b5 |
$style_count = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
$sql_from = STYLES_TABLE;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT user_style, COUNT(user_style) AS style_count
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
GROUP BY user_style';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_count[$row['user_style']] = $row['style_count'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_prefix = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'ACP_' . $l_prefix . 'S';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_FRONTEND' => true,
|
|
|
4c79b5 |
'S_STYLE' => ($mode == 'style') ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_NAME' => $user->lang[$l_prefix . '_NAME'],
|
|
|
4c79b5 |
'L_INSTALLED' => $user->lang['INSTALLED_' . $l_prefix],
|
|
|
4c79b5 |
'L_UNINSTALLED' => $user->lang['UNINSTALLED_' . $l_prefix],
|
|
|
4c79b5 |
'L_NO_UNINSTALLED' => $user->lang['NO_UNINSTALLED_' . $l_prefix],
|
|
|
4c79b5 |
'L_CREATE' => $user->lang['CREATE_' . $l_prefix],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action,
|
|
|
4c79b5 |
)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT *
|
|
|
4c79b5 |
FROM $sql_from";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$installed = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$basis_options = '<option class="sep" value="">' . $user->lang['OPTIONAL_BASIS'] . '</option>';
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$installed[] = $row[$mode . '_name'];
|
|
|
4c79b5 |
$basis_options .= '<option value="' . $row[$mode . '_id'] . '">' . $row[$mode . '_name'] . '</option>';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$stylevis = ($mode == 'style' && !$row['style_active']) ? 'activate' : 'deactivate';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$s_options = array();
|
|
|
4c79b5 |
foreach ($options as $option)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$s_options[] = '' . $user->lang[strtoupper($option)] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$s_actions = array();
|
|
|
4c79b5 |
foreach ($actions as $option)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$s_actions[] = '' . $user->lang[strtoupper($option)] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_block_vars('installed', array(
|
|
|
4c79b5 |
'S_DEFAULT_STYLE' => ($mode == 'style' && $row['style_id'] == $config['default_style']) ? true : false,
|
|
|
4c79b5 |
'U_EDIT' => $this->u_action . '&action=' . (($mode == 'style') ? 'details' : 'edit') . '&id=' . $row[$mode . '_id'],
|
|
|
4c79b5 |
'U_STYLE_ACT_DEACT' => $this->u_action . '&action=' . $stylevis . '&id=' . $row[$mode . '_id'],
|
|
|
4c79b5 |
'L_STYLE_ACT_DEACT' => $user->lang['STYLE_' . strtoupper($stylevis)],
|
|
|
4c79b5 |
'S_OPTIONS' => implode(' | ', $s_options),
|
|
|
4c79b5 |
'S_ACTIONS' => implode(' | ', $s_actions),
|
|
|
4c79b5 |
'U_PREVIEW' => ($mode == 'style') ? append_sid("{$phpbb_root_path}index.$phpEx", "$mode=" . $row[$mode . '_id']) : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'NAME' => $row[$mode . '_name'],
|
|
|
4c79b5 |
'STYLE_COUNT' => ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0,
|
|
|
4c79b5 |
)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Grab uninstalled items
|
|
|
4c79b5 |
$new_ary = $cfg = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$dp = @opendir("{$phpbb_root_path}styles");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($dp)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
while (($file = readdir($dp)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$subpath = ($mode != 'style') ? "$mode/" : '';
|
|
|
4c79b5 |
if ($file[0] != '.' && file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$items = parse_cfg_file('', $cfg);
|
|
|
4c79b5 |
$name = (isset($items['name'])) ? trim($items['name']) : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($name && !in_array($name, $installed))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$new_ary[] = array(
|
|
|
4c79b5 |
'path' => $file,
|
|
|
4c79b5 |
'name' => $name,
|
|
|
4c79b5 |
'copyright' => $items['copyright'],
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dp);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($installed);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($new_ary))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($new_ary as $cfg)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('uninstalled', array(
|
|
|
4c79b5 |
'NAME' => $cfg['name'],
|
|
|
4c79b5 |
'COPYRIGHT' => $cfg['copyright'],
|
|
|
4c79b5 |
'U_INSTALL' => $this->u_action . '&action=install&path=' . urlencode($cfg['path']))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($new_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_BASIS_OPTIONS' => $basis_options)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Provides a template editor which allows saving changes to template files on the filesystem or in the database.
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param int $template_id specifies which template set is being edited
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function edit_template($template_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (defined('PHPBB_DISABLE_ACP_EDITOR'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['EDITOR_DISABLED'] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'EDIT_TEMPLATE';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filelist = $filelist_cats = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template_data = utf8_normalize_nfc(request_var('template_data', '', true));
|
|
|
4c79b5 |
$template_data = htmlspecialchars_decode($template_data);
|
|
|
4c79b5 |
$template_file = utf8_normalize_nfc(request_var('template_file', '', true));
|
|
|
4c79b5 |
$text_rows = max(5, min(999, request_var('text_rows', 20)));
|
|
|
4c79b5 |
$save_changes = (isset($_POST['save'])) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// make sure template_file path doesn't go upwards
|
|
|
4c79b5 |
$template_file = str_replace('..', '.', $template_file);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Retrieve some information about the template
|
|
|
4c79b5 |
$sql = 'SELECT template_storedb, template_path, template_name
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $template_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$template_info = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$template_info)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($save_changes && !check_form_key('acp_styles'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (!$save_changes)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
add_form_key('acp_styles');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// save changes to the template if the user submitted any
|
|
|
4c79b5 |
if ($save_changes && $template_file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Get the filesystem location of the current file
|
|
|
4c79b5 |
$file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file";
|
|
|
4c79b5 |
$additional = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the template is stored on the filesystem try to write the file else store it in the database
|
|
|
4c79b5 |
if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && @is_writable($file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!($fp = @fopen($file, 'wb')))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
fwrite($fp, $template_data);
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If it's not stored in the db yet, then update the template setting and store all template files in the db
|
|
|
4c79b5 |
if (!$template_info['template_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($this->get_super('template', $template_id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->store_in_db('template', $super['template_id']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->store_in_db('template', $template_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_TEMPLATE_EDIT_DETAILS', $template_info['template_name']);
|
|
|
4c79b5 |
$additional .= ' ' . $user->lang['EDIT_TEMPLATE_STORED_DB'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Update the template_data table entry for this template file
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
SET template_data = '" . $db->sql_escape($template_data) . "', template_mtime = " . time() . "
|
|
|
4c79b5 |
WHERE template_id = $template_id
|
|
|
4c79b5 |
AND template_filename = '" . $db->sql_escape($template_file) . "'";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// destroy the cached version of the template (filename without extension)
|
|
|
4c79b5 |
$this->clear_template_cache($template_info, array(substr($template_file, 0, -5)));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file);
|
|
|
4c79b5 |
trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . $additional . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file"));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate a category array containing template filenames
|
|
|
4c79b5 |
if (!$template_info['template_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filelist = filelist($template_path, '', 'html');
|
|
|
4c79b5 |
$filelist[''] = array_diff($filelist[''], array('bbcode.html'));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($template_file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file")))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $template_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filelist = array('' => array());
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file_info = pathinfo($row['template_filename']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (($file_info['basename'] != 'bbcode') && ($file_info['extension'] == 'html'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (($file_info['dirname'] == '.') || empty($file_info['dirname']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist[''][] = $row['template_filename'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist[$file_info['dirname'] . '/'][] = $file_info['basename'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['template_filename'] == $template_file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template_data = $row['template_data'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
unset($file_info);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now create the categories
|
|
|
4c79b5 |
$filelist_cats[''] = array();
|
|
|
4c79b5 |
foreach ($filelist as $pathfile => $file_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Use the directory name as category name
|
|
|
4c79b5 |
if (!empty($pathfile))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist_cats[$pathfile] = array();
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist_cats[$pathfile][$pathfile . $file] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// or if it's in the main category use the word before the first underscore to group files
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cats = array();
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cats[] = substr($file, 0, strpos($file, '_'));
|
|
|
4c79b5 |
$filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cats = array_values(array_unique($cats));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we don't need any single element categories so put them into the misc '' category
|
|
|
4c79b5 |
for ($i = 0, $n = sizeof($cats); $i < $n; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (sizeof($filelist_cats[$cats[$i]]) == 1 && $cats[$i] !== '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]);
|
|
|
4c79b5 |
unset($filelist_cats[$cats[$i]]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($cats);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($filelist);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate list of categorised template files
|
|
|
4c79b5 |
$tpl_options = '';
|
|
|
4c79b5 |
ksort($filelist_cats);
|
|
|
4c79b5 |
foreach ($filelist_cats as $category => $tpl_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
ksort($tpl_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!empty($category))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$tpl_options .= '<option class="sep" value="">' . $category . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($tpl_ary as $filename => $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($template_file == $filename) ? ' selected="selected"' : '';
|
|
|
4c79b5 |
$tpl_options .= '<option value="' . $filename . '"' . $selected . '>' . $file . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_EDIT_TEMPLATE' => true,
|
|
|
4c79b5 |
'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $template_file)),
|
|
|
4c79b5 |
'S_TEMPLATES' => $tpl_options,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows",
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_EDIT' => $user->lang['EDIT_TEMPLATE'],
|
|
|
4c79b5 |
'L_EDIT_EXPLAIN' => $user->lang['EDIT_TEMPLATE_EXPLAIN'],
|
|
|
4c79b5 |
'L_EDITOR' => $user->lang['TEMPLATE_EDITOR'],
|
|
|
4c79b5 |
'L_EDITOR_HEIGHT' => $user->lang['TEMPLATE_EDITOR_HEIGHT'],
|
|
|
4c79b5 |
'L_FILE' => $user->lang['TEMPLATE_FILE'],
|
|
|
4c79b5 |
'L_SELECT' => $user->lang['SELECT_TEMPLATE'],
|
|
|
4c79b5 |
'L_SELECTED' => $user->lang['SELECTED_TEMPLATE'],
|
|
|
4c79b5 |
'L_SELECTED_FILE' => $user->lang['SELECTED_TEMPLATE_FILE'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'SELECTED_TEMPLATE' => $template_info['template_name'],
|
|
|
4c79b5 |
'TEMPLATE_FILE' => $template_file,
|
|
|
4c79b5 |
'TEMPLATE_DATA' => utf8_htmlspecialchars($template_data),
|
|
|
4c79b5 |
'TEXT_ROWS' => $text_rows)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Allows the admin to view cached versions of template files and clear single template cache files
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param int $template_id specifies which template's cache is shown
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function template_cache($template_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$source = str_replace('/', '.', request_var('source', ''));
|
|
|
4c79b5 |
$file_ary = array_diff(request_var('delete', array('')), array(''));
|
|
|
4c79b5 |
$submit = isset($_POST['submit']) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $template_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$template_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$template_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// User wants to delete one or more files ...
|
|
|
4c79b5 |
if ($submit && $file_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->clear_template_cache($template_row, $file_ary);
|
|
|
4c79b5 |
trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action . "&action=cache&id=$template_id"));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Someone wants to see the cached source ... so we'll highlight it,
|
|
|
4c79b5 |
// add line numbers and indent it appropriately. This could be nasty
|
|
|
4c79b5 |
// on larger source files ...
|
|
|
4c79b5 |
if ($source && file_exists("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
adm_page_header($user->lang['TEMPLATE_CACHE']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->set_filenames(array(
|
|
|
4c79b5 |
'body' => 'viewsource.html')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'FILENAME' => str_replace('.', '/', $source) . '.html')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$code = str_replace(array("\r\n", "\r"), array("\n", "\n"), file_get_contents("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx"));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string');
|
|
|
4c79b5 |
foreach ($conf as $ini_var)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$marker = 'MARKER' . time();
|
|
|
4c79b5 |
$code = highlight_string(str_replace("\n", $marker, $code), true);
|
|
|
4c79b5 |
$code = str_replace($marker, "\n", $code);
|
|
|
4c79b5 |
$str_from = array('', '', ' ','[', ']', '.', ':');
|
|
|
4c79b5 |
$str_to = array('', '', '', '[', ']', '.', ':');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$code = str_replace($str_from, $str_to, $code);
|
|
|
4c79b5 |
$code = preg_replace('#^()\n?(.*?)\n?()$#ism', '$1$2$3', $code);
|
|
|
4c79b5 |
$code = substr($code, strlen(''));
|
|
|
4c79b5 |
$code = substr($code, 0, -1 * strlen(''));
|
|
|
4c79b5 |
$code = explode("\n", $code);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($code as $key => $line)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('source', array(
|
|
|
4c79b5 |
'LINENUM' => $key + 1,
|
|
|
4c79b5 |
'LINE' => preg_replace('#([^ ;]) ([^ &])#', '$1 $2', $line))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
unset($code[$key]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
adm_page_footer();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filemtime = array();
|
|
|
4c79b5 |
if ($template_row['template_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$ids = array();
|
|
|
4c79b5 |
if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$ids[] = $template_row['template_inherits_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$ids[] = $template_row['template_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filemtime = array();
|
|
|
4c79b5 |
$file_template_db = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($ids as $id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT template_filename, template_mtime
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filemtime[$row['template_filename']] = $row['template_mtime'];
|
|
|
4c79b5 |
$file_template_db[$row['template_filename']] = $id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Get a list of cached template files and then retrieve additional information about them
|
|
|
4c79b5 |
$file_ary = $this->template_cache_filelist($template_row['template_path']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file = str_replace('/', '.', $file);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// perform some dirty guessing to get the path right.
|
|
|
4c79b5 |
// We assume that three dots in a row were '../'
|
|
|
4c79b5 |
$tpl_file = str_replace('.', '/', $file);
|
|
|
4c79b5 |
$tpl_file = str_replace('///', '../', $tpl_file);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filename = "{$cache_prefix}_$file.html.$phpEx";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!file_exists("{$phpbb_root_path}cache/$filename"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$file_tpl = "{$phpbb_root_path}styles/{$template_row['template_path']}/template/$tpl_file.html";
|
|
|
4c79b5 |
$inherited = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$template_row['template_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!file_exists($file_tpl))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html";
|
|
|
4c79b5 |
$inherited = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($file_template_db[$file . '.html'] == $template_row['template_inherits_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html";
|
|
|
4c79b5 |
$inherited = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_block_vars('file', array(
|
|
|
4c79b5 |
'U_VIEWSOURCE' => $this->u_action . "&action=cache&id=$template_id&source=$file",
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'CACHED' => $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")),
|
|
|
4c79b5 |
'FILENAME' => $file,
|
|
|
4c79b5 |
'FILENAME_PATH' => $file_tpl,
|
|
|
4c79b5 |
'FILESIZE' => sprintf('%.1f ' . $user->lang['KIB'], filesize("{$phpbb_root_path}cache/$filename") / 1024),
|
|
|
4c79b5 |
'MODIFIED' => $user->format_date((!$template_row['template_storedb']) ? filemtime($file_tpl) : $filemtime[$file . '.html']))
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($filemtime);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_CACHE' => true,
|
|
|
4c79b5 |
'S_TEMPLATE' => true,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&action=cache&id=$template_id",
|
|
|
4c79b5 |
'U_BACK' => $this->u_action)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Provides a css editor and a basic easier to use stylesheet editing tool for less experienced (or lazy) users
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param int $theme_id specifies which theme is being edited
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function edit_theme($theme_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'EDIT_THEME';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filelist = $filelist_cats = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$theme_data = utf8_normalize_nfc(request_var('template_data', '', true));
|
|
|
4c79b5 |
$theme_data = htmlspecialchars_decode($theme_data);
|
|
|
4c79b5 |
$theme_file = utf8_normalize_nfc(request_var('template_file', '', true));
|
|
|
4c79b5 |
$text_rows = max(5, min(999, request_var('text_rows', 20)));
|
|
|
4c79b5 |
$save_changes = (isset($_POST['save'])) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// make sure theme_file path doesn't go upwards
|
|
|
4c79b5 |
$theme_file = str_replace('..', '.', $theme_file);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Retrieve some information about the theme
|
|
|
4c79b5 |
$sql = 'SELECT theme_storedb, theme_path, theme_name, theme_data
|
|
|
4c79b5 |
FROM ' . STYLES_THEME_TABLE . "
|
|
|
4c79b5 |
WHERE theme_id = $theme_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!($theme_info = $db->sql_fetchrow($result)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// save changes to the theme if the user submitted any
|
|
|
4c79b5 |
if ($save_changes)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Get the filesystem location of the current file
|
|
|
4c79b5 |
$file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file";
|
|
|
4c79b5 |
$additional = '';
|
|
|
4c79b5 |
$message = $user->lang['THEME_UPDATED'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the theme is stored on the filesystem try to write the file else store it in the database
|
|
|
4c79b5 |
if (!$safe_mode && !$theme_info['theme_storedb'] && file_exists($file) && @is_writable($file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!($fp = @fopen($file, 'wb')))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
fwrite($fp, $theme_data);
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Write stylesheet to db
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'theme_mtime' => time(),
|
|
|
4c79b5 |
'theme_storedb' => 1,
|
|
|
4c79b5 |
'theme_data' => $this->db_theme_data($theme_info, $theme_data),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_THEME_TABLE . '
|
|
|
4c79b5 |
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
|
|
|
4c79b5 |
WHERE theme_id = ' . $theme_id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_THEME_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// notify the user if the theme was not stored in the db before his modification
|
|
|
4c79b5 |
if (!$theme_info['theme_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
add_log('admin', 'LOG_THEME_EDIT_DETAILS', $theme_info['theme_name']);
|
|
|
4c79b5 |
$message .= ' ' . $user->lang['EDIT_THEME_STORED_DB'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_THEME_TABLE);
|
|
|
4c79b5 |
add_log('admin', (!$theme_info['theme_storedb']) ? 'LOG_THEME_EDIT_FILE' : 'LOG_THEME_EDIT', $theme_info['theme_name'], (!$theme_info['theme_storedb']) ? $theme_file : '');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error($message . adm_back_link($this->u_action . "&action=edit&id=$theme_id&template_file=$theme_file&text_rows=$text_rows"));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate a category array containing theme filenames
|
|
|
4c79b5 |
if (!$theme_info['theme_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filelist = filelist($theme_path, '', 'css');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($theme_file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file")))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$theme_data = &$theme_info['theme_data'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now create the categories
|
|
|
4c79b5 |
$filelist_cats[''] = array();
|
|
|
4c79b5 |
foreach ($filelist as $pathfile => $file_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Use the directory name as category name
|
|
|
4c79b5 |
if (!empty($pathfile))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist_cats[$pathfile] = array();
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist_cats[$pathfile][$pathfile . $file] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// or if it's in the main category use the word before the first underscore to group files
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cats = array();
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cats[] = substr($file, 0, strpos($file, '_'));
|
|
|
4c79b5 |
$filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cats = array_values(array_unique($cats));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we don't need any single element categories so put them into the misc '' category
|
|
|
4c79b5 |
for ($i = 0, $n = sizeof($cats); $i < $n; $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (sizeof($filelist_cats[$cats[$i]]) == 1 && $cats[$i] !== '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]);
|
|
|
4c79b5 |
unset($filelist_cats[$cats[$i]]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($cats);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($filelist);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate list of categorised theme files
|
|
|
4c79b5 |
$tpl_options = '';
|
|
|
4c79b5 |
ksort($filelist_cats);
|
|
|
4c79b5 |
foreach ($filelist_cats as $category => $tpl_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
ksort($tpl_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!empty($category))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$tpl_options .= '<option class="sep" value="">' . $category . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($tpl_ary as $filename => $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($theme_file == $filename) ? ' selected="selected"' : '';
|
|
|
4c79b5 |
$tpl_options .= '<option value="' . $filename . '"' . $selected . '>' . $file . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_EDIT_THEME' => true,
|
|
|
4c79b5 |
'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $theme_file)),
|
|
|
4c79b5 |
'S_THEME_IN_DB' => $theme_info['theme_storedb'],
|
|
|
4c79b5 |
'S_TEMPLATES' => $tpl_options,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&action=edit&id=$theme_id&text_rows=$text_rows",
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_EDIT' => $user->lang['EDIT_THEME'],
|
|
|
4c79b5 |
'L_EDIT_EXPLAIN' => $user->lang['EDIT_THEME_EXPLAIN'],
|
|
|
4c79b5 |
'L_EDITOR' => $user->lang['THEME_EDITOR'],
|
|
|
4c79b5 |
'L_EDITOR_HEIGHT' => $user->lang['THEME_EDITOR_HEIGHT'],
|
|
|
4c79b5 |
'L_FILE' => $user->lang['THEME_FILE'],
|
|
|
4c79b5 |
'L_SELECT' => $user->lang['SELECT_THEME'],
|
|
|
4c79b5 |
'L_SELECTED' => $user->lang['SELECTED_THEME'],
|
|
|
4c79b5 |
'L_SELECTED_FILE' => $user->lang['SELECTED_THEME_FILE'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'SELECTED_TEMPLATE' => $theme_info['theme_name'],
|
|
|
4c79b5 |
'TEMPLATE_FILE' => $theme_file,
|
|
|
4c79b5 |
'TEMPLATE_DATA' => utf8_htmlspecialchars($theme_data),
|
|
|
4c79b5 |
'TEXT_ROWS' => $text_rows)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Edit imagesets
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param int $imageset_id specifies which imageset is being edited
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function edit_imageset($imageset_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user, $phpbb_root_path, $cache, $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'EDIT_IMAGESET';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imgname = request_var('imgname', '');
|
|
|
4c79b5 |
$imgpath = request_var('imgpath', '');
|
|
|
4c79b5 |
$imgsize = request_var('imgsize', false);
|
|
|
4c79b5 |
$imgwidth = request_var('imgwidth', 0);
|
|
|
4c79b5 |
$imgheight = request_var('imgheight', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imgname = preg_replace('#[^a-z0-9\-+_]#i', '', $imgname);
|
|
|
4c79b5 |
$imgpath = str_replace('..', '.', $imgpath);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($imageset_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT imageset_path, imageset_name
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_TABLE . "
|
|
|
4c79b5 |
WHERE imageset_id = $imageset_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$imageset_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imageset_path = $imageset_row['imageset_path'];
|
|
|
4c79b5 |
$imageset_name = $imageset_row['imageset_name'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_extra = '';
|
|
|
4c79b5 |
if (strpos($imgname, '-') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($imgname, $imgnamelang) = explode('-', $imgname);
|
|
|
4c79b5 |
$sql_extra = " AND image_lang IN ('" . $db->sql_escape($imgnamelang) . "', '')";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT image_filename, image_width, image_height, image_lang, image_id
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE imageset_id = $imageset_id
|
|
|
4c79b5 |
AND image_name = '" . $db->sql_escape($imgname) . "'$sql_extra";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$imageset_data_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$image_filename = $imageset_data_row['image_filename'];
|
|
|
4c79b5 |
$image_width = $imageset_data_row['image_width'];
|
|
|
4c79b5 |
$image_height = $imageset_data_row['image_height'];
|
|
|
4c79b5 |
$image_lang = $imageset_data_row['image_lang'];
|
|
|
4c79b5 |
$image_id = $imageset_data_row['image_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$imageset_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check to see whether the selected image exists in the table
|
|
|
4c79b5 |
$valid_name = ($update) ? false : true;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($this->imageset_keys as $category => $img_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (in_array($imgname, $img_ary))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$valid_name = true;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update && isset($_POST['imgpath']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($valid_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// If imgwidth and imgheight are non-zero grab the actual size
|
|
|
4c79b5 |
// from the image itself ... we ignore width settings for the poll center image
|
|
|
4c79b5 |
$imgwidth = request_var('imgwidth', 0);
|
|
|
4c79b5 |
$imgheight = request_var('imgheight', 0);
|
|
|
4c79b5 |
$imglang = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($imgpath && !file_exists("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_IMAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($imgsize && $imgpath)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$imgwidth || !$imgheight)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($imgwidth_file, $imgheight_file) = getimagesize("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath");
|
|
|
4c79b5 |
$imgwidth = ($imgwidth) ? $imgwidth : $imgwidth_file;
|
|
|
4c79b5 |
$imgheight = ($imgheight) ? $imgheight : $imgheight_file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$imgwidth = ($imgname != 'poll_center') ? (int) $imgwidth : 0;
|
|
|
4c79b5 |
$imgheight = (int) $imgheight;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strpos($imgpath, '/') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($imglang, $imgfilename) = explode('/', $imgpath);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imgfilename = $imgpath;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'image_filename' => (string) $imgfilename,
|
|
|
4c79b5 |
'image_width' => (int) $imgwidth,
|
|
|
4c79b5 |
'image_height' => (int) $imgheight,
|
|
|
4c79b5 |
'image_lang' => (string) $imglang,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// already exists
|
|
|
4c79b5 |
if ($imageset_data_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_IMAGESET_DATA_TABLE . '
|
|
|
4c79b5 |
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
|
|
|
4c79b5 |
WHERE image_id = $image_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// does not exist
|
|
|
4c79b5 |
else if (!$imageset_data_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary['image_name'] = $imgname;
|
|
|
4c79b5 |
$sql_ary['imageset_id'] = (int) $imageset_id;
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_IMAGESET_EDIT', $imageset_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_var('SUCCESS', true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$image_filename = $imgfilename;
|
|
|
4c79b5 |
$image_width = $imgwidth;
|
|
|
4c79b5 |
$image_height = $imgheight;
|
|
|
4c79b5 |
$image_lang = $imglang;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imglang = '';
|
|
|
4c79b5 |
$imagesetlist = array('nolang' => array(), 'lang' => array());
|
|
|
4c79b5 |
$langs = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$dir = "{$phpbb_root_path}styles/$imageset_path/imageset";
|
|
|
4c79b5 |
$dp = @opendir($dir);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($dp)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
while (($file = readdir($dp)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($file[0] != '.' && strtoupper($file) != 'CVS' && !is_file($dir . '/' . $file) && !is_link($dir . '/' . $file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$langs[] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (preg_match('#\.(?:gif|jpg|png)$#', $file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imagesetlist['nolang'][] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($sql_extra)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$dp2 = @opendir("$dir/$imgnamelang");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($dp2)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
while (($file2 = readdir($dp2)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (preg_match('#\.(?:gif|jpg|png)$#', $file2))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imagesetlist['lang'][] = "$imgnamelang/$file2";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dp2);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dp);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Generate list of image options
|
|
|
4c79b5 |
$img_options = '';
|
|
|
4c79b5 |
foreach ($this->imageset_keys as $category => $img_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('category', array(
|
|
|
4c79b5 |
'NAME' => $user->lang['IMG_CAT_' . strtoupper($category)]
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($img_ary as $img)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($category == 'buttons')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($langs as $language)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('category.images', array(
|
|
|
4c79b5 |
'SELECTED' => ($img == $imgname && $language == $imgnamelang),
|
|
|
4c79b5 |
'VALUE' => $img . '-' . $language,
|
|
|
4c79b5 |
'TEXT' => $user->lang['IMG_' . strtoupper($img)] . ' [ ' . $language . ' ]'
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('category.images', array(
|
|
|
4c79b5 |
'SELECTED' => ($img == $imgname),
|
|
|
4c79b5 |
'VALUE' => $img,
|
|
|
4c79b5 |
'TEXT' => (($category == 'custom') ? $img : $user->lang['IMG_' . strtoupper($img)])
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Make sure the list of possible images is sorted alphabetically
|
|
|
4c79b5 |
sort($imagesetlist['lang']);
|
|
|
4c79b5 |
sort($imagesetlist['nolang']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$image_found = false;
|
|
|
4c79b5 |
$img_val = '';
|
|
|
4c79b5 |
foreach ($imagesetlist as $type => $img_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($type !== 'lang' || $sql_extra)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template->assign_block_vars('imagesetlist', array(
|
|
|
4c79b5 |
'TYPE' => ($type == 'lang')
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($img_ary as $img)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imgtext = preg_replace('/^([^\/]+\/)/', '', $img);
|
|
|
4c79b5 |
$selected = (!empty($imgname) && strpos($image_filename, $imgtext) !== false);
|
|
|
4c79b5 |
if ($selected)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_found = true;
|
|
|
4c79b5 |
$img_val = htmlspecialchars($img);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$template->assign_block_vars('imagesetlist.images', array(
|
|
|
4c79b5 |
'SELECTED' => $selected,
|
|
|
4c79b5 |
'TEXT' => $imgtext,
|
|
|
4c79b5 |
'VALUE' => htmlspecialchars($img)
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imgsize_bool = (!empty($imgname) && $image_width && $image_height) ? true : false;
|
|
|
4c79b5 |
$image_request = '../styles/' . $imageset_path . '/imageset/' . ($image_lang ? $imgnamelang . '/' : '') . $image_filename;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_EDIT_IMAGESET' => true,
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'IMAGE_OPTIONS' => $img_options,
|
|
|
4c79b5 |
'IMAGE_SIZE' => $image_width,
|
|
|
4c79b5 |
'IMAGE_HEIGHT' => $image_height,
|
|
|
4c79b5 |
'IMAGE_REQUEST' => (empty($image_filename)) ? 'images/no_image.png' : $image_request,
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&action=edit&id=$imageset_id",
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
'NAME' => $imageset_name,
|
|
|
4c79b5 |
'A_NAME' => addslashes($imageset_name),
|
|
|
4c79b5 |
'ERROR' => !$valid_name,
|
|
|
4c79b5 |
'IMG_SRC' => ($image_found) ? '../styles/' . $imageset_path . '/imageset/' . $img_val : 'images/no_image.png',
|
|
|
4c79b5 |
'IMAGE_SELECT' => $image_found
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Remove style/template/theme/imageset
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function remove($mode, $style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $template, $user, $phpbb_root_path, $cache, $config;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_id = request_var('new_id', 0);
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
$sql_where = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
$sql_from = STYLES_TABLE;
|
|
|
4c79b5 |
$sql_select = 'style_name';
|
|
|
4c79b5 |
$sql_where = 'AND style_active = 1';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
$sql_select = 'template_name, template_path, template_storedb';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
$sql_select = 'theme_name, theme_path, theme_storedb';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
$sql_select = 'imageset_name, imageset_path';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode === 'template' && ($conflicts = $this->check_inheritance($mode, $style_id)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
$msg = $user->lang[$l_type . '_DELETE_DEPENDENT'];
|
|
|
4c79b5 |
foreach ($conflicts as $id => $values)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$msg .= ' ' . $values['template_name'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error($msg . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_prefix = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT $sql_select
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id <> $style_id
|
|
|
4c79b5 |
$sql_where
|
|
|
4c79b5 |
ORDER BY {$mode}_name ASC";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$s_options = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
do
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$s_options .= '<option value="' . $row[$mode . '_id'] . '">' . $row[$mode . '_name'] . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "DELETE FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
|
4c79b5 |
SET user_style = $new_id
|
|
|
4c79b5 |
WHERE user_style = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
|
|
4c79b5 |
SET forum_style = $new_id
|
|
|
4c79b5 |
WHERE forum_style = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($style_id == $config['default_style'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
set_config('default_style', $new_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($mode == 'imageset')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE imageset_id = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_TABLE . "
|
|
|
4c79b5 |
SET {$mode}_id = $new_id
|
|
|
4c79b5 |
WHERE {$mode}_id = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_' . $l_prefix . '_DELETE', $style_row[$mode . '_name']);
|
|
|
4c79b5 |
$message = ($mode != 'style') ? $l_prefix . '_DELETED_FS' : $l_prefix . '_DELETED';
|
|
|
4c79b5 |
trigger_error($user->lang[$message] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'DELETE_' . $l_prefix;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_DELETE' => true,
|
|
|
4c79b5 |
'S_REPLACE_OPTIONS' => $s_options,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_NAME' => $user->lang[$l_prefix . '_NAME'],
|
|
|
4c79b5 |
'L_REPLACE' => $user->lang['REPLACE_' . $l_prefix],
|
|
|
4c79b5 |
'L_REPLACE_EXPLAIN' => $user->lang['REPLACE_' . $l_prefix . '_EXPLAIN'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&action=delete&id=$style_id",
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'NAME' => $style_row[$mode . '_name'],
|
|
|
4c79b5 |
)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Export style or style elements
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function export($mode, $style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $template, $user, $phpbb_root_path, $cache, $phpEx, $config;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$inc_template = request_var('inc_template', 0);
|
|
|
4c79b5 |
$inc_theme = request_var('inc_theme', 0);
|
|
|
4c79b5 |
$inc_imageset = request_var('inc_imageset', 0);
|
|
|
4c79b5 |
$store = request_var('store', 0);
|
|
|
4c79b5 |
$format = request_var('format', '');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
$methods = array('tar');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$available_methods = array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib');
|
|
|
4c79b5 |
foreach ($available_methods as $type => $module)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!@extension_loaded($module))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$methods[] = $type;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!in_array($format, $methods))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$format = 'tar';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
if ($update && ($inc_template + $inc_theme + $inc_imageset) < 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_MORE_ELEMENTS'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$name = 'style_name';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_select = 's.style_id, s.style_name, s.style_copyright';
|
|
|
4c79b5 |
$sql_select .= ($inc_template) ? ', t.*' : ', t.template_name';
|
|
|
4c79b5 |
$sql_select .= ($inc_theme) ? ', c.*' : ', c.theme_name';
|
|
|
4c79b5 |
$sql_select .= ($inc_imageset) ? ', i.*' : ', i.imageset_name';
|
|
|
4c79b5 |
$sql_from = STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i';
|
|
|
4c79b5 |
$sql_where = "s.style_id = $style_id AND t.template_id = s.template_id AND c.theme_id = s.theme_id AND i.imageset_id = s.imageset_id";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_prefix = 'STYLE';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$name = 'template_name';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_select = '*';
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
$sql_where = "template_id = $style_id";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_prefix = 'TEMPLATE';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$name = 'theme_name';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_select = '*';
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
$sql_where = "theme_id = $style_id";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_prefix = 'THEME';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$name = 'imageset_name';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_select = '*';
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
$sql_where = "imageset_id = $style_id";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_prefix = 'IMAGESET';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update && !sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT $sql_select
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE $sql_where";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data', 'imageset_id', 'imageset_name', 'imageset_path', 'imageset_copyright');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($var_ary as $var)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!isset($style_row[$var]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row[$var] = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$files = $data = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['style_name'], $style_row['style_copyright'], $config['version']), $this->style_cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_cfg .= (!$inc_template) ? "\nrequired_template = {$style_row['template_name']}" : '';
|
|
|
4c79b5 |
$style_cfg .= (!$inc_theme) ? "\nrequired_theme = {$style_row['theme_name']}" : '';
|
|
|
4c79b5 |
$style_cfg .= (!$inc_imageset) ? "\nrequired_imageset = {$style_row['imageset_name']}" : '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => $style_cfg,
|
|
|
4c79b5 |
'prefix' => 'style.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($style_cfg);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Export template core code
|
|
|
4c79b5 |
if ($mode == 'template' || $inc_template)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version']), $this->template_cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$use_template_name = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add the inherit from variable, depending on it's use...
|
|
|
4c79b5 |
if ($style_row['template_inherits_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Get the template name
|
|
|
4c79b5 |
$sql = 'SELECT template_name
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_TABLE . '
|
|
|
4c79b5 |
WHERE template_id = ' . (int) $style_row['template_inherits_id'];
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$use_template_name = (string) $db->sql_fetchfield('template_name');
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template_cfg .= ($use_template_name) ? "\ninherit_from = $use_template_name" : "\n#inherit_from = ";
|
|
|
4c79b5 |
$template_cfg .= "\n\nbbcode_bitfield = {$style_row['bbcode_bitfield']}";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => $template_cfg,
|
|
|
4c79b5 |
'prefix' => 'template/template.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// This is potentially nasty memory-wise ...
|
|
|
4c79b5 |
if (!$style_row['template_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$files[] = array(
|
|
|
4c79b5 |
'src' => "styles/{$style_row['template_path']}/template/",
|
|
|
4c79b5 |
'prefix-' => "styles/{$style_row['template_path']}/",
|
|
|
4c79b5 |
'prefix+' => false,
|
|
|
4c79b5 |
'exclude' => 'template.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT template_filename, template_data
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = {$style_row['template_id']}";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => $row['template_data'],
|
|
|
4c79b5 |
'prefix' => 'template/' . $row['template_filename']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($template_cfg);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Export theme core code
|
|
|
4c79b5 |
if ($mode == 'theme' || $inc_theme)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$theme_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['theme_name'], $style_row['theme_copyright'], $config['version']), $this->theme_cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Read old cfg file
|
|
|
4c79b5 |
$items = $cache->obtain_cfg_items($style_row);
|
|
|
4c79b5 |
$items = $items['theme'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!isset($items['parse_css_file']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$items['parse_css_file'] = 'off';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$theme_cfg = str_replace(array('{PARSE_CSS_FILE}'), array($items['parse_css_file']), $theme_cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$files[] = array(
|
|
|
4c79b5 |
'src' => "styles/{$style_row['theme_path']}/theme/",
|
|
|
4c79b5 |
'prefix-' => "styles/{$style_row['theme_path']}/",
|
|
|
4c79b5 |
'prefix+' => false,
|
|
|
4c79b5 |
'exclude' => ($style_row['theme_storedb']) ? 'stylesheet.css,theme.cfg' : 'theme.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => $theme_cfg,
|
|
|
4c79b5 |
'prefix' => 'theme/theme.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($style_row['theme_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => $style_row['theme_data'],
|
|
|
4c79b5 |
'prefix' => 'theme/stylesheet.css'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($items, $theme_cfg);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Export imageset core code
|
|
|
4c79b5 |
if ($mode == 'imageset' || $inc_imageset)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['imageset_name'], $style_row['imageset_copyright'], $config['version']), $this->imageset_cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imageset_main = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT image_filename, image_name, image_height, image_width
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE imageset_id = $style_id
|
|
|
4c79b5 |
AND image_lang = ''";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_main[$row['image_name']] = $row['image_filename'] . ($row['image_height'] ? '*' . $row['image_height']: '') . ($row['image_width'] ? '*' . $row['image_width']: '');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($this->imageset_keys as $topic => $key_array)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($key_array as $key)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (isset($imageset_main[$key]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_cfg .= "\nimg_" . $key . ' = ' . str_replace("styles/{$style_row['imageset_path']}/imageset/", '{PATH}', $imageset_main[$key]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$files[] = array(
|
|
|
4c79b5 |
'src' => "styles/{$style_row['imageset_path']}/imageset/",
|
|
|
4c79b5 |
'prefix-' => "styles/{$style_row['imageset_path']}/",
|
|
|
4c79b5 |
'prefix+' => false,
|
|
|
4c79b5 |
'exclude' => 'imageset.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => trim($imageset_cfg),
|
|
|
4c79b5 |
'prefix' => 'imageset/imageset.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
end($data);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imageset_root = "{$phpbb_root_path}styles/{$style_row['imageset_path']}/imageset/";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($dh = @opendir($imageset_root))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
while (($fname = readdir($dh)) !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($fname[0] != '.' && $fname != 'CVS' && is_dir("$imageset_root$fname"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$files[key($files)]['exclude'] .= ',' . $fname . '/imageset.cfg';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dh);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imageset_lang = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT image_filename, image_name, image_height, image_width, image_lang
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE imageset_id = $style_id
|
|
|
4c79b5 |
AND image_lang <> ''";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_lang[$row['image_lang']][$row['image_name']] = $row['image_filename'] . ($row['image_height'] ? '*' . $row['image_height']: '') . ($row['image_width'] ? '*' . $row['image_width']: '');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($imageset_lang as $lang => $imageset_localized)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['imageset_name'], $style_row['imageset_copyright'], $config['version']), $this->imageset_cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($this->imageset_keys as $topic => $key_array)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($key_array as $key)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (isset($imageset_localized[$key]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_cfg .= "\nimg_" . $key . ' = ' . str_replace("styles/{$style_row['imageset_path']}/imageset/", '{PATH}', $imageset_localized[$key]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$data[] = array(
|
|
|
4c79b5 |
'src' => trim($imageset_cfg),
|
|
|
4c79b5 |
'prefix' => 'imageset/' . $lang . '/imageset.cfg'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($imageset_cfg);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($format)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'tar':
|
|
|
4c79b5 |
$ext = '.tar';
|
|
|
4c79b5 |
$mimetype = 'x-tar';
|
|
|
4c79b5 |
$compress = 'compress_tar';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'zip':
|
|
|
4c79b5 |
$ext = '.zip';
|
|
|
4c79b5 |
$mimetype = 'zip';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tar.gz':
|
|
|
4c79b5 |
$ext = '.tar.gz';
|
|
|
4c79b5 |
$mimetype = 'x-gzip';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'tar.bz2':
|
|
|
4c79b5 |
$ext = '.tar.bz2';
|
|
|
4c79b5 |
$mimetype = 'x-bzip2';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
$error[] = $user->lang[$l_prefix . '_ERR_ARCHIVE'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$path = preg_replace('#[^\w-]+#', '_', $style_row['style_name']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$path = $style_row[$mode . '_path'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($format == 'zip')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$compress = new compress_zip('w', $phpbb_root_path . "store/$path$ext");
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$compress = new compress_tar('w', $phpbb_root_path . "store/$path$ext", $ext);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($files))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($files as $file_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$compress->add_file($file_ary['src'], $file_ary['prefix-'], $file_ary['prefix+'], $file_ary['exclude']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($data))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($data as $data_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$compress->add_data($data_ary['src'], $data_ary['prefix']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$compress->close();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_' . $l_prefix . '_EXPORT', $style_row[$mode . '_name']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$store)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$compress->download($path);
|
|
|
4c79b5 |
@unlink("{$phpbb_root_path}store/$path$ext");
|
|
|
4c79b5 |
exit;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
trigger_error(sprintf($user->lang[$l_prefix . '_EXPORTED'], "store/$path$ext") . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name
|
|
|
4c79b5 |
FROM " . (($mode == 'style') ? STYLES_TABLE : $sql_from) . "
|
|
|
4c79b5 |
WHERE {$mode}_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = $l_prefix . '_EXPORT';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$format_buttons = '';
|
|
|
4c79b5 |
foreach ($methods as $method)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$format_buttons .= '<label><input type="radio"' . ((!$format_buttons) ? ' id="format"' : '') . ' class="radio" value="' . $method . '" name="format"' . (($method == $format) ? ' checked="checked"' : '') . ' /> ' . $method . '</label>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_EXPORT' => true,
|
|
|
4c79b5 |
'S_ERROR_MSG' => (sizeof($error)) ? true : false,
|
|
|
4c79b5 |
'S_STYLE' => ($mode == 'style') ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_NAME' => $user->lang[$l_prefix . '_NAME'],
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . '&action=export&id=' . $style_id,
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($error)) ? implode(' ', $error) : '',
|
|
|
4c79b5 |
'NAME' => $style_row[$mode . '_name'],
|
|
|
4c79b5 |
'FORMAT_BUTTONS' => $format_buttons)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Display details
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function details($mode, $style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $template, $db, $config, $user, $safe_mode, $cache, $phpbb_root_path;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
$element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
$sql_from = STYLES_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT *
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id = $style_id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_row['style_default'] = ($mode == 'style' && $config['default_style'] == $style_id) ? 1 : 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$name = utf8_normalize_nfc(request_var('name', '', true));
|
|
|
4c79b5 |
$copyright = utf8_normalize_nfc(request_var('copyright', '', true));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template_id = request_var('template_id', 0);
|
|
|
4c79b5 |
$theme_id = request_var('theme_id', 0);
|
|
|
4c79b5 |
$imageset_id = request_var('imageset_id', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_active = request_var('style_active', 0);
|
|
|
4c79b5 |
$style_default = request_var('style_default', 0);
|
|
|
4c79b5 |
$store_db = request_var('store_db', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the admin selected the style to be the default style, but forgot to activate it... we will do it for him
|
|
|
4c79b5 |
if ($style_default)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_active = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id <> $style_id
|
|
|
4c79b5 |
AND LOWER({$mode}_name) = '" . $db->sql_escape(strtolower($name)) . "'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$conflict = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style' && (!$template_id || !$theme_id || !$imageset_id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_NO_IDS'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style' && $style_row['style_active'] && !$style_active && $config['default_style'] == $style_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['DEACTIVATE_DEFAULT'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$name || $conflict)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_STYLE_NAME'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode === 'theme' || $mode === 'template')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// a rather elaborate check we have to do here once to avoid trouble later
|
|
|
4c79b5 |
$check = "{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . (($mode === 'theme') ? '/theme/stylesheet.css' : '/template');
|
|
|
4c79b5 |
if (($style_row["{$mode}_storedb"] != $store_db) && !$store_db && ($safe_mode || !@is_writable($check)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['EDIT_' . strtoupper($mode) . '_STORED_DB'];
|
|
|
4c79b5 |
$store_db = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// themes which have to be parsed have to go into db
|
|
|
4c79b5 |
if ($mode == 'theme')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cfg = parse_cfg_file("{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . "/theme/theme.cfg");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($cfg['parse_css_file']) && $cfg['parse_css_file'] && !$store_db)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['EDIT_THEME_STORE_PARSED'];
|
|
|
4c79b5 |
$store_db = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Check length settings
|
|
|
4c79b5 |
if (utf8_strlen($name) > 30)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_NAME_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (utf8_strlen($copyright) > 60)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_COPY_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update && sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row = array_merge($style_row, array(
|
|
|
4c79b5 |
'template_id' => $template_id,
|
|
|
4c79b5 |
'theme_id' => $theme_id,
|
|
|
4c79b5 |
'imageset_id' => $imageset_id,
|
|
|
4c79b5 |
'style_active' => $style_active,
|
|
|
4c79b5 |
$mode . '_storedb' => $store_db,
|
|
|
4c79b5 |
$mode . '_name' => $name,
|
|
|
4c79b5 |
$mode . '_copyright' => $copyright)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// User has submitted form and no errors have occurred
|
|
|
4c79b5 |
if ($update && !sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
$mode . '_name' => $name,
|
|
|
4c79b5 |
$mode . '_copyright' => $copyright
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary += array(
|
|
|
4c79b5 |
'template_id' => (int) $template_id,
|
|
|
4c79b5 |
'theme_id' => (int) $theme_id,
|
|
|
4c79b5 |
'imageset_id' => (int) $imageset_id,
|
|
|
4c79b5 |
'style_active' => (int) $style_active,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($style_row['theme_storedb'] != $store_db)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$theme_data = '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row['theme_storedb'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$theme_data = $this->db_theme_data($style_row);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (!$store_db && !$safe_mode && @is_writable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$store_db = 1;
|
|
|
4c79b5 |
$theme_data = $style_row['theme_data'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($fp = @fopen("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css", 'wb'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$store_db = (@fwrite($fp, str_replace("styles/{$style_row['theme_path']}/theme/", './', $theme_data))) ? 0 : 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary += array(
|
|
|
4c79b5 |
'theme_mtime' => ($store_db) ? filemtime("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css") : 0,
|
|
|
4c79b5 |
'theme_storedb' => $store_db,
|
|
|
4c79b5 |
'theme_data' => ($store_db) ? $theme_data : '',
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($style_row['template_storedb'] != $store_db)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($super = $this->get_super($mode, $style_row['template_id']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name']));
|
|
|
4c79b5 |
$sql_ary = array();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!$store_db && !$safe_mode && @is_writable("{$phpbb_root_path}styles/{$style_row['template_path']}/template"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$err = $this->store_in_fs('template', $style_row['template_id']);
|
|
|
4c79b5 |
if ($err)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error += $err;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($store_db)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->store_in_db('template', $style_row['template_id']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// We no longer store within the db, but are also not able to update the file structure
|
|
|
4c79b5 |
// Since the admin want to switch this, we adhere to his decision. But we also need to remove the cache
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary += array(
|
|
|
4c79b5 |
'template_storedb' => $store_db,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($sql_ary))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "UPDATE $sql_from
|
|
|
4c79b5 |
SET " . $db->sql_build_array('UPDATE', $sql_ary) . "
|
|
|
4c79b5 |
WHERE {$mode}_id = $style_id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Making this the default style?
|
|
|
4c79b5 |
if ($mode == 'style' && $style_default)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
set_config('default_style', $style_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_' . $l_type . '_EDIT_DETAILS', $name);
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error(implode(' ', $error) . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang[$l_type . '_DETAILS_UPDATED'] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($element_ary as $element => $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT {$element}_id, {$element}_name
|
|
|
4c79b5 |
FROM $table
|
|
|
4c79b5 |
ORDER BY {$element}_id ASC";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
${$element . '_options'} = '';
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($row[$element . '_id'] == $style_row[$element . '_id']) ? ' selected="selected"' : '';
|
|
|
4c79b5 |
${$element . '_options'} .= '<option value="' . $row[$element . '_id'] . '"' . $selected . '>' . $row[$element . '_name'] . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'template')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$super = array();
|
|
|
4c79b5 |
if (isset($style_row[$mode . '_inherits_id']) && $style_row['template_inherits_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$super = $this->get_super($mode, $style_row['template_id']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'EDIT_DETAILS_' . $l_type;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_DETAILS' => true,
|
|
|
4c79b5 |
'S_ERROR_MSG' => (sizeof($error)) ? true : false,
|
|
|
4c79b5 |
'S_STYLE' => ($mode == 'style') ? true : false,
|
|
|
4c79b5 |
'S_TEMPLATE' => ($mode == 'template') ? true : false,
|
|
|
4c79b5 |
'S_THEME' => ($mode == 'theme') ? true : false,
|
|
|
4c79b5 |
'S_IMAGESET' => ($mode == 'imageset') ? true : false,
|
|
|
4c79b5 |
'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0,
|
|
|
4c79b5 |
'S_STORE_DB_DISABLED' => (isset($style_row[$mode . '_inherits_id'])) ? $style_row[$mode . '_inherits_id'] : 0,
|
|
|
4c79b5 |
'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0,
|
|
|
4c79b5 |
'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0,
|
|
|
4c79b5 |
'S_SUPERTEMPLATE' => (isset($style_row[$mode . '_inherits_id']) && $style_row[$mode . '_inherits_id']) ? $super['template_name'] : 0,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '',
|
|
|
4c79b5 |
'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '',
|
|
|
4c79b5 |
'S_IMAGESET_OPTIONS' => ($mode == 'style') ? $imageset_options : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . '&action=details&id=' . $style_id,
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_NAME' => $user->lang[$l_type . '_NAME'],
|
|
|
4c79b5 |
'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '',
|
|
|
4c79b5 |
'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($error)) ? implode(' ', $error) : '',
|
|
|
4c79b5 |
'NAME' => $style_row[$mode . '_name'],
|
|
|
4c79b5 |
'COPYRIGHT' => $style_row[$mode . '_copyright'],
|
|
|
4c79b5 |
)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Load css file contents
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function load_css_file($path, $filename)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$file = "{$phpbb_root_path}styles/$path/theme/$filename";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (file_exists($file) && ($content = file_get_contents($file)))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$content = trim($content);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$content = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if (defined('DEBUG'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$content = "/* BEGIN @include $filename */ \n $content \n /* END @include $filename */ \n";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $content;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Returns a string containing the value that should be used for the theme_data column in the theme database table.
|
|
|
4c79b5 |
* Includes contents of files loaded via @import
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param array $theme_row is an associative array containing the theme's current database entry
|
|
|
4c79b5 |
* @param mixed $stylesheet can either be the new content for the stylesheet or false to load from the standard file
|
|
|
4c79b5 |
* @param string $root_path should only be used in case you want to use a different root path than "{$phpbb_root_path}styles/{$theme_row['theme_path']}"
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @return string Stylesheet data for theme_data column in the theme table
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function db_theme_data($theme_row, $stylesheet = false, $root_path = '')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$root_path)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$root_path = $phpbb_root_path . 'styles/' . $theme_row['theme_path'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$stylesheet)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$stylesheet = '';
|
|
|
4c79b5 |
if (file_exists($root_path . '/theme/stylesheet.css'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$stylesheet = file_get_contents($root_path . '/theme/stylesheet.css');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Match CSS imports
|
|
|
4c79b5 |
$matches = array();
|
|
|
4c79b5 |
preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($matches))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($matches[0] as $idx => $match)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[1][$idx]), $stylesheet);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// adjust paths
|
|
|
4c79b5 |
return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Store template files into db
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function store_templates($mode, $style_id, $template_path, $filelist)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template_path = $template_path . '/template/';
|
|
|
4c79b5 |
$includes = array();
|
|
|
4c79b5 |
foreach ($filelist as $pathfile => $file_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!($fp = @fopen("{$phpbb_root_path}styles/$template_path$pathfile$file", 'r')))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error("Could not open {$phpbb_root_path}styles/$template_path$pathfile$file", E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$template_data = fread($fp, filesize("{$phpbb_root_path}styles/$template_path$pathfile$file"));
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (preg_match_all('##is', $template_data, $matches))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($matches[1] as $match)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$includes[trim($match)][] = $file;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($filelist as $pathfile => $file_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Skip index.
|
|
|
4c79b5 |
if (strpos($file, 'index.') === 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We could do this using extended inserts ... but that could be one
|
|
|
4c79b5 |
// heck of a lot of data ...
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'template_id' => (int) $style_id,
|
|
|
4c79b5 |
'template_filename' => "$pathfile$file",
|
|
|
4c79b5 |
'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '',
|
|
|
4c79b5 |
'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/$template_path$pathfile$file"),
|
|
|
4c79b5 |
'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/$template_path$pathfile$file"),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'insert')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'INSERT INTO ' . STYLES_TEMPLATE_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
|
|
|
4c79b5 |
WHERE template_id = $style_id
|
|
|
4c79b5 |
AND template_filename = '" . $db->sql_escape("$pathfile$file") . "'";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Returns an array containing all template filenames for one template that are currently cached.
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param string $template_path contains the name of the template's folder in /styles/
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @return array of filenames that exist in /styles/$template_path/template/ (without extension!)
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function template_cache_filelist($template_path)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache_prefix = 'tpl_' . str_replace('_', '-', $template_path);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!($dp = @opendir("{$phpbb_root_path}cache")))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['TEMPLATE_ERR_CACHE_READ'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$file_ary = array();
|
|
|
4c79b5 |
while ($file = readdir($dp))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($file[0] == '.')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (is_file($phpbb_root_path . 'cache/' . $file) && (strpos($file, $cache_prefix) === 0))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file_ary[] = str_replace('.', '/', preg_replace('#^' . preg_quote($cache_prefix, '#') . '_(.*?)\.html\.' . $phpEx . '$#i', '\1', $file));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
closedir($dp);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $file_ary;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Destroys cached versions of template files
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @param array $template_row contains the template's row in the STYLES_TEMPLATE_TABLE database table
|
|
|
4c79b5 |
* @param mixed $file_ary is optional and may contain an array of template file names which should be refreshed in the cache.
|
|
|
4c79b5 |
* The file names should be the original template file names and not the cache file names.
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function clear_template_cache($template_row, $file_ary = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$file_ary || !is_array($file_ary))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file_ary = $this->template_cache_filelist($template_row['template_path']);
|
|
|
4c79b5 |
$log_file_list = $user->lang['ALL_FILES'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$log_file_list = implode(', ', $file_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($file_ary as $file)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$file = str_replace('/', '.', $file);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$file = "{$phpbb_root_path}cache/{$cache_prefix}_$file.html.$phpEx";
|
|
|
4c79b5 |
if (file_exists($file) && is_file($file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@unlink($file);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($file_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_TEMPLATE_CACHE_CLEARED', $template_row['template_name'], $log_file_list);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Install Style/Template/Theme/Imageset
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function install($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error = $installcfg = $style_row = array();
|
|
|
4c79b5 |
$root_path = $cfg_file = '';
|
|
|
4c79b5 |
$element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$install_path = request_var('path', '');
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Installing, obtain cfg file contents
|
|
|
4c79b5 |
if ($install_path)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$root_path = $phpbb_root_path . 'styles/' . $install_path . '/';
|
|
|
4c79b5 |
$cfg_file = ($mode == 'style') ? "$root_path$mode.cfg" : "$root_path$mode/$mode.cfg";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!file_exists($cfg_file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_NOT_' . $l_type];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$installcfg = parse_cfg_file($cfg_file);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Installing
|
|
|
4c79b5 |
if (sizeof($installcfg))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$name = $installcfg['name'];
|
|
|
4c79b5 |
$copyright = $installcfg['copyright'];
|
|
|
4c79b5 |
$version = $installcfg['version'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_row = array(
|
|
|
4c79b5 |
$mode . '_id' => 0,
|
|
|
4c79b5 |
$mode . '_name' => '',
|
|
|
4c79b5 |
$mode . '_copyright' => ''
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_row = array(
|
|
|
4c79b5 |
'style_id' => 0,
|
|
|
4c79b5 |
'style_name' => $installcfg['name'],
|
|
|
4c79b5 |
'style_copyright' => $installcfg['copyright']
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false;
|
|
|
4c79b5 |
$reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false;
|
|
|
4c79b5 |
$reqd_imageset = (isset($installcfg['required_imageset'])) ? $installcfg['required_imageset'] : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check to see if each element is already installed, if it is grab the id
|
|
|
4c79b5 |
foreach ($element_ary as $element => $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row = array_merge($style_row, array(
|
|
|
4c79b5 |
$element . '_id' => 0,
|
|
|
4c79b5 |
$element . '_name' => '',
|
|
|
4c79b5 |
$element . '_copyright' => '')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->test_installed($element, $error, (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . $reqd_template . '/' : $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row[$element . '_name'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row[$element . '_name'] = $reqd_template;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Merge other information to installcfg... if present
|
|
|
4c79b5 |
$cfg_file = $phpbb_root_path . 'styles/' . $install_path . '/' . $element . '/' . $element . '.cfg';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (file_exists($cfg_file))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cfg_contents = parse_cfg_file($cfg_file);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Merge only specific things. We may need them later.
|
|
|
4c79b5 |
foreach (array('inherit_from', 'parse_css_file') as $key)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!empty($cfg_contents[$key]) && !isset($installcfg[$key]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$installcfg[$key] = $cfg_contents[$key];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$this->test_installed('template', $error, $root_path, false, $style_row['template_id'], $style_row['template_name'], $style_row['template_copyright']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$this->test_installed('theme', $error, $root_path, false, $style_row['theme_id'], $style_row['theme_name'], $style_row['theme_copyright']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$this->test_installed('imageset', $error, $root_path, false, $style_row['imageset_id'], $style_row['imageset_name'], $style_row['imageset_copyright']);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_row['store_db'] = request_var('store_db', 0);
|
|
|
4c79b5 |
$style_row['style_active'] = request_var('style_active', 1);
|
|
|
4c79b5 |
$style_row['style_default'] = request_var('style_default', 0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// User has submitted form and no errors have occurred
|
|
|
4c79b5 |
if ($update && !sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($element_ary as $element => $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
${$element . '_root_path'} = (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . ${'reqd_' . $element} . '/' : false;
|
|
|
4c79b5 |
${$element . '_path'} = (${'reqd_' . $element}) ? ${'reqd_' . $element} : false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$this->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row, $template_root_path, $template_path, $theme_root_path, $theme_path, $imageset_root_path, $imageset_path);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row['store_db'] = $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright'], $style_row['store_db']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$message = ($style_row['store_db']) ? '_ADDED_DB' : '_ADDED';
|
|
|
4c79b5 |
trigger_error($user->lang[$l_type . $message] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'INSTALL_' . $l_type;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_DETAILS' => true,
|
|
|
4c79b5 |
'S_INSTALL' => true,
|
|
|
4c79b5 |
'S_ERROR_MSG' => (sizeof($error)) ? true : false,
|
|
|
4c79b5 |
'S_LOCATION' => (isset($installcfg['inherit_from']) && $installcfg['inherit_from']) ? false : true,
|
|
|
4c79b5 |
'S_STYLE' => ($mode == 'style') ? true : false,
|
|
|
4c79b5 |
'S_TEMPLATE' => ($mode == 'template') ? true : false,
|
|
|
4c79b5 |
'S_SUPERTEMPLATE' => (isset($installcfg['inherit_from'])) ? $installcfg['inherit_from'] : '',
|
|
|
4c79b5 |
'S_THEME' => ($mode == 'theme') ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0,
|
|
|
4c79b5 |
'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0,
|
|
|
4c79b5 |
'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . "&action=install&path=" . urlencode($install_path),
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_NAME' => $user->lang[$l_type . '_NAME'],
|
|
|
4c79b5 |
'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '',
|
|
|
4c79b5 |
'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($error)) ? implode(' ', $error) : '',
|
|
|
4c79b5 |
'NAME' => $style_row[$mode . '_name'],
|
|
|
4c79b5 |
'COPYRIGHT' => $style_row[$mode . '_copyright'],
|
|
|
4c79b5 |
'TEMPLATE_NAME' => ($mode == 'style') ? $style_row['template_name'] : '',
|
|
|
4c79b5 |
'THEME_NAME' => ($mode == 'style') ? $style_row['theme_name'] : '',
|
|
|
4c79b5 |
'IMAGESET_NAME' => ($mode == 'style') ? $style_row['imageset_name'] : '')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Add new style
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function add($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
$element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE);
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$style_row = array(
|
|
|
4c79b5 |
$mode . '_name' => utf8_normalize_nfc(request_var('name', '', true)),
|
|
|
4c79b5 |
$mode . '_copyright' => utf8_normalize_nfc(request_var('copyright', '', true)),
|
|
|
4c79b5 |
'template_id' => 0,
|
|
|
4c79b5 |
'theme_id' => 0,
|
|
|
4c79b5 |
'imageset_id' => 0,
|
|
|
4c79b5 |
'store_db' => request_var('store_db', 0),
|
|
|
4c79b5 |
'style_active' => request_var('style_active', 1),
|
|
|
4c79b5 |
'style_default' => request_var('style_default', 0),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$basis = request_var('basis', 0);
|
|
|
4c79b5 |
$update = (isset($_POST['update'])) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($basis)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'style':
|
|
|
4c79b5 |
$sql_select = 'template_id, theme_id, imageset_id';
|
|
|
4c79b5 |
$sql_from = STYLES_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_select = 'template_id';
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_select = 'theme_id';
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_select = 'imageset_id';
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT $sql_select
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id = $basis";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['NO_' . $l_type];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row['template_id'] = (isset($row['template_id'])) ? $row['template_id'] : $style_row['template_id'];
|
|
|
4c79b5 |
$style_row['theme_id'] = (isset($row['theme_id'])) ? $row['theme_id'] : $style_row['theme_id'];
|
|
|
4c79b5 |
$style_row['imageset_id'] = (isset($row['imageset_id'])) ? $row['imageset_id'] : $style_row['imageset_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row['template_id'] = request_var('template_id', $style_row['template_id']);
|
|
|
4c79b5 |
$style_row['theme_id'] = request_var('theme_id', $style_row['theme_id']);
|
|
|
4c79b5 |
$style_row['imageset_id'] = request_var('imageset_id', $style_row['imageset_id']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style' && (!$style_row['template_id'] || !$style_row['theme_id'] || !$style_row['imageset_id']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_NO_IDS'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// User has submitted form and no errors have occurred
|
|
|
4c79b5 |
if ($update && !sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row['style_id'] = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->install_style($error, 'add', '', $style_row['style_id'], $style_row['style_name'], '', $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cache->destroy('sql', STYLES_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$message = ($style_row['store_db']) ? '_ADDED_DB' : '_ADDED';
|
|
|
4c79b5 |
trigger_error($user->lang[$l_type . $message] . adm_back_link($this->u_action));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'style')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($element_ary as $element => $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT {$element}_id, {$element}_name
|
|
|
4c79b5 |
FROM $table
|
|
|
4c79b5 |
ORDER BY {$element}_id ASC";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
${$element . '_options'} = '';
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$selected = ($row[$element . '_id'] == $style_row[$element . '_id']) ? ' selected="selected"' : '';
|
|
|
4c79b5 |
${$element . '_options'} .= '<option value="' . $row[$element . '_id'] . '"' . $selected . '>' . $row[$element . '_name'] . '</option>';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->page_title = 'ADD_' . $l_type;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$template->assign_vars(array(
|
|
|
4c79b5 |
'S_DETAILS' => true,
|
|
|
4c79b5 |
'S_ADD' => true,
|
|
|
4c79b5 |
'S_ERROR_MSG' => (sizeof($error)) ? true : false,
|
|
|
4c79b5 |
'S_STYLE' => ($mode == 'style') ? true : false,
|
|
|
4c79b5 |
'S_TEMPLATE' => ($mode == 'template') ? true : false,
|
|
|
4c79b5 |
'S_THEME' => ($mode == 'theme') ? true : false,
|
|
|
4c79b5 |
'S_BASIS' => ($basis) ? true : false,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'S_STORE_DB' => (isset($style_row['storedb'])) ? $style_row['storedb'] : 0,
|
|
|
4c79b5 |
'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0,
|
|
|
4c79b5 |
'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0,
|
|
|
4c79b5 |
'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '',
|
|
|
4c79b5 |
'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '',
|
|
|
4c79b5 |
'S_IMAGESET_OPTIONS' => ($mode == 'style') ? $imageset_options : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'U_ACTION' => $this->u_action . '&action=add&basis=' . $basis,
|
|
|
4c79b5 |
'U_BACK' => $this->u_action,
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
|
4c79b5 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
|
4c79b5 |
'L_NAME' => $user->lang[$l_type . '_NAME'],
|
|
|
4c79b5 |
'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '',
|
|
|
4c79b5 |
'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'ERROR_MSG' => (sizeof($error)) ? implode(' ', $error) : '',
|
|
|
4c79b5 |
'NAME' => $style_row[$mode . '_name'],
|
|
|
4c79b5 |
'COPYRIGHT' => $style_row[$mode . '_copyright'])
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false;
|
|
|
4c79b5 |
$reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false;
|
|
|
4c79b5 |
$reqd_imageset = (isset($installcfg['required_imageset'])) ? $installcfg['required_imageset'] : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check to see if each element is already installed, if it is grab the id
|
|
|
4c79b5 |
foreach ($element_ary as $element => $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$style_row = array_merge($style_row, array(
|
|
|
4c79b5 |
$element . '_id' => 0,
|
|
|
4c79b5 |
$element . '_name' => '',
|
|
|
4c79b5 |
$element . '_copyright' => '')
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->test_installed($element, $error, $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright']);
|
|
|
4c79b5 |
* Is this element installed? If not, grab its cfg details
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function test_installed($element, &$error, $root_path, $reqd_name, &$id, &$name, &$copyright)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($element)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_element = strtoupper($element);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$chk_name = ($reqd_name !== false) ? $reqd_name : $name;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$element}_id, {$element}_name
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$element}_name = '" . $db->sql_escape($chk_name) . "'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$name = $row[$element . '_name'];
|
|
|
4c79b5 |
$id = $row[$element . '_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!($cfg = @file("$root_path$element/$element.cfg")))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang['REQUIRES_' . $l_element], $reqd_name);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cfg = parse_cfg_file("$root_path$element/$element.cfg", $cfg);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$name = $cfg['name'];
|
|
|
4c79b5 |
$copyright = $cfg['copyright'];
|
|
|
4c79b5 |
$id = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
unset($cfg);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Install/Add style
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function install_style(&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false, $imageset_root_path = false, $imageset_path = false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $config, $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$element_ary = array('template', 'theme', 'imageset');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_STYLE_NAME'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check length settings
|
|
|
4c79b5 |
if (utf8_strlen($name) > 30)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_NAME_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (utf8_strlen($copyright) > 60)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_COPY_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check if the name already exist
|
|
|
4c79b5 |
$sql = 'SELECT style_id
|
|
|
4c79b5 |
FROM ' . STYLES_TABLE . "
|
|
|
4c79b5 |
WHERE style_name = '" . $db->sql_escape($name) . "'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_NAME_EXIST'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($element_ary as $element)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Zero id value ... need to install element ... run usual checks
|
|
|
4c79b5 |
// and do the install if necessary
|
|
|
4c79b5 |
if (!$style_row[$element . '_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->install_element($element, $error, $action, (${$element . '_root_path'}) ? ${$element . '_root_path'} : $root_path, $style_row[$element . '_id'], $style_row[$element . '_name'], (${$element . '_path'}) ? ${$element . '_path'} : $path, $style_row[$element . '_copyright']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$style_row['template_id'] || !$style_row['theme_id'] || !$style_row['imageset_id'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang['STYLE_ERR_NO_IDS'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'style_name' => $name,
|
|
|
4c79b5 |
'style_copyright' => $copyright,
|
|
|
4c79b5 |
'style_active' => (int) $active,
|
|
|
4c79b5 |
'template_id' => (int) $style_row['template_id'],
|
|
|
4c79b5 |
'theme_id' => (int) $style_row['theme_id'],
|
|
|
4c79b5 |
'imageset_id' => (int) $style_row['imageset_id'],
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'INSERT INTO ' . STYLES_TABLE . '
|
|
|
4c79b5 |
' . $db->sql_build_array('INSERT', $sql_ary);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$id = $db->sql_nextid();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($default)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
|
4c79b5 |
SET user_style = $id
|
|
|
4c79b5 |
WHERE user_style = " . $config['default_style'];
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('default_style', $id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('admin', 'LOG_STYLE_ADD', $name);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Install/add an element, doing various checks as we go
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright, $store_db = 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we parse the cfg here (again)
|
|
|
4c79b5 |
$cfg_data = parse_cfg_file("$root_path$mode/$mode.cfg");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_STYLE_NAME'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check length settings
|
|
|
4c79b5 |
if (utf8_strlen($name) > 30)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_NAME_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (utf8_strlen($copyright) > 60)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_COPY_LONG'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Check if the name already exist
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_name = '" . $db->sql_escape($name) . "'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// If it exist, we just use the style on installation
|
|
|
4c79b5 |
if ($action == 'install')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$id = $row[$mode . '_id'];
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error[] = $user->lang[$l_type . '_ERR_NAME_EXIST'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "'
|
|
|
4c79b5 |
AND {$mode}_inherits_id = 0";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
if (!$row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = sprintf($user->lang[$l_type . '_ERR_REQUIRED_OR_INCOMPLETE'], $cfg_data['inherit_from']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$inherit_id = $row["{$mode}_id"];
|
|
|
4c79b5 |
$inherit_path = $row["{$mode}_path"];
|
|
|
4c79b5 |
$cfg_data['store_db'] = $row["{$mode}_storedb"];
|
|
|
4c79b5 |
$store_db = $row["{$mode}_storedb"];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$inherit_id = 0;
|
|
|
4c79b5 |
$inherit_path = '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
$mode . '_name' => $name,
|
|
|
4c79b5 |
$mode . '_copyright' => $copyright,
|
|
|
4c79b5 |
$mode . '_path' => $path,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
// We check if the template author defined a different bitfield
|
|
|
4c79b5 |
if (!empty($cfg_data['template_bitfield']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary['bbcode_bitfield'] = TEMPLATE_BITFIELD;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We set a pre-defined bitfield here which we may use further in 3.2
|
|
|
4c79b5 |
$sql_ary += array(
|
|
|
4c79b5 |
'template_storedb' => $store_db,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary += array(
|
|
|
4c79b5 |
'template_inherits_id' => $inherit_id,
|
|
|
4c79b5 |
'template_inherit_path' => $inherit_path,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
// We are only interested in the theme configuration for now
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($cfg_data['parse_css_file']) && $cfg_data['parse_css_file'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$store_db = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary += array(
|
|
|
4c79b5 |
'theme_storedb' => $store_db,
|
|
|
4c79b5 |
'theme_data' => ($store_db) ? $this->db_theme_data($sql_ary, false, $root_path) : '',
|
|
|
4c79b5 |
'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css")
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// all the heavy lifting is done later
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "INSERT INTO $sql_from
|
|
|
4c79b5 |
" . $db->sql_build_array('INSERT', $sql_ary);
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$id = $db->sql_nextid();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($mode == 'template' && $store_db)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$filelist = filelist("{$root_path}template", '', 'html');
|
|
|
4c79b5 |
$this->store_templates('insert', $id, $path, $filelist);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($mode == 'imageset')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cfg_data = parse_cfg_file("$root_path$mode/imageset.cfg");
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$imageset_definitions = array();
|
|
|
4c79b5 |
foreach ($this->imageset_keys as $topic => $key_array)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$imageset_definitions = array_merge($imageset_definitions, $key_array);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($cfg_data as $key => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strpos($value, '*') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (substr($value, -1, 1) === '*')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height) = explode('*', $value);
|
|
|
4c79b5 |
$image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height, $image_width) = explode('*', $value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_filename = $value;
|
|
|
4c79b5 |
$image_height = $image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strpos($key, 'img_') === 0 && $image_filename)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$key = substr($key, 4);
|
|
|
4c79b5 |
if (in_array($key, $imageset_definitions))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'image_name' => $key,
|
|
|
4c79b5 |
'image_filename' => str_replace('{PATH}', "styles/$path/imageset/", trim($image_filename)),
|
|
|
4c79b5 |
'image_height' => (int) $image_height,
|
|
|
4c79b5 |
'image_width' => (int) $image_width,
|
|
|
4c79b5 |
'imageset_id' => (int) $id,
|
|
|
4c79b5 |
'image_lang' => '',
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($cfg_data);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT lang_dir
|
|
|
4c79b5 |
FROM ' . LANG_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (@file_exists("$root_path$mode/{$row['lang_dir']}/imageset.cfg"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$cfg_data_imageset_data = parse_cfg_file("$root_path$mode/{$row['lang_dir']}/imageset.cfg");
|
|
|
4c79b5 |
foreach ($cfg_data_imageset_data as $image_name => $value)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (strpos($value, '*') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (substr($value, -1, 1) === '*')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height) = explode('*', $value);
|
|
|
4c79b5 |
$image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($image_filename, $image_height, $image_width) = explode('*', $value);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_filename = $value;
|
|
|
4c79b5 |
$image_height = $image_width = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strpos($image_name, 'img_') === 0 && $image_filename)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$image_name = substr($image_name, 4);
|
|
|
4c79b5 |
if (in_array($image_name, $imageset_definitions))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'image_name' => $image_name,
|
|
|
4c79b5 |
'image_filename' => $image_filename,
|
|
|
4c79b5 |
'image_height' => (int) $image_height,
|
|
|
4c79b5 |
'image_width' => (int) $image_width,
|
|
|
4c79b5 |
'imageset_id' => (int) $id,
|
|
|
4c79b5 |
'image_lang' => $row['lang_dir'],
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($cfg_data_imageset_data);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$log = ($store_db) ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS';
|
|
|
4c79b5 |
add_log('admin', $log, $name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Return store_db in case it had to be altered
|
|
|
4c79b5 |
return $store_db;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Checks downwards dependencies
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
* @param string $mode The element type to check - only template is supported
|
|
|
4c79b5 |
* @param int $id The template id
|
|
|
4c79b5 |
* @returns false if no component inherits, array with name, path and id for each subtemplate otherwise
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function check_inheritance($mode, $id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_inherits_id = " . (int) $id;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$names = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$names[$row["{$mode}_id"]] = array(
|
|
|
4c79b5 |
"{$mode}_id" => $row["{$mode}_id"],
|
|
|
4c79b5 |
"{$mode}_name" => $row["{$mode}_name"],
|
|
|
4c79b5 |
"{$mode}_path" => $row["{$mode}_path"],
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($names))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $names;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Checks upwards dependencies
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
* @param string $mode The element type to check - only template is supported
|
|
|
4c79b5 |
* @param int $id The template id
|
|
|
4c79b5 |
* @returns false if the component does not inherit, array with name, path and id otherwise
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function get_super($mode, $id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($mode)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'template':
|
|
|
4c79b5 |
$sql_from = STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'theme':
|
|
|
4c79b5 |
$sql_from = STYLES_THEME_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'imageset':
|
|
|
4c79b5 |
$sql_from = STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_inherits_id
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id = " . (int) $id;
|
|
|
4c79b5 |
$result = $db->sql_query_limit($sql, 1);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$super_id = $row["{$mode}_inherits_id"];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path
|
|
|
4c79b5 |
FROM $sql_from
|
|
|
4c79b5 |
WHERE {$mode}_id = " . (int) $super_id;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query_limit($sql, 1);
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Moves a template set and its subtemplates to the database
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
* @param string $mode The component to move - only template is supported
|
|
|
4c79b5 |
* @param int $id The template id
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function store_in_db($mode, $id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
if ($super = $this->get_super($mode, $id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name']));
|
|
|
4c79b5 |
return $error;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path
|
|
|
4c79b5 |
FROM " . STYLES_TEMPLATE_TABLE . '
|
|
|
4c79b5 |
WHERE template_id = ' . (int) $id;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query_limit($sql, 1);
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
$subs = $this->check_inheritance($mode, $id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->_store_in_db($mode, $id, $row["{$mode}_path"]);
|
|
|
4c79b5 |
if ($subs && sizeof($subs))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($subs as $sub_id => $sub)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($err = $this->_store_in_db($mode, $sub["{$mode}_id"], $sub["{$mode}_path"]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = $err;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $error;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Moves a template set to the database
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
* @param string $mode The component to move - only template is supported
|
|
|
4c79b5 |
* @param int $id The template id
|
|
|
4c79b5 |
* @param string $path TThe path to the template files
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _store_in_db($mode, $id, $path)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$filelist = filelist("{$phpbb_root_path}styles/{$path}/template", '', 'html');
|
|
|
4c79b5 |
$this->store_templates('insert', $id, $path, $filelist);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Okay, we do the query here -shouldn't be triggered often.
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . '
|
|
|
4c79b5 |
SET template_storedb = 1
|
|
|
4c79b5 |
WHERE template_id = ' . $id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Moves a template set and its subtemplates to the filesystem
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access public
|
|
|
4c79b5 |
* @param string $mode The component to move - only template is supported
|
|
|
4c79b5 |
* @param int $id The template id
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function store_in_fs($mode, $id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $user;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
$l_type = strtoupper($mode);
|
|
|
4c79b5 |
if ($super = $this->get_super($mode, $id))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name']));
|
|
|
4c79b5 |
return($error);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path
|
|
|
4c79b5 |
FROM " . STYLES_TEMPLATE_TABLE . '
|
|
|
4c79b5 |
WHERE template_id = ' . (int) $id;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query_limit($sql, 1);
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
if (!sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$subs = $this->check_inheritance($mode, $id);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$this->_store_in_fs($mode, $id, $row["{$mode}_path"]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($subs && sizeof($subs))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($subs as $sub_id => $sub)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->_store_in_fs($mode, $sub["{$mode}_id"], $sub["{$mode}_path"]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$this->store_in_db($id, $mode);
|
|
|
4c79b5 |
return $error;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Moves a template set to the filesystem
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @access private
|
|
|
4c79b5 |
* @param string $mode The component to move - only template is supported
|
|
|
4c79b5 |
* @param int $id The template id
|
|
|
4c79b5 |
* @param string $path The path to the template
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _store_in_fs($mode, $id, $path)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $db, $user, $safe_mode;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$store_db = 0;
|
|
|
4c79b5 |
$error = array();
|
|
|
4c79b5 |
if (!$safe_mode && @is_writable("{$phpbb_root_path}styles/{$path}/template"))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $id";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!($fp = @fopen("{$phpbb_root_path}styles/{$path}/template/" . $row['template_filename'], 'wb')))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$store_db = 1;
|
|
|
4c79b5 |
$error[] = $user->lang['EDIT_TEMPLATE_STORED_DB'];
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
fwrite($fp, $row['template_data']);
|
|
|
4c79b5 |
fclose($fp);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$store_db)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . "
|
|
|
4c79b5 |
WHERE template_id = $id";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
if (sizeof($error))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return $error;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . '
|
|
|
4c79b5 |
SET template_storedb = 0
|
|
|
4c79b5 |
WHERE template_id = ' . $id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|