CFDBShortCodeContentParser

"Contact Form to Database" Copyright (C) 2011-2013 Michael Simpson (email : michael.d.simpson@gmail.com).

Defined (1)

The class is defined in the following location(s).

/CFDBShortCodeContentParser.php  
  1. class CFDBShortCodeContentParser { 
  2.  
  3. const BEFORE_START_DELIMITER = '{{BEFORE}}'; 
  4. const BEFORE_END_DELIMITER = '{{/BEFORE}}'; 
  5.  
  6. const AFTER_START_DELIMITER = '{{AFTER}}'; 
  7. const AFTER_END_DELIMITER = '{{/AFTER}}'; 
  8.  
  9. /** 
  10. * @param $content string 
  11. * @return array[$before, $template, $after] 
  12. */ 
  13. public function parseBeforeContentAfter($content) { 
  14. $before = null; 
  15. $startDelimiter = self::BEFORE_START_DELIMITER; 
  16. $endDelimiter = self::BEFORE_END_DELIMITER; 
  17. $startDelimiterStartPos = strpos($content, $startDelimiter); 
  18. $endDelimiterStartPos = strpos($content, $endDelimiter); 
  19. if ($startDelimiterStartPos !== false && 
  20. $endDelimiterStartPos !== false && 
  21. $startDelimiterStartPos < $endDelimiterStartPos) { 
  22. $startDelimiterEndPos = $startDelimiterStartPos + strlen($startDelimiter); 
  23. $endDelimiterEndPos = $endDelimiterStartPos + strlen($endDelimiter); 
  24. $before = substr($content, $startDelimiterEndPos, $endDelimiterStartPos - $startDelimiterEndPos); 
  25. $content = substr($content, $endDelimiterEndPos, strlen($content) - $startDelimiterEndPos); 
  26.  
  27. $after = null; 
  28. $startDelimiter = self::AFTER_START_DELIMITER; 
  29. $endDelimiter = self::AFTER_END_DELIMITER; 
  30. $startDelimiterStartPos = strpos($content, $startDelimiter); 
  31. $endDelimiterStartPos = strpos($content, $endDelimiter); 
  32. if ($startDelimiterStartPos !== false && 
  33. $endDelimiterStartPos !== false && 
  34. $startDelimiterStartPos < $endDelimiterStartPos) { 
  35. $startDelimiterEndPos = $startDelimiterStartPos + strlen($startDelimiter); 
  36. $after = substr($content, $startDelimiterEndPos, $endDelimiterStartPos - $startDelimiterEndPos); 
  37. $content = substr($content, 0, $startDelimiterStartPos); 
  38.  
  39. return array($before, $content, $after); 
  40.