function modifyConditionData($modify_class) { $update_class = $_GET['update_class']; $update_value = $_GET['value']; $condition = $_GET['condition']; // cid or name | season or year $table_name = getTableName($modify_class); // 判斷 condition1 的種類 switch ($modify_class) { case SECTOR_GROUP_INFO: $condition1_col_name = 'name'; break; case TOP100_DATA: // top100用 year 找出對應當年份的季別 $condition1_col_name = 'company_id'; $condition[1] = $GLOBALS['dbc_object']->getTop100Season($condition[1]); $table_name = isTop100Info($update_class); // 確認要修改的項目是財務指標還是前百大資料 break; default: $condition1_col_name = 'company_id'; break; } // company_id = "1234" AND season = "2013Q2" // name = "1234" AND season = "2013Q2" // condition_str : 組成欲修改資料的條件 $condition_str = '`' . $condition1_col_name . '` = "' . $condition[0] . '"'; if (count($condition) > 1) { $condition_str .= ' AND `season`= "' . $condition[1] . '"'; } // 修改資料 if ($table_name) { $GLOBALS['dbc_object']->updateData($table_name, $update_class, $update_value, $condition_str); } }
function _post_save_vote(&$data, &$msg) { $msg->voteHash = md5(strtolower(substr($data['text'], 1))); // but if this person already voted, we need to unregister these previous votes DB_Update('UPDATE ' . getTableName('messages') . ' SET m_votehash = "", m_deleted = "Y" WHERE m_parent = ? AND m_author = ?', array($msg->parentKey, $msg->authorEntity->key())); DB_Update('DELETE FROM ' . getTableName('votes') . ' WHERE v_msg = ?', array($msg->parentKey)); // update the vote summary foreach (DB_GetList('SELECT COUNT(*) as votecount,m_data,m_id,m_votehash as count FROM ' . getTableName('messages') . ' WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash != "" GROUP BY m_votehash') as $vds) { $msgData = HubbubMessage::unpackData($vds); // get the some exemplary votes for this $voterList = array(); foreach (DB_GetList('SELECT m_author FROM ' . getTableName('messages') . ' WHERE m_parent = ? AND m_votehash = ? ORDER BY m_created DESC LIMIT 3', array($msg->parentKey, $vds['m_votehash'])) as $vex) { $voterList[] = $vex; } // if this is also what this message votes for, add it to the list if ($this->{$msg}->voteHash == $vds['m_votehash']) { $voterList[] = getDefault($msg->authorKey, $msg->ownerKey); } // make the vote summary dataset $voteDS = array('v_msg' => $msg->parentKey, 'v_choice' => $vds['m_votehash'], 'v_text' => $msgData['text'], 'v_voters' => implode(',', $voterList), 'v_count' => $vds['votecount']); DB_UpdateDataset('votes', $voteDS); } }
function InstallSampleData($mysqli) { $galleryTableName = getTableName("example_gallery"); $create = "CREATE TABLE `{$galleryTableName}` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `active` tinyint(4) DEFAULT NULL,\n `wysiwyg` text,\n `checkbox` tinyint(4) DEFAULT NULL,\n `color` varchar(10) DEFAULT NULL,\n `date` date DEFAULT NULL,\n `datetime` datetime DEFAULT NULL,\n `enum` enum('ENTRY 1','ENTRY 2','ENTRY 3') DEFAULT NULL,\n `multiselect` varchar(255) DEFAULT NULL,\n `numeric` int(11) DEFAULT NULL,\n `password` varchar(255) DEFAULT NULL,\n `salt` varchar(255) DEFAULT NULL,\n `radiobuttons` varchar(255) DEFAULT NULL,\n `select` varchar(255) DEFAULT NULL,\n `slider` int(11) DEFAULT NULL,\n `slug` varchar(255) DEFAULT NULL,\n `system` tinyint(4) DEFAULT NULL,\n `tags` varchar(255) DEFAULT NULL,\n `textarea` text,\n `textinput` varchar(255) DEFAULT NULL,\n `time` time DEFAULT NULL,\n `single_file` int(11) DEFAULT NULL,\n `user` int(11) DEFAULT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;"; $mysqli->query($create); $uiUsersTableName = getTableName("example_users"); $create = "CREATE TABLE `{$uiUsersTableName}` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `ui_id` int(4) DEFAULT NULL,\n `user_id` int(4) DEFAULT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; $mysqli->query($create); $uiFilesTableName = getTableName("example_files"); $create = "CREATE TABLE `{$uiFilesTableName}` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `file_id` int(4) DEFAULT NULL,\n `ui_id` int(4) DEFAULT NULL,\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; $mysqli->query($create); $insert = "INSERT INTO `{$uiUsersTableName}` (`ui_id`, `user_id`)\nVALUES\n (1, 1);"; $mysqli->query($insert); $insert = "INSERT INTO `{$galleryTableName}` (`id`, `active`, `wysiwyg`, `checkbox`, `color`, `date`, `datetime`, `enum`, `multiselect`, `numeric`, `password`, `salt`, `radiobuttons`, `select`, `slider`, `slug`, `system`, `tags`, `textarea`, `textinput`, `time`, `single_file`, `user`)\nVALUES\n (1, 1, '<u>Test</u>', 1, '#27cd2b', '2014-07-10', '2014-07-10 11:53:00', 'ENTRY 2', 'Option 1,Option 2', 634, '74d26f2ab730ac48ee8a9c8f494508a542a6273e', '537d2d1852208', 'Option 2', 'Select 2', 46, 'test-field', 2, 'tag1,tag 2,tag 3', 'Test Text Area', 'test field', '11:58:00', NULL, 1);"; $mysqli->query($insert); $columnsTableName = getTableName("directus_columns"); $insert = "INSERT INTO `{$columnsTableName}` ( `table_name`, `column_name`, `data_type`, `ui`, `system`, `master`, `hidden_input`, `hidden_list`, `required`, `relationship_type`, `table_related`, `junction_table`, `junction_key_left`, `junction_key_right`, `sort`, `comment`)\nVALUES\n ('example_gallery', 'id', NULL, 'numeric', 0, 0, 0, 0, 1, NULL, NULL, NULL, NULL, NULL, 1, ''),\n ('example_gallery', 'active', NULL, 'checkbox', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 2, ''),\n ('example_gallery', 'wysiwyg', NULL, 'wysiwyg', 0, 1, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 3, ''),\n ('example_gallery', 'checkbox', NULL, 'checkbox', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 4, ''),\n ('example_gallery', 'color', NULL, 'color', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 5, ''),\n ('example_gallery', 'date', NULL, 'date', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 6, ''),\n ('example_gallery', 'datetime', NULL, 'datetime', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 7, ''),\n ('example_gallery', 'enum', NULL, 'enum', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 8, ''),\n ('example_gallery', 'many_to_one', NULL, 'many_to_one', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 9, ''),\n ('example_gallery', 'multiselect', NULL, 'multi_select', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 10, ''),\n ('example_gallery', 'numeric', NULL, 'numeric', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 11, ''),\n ('example_gallery', 'password', NULL, 'password', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 12, ''),\n ('example_gallery', 'salt', NULL, 'salt', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 13, ''),\n ('example_gallery', 'radiobuttons', NULL, 'radiobuttons', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 14, ''),\n ('example_gallery', 'select', NULL, 'select', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 15, ''),\n ('example_gallery', 'slider', NULL, 'slider', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 16, ''),\n ('example_gallery', 'slug', NULL, 'slug', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 17, ''),\n ('example_gallery', 'system', NULL, 'system', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 18, ''),\n ('example_gallery', 'tags', NULL, 'tags', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 19, ''),\n ('example_gallery', 'textarea', NULL, 'textarea', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 20, ''),\n ('example_gallery', 'textinput', NULL, 'textinput', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 21, ''),\n ('example_gallery', 'time', NULL, 'time', 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 22, ''),\n ('example_gallery', 'single_file', 'INT', 'single_file', 0, 0, 0, 0, 0, 'MANYTOONE', 'directus_files', NULL, NULL, 'single_file', 9999, ''),\n ('example_gallery', 'user', 'INT', 'many_to_one', 0, 0, 0, 0, 0, 'MANYTOONE', 'directus_users', NULL, NULL, 'user', 9999, ''),\n ('example_gallery', 'users', 'MANYTOMANY', 'many_to_many', 0, 0, 0, 0, 1, 'MANYTOMANY', 'directus_users', 'example_users', 'ui_id', 'user_id', 9999, ''),\n ('example_gallery', 'files', 'MANYTOMANY', 'multiple_files', 0, 0, 0, 0, 0, 'MANYTOMANY', 'directus_files', 'example_files', 'ui_id', 'file_id', 9999, '');"; $mysqli->query($insert); $columnsTableName = getTableName("directus_tables"); $insert = "INSERT INTO `{$columnsTableName}` (`table_name`, `hidden`, `single`, `is_junction_table`, `footer`, `list_view`, `column_groupings`, `primary_column`, `user_create_column`, `user_update_column`, `date_create_column`, `date_update_column`, `filter_column_blacklist`)\nVALUES\n ('example_gallery',0,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),\n ('example_users',1,0,1,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),\n ('example_files',1,0,1,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);"; $mysqli->query($insert); $directusPrivilegesTableName = getTableName("directus_privileges"); $insert = "INSERT INTO `{$directusPrivilegesTableName}` (`id`, `table_name`, `group_id`, `read_field_blacklist`, `write_field_blacklist`, `nav_listed`, `allow_view`, `allow_add`, `allow_edit`, `allow_delete`, `allow_alter`, `status_id`)\nVALUES\n (DEFAULT, 'example_gallery',1,NULL,NULL,1,2,1,2,2,1,NULL),\n (DEFAULT, 'example_users',1,NULL,NULL,1,2,1,2,2,1,NULL),\n (DEFAULT, 'example_files',1,NULL,NULL,1,2,1,2,2,1,NULL);"; $mysqli->query($insert); $directusUITableName = getTableName("directus_ui"); $insert = "INSERT INTO `{$directusUITableName}` (`table_name`, `column_name`, `ui_name`, `name`, `value`)\nVALUES\n ('example_gallery', 'radiobuttons', 'radiobuttons', 'options', 'Option 1,Option 2,Option 3'),\n ('example_gallery', 'multiselect', 'multi_select', 'type', 'select_list'),\n ('example_gallery', 'multiselect', 'multi_select', 'delimiter', ','),\n ('example_gallery', 'multiselect', 'multi_select', 'options', '{\r\n\"Option 1\":\"option_1\",\r\n\"Option 2\":\"option_2\",\r\n\"Option 3\":\"option_3\"\r\n}'),\n ('example_gallery', 'password', 'password', 'require_confirmation', '1'),\n ('example_gallery', 'password', 'password', 'salt_field', 'salt'),\n ('example_gallery', 'select', 'select', 'options', '{\r\n\"Select 1\":\"select_1\",\r\n\"Select 2\":\"select_2\",\r\n\"Select 3\":\"select_3\"\r\n}'),\n ('example_gallery', 'select', 'select', 'allow_null', '0'),\n ('example_gallery', 'select', 'select', 'placeholder_text', ''),\n ('example_gallery', 'slider', 'slider', 'minimum', '0'),\n ('example_gallery', 'slider', 'slider', 'maximum', '100'),\n ('example_gallery', 'slider', 'slider', 'step', '2'),\n ('example_gallery', 'slug', 'slug', 'readonly', '1'),\n ('example_gallery', 'slug', 'slug', 'size', 'large'),\n ('example_gallery', 'slug', 'slug', 'mirrored_field', 'textinput'),\n ('example_gallery', 'user', 'many_to_one', 'readonly', '0'),\n ('example_gallery', 'user', 'many_to_one', 'visible_status_ids', '1'),\n ('example_gallery', 'user', 'many_to_one', 'visible_column', 'email'),\n ('example_gallery', 'user', 'many_to_one', 'visible_column_template', '{{email}}'),\n ('example_gallery', 'user', 'many_to_one', 'placeholder_text', ''),\n ('example_gallery', 'user', 'many_to_one', 'filter_type', 'dropdown'),\n ('example_gallery', 'user', 'many_to_one', 'filter_column', 'email'),\n ('example_gallery', 'users', 'many_to_many', 'visible_columns', 'email'),\n ('example_gallery', 'users', 'many_to_many', 'add_button', '0'),\n ('example_gallery', 'users', 'many_to_many', 'choose_button', '1'),\n ('example_gallery', 'users', 'many_to_many', 'remove_button', '1'),\n ('example_gallery', 'users', 'many_to_many', 'filter_type', 'dropdown'),\n ('example_gallery', 'users', 'many_to_many', 'filter_column', 'email'),\n ('example_gallery', 'users', 'many_to_many', 'visible_column_template', '{{email}}'),\n ('example_gallery', 'files', 'multiple_files', 'add_button', '0'),\n ('example_gallery', 'files', 'multiple_files', 'choose_button', '1'),\n ('example_gallery', 'files', 'multiple_files', 'remove_button', '1');"; $mysqli->query($insert); }
function getFriends($eid) { $result = array(); foreach(DB_GetList('SELECT * FROM '.getTableName('connections').' WHERE c_from = ?', array($eid)) as $cds) { $result[] = $cds['c_to']; } return($result); }
function getScoreList($level) { $tableName = getTableName($level); $sql = "SELECT name, score FROM {$tableName} order by score desc limit 15"; $res = mysql_query($sql); $temp = array(); while ($row = mysql_fetch_assoc($res)) { array_push($temp, $row); } return json_encode($temp); }
function __init() { access_policy('auth'); foreach(DB_GetList('SELECT c_status,COUNT(*) as count FROM '.getTableName('connections').' WHERE c_from = ? GROUP BY c_status', array($this->user->entity)) as $item) $menuCount[$item['c_status']] = $item['count']; $countArray = array(); if($menuCount['friend'] > 0) $countArray[] = ' ('.$menuCount['friend'].')'; else $countArray[] = ''; $countArray[] = ''; if($menuCount['req.rcv'] > 0) $countArray[] = ' ('.$menuCount['req.rcv'].')'; else $countArray[] = ''; if($menuCount['req.sent'] > 0) $countArray[] = ' ('.$menuCount['req.sent'].')'; else $countArray[] = ''; $this->menu = $this->makeMenu('index,add,ab,rcv', $countArray); $this->invokeModel(); $this->myEntity = $this->user->selfEntity(); $this->integrate('ab'); }
function getComments($forPostKey, $getLimit = 3) { $countDS = DB_GetDatasetWQuery('SELECT COUNT(*) as count FROM '.getTableName('messages').' WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash = "" ', array($forPostKey)); return(array( 'count' => $countDS['count'], 'votes' => DB_GetList('SELECT COUNT(*) as votecount,m_data,m_id as count FROM '.getTableName('messages').' WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash != "" GROUP BY m_votehash ORDER BY votecount DESC, m_created ASC LIMIT 10 ', array($forPostKey)), 'list' => array_reverse(DB_GetList('SELECT * FROM '.getTableName('messages').' WHERE m_parent = ? AND m_deleted = "N" AND m_type="post" AND m_votehash = "" ORDER BY m_created DESC LIMIT '.$getLimit, array($forPostKey))), )); }
function feed_poll_receive(&$data, &$msg) { if (!$msg->validateSignature()) { return true; } $forServer = new HubbubServer($msg->authorEntity->ds['server']); $msg->response['listing_time'] = time(); $msg->response['_listing_from_date'] = gmdate('Y-m-d H:i:s', $msg->data['last']); $msg->response['_listing_to_date'] = gmdate('Y-m-d H:i:s'); $msg->response['_for_server'] = $msg->authorEntity->ds['server'] . ':' . $forServer->ds['s_key']; $serverKey = $forServer->ds['s_key']; // let's get a list of items $msg->response['feed'] = array(); foreach (DB_GetList('SELECT * FROM ' . getTableName('messages') . ' LEFT JOIN ' . getTableName('connections') . ' ON (c_toserverkey = ' . $serverKey . ' AND (c_from = m_owner OR c_from = m_author)) ' . ' WHERE c_toserverkey > 0 AND m_publish="Y" AND m_changed >= "' . ($msg->data['last'] + 0) . '" ' . ' GROUP BY m_key ' . ' LIMIT ' . cfg('service/maxfeedsize', 200)) as $msgDS) { $resultCount++; $msg->response['feed'][] = json_decode(gzinflate($msgDS['m_data']), true); } $msg->response['_count'] = $resultCount; $msg->ok(); }
function friend_ignore($entityKey) { DB_Update('DELETE FROM '.getTableName('connections').' WHERE c_from = ? AND c_to = ?', array(object('user')->ds['u_entity'], $entityKey)); }
function addClassScore($uid, $semester) { $sum = 0; $sql = "SELECT id,ratio FROM class_type"; $res = mysql_query($sql); while ($arr = @mysql_fetch_assoc($res)) { $table = getTableName($semester, $arr["id"]); $sql2 = "SELECT average FROM {$table} WHERE uid = {$uid}"; $res2 = mysql_query($sql2); $arr2 = @mysql_fetch_assoc($res2); if ($arr2["average"]) { $sum += $arr2["average"] * $arr["ratio"]; } else { $sum = 0; break; } } $sql3 = "UPDATE score SET class_score = {$sum} WHERE uid = {$uid} AND semester = {$semester}"; mysql_query($sql3); }
/** * 获取审批吧主列表 * @access private * @param string $fid 贴吧id * @param string $is_pass 是否通过 * @return array */ private function getManagerPendList($fid, $is_pass) { $u = getTableName('users'); $fma = getTableName('forum_manager_apply'); if ($is_pass == 0) { $condition["{$fma}.is_pass"] = 0; } elseif ($is_pass == 1) { $condition["{$fma}.is_pass"] = array('neq', 0); } $condition["{$fma}.forum_id"] = $fid; $count = M('forum_manager_apply')->where($condition)->count(); $Pager = new \Tieba\Library\Pager($count, 20, 'active', true); $show = $Pager->show(); $info = M('forum_manager_apply')->field("{$u}.user_name,{$fma}.data_id,{$fma}.user_id,{$fma}.apply_date,{$fma}.apply_type,{$fma}.apply_content")->join("{$u} ON {$fma}.user_id = {$u}.user_id")->where($condition)->limit($Pager->firstRow . ',' . $Pager->listRows)->select(); foreach ($info as $key => $value) { $info[$key]['user_age'] = A('Home')->getAge($info[$key]['user_id']); $info[$key]['post_count'] = A('Home')->getPostCount($info[$key]['user_id']); $info[$key]['apply_type_cn'] = $info[$key]['apply_type'] == 0 ? '吧主' : '小吧主'; $info[$key]['user_level'] = A('Home')->getLevel($info[$key]['user_id'], $fid); } $array[0] = $info; $array[1] = $show; $array[2] = $count; $array[3] = $Pager->totalPages; return $array; }
function GetClosestServers($entityId) { return DB_GetList('SELECT *,SUM(c_count_sent) as sent_count FROM ' . getTableName('connections') . ' LEFT JOIN ' . getTableName('servers') . ' ON (c_toserverkey = s_key) WHERE c_from = "' . ($entityId + 0) . '" and c_status="friend" GROUP BY c_toserverkey ORDER BY sent_count DESC LIMIT ' . getDefault($GLOBALS['config']['service']['dmn_maxsize'], 10)); }
/** * 获取帖子的楼层引用(回复) * @access private * @param string $rid 回复的帖子id * @return string */ private function getReply($rid) { $u = getTableName('users'); $p = getTableName('post'); if ($rid != '0') { $info = M('post')->field("{$p}.user_id,{$u}.user_name,{$p}.post_content,{$p}.floor_id")->join("{$u} ON {$p}.user_id = {$u}.user_id")->where(array("{$p}.post_id" => $rid))->find(); $html = '<blockquote class="d_quote"><fieldset><legend> 回复 <a class="at j_user_card" data-uid="' . $info['user_id'] . '" target="_blank" href="' . U('Home/main', array('id' => $info['user_id'])) . '">@' . $info['user_name'] . '</a> (' . $info['floor_id'] . '楼) </legend> <p class="quote_content">' . $info['post_content'] . '</p></fieldset></blockquote>'; return $html; } else { return; } }
function __construct() { $this->reflection = new ReflectionObject($this); $this->table_name = getTableName(); }
/** * 获取精品列表 * @access private * @param string $uid 用户id * @return array */ private function getGoodList($uid) { $tt = getTableName('thread_type'); $t = getTableName('thread'); $l = getTableName('log'); $u = getTableName('users'); $f = getTableName('forum'); $condition["{$t}.user_id"] = $uid; $condition["{$tt}.thread_type"] = array('in', array('good', 'good,top')); $condition["{$l}.log_type"] = 'set-good'; $join1 = "{$tt} ON {$t}.thread_id = {$tt}.thread_id"; $join2 = "{$l} ON {$t}.thread_id = {$l}.object_id"; $count = M('thread')->join($join1)->join($join2)->where($condition)->count(); $Pager = new \Tieba\Library\Pager($count, 20, 'cur', false); $show = $Pager->show(); $info = M('thread')->field("{$t}.thread_id,{$t}.thread_title,{$t}.forum_id,{$f}.forum_name,{$l}.log_date,{$l}.user_id,{$u}.user_name")->join($join1)->join($join2)->join("{$f} ON {$t}.forum_id = {$f}.forum_id")->join("{$u} ON {$l}.user_id = {$u}.user_id")->where($condition)->group("{$l}.object_id")->order("{$l}.log_date desc")->limit($Pager->firstRow . ',' . $Pager->listRows)->select(); $array[0] = $info; $array[1] = $show; return $array; }
/** * 获取搜索结果列表 * @access private * @param string $fid 贴吧id * @param string $word 关键字 * @param string $order 排序方式 * @return array */ private function getSearchResultList($fid, $word, $order) { $f = getTableName('forum'); $p = getTableName('post'); $t = getTableName('thread'); $u = getTableName('users'); if ($fid != '') { $condition_is_forum = "AND {$t}.forum_id='{$fid}'"; } else { $condition_is_forum = ''; } switch ($order) { case '': $order = "post_date desc"; break; case 'date': $order = "post_date asc"; break; case 'thread': $condition_is_thread = "AND {$p}.floor_id=1"; $order = "post_date desc"; break; } $sql = "(SELECT tb_post.thread_id,tb_thread.thread_title,tb_post.post_content,tb_post.post_id,tb_post.post_date,tb_post.user_id,tb_forum.forum_name,tb_thread.forum_id,tb_users.user_name,tb_post.floor_id FROM `tb_post` INNER JOIN tb_thread ON tb_post.thread_id = tb_thread.thread_id INNER JOIN tb_forum ON tb_thread.forum_id = tb_forum.forum_id INNER JOIN tb_users ON tb_post.user_id = tb_users.user_id WHERE tb_post.post_content LIKE '%{$word}%' AND tb_post.is_exist = 1 {$condition_is_forum} {$condition_is_thread}) UNION (SELECT tb_post.thread_id,tb_thread.thread_title,tb_post.post_content,tb_post.post_id,tb_post.post_date,tb_post.user_id,tb_forum.forum_name,tb_thread.forum_id,tb_users.user_name,tb_post.floor_id FROM `tb_thread` INNER JOIN tb_post ON tb_post.thread_id = tb_thread.thread_id INNER JOIN tb_forum ON tb_thread.forum_id = tb_forum.forum_id INNER JOIN tb_users ON tb_post.user_id = tb_users.user_id WHERE tb_thread.thread_title LIKE '%{$word}%' AND tb_thread.is_exist = 1 AND tb_post.floor_id=1 {$condition_is_forum}) "; $count_array = M()->query($sql); $count = count($count_array); $Pager = new \Tieba\Library\Pager($count, 20, 'cur', false); $sql_end = "ORDER BY {$order} LIMIT {$Pager->firstRow},{$Pager->listRows}"; $show = $Pager->show(); //开始计时 $s_time = microtime(true); // $info = M('post')->field("{$p}.thread_id,{$t}.thread_title,{$p}.post_content,{$p}.post_id,{$p}.post_date,{$p}.user_id,{$f}.forum_name,{$t}.forum_id,{$u}.user_name,{$p}.floor_id")->join($join)->join("{$f} ON {$t}.forum_id = {$f}.forum_id")->join("{$u} ON {$p}.user_id = {$u}.user_id") // ->where($condition)->group("{$p}.post_id")->order($order)->limit($Pager->firstRow . ',' . $Pager->listRows)->select(); $info = M()->query($sql . $sql_end); foreach ($info as $key => $value) { $info[$key]['post_content_convert'] = $this->getThreadText($info[$key]['post_content'], 'post'); $info[$key]['post_content_convert'] = str_replace($word, '<em>' . $word . '</em>', $info[$key]['post_content_convert']); $info[$key]['thread_title_convert'] = str_replace($word, '<em>' . $word . '</em>', $info[$key]['thread_title']); } //结束计时 $e_time = microtime(true); $total_time = number_format($e_time - $s_time, 3); $array[0] = $info; $array[1] = $show; $array[2] = $count; $array[3] = $total_time; return $array; }
/** * 获取有图的帖子 * @access public * @return string */ public function getThreadHasImgList() { $t = getTableName('thread'); $p = getTableName('post'); $info = M('thread')->field("{$t}.thread_id,{$t}.thread_title,{$p}.post_content")->join("{$p} ON {$t}.thread_id = {$p}.thread_id")->where(array("{$p}.floor_id" => 1, "{$t}.is_exist" => 1, "{$p}.post_content" => array('like', '%[img]%[/img]%')))->order("{$p}.post_date desc")->limit(6)->select(); foreach ($info as $key => $value) { $info[$key]['thread_image'] = $this->getThreadImg($info[$key]['post_content']); } return $info; }
<? $myOldUsername = $this->user->getUsername(); $ctr = 1; // let's get the attributes exported to us from other services $infoDS = DB_Getdataset('idaccounts', $this->user->key(), 'ia_user'); $twitterInfo = json_decode($infoDS['ia_properties'], true); $fbInfo = $twitterInfo; $openInfo = $twitterInfo; // let's try to determine sensible user data from the login services $idAccountWithEmail = DB_GetDatasetWQuery('SELECT * FROM '.getTableName('idaccounts').' WHERE ia_user=? AND ia_type = "email"', array($this->user->key())); $defaultEmail = getDefault($openInfo['contact/email'], $fbInfo['email'], $idAccountWithEmail['ia_url']); // determining a default username idea $emlName = trim(substr($defaultEmail, 0, strpos($defaultEmail, '@'))); $defaultUsername = safename(getDefault($twitterInfo['screen_name'], $fbInfo['first_name'], $emlName, $openInfo['namePerson/friendly'])); if($defaultUsername != '' && !HubbubEntity::isNameAvailable($defaultUsername)) { do { $defaultUsername2 = $defaultUsername.$ctr++; } while (!HubbubEntity::isNameAvailable($defaultUsername2)); $defaultUsername = $defaultUsername2; } // making a reasonable default name of of the email address $nameParts = array(); foreach(explode('.', $defaultUsername) as $namePart) $nameParts[] = strtoupper(substr($namePart, 0, 1)).strtolower(substr($namePart, 1)); $emailNameReconstruction = implode(' ', $nameParts);
function PageCompListMembers($list, $table, $sqlWho, $sqlWhom, $sqlSelectAdd = '', $sqlWhereAdd = '', $sqlOrderAdd = '') { global $memberID; global $site; global $dir; global $tmpl; $form = "{$table}_{$list}"; if ($list == '') { $query = "\n\t\t\tSELECT\n\t\t\t\tIF( `{$table}`.`{$sqlWho}` = {$memberID}, `{$table}`.`{$sqlWhom}`, `{$table}`.`{$sqlWho}` ) AS `{$sqlWhom}`,\n\t\t\t\t`Profiles`.`NickName`\n\t\t\t\t{$sqlSelectAdd}\n\t\t\tFROM `{$table}`\n\t\t\tLEFT JOIN `Profiles`\n\t\t\t\tON `Profiles`.`ID` = IF( `{$table}`.`{$sqlWho}` = {$memberID}, `{$table}`.`{$sqlWhom}`, `{$table}`.`{$sqlWho}` )\n\t\t\tWHERE\n\t\t\t\t( `{$table}`.`{$sqlWho}` = {$memberID} OR `{$table}`.`{$sqlWhom}` = {$memberID} )\n\t\t\t\t{$sqlWhereAdd}\n\t\t\tORDER BY {$sqlOrderAdd} `Profiles`.`NickName` ASC\n\t\t"; } else { $query = "\n\t\t\tSELECT\n\t\t\t\t`{$table}`.`{$sqlWho}`,\n\t\t\t\t`{$table}`.`{$sqlWhom}`,\n\t\t\t\t`Profiles`.`NickName`\n\t\t\t\t{$sqlSelectAdd}\n\t\t\tFROM `{$table}`\n\t\t\tLEFT JOIN `Profiles`\n\t\t\t\tON `Profiles`.`ID` = `{$table}`.`{$sqlWhom}`\n\t\t\tWHERE\n\t\t\t\t`{$table}`.`{$sqlWho}` = {$memberID}\n\t\t\t\t{$sqlWhereAdd}\n\t\t\tORDER BY {$sqlOrderAdd} `Profiles`.`NickName` ASC\n\t\t"; } $rMembers = db_res($query); if ($num_res = mysql_num_rows($rMembers)) { $sWhole = file_get_contents("{$dir['root']}templates/tmpl_{$tmpl}/contacts_tmpl.html"); $aMyTmpl = preg_split("/\\{\\/?InsertRows\\}/", $sWhole); $tmplRow = $aMyTmpl[1]; $sWhole = "{$aMyTmpl[0]}{InsertRows /}{$aMyTmpl[2]}"; $InsertRows = ''; $tr_class = 'odd'; while ($aMember = mysql_fetch_assoc($rMembers)) { $aReplace = array(); $aReplace['ID'] = $aMember[$sqlWhom]; $aReplace['CheckBoxName'] = "mem[{$aMember[$sqlWhom]}]"; if ($aMember[$sqlWhom] > 0) { $aReplace['Thumbnail'] = get_member_icon($aMember[$sqlWhom], 'left'); $aReplace['NickName'] = "<a href=\"" . getProfileLink($aMember[$sqlWhom]) . "\">{$aMember['NickName']}</a>"; $aReplace['SendGreet'] = sendKissPopUp($aMember[$sqlWhom]); $aReplace['SendMsg'] = "\n\t\t\t\t <a href=\"{$site['url']}compose.php?ID={$aMember[$sqlWhom]}\" title=\"" . _t('_Send Message') . "\">\n\t\t\t\t\t<img src=\"" . getTemplateIcon('compose.png') . "\" alt=\"" . _t('_Send Message') . "\" />\n\t\t\t\t </a>"; } else { $aReplace['Thumbnail'] = ''; $aReplace['NickName'] = _t('_Visitor'); $aReplace['SendGreet'] = ''; $aReplace['SendMsg'] = ''; } $aReplace['Times'] = $aMember['Number'] ? _t("_N times", $aMember['Number']) : ' '; $aReplace['PicNew'] = $aMember['New'] ? '<img src="' . getTemplateIcon('new.gif') . '" class="pic_new" />' : ''; $aReplace['Date'] = $aMember['Arrived'] ? $aMember['Arrived'] : ' '; $aReplace['tr_class'] = $tr_class; $sInsertRow = $tmplRow; foreach ($aReplace as $key => $val) { $sInsertRow = str_replace("{{$key}}", $val, $sInsertRow); } $sInsertRows .= $sInsertRow; $tr_class = $tr_class == 'odd' ? 'even' : 'odd'; } $aReplace = array(); $aReplace['InsertRows /'] = $sInsertRows; $aReplace['Self'] = $_SERVER['PHP_SELF'] . '?show=' . $_GET['show'] . '&list=' . $_GET['list']; $aReplace['FormName'] = "{$form}_form"; $aReplace['CheckAll'] = _t('_Check all'); $aReplace['UncheckAll'] = _t('_Uncheck all'); $aReplace['Actions'] = getButtons($form); foreach ($aReplace as $key => $val) { $sWhole = str_replace("{{$key}}", $val, $sWhole); } // unset "new" flag for kisses if ($table == 'VKisses' and $list == 'me') { db_res("UPDATE `VKisses` SET `New`='0' WHERE `Member`={$memberID} AND `New`='1'"); } } else { $sWhole = file_get_contents("{$dir['root']}templates/tmpl_{$tmpl}/contacts_tmpl_nores.html"); $aReplace = array(); $aReplace['NoResults'] = _t('_No members found here'); foreach ($aReplace as $key => $val) { $sWhole = str_replace("{{$key}}", $val, $sWhole); } } $sWhole = str_replace('{TableCaption}', getTableName($form, $num_res), $sWhole); return $sWhole; }
function clearAllTables() { $this->skipView = true; foreach(explode(',', 'auditlog,connections,entities,idaccounts,localgroups,messages,nvstore,servers,usagestats,users,votes') as $table) DB_Update('TRUNCATE '.getTableName($table)); }
function DB_GetDatasetMatch($table, $matchOptions, $fillIfEmpty = true, $noMatchOptions = array()) { DB_Connect(); $where = array('1'); if (!is_array($matchOptions)) { $matchOptions = stringParamsToArray($matchOptions); } foreach ($matchOptions as $k => $v) { $where[] = '(' . $k . '="' . DB_Safe($v) . '")'; } foreach ($noMatchOptions as $k => $v) { $where[] = '(' . $k . '!="' . DB_Safe($v) . '")'; } $iwhere = implode(' AND ', $where); $query = 'SELECT * FROM ' . getTableName($table) . ' WHERE ' . $iwhere; $resultDS = DB_GetDatasetWQuery($query); if ($fillIfEmpty && sizeof($resultDS) == 0) { foreach ($matchOptions as $k => $v) { $resultDS[$k] = $v; } } profile_point('DB_GetDatasetMatch(' . $table . ', ' . $iwhere . ')'); return $resultDS; }