public function update_all($data)
 {
     if (is_array($data)) {
         $update = array();
         foreach ($data as $key => $val) {
             $update[] = "`" . $key . "` = '" . $val . "'";
         }
         $setwhere = implode($update, ', ');
         XDB::query("UPDATE " . XDB::table($this->_table) . " SET " . $setwhere);
     }
 }
예제 #2
0
 public function check_moderator_for_uid($fid, $uid, $accessmasks = 0)
 {
     if (!intval($fid) || !intval($uid)) {
         return false;
     }
     if ($accessmasks) {
         $accessadd1 = ', a.allowview, a.allowpost, a.allowreply, a.allowgetattach, a.allowgetimage, a.allowpostattach';
         $accessadd2 = "LEFT JOIN " . XDB::table('forum_access') . " a ON a." . XDB::field('uid', $uid) . " AND a." . XDB::field('fid', $fid);
     }
     return XDB::fetch_first("SELECT ff.postperm, m.uid AS istargetmod {$accessadd1}\n\t\t\t\tFROM " . XDB::table($this->_table) . " ff\n\t\t\t\t{$accessadd2}\n\t\t\t\tLEFT JOIN " . XDB::table('forum_moderator') . " m ON m.fid=%d AND m.uid=%d\n\t\t\t\tWHERE ff.fid=%d", array($fid, $uid, $fid));
 }
예제 #3
0
 public function updatestar_by_bid($uid, $username, $bid, $star = 1)
 {
     !in_array($star, array(1, 2, 3, 4, 5)) && ($star = 1);
     $hcount = C::t('#sanree_brand#sanree_brand_voterlog')->getvoter_by_bid_uid($uid, $bid);
     if ($hcount > 0) {
         return 0;
     }
     $data = array('uid' => $uid, 'username' => $username, 'bid' => $bid, 'star' => $star, 'dateline' => TIMESTAMP);
     C::t('#sanree_brand#sanree_brand_voterlog')->insert($data);
     $tcount = $this->getvoter_by_bid($bid);
     if ($tcount > 0) {
         XDB::query("UPDATE " . XDB::table($this->_table) . " SET `star" . $star . "`= star" . $star . " + 1 WHERE `bid`=" . $bid);
     } else {
         $mdata = array('uid' => $uid, 'bid' => $bid, 'star' . $star => 1, 'dateline' => TIMESTAMP);
         $this->insert($mdata);
     }
     return 1;
 }
예제 #4
0
 public function fetch_all_for_manage($tableid, $inforum = '', $authorid = 0, $filename = '', $keyword = '', $sizeless = 0, $sizemore = 0, $dlcountless = 0, $dlcountmore = 0, $daysold = 0, $count = 0, $start = 0, $limit = 0)
 {
     $sql = "1";
     if (!is_numeric($tableid) || $tableid < 0 || $tableid > 9) {
         return;
     }
     if ($inforum) {
         $sql .= is_numeric($inforum) ? " AND t.fid=" . XDB::quote($inforum) : '';
         $sql .= $inforum == 'isgroup' ? ' AND t.isgroup=\'1\'' : ' AND t.isgroup=\'0\'';
     }
     if ($authorid) {
         $sql .= " AND a.uid=" . XDB::quote($authorid);
     }
     if ($filename) {
         $sql .= " AND a.filename LIKE " . XDB::quote('%' . $filename . '%');
     }
     if ($keyword) {
         $sqlkeywords = $or = '';
         foreach (explode(',', str_replace(' ', '', $keyword)) as $keyword) {
             $sqlkeywords .= " {$or} a.description LIKE " . XDB::quote('%' . $keyword . '%');
             $or = 'OR';
         }
         $sql .= " AND ({$sqlkeywords})";
     }
     $sql .= $sizeless ? " AND a.filesize>'{$sizeless}'" : '';
     $sql .= $sizemore ? " AND a.filesize<'{$sizemore}' " : '';
     $sql .= $dlcountless ? " AND ai.downloads<'{$dlcountless}'" : '';
     $sql .= $dlcountmore ? " AND ai.downloads>'{$dlcountmore}'" : '';
     $sql .= $daysold ? " AND a.dateline<'" . (TIMESTAMP - intval($daysold) * 86400) . "'" : '';
     if ($count) {
         return XDB::result_first("SELECT COUNT(*)\n\t\t\t\tFROM " . XDB::table('forum_attachment_' . $tableid) . " a\n\t\t\t\tINNER JOIN " . XDB::table('forum_attachment') . " ai USING(aid)\n\t\t\t\tINNER JOIN " . XDB::table('forum_thread') . " t\n\t\t\t\tINNER JOIN " . XDB::table('forum_forum') . " f\n\t\t\t\tWHERE t.tid=a.tid AND f.fid=t.fid AND t.displayorder>='0' AND {$sql}");
     }
     return XDB::fetch_all("SELECT a.*, ai.downloads, t.fid, t.tid, t.subject, f.name AS fname\n\t\t\t\tFROM " . XDB::table('forum_attachment_' . $tableid) . " a\n\t\t\t\tINNER JOIN " . XDB::table('forum_attachment') . " ai USING(aid)\n\t\t\t\tINNER JOIN " . XDB::table('forum_thread') . " t\n\t\t\t\tINNER JOIN " . XDB::table('forum_forum') . " f\n\t\t\t\tWHERE t.tid=a.tid AND f.fid=t.fid AND t.displayorder>='0' AND {$sql} ORDER BY a.aid DESC " . XDB::limit($start, $limit));
 }
