summaryrefslogtreecommitdiff
path: root/forum/utils/parser.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-11 10:55:28 +0000
committerdeva <deva>2008-10-11 10:55:28 +0000
commit07882614bfd402132d2f8df23cc23c2c013b5f14 (patch)
treec66a6cd2ce98d04921882176e90a2226c7db5350 /forum/utils/parser.php
parentf6d90d8d3504fc1ba428da81e77c4484c4646f30 (diff)
Did a lot of work on the imagecache, and the filehandler. Now both are functional, and used indirectly throught index.php, thus requiering login for access.
Diffstat (limited to 'forum/utils/parser.php')
-rw-r--r--forum/utils/parser.php93
1 files changed, 37 insertions, 56 deletions
diff --git a/forum/utils/parser.php b/forum/utils/parser.php
index e857c7e..b5a80b7 100644
--- a/forum/utils/parser.php
+++ b/forum/utils/parser.php
@@ -7,6 +7,7 @@ include_once($UTIL_DIR . "/smileys.php");
// strtr
// ereg_replace
// str_replace
+// error_reporting
//
function parse($input, $indent = "")
@@ -28,23 +29,32 @@ function parse($input, $indent = "")
$output = $smile;
}
- // Insert images
- $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/s", "IMAGE$1EGAMI", $output);
+ // Find a unique symbols for image start and end markers
+ $imgstartsymbol = "A";
+ $imgstartmarker = $imgstartsymbol;
+ while(strpos($output, $imgstartmarker)) $imgstartmarker .= $imgstartsymbol;
+
+ $imgendsymbol = "B";
+ $imgendmarker = $imgendsymbol;
+ while(strpos($output, $imgendmarker)) $imgendmarker .= $imgendsymbol;
+
+ // Find and mark image URLs (so that they don't get converted into normal <a/> links)
+ $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/", $imgstartmarker."$1".$imgendmarker, $output);
// Replace URLs with <a></a> tags
$output = preg_replace("/http:\/\/(.*?)([\n ])/s", "<a href=\"http://$1\">$1</a>$2", $output);
- // Finish inserting images
- $output = preg_replace("/IMAGE(.*?)EGAMI/s", "<img alt=\"$1\" src=\"imagecache.php?filename=$1\"/>", $output);
+ // Convert marked images to img tags and links
+ $output = preg_replace("/".$imgstartmarker."(.*?)".$imgendmarker."/s", "<a href=\"http://$1\"><img alt=\"$1\" src=\"?mode=imagecache&amp;uri=http://$1\"/></a>", $output);
// Replace [quote title=...]...[/quote]
- $urls = "";
+ $urls = "";
while(($start = strpos($output, "[quote"))) {
- $pre = substr($output, 0, $start);
- $url = substr($output, $start);
- $end = strpos($url, "[/quote]") + strlen("[/quote]");
- $url = substr($url, 0, $end - strlen("[/quote]"));
- $post = substr($output, $start + $end + strlen("[/quote]") );
+ $pre = substr($output, 0, $start);
+ $url = substr($output, $start);
+ $end = strpos($url, "[/quote]") + strlen("[/quote]");
+ $url = substr($url, 0, $end - strlen("[/quote]"));
+ $post = substr($output, $start + $end + strlen("[/quote]") );
$header = substr($url, 0, strpos($url, "]") + 1);
$body = substr($url, strpos($url, "]") + 1);
@@ -54,17 +64,17 @@ function parse($input, $indent = "")
$header = str_replace(array("[quote"), "<div class=\"quote\">", $header);
$header = str_replace(array("]"), " </div>", $header);
- $urls .= $pre . $header . $body . "</div>";
- $output = $post;
+ $urls .= $pre . $header . $body . "</div>";
+ $output = $post;
}
- $urls .= $output;
- $output = $urls;
+ $urls .= $output;
+ $output = $urls;
//
// Hack to make quotes two levels deep.
//
// Replace [quote title=...]...[/quote]
- $urls = "";
+ $urls = "";
while(($start = strpos($output, "[quote"))) {
$pre = substr($output, 0, $start);
$url = substr($output, $start);
@@ -83,48 +93,19 @@ function parse($input, $indent = "")
$urls .= $pre . $header . $body . "</div>";
$output = $post;
}
- $urls .= $output;
- $output = $urls;
-
- $search = array(
- '/\[b\](.*?)\[\/b\]/is',
- '/\[i\](.*?)\[\/i\]/is',
- '/\[u\](.*?)\[\/u\]/is',
- '/\[img\](.*?)\[\/img\]/is',
- '/\[url\](.*?)\[\/url\]/is',
- '/\[url\=(.*?)\](.*?)\[\/url\]/is'
- );
-
- $replace = array(
- '<strong>$1</strong>',
- '<em>$1</em>',
- '<u>$1</u>',
- '<img src="$1" />',
- '<a href="$1">$1</a>',
- '<a href="$1">$2</a>'
- );
-
- $output = preg_replace ($search, $replace, $output);
- /*
- // <b></b>
- $b = array("[b]", "[B]");
- $b = str_replace($b, "<strong>", $output);
- $output = $b;
-
- $b = array("[/b]", "[/B]");
- $b = str_replace($b, "</strong>", $output);
- $output = $b;
-
- // <i></i>
- $i = array("[i]", "[I]");
- $i = str_replace($i, "<em>", $output);
- $output = $i;
-
- $i = array("[/i]", "[/i]");
- $i = str_replace($i, "</em>", $output);
- $output = $i;
- */
+ $urls .= $output;
+ $output = $urls;
+
+ $search = array('/\[b\](.*?)\[\/b\]/is',
+ '/\[i\](.*?)\[\/i\]/is',
+ '/\[u\](.*?)\[\/u\]/is');
+
+ $replace = array('<strong>$1</strong>',
+ '<em>$1</em>',
+ '<u>$1</u>');
+ $output = preg_replace ($search, $replace, $output);
+
// Replace newlines with <br/> tags
$nls = array("\n");
$nls = str_replace($nls, "<br/>\n", $output);