Index: inc/public/class.dc.template.php
===================================================================
--- inc/public/class.dc.template.php	(revision 406)
+++ inc/public/class.dc.template.php	(revision 407)
@@ -54,18 +54,4 @@
 		$this->addValue('ArchiveEntriesCount',array($this,'ArchiveEntriesCount'));
 		$this->addValue('ArchiveURL',array($this,'ArchiveURL'));
-		
-		# Attachments
-		$this->addBlock('Attachments',array($this,'Attachments'));
-		$this->addBlock('AttachmentsHeader',array($this,'AttachmentsHeader'));
-		$this->addBlock('AttachmentsFooter',array($this,'AttachmentsFooter'));
-		$this->addValue('AttachmentMimeType',array($this,'AttachmentMimeType'));
-		$this->addValue('AttachmentType',array($this,'AttachmentType'));
-		$this->addValue('AttachmentFileName',array($this,'AttachmentFileName'));
-		$this->addValue('AttachmentSize',array($this,'AttachmentSize'));
-		$this->addValue('AttachmentTitle',array($this,'AttachmentTitle'));
-		$this->addValue('AttachmentThumbnailURL',array($this,'AttachmentThumbnailURL'));
-		$this->addValue('AttachmentURL',array($this,'AttachmentURL'));
-		$this->addBlock('AttachmentIf',array($this,'AttachmentIf'));
-		$this->addValue('MediaURL',array($this,'MediaURL'));
 		
 		# Blog
@@ -141,5 +127,4 @@
 		$this->addBlock('EntriesHeader',array($this,'EntriesHeader'));
 		$this->addValue('EntryExcerpt',array($this,'EntryExcerpt'));
-		$this->addValue('EntryAttachmentCount',array($this,'EntryAttachmentCount'));
 		$this->addValue('EntryAuthorCommonName',array($this,'EntryAuthorCommonName'));
 		$this->addValue('EntryAuthorDisplayName',array($this,'EntryAuthorDisplayName'));
@@ -749,173 +734,4 @@
 	}
 	
