Location: PHPKode > projects > Write2Left > Build/Tags/Post.php
<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: Post.php
| Description:
|   Adds the post parts to a page
| Created Jul-12-2003
+------------------------------------------------------
*/

/* Class: TagPost 
 * Description:
 *   Parses single-post-related tags tags
 */
class TagPost
{
	function register_callbacks( &$callbacks )
	{
		$callbacks['PostItem'] = array( 'TagPost', 'post_item' );
		
		$callbacks['IfInvalidPostID'] = array( 'TagPost', 'do_tags' );
		$callbacks['IfNoPostID'] = array( 'TagPost', 'do_tags' );
	}

	function post_item( $tag_name, $context, $attributes, $content, $filename, $settings )
	{
	    global $W2L;

		return ItemCode::item_start( $settings['cache_path'] ) .
			   $content .
			   ItemCode::item_end();

	}


	function do_tags( $tag_name, $context, $attributes, $content, $filename, $settings )
	{
		global $W2L;

		switch( $tag_name )
		{
			case 'IfInvalidPostID':
				return "<?php if( !file_exists( \"{$settings['cache_path']}item.{\$INPUT['id']}.cache.php\" ) ) { ?".'>' .
					   $content .
					   '<?php } ?'.'>';
			case 'IfNoPostID':
				return '<?php if( !array_key_exists( \'id\', $INPUT ) ) { ?'.'>' .
					   $content .
					   '<?php } ?'.'>';
			default:
				return $content;
		}
	}
}

class ItemCode
{
	function item_start( $cache )
	{
		return <<<EOF
<?php
if( array_key_exists( 'id', \$INPUT ) )
{
	if( file_exists( "{$cache}item.{\$INPUT['id']}.cache.php" ) )
	{
		include_once( "{$cache}item.{\$INPUT['id']}.cache.php" );
?>
EOF;
	}

	function item_end()
	{
		return <<<EOF
<?php } } ?>
EOF;
	}
}

$tag_parser[] = new TagPost();

?>
Return current item: Write2Left