) * e.g. (:publishfaq Main.DemoFAQ1Data:) * * * - A path to the WikiPage that contains the list of Qs and As for the FAQ * * Dependencies: * PmWiki v2.x * * Version History * --------------- * [15 April 2006] - 0.1 initial release */ #Markup('publishfaq', '<_begin', // uncomment to see the source Markup('publishfaq', '<[[<<]]', '/\\(:[p|P]ublish[f|F][A|a][Q|q] +(.+)\\s*:\\)/e', "PublishFAQ('$1')"); //++ // Details: The main function // Args: $PagePath - Path to faq page // Return: Formatted FAQ page ready to be rendered by the PmWiki engine //-- function PublishFAQ($PagePath) { $lf = chr(10); $WikiCrLf = "[[<<]]"; $FAQData = PublishFAQGetWholePage($PagePath); $TOCStyle = 'faqtoc'; $QTitle = 'Questions'; $ATitle = 'Answers'; #! #! Extract FAQ Properties #! if( preg_match('/\\(TOC-Style:\\s*(.+):\\)/i', $FAQData, $match) ) { $TOCStyle = $match[1]; } if( preg_match('/\\(Q-Title:\\s*(.+):\\)/i', $FAQData, $match) ) { $QTitle = $match[1]; } if( preg_match('/\\(A-Title:\\s*(.+):\\)/i', $FAQData, $match) ) { $ATitle = $match[1]; } #! #! Get all the Q&As into an array #! $NumQuestions = preg_match_all('/\\[Q:\\s*(.*?):\\]/s', $FAQData, $Question); $NumAnswers = preg_match_all('/\\[A:\\s*(.*?):\\]/s', $FAQData, $Answer); if( $NumQuestions != $NumAnswers || $NumQuestions + $NumAnswers == 0 ) { return "$lf $WikiCrLf $WikiCrLf {+PublishFAQ:+}$WikiCrLf The number of questions and answers are zero or not equal to eachother. $WikiCrLf Click to [[edit -> $PagePath?action=edit]] or [[view -> $PagePath]] the data."; } #! #! Create the initial FAQ table of contents #! $out = "![[#$QTitle]]$QTitle:"; $out .= "$lf(:div class='$TOCStyle':)" . $WikiCrLf; for( $i=0; $i<$NumQuestions; $i++ ) { $Q = trim( $Question[1][$i] ); $Num = $i + 1; $out .= $lf; $out .= "'''[[ #Q".$QTitle."$Num | $Num. $Q ]]'''$WikiCrLf"; } $out .= $WikiCrLf . "$lf(:divend:)" . $WikiCrLf; $out .= $lf . "!$ATitle:"; #! #! Create the bookmarked list of Qs and As #! for( $i=0; $i<$NumQuestions; $i++ ) { $Q = trim( $Question[1][$i] ); $A = trim( $Answer[1][$i] ); $Num = $i + 1; # the Question: $out .= $WikiCrLf . "$lf(:div class='$TOCStyle' style='padding: 0':)"; $out .= "[[#Q".$QTitle."$Num]]$lf:: :'''Q: $Q''' [['-'^(^)^'-' -> #$QTitle]] $WikiCrLf"; $out .= "$lf(:divend:)"; # then the Answer $out .= "$lf:: :'''A:''' $A $WikiCrLf"; } # restart markup rule sequence PRR(); return $out; } //++ // Details: Extracts WikiContent out of a WikiPage // Args: $PagePath - Path to WikiPage to be extracted // Return: WikiPage content as a string //-- function PublishFAQGetWholePage($PagePath) { $page = ReadPage( $PagePath, READPAGE_CURRENT ); $ReturnData = $page['text']; # handle html special chars such as '<', '>', '&' $ReturnData = htmlspecialchars($ReturnData, ENT_NOQUOTES); # treat blank lines as <:vspace> $ReturnData = PVS($ReturnData); return $ReturnData; }