Advertisement
choctaw

xslt on Linux server

Apr 9th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. function: getForm establishes parameters: form[.xsl], [contactForm.xml] and array of parameters for xsl file
  2.  
  3. $param = 'contactform [form: action parameter]'
  4.  
  5. public function getForm($param) {
  6. $paramArray = explode(' ',$param);
  7. if ($_POST['runon'] == 'end') {
  8. if (self::checkValid()) return "<p><strong>".self::sendMail()."</strong></p>\r";
  9. else return self::getXMLData('xmlData')->emailFail;
  10. }
  11. else {
  12. if (!$form = $_POST['runon']) $form = $paramArray[0];
  13. $code = self::keyCode();
  14. $postArray = array();
  15. if ($_POST) $postArray = $_POST['mail'];
  16. $postArray['destination'] = $paramArray[1].".php";
  17. $postArray['cipher'] = $code[0];
  18. $postArray['code'] = $code[1];
  19. $postArray['timestamp'] = time();
  20. }
  21. return self::xmlTransform('form',$form,$postArray);
  22. }
  23.  
  24. function: xmlTransform returns the output from xslt
  25.  
  26. public function xmlTransform($xsl,$xml,$postArray) {
  27. $style = new DOMDocument;
  28. $style->load('data/'.$xsl.'.xsl');
  29. $source = new DOMDocument;
  30. $source->load('data/'.$xml.'.xml');
  31. $proc = new XSLTProcessor();
  32. $proc->registerPHPFunctions();
  33. $proc->importStylesheet($style);
  34. $transformData = array($proc,$source);
  35. foreach ($postArray as $key => $value) {
  36. $transformData[0]->setParameter('',$key,$value);
  37. }
  38. return $transformData[0]->transformToXML($transformData[1]);
  39. }
  40.  
  41. function: getMenu creates navigation menu for page using menu.xsl and menu.xml
  42.  
  43. public function getMenu($param) {
  44. $postArray = array (
  45. 'trunk' => $param,
  46. 'status' => self::checkLogin('session'),
  47. 'pageid' => PAGEID
  48. );
  49. return self::xmlTransform('menu','menu',$postArray);
  50. }
  51.  
  52. function: sendMail compiles emails from form submission
  53.  
  54. $_POST['form'] = xml filename prefix
  55. $text = output from xslt on mail.xsl and contactForm.xml
  56. $output replaces form: name fields with their values got from form submission
  57.  
  58. public function sendMail() {
  59. $headers = "X-Mailer: PHP v".phpversion()."\r\n".
  60. "Content-Type: text/plain; charset=utf-8\r\n".
  61. "Return-Path: ".self::getXMLData('xmlData')->emailReturn."\r\n".
  62. "From: ".self::getXMLData('xmlData')->webmaster."\r\n".
  63. "Reply-to: ".self::getXMLData('xmlData')->webmaster."\r\n";
  64.  
  65. $subject = self::cleanInput($_POST['subject'],40);
  66. $form = self::cleanInput($_POST['form'],40);
  67. $to = self::getXMLData('xmlData')->webmaster;
  68. $postArray = array ('subject' => $subject);
  69. $text = self::xmlTransform('mail',$form,$postArray);
  70. $output = preg_replace('/\|~(\w+)~\|/e','$_POST[$1]',$text);
  71. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement