move code up one directory
[atutor.git] / include / classes / ContentOutputUtils.class.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                       */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                */
12 /****************************************************************/
13 // $Id: $
14
15 //This code is not being used. Place holder for some utilities to fix the [code] blocks
16 //in the visual html editor.
17
18 define("PATTERN", "/<\/p>[\W]*<p>/");
19 define("REPLACE", "\n");
20 define("CODESTART", "[code]");
21 define("CODEEND", "[/code]");
22
23 class ContentOutputUtils {
24     /**
25      * Recursive function which strips </p><p> tags from between [code] tags and
26      * replaces them with line feeds
27      *
28      * @param string $text
29      * @return string
30      */
31     public function stripPtags($text) {
32         $codestart = strpos($text, CODESTART);
33         if ($codestart == FALSE) {
34             return $text;
35         }
36         else {
37             $codestart += strlen(CODESTART);
38             $firstpart = substr($text, 0, $codestart);
39              
40             $codeend = strpos($text, CODEEND) + strlen(CODEEND);
41             $lastpart = substr($text, $codeend);
42
43             $codetext = substr($text, $codestart, $codeend - $codestart);
44             $newcodetext = preg_replace(PATTERN, REPLACE, $codetext);
45             $result = $firstpart.$newcodetext.$this->stripPtags($lastpart);
46         }
47         return $result;
48     }
49 }
50 ?>