我正在尝试在现有论坛上创建一个新论坛。我可以很容易地创建新论坛并从管理控制台查看它。问题是我需要它也显示在前端以供用户使用。这是通过权限完成的。
因此,我试图做的是将父论坛(公共(public))的权限复制到我创建的论坛。然而,该论坛似乎仍然没有出现在面向公众的一面。
这是我的代码(请注意之前已经加载了 phpBB 包含文件):
// $forum_name = name of the new forum
// $parent_id = the forum which this is a child of
function create_forum($forum_name, $parent_id)
{
global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;
$response = array();
$data = array(
'forum_name' => $forum_name,
);
// Forum info
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_build_array('SELECT', $data);
$result = $db->sql_query($sql);
$forum_id = (int) $db->sql_fetchfield('forum_id');
$db->sql_freeresult($result);
if ($forum_id)
{
$response['error'] = TRUE;
$response['error_msg'] = 'FORUM_EXISTS';
$response['forum_id'] = $forum_id;
}
else
{
$forum_data = array(
'parent_id' => $parent_id,
'left_id' => 0,
'right_id' => 0,
'forum_parents' => '',
'forum_name' => $data['forum_name'],
'forum_desc' => '',
'forum_desc_bitfield' => '',
'forum_desc_options' => 7,
'forum_desc_uid' => '',
'forum_link' => '',
'forum_password' => '',
'forum_style' => 0,
'forum_image' => '',
'forum_rules' => '',
'forum_rules_link' => '',
'forum_rules_bitfield' => '',
'forum_rules_options' => 7,
'forum_rules_uid' => '',
'forum_topics_per_page' => 0,
'forum_type' => 1,
'forum_status' => 0,
'forum_posts' => 0,
'forum_topics' => 0,
'forum_topics_real' => 0,
'forum_last_post_id' => 0,
'forum_last_poster_id' => 0,
'forum_last_post_subject' => '',
'forum_last_post_time' => 0,
'forum_last_poster_name' => '',
'forum_last_poster_colour' => '',
'forum_flags' => 32,
'display_on_index' => FALSE,
'enable_indexing' => TRUE,
'enable_icons' => FALSE,
'enable_prune' => FALSE,
'prune_next' => 0,
'prune_days' => 7,
'prune_viewed' => 7,
'prune_freq' => 1,
);
$sql = 'SELECT MAX(right_id) AS right_id
FROM ' . FORUMS_TABLE;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$forum_data['left_id'] = $row['right_id'] + 1;
$forum_data['right_id'] = $row['right_id'] + 2;
// And as last, a insert query
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data);
$db->sql_query($sql);
$forum_data['forum_id'] = $db->sql_nextid();
// successful result
$response['error'] = FALSE;
$response['error_msg'] = '';
$response['forum_id'] = $forum_data['forum_id'];
/* PERMISSIONS ----------------------------------------------- */
// copy permissions from parent forum
$forum_perm_from = $parent_id;
///////////////////////////
// COPY USER PERMISSIONS //
///////////////////////////
// Copy permisisons from/to the acl users table (only forum_id gets changed)
$sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_USERS_TABLE . '
WHERE forum_id = ' . $forum_perm_from;
$result = $db->sql_query($sql);
$users_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$users_sql_ary[] = array(
'user_id' => (int) $row['user_id'],
'forum_id' => $forum_data['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
////////////////////////////
// COPY GROUP PERMISSIONS //
////////////////////////////
// Copy permisisons from/to the acl groups table (only forum_id gets changed)
$sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_GROUPS_TABLE . '
WHERE forum_id = ' . $forum_perm_from;
$result = $db->sql_query($sql);
$groups_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$groups_sql_ary[] = array(
'group_id' => (int) $row['group_id'],
'forum_id' => $forum_data['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
//////////////////////////////////
// INSERT NEW FORUM PERMISSIONS //
//////////////////////////////////
$db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
$db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
$auth->acl_clear_prefetch();
return $response;
}
}
最佳答案
function create_forum($forum_name, $parent_id)
{
global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix;
$response = array();
$data = array(
'forum_name' => $forum_name,
);
// Forum info
$sql = 'SELECT forum_id
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_build_array('SELECT', $data);
$result = $db->sql_query($sql);
$forum_id = (int) $db->sql_fetchfield('forum_id');
$db->sql_freeresult($result);
if ($forum_id)
{
$response['error'] = TRUE;
$response['error_msg'] = 'FORUM_EXISTS';
$response['forum_id'] = $forum_id;
}
else
{
$forum_data = array(
'parent_id' => $parent_id,
'left_id' => 0,
'right_id' => 0,
'forum_parents' => '',
'forum_name' => $data['forum_name'],
'forum_desc' => '',
'forum_desc_bitfield' => '',
'forum_desc_options' => 7,
'forum_desc_uid' => '',
'forum_link' => '',
'forum_password' => '',
'forum_style' => 0,
'forum_image' => '',
'forum_rules' => '',
'forum_rules_link' => '',
'forum_rules_bitfield' => '',
'forum_rules_options' => 7,
'forum_rules_uid' => '',
'forum_topics_per_page' => 0,
'forum_type' => 1,
'forum_status' => 0,
'forum_posts' => 0,
'forum_topics' => 0,
'forum_topics_real' => 0,
'forum_last_post_id' => 0,
'forum_last_poster_id' => 0,
'forum_last_post_subject' => '',
'forum_last_post_time' => 0,
'forum_last_poster_name' => '',
'forum_last_poster_colour' => '',
'forum_flags' => 32,
'display_on_index' => FALSE,
'enable_indexing' => TRUE,
'enable_icons' => FALSE,
'enable_prune' => FALSE,
'prune_next' => 0,
'prune_days' => 7,
'prune_viewed' => 7,
'prune_freq' => 1,
);
/**
/*Changed the code from here
/*Pulled straight from acl_forums.php from line 973 to line 1002
/*Removed lines 980 -> 989
/*Changed $forum_data_sql['parent_id']; line 975 to $parent_id
/*Changed $forum_data_sql on lines 1001, 1002 to $forum_data
**/
$sql = 'SELECT left_id, right_id, forum_type
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $parent_id;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET left_id = left_id + 2, right_id = right_id + 2
WHERE left_id > ' . $row['right_id'];
$db->sql_query($sql);
$sql = 'UPDATE ' . FORUMS_TABLE . '
SET right_id = right_id + 2
WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
$db->sql_query($sql);
$forum_data['left_id'] = $row['right_id'];
$forum_data['right_id'] = $row['right_id'] + 1;
// And as last, a insert query
$sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data);
$db->sql_query($sql);
$forum_data['forum_id'] = $db->sql_nextid();
// successful result
$response['error'] = FALSE;
$response['error_msg'] = '';
$response['forum_id'] = $forum_data['forum_id'];
/* PERMISSIONS ----------------------------------------------- */
// copy permissions from parent forum
$forum_perm_from = $parent_id;
///////////////////////////
// COPY USER PERMISSIONS //
///////////////////////////
// Copy permisisons from/to the acl users table (only forum_id gets changed)
$sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_USERS_TABLE . '
WHERE forum_id = ' . $forum_perm_from;
$result = $db->sql_query($sql);
$users_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$users_sql_ary[] = array(
'user_id' => (int) $row['user_id'],
'forum_id' => $forum_data['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
////////////////////////////
// COPY GROUP PERMISSIONS //
////////////////////////////
// Copy permisisons from/to the acl groups table (only forum_id gets changed)
$sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
FROM ' . ACL_GROUPS_TABLE . '
WHERE forum_id = ' . $forum_perm_from;
$result = $db->sql_query($sql);
$groups_sql_ary = array();
while ($row = $db->sql_fetchrow($result))
{
$groups_sql_ary[] = array(
'group_id' => (int) $row['group_id'],
'forum_id' => $forum_data['forum_id'],
'auth_option_id' => (int) $row['auth_option_id'],
'auth_role_id' => (int) $row['auth_role_id'],
'auth_setting' => (int) $row['auth_setting']
);
}
$db->sql_freeresult($result);
//////////////////////////////////
// INSERT NEW FORUM PERMISSIONS //
//////////////////////////////////
$db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
$db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
$auth->acl_clear_prefetch();
print_r($response);
return $response;
}
}
关于php - 从 PHP 和设置权限在 phpBB3 中创建论坛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258296/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我有一个正在构建的应用程序,我需要一个模型来创建另一个模型的实例。我希望每辆车都有4个轮胎。汽车模型classCar轮胎模型classTire但是,在make_tires内部有一个错误,如果我为Tire尝试它,则没有用于创建或新建的activerecord方法。当我检查轮胎时,它没有这些方法。我该如何补救?错误是这样的:未定义的方法'create'forActiveRecord::AttributeMethods::Serialization::Tire::Module我测试了两个环境:测试和开发,它们都因相同的错误而失败。 最佳答案
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
我正在尝试找出如何为我的Ruby项目创建一种“无类DSL”,类似于在Cucumber步骤定义文件中定义步骤定义或在Sinatra应用程序中定义路由。例如,我想要一个文件,其中调用了我的所有DSL函数:#sample.rbwhen_string_matches/hello(.+)/do|name|call_another_method(name)end我认为用我的项目特有的一堆方法污染全局(内核)命名空间是一种不好的做法。因此方法when_string_matches和call_another_method将在我的库中定义,并且sample.rb文件将以某种方式在我的DSL方法的上下文中
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
有这些railscast。http://railscasts.com/episodes/218-making-generators-in-rails-3有了这个,你就会知道如何创建样式表和脚手架生成器。http://railscasts.com/episodes/216-generators-in-rails-3通过这个,您可以了解如何添加一些文件来修改脚手架View。我想把两者结合起来。我想创建一个生成器,它也可以创建脚手架View。有点像RyanBates漂亮的生成器或web_app_themegem(https://github.com/pilu/web-app-theme)。我
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Rubysyntaxquestion:Rational(a,b)andRational.new!(a,b)我正在阅读ruby镐书,我对创建有理数的语法感到困惑。Rational(3,4)*Rational(1,2)产生=>3/8为什么Rational不需要new方法(我还注意到例如我可以在没有new方法的情况下创建字符串)?