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

📄 blog.php

📁 php 开发的内容管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
// $Id: blog.php,v 1.1.1.1 2005/11/14 00:33:46 phppp Exp $
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License, or        //
// (at your option) any later version.                                      //
//                                                                          //
// You may not change or alter any portion of this comment or credits       //
// of supporting developers from this source code or any supporting         //
// source code which is considered copyrighted (c) material of the          //
// original comment or credit authors.                                      //
//                                                                          //
// This program is distributed in the hope that it will be useful,          //
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
// GNU General Public License for more details.                             //
//                                                                          //
// You should have received a copy of the GNU General Public License        //
// along with this program; if not, write to the Free Software              //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: phppp (D.J., infomax@gmail.com)                                  //
// URL: http://xoopsforge.com, http://xoops.org.cn                          //
// Project: Article Project                                                 //
// ------------------------------------------------------------------------ //
/**
 * @package module::blogline
 * @copyright copyright &copy; 2005 XoopsForge.com
 */
 
if (!defined("XOOPS_ROOT_PATH")) {
	exit();
}
include_once dirname(dirname(__FILE__))."/include/vars.php";
mod_loadFunctions("", $GLOBALS["moddirname"]);

/**
 * Xtopic 
 * 
 * @author D.J. (phppp)
 * @copyright copyright &copy; 2005 XoopsForge.com
 * @package module::article
 *
 * {@link XoopsObject} 
 **/
if(!class_exists("Bblog")):

class Bblog extends ArtObject
{
    /**
     * Constructor
     */
    function Bblog()
    {
	    $this->ArtObject();
        $this->table = planet_DB_prefix("blog");
        $this->initVar("blog_id", XOBJ_DTYPE_INT, null, false);
        $this->initVar("blog_title", XOBJ_DTYPE_TXTBOX, null, true);
        $this->initVar("blog_desc", XOBJ_DTYPE_TXTBOX, null);
        /* rss URI */
        $this->initVar("blog_feed", XOBJ_DTYPE_TXTBOX, null, true);
        $this->initVar("blog_language", XOBJ_DTYPE_TXTBOX, null);
        $this->initVar("blog_charset", XOBJ_DTYPE_TXTBOX, null);
        /* blog website */
        $this->initVar("blog_link", XOBJ_DTYPE_TXTBOX, null);
        $this->initVar("blog_image", XOBJ_DTYPE_TXTBOX, null);
        
        /* regexp for blog article trackback
         * From article url to article trackback URI
         *
         * For example: http://www.example.com/blog/111.html => http://www.example.com/blog/trackback/111.html
         * The input shall be: pattern[SPACE]replacement
         *                     (.*blog/)([\d]+\.html$) $1trackback/$2      
         *
         * For example: http://www.example.com/modules/wordpress/?p=123 => http://www.example.com/modules/wordpress/wp-trackback.php?p=123
         * The input shall be: pattern[SPACE]replacement
         *                     (.*wordpress/)(index.php)?(\?p.*) $1wp-trackback/$3      
         */
        $this->initVar("blog_trackback", XOBJ_DTYPE_TXTBOX, "");
        
        /* blog submitter: is_numeric - uid; is_string - IP */
        $this->initVar("blog_submitter", XOBJ_DTYPE_TXTBOX, "");
        
        /* blog status: 0 - pending; 1 - active; 2 - featured */ 
        $this->initVar("blog_status", XOBJ_DTYPE_INT, 1);
        
        /* key for blog content */
        $this->initVar("blog_key", XOBJ_DTYPE_TXTBOX, "");
        
        $this->initVar("blog_time", XOBJ_DTYPE_INT, 0);
        $this->initVar("blog_rating", XOBJ_DTYPE_INT, 0);
        $this->initVar("blog_rates", XOBJ_DTYPE_INT, 0);
        /* bookmark times */
        $this->initVar("blog_marks", XOBJ_DTYPE_INT, 0);
    }

    /**
     * get formatted publish time of the article
     * 
 	 * {@link Config} 
 	 *
     * @param string $format format of time
     * @return string
     */
    function getTime($format ="")
    {
	    $time = planet_formatTimestamp($this->getVar("blog_time"), $format);
		return $time;
    }
    
    /**
     * get verified image url of the category
     * 
     * @return 	string
     */
    function getImage()
    {
		$image = $this->getVar("blog_image");
		return $image;
    }
    
    /**
     * get rating average of the article
     * 
     * @param int $decimals decimal length
     * @return numeric
     */
    function getRatingAverage($decimals = 1)
    {
	    $ave=3;
	    if($this->getVar("blog_rates")){
	    	$ave = number_format($this->getVar("blog_rating")/$this->getVar("blog_rates"),$decimals);
    	}
	    return $ave;
    }

    function getStar()
    {
	    return $this->getRatingAverage(0);
    }
}
endif;
/**
* Topic object handler class.  
* @package module::article
*
* @author  D.J. (phppp)
* @copyright copyright &copy; 2005 The XOOPS Project
*
* {@link XoopsPersistableObjectHandler} 
*
* @param CLASS_PREFIX variable prefix for the class name
*/

