function AuditRecords_AddMenu(&$m) { global $zbp; array_unshift($m, ''); $n = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(log_ID) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=0 AND log_Status=2'), 'num'); $m[0] = $m[1]; $m[1] = MakeLeftMenu("audit", "(" . $n . ")审核管理", $zbp->host . "zb_users/plugin/AuditRecords/main.php", "nav_AuditRecords", "aAuditRecords", ""); }
/** * @todo * @override */ protected function buildCreate() { $sqlAll = array(); foreach ($this->table as $tableIndex => $table) { $sql = array(); $sql[] = 'CREATE TABLE ' . $table; $sql[] = ' ('; $createData = array(); $idname = GetValueInArrayByCurrent($this->data, 0); $i = 0; foreach ($this->data as $key => $value) { if ($value[1] == 'integer') { if ($i == 0) { $createData[] = $value[0] . ' integer primary key' . ($this->dbclass == 'DbSQLite' ? '' : ' autoincrement'); } else { $createData[] = $value[0] . ' integer NOT NULL DEFAULT \'' . $value[3] . '\''; } } if ($value[1] == 'boolean') { $createData[] = $value[0] . ' bit NOT NULL DEFAULT \'' . (int) $value[3] . '\''; } if ($value[1] == 'string') { if ($value[2] != '') { if (strpos($value[2], 'char') !== false) { $createData[] = $value[0] . ' char(' . str_replace('char', '', $value[2]) . ') NOT NULL DEFAULT \'' . $value[3] . '\''; } elseif (is_int($value[2])) { $createData[] = $value[0] . ' varchar(' . $value[2] . ') NOT NULL DEFAULT \'' . $value[3] . '\''; } else { $createData[] = $value[0] . ' text NOT NULL DEFAULT \'\''; } } else { $createData[] = $value[0] . ' text NOT NULL DEFAULT \'\''; } } if ($value[1] == 'double' || $value[1] == 'float') { $createData[] = $value[0] . " {$value['1']} NOT NULL DEFAULT 0"; } if ($value[1] == 'date' || $value[1] == 'datetime') { $createData[] = $value[0] . " {$value['1']} NOT NULL"; } if ($value[1] == 'timestamp') { $createData[] = $value[0] . " {$value['1']} NOT NULL DEFAULT CURRENT_TIMESTAMP"; } $i += 1; } $sql[] = implode(', ', $createData); $sql[] = ');'; $sql[] = 'CREATE UNIQUE INDEX ' . $table . '_' . $idname; $sql[] = ' on ' . $table . ' (' . $idname . ');'; $sqlAll[] = implode($sql, ' '); } $this->_sql = $sqlAll; }
/** * 添加评论管理子菜单 */ function Zbp_Admin_Addcmtsubmenu() { global $zbp; if ($zbp->CheckRights('CommentAll')) { $n = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(comm_ID) AS num FROM ' . $GLOBALS['table']['Comment'] . ' WHERE comm_Ischecking=1'), 'num'); if ($n != 0) { $n = ' (' . $n . ')'; } else { $n = ''; } echo '<a href="../cmd.php?act=CommentMng&ischecking=1"><span class="m-left ' . (GetVars('ischecking') ? 'm-now' : '') . '">' . $GLOBALS['lang']['msg']['check_comment'] . $n . '</span></a>'; } }
function misc_statistic() { global $zbp; $zbp->BuildTemplate(); $r = null; CountNormalArticleNums(); CountTopArticle(null, null); CountCommentNums(null, null); $all_comments = $zbp->cache->all_comment_nums; $xmlrpc_address = $zbp->xmlrpcurl; $current_member = $zbp->user->Name; $current_version = ZC_VERSION_FULL; $all_artiles = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=\'0\''), 'num'); $all_pages = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=\'1\''), 'num'); $all_categorys = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Category']), 'num'); $all_views = $zbp->option['ZC_VIEWNUMS_TURNOFF'] == true ? 0 : GetValueInArrayByCurrent($zbp->db->Query('SELECT SUM(log_ViewNums) AS num FROM ' . $GLOBALS['table']['Post']), 'num'); $all_tags = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) as num FROM ' . $GLOBALS['table']['Tag']), 'num'); $all_members = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Member']), 'num'); $current_theme = '{$zbp->theme}'; $current_style = '{$zbp->style}'; $current_member = '{$zbp->user->Name}'; $current_version = '{$zbp->version}'; $system_environment = '{$system_environment}'; if ($zbp->option['ZC_DEBUG_MODE']) { $r .= "<tr><td colspan='4' style='text-align: center'>{$zbp->lang['msg']['debugging_warning']}</td></tr>"; } $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_member']}</td><td class='td30'><a href='../cmd.php?act=misc&type=vrs' target='_blank'>{$current_member}</a></td><td class='td20'>{$zbp->lang['msg']['current_version']}</td><td class='td30'>{$current_version}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_artiles']}</td><td>{$all_artiles}</td><td>{$zbp->lang['msg']['all_categorys']}</td><td>{$all_categorys}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_pages']}</td><td>{$all_pages}</td><td>{$zbp->lang['msg']['all_tags']}</td><td>{$all_tags}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_comments']}</td><td>{$all_comments}</td><td>{$zbp->lang['msg']['all_views']}</td><td>{$all_views}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_theme']} / {$zbp->lang['msg']['current_style']}</td><td>{$current_theme}/{$current_style}</td><td>{$zbp->lang['msg']['all_members']}</td><td>{$all_members}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['xmlrpc_address']}</td><td>{$xmlrpc_address}</td><td>{$zbp->lang['msg']['system_environment']}</td><td><a href='../cmd.php?act=misc&type=phpinfo' target='_blank'>{$system_environment}</a></td></tr>"; $r .= "<script type=\"text/javascript\">\$('#statistic').attr('title','" . date("c", $zbp->cache->reload_statistic_time) . "');</script>"; $zbp->cache->reload_statistic = $r; $zbp->cache->reload_statistic_time = time(); $zbp->cache->system_environment = GetEnvironment(); $zbp->cache->all_article_nums = $all_artiles; $zbp->cache->all_page_nums = $all_pages; $zbp->AddBuildModule('statistics', array($all_artiles, $all_pages, $all_categorys, $all_tags, $all_views, $all_comments)); $zbp->BuildModule(); $zbp->SaveCache(); $r = str_replace('{#ZC_BLOG_HOST#}', $zbp->host, $r); $r = str_replace('{$zbp->user->Name}', $zbp->user->Name, $r); $r = str_replace('{$zbp->theme}', $zbp->theme, $r); $r = str_replace('{$zbp->style}', $zbp->style, $r); $r = str_replace('{$zbp->version}', ZC_VERSION_FULL, $r); $r = str_replace('{$system_environment}', $zbp->cache->system_environment, $r); echo $r; }
function misc_statistic() { global $zbp; $r = null; $zbp->BuildTemplate(); $xmlrpc_address = $zbp->host . 'zb_system/xml-rpc/'; $current_member = $zbp->user->Name; $current_version = $zbp->option['ZC_BLOG_VERSION']; $all_artiles = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=0'), 'num'); $all_pages = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=1'), 'num'); $all_categorys = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Category']), 'num'); $all_comments = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Comment']), 'num'); $all_views = $zbp->option['ZC_VIEWNUMS_TURNOFF'] == true ? 0 : GetValueInArrayByCurrent($zbp->db->Query('SELECT SUM(log_ViewNums) AS num FROM ' . $GLOBALS['table']['Post']), 'num'); $all_tags = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) as num FROM ' . $GLOBALS['table']['Tag']), 'num'); $all_members = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Member']), 'num'); $current_theme = $zbp->theme; $current_style = $zbp->style; $current_member = '{$zbp->user->Name}'; $ajax = Network::Create(); if ($ajax) { $ajax = substr(get_class($ajax), 7); } $system_environment = PHP_OS . ';' . GetValueInArray(explode(' ', str_replace(array('Microsoft-', '/'), array('', ''), GetVars('SERVER_SOFTWARE', 'SERVER'))), 0) . ';' . 'PHP' . phpversion() . ';' . $zbp->option['ZC_DATABASE_TYPE'] . ';' . $ajax; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_member']}</td><td class='td30'>{$current_member}</td><td class='td20'>{$zbp->lang['msg']['current_version']}</td><td class='td30'>{$current_version}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_artiles']}</td><td>{$all_artiles}</td><td>{$zbp->lang['msg']['all_categorys']}</td><td>{$all_categorys}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_pages']}</td><td>{$all_pages}</td><td>{$zbp->lang['msg']['all_tags']}</td><td>{$all_tags}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_comments']}</td><td>{$all_comments}</td><td>{$zbp->lang['msg']['all_views']}</td><td>{$all_views}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_theme']}/{$zbp->lang['msg']['current_style']}</td><td>{$current_theme}/{$current_style}</td><td>{$zbp->lang['msg']['all_members']}</td><td>{$all_members}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['xmlrpc_address']}</td><td>{$xmlrpc_address}</td><td>{$zbp->lang['msg']['system_environment']}</td><td>{$system_environment}</td></tr>"; $zbp->cache->reload_statistic = $r; $zbp->cache->reload_statistic_time = time(); $zbp->cache->system_environment = $system_environment; //$zbp->SaveCache(); CountNormalArticleNums(); $zbp->AddBuildModule('statistics', array($all_artiles, $all_pages, $all_categorys, $all_tags, $all_views, $all_comments)); $zbp->BuildModule(); $r = str_replace('{#ZC_BLOG_HOST#}', $zbp->host, $r); $r = str_replace('{$zbp->user->Name}', $zbp->user->Name, $r); echo $r; }
function misc_statistic() { global $zbp; $r = null; $zbp->BuildTemplate(); $xmlrpc_address = $zbp->host . 'zb_system/xml-rpc/'; $current_member = $zbp->user->Name; $current_version = $zbp->option['ZC_BLOG_VERSION']; $all_artiles = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(log_ID) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=0'), 'num'); $all_pages = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(log_ID) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=1'), 'num'); $all_categorys = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(cate_ID) AS num FROM ' . $GLOBALS['table']['Category']), 'num'); $all_comments = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(comm_ID) AS num FROM ' . $GLOBALS['table']['Comment']), 'num'); $all_views = GetValueInArrayByCurrent($zbp->db->Query('SELECT SUM(log_ViewNums) AS num FROM ' . $GLOBALS['table']['Post']), 'num'); $all_tags = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(tag_ID) as num FROM ' . $GLOBALS['table']['Tag']), 'num'); $all_members = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(mem_ID) AS num FROM ' . $GLOBALS['table']['Member']), 'num'); $current_theme = $zbp->theme; $current_style = $zbp->style; $current_member = '{$zbp->user->Name}'; $system_environment = PHP_OS . ';' . GetValueInArray(explode('/', GetVars('SERVER_SOFTWARE', 'SERVER')), 0) . ';' . 'PHP ' . phpversion() . ';' . $zbp->option['ZC_DATABASE_TYPE']; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_member']}</td><td class='td30'>{$current_member}</td><td class='td20'>{$zbp->lang['msg']['current_version']}</td><td class='td30'>{$current_version}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_artiles']}</td><td>{$all_artiles}</td><td>{$zbp->lang['msg']['all_categorys']}</td><td>{$all_categorys}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_pages']}</td><td>{$all_pages}</td><td>{$zbp->lang['msg']['all_tags']}</td><td>{$all_tags}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_comments']}</td><td>{$all_comments}</td><td>{$zbp->lang['msg']['all_views']}</td><td>{$all_views}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_theme']}/{$zbp->lang['msg']['current_style']}</td><td>{$current_theme}/{$current_style}</td><td>{$zbp->lang['msg']['all_members']}</td><td>{$all_members}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['xmlrpc_address']}</td><td>{$xmlrpc_address}</td><td>{$zbp->lang['msg']['system_environment']}</td><td>{$system_environment}</td></tr>"; $s = $zbp->db->sql->Count($zbp->table['Post'], array(array('COUNT', '*', 'num')), array(array('=', 'log_Type', 0), array('=', 'log_IsTop', 0), array('=', 'log_Status', 0))); $num = GetValueInArrayByCurrent($zbp->db->Query($s), 'num'); $zbp->LoadConfigs(); $zbp->LoadCache(); $zbp->cache->reload_statistic = $r; $zbp->cache->reload_statistic_time = time(); $zbp->cache->normal_article_nums = $num; $zbp->SaveCache(); $zbp->AddBuildModule('statistics', array($all_artiles, $all_pages, $all_categorys, $all_tags, $all_views, $all_comments)); $zbp->BuildModule(); $r = str_replace('{$zbp->user->Name}', $zbp->user->Name, $r); echo $r; }
function BuildModule_archives() { global $zbp; $fdate; $ldate; $sql = $zbp->db->sql->Select($zbp->table['Post'], array('log_PostTime'), null, array('log_PostTime' => 'DESC'), array(1), null); $array = $zbp->db->Query($sql); if (count($array) == 0) { return ''; } $ldate = array(date('Y', $array[0]['log_PostTime']), date('m', $array[0]['log_PostTime'])); $sql = $zbp->db->sql->Select($zbp->table['Post'], array('log_PostTime'), null, array('log_PostTime' => 'ASC'), array(1), null); $array = $zbp->db->Query($sql); if (count($array) == 0) { return ''; } $fdate = array(date('Y', $array[0]['log_PostTime']), date('m', $array[0]['log_PostTime'])); $arraydate = array(); for ($i = $fdate[0]; $i < $ldate[0] + 1; $i++) { for ($j = 1; $j < 13; $j++) { $arraydate[] = strtotime($i . '-' . $j); } } foreach ($arraydate as $key => $value) { if ($value - strtotime($ldate[0] . '-' . $ldate[1]) > 0) { unset($arraydate[$key]); } if ($value - strtotime($fdate[0] . '-' . $fdate[1]) < 0) { unset($arraydate[$key]); } } $arraydate = array_reverse($arraydate); $s = ''; foreach ($arraydate as $key => $value) { $url = new UrlRule($zbp->option['ZC_DATE_REGEX']); $url->Rules['{%date%}'] = date('Y-n', $value); $url->Rules['{%year%}'] = date('Y', $value); $url->Rules['{%month%}'] = date('n', $value); $url->Rules['{%day%}'] = 1; $fdate = $value; $ldate = strtotime(date('Y-m-t', $value)) + 60 * 60 * 24; $sql = $zbp->db->sql->Count($zbp->table['Post'], array(array('COUNT', '*', 'num')), array(array('=', 'log_Type', '0'), array('=', 'log_Status', '0'), array('BETWEEN', 'log_PostTime', $fdate, $ldate))); $n = GetValueInArrayByCurrent($zbp->db->Query($sql), 'num'); if ($n > 0) { $s .= '<li><a href="' . $url->Make() . '">' . str_replace(array('%y%', '%m%'), array(date('Y', $fdate), date('n', $fdate)), $zbp->lang['msg']['year_month']) . ' (' . $n . ')</a></li>'; } } return $s; }
/** * @todo * @override */ protected function buildCreate() { //parent::buildCreate(); if (!empty($this->index) && empty($this->data)) { $this->buildIndex(); return; } $sqlAll = array(); foreach ($this->table as $tableIndex => $table) { $sql = array(); $sql[] = 'CREATE TABLE IF NOT EXISTS ' . $table; $sql[] = ' ('; $engine = $this->option['engine']; $idname = GetValueInArrayByCurrent($this->data, 0); $i = 0; foreach ($this->data as $key => $value) { if ($value[1] == 'integer') { if ($i == 0) { $sql[] = $value[0] . ' int(11) NOT NULL AUTO_INCREMENT' . ','; } else { if ($value[2] == '') { $sql[] = $value[0] . ' int(11) NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'tinyint') { $sql[] = $value[0] . ' tinyint(4) NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'smallint') { $sql[] = $value[0] . ' smallint(6) NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'mediumint') { $sql[] = $value[0] . ' mediumint(9) NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'int') { $sql[] = $value[0] . ' int(11) NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'bigint') { $sql[] = $value[0] . ' bigint(20) NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } } } if ($value[1] == 'boolean') { $sql[] = $value[0] . ' tinyint(1) NOT NULL DEFAULT \'' . (int) $value[3] . '\'' . ','; } if ($value[1] == 'string') { if ($value[2] != '') { if (strpos($value[2], 'char') !== false) { $sql[] = $value[0] . ' char(' . str_replace('char', '', $value[2]) . ') NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif (is_int($value[2])) { $sql[] = $value[0] . ' varchar(' . $value[2] . ') NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'tinytext') { $sql[] = $value[0] . ' tinytext NOT NULL ' . ','; } elseif ($value[2] == 'text') { $sql[] = $value[0] . ' text NOT NULL ' . ','; } elseif ($value[2] == 'mediumtext') { $sql[] = $value[0] . ' mediumtext NOT NULL ' . ','; } elseif ($value[2] == 'longtext') { $sql[] = $value[0] . ' longtext NOT NULL ' . ','; } } else { $sql[] = $value[0] . ' longtext NOT NULL ' . ','; } } if ($value[1] == 'double' || $value[1] == 'float') { $sql[] = $value[0] . " {$value['1']} NOT NULL DEFAULT 0" . ','; } if ($value[1] == 'date' || $value[1] == 'time' || $value[1] == 'datetime') { $sql[] = $value[0] . " {$value['1']} NOT NULL,"; } if ($value[1] == 'timestamp') { $sql[] = $value[0] . " {$value['1']} NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,"; } $i += 1; } $sql[] = 'PRIMARY KEY (' . $idname . ')'; $myengtype = $this->db->dbengine; if ($engine != null) { $myengtype = $engine; } if (!$myengtype) { $myengtype = 'MyISAM'; } $sql[] = ') ENGINE=' . $myengtype . ' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'; $sqlAll[] = implode($sql, ' '); } $this->_sql = $sqlAll; }
function LargeData_Misc_Statistic() { global $zbp; $r = null; CountNormalArticleNums(); CountTopArticle(null, null); CountCommentNums(null, null); $all_comments = $zbp->cache->all_comment_nums; $xmlrpc_address = $zbp->host . 'zb_system/xml-rpc/'; $current_member = $zbp->user->Name; $current_version = ZC_VERSION_FULL; $all_artiles = GetValueInArrayByCurrent($zbp->db->Query($zbp->db->sql->Select($zbp->table['Post'], 'Count(log_ID) AS num', array(array('=', 'log_Type', '0')), null, 1, null)), 'num'); $all_pages = GetValueInArrayByCurrent($zbp->db->Query($zbp->db->sql->Select($zbp->table['Post'], 'Count(log_ID) AS num', array(array('=', 'log_Type', '1')), null, 1, null)), 'num'); $all_categorys = GetValueInArrayByCurrent($zbp->db->Query($zbp->db->sql->Select($zbp->table['Category'], 'Count(*) AS num', null, null, 1, null)), 'num'); $all_views = '不计算'; $all_tags = GetValueInArrayByCurrent($zbp->db->Query($zbp->db->sql->Select($zbp->table['Tag'], 'Count(*) AS num', null, null, 1, null)), 'num'); $all_members = GetValueInArrayByCurrent($zbp->db->Query($zbp->db->sql->Select($zbp->table['Member'], 'Count(*) AS num', null, null, 1, null)), 'num'); $current_theme = '{$zbp->theme}'; $current_style = '{$zbp->style}'; $current_member = '{$zbp->user->Name}'; $system_environment = '{$system_environment}'; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_member']}" . '' . "</td><td class='td30'>{$current_member}</td><td class='td20'>{$zbp->lang['msg']['current_version']}</td><td class='td30'>{$current_version}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_artiles']}" . '' . "</td><td>{$all_artiles}</td><td>{$zbp->lang['msg']['all_categorys']}" . '' . "</td><td>{$all_categorys}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_pages']}" . '' . "</td><td>{$all_pages}</td><td>{$zbp->lang['msg']['all_tags']}" . '' . "</td><td>{$all_tags}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['all_comments']}" . '' . "</td><td>{$all_comments}</td><td>{$zbp->lang['msg']['all_views']}" . '' . "</td><td>{$all_views}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['current_theme']}/{$zbp->lang['msg']['current_style']}</td><td>{$current_theme}/{$current_style}</td><td>{$zbp->lang['msg']['all_members']}" . '' . "</td><td>{$all_members}</td></tr>"; $r .= "<tr><td class='td20'>{$zbp->lang['msg']['xmlrpc_address']}</td><td>{$xmlrpc_address}</td><td>{$zbp->lang['msg']['system_environment']}</td><td>{$system_environment}</td></tr>"; $r .= "<script type=\"text/javascript\">\$('#statistic').next('small').remove();\$('#statistic').after('<small> 更新时间:" . date("c", $zbp->cache->reload_statistic_time) . "</small>');</script>"; $zbp->cache->reload_statistic = $r; $zbp->cache->reload_statistic_time = time(); $zbp->cache->system_environment = $system_environment; $zbp->cache->all_article_nums = $all_artiles; $zbp->cache->all_page_nums = $all_pages; $zbp->AddBuildModule('statistics', array($all_artiles, $all_pages, $all_categorys, $all_tags, $all_views, $all_comments)); $zbp->BuildModule(); $zbp->SaveCache(); $r = str_replace('{#ZC_BLOG_HOST#}', $zbp->host, $r); $r = str_replace('{$zbp->user->Name}', $zbp->user->Name, $r); $r = str_replace('{$zbp->theme}', $zbp->theme, $r); $r = str_replace('{$zbp->style}', $zbp->style, $r); $r = str_replace('{$system_environment}', GetEnvironment(), $r); echo $r; }
/** * 导出文章归档模块数据 * @return string 模块内容 */ public static function Archives() { global $zbp; $template = $zbp->template; $tags = array(); $urls = array(); //array(url,name,count); $maxli = $zbp->modulesbyfilename['archives']->MaxLi; if ($maxli < 0) { return ''; } $sql = $zbp->db->sql->Select($zbp->table['Post'], array('log_PostTime'), null, array('log_PostTime' => 'DESC'), array(1), null); $array = $zbp->db->Query($sql); if (count($array) == 0) { return ''; } $ldate = array(date('Y', $array[0]['log_PostTime']), date('m', $array[0]['log_PostTime'])); $sql = $zbp->db->sql->Select($zbp->table['Post'], array('log_PostTime'), null, array('log_PostTime' => 'ASC'), array(1), null); $array = $zbp->db->Query($sql); if (count($array) == 0) { return ''; } $fdate = array(date('Y', $array[0]['log_PostTime']), date('m', $array[0]['log_PostTime'])); $arraydate = array(); for ($i = $fdate[0]; $i < $ldate[0] + 1; $i++) { for ($j = 1; $j < 13; $j++) { $arraydate[] = strtotime($i . '-' . $j); } } foreach ($arraydate as $key => $value) { if ($value - strtotime($ldate[0] . '-' . $ldate[1]) > 0) { unset($arraydate[$key]); } if ($value - strtotime($fdate[0] . '-' . $fdate[1]) < 0) { unset($arraydate[$key]); } } $arraydate = array_reverse($arraydate); $s = ''; $i = 0; foreach ($arraydate as $key => $value) { if ($i >= $maxli && $maxli > 0) { break; } $url = new UrlRule($zbp->option['ZC_DATE_REGEX']); $url->Rules['{%date%}'] = date('Y-n', $value); $url->Rules['{%year%}'] = date('Y', $value); $url->Rules['{%month%}'] = date('n', $value); $url->Rules['{%day%}'] = 1; $fdate = $value; $ldate = strtotime(date('Y-m-t', $value)) + 60 * 60 * 24; $sql = $zbp->db->sql->Count($zbp->table['Post'], array(array('COUNT', '*', 'num')), array(array('=', 'log_Type', '0'), array('=', 'log_Status', '0'), array('BETWEEN', 'log_PostTime', $fdate, $ldate))); $n = GetValueInArrayByCurrent($zbp->db->Query($sql), 'num'); if ($n > 0) { //$urls[]=array($url->Make(),str_replace(array('%y%', '%m%'), array(date('Y', $fdate), date('n', $fdate)), $zbp->lang['msg']['year_month']),$n); $meta = new Metas(); $meta->Url = $url->Make(); $meta->Name = str_replace(array('%y%', '%m%'), array(date('Y', $fdate), date('n', $fdate)), $zbp->lang['msg']['year_month']); $meta->Count = $n; $urls[] = $meta; $i++; } } $tags['urls'] = $urls; $template->SetTagsAll($tags); $ret = $template->Output('module-archives'); return $ret; }
public function Select($table, $select, $where, $order, $limit, $option) { global $zbp; $sqls = ''; $sqlw = ''; $sqlo = ''; $sqll = ''; if (!empty($select)) { if (is_array($select)) { $selectstr = implode($select, ','); $sqls = "SELECT {$selectstr} FROM {$table} "; } else { $sqls = "SELECT {$select} FROM {$table} "; } } $sqlw = $this->ParseWhere($where); if (!empty($order)) { $sqlo .= ' ORDER BY '; $comma = ''; foreach ($order as $k => $v) { $sqlo .= $comma . "{$k} {$v}"; $comma = ','; } } if (!empty($limit)) { if (!isset($limit[1])) { $sqll .= " LIMIT {$limit['0']}"; } else { if ($limit[1] > 0) { $sqll .= " LIMIT {$limit['0']}, {$limit['1']}"; } } } if (!empty($option)) { if (isset($option['pagebar'])) { if ($option['pagebar']->Count === null) { $s2 = $this->Count($table, array(array('COUNT', '*', 'num')), $where); $option['pagebar']->Count = GetValueInArrayByCurrent($zbp->db->Query($s2), 'num'); } $option['pagebar']->Count = (int) $option['pagebar']->Count; $option['pagebar']->make(); } } return $sqls . $sqlw . $sqlo . $sqll; }
/** * 构造查询语句 * @param string $table * @param string $select * @param string $where * @param string $order * @param string $limit * @param array|null $option * @return string 返回构造的语句 */ public function Select($table, $select = null, $where = null, $order = null, $limit = null, $option = null) { $this->ReplacePre($table); $sqlp = 'SELECT '; $sqls = ''; $sqlw = ''; $sqlg = ''; $sqlh = ''; $sqlo = ''; $sqll = ''; if (is_array($option) == false) { $option = array(); } $option = array_change_key_case($option); if (isset($option['sql_no_cache'])) { $sqlp .= 'SQL_NO_CACHE '; } if (isset($option['sql_cache'])) { $sqlp .= 'SQL_CACHE '; } if (isset($option['sql_buffer_result'])) { $sqlp .= 'SQL_BUFFER_RESULT '; } if (isset($option['select2count'])) { $sqls = $sqlp; if (is_array($select)) { foreach ($select as $key => $value) { if (count($value) == 3) { $sqls .= "{$value['0']}({$value['1']}) AS {$value['2']},"; } if (count($value) == 2) { $sqls .= "{$value['0']}({$value['1']}),"; } } $sqls = substr($sqls, 0, strlen($sqls) - 1); } else { $sqls .= $select; } } else { if (!empty($select)) { if (is_array($select)) { $selectstr = implode($select, ','); if (trim($selectstr) == '') { $selectstr = '*'; } $sqls = "{$sqlp} {$selectstr} "; } else { if (trim($sqls) == '') { $sqls = '*'; } $sqls = "{$sqlp} {$select} "; } } else { $sqls = "{$sqlp} *"; } } $sqls .= " FROM {$table} "; if (isset($option['useindex'])) { if (is_array($option['useindex'])) { $sqls .= 'USE INDEX (' . implode($option['useindex'], ',') . ') '; } else { $sqls .= 'USE INDEX (' . $option['useindex'] . ') '; } } if (isset($option['forceindex'])) { if (is_array($option['forceindex'])) { $sqls .= 'FORCE INDEX (' . implode($option['forceindex'], ',') . ') '; } else { $sqls .= 'FORCE INDEX (' . $option['forceindex'] . ') '; } } if (isset($option['ignoreindex'])) { if (is_array($option['ignoreindex'])) { $sqls .= 'IGNORE INDEX (' . implode($option['ignoreindex'], ',') . ') '; } else { $sqls .= 'IGNORE INDEX (' . $option['ignoreindex'] . ') '; } } if (!empty($where)) { if (isset($option['changewhere'])) { $sqlw = $this->ParseWhere($where, $option['changewhere']); } else { $sqlw = $this->ParseWhere($where); } } if (isset($option['groupby'])) { $sqlg = ' GROUP BY '; $comma = ''; if (!is_array($option['groupby'])) { $sqlg .= $option['groupby']; } else { foreach ($option['groupby'] as $k => $v) { $sqlg .= $comma . "{$v}"; $comma = ','; } } } if (isset($option['having'])) { $sqlh = ' HAVING '; $comma = ''; if (!is_array($option['having'])) { $sqlh .= $option['having']; } else { $sqlh .= $this->ParseWhere($option['having'], ''); } } if (!empty($order)) { $sqlo .= ' ORDER BY '; $comma = ''; if (!is_array($order)) { $sqlo .= $order; } else { foreach ($order as $k => $v) { $sqlo .= $comma . "{$k} {$v}"; $comma = ','; } } } if (!empty($limit)) { if (!is_array($limit)) { $sqll .= " LIMIT {$limit}"; } elseif (!isset($limit[1])) { $sqll .= " LIMIT {$limit['0']}"; } else { if ($limit[1] > 0) { //$sqll .= " LIMIT $limit[0], $limit[1]"; $sqll .= " LIMIT {$limit['1']} OFFSET {$limit['0']}"; } } } if (!empty($option)) { if (isset($option['pagebar'])) { if ($option['pagebar']->Count === null) { $s2 = $this->Count($table, array(array('COUNT', '*', 'num')), $where); $option['pagebar']->Count = GetValueInArrayByCurrent($this->db->Query($s2), 'num'); } $option['pagebar']->Count = (int) $option['pagebar']->Count; $option['pagebar']->make(); } } return $sqls . $sqlw . $sqlg . $sqlh . $sqlo . $sqll; }
/** * 构造查询语句 * @param string $table * @param string $select * @param string $where * @param string $order * @param string $limit * @param array|null $option * @return string 返回构造的语句 */ public function Select($table, $select = null, $where = null, $order = null, $limit = null, $option = null) { if (!is_array($option)) { $option = array(); } $sql = $this->get()->select($table)->option($option)->where($where)->orderBy($order)->limit($limit); if (isset($option['select2count'])) { foreach ($select as $key => $value) { if (count($value) > 2) { $sql->count(array_slice($value, 1)); } else { $sql->count($value); } } } else { if (!is_array($select)) { $select = array($select); } call_user_func_array(array($sql, 'column'), $select); } if (!empty($option)) { if (isset($option['pagebar'])) { if ($option['pagebar']->Count === null) { $s2 = $this->Count($table, array(array('*', 'num')), $where); $option['pagebar']->Count = GetValueInArrayByCurrent($this->db->Query($s2), 'num'); } $option['pagebar']->Count = (int) $option['pagebar']->Count; $option['pagebar']->make(); } } $sql = $sql->sql; return $sql; }
/** * 统计用户下的文章数、页面数、评论数、附件数等 * @param $member * @param array $plus 设置是否需要完全全表扫描 */ function CountMember(&$member, $plus = array(null, null, null, null)) { global $zbp; if (!$member instanceof Member) { return; } $id = $member->ID; if ($plus[0] === null) { $s = $zbp->db->sql->Count($zbp->table['Post'], array(array('COUNT', '*', 'num')), array(array('=', 'log_AuthorID', $id), array('=', 'log_Type', 0))); $member_Articles = GetValueInArrayByCurrent($zbp->db->Query($s), 'num'); $member->Articles = $member_Articles; } else { $member->Articles += $plus[0]; } if ($plus[1] === null) { $s = $zbp->db->sql->Count($zbp->table['Post'], array(array('COUNT', '*', 'num')), array(array('=', 'log_AuthorID', $id), array('=', 'log_Type', 1))); $member_Pages = GetValueInArrayByCurrent($zbp->db->Query($s), 'num'); $member->Pages = $member_Pages; } else { $member->Pages += $plus[1]; } if ($plus[2] === null) { $s = $zbp->db->sql->Count($zbp->table['Comment'], array(array('COUNT', '*', 'num')), array(array('=', 'comm_AuthorID', $id))); $member_Comments = GetValueInArrayByCurrent($zbp->db->Query($s), 'num'); $member->Comments = $member_Comments; } else { $member->Comments += $plus[2]; } if ($plus[3] === null) { $s = $zbp->db->sql->Count($zbp->table['Upload'], array(array('COUNT', '*', 'num')), array(array('=', 'ul_AuthorID', $id))); $member_Uploads = GetValueInArrayByCurrent($zbp->db->Query($s), 'num'); $member->Uploads = $member_Uploads; } else { $member->Uploads += $plus[3]; } }
/** * @todo * @override */ protected function buildCreate() { $sqlAll = array(); foreach ($this->table as $tableIndex => $table) { $sql = array(); $sql[] = 'CREATE SEQUENCE ' . $table . '_seq;'; $sql[] = 'CREATE TABLE ' . $table . ' ('; $idname = GetValueInArrayByCurrent($this->data, 0); $i = 0; foreach ($this->data as $key => $value) { if ($value[1] == 'integer') { if ($i == 0) { $sql[] = $value[0] . ' INT NOT NULL DEFAULT nextval(\'' . $table . '_seq\')' . ','; } else { if ($value[2] == '') { $sql[] = $value[0] . ' integer NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'tinyint') { $sql[] = $value[0] . ' integer NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'smallint') { $sql[] = $value[0] . ' smallint NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'mediumint') { $sql[] = $value[0] . ' integer NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'int') { $sql[] = $value[0] . ' integer NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif ($value[2] == 'bigint') { $sql[] = $value[0] . ' bigint NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } } } if ($value[1] == 'boolean') { $sql[] = $value[0] . ' char(1) NOT NULL DEFAULT \'' . (int) $value[3] . '\'' . ','; } if ($value[1] == 'string') { if ($value[2] != '') { if (strpos($value[2], 'char') !== false) { $sql[] = $value[0] . ' char(' . str_replace('char', '', $value[2]) . ') NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } elseif (is_int($value[2])) { $sql[] = $value[0] . ' varchar(' . $value[2] . ') NOT NULL DEFAULT \'' . $value[3] . '\'' . ','; } else { $sql[] = $value[0] . ' text NOT NULL DEFAULT \'\','; } } else { $sql[] = $value[0] . ' text NOT NULL DEFAULT \'\','; } } if ($value[1] == 'double') { $sql[] = $value[0] . " double precision NOT NULL DEFAULT 0" . ','; } if ($value[1] == 'float') { $sql[] = $value[0] . " real NOT NULL DEFAULT 0" . ','; } if ($value[1] == 'date' || $value[1] == 'time') { $sql[] = $value[0] . " {$value['1']} NOT NULL,"; } if ($value[1] == 'datetime') { $sql[] = $value[0] . " time NOT NULL,"; } if ($value[1] == 'timestamp') { $sql[] = $value[0] . " {$value['1']} NOT NULL DEFAULT CURRENT_TIMESTAMP,"; } $i += 1; } $sql[] = 'PRIMARY KEY (' . $idname . ')'; $sql[] = ');'; $sql[] = 'CREATE INDEX ' . $table . '_ix_id on ' . $table . '(' . $idname . ');'; $sqlAll[] = implode($sql, ' '); } $this->_sql = $sqlAll; }