-	/* Attachments ---------------------------------------- */
-	/*dtd
-	<!ELEMENT tpl:Attachments - - -- Post Attachments loop -->
-	*/
-	public function Attachments($attr,$content)
-	{
-		$res =
-		"<?php\n".
-		'if ($_ctx->posts !== null && $core->media) {'."\n".
-			'$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id));'."\n".
-		"?>\n".
-		
-		'<?php foreach ($_ctx->attachments as $attach_i => $attach_f) : '.
-		'$GLOBALS[\'attach_i\'] = $attach_i; $GLOBALS[\'attach_f\'] = $attach_f;'.
-		'$_ctx->file_url = $attach_f->file_url; ?>'.
-		$content.
-		'<?php endforeach; $_ctx->attachments = null; unset($attach_i,$attach_f,$_ctx->file_url); ?>'.
-		
-		"<?php } ?>\n";
-		
-		return $res;
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentsHeader - - -- First attachments result container -->
-	*/
-	public function AttachmentsHeader($attr,$content)
-	{
-		return
-		"<?php if (\$attach_i == 0) : ?>".
-		$content.
-		"<?php endif; ?>";
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentsFooter - - -- Last attachments result container -->
-	*/
-	public function AttachmentsFooter($attr,$content)
-	{
-		return
-		"<?php if (\$attach_i+1 == count(\$_ctx->attachments)) : ?>".
-		$content.
-		"<?php endif; ?>";
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentsIf - - -- Test on attachment fields -->
-	<!ATTLIST tpl:AttachmentIf
-	is_image	(0|1)	#IMPLIED	-- test if attachment is an image (value : 1) or not (value : 0)
-	has_thumb	(0|1)	#IMPLIED	-- test if attachment has a square thumnail (value : 1) or not (value : 0)
-	is_mp3	(0|1)	#IMPLIED	-- test if attachment is a mp3 file (value : 1) or not (value : 0)
-	is_flv	(0|1)	#IMPLIED	-- test if attachment is a flv file (value : 1) or not (value : 0)
-	>
-	*/
-	public function AttachmentIf($attr,$content)
-	{
-		$if = array();
-		
-		$operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
-		
-		if (isset($attr['is_image'])) {
-			$sign = (boolean) $attr['is_image'] ? '' : '!';
-			$if[] = $sign.'$attach_f->media_image';
-		}
-		
-		if (isset($attr['has_thumb'])) {
-			$sign = (boolean) $attr['has_thumb'] ? '' : '!';
-			$if[] = $sign.'isset($attach_f->media_thumb[\'sq\'])';
-		}
-		
-		if (isset($attr['is_mp3'])) {
-			$sign = (boolean) $attr['is_mp3'] ? '==' : '!=';
-			$if[] = '$attach_f->type '.$sign.' "audio/mpeg3"';
-		}
-		
-		if (isset($attr['is_flv'])) {
-			$sign = (boolean) $attr['is_flv'] ? '' : '!';
-			$if[] = $sign.
-				'($attach_f->type == "video/x-flv" || '.
-				'$attach_f->type == "video/mp4" || '.
-				'$attach_f->type == "video/x-m4v")';
-		}
-		
-		if (!empty($if)) {
-			return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
-		} else {
-			return $content;
-		}
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentMimeType - O -- Attachment MIME Type -->
-	*/
-	public function AttachmentMimeType($attr)
-	{
-		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->type').'; ?>';
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentType - O -- Attachment type -->
-	*/
-	public function AttachmentType($attr)
-	{
-		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->media_type').'; ?>';
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentFileName - O -- Attachment file name -->
-	*/
-	public function AttachmentFileName($attr)
-	{
-		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->basename').'; ?>';
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentSize - O -- Attachment size -->
-	<!ATTLIST tpl:AttachmentSize
-	full	CDATA	#IMPLIED	-- if set, size is rounded to a human-readable value (in KB, MB, GB, TB)
-	>
-	*/
-	public function AttachmentSize($attr)
-	{
-		$f = $this->getFilters($attr);
-		if (!empty($attr['full'])) {
-			return '<?php echo '.sprintf($f,'$attach_f->size').'; ?>';
-		}
-		return '<?php echo '.sprintf($f,'files::size($attach_f->size)').'; ?>';
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentTitle - O -- Attachment title -->
-	*/
-	public function AttachmentTitle($attr)
-	{
-		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->media_title').'; ?>';
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentThumbnailURL - O -- Attachment square thumbnail URL -->
-	*/
-	public function AttachmentThumbnailURL($attr)
-	{
-		$f = $this->getFilters($attr);
-		return
-		'<?php '.
-		'if (isset($attach_f->media_thumb[\'sq\'])) {'.
-			'echo '.sprintf($f,'$attach_f->media_thumb[\'sq\']').';'.
-		'}'.
-		'?>';
-	}
-	
-	/*dtd
-	<!ELEMENT tpl:AttachmentURL - O -- Attachment URL -->
-	*/
-	public function AttachmentURL($attr)
-	{
-		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->file_url').'; ?>';
-	}
-	
-	public function MediaURL($attr)
-	{
-		$f = $this->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$_ctx->file_url').'; ?>';
-	}
 	
 	/* Blog ----------------------------------------------- */
@@ -1160,5 +976,5 @@
 	public function CategoryIf($attr,$content)
 	{
-		$if = array();
+		$if = new ArrayObject();
 		$operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';
 		
@@ -1182,4 +998,6 @@
 			$if[] = '$_ctx->categories->cat_desc '.$sign.' ""'; 
 		} 
+		
+		$this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if);
 		
 		if (!empty($if)) {
@@ -1431,5 +1249,5 @@
 	selected	(0|1)	#IMPLIED	-- post is selected (value : 1) or not (value : 0)
 	has_category	(0|1)	#IMPLIED	-- post has a category (value : 1) or not (value : 0)
-	has_attachment	(0|1)	#IMPLIED	-- post has attachments (value : 1) or not (value : 0)
+	has_attachment	(0|1)	#IMPLIED	-- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code)
 	comments_active	(0|1)	#IMPLIED	-- comments are active for this post (value : 1) or not (value : 0)
 	pings_active	(0|1)	#IMPLIED	-- trackbacks are active for this post (value : 1) or not (value : 0)
@@ -1442,5 +1260,5 @@
 	public function EntryIf($attr,$content)
 	{
-		$if = array();
+		$if = new ArrayObject();
 		$extended = null;
 		$hascategory = null;
@@ -1499,9 +1317,4 @@
 		}
 		
-		if (isset($attr['has_attachment'])) {
-			$sign = (boolean) $attr['has_attachment'] ? '' : '!';
-			$if[] = $sign.'$_ctx->posts->countMedia()';
-		}
-		
 		if (isset($attr['comments_active'])) {
 			$sign = (boolean) $attr['comments_active'] ? '' : '!';
@@ -1540,6 +1353,8 @@
 		}
 		
+		$this->core->callBehavior('tplIfConditions','EntryIf',$attr,$content,$if);
+		
 		if (!empty($if)) {
-			return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>';
+			return '<?php if('.implode(' '.$operator.' ',(array)$if).') : ?>'.$content.'<?php endif; ?>';
 		} else {
 			return $content;
@@ -1636,37 +1451,4 @@
 	}
 	
-	/*dtd
-	<!ELEMENT tpl:EntryAttachmentCount - O -- Number of attachments for entry -->
-	<!ATTLIST tpl:EntryAttachmentCount
-	none	CDATA	#IMPLIED	-- text to display for "no attachment" (default: no attachment)
-	one	CDATA	#IMPLIED	-- text to display for "one attachment" (default: one attachment)
-	more	CDATA	#IMPLIED	-- text to display for "more attachment" (default: %s attachment, %s is replaced by the number of attachments)
-	>
-	*/
-	public function EntryAttachmentCount($attr)
-	{
-		$none = 'no attachment';
-		$one = 'one attachment';
-		$more = '%d attachments';
-		
-		if (isset($attr['none'])) {
-			$none = addslashes($attr['none']);
-		}
-		if (isset($attr['one'])) {
-			$one = addslashes($attr['one']);
-		}
-		if (isset($attr['more'])) {
-			$more = addslashes($attr['more']);
-		}
-		
-		return
-		"<?php if (\$_ctx->posts->countMedia() == 0) {\n".
-		"  printf(__('".$none."'),(integer) \$_ctx->posts->countMedia());\n".
-		"} elseif (\$_ctx->posts->countMedia() == 1) {\n".
-		"  printf(__('".$one."'),(integer) \$_ctx->posts->countMedia());\n".
-		"} else {\n".
-		"  printf(__('".$more."'),(integer) \$_ctx->posts->countMedia());\n".
-		"} ?>";
-	}
 	
 	/*dtd
@@ -2223,4 +2005,6 @@
 			$if[] = $sign.'context::PaginationEnd()';
 		}
+		
+		$this->core->callBehavior('tplIfConditions','PaginationIf',$attr,$content,$if);
 		
 		if (!empty($if)) {
@@ -2497,4 +2281,6 @@
 		}
 		
+		$this->core->callBehavior('tplIfConditions','CommentIf',$attr,$content,$if);
+		
 		if (!empty($if)) {
 			return '<?php if('.implode(' && ',$if).') : ?>'.$content.'<?php endif; ?>';
@@ -2988,5 +2774,5 @@
 	current_mode		CDATA	#IMPLIED	-- tests if current URL mode is the one given in parameter
 	has_tpl			CDATA     #IMPLIED  -- tests if a named template exists
-	has_tag			CDATA     #IMPLIED  -- tests if a named template tag exists
+	has_tag			CDATA     #IMPLIED  -- tests if a named template tag exists (see Tag plugin for code)
 	blog_id			CDATA     #IMPLIED  -- tests if current blog ID is the one given in parameter
 	comments_active	(0|1)	#IMPLIED	-- test if comments are enabled blog-wide 
@@ -2998,5 +2784,5 @@
 	public function SysIf($attr,$content)
 	{
-		$if = array();
+		$if = new ArrayObject();
 		$is_ping = null;
 		
@@ -3044,13 +2830,4 @@
 		}
 		
-		if (isset($attr['has_tag'])) {
-			$sign = '';
-			if (substr($attr['has_tag'],0,1) == '!') {
-				$sign = '!';
-				$attr['has_tag'] = substr($attr['has_tag'],1);
-			}
-			$if[] =  $sign."(\$core->tpl->tagExists('".addslashes($attr['has_tag'])."') )";
-		}
-		
 		if (isset($attr['blog_id'])) {
 			$sign = '';
@@ -3081,4 +2858,6 @@
 			$if[] = '(isset($_search_count) && $_search_count '.html::decodeEntities($attr['search_count']).')';
 		}
+		
+		$this->core->callBehavior('tplIfConditions','SysIf',$attr,$content,$if);
 		
 		if (!empty($if)) {