예제 #5
0
 function get_forum_by_fid($fid, $field = '', $table = 'forum')
 {
     static $forumlist = array('forum' => array(), 'forumfield' => array());
     $table = $table != 'forum' ? 'forumfield' : 'forum';
     $return = array();
     if (!array_key_exists($fid, $forumlist[$table])) {
         $forumlist[$table][$fid] = XDB::fetch_first("SELECT * FROM " . XDB::table('forum_' . $table) . " WHERE fid=%d", array($fid));
         if (!is_array($forumlist[$table][$fid])) {
             $forumlist[$table][$fid] = array();
         }
     }
     if (!empty($field)) {
         $return = isset($forumlist[$table][$fid][$field]) ? $forumlist[$table][$fid][$field] : null;
     } else {
         $return = $forumlist[$table][$fid];
     }
     return $return;
 }
 public function addfield($addsql)
 {
     runquery("ALTER TABLE " . XDB::table($this->_table) . " ADD " . $addsql);
 }
예제 #7
0
 public function fetch_count()
 {
     return XDB::result_first("SELECT count(*) FROM " . XDB::table('forum_grouplevel'));
 }
예제 #8
0
 public function cleartable()
 {
     runquery("TRUNCATE TABLE `" . XDB::table($this->_table) . "`;");
 }
예제 #9
0
 public function fetch_all_group_for_user($uid, $count = 0, $ismanager = 0, $start = 0, $num = 0)
 {
     $uid = intval($uid);
     if (empty($uid)) {
         return array();
     }
     if (empty($ismanager)) {
         $levelsql = '';
     } elseif ($ismanager == 1) {
         $levelsql = ' AND level IN(1,2)';
     } elseif ($ismanager == 2) {
         $levelsql = ' AND level IN(3,4)';
     }
     if ($count == 1) {
         return XDB::result_first("SELECT count(*) FROM " . XDB::table('forum_groupuser') . " WHERE uid='{$uid}' {$levelsql}");
     }
     empty($start) && ($start = 0);
     empty($num) && ($num = 100);
     return XDB::fetch_all("SELECT fid, level FROM " . XDB::table('forum_groupuser') . " WHERE uid='{$uid}' {$levelsql} ORDER BY lastupdate DESC " . XDB::limit($start, $num));
 }
예제 #10
0
 public function optimize()
 {
     XDB::query('OPTIMIZE TABLE ' . XDB::table($this->_table), 'SILENT');
 }
예제 #11
0
 public function fetch_all_by_block($aids, $bannedids, $uids, $catid, $startrow, $items, $orderby)
 {
     $wheres = array();
     if ($aids) {
         $wheres[] = XDB::field('albumid', $aids, 'in');
     }
     if ($bannedids) {
         $wheres[] = XDB::field('albumid', $bannedids, 'notin');
     }
     if ($uids) {
         $wheres[] = XDB::field('uid', $uids, 'in');
     }
     if ($catid && !in_array('0', $catid)) {
         $wheres[] = XDB::field('catid', $catid, 'in');
     }
     $wheres[] = "friend = '0'";
     $wheresql = $wheres ? implode(' AND ', $wheres) : '1';
     if (!in_array($orderby, array('dateline', 'picnum', 'updatetime'))) {
         $orderby = 'dateline';
     }
     return XDB::fetch_all('SELECT * FROM ' . XDB::table($this->_table) . ' WHERE ' . $wheresql . ' ORDER BY ' . XDB::order($orderby, 'DESC') . XDB::limit($startrow, $items));
 }
예제 #12
0
 public function create_table($maxtableid)
 {
     if ($maxtableid) {
         XDB::query('SET SQL_QUOTE_SHOW_CREATE=0', 'SILENT');
         $db =& XDB::object();
         $query = XDB::query("SHOW CREATE TABLE %t", array($this->get_table_name()));
         $create = $db->fetch_row($query);
         $createsql = $create[1];
         $createsql = str_replace(XDB::table($this->get_table_name()), XDB::table($this->get_table_name($maxtableid)), $createsql);
         XDB::query($createsql);
         return true;
     } else {
         return false;
     }
 }
예제 #13
0
 public static function getposttable($tableid = 0, $prefix = false)
 {
     global $_G;
     $tableid = intval($tableid);
     if ($tableid) {
         loadcache('posttableids');
         $tableid = $_G['cache']['posttableids'] && in_array($tableid, $_G['cache']['posttableids']) ? $tableid : 0;
         $tablename = 'forum_post' . ($tableid ? "_{$tableid}" : '');
     } else {
         $tablename = 'forum_post';
     }
     if ($prefix) {
         $tablename = XDB::table($tablename);
     }
     return $tablename;
 }
예제 #14
0
 public function get_total_filesize()
 {
     $attachsize = 0;
     for ($i = 0; $i < 10; $i++) {
         $attachsize += XDB::result_first("SELECT SUM(filesize) FROM " . XDB::table('forum_attachment_' . $i));
     }
     return $attachsize;
 }