Fox Auth User Comment Box
Summary: Posting comments for logged in users only, using Fox Version: 2011-12-23 Prerequisites: fox.php, foxdelete.php, authuser.php Status: Maintainer: HansB? Categories: Fox Security CMS Forms
Questions answered by this recipe
How to add comments for logged in users only, using Fox
Description
This is an example for setting up a comment form for posting comments for logged in users only, using Fox and AuthUser
Installation
Prerequisites: install Cookbook:AuthUser, Cookbook:Fox and Cookbook:FoxDelete. Add following to config.php, $FoxPagePermissions should be set for the group or page in which comments should be posted (in this example it is for all pages in group Test):
include_once("scripts/authuser.php"); if ($AuthId) { $Author = $AuthId; setcookie('author',$Author,0,'/'); } include_once("$FarmD/scripts/author.php"); Conditions['authuser'] = '\$GLOBALS["AuthId"]==\$condparm'; $FoxPagePermissions['Test.*'] = 'add,delete'; include_once("$FarmD/cookbook/fox/fox.php"); include_once("$FarmD/cookbook/fox/foxdelete.php");
Configuration
Page Site.AuthUser should be configured with user ids and their passwords, or users and passwords set up in a different way.
Add to Site.FoxForms this Fox comment form code:
[[#commentform]] (:foxmessage:) (:fox cbox put=below mark=!!Comments template=Site.FoxTemplates#comment:) Subject: (:input text heading size=60:) '''Your Comment:''' (:input textarea comment cols=60 rows=6:) (:input hidden author value='{$AuthId}' :) (:input submit post "Add Comment":) (:foxend cbox:) [[#commentformend]]
Add to Site.FoxTemplates this comment template:
[[#comment]] #foxbegin# (:div1 class=messagehead:) >>rfloat<< [-{$$(date d.m.Y - H:i)}-] (:if expr auth admin or authuser {$$author}:){[foxdelrange]}(:if:) >><< !!!!!{$$author} (:div1end:) >>messageitem<< '''{$$heading}''' >>messageitem<< {$$comment} >><< #foxend# [[#commentend]]
Add to each page or the GroupHeader (or GroupFooter) this markup for the comment form:
(:if authid:)Logged in as '''{$AuthId}''' - [-[[{*$FullName}?action=logout| (log out)]]-] (:foxform Site.FoxForms#commentform :) (:else:)Please [[{*$FullName}?action=login|log in]] to add comment! (:ifend:) !!Comments
Add to pub/css/local.css some styles (taken from CommentBoxPlus? styles css):
/* styling of commentbox entries */ #message { clear:both; } .messagehead, .journalhead { margin:1em 0 0 0; padding:0 0 0 3px; border:1px solid #ccc; } .messageitem, .journalitem { margin:0; padding:3px; border-left:1px solid #ccc; border-right:1px solid #ccc; border-bottom:1px solid #ccc; } .messagehead { background:#f0f0f0; } /*use the following if message head should be same as message item */ /* .messagehead { background:#eef; border-bottom:none; } */ .messageitem { background:#f7f7f7; }
Notes
- The comment box form is set up for use with AuthUser?.
- It has no author field, as author is set via login with the AuthId of
the user.
- You need to log in to see the comment form.
- The delete link will only show for the logged in user's posts, and
for the admin (logged in as admin).
- You may wish to tighten security by making sure only logged in users are allowed to post, but not allowed to fully edit pages. Follow instructions for AddingAuthLevels?
Usage
Change log / Release notes
- 2011-12-23: initial write up
See also
Contributors
Comments
See discussion at FoxAuthUserCommentBox-Talk?