📄 xoopsblock.php
字号:
<?php
// $Id: xoopsblock.php 1099 2007-10-19 01:08:14Z dugris $
// ------------------------------------------------------------------------ //
// 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 //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
require_once XOOPS_ROOT_PATH."/kernel/object.php";
class XoopsBlock extends XoopsObject
{
var $db;
function XoopsBlock($id = null)
{
$this->db =& Database::getInstance();
$this->initVar('bid', XOBJ_DTYPE_INT, null, false);
$this->initVar('mid', XOBJ_DTYPE_INT, 0, false);
$this->initVar('func_num', XOBJ_DTYPE_INT, 0, false);
$this->initVar('options', XOBJ_DTYPE_TXTBOX, null, false, 255);
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150);
//$this->initVar('position', XOBJ_DTYPE_INT, 0, false);
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 150);
$this->initVar('content', XOBJ_DTYPE_TXTAREA, null, false);
$this->initVar('side', XOBJ_DTYPE_INT, 0, false);
$this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
$this->initVar('visible', XOBJ_DTYPE_INT, 0, false);
$this->initVar('block_type', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('c_type', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('isactive', XOBJ_DTYPE_INT, null, false);
$this->initVar('dirname', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('func_file', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('show_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('edit_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
$this->initVar('template', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('bcachetime', XOBJ_DTYPE_INT, 0, false);
$this->initVar('last_modified', XOBJ_DTYPE_INT, 0, false);
if ( !empty($id) ) {
if ( is_array($id) ) {
$this->assignVars($id);
} else {
$this->load(intval($id));
}
}
}
function load($id)
{
$id = intval($id);
$sql = 'SELECT * FROM '.$this->db->prefix('newblocks').' WHERE bid = '.$id;
$arr = $this->db->fetchArray($this->db->query($sql));
$this->assignVars($arr);
}
function store()
{
if ( !$this->cleanVars() ) {
return false;
}
foreach ( $this->cleanVars as $k=>$v ) {
${$k} = $v;
}
if ( empty($bid) ) {
$bid = $this->db->genId($this->db->prefix("newblocks")."_bid_seq");
$sql = sprintf("INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES (%u, %u, %u, %s, %s, %s, %s, %u, %u, %u, %s, %s, %u, %s, %s, %s, %s, %s, %u, %u)", $this->db->prefix('newblocks'), $bid, $mid, $func_num, $this->db->quoteString($options), $this->db->quoteString($name), $this->db->quoteString($title), $this->db->quoteString($content), $side, $weight, $visible, $this->db->quoteString($block_type), $this->db->quoteString($c_type), 1, $this->db->quoteString($dirname), $this->db->quoteString($func_file), $this->db->quoteString($show_func), $this->db->quoteString($edit_func), $this->db->quoteString($template), $bcachetime, time());
} else {
$sql = "UPDATE ".$this->db->prefix("newblocks")." SET options=".$this->db->quoteString($options);
// a custom block needs its own name
if ( $block_type == "C" ) {
$sql .= ", name=".$this->db->quoteString($name);
}
$sql .= ", isactive=".$isactive.", title=".$this->db->quoteString($title).", content=".$this->db->quoteString($content).", side=".$side.", weight=".$weight.", visible=".$visible.", c_type=".$this->db->quoteString($c_type).", template=".$this->db->quoteString($template).", bcachetime=".$bcachetime.", last_modified=".time()." WHERE bid=".$bid;
}
if ( !$this->db->query($sql) ) {
$this->setErrors("Could not save block data into database");
return false;
}
if ( empty($bid) ) {
$bid = $this->db->getInsertId();
}
return $bid;
}
function delete()
{
$sql = sprintf("DELETE FROM %s WHERE bid = %u", $this->db->prefix('newblocks'), $this->getVar('bid'));
if ( !$this->db->query($sql) ) {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE gperm_name = 'block_read' AND gperm_itemid = %u AND gperm_modid = 1", $this->db->prefix('group_permission'), $this->getVar('bid'));
$this->db->query($sql);
$sql = sprintf("DELETE FROM %s WHERE block_id = %u", $this->db->prefix('block_module_link'), $this->getVar('bid'));
$this->db->query($sql);
return true;
}
/**
* do stripslashes/htmlspecialchars according to the needed output
*
* @param $format output use: S for Show and E for Edit
* @param $c_type type of block content
* @returns string
*/
function getContent($format = 'S', $c_type = 'T')
{
switch ( $format ) {
case 'S':
// check the type of content
// H : custom HTML block
// P : custom PHP block
// S : use text sanitizater (smilies enabled)
// T : use text sanitizater (smilies disabled)
if ( $c_type == 'H' ) {
return str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
} elseif ( $c_type == 'P' ) {
ob_start();
echo eval($this->getVar('content', 'N'));
$content = ob_get_contents();
ob_end_clean();
return str_replace('{X_SITEURL}', XOOPS_URL.'/', $content);
} elseif ( $c_type == 'S' ) {
$myts =& MyTextSanitizer::getInstance();
$content = str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
return $myts->displayTarea($content, 1, 1);
} else {
$myts =& MyTextSanitizer::getInstance();
$content = str_replace('{X_SITEURL}', XOOPS_URL.'/', $this->getVar('content', 'N'));
return $myts->displayTarea($content, 1, 0);
}
break;
case 'E':
return $this->getVar('content', 'E');
break;
default:
return $this->getVar('content', 'N');
break;
}
}
function buildBlock()
{
global $xoopsConfig, $xoopsOption;
$block = array();
// M for module block, S for system block C for Custom
if ( $this->getVar("block_type") != "C" ) {
// get block display function
$show_func = $this->getVar('show_func');
if ( !$show_func ) {
return false;
}
// must get lang files b4 execution of the function
if ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/blocks/".$this->getVar('func_file')) ) {
if ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/".$xoopsConfig['language']."/blocks.php") ) {
include_once XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/".$xoopsConfig['language']."/blocks.php";
} elseif ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/english/blocks.php") ) {
include_once XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/english/blocks.php";
}
include_once XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/blocks/".$this->getVar('func_file');
$options = explode("|", $this->getVar("options"));
if ( function_exists($show_func) ) {
// execute the function
$block = $show_func($options);
if ( !$block ) {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
// it is a custom block, so just return the contents
$block['content'] = $this->getContent("S",$this->getVar("c_type"));
if (empty($block['content'])) {
return false;
}
}
return $block;
}
/*
* Aligns the content of a block
* If position is 0, content in DB is positioned
* before the original content
* If position is 1, content in DB is positioned
* after the original content
*/
function buildContent($position,$content="",$contentdb="")
{
if ( $position == 0 ) {
$ret = $contentdb.$content;
} elseif ( $position == 1 ) {
$ret = $content.$contentdb;
}
return $ret;
}
function buildTitle($originaltitle, $newtitle="")
{
if ($newtitle != "") {
$ret = $newtitle;
} else {
$ret = $originaltitle;
}
return $ret;
}
function isCustom()
{
if ( $this->getVar("block_type") == "C" ) {
return true;
}
return false;
}
/**
* gets html form for editting block options
*
*/
function getOptions()
{
global $xoopsConfig;
if ( $this->getVar("block_type") != "C" ) {
$edit_func = $this->getVar('edit_func');
if ( !$edit_func ) {
return false;
}
if ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/blocks/".$this->getVar('func_file')) ) {
if ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/".$xoopsConfig['language']."/blocks.php") ) {
include_once XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/".$xoopsConfig['language']."/blocks.php";
} elseif ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/english/blocks.php") ) {
include_once XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/language/english/blocks.php";
}
include_once XOOPS_ROOT_PATH.'/modules/'.$this->getVar('dirname').'/blocks/'.$this->getVar('func_file');
$options = explode("|", $this->getVar("options"));
$edit_form = $edit_func($options);
if ( !$edit_form ) {
return false;
}
return $edit_form;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -