标签归档:discuz

discuz 数据调用模板语法的php写法

琢磨了两天,终于给找到苗头了。赶紧记录下,以备下回使用。
discuz数据调用的内部调用的模板写法是,由于在实践中需批量对不同的页面调用对应的模块,模板中的语法无法再结合变量使用,于是只好在php中直接写了。代码如下

//discuz X3.1
loadcache('blockclass');
$bid = 123;//模块ID
block_get($bid);
$data = block_display($bid);

模块中的数据都在$data里了

discuz用起来顺手多了哈。

//直接这样写?
block_display($bid)

Discuz_X3.1扩展模块相关备忘

入口页面


<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: sample.php 24842 2011-10-12 09:51:37Z zhengqingpeng $
 */

define('APPTYPEID', 2140);
define('CURSCRIPT', 'sample');


require './source/class/class_core.php';

$discuz = C::app();

$modarray = array('mod1','mod2','mod3','mod4');

$mod = !in_array($discuz->var['mod'], $modarray) ? 'mod1' : $discuz->var['mod'];

$discuz->init();

define('CURMODULE', $mod);
runhooks();


require DISCUZ_ROOT.'./source/module/'.CURSCRIPT.'/'.$mod.'.php';

?>


mod页面


<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: mod.php 2011/8/10 15:31 fuqingrong $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$actionarray = array('ac1','ac2');
$action = getgpc('ac');
$action = in_array($action,$actionarray) ? $action : 'ac1';

if($action == 'ac1'){
	
	
//some code....	
	
}elseif($action == 'ac2'){
	
	
//some code....
	
}


	include template('diy:'.CURSCRIPT.'/'.$mod.'_'.$action);

?>

终于找到了discuz 伪静态功能失效的原因所在!

近日为某事业单位做一门户网站,选用了discuz x3.1作为门户程序,自制风格模板,而当要进行伪静态时,发现页面上的动态链接仍然保持原样。后来一一排除了各种可能性,依然无果。就在刚刚,查看discuz 默认模板文件时,发现上方有一段

<!--{eval output();}-->

,立刻眼前一亮,原来很久以前也遇到过类似问题,而罪魁祸首就是自制的模板文档末尾未加上这段代码!

IIS7.5/PHPv5.3.24 DiscuzX2.5上传文件出现Upload Error: 500的解决方法

添加了临时目录,重启IIS服务器后终于解决了。

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir =C:\phpfileuploadtmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 24M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

Discuz X2.5相关备忘

1、在直接操作了数据库字段更新后,由于某些变量是被缓存的,所以页面上不会当即展示最新的数据,如需立即展示可更新缓存,比如要更新用户组相关的数据,可在代码中加入

loadcache('usergroups');

2、把形如 2012-12-03 17:40:00 这样格式的时间转化为Unix时间戳

strtotime($_GET['dateline']);

把时间戳转化为格式化日期

 

$l['dateline'] = dgmdate($l['dateline']);

$date = dgmdate($_G[timestamp],'u');

 

301跳转

showmessage('301跳转', 'yoururl', array(), array('header' => true));

3、把一个php数组转字符串

$biuuu = array('b','i','u','u','u');
print_r(implode('',$biuuu)); 

4、字符串编码转换

$keywordGbk = iconv( "UTF-8", "gbk" , $keyword);

5、添加关联链接(这个功能太强大了)

if(!$_G['setting']['relatedlinkstatus']) {
	$_G['relatedlinks'] = get_related_link('article');
} else {
	$content['content'] = parse_related_link($content['content'], 'article');
}

6、加载ucenter功能

loaducenter();

7、cookies的使用

//设置cookies 
dsetcookie($var, $value = '', $life = 0, $prefix = 1, $httponly = false);

//获取cookies
getcookie($key);

8、常用的SQL语句

$thread = DB::fetch_first("SELECT qxzy,pcdm FROM ".DB::table('zytb_360')." WHERE 1 AND tid = '$tid'  ");

 

	$list = array();
	$query = DB::query("SELECT id,yxmc,desc1,yxdh,sscs,pxf,gjdm FROM ".DB::table('zytb_quanguo_xkx_2012')." WHERE 1 ");
	while($l = DB::fetch($query)){
		$list[] = $l;
	}
//总数获取
$count =  DB::result_first("SELECT count(id) FROM ".DB::table('tebale1')." WHERE 1  ");
DB::query("INSERT INTO ".DB::table('zytb_order')." (orderid, payment, money, uid, status, createdateline,completedateline,goodid,type) VALUES ('$orderid','$payment','$money','$_G[uid]', '$status', '$_G[timestamp]', '','$tid','$type')");

$id = DB::insert_id();

 

DB::query("UPDATE ".DB::table('zytb_360')." SET realname = '$realname', school = '$school', gender = '$gender', kldm = '$kldm', pcdm = '$pcdm', zfs = '$zfs', dateline = '".TIMESTAMP."' WHERE tid = '$tid' ");
DB::delete('zs_meng_report', array('id' => $id,'type' => $type));//删除
//post
if(submitcheck('submit')) {
	$message = cutstr(dhtmlspecialchars(stripslashes($_POST['message'])), 150, ''); //截取150个字节的内容
	DB::query("INSERT INTO ".DB::table('mood_wall')." (uid, username, dateline, message) VALUES ('$_G[uid]', '$_G[username]', '".TIMESTAMP."', '".daddslashes($message)."')");
	showmessage('发表成功。', 'mood.php?mod=list');
}
//{FORMHASH}

9、include


require libfile('post/albumphoto', 'include');

//对应的路径为:/source/include/post/post_albumphoto.php

10、memcache的使用


$allow = memory('check');//看memcache是否可用
if($allow == 'memcache'){
	$str = memory('get', 'abc');
	
	if(empty($str)){
		
		//some codes
		
		//写入
		$ret = memory('set', 'abc', $aa, $ttl);//$ttl 默认为0,可设置最长的失效时间为30天,即2592000秒
		
	}else{
		
		$xxx = $str;//直接取来用
		
		
	} 
}

//其它操作方法
memory('rm', 'abc');//删除