From d7735d2587e68bab42fde8753ee733de76369f72 Mon Sep 17 00:00:00 2001
From: Meik Sievertsen <acydburn@phpbb.com>
Date: Sun, 8 Feb 2004 18:02:17 +0000
Subject: inline attachment capability...

git-svn-id: file:///svn/phpbb/trunk@4819 89ea8834-ac86-4346-8a33-228a782c2dd0
---
 phpBB/includes/message_parser.php | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

(limited to 'phpBB/includes/message_parser.php')

diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index ec3f4cd841..bfd50c54cb 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -165,6 +165,7 @@ class parse_message
 		$this->bbcodes = array(
 			'code'		=>	array('bbcode_id' => 8, 'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#ise' => "\$this->bbcode_code('\$1', '\$2')")),
 			'quote'		=>	array('bbcode_id' => 0, 'regexp' => array('#\[quote(?:=&quot;(.*?)&quot;)?\](.+)\[/quote\]#ise' => "\$this->bbcode_quote('\$0')")),
+			'attachment'=>	array('bbcode_id' => 12, 'regexp' => array('#\[attachment=([0-9]+)\](.*?)\[/attachment\]#ise' => "\$this->bbcode_attachment('\$1', '\$2')")),
 			'b'			=>	array('bbcode_id' => 1, 'regexp' => array('#\[b\](.*?)\[/b\]#is' => '[b:' . $this->bbcode_uid . ']$1[/b:' . $this->bbcode_uid . ']')),
 			'i'			=>	array('bbcode_id' => 2, 'regexp' => array('#\[i\](.*?)\[/i\]#is' => '[i:' . $this->bbcode_uid . ']$1[/i:' . $this->bbcode_uid . ']')),
 			'url'		=>	array('bbcode_id' => 3, 'regexp' => array('#\[url=?(.*?)?\](.*?)\[/url\]#ise' => "\$this->validate_url('\$1', '\$2')")),
@@ -200,6 +201,12 @@ class parse_message
 		}
 	}
 
+	function bbcode_attachment($stx, $in)
+	{
+		$out = '[attachment=' . $stx . ':' . $this->bbcode_uid . ']<!-- ia' . $stx . ' -->' . $in . '<!-- ia' . $stx . ' -->[/attachment:' . $this->bbcode_uid . ']';
+		return $out;
+	}
+
 	// Expects the argument to start right after the opening [code] tag and to end with [/code]
 	function bbcode_code($stx, $in)
 	{
@@ -673,7 +680,8 @@ class parse_message
 
 	function parse_attachments($mode, $post_id, $submit, $preview, $refresh)
 	{
-		global $config, $_FILES, $_POST, $auth, $user;
+		global $config, $auth, $user;
+		global $_FILES, $_POST;
 
 		$error = array();
 
@@ -708,6 +716,8 @@ class parse_message
 					);
 
 					$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
+					$this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
+					
 					$this->filename_data['filecomment'] = '';
 
 					// This Variable is set to false here, because Attachments are entered into the
@@ -750,7 +760,8 @@ class parse_message
 				}
 				
 				unset($this->attachment_data[$index]);
-				
+				$this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "(\\1 == \$index) ? '' : ((\\1 > \$index) ? '[attachment=' . (\\1 - 1) . ']\\2[/attachment]' : '\\0')", $this->message);
+
 				// Reindex Array
 				$this->attachment_data = array_values($this->attachment_data);
 			}
@@ -789,6 +800,7 @@ class parse_message
 							);
 
 							$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
+							$this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
 							$this->filename_data['filecomment'] = '';
 						}
 					}
-- 
cgit v1.2.1