<?php

/**
 *--------------------------------------
 * 公共函数库
 *--------------------------------------
 * @project		: uwa
 * @author		: cblee
 * @created		: 2012-10-2
 * @copyright	: (c)2012 AsThis
 *--------------------------------------
 */

/* 获取文档属性 */
function get_archiveFlag($afAlias, $falgLen = 0)
{
	$afList = M('ArchiveFlag')->get_flagList();
	$result = '';
	foreach($afList as $v)
	{
		$aFlag = $v['af_name'];
		if($falgLen > 0)
		{
			$aFlag = AString::msubstr($aFlag, 0, $falgLen);
		}
		$result .= (preg_match("#".$v['af_alias']."#", $afAlias) ? ' <span class="fc_wht fs_11 bg_gry br_3">'.$aFlag.'</span>' : '');
	}
	$result = trim($result);
	return $result;
}

/* 获取控制器列表 */
function get_ctrlrList($ctrlrPath)
{
	$names = require_cache($ctrlrPath.'/_names.php');
	$ctrlrList = array();
	$dirRes = opendir($ctrlrPath);
	while($dir = readdir($dirRes))
	{
		if(!in_array($dir, array('.', '..', 'index.html', '_names.php', '.svn')))
		{
			$ctrlr = basename($dir, 'Ctrlr.class.php');
			$name = isset($names[$ctrlr]) ? $names[$ctrlr] : $ctrlr;
			$ctrlrList[] = array('ctrlr' => $ctrlr, 'name' => $name);
		}
	}
	return $ctrlrList;
}

/* 列出某个控制器的 */
function get_actnList($ctrlr)
{
	$ctrlrClass = $ctrlr.'Ctrlr';
	$baseCtrlr = get_class_methods('Ctrlr');
	$advCtrlr = get_class_methods($ctrlrClass);
	$actnList = array_diff($advCtrlr, $baseCtrlr);
	return $actnList;
}

/* 从文件获取控制器 */
function get_fileActnList($file)
{
	$arr = file($file);
	foreach($arr as $line)
	{
		if(preg_match('/function ([_A-Za-z0-9]+)/i', $line, $regs))
		{
			$arr_methods[] = $regs[1];
		}
	}
	return $arr_methods;
}

/* 获取文件夹列表 */
function list_dir($dir)
{
	$items = array();
	$files = glob($dir.D_S.'*');
	if(is_array($files))
	{
		$names = require_cache($dir.'/_names.php');
		foreach($files as $v)
		{
			if(is_file($v))
			{
				continue;
			}
			$v = basename($v);
			$n = isset($names[$v]) ? $names[$v] : $v;
			$items[] = array('dir' => $v, 'name' => $n);
		}
	}
	return $items;
}

?>