/** * * Name: UserComments * Desc: Append User Comments to any Document * Created by Raymond Irving, July 2005 * * Version: 1.1 * Updated: December 8, 2005 * * Changes: * Dec 8, 05 - Fixed ability to specify the comments to display (remote show via passing in &docid) by modx@vertexworks.com * * Parameters: * &displaytpl - display template (chunk name) * &formtpl - form template (chunk name) * * &canpost - comma delimitted web groups that can post comments. leave blank for public posting * &canview - comma delimitted web groups that can view comments. leave blank for public viewing * &badwords - comma delimited list of words not allowed in post * &makefolder - set to 1 to automatically convert the parent document to a folder. Defaults to 0 * &folder - folder id where comments are stored * &docid - document id to use where comments are stored ... use for "remote comment displays" * &tagid - a unique id used to identify or tag user comments on a page where multiple comments are required. * &freeform - set this option to 1 to use the [+UserComments.Form+] placholder to relocate the comment form. * * &postcss - sets the css class used to format the comment block DIV * &titlecss - sets the css class used to format the comment title DIV * &codecss - sets the css class used to format code tags * &numbecss - sets the css class used to format the comment number DIV * &authorcss - sets the css class used identify author's comments * &ownercss - sets the css class used identify the owner's comments * &altrowcss - sets the css class used identify author's comments * * &dateformat - sets php date format for new comments (see http://php.net/strftime for formatting options) * &sortorder - sort the comments in either ascending order (when set to 0) or descending order (when set to 1). Defaults to descending (1) * &recentposts - set the number of recent posts to be displayed. set to 0 to show all post. Defaults to 0 * */ // redirect to host document if an attempt was // made to display the document containing the comments if(isset($hostid)) { $url = $modx->makeUrl($hostid); $modx->sendRedirect($url); exit; } // set to true to echo out variables before the comment block for troubleshooting $debug = false; // get user groups that can post & view comments $postgrp = isset($canpost) ? explode(",",$canpost):array(); $viewgrp = isset($canview) ? explode(",",$canview):array(); $allowAnyPost = count($postgrp)==0 ? true : false; $allowAnyView = count($viewgrp)==0 ? true : false; // get current document id (if set, show-only mode) $docid = isset($docid) ? intval($docid):$modx->documentIdentifier; // get folder id where we should store comments // else store in current document $folder = isset($folder) ? intval($folder):$docid; // get free form option $freeform = isset($freeform) && $freeform==1 ? 1:0; // get tagid $tagid = isset($tagid) ? preg_replace("/[^A-z0-9_\-]/",'',$tagid):''; // set alias name of document used to store comments $alias = 'usrcmt-'.$docid.($tagid ? '-'.$tagid:''); // get sort order $sortorder = isset($sortorder) ? $sortorder : 1; // get comment block style/class $postcss = isset($postcss) ? ' class="'.$postcss.'[+altrowclass+][+authorclass+]"' : ' style="font-size:11px;line-height: 17px;white-space:normal;width:100%;background-color:#eee;color: #111;padding:5px;margin-bottom:10px;" class="[+altrowclass+][+authorclass+]"'; // get post title class $titlecss = isset($titlecss) ? ' class="'.$titlecss.'"' : ' style="width:100%;background-color:#c0c0c0;padding:2px;margin-bottom:5px;"'; // get post number class $numbercss = isset($numbercss) ? ' class="'.$numbercss.'"' : ' style="float:right; padding: 0 0 20px 20px;font-size:24px;color:#ccc;font-weight:bold;"'; // get code style/class $codecss = isset($codecss) ? ' class="'.$codecss.'"' : ' style="background-color:#eee;border-top:2px solid #e0e0e0;margin:0;"'; // get author class $authorcss = isset($authorcss) ? ' '.$authorcss : ''; // get owner's class $ownercss = isset($ownercss) ? ' '.$ownercss : ''; // get alt row style/class $altrowcss = isset($altrowcss) ? ' '.$altrowcss : ''; // get date format $dateformat = isset($dateformat) ? $dateformat : '%e%b%Y %I:%M%p'; // set recent post value $recentposts = isset($recentposts) ? $recentposts : 0; // get badwords if(isset($badwords)) { $badwords = str_replace(' ','', $badwords); $badwords = "/".str_replace(',','|', $badwords)."/i"; } // set splitter $splitter = ''; // get postback status $isPostBack = isset($_POST['UserCommentForm'.$tagid]) ? true:false; // get display template if(isset($displaytpl)) $displayTpl = $modx->getChunk($displaytpl); if(empty($displaytpl)) $displayTpl = ' [+UID:[+uid+]+]