mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
ok, i am very sorry, but this needs to be fixed.
Generally, our config table is not really suited for holding large datasets. Because feed settings for the forums to enable news feeds and excluded forums rely on the forums itself we have decided to introduce a forum_options table where custom options can be stored. Additionally, for this to work across all DBMS we support, we added a new method to the DBAL for the bitwise AND operator. Also moved the forum/topic feed template variable to the location where they belong to (forum and topic view) git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9965 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -272,8 +272,8 @@ class acp_board
|
||||
'feed_overall_topics_limit' => array('lang' => 'ACP_FEED_OVERALL_TOPIC_LIMIT', 'validate' => 'int:5', 'type' => 'text:3:4', 'explain' => false),
|
||||
'feed_forum' => array('lang' => 'ACP_FEED_FORUM', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true ),
|
||||
'feed_topic' => array('lang' => 'ACP_FEED_TOPIC', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true ),
|
||||
'feed_news_id' => array('lang' => 'ACP_FEED_NEWS', 'validate' => 'string', 'type' => 'select_multiple', 'method' => 'select_news_forums', 'explain' => true ),
|
||||
'feed_exclude_id' => array('lang' => 'ACP_FEED_EXCLUDE_ID', 'validate' => 'string', 'type' => 'select_multiple', 'method' => 'select_exclude_forums', 'explain' => true),
|
||||
'feed_news_id' => array('lang' => 'ACP_FEED_NEWS', 'validate' => 'string', 'type' => 'custom', 'method' => 'select_news_forums', 'explain' => true),
|
||||
'feed_exclude_id' => array('lang' => 'ACP_FEED_EXCLUDE_ID', 'validate' => 'string', 'type' => 'custom', 'method' => 'select_exclude_forums', 'explain' => true),
|
||||
)
|
||||
);
|
||||
break;
|
||||
@@ -440,35 +440,16 @@ class acp_board
|
||||
// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
|
||||
foreach ($display_vars['vars'] as $config_name => $null)
|
||||
{
|
||||
if (strpos($config_name, 'legend') !== false)
|
||||
if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($config_name == 'auth_method')
|
||||
if ($config_name == 'auth_method' || $config_name == 'feed_news_id' || $config_name == 'feed_exclude_id')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// It could happen that the cfg array is not set. This happens within feed settings if unselecting all forums in the multiple select fields for example (it is the same as checkbox handling)
|
||||
if (!isset($cfg_array[$config_name]))
|
||||
{
|
||||
$cfg_array[$config_name] = '';
|
||||
}
|
||||
|
||||
// Erm, we spotted an array
|
||||
if ($null['type'] == 'select_multiple' && $submit && isset($_REQUEST['config'][$config_name]))
|
||||
{
|
||||
// Get config *array*
|
||||
$cfg_ = utf8_normalize_nfc(request_var('config', array('' => array('')), true));
|
||||
|
||||
// Check if the variable is set and an array
|
||||
if (isset($cfg_[$config_name]) && is_array($cfg_[$config_name]))
|
||||
{
|
||||
$cfg_array[$config_name] = trim(serialize($cfg_[$config_name]));
|
||||
}
|
||||
}
|
||||
|
||||
$this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
|
||||
|
||||
if ($config_name == 'email_function_name')
|
||||
@@ -484,6 +465,13 @@ class acp_board
|
||||
}
|
||||
}
|
||||
|
||||
// Store news and exclude ids
|
||||
if ($mode == 'feed' && $submit)
|
||||
{
|
||||
$this->store_feed_forums(FORUM_OPTION_FEED_NEWS, 'feed_news_id');
|
||||
$this->store_feed_forums(FORUM_OPTION_FEED_EXCLUDE, 'feed_exclude_id');
|
||||
}
|
||||
|
||||
if ($mode == 'auth')
|
||||
{
|
||||
// Retrieve a list of auth plugins and check their config values
|
||||
@@ -902,17 +890,17 @@ class acp_board
|
||||
{
|
||||
global $user, $config;
|
||||
|
||||
// Determine ids to be selected
|
||||
$select_ids = (sizeof($value)) ? $value : false;
|
||||
|
||||
$forum_list = make_forum_select($select_ids, false, true, true, true, false, true);
|
||||
$forum_list = make_forum_select(false, false, true, true, true, false, true);
|
||||
|
||||
// Build forum options
|
||||
$s_forum_options = '';
|
||||
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
|
||||
foreach ($forum_list as $f_id => $f_row)
|
||||
{
|
||||
$f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_NEWS, $f_row['forum_options']);
|
||||
|
||||
$s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
|
||||
}
|
||||
$s_forum_options .= '</select>';
|
||||
|
||||
return $s_forum_options;
|
||||
}
|
||||
@@ -921,20 +909,48 @@ class acp_board
|
||||
{
|
||||
global $user, $config;
|
||||
|
||||
// Determine ids to be selected
|
||||
$select_ids = (sizeof($value)) ? $value : false;
|
||||
|
||||
$forum_list = make_forum_select($select_ids, false, true, false, false, false, true);
|
||||
$forum_list = make_forum_select(false, false, true, false, false, false, true);
|
||||
|
||||
// Build forum options
|
||||
$s_forum_options = '';
|
||||
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
|
||||
foreach ($forum_list as $f_id => $f_row)
|
||||
{
|
||||
$f_row['selected'] = phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $f_row['forum_options']);
|
||||
|
||||
$s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
|
||||
}
|
||||
$s_forum_options .= '</select>';
|
||||
|
||||
return $s_forum_options;
|
||||
}
|
||||
|
||||
function store_feed_forums($option, $key)
|
||||
{
|
||||
global $db, $cache;
|
||||
|
||||
// Get key
|
||||
$values = request_var($key, array(0 => 0));
|
||||
|
||||
// Empty option bit for all forums
|
||||
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
||||
SET forum_options = forum_options - ' . (1 << $option) . '
|
||||
WHERE ' . $db->sql_bit_and('forum_options', $option, '<> 0');
|
||||
$db->sql_query($sql);
|
||||
|
||||
// Already emptied for all...
|
||||
if (sizeof($values))
|
||||
{
|
||||
// Set for selected forums
|
||||
$sql = 'UPDATE ' . FORUMS_TABLE . '
|
||||
SET forum_options = forum_options + ' . (1 << $option) . '
|
||||
WHERE ' . $db->sql_in_set('forum_id', $values);
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
// Empty sql cache for forums table because options changed
|
||||
$cache->destroy('sql', FORUMS_TABLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -93,6 +93,10 @@ define('FORUM_FLAG_ACTIVE_TOPICS', 16);
|
||||
define('FORUM_FLAG_POST_REVIEW', 32);
|
||||
define('FORUM_FLAG_QUICK_REPLY', 64);
|
||||
|
||||
// Forum Options... sequential order. Modifications should begin at number 10 (number 29 is maximum)
|
||||
define('FORUM_OPTION_FEED_NEWS', 1);
|
||||
define('FORUM_OPTION_FEED_EXCLUDE', 2);
|
||||
|
||||
// Optional text flags
|
||||
define('OPTION_FLAG_BBCODE', 1);
|
||||
define('OPTION_FLAG_SMILIES', 2);
|
||||
|
@@ -411,6 +411,24 @@ class dbal
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run binary AND operator on DB column.
|
||||
* Results in sql statement: "{$column_name} & (1 << {$bit}) {$compare}"
|
||||
*
|
||||
* @param string $column_name The column name to use
|
||||
* @param int $bit The value to use for the AND operator, will be converted to (1 << $bit). Is used by options, using the number schema... 0, 1, 2...29
|
||||
* @param string $compare Any custom SQL code after the check (for example "= 0")
|
||||
*/
|
||||
function sql_bit_and($column_name, $bit, $compare = '')
|
||||
{
|
||||
if (method_exists($this, '_sql_bit_and'))
|
||||
{
|
||||
return $this->_sql_bit_and($column_name, $bit, $compare);
|
||||
}
|
||||
|
||||
return $column_name . ' & ' . (1 << $bit) . (($compare) ? ' ' . $compare : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run more than one insert statement.
|
||||
*
|
||||
|
@@ -446,6 +446,11 @@ class dbal_firebird extends dbal
|
||||
return $data;
|
||||
}
|
||||
|
||||
function _sql_bit_and($column_name, $bit, $compare = '')
|
||||
{
|
||||
return 'BIN_AND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
|
@@ -568,6 +568,11 @@ class dbal_oracle extends dbal
|
||||
return $data;
|
||||
}
|
||||
|
||||
function _sql_bit_and($column_name, $bit, $compare = '')
|
||||
{
|
||||
return 'BITAND(' . $column_name . ', ' . (1 << $bit) . ')' . (($compare) ? ' ' . $compare : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* return sql error array
|
||||
* @access private
|
||||
|
@@ -3505,7 +3505,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
|
||||
$l_notify = '<p>Please notify the board administrator or webmaster: <a href="mailto:' . $config['board_contact'] . '">' . $config['board_contact'] . '</a></p>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (defined('DEBUG') || defined('IN_CRON') || defined('IMAGE_OUTPUT'))
|
||||
{
|
||||
// let's avoid loops
|
||||
@@ -3857,6 +3857,40 @@ function obtain_users_online_string($online_users, $item_id = 0, $item = 'forum'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get option bitfield from custom data
|
||||
*
|
||||
* @param int $bit The bit/value to get
|
||||
* @param int $data Current bitfield to check
|
||||
* @return bool Returns true if value of constant is set in bitfield, else false
|
||||
*/
|
||||
function phpbb_optionget($bit, $data)
|
||||
{
|
||||
return ($data & 1 << (int) $bit) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set option bitfield
|
||||
*
|
||||
* @param int $bit The bit/value to set/unset
|
||||
* @param bool $set True if option should be set, false if option should be unset.
|
||||
* @param int $data Current bitfield to change
|
||||
*
|
||||
* @return int The new bitfield
|
||||
*/
|
||||
function phpbb_optionset($bit, $set, $data)
|
||||
{
|
||||
if ($set && !($data & 1 << $bit))
|
||||
{
|
||||
$data += 1 << $bit;
|
||||
}
|
||||
else if (!$set && ($data & 1 << $bit))
|
||||
{
|
||||
$data -= 1 << $bit;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate page header
|
||||
@@ -3917,7 +3951,7 @@ function page_header($page_title = '', $display_online_list = true, $forum_id =
|
||||
* }
|
||||
* </code>
|
||||
*/
|
||||
|
||||
|
||||
if ($forum_id)
|
||||
{
|
||||
$item_id = max($forum_id, 0);
|
||||
@@ -3926,7 +3960,7 @@ function page_header($page_title = '', $display_online_list = true, $forum_id =
|
||||
{
|
||||
$item_id = 0;
|
||||
}
|
||||
|
||||
|
||||
// workaround legacy code
|
||||
$item = 'forum';
|
||||
$online_users = obtain_users_online($item_id, $item);
|
||||
@@ -4005,6 +4039,19 @@ function page_header($page_title = '', $display_online_list = true, $forum_id =
|
||||
$forum_id = request_var('f', 0);
|
||||
$topic_id = request_var('t', 0);
|
||||
|
||||
$s_feed_news = false;
|
||||
|
||||
// Get option for news
|
||||
if ($config['feed_enable'])
|
||||
{
|
||||
$sql = 'SELECT forum_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
|
||||
$result = $db->sql_query_limit($sql, 1, 0, 600);
|
||||
$s_feed_news = (int) $db->sql_fetchfield('forum_id');
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
// The following assigns all _common_ variables that may be used at any point in a template.
|
||||
$template->assign_vars(array(
|
||||
'SITENAME' => $config['sitename'],
|
||||
@@ -4082,11 +4129,9 @@ function page_header($page_title = '', $display_online_list = true, $forum_id =
|
||||
'S_TOPIC_ID' => $topic_id,
|
||||
|
||||
'S_ENABLE_FEEDS' => ($config['feed_enable']) ? true : false,
|
||||
'S_ENABLE_FEEDS_NEWS' => ($config['feed_news_id'] != '') ? true : false,
|
||||
'S_ENABLE_FEEDS_FORUMS' => ($config['feed_overall_forums']) ? true : false,
|
||||
'S_ENABLE_FEEDS_TOPICS' => ($config['feed_overall_topics']) ? true : false,
|
||||
'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_id && strpos($user->page['page_name'], 'viewforum') !== false) ? true : false,
|
||||
'S_ENABLE_FEEDS_TOPIC' => ($config['feed_topic'] && $topic_id && strpos($user->page['page_name'], 'viewtopic') !== false) ? true : false,
|
||||
'S_ENABLE_FEEDS_NEWS' => ($s_feed_news) ? true : false,
|
||||
|
||||
'T_THEME_PATH' => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme',
|
||||
'T_TEMPLATE_PATH' => "{$phpbb_root_path}styles/" . $user->theme['template_path'] . '/template',
|
||||
|
@@ -69,7 +69,7 @@ function make_forum_select($select_id = false, $ignore_id = false, $ignore_acl =
|
||||
$acl = ($ignore_acl) ? '' : (($only_acl_post) ? 'f_post' : array('f_list', 'a_forum', 'a_forumadd', 'a_forumdel'));
|
||||
|
||||
// This query is identical to the jumpbox one
|
||||
$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
|
||||
$sql = 'SELECT forum_id, forum_name, parent_id, forum_type, forum_flags, forum_options, left_id, right_id
|
||||
FROM ' . FORUMS_TABLE . '
|
||||
ORDER BY left_id ASC';
|
||||
$result = $db->sql_query($sql, 600);
|
||||
@@ -1364,15 +1364,15 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
|
||||
WHERE ' . $db->sql_in_set('topic_id', $topic_id_ary);
|
||||
$db->sql_query($sql);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
break;
|
||||
|
||||
case 'topic_approved':
|
||||
|
||||
|
||||
$db->sql_transaction('begin');
|
||||
switch ($db->sql_layer)
|
||||
{
|
||||
@@ -1409,15 +1409,15 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
$db->sql_query($sql);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
break;
|
||||
|
||||
case 'post_reported':
|
||||
$post_ids = $post_reported = array();
|
||||
|
||||
|
||||
$db->sql_transaction('begin');
|
||||
|
||||
|
||||
$sql = 'SELECT p.post_id, p.post_reported
|
||||
FROM ' . POSTS_TABLE . " p
|
||||
$where_sql
|
||||
@@ -1468,7 +1468,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
WHERE ' . $db->sql_in_set('post_id', $post_ids);
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
break;
|
||||
|
||||
@@ -1481,7 +1481,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
$topic_ids = $topic_reported = array();
|
||||
|
||||
$db->sql_transaction('begin');
|
||||
|
||||
|
||||
$sql = 'SELECT DISTINCT(t.topic_id)
|
||||
FROM ' . POSTS_TABLE . " t
|
||||
$where_sql_and t.post_reported = 1";
|
||||
@@ -1514,7 +1514,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
break;
|
||||
|
||||
@@ -1522,7 +1522,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
$post_ids = $post_attachment = array();
|
||||
|
||||
$db->sql_transaction('begin');
|
||||
|
||||
|
||||
$sql = 'SELECT p.post_id, p.post_attachment
|
||||
FROM ' . POSTS_TABLE . " p
|
||||
$where_sql
|
||||
@@ -1573,7 +1573,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
WHERE ' . $db->sql_in_set('post_id', $post_ids);
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
break;
|
||||
|
||||
@@ -1619,15 +1619,15 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'forum':
|
||||
|
||||
$db->sql_transaction('begin');
|
||||
|
||||
|
||||
// 1: Get the list of all forums
|
||||
$sql = 'SELECT f.*
|
||||
FROM ' . FORUMS_TABLE . " f
|
||||
@@ -1828,7 +1828,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
break;
|
||||
|
||||
@@ -1836,7 +1836,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
$topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array();
|
||||
|
||||
$db->sql_transaction('begin');
|
||||
|
||||
|
||||
$sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_last_post_id, t.topic_last_post_subject, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_poster_colour, t.topic_last_post_time
|
||||
FROM ' . TOPICS_TABLE . " t
|
||||
$where_sql";
|
||||
@@ -2160,7 +2160,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
|
||||
unset($topic_data);
|
||||
|
||||
$db->sql_transaction('commit');
|
||||
|
||||
|
||||
// if some topics have been resync'ed then resync parent forums
|
||||
// except when we're only syncing a range, we don't want to sync forums during
|
||||
// batch processing.
|
||||
|
Reference in New Issue
Block a user