本文整理汇总了PHP中TPL::cond方法的典型用法代码示例。如果您正苦于以下问题:PHP TPL::cond方法的具体用法?PHP TPL::cond怎么用?PHP TPL::cond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TPL
的用法示例。
在下文中一共展示了TPL::cond方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _module_config_load
public function _module_config_load()
{
$cfg = core::s('cfg');
TPL::add('SITE_TITLE', '{L_SITE_CONFIG} — {SITE_HEADER} / {L_ACP}');
$sql = new SQLObject();
if ($sql->query("\r\nSELECT module,name,value,type\r\nFROM " . $sql->table('config') . "\r\nWHERE (module = 'core')")) {
foreach ($sql->fetch() as $item) {
switch ($item->type) {
case 'integer':
$value = (int) $item->value;
break;
case 'string':
$value = (string) $item->value;
break;
case 'float':
$value = (double) $item->value;
break;
case 'timestamp':
$value = strtotime((string) $item->value);
break;
case 'boolean':
if ((int) $item->value == 0) {
$value = false;
} else {
$value = true;
}
TPL::cond('MODULE_CONFIG:' . strtoupper($item->name), $value);
break;
default:
$value = $item->value;
break;
}
TPL::add('MODULE_CONFIG:' . strtoupper($item->name), $value);
}
}
$dir = dir('./langs/');
while ($file = $dir->read()) {
if ($file == '.' || $file == '..') {
continue;
}
$langs[] = $file;
}
sort($langs);
$f_langs = array();
foreach ($langs as $lang) {
$f_langs[] = array('LANG_CODENAME' => $lang, 'conds' => array('LANG_ACTIVE' => $lang == $cfg['etc']['core']['site_lang'] ? true : false));
}
TPL::assignAsLoop('MODULE_CONFIG:SITE_LANG', $f_langs);
$f_langs = array();
foreach ($langs as $lang) {
$f_langs[] = array('LANG_CODENAME' => $lang, 'conds' => array('LANG_ACTIVE' => $lang == $cfg['etc']['core']['acp_lang'] ? true : false));
}
TPL::assignAsLoop('MODULE_CONFIG:ACP_LANG', $f_langs);
$dir = dir('./styles/');
while ($file = $dir->read()) {
if ($file == '.' || $file == '..' || $file == '.acp') {
continue;
}
$styles[] = $file;
}
sort($styles);
$f_styles = array();
foreach ($styles as $style) {
$info = array();
$path = './styles/' . $style . '/style.cfg';
if (file_exists($path)) {
$data = simplexml_load_file($path);
foreach ($data->children() as $item) {
switch ($item['name']) {
case 'name':
$info['name'] = $item['value'];
break;
case 'author':
$info['author'] = $item['value'];
break;
case 'author_link':
$info['author_link'] = $item['value'];
break;
case 'preview':
$preview = true;
$info['preview'] = './styles/' . $style . '/' . $item['value'];
break;
}
}
}
if (!isset($info['name'])) {
$info['name'] = $style;
}
if (!isset($info['author'])) {
$info['author'] = '{L_UNKNOWN}';
}
if (!isset($info['preview'])) {
$preview = false;
$info['preview'] = './styles/.acp/media/images/style_preview.png';
}
if ($style == $cfg['etc']['core']['site_style']) {
TPL::add('MODULE_CONFIG:SITE_STYLE_NAME', strlen($info['name']) > 24 ? mb_substr($info['name'], 0, 24, 'UTF-8') . '...' : $info['name']);
}
$f_styles[] = array('STYLE_CODENAME' => $style, 'STYLE_NAME' => $info['name'], 'STYLE_AUTHOR' => $info['author'], 'STYLE_AUTHOR_LINK' => $info['author_link'], 'STYLE_PREVIEW' => $info['preview'], 'conds' => array('STYLE_ACTIVE' => $style == $cfg['etc']['core']['site_style'] ? true : false, 'STYLE_AUTHOR_LINK' => isset($info['author_link']) ? true : false, 'STYLE_PREVIEW' => $preview));
}
//.........这里部分代码省略.........
示例2: getOnlineUsers
public function getOnlineUsers($count = 0, $groups = array(), $loop_key = 'ONLINE_USERS')
{
$sql = new SQLObject();
$cfg = core::s('cfg');
$query = "\r\nSELECT\r\n\t" . $sql->table('auth_users') . ".user_id AS user_id,\r\n\t" . $sql->table('auth_users') . ".user_username AS user_username,\r\n\t" . $sql->table('auth_users') . ".user_group_main AS user_group_main,\r\n\t" . $sql->table('auth_users') . ".session_last_time AS session_last_time,\r\n\t" . $sql->table('auth_groups') . ".group_name AS group_name\r\nFROM " . $sql->table('auth_users') . "\r\nLEFT JOIN " . $sql->table('auth_groups') . "\r\n\tON " . $sql->table('auth_users') . ".user_group_main = " . $sql->table('auth_groups') . ".group_id\r\nWHERE (session_last_time >= " . (time() - $cfg['etc']['core']['online_offset']);
if ($groups) {
$query .= " AND (";
$i = 0;
foreach ($groups as $group_id) {
$query .= " user_groups LIKE '%" . $group_id . "%'";
if ($i != count($groups) - 1) {
$query .= " AND";
} else {
$query .= ")";
}
$i++;
}
}
$query .= ") ORDER BY session_last_time DESC";
if ($count) {
$query .= " LIMIT 0," . (int) $count;
}
if (!$sql->query($query)) {
TPL::cond($loop_key, false);
core::s('tpl')->assignLoop($loop_key, array());
echo $sql->error;
} else {
TPL::cond($loop_key, true);
$users = new TPLLoop($loop_key);
foreach ($sql->fetch() as $user) {
$item = new TPLLoopItem();
$item->add('USER_ID', $user->user_id);
$item->add('USER_USERNAME', $user->user_username);
$item->add('USER_GROUP', $user->user_group_main);
$item->add('USER_SESSION_TIME_OFFSET', $this->getSessionTimeOffset($user->session_last_time));
$item->cond('ADMIN', in_array(1, (array) $groups) || (int) $user->user_group_main == 1);
$users->append($item);
}
$users->pack();
}
}