Index: plugins/attachments/_public.php
===================================================================
--- plugins/attachments/_public.php	(revision 1179)
+++ plugins/attachments/_public.php	(revision 1220)
@@ -40,12 +40,15 @@
 		"<?php\n".
 		'if ($_ctx->posts !== null && $core->media) {'."\n".
-			'$_ctx->attachments = new ArrayObject($core->media->getPostMedia($_ctx->posts->post_id));'."\n".
+		'$_ctx->attachments = staticRecord::newFromArray($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 $attach_i = 0; ?>'. // LEGACY
+		'<?php while ($_ctx->attachments->fetch()) : ?>'.
+		
+		'<?php $GLOBALS[\'attach_i\'] = $attach_i++; $GLOBALS[\'attach_f\'] = $_ctx->attachments->row();'. // LEGACY
+		'$_ctx->file_url = $_ctx->attachments->file_url; ?>'. // LEGACY
+		
+		$content.'<?php endwhile; '.
+		'$_ctx->attachments = null; ?>'.
 		
 		"<?php } ?>\n";
@@ -60,5 +63,5 @@
 	{
 		return
-		"<?php if (\$attach_i == 0) : ?>".
+		"<?php if (\$_ctx->attachments->isStart()) : ?>".
 		$content.
 		"<?php endif; ?>";
@@ -71,5 +74,5 @@
 	{
 		return
-		"<?php if (\$attach_i+1 == count(\$_ctx->attachments)) : ?>".
+		"<?php if (\$_ctx->attachments->isEnd()) : ?>".
 		$content.
 		"<?php endif; ?>";
@@ -93,15 +96,15 @@
 		if (isset($attr['is_image'])) {
 			$sign = (boolean) $attr['is_image'] ? '' : '!';
-			$if[] = $sign.'$attach_f->media_image';
+			$if[] = $sign.'$_ctx->attachments->media_image';
 		}
 		
 		if (isset($attr['has_thumb'])) {
 			$sign = (boolean) $attr['has_thumb'] ? '' : '!';
-			$if[] = $sign.'isset($attach_f->media_thumb[\'sq\'])';
+			$if[] = $sign.'isset($_ctx->attachments->media_thumb[\'sq\'])';
 		}
 		
 		if (isset($attr['is_mp3'])) {
 			$sign = (boolean) $attr['is_mp3'] ? '==' : '!=';
-			$if[] = '$attach_f->type '.$sign.' "audio/mpeg3"';
+			$if[] = '$_ctx->attachments->type '.$sign.' "audio/mpeg3"';
 		}
 		
@@ -109,7 +112,7 @@
 			$sign = (boolean) $attr['is_flv'] ? '' : '!';
 			$if[] = $sign.
-				'($attach_f->type == "video/x-flv" || '.
-				'$attach_f->type == "video/mp4" || '.
-				'$attach_f->type == "video/x-m4v")';
+				'($_ctx->attachments->type == "video/x-flv" || '.
+				'$_ctx->attachments->type == "video/mp4" || '.
+				'$_ctx->attachments->type == "video/x-m4v")';
 		}
 		
@@ -127,5 +130,5 @@
 	{
 		$f = $GLOBALS['core']->tpl->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->type').'; ?>';
+		return '<?php echo '.sprintf($f,'$_ctx->attachments->type').'; ?>';
 	}
 	
@@ -136,5 +139,5 @@
 	{
 		$f = $GLOBALS['core']->tpl->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->media_type').'; ?>';
+		return '<?php echo '.sprintf($f,'$_ctx->attachments->media_type').'; ?>';
 	}
 	
@@ -145,5 +148,5 @@
 	{
 		$f = $GLOBALS['core']->tpl->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->basename').'; ?>';
+		return '<?php echo '.sprintf($f,'$_ctx->attachments->basename').'; ?>';
 	}
 	
@@ -158,7 +161,7 @@
 		$f = $GLOBALS['core']->tpl->getFilters($attr);
 		if (!empty($attr['full'])) {
-			return '<?php echo '.sprintf($f,'$attach_f->size').'; ?>';
-		}
-		return '<?php echo '.sprintf($f,'files::size($attach_f->size)').'; ?>';
+			return '<?php echo '.sprintf($f,'$_ctx->attachments->size').'; ?>';
+		}
+		return '<?php echo '.sprintf($f,'files::size($_ctx->attachments->size)').'; ?>';
 	}
 	
@@ -169,5 +172,5 @@
 	{
 		$f = $GLOBALS['core']->tpl->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->media_title').'; ?>';
+		return '<?php echo '.sprintf($f,'$_ctx->attachments->media_title').'; ?>';
 	}
 	
@@ -180,6 +183,6 @@
 		return
 		'<?php '.
-		'if (isset($attach_f->media_thumb[\'sq\'])) {'.
-			'echo '.sprintf($f,'$attach_f->media_thumb[\'sq\']').';'.
+		'if (isset($_ctx->attachments->media_thumb[\'sq\'])) {'.
+			'echo '.sprintf($f,'$_ctx->attachments->media_thumb[\'sq\']').';'.
 		'}'.
 		'?>';
@@ -192,5 +195,5 @@
 	{
 		$f = $GLOBALS['core']->tpl->getFilters($attr);
-		return '<?php echo '.sprintf($f,'$attach_f->file_url').'; ?>';
+		return '<?php echo '.sprintf($f,'$_ctx->attachments->file_url').'; ?>';
 	}
 	