planet_parse_class('
class [CLASS_PREFIX]BlogHandler extends ArtObjectHandler
{
	/**
	 * Constructor
	 *
	 * @param object $db reference to the {@link XoopsDatabase} object	 
	 **/
    function [CLASS_PREFIX]BlogHandler(&$db) {
        $this->ArtObjectHandler($db, planet_DB_prefix("blog", true), "Bblog", "blog_id", "blog_title");
    }

    /**
     * Fetch blog info by parsing given feed
     * 
     * @param 	object	$criteria 	{@link CriteriaElement} to match
     * @param 	array	$tags 		variables to fetch
     * @param 	bool	$asObject 	flag indicating as object, otherwise as array
     * @return 	array of blogs {@link Bblog}
     */
    function &fetch($feed)
    {
	    $feed = formatURL($feed);
	    $blog =& $this->create();
	    $content = planet_remote_content($feed);
	    if(empty($content)){
		    return $blog;
	    }
		if (preg_match("/<\?xml.*encoding=[\'\"](.*?)[\'\"].*\?>/m", $content, $match)) {
			$charset = strtoupper($match[1]);
		}else {
			$charset = "UTF-8";
		}
		$res = $this->parse($content, $charset, array("channel", "image"));
		
		$blog->setVar("blog_feed", $feed);
		$blog->setVar("blog_charset", $charset);
		$blog->setVar("blog_language", @$res["channel"]["language"]);
		$blog->setVar("blog_title", $res["channel"]["title"]);
		$blog->setVar("blog_desc", $res["channel"]["description"]);
		$blog->setVar("blog_link", $res["channel"]["link"]);
		$blog->setVar("blog_image", @$res["image"]["url"]);
		
		return $blog;
    }
    
    /**
     * check if content has been updated according to a stored key (md5)
     * 
     * @param 	object	$blog 	
     * @param 	string	$content 	fetched content
     * @param 	bool	$update 	update articles
     * @return 	mixed	key or updated article count
     */
    function do_update(&$blog, $update = true)
    {
	    $content = planet_remote_content($blog->getVar("blog_feed"));
	    if(empty($content)){
		    planet_message("Empty content");
		    return false;
	    }
		
	    /* quick fetch items */
	    $is_rss = true;
	    if( !$pos_end = planet_strrpos($content, "</item>") ){
	    	if(!$pos_end = planet_strrpos($content, "</entry>")) {
		    	planet_message("blog ID ".$blog->getVar("blog_id").": No item/entry found!");
		    	return false;
	    	}
	    	$is_rss = false;
	    }
	    if(!empty($is_rss)){
	    	if(!$pos_start = strpos($content, "<item>")) {
		    	if(!$pos_start = strpos($content, "<item ")) {
		    		planet_message("blog ID ".$blog->getVar("blog_id").": No item found!");
			    	return false;
		    	}
	    	}
	    }elseif((!$pos_start = strpos($content, "<entry>")) && (!$pos_start = strpos($content, "<entry "))){ 
		    planet_message("blog ID ".$blog->getVar("blog_id").": No entry found!");
		    return false;
	    }
	    
	    /* check if content has changed */
	    $key = md5(substr($pos_start, $pos_end, $content));
	    if($key == $blog->getVar("blog_key")) {
		    planet_message("key identical!");
		    return false;
	    }
	    if(empty($update)) return $key;
	    
	    
	    /* parse items */
	    $res = $this->parse($content, $blog->getVar("blog_charset"), array("items"));
	    $items = $res["items"];
	    $blog_time = 0;
	    $crit = $blog->getVar("blog_time");
	    $articles = array();
	    $times = array();
	    foreach($items as $item){
		    if(is_numeric($item["date_timestamp"]) && $item["date_timestamp"] <= $crit) continue;
		    if(is_numeric($item["date_timestamp"]) && $item["date_timestamp"] > $blog_time) {
			    $blog_time = $item["date_timestamp"];
		    }
		    $_article = array(
		    	"blog_id"		=> $blog->getVar("blog_id"),
		    	"art_link"		=> $item["link"],
		    	"art_time"		=> $item["date_timestamp"],
		    	"art_title"		=> $item["title"],
		    	"art_content"	=> empty($item["content"]["encoded"]) ? @$item["description"] : $item["content"]["encoded"]
		    	);
		    if(!empty($item["author"])){
			    $_article["art_author"] = $item["author"];
	    	}elseif(!empty($item["author"]["name"])){
			    $_article["art_author"] = $item["author"]["name"];
		    }elseif(!empty($item["author_name"])){
			    $_article["art_author"] = $item["author_name"];
		    }elseif(!empty($item["dc"]["creator"])){
			    $_article["art_author"] = $item["dc"]["creator"];
		    }else{
			    $_article["art_author"] = "";
		    }
		    $articles[] = $_article;
		    $times[] = $item["date_timestamp"];
	    }
	    array_multisort($articles, $times, SORT_ASC, SORT_NUMERIC);
	    

⌨️ 快捷键说明

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