<?php

/**
 *--------------------------------------
 * loga:gb_list
 *--------------------------------------
 * @project		: loga
 * @author		: cblee
 * @created		: 2016-07-07
 * @copyright	: (c)2016 AsThis
 *--------------------------------------
 */
defined('PFA_PATH') or exit('Access Denied');

class TagLogaGbList {
	public function get_tagStr($a) {
		$offset = 0;
		$row = 10;
		$key = 'k';
		$as = 'item';

		$where = "	\$where = array();\r\n";
		$where .= "	\$where['__GUESTBOOK__.g_status'] = array('GT', 0);\r\n";

		/* limit start row */
		if(isset($a['offset']) and !empty($a['offset'])) {
			if(strpos($a['offset'], '$')) {
				$offset = "'.(!empty(".substr($a['offset'], 2, -2).") ? '{$a['offset']}' : '{$offset}').'";
			}
			else {
				$offset = $a['offset'];
			}
		}

		/* row */
		if(isset($a['row']) and !empty($a['row'])) {
			if(strpos($a['row'], '$')) {
				$row = "'.(!empty(".substr($a['row'], 2, -2).") ? '{$a['row']}' : '{$row}').'";
			}
			else {
				$row = $a['row'];
			}
		}

		/* key */
		if(isset($a['key']) and !empty($a['key'])) {
			if(strpos($a['key'], '$')) {
				$key = "'.(!empty(".substr($a['key'], 2, -2).") ? '{$a['key']}' : '{$key}').'";
			}
			else {
				$key = $a['key'];
			}
		}

		/* as */
		if(isset($a['as']) and !empty($a['as'])) {
			if(strpos($a['as'], '$')) {
				$as = "'.(!empty(".substr($a['as'], 2, -2).") ? '{$a['as']}' : '{$as}').'";
			}
			else {
				$as = $a['as'];
			}
		}

		$str = "<?php\r\n";
		$str .= "\$var_gbl = LANG_NAME.'_gb_list_{$offset}_{$row}';\r\n";
		$str .= "\$\$var_gbl = S('_list/_'.ltrim(\$var_gbl, '_'), '', null, array('temp' => TEMP_PATH.D_S.'home'));\r\n";
		$str .= "if(empty(\$\$var_gbl)) {\r\n";
		$str .= $where;
		$str .= "	\$\$var_gbl = M('Guestbook')->get_guestbookList(\$where, '`g_add_time` DESC', '{$offset},{$row}');\r\n";
		/* expire */
		if(isset($a['expire']) and !empty($a['expire'])) {
			if(strpos($a['expire'], '$')) {
				$expire = "'.(!empty(".substr($a['expire'], 2, -2).") ? '{$a['expire']}' : '{$expire}').'";
			}
			else {
				$expire = $a['expire'];
			}
			$str .= "	S('_list/_'.ltrim(\$var_gbl, '_'), \$\$var_gbl, '{$expire}', array('temp' => TEMP_PATH.D_S.'home'));\r\n";
		}
		else {
			$str .= "	S('_list/_'.ltrim(\$var_gbl, '_'), \$\$var_gbl, null, array('temp' => TEMP_PATH.D_S.'home'));\r\n";
		}
		$str .= "}\r\n";
		$str .= "if(\$\$var_gbl) : foreach(\$\$var_gbl as \${$key} => \${$as}): \r\n";
		$str .= "?>\r\n";
		return $str;
	}

	public function get_tagEndStr() {
		$str = "<?php endforeach; endif; ?>\r\n";
		return $str;
	}
}

?>