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

📄 post.php

📁 在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布XOOPS 2.09中文版 XOOPS 2.09x 版主要是PHP5升级、bug修正和安全补正: 1 全面兼容PHP 5.
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php// $Id: post.php,v 1.1.1.113 2004/11/22 19:48:13 praedator Exp $//  ------------------------------------------------------------------------ ////                XOOPS - PHP Content Management System                      ////                    Copyright (c) 2000 XOOPS.org                           ////                       <http://www.xoops.org/>                             ////  ------------------------------------------------------------------------ ////  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 ////  ------------------------------------------------------------------------ //class Post extends XoopsObject {    var $db;    var $attachment_array = array();    function Post($id = null)    {        $this->db = &Database::getInstance();        $this->initVar('post_id', XOBJ_DTYPE_INT);        $this->initVar('topic_id', XOBJ_DTYPE_INT);        $this->initVar('forum_id', XOBJ_DTYPE_INT);        $this->initVar('post_time', XOBJ_DTYPE_INT);        $this->initVar('poster_ip', XOBJ_DTYPE_INT);        $this->initVar('poster_name', XOBJ_DTYPE_TXTBOX);        $this->initVar('subject', XOBJ_DTYPE_TXTBOX);        $this->initVar('pid', XOBJ_DTYPE_INT);        $this->initVar('dohtml', XOBJ_DTYPE_INT, 0);        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1);        $this->initVar('doxcode', XOBJ_DTYPE_INT, 1);        $this->initVar('uid', XOBJ_DTYPE_INT, 1);        $this->initVar('icon', XOBJ_DTYPE_TXTBOX);        $this->initVar('attachsig', XOBJ_DTYPE_INT);        $this->initVar('approved', XOBJ_DTYPE_INT, 1);        $this->initVar('post_karma', XOBJ_DTYPE_INT);        $this->initVar('require_reply', XOBJ_DTYPE_INT);        $this->initVar('attachment', XOBJ_DTYPE_TXTAREA);        $this->initVar('post_text', XOBJ_DTYPE_TXTAREA);        $this->initVar('post_edit', XOBJ_DTYPE_TXTAREA);        $this->initVar('doimage', XOBJ_DTYPE_INT, 1);        $this->initVar('dobr', XOBJ_DTYPE_INT, 1);    }    // prepareVars for db store    // by phppp    // not fully tested yet    /**     * add slashes to string variables of the object for storage.     * also add slashes whereever needed     *     * @return bool true if successful     * @access public     */    function prepareVars()    {        foreach ($this->vars as $k => $v) {            $cleanv = $this->cleanVars[$k];            switch ($v['data_type']) {                case XOBJ_DTYPE_TXTBOX:                case XOBJ_DTYPE_TXTAREA:                case XOBJ_DTYPE_SOURCE:                case XOBJ_DTYPE_EMAIL:                    $cleanv = ($v['changed'])?$cleanv:(empty($v['value'])?'':$v['value']);                    if (!isset($v['not_gpc']) || !$v['not_gpc']) {                        $cleanv = $this->db->quoteString($cleanv);                    }                    break;                case XOBJ_DTYPE_INT:                    $cleanv = ($v['changed'])?intval($cleanv):(empty($v['value'])?0:$v['value']);                    break;                case XOBJ_DTYPE_ARRAY:                    $cleanv = ($v['changed'])?$cleanv:serialize((count($v['value'])>0)?$v['value']:array());                    break;                case XOBJ_DTYPE_STIME:                case XOBJ_DTYPE_MTIME:                case XOBJ_DTYPE_LTIME:                    $cleanv = ($v['changed'])?$cleanv:(empty($v['value'])?0:$v['value']);                    break;                default:                    break;            }            $this->cleanVars[$k] = &$cleanv;            unset($cleanv);        }        return true;    }    // ////////////////////////////////////////////////////////////////////////////////////    // attachment functions    TODO: there should be a file/attachment management class    function getAttachment()    {        if (count($this->attachment_array)) return $this->attachment_array;        $attachment = $this->getVar('attachment');        if (empty($attachment)) $this->attachment_array = false;        else $this->attachment_array = @unserialize(base64_decode($attachment));        return $this->attachment_array;    }    function incrementDownload($attach_key)    {        if (!$attach_key) return false;        $this->attachment_array[strval($attach_key)]['num_download'] ++;        return $this->attachment_array[strval($attach_key)]['num_download'];    }    function saveAttachment()    {        if (is_array($this->attachment_array) && count($this->attachment_array) > 0)            $attachment_save = base64_encode(serialize($this->attachment_array));        else $attachment_save = '';        $this->setVar('attachment', $attachment_save);        $sql = "UPDATE " . $this->db->prefix("bb_posts") . " SET attachment=" . $this->db->quoteString($attachment_save) . " WHERE post_id = " . $this->getVar('post_id');        if (!$result = $this->db->queryF($sql)) {            echo _MD_ERROR_UPATEATTACHMENT . "<br />" . $sql;            return false;        }        return true;    }    function deleteAttachment($attach_array = '')    {        global $xoopsModuleConfig;        $attach_old = $this->getAttachment();        if (!is_array($attach_old) || count($attach_old) < 1) return true;        $this->attachment_array = array();        if (!isset($attach_array)) $attach_array = array_keys($attach_old); // to delete all!        if (!is_array($attach_array)) $attach_array = array($attach_array);        foreach($attach_old as $key => $attach) {            if (in_array($key, $attach_array)) {                @unlink(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $attach['name_saved']);                @unlink(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/thumbs/' . $attach['name_saved']); // delete thumbnails                continue;            }            $this->attachment_array[$key] = $attach;        }        if (is_array($this->attachment_array) && count($this->attachment_array) > 0)            $attachment_save = base64_encode(serialize($this->attachment_array));        else $attachment_save = '';        $this->setVar('attachment', $attachment_save);        return true;    }    function setAttachment($name_saved = '', $name_display = '', $mimetype = '', $num_download = '')    {        $this->getAttachment();        if ($name_saved) {            $key = strval(time());            $this->attachment_array[$key] = array('name_saved' => $name_saved,                'name_display' => isset($name_display)?$name_display:$name_saved,                'mimetype' => $mimetype,                'num_download' => isset($num_download)?intval($num_download):0                );        }        if (is_array($this->attachment_array))            $attachment_save = base64_encode(serialize($this->attachment_array));        else $attachment_save = '';        $this->setVar('attachment', $attachment_save);        return true;    }    function displayAttachment($asSource = false)    {        global $xoopsModule, $xoopsModuleConfig;        $post_attachment = '';        $attachments = $this->getAttachment();        if (is_array($attachments) && count($attachments) > 0) {        	$image_extensions = array("jpg", "jpeg", "gif", "png", "bmp"); // need improve !!!            foreach($attachments as $key => $att) {                $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.');                $filetype = $file_extension;                if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/images/filetypes/' . $filetype . '.gif'))                    $icon_filetype = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/images/filetypes/' . $filetype . '.gif';                else                    $icon_filetype = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/images/filetypes/unknown.gif';                $post_attachment .= '<br /><br />';                $file_size = filesize(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $att['name_saved']);                $file_size = number_format ($file_size / 1024, 2)." KB";                if ($xoopsModuleConfig['media_allowed'] && in_array($file_extension, $image_extensions)) {					$imginfo = @getimagesize(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $att['name_saved']);					if ( $imginfo )$file_size .= "; ".$imginfo[0]."X".$imginfo[1].' px';                    $post_attachment .= '<br /><strong>' . _MD_THIS_FILE_WAS_ATTACHED_TO_THIS_POST . '</strong>&nbsp;<img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong>&nbsp; ' . $att['name_display'] . '</strong> <small>('.$file_size.')</small>';                    $post_attachment .= '<br /><hr size="1" noshade="noshade" />';                    $post_attachment .= '<br />' . newbb_attachmentImage($att['name_saved'], $asSource);                } else {                    $post_attachment .= '<br /><table width="80%" bordercolor="#000000" border="1" cellspacing="1">';                    $post_attachment .= '<tr><td colspan="3" class="head"><strong>' . _MD_ATTACHMENT . '</strong></td></tr>';                    $post_attachment .= '<tr class="even"><td width="50%"><strong>' . _MD_THIS_FILE_WAS_ATTACHED_TO_THIS_POST . '</strong></td><td><strong>' . _MD_FILESIZE . '</strong></td><td><strong>' . _MD_HITS . '</strong></td></tr>';                    $post_attachment .= '<tr class="odd"><td><a href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/dl_attachment.php?attachid=' . $key . '&amp;post_id=' . $this->getVar('post_id') . '"> <img src="' . $icon_filetype . '" alt="' . $filetype . '" /> ' . $att['name_display'] . '</a></td>';                    $post_attachment .= '<td> ' . $file_size . '</td>';                    $post_attachment .= '<td> ' . $att['num_download'] . '</td>';                    $post_attachment .= '</tr></table>';                }            }        }        return $post_attachment;

⌨️ 快捷键说明

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