⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtdb_base.php

📁 1. 记录每个帖子的访问人情况
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php# Copyright 2001-2005 Six Apart.# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS## $Id: mtdb_base.php 10954 2005-04-05 00:32:08Z bchoate $class MTDatabaseBase extends ezsql {    var $savedqueries = array();    var $_entry_id_cache = array();    var $_author_id_cache = array();    var $_comment_count_cache = array();    var $_ping_count_cache = array();    var $_cat_id_cache = array();    var $_blog_id_cache = array();    var $_entry_link_cache = array();    var $_cat_link_cache = array();    var $_archive_link_cache = array();    var $id;    function MTDatabaseBase($dbuser, $dbpassword, $dbname, $dbhost) {        $this->id = md5(uniqid('MTDatabaseBase',true));        $this->db($dbuser, $dbpassword, $dbname, $dbhost);    }    function query($query) {        $this->savedqueries[] = $query;        parent::query($query);    }    function &resolve_url($path, $blog_id) {        $path = preg_replace('!/$!', '', $path);        $path = $this->escape($path);        $blog_id = intval($blog_id);        # resolve for $path -- one of:        #      /path/to/file.html        #      /path/to/index.html        #      /path/to/default.asp        #      /path/to/        #      /path/to        $indexes = array('index', 'default');        $index_list = '';        foreach ($indexes as $index) {            if ($index_list) $index_list .= ' or ';            $index_list .= "fileinfo_url like '$path/$index%'";        }        $sql = "            select *              from mt_blog, mt_fileinfo, mt_template              left outer join mt_templatemap on templatemap_id = fileinfo_templatemap_id             where fileinfo_blog_id = $blog_id               and ((fileinfo_url = '$path' or fileinfo_url = '$path/') or ($index_list))               and blog_id = fileinfo_blog_id               and template_id = fileinfo_template_id             order by length(fileinfo_url) asc        ";        $rows = $this->get_results($sql, ARRAY_A);        if (!$rows) return null;        $found = false;        foreach ($rows as $row) {            $fiurl = $row['fileinfo_url'];            if ($fiurl == $path) {                $found = true;                break;            }            if ($fiurl == "$path/") {                $found = true;                break;            }            $ext = $row['blog_file_extension'];            if (!empty($ext)) $ext = '.' . $ext;            foreach ($indexes as $index) {                if ($fiurl == ($path.'/'.$index.$ext))                    $found = true;                if ($fiurl == ($path.'/$index.html'))                    $found = true;                if ($fiurl == ($path.'/$index.htm'))                    $found = true;                if ($fiurl == ($path.'/$index.php'))                    $found = true;                if ($found) break;            }            if ($found) break;        }        if (!$found) return null;        $data = array();        foreach ($row as $key => $value) {            if (preg_match('/^([a-z]+)/', $key, $matches)) {                $data[$matches[1]][$key] = $value;            }        }        $this->_blog_id_cache[$data['blog']['blog_id']] =& $data['blog'];        return $data;    }    function load_index_template(&$ctx, $tmpl) {        return $this->load_special_template($ctx, $tmpl, 'index');    }    function load_special_template(&$ctx, $tmpl, $type) {        $blog_id = $ctx->stash('blog_id');        $sql = "select * from mt_template where template_blog_id=$blog_id ".($tmpl ? "and template_name='".$this->escape($tmpl)."' " : "")."and template_type='".$this->escape($type)."'";        list($row) = $this->get_results($sql, ARRAY_A);        if (!$row) return null;        return $row;    }    function category_link($cid, $args) {        if (isset($this->_cat_link_cache[$cid])) {            $url = $this->_cat_link_cache[$cid];        } else {            $sql = "select fileinfo_url, fileinfo_blog_id                      from mt_fileinfo, mt_templatemap                     where fileinfo_category_id = $cid                       and fileinfo_archive_type = 'Category'                       and templatemap_id = fileinfo_templatemap_id                       and templatemap_is_preferred = 1";            $rows = $this->get_results($sql, ARRAY_A);            if (count($rows)) {                $link =& $rows[0];            } else {                return null;            }            $blog =& $this->fetch_blog($link['fileinfo_blog_id']);            $blog_url = $blog['blog_site_url'];            $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url);            $url = $blog_url . $link['fileinfo_url'];            $this->_cat_link_cache[$cid] = $url;        }        return $url;    }    function archive_link($ts, $at, $args) {        if (isset($this->_archive_link_cache[$ts.';'.$at])) {            $url = $this->_archive_link_cache[$ts.';'.$at];        } else {            $blog_id = $args['blog_id'];            $sql = "select fileinfo_url                      from mt_fileinfo, mt_templatemap                     where fileinfo_startdate = '$ts'                       and fileinfo_blog_id = $blog_id                       and fileinfo_archive_type = '".$this->escape($at)."'                       and templatemap_id = fileinfo_templatemap_id                       and templatemap_is_preferred = 1";            $rows = $this->get_results($sql, ARRAY_A);            if (count($rows)) {                $link =& $rows[0];            } else {                return null;            }            $blog =& $this->fetch_blog($blog_id);            $blog_url = $blog['blog_site_url'];            $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url);            $url = $blog_url . $link['fileinfo_url'];            $this->_archive_link_cache[$ts.';'.$at] = $url;        }        return $url;    }    function entry_link($eid, $at, $args) {        if (isset($this->_entry_link_cache[$eid.';'.$at])) {            $url = $this->_entry_link_cache[$eid.';'.$at];        } else {            if ($at == 'Individual') {                $sql = "select fileinfo_url, fileinfo_blog_id                          from mt_fileinfo, mt_templatemap                         where fileinfo_entry_id=$eid                           and templatemap_id = fileinfo_templatemap_id                           and templatemap_archive_type='Individual'                           and templatemap_is_preferred = 1";            } elseif ($at == 'Category') {                $sql = "select fileinfo_url, fileinfo_blog_id                          from mt_fileinfo, mt_templatemap, mt_placement                         where placement_entry_id = $eid                           and fileinfo_category_id = placement_category_id                           and placement_is_primary = 1                           and fileinfo_templatemap_id = templatemap_id                           and templatemap_archive_type='Category'                           and templatemap_is_preferred = 1";            } else {                $entry = $this->fetch_entry($eid);                $ts = $entry['entry_created_on'];                if ($at == 'Monthly') {                    $ts = substr($ts, 0, 6) . '01000000';                } elseif ($at == 'Daily') {                    $ts = substr($ts, 0, 8) . '000000';                } elseif ($at == 'Weekly') {                    require_once("MTUtil.php");                    list($ws, $we) = start_end_week($ts);                    $ts = $ws;                } elseif ($at == 'Yearly') {                    $ts = substr($ts, 0, 4) . '0101000000';                }                $sql = "select fileinfo_url, fileinfo_blog_id                          from mt_fileinfo, mt_templatemap                         where fileinfo_templatemap_id = templatemap_id                           and fileinfo_startdate = '$ts'                           and templatemap_archive_type='".$this->escape($at)."'                           and templatemap_is_preferred = 1";            }            $rows = $this->get_results($sql, ARRAY_A);            if (count($rows)) {                $link =& $rows[0];            } else {                return null;            }            $blog =& $this->fetch_blog($link['fileinfo_blog_id']);            $blog_url = $blog['blog_site_url'];            $blog_url = preg_replace('!(https?://(?:[^/]+))/.*!', '$1', $blog_url);            $url = $blog_url . $link['fileinfo_url'];            $this->_entry_link_cache[$eid.';'.$at] = $url;        }        if ($at != 'Individual') {            if (!isset($args['no_anchor'])) {                $url .= '#' . (isset($args['valid_html']) ? 'a' : '') .                        sprintf("%06d", $eid);            }        }        return $url;    }    /* recreation of generic load method functionality from MT::Object */    function &load($class, $terms = null, $args = null) {        $sql = "select * from mt_$class";        $where = '';        if ($terms) {          if (is_array($terms)) {            foreach ($terms as $col => $val) {              $col = $class.'_'.$col;              $where .= " and ($col='".mysql_escape_string($val)."')";            }            $where = preg_replace('/^ and/', '', $where);          } else {            $where = " ($class"."_id='".intval($terms)."')";          }          $where = 'where'.$where;        }      /*        if ($args) {          if (        }      */        return $this->get_results($sql.' '.$where, ARRAY_A);    }    function get_template_text($ctx, $module) {        return $this->get_var("            select template_text              from mt_template             where template_blog_id=".$ctx->stash('blog_id')."               and template_name='".$this->escape($module)."'            ");    }    function &fetch_entries($args) {        if (isset($args['blog_id'])) {            $blog_filter = 'and entry_blog_id = '.$args['blog_id'];            $blog =& $this->fetch_blog($args['blog_id']);        } else {            $blog_filter = '';        }        if (isset($args['lastn'])) {            $limit = intval($args['lastn']);        }        if (isset($args['days'])) {            $day_limit = 'and date_add(entry_created_on, interval '.intval($args['days']).' day) >= now()';        } else {            if ((!isset($args['current_timestamp']) && !isset($args['current_timestamp_end'])) && ($limit <= 0) && (!isset($args['category'])) && (isset($blog))) {                $days = $blog['blog_days_on_index'];                $days or $days = 10;                $day_limit = 'and date_add(entry_created_on, interval '.$days.' day) >= now()';            }        }        if (isset($args['recently_commented_on']) && ($rco = $args['recently_commented_on'])) {            $comment_join = 'inner join mt_comment on comment_entry_id = entry_id and comment_visible = 1';            if ($blog) {                $comment_join .= ' and comment_blog_id = '.$blog['blog_id'];            }            $sort_field = 'comment_created_on';            $order = 'desc';            $limit = $rco;            $day_limit = '';            $distinct = 'distinct';        }        if (isset($args['offset'])) {            $offset = 'offset '.intval($args['offset']);        }        if (!isset($rco)) {            $order = 'desc';            if (isset($args['sort_order'])) {                if ($args['sort_order'] == 'ascend') {                    $order = 'asc';                }            } elseif (isset($blog) && isset($blog['blog_sort_order_posts'])) {                if ($blog['blog_sort_order_posts'] == 'ascend') {                    $order = 'asc';                }            }        }        $sort_field or $sort_field = 'entry_created_on';        if (isset($args['sort_by'])) {            if ($args['sort_by'] == 'title') {                $sort_field = 'entry_title';            } elseif ($args['sort_by'] == 'status') {                $sort_field = 'entry_status';            } elseif ($args['sort_by'] == 'modified_on') {                $sort_field = 'entry_modified_on';            } elseif ($args['sort_by'] == 'author_id') {                $sort_field = 'entry_author_id';            } elseif ($args['sort_by'] == 'excerpt') {                $sort_field = 'entry_excerpt';            }        }        if (isset($args['author'])) {            $author_filter = 'and author_name = ' . "'" . $this->escape($args['author']) . "'";        } else {            $author_filter = '';        }        $start = isset($args['current_timestamp']) ? $args['current_timestamp'] : null;        $end = isset($args['current_timestamp_end']) ? $args['current_timestamp_end'] : null;        if (isset($args['entry_id'])) {            $entry_filter = 'and entry_id = '.$args['entry_id'];            $start = ''; $end = ''; $limit = 1; $blog_filter = ''; $day_limit = '';        } else {            $entry_filter = '';        }        if (isset($args['not_entry_id'])) {            $entry_filter .= 'and entry_id != '.$args['not_entry_id'];        }        if ($start and $end) {            $daterange = "and entry_created_on between '$start' and '$end'";        } elseif ($start) {            $daterange = "and entry_created_on >= '$start'";        } elseif ($end) {            $daterange = "and entry_created_on <= '$end'";        } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -