<?php
if ( !defined( "SAXUE_CORE_INCLUDE" ) ) {
		include "../core.php";
} 
saxue_checkpower( 'blocks' );
include SAXUE_ADMIN_PATH . "/header.php";
if ( isset( $_POST['dosubmit'] ) ) {
		$_POST['filename'] = str_replace( '.php', '', trim( $_POST['filename'] ) );
		$_POST['vars'] = trim( $_POST['vars'] );
		$_POST['template'] = trim( $_POST['template'] );
		$tmp = explode( '_', $_POST['filename'] );
		$_POST['classname'] = ucfirst( $tmp[0] ) . ucfirst( $tmp[1] );
		$ret = array();
		$ret['block_temp'] = '{?block classname="' . $_POST['classname'] . '" filename="' . $_POST['filename'] . '" vars="' . $_POST['vars'] . '" template="' . $_POST['template'] . '"?}';
		$ret['eloop_temp'] = '{?eloop name="i" loop="$items" classname="' . $_POST['classname'] . '" filename="' . $_POST['filename'] . '" vars="' . $_POST['vars'] . '"?}' . "\n...\nHTML代码\n...\n{?/eloop?}";
		$data = saxue_get_eloop( $_POST );
		if ( !$data ) {
				$ret['eloop_data'] = 'Array()';
		} else {
				$ret['eloop_data'] = var_export( $data, true );
		}
		$ret['block_data'] = saxue_get_block( $_POST, 1 );
		exit( json_encode( $ret ) );
}
$block_path = SAXUE_ROOT_PATH . '/blocks';
$block_list = glob( $block_path . '/block_*.php' );
$blocks = array();
$k = 0;
if ( $block_list ) {
		foreach( $block_list as $file ) {
				$filename = basename( $file );
				if ( $filename == 'block_sql.php' || $filename == 'block_custom.php' ) continue;
				$blocks[$k]['filepath'] = $file;
				$blocks[$k]['filename'] = $filename;
				$temp = saxue_readfile( $file );
				if ( preg_match( "#/\*(.+?)\*/#isU", $temp, $match ) ) {
						$blocks[$k]['intro'] = nl2br( trim( $match[1] ) );
				} else {
						$blocks[$k]['intro'] = '';
				}
				++$k;
		}
}
$saxueTpl -> assign( "blocks", $blocks );
$saxueTset['saxue_contents_template'] = SAXUE_ADMIN_PATH . "/templates/block_file.html";
include SAXUE_ADMIN_PATH . "/footer.php";
