系统实际上不支持您要求的内容,但您可以使用以下设置:
创建一个内容插件(
http://docs.joomla.org/J2.5:Creating_a_content_plugin)。在onContentPrepareForm事件中,您可以修改created_by_alias字段,以便将其用于允许查看此内容文章的特殊用户。
function onContentPrepareForm($form, $data){
$form->getField('created_by_alias')->__set('type', 'user');
}
在 onContentPrepareData 事件中,检查 created_by_alias 中的数据是否引用了您的用户应该属于的用户组中的有效用户。
public function onContentPrepare($context, $article, $params, $page){
// first check that context is right
//Then fetch the user data:
if(is_int($article->created_by_alias)){ // ( Optionally check if the article is in a specific category )
$db=JFactory::getDbo();
$currentuser=JFactory::getUser();
$allowedgroup=2; // the registered users group
$sql="select u.id from #__users inner join #__user_usergroup_map ug (u.id=ug.user_id) where ug.group_id={$allowedgroup}";
$db->setQuery($sql);
$user=$db->loadObject();
if($user->id==$currentuser){
$data->user=$user;
}
else{
//Unset the article content to prevent unothorized users from seeing the content.
unset($article);
}
}
最后,创建一个模块(
http://docs.joomla.org/Creating_a_simple_module),为特定用户提供文章,至少包含以下内容:
$list=array();
$user=Jfactory::getUser();
if($user->id>0){
$sql="select * from #__content where created_by_alias={$user->id}";
$db=Jfactory::getDbo();
$db->setQuery($sql);
$list=$db->loadObjectList();
if(!count($list)) return;
}
else return;
print_r($list);
这个方案应该保护未经授权的用户无法查看为特定用户准备的文章内容。模块应该在漂亮地输出所需显示内容后,为已登录的用户展示文章列表。该模块可以按照正常方式链接到文章,授权用户将能够访问。因此,它应该是“足够安全”的,并提供您需要的功能而不会带来太多麻烦。