Here it is. I’ll be putting it in the Repository when I get a chance.
Now, anything above the first Q: is rendered as is. Be sure to uncheck the rtf box when you save the content. Also, don’t put "EXTRA:" for the stuff at the top. You shouldn’t need the <div> around the content.
PS: some of your anchors are misnamed.
<?php
/*
Snippet: EZfaq
$Revision: 28 $
$Date: 2008-07-29 12:51:35 -0700 (Tue, 29 Jul 2008) $
Author: Bob Ray (based on an idea from SorenG JavaScript code from DynamicDrive.com)
Version: 1.0.5
Compatibility: MODX 0.9.6, 0.9.7
Thanks to: jaredc for suggestions on .css usage and cssPath parameter
cbaone for suggestions about inserting anchors
*/
/************************************************************
Usage (see readme.txt for installation information and usage)
-----
Minimal EZfaq call:
-------------------
[[EZfaq? &docID=`12`]]
(Use the document ID of your unpublished FAQ content document
-- NOT THE DOCUMENT THAT SHOWS THE FAQ --.)
&docID is required.
Optional parameters:
--------------------
&lang [Language for error messages and prompts - defaults to "en"]
&showHideAllOption [display the show/hide all buttons - default "true"]
&statusOpenHTML [symbol to put next to open topics (can be an image URL) - defaults to "[-]"]
&statusClosedHTML [symbol to put next to closed topics (can be an image URL) - defaults to "[+]"]
&openColor [color for open questions (name or hex value #ffffff) - default "red"]
&closedColor [color for closed questions (name or hex value #ffffff) - default "black"]
&setPersist [does open state persist across visits/reloads - default "true";]
&collapsePrevious [if set, only one answer can be open at a time - default "true"]
&defaultExpanded [expand answers n1 through n2 ("0,1" expands items 1 through 2)when page is opened (default, no)]
&cssPath [Optional Path to .css file -- set to `` for no .css file]
***************************************************/
$faqPath = "assets/snippets/ezfaq/"; // set path to resources (language file, .css, .js)
$error_message = ""; // initialize error message variable
/* ********************************************
Make sure we have what we need before proceding
***********************************************/
$lang = isset($lang)?$lang:'en'; // set default language
require_once $modx->config['base_path'].$faqPath."lang/".$lang.".inc.php"; // get the language file
if (!isset($docID)) { // user didn't send docID parameter
return $faq_lang['ezfaq-docID-required'];
}
$doc = $modx->getDocument((string)$docID, '*', 1); // Search published first.
if (empty($doc)) {
$doc = $modx->getDocument((string)$docID, '*', 0); // Un-published next?
}
if (empty($doc)) { // user requested a non-existing document
return $faq_lang['ezfaq-doc-not-found'];
}
/****************************************************************************************
Now that we have the language file and the document with the FAQ
content, we'll plug in the .css and .js and initialize the optional parameters.
*****************************************************************************************/
/* Inject .css file into document header - maybe.
Use $cssPath=`` if you want to put the .css in your site's .css file
rather than using a separate .css file for the FAQ
*/
if (isset($cssPath) ) { // user has set this parameter
if ($cssPath == "") {
// do nothing, user doesn't want a separate .css file
} else { // user has specified the .css file to use
$src = $cssPath;
$modx->regClientCSS($src);
}
} else { // not set, use the default .css file
$src = $faqPath."ezfaq.css";
$modx->regClientCSS($src);
}
// inject the .js into the document header.
$src = $faqPath."switchcontent.js";
$modx->regClientStartupScript($src);
//Show the buttons that show and hide all answers.
$showHideAllOption = isset($showHideAllOption)?$showHideAllOption:true;
// Set prefix markers for open and closed answers (can be string or an
// image URL). Defaults to plus and minus signs.
$statusOpenHTML = isset($statusOpenHTML)?$statusOpenHTML:"[-]";
$statusClosedHTML = isset($statusClosedHTML)?$statusClosedHTML:"[+]";
// Set colors for open and closed (applies to question; answer is styled in .css).
// can be color name or hex color value (#ffffff);
$openColor = isset($openColor)?$openColor:"red";
$closedColor = isset($closedColor)?$closedColor:"black";
// set whether state persists on return visits
$setPersist = isset($setPersist)?$setPersist:"true";
//when set to true, only one answer can be expanded at a time (default)
$collapsePrevious = isset($collapsePrevious)?$collapsePrevious:"true";
//expand answers n1 through n2 when page is opened (default, no)
// to set, use "0,2" to expand first three answers, "0" to expand just the first
$defaultExpanded = isset($defaultExpanded)?$defaultExpanded:"";
// Work starts here
//replace "EQUALS" in URLs with "="
$statusOpenHTML = str_replace("EQUALS","=",$statusOpenHTML);
$statusClosedHTML = str_replace("EQUALS","=",$statusClosedHTML);
$output = "";
$docString = $doc['content'];
if ($showHideAllOption) {
$output .= '<div class="faqExpand">';
$output .= '<p>'.$faq_lang['ezfaq-show-hide-msg'].'</p>';
$output .= '<a href="javascript:faq.sweepToggle('."'expand')".'"> '.$faq_lang['ezfaq-expand-button-msg'].' </a>';
$output .=' ';
$output .= '<a href="javascript:faq.sweepToggle('."'contract')".'"> '.$faq_lang['ezfaq-contract-button-msg'].' </a>';
$output .= '</div>';
}
$docArray = explode("Q:",$docString);
//$i = count($docArray);
// echo "count: ".$i.'<br>';
$itemCount=0; // used to make every id different
$output .= '<div class="faqContainer">'."\n";
foreach($docArray as $value) {
if ($itemCount==0) { // very first item (or pre first item)
if (!strstr($value,"A:")) { // no answer, assume it's before the beginning
$output .= $value; // send it out without processing
continue; // got to the next (first real item)
}
} else {
//normal item, continue
}
$items = explode("A:",$value);
if (stristr($items[0],"FAQ-END")) {
break;
}
if ( ($items[0] != "") && ($items[1] != "") ) {
$output .= '<p id="faq'.$itemCount.'-title" class="handcursor">';
$output .= '<span class="faqQuestion">';
$output .= $items[0];
$output .= '</span>';
$output .= '</p>';
$aArray = explode("Extra:",$items[1]);
$output .= '<div id="faq'.$itemCount.'" class="switchgroup1">';
//$output .= '<p class="faqAnswer">';
$output .= $aArray[0];
//$output .= '</p>';
$output .= '</div>';
if ($aArray[1] != "") {
$output .= $aArray[1];
}
}
$itemCount++;
}
$output .= '</div>'."\n"; // end of faqContainer div
// MAIN FUNCTION: new switchcontent("class name", "[optional_element_type_to_scan_for]") REQUIRED
//1) Instance.setStatus(openHTML, closedHTML)- Sets optional HTML to prefix the headers to indicate open/closed states
//2) Instance.setColor(openheaderColor, closedheaderColor)- Sets optional color of header when it's open/closed
//3) Instance.setPersist(true/false)- Enables or disabled session only persistence (recall contents' expand/contract states)
//4) Instance.collapsePrevious(true/false)- Sets whether previous content should be contracted when current one is expanded
//5) Instance.defaultExpanded(indices)- Sets contents that should be expanded by default (ie: 0, 1). Persistence feature overrides this setting!
//6) Instance.init() REQUIRED
$output .= '<script type="text/javascript">;'."\n";
$output .= 'var faq=new switchcontent("switchgroup1", "div");'."\n"; //Limit scanning of switch contents to just "div" elements
$output .= "faq.setStatus('".$statusOpenHTML." ','".$statusClosedHTML." ');"."\n"; // set open/closed indicators
$output .= 'faq.setColor("'.$openColor.'", "'.$closedColor.'");'."\n"; // set open/closed text colors
$output .= 'faq.setPersist('.$setPersist.');'."\n";
$output .= 'faq.collapsePrevious('.$collapsePrevious.');'."\n"; //Only one content open at any given time
$output .= 'faq.defaultExpanded("'.$defaultExpanded.'");'."\n"; // expand some on open?
$output .= 'faq.init();'."\n";
$output .= '</script>'."\n";
//$output .='<hr>'.$doc['content'];
return $output;
?>