📄 mtdb_base.php
字号:
if ($results) { foreach ($results as $row) { $this->_comment_count_cache[$row[0]] = $row[1]; } } } function blog_entry_count($blog_id) { $count = $this->get_var(" select count(*) from mt_entry where entry_blog_id = $blog_id and entry_status = 2"); return $count; } function blog_comment_count($blog_id) { $count = $this->get_var(" select count(*) from mt_entry, mt_comment where entry_blog_id = $blog_id and entry_status = 2 and comment_visible = 1 and comment_entry_id = entry_id"); return $count; } function entry_comment_count($entry_id) { if (isset($this->_comment_count_cache[$entry_id])) { return $this->_comment_count_cache[$entry_id]; } $count = $this->get_var(" select count(*) from mt_comment and comment_visible = 1 where comment_entry_id = $entry_id "); $this->_comment_count_cache[$entry_id] = $count; return $count; } function &fetch_comments($args) { $entry_id = $args['entry_id']; # load comments $limit = isset($args['lastn']) ? $args['lastn'] : null; if ($limit > 0) { $limit = "limit $limit"; } else { $limit = ''; } if (isset($args['offset'])) { $offset = 'offset '.intval($args['offset']); } else { $offset = ''; } $order = ''; if (isset($args['sort_order'])) { if ($args['sort_order'] == 'ascend') { $order = 'asc'; } elseif ($args['sort_order'] == 'descend') { $order = 'desc'; } } $comments = $this->get_results(" select * from mt_comment where comment_entry_id = $entry_id and comment_visible = 1 order by comment_created_on $order $limit $offset", ARRAY_A); if (!is_array($comments)) return array(); return $comments; } function cache_ping_counts(&$entry_list) { $id_list = ''; foreach ($entry_list as $entry_id) { if (!isset($this->_ping_count_cache[$entry_id])) { $id_list .= ','.$entry_id; } } $id_list = substr($id_list, 1); if (empty($id_list)) return; $query = " select trackback_entry_id, count(*) from mt_trackback, mt_tbping where trackback_entry_id in ($id_list) and tbping_tb_id = trackback_id group by trackback_entry_id "; $results = $this->get_results($query, ARRAY_N); foreach ($entry_list as $entry_id) { $this->_ping_count_cache[$entry_id] = 0; } if ($results) { foreach ($results as $row) { $this->_ping_count_cache[$row[0]] = $row[1]; } } } function entry_ping_count($entry_id) { if (isset($this->_ping_count_cache[$entry_id])) { return $this->_ping_count_cache[$entry_id]; } $count = $this->get_var(" select count(*) from mt_trackback, mt_tbping where trackback_entry_id = $entry_id and tbping_tb_id = trackback_id "); $_ping_count_cache[$entry_id] = $count; return $count; } function &fetch_pings($args) { $entry_id = $args['entry_id']; # load pings $limit = $args['lastn']; if ($limit > 0) { $limit = "limit $limit"; } else { $limit = ''; } $order = 'asc'; if (isset($args['sort_order'])) { if ($args['sort_order'] == 'descend') { $order = 'desc'; } } $pings = $this->get_results(" select * from mt_trackback, mt_tbping where trackback_entry_id = '$entry_id' and tbping_tb_id = trackback_id order by tbping_created_on $order $limit", ARRAY_A); return $pings; } function cache_categories(&$entry_list) { $id_list = ''; foreach ($entry_list as $entry_id) { if (!isset($this->_cat_id_cache['e'.$entry_id])) { $id_list .= ','.$entry_id; } } $id_list = substr($id_list, 1); if (!$id_list) return; $query = " select * from mt_category, mt_placement where placement_entry_id in ($id_list) and placement_category_id = category_id and placement_is_primary = 1 "; $results = $this->get_results($query, ARRAY_A); foreach ($entry_list as $entry_id) { $this->_cat_id_cache['e'.$entry_id] = null; } if (is_array($results)) { foreach ($results as $row) { $entry_id = $row['placement_entry_id']; $this->_cat_id_cache['e'.$entry_id] = $row; $cat_id = $row['category_id']; $this->_cat_id_cache['c'.$cat_id] = $row; } } } function &fetch_category($cat_id) { if (isset($this->_cat_id_cache['c'.$cat_id])) { return $this->_cat_id_cache['c'.$cat_id]; } $cats =& $this->fetch_categories(array('category_id' => $cat_id)); if ($cats && (count($cats) > 0)) { $this->_cat_id_cache['c'.$cat_id] = $cats[0]; return $cats[0]; } else { return null; } } function &fetch_blog($blog_id) { if (isset($this->_blog_id_cache[$blog_id])) { return $this->_blog_id_cache[$blog_id]; } list($blog) = $this->load('blog', $blog_id); $this->_blog_id_cache[$blog_id] = $blog; return $blog; } function &get_archive_list($args) { $blog_id = $args['blog_id']; if (($n = $args['lastn']) && ($n > 0)) { $limit = "limit $n"; } else { $limit = ''; } $at = $args['archive_type']; if ($at == 'Daily') { $group_sql = " select count(*), extract(year from entry_created_on), extract(month from entry_created_on), extract(day from entry_created_on) from mt_entry where entry_blog_id = $blog_id and entry_status = 2 group by extract(year from entry_created_on), extract(month from entry_created_on), extract(day from entry_created_on) order by extract(year from entry_created_on) desc, extract(month from entry_created_on) desc, extract(day from entry_created_on) desc $limit"; } elseif ($at == 'Weekly') { $group_sql = " select count(*), extract(year from entry_created_on), date_format(entry_created_on,'%U')+1 from mt_entry where entry_blog_id = $blog_id and entry_status = 2 group by extract(year from entry_created_on), date_format(entry_created_on,'%U') order by extract(year from entry_created_on)+1 desc, date_format(entry_created_on,'%U')+1 desc $limit"; } elseif ($at == 'Monthly') { $group_sql = " select count(*), extract(year from entry_created_on), extract(month from entry_created_on) from mt_entry where entry_blog_id = $blog_id and entry_status = 2 group by extract(year from entry_created_on), extract(month from entry_created_on) order by extract(year from entry_created_on) desc, extract(month from entry_created_on) desc $limit"; } elseif ($at == 'Yearly') { $group_sql = " select count(*), extract(year from entry_created_on) from mt_entry where entry_blog_id = $blog_id and entry_status = 2 group by extract(year from entry_created_on) order by extract(year from entry_created_on) desc $limit"; } elseif ($at == 'Individual') { $group_sql = " select entry_id, entry_created_on from mt_entry where entry_blog_id = $blog_id and entry_status = 2 order by entry_created_on desc $limit"; } $results = $this->get_results($group_sql, ARRAY_N); if (is_array($results)) { if ($at == 'Daily') { $hi = sprintf("%04d%02d%02d", $results[0][1], $results[0][2], $results[0][3]); $low = sprintf("%04d%02d%02d", $results[count($results)-1][1], $results[count($results)-1][2], $results[count($results)-1][3]); } elseif ($at == 'Weekly') { require_once("MTUtil.php"); list($y,$m,$d) = week2ymd($results[0][1], $results[0][2]); $hi = sprintf("%04d%02d%02d", $y, $m, $d); list($y,$m,$d) = week2ymd($results[count($results)-1][1], $results[count($results)-1][2]); $low = sprintf("%04d%02d%02d", $y, $m, $d); } elseif ($at == 'Monthly') { $hi = sprintf("%04d%02d00", $results[0][1], $results[0][2]); $low = sprintf("%04d%02d00", $results[count($results)-1][1], $results[count($results)-1][2]); } elseif ($at == 'Yearly') { $hi = sprintf("%04d0000", $results[0][1]); $low = sprintf("%04d0000", $results[count($results)-1][1]); } elseif ($at == 'Individual') { $hi = $results[0][1]; $low = $results[count($results)-1][1]; } $range = "'$low' and '$hi'"; $link_cache_sql = " select fileinfo_startdate, fileinfo_url, blog_site_url from mt_fileinfo, mt_templatemap, mt_blog where fileinfo_startdate between $range and fileinfo_archive_type = '$at' and blog_id = $blog_id and fileinfo_blog_id = blog_id and templatemap_id = fileinfo_templatemap_id and templatemap_is_preferred = 1 "; $cache_results = $this->get_results($link_cache_sql, ARRAY_N); if (is_array($cache_results)) { foreach ($cache_results as $row) { $date = $row[0]; $blog_url = $row[2]; $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url); $url = $blog_url . $row[1]; $this->_archive_link_cache[$date.';'.$at] = $url; } } } return $results; } function get_author_token($blog_id) { $auth_token = $this->get_var(" select author_remote_auth_token from mt_author, mt_permission where permission_blog_id = $blog_id and author_remote_auth_token is not null limit 1"); return $auth_token; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -