discuz自定义DIY模块类

在使用DISCUZ系统的DIY功能时,可能有的模块不能满足自己的需求,所以需要自定义DIY模块类来实现自己想要需求。实现自定义功能步骤如下:

第一步:添加DIY模块类

在/source/class/block目录下创建新模块类文件夹

20140626024821

 

然后创建blockclass.php文件,代码如下:

<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: blockclass.php 27449 2012-02-01 05:32:35Z zhangguosheng $
 */

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

$blockclass = array(
	'name' => lang('blockclass', 'blockclass_jhonse'),
);

?>

20140626025131

再添加功能模块类block_jhonseforum.php

20140626025446

 

<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class block_jhonseforum extends discuz_block {
	var $setting = array();
	function block_jhonseforum() {
		$this->setting = array(
			'fids'	=> array(
				'title' => 'forumlist_fids',
				'type' => 'text',
			),
			'fups'	=> array(
				'title' => 'forumlist_fups',
				'type' => 'mselect',
				'value' => array()
			),
			'titlelength' => array(
				'title' => 'forumlist_titlelength',
				'type' => 'text',
				'default' => 40
			),
			'summarylength' => array(
				'title' => 'forumlist_summarylength',
				'type' => 'text',
				'default' => 80
			),
			'orderby' => array(
				'title' => 'forumlist_orderby',
				'type' => 'mradio',
				'value' => array(
					array('displayorder', 'forumlist_orderby_displayorder'),
					array('threads', 'forumlist_orderby_threads'),
					array('todayposts', 'forumlist_orderby_todayposts'),
					array('posts', 'forumlist_orderby_posts')
				),
				'default' => 'displayorder'
			)
		);
	}

	function name() {
		return lang('blockclass', 'blockclass_jhonse_forum_script_forum');
	}

	function blockclass() {
		return array('forum', lang('blockclass', 'blockclass_jhonse_forum'));
	}

	function fields() {
		return array(
					'id' => array('name' => lang('blockclass', 'blockclass_field_id'), 'formtype' => 'text', 'datatype' => 'int'),
					'url' => array('name' => lang('blockclass', 'blockclass_jhonse_forum_field_url'), 'formtype' => 'text', 'datatype' => 'string'),
					'title' => array('name' => lang('blockclass', 'blockclass_jhonse_forum_field_title'), 'formtype' => 'title', 'datatype' => 'title'),
					'moderators' => array('name' => lang('blockclass', 'blockclass_jhonse_forum_field_moderators'), 'formtype' => 'moderators', 'datatype' => 'moderators'),
					'sonhtml' => array('name' => lang('blockclass', 'blockclass_jhonse_forum_field_sonhtml'), 'formtype' => 'sonhtml', 'datatype' => 'sonhtml'),
					'summary' => array('name' => lang('blockclass', 'blockclass_jhonse_forum_field_summary'), 'formtype' => 'summary', 'datatype' => 'summary'),
					'icon' => array('name' => lang('blockclass', 'blockclass_jhonse_forum_field_icon'), 'formtype' => 'text', 'datatype' => 'string'),
					'posts' => array('name'=>lang('blockclass', 'blockclass_jhonse_forum_field_posts'), 'formtype' => 'text', 'datatype'=>'int'),
					'threads' => array('name'=>lang('blockclass', 'blockclass_jhonse_forum_field_threads'), 'formtype' => 'text', 'datatype'=>'int'),
					'todayposts' => array('name'=>lang('blockclass', 'blockclass_jhonse_forum_field_todayposts'), 'formtype' => 'text', 'datatype'=>'int'),
				);
	}

	function fieldsconvert() {
		return array(
				'group_group' => array(
					'name' => lang('blockclass', 'blockclass_group_group'),
					'script' => 'group',
					'searchkeys' => array(),
					'replacekeys' => array(),
				),
				'portal_category' => array(
					'name' => lang('blockclass', 'blockclass_portal_category'),
					'script' => 'portalcategory',
					'searchkeys' => array('threads'),
					'replacekeys' => array('articles'),
				),
			);
	}

	function getsetting() {
		global $_G;

		$settings = $this->setting;
		loadcache('forums');
		$settings['fups']['value'][] = array(0, lang('portalcp', 'block_all_forum'));
		if(empty($_G['cache']['forums'])) $_G['cache']['forums'] = array();
		foreach($_G['cache']['forums'] as $fid => $forum) {
			$settings['fups']['value'][] = array($fid, ($forum['type'] == 'forum' ? str_repeat('&nbsp;', 4) : ($forum['type'] == 'sub' ? str_repeat('&nbsp;', 8) : '')).$forum['name']);
		}
		return $settings;
	}

	function getdata($style, $parameter) {
		global $_G;

		$parameter = $this->cookparameter($parameter);
		$fids	= !empty($parameter['fids']) ? explode(',',$parameter['fids']) : array();
		$fups		= isset($parameter['fups']) && !in_array(0, (array)$parameter['fups']) ? $parameter['fups'] : '';
		$orderby	= isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('displayorder','threads','posts', 'todayposts')) ? $parameter['orderby'] : 'displayorder') : 'displayorder';
		$titlelength = isset($parameter['titlelength']) ? intval($parameter['titlelength']) : 40;
		$summarylength = isset($parameter['summarylength']) ? intval($parameter['summarylength']) : 80;
		$startrow	= isset($parameter['startrow']) ? intval($parameter['startrow']) : 0;
		$items		= !empty($parameter['items']) ? intval($parameter['items']) : 10;

		$bannedids = !empty($parameter['bannedids']) ? explode(',', $parameter['bannedids']) : array();
		$sqlban = !empty($bannedids) ? ' AND f.fid NOT IN ('.dimplode($bannedids).')' : '';

		if(empty($fups)) {
			loadcache('forums');
			if(empty($_G['cache']['forums'])) {
				$fups = array('0');
			} else {
				$fups = array_keys($_G['cache']['forums']);
			}
		}

		$wheres = array();
		if($fids) {
			$wheres[] = 'f.`fid` IN ('.dimplode($fids).')';
		}
		if($fups) {
			$wheres[] = 'f.`fup` IN ('.dimplode($fups).')';
		}
		$wheres[] = "f.`status`='1'";
		$wheres[] = "f.`type`!='group'";
		$wheresql = implode(' AND ', $wheres);

		$ffadd1 = ", ff.icon, ff.description, ff.moderators";
		$ffadd2 = "LEFT JOIN `".DB::table('forum_forumfield')."` ff ON f.`fid`=ff.`fid`";
		$query = DB::query("SELECT f.* $ffadd1
			FROM `".DB::table('forum_forum')."` f $ffadd2
			WHERE $wheresql
			$sqlban
			ORDER BY ".($orderby == 'displayorder' ? "f.fup, f.`displayorder` ASC " : "f.`$orderby` DESC")
			." LIMIT $startrow, $items"
		);
		$datalist = $list = array();
		$attachurl = preg_match('/^(http|ftp|ftps|https):\/\//', $_G['setting']['attachurl']) ? $_G['setting']['attachurl'] : $_G['siteurl'].$_G['setting']['attachurl'];
		while($data = DB::fetch($query)) {
			if(!empty($data['icon'])) {
				$data['icon'] = preg_match('/^(http|ftp|ftps|https):\/\//', $data['icon']) ? $data['icon'] : $attachurl.'common/'.$data['icon'];
			} else {
				$data['icon'] = 'static/image/common/forum_new.gif';
			}
			if($data['moderators']) {
				$data['moderators'] = $this->moddisplay($data['moderators']);
			}else{
				$data['moderators'] = '无';
			}
			$data['sonhtml'] = $this->sondisplay($data['fid']);
			$list[] = array(
				'id' => $data['fid'],
				'idtype' => 'fid',
				'title' => cutstr($data['name'], $titlelength, ''),
				'url' => 'forum.php?mod=forumdisplay&fid='.$data['fid'],
				'pic' => '',
				'summary' => cutstr($data['description'], $summarylength, ''),
				'fields' => array(
					'fulltitle' => $data['name'],
					'icon' => $data['icon'],
					'moderators' => $data['moderators'],
					'sonhtml'=>$data['sonhtml'],
					'threads' => intval($data['threads']),
					'posts' => intval($data['posts']),
					'todayposts' => intval($data['todayposts'])
				)
			);
		}
		return array('html' => '', 'data' => $list);
	}

 第二步: 添加语言包

在/source/language目录下的lang_blockclass.php添加代码

'blockclass_jhonse' => 'Jhonse类',
	'blockclass_jhonse_forum' => '版块模块',
	'blockclass_jhonse_forum_field_title' => '版块名称',
	'blockclass_jhonse_forum_field_url' => '版块链接',
	'blockclass_jhonse_forum_field_summary' => '版块介绍',
	'blockclass_jhonse_forum_field_icon' => '版块图标',
	'blockclass_jhonse_forum_field_posts' => '版块帖子数',
	'blockclass_jhonse_forum_field_threads' => '版块话题数',
	'blockclass_jhonse_forum_field_todayposts' => '版块今日新帖数',
	'blockclass_jhonse_forum_field_moderators' => '版主',
	'blockclass_jhonse_forum_field_sonhtml' => '子版块代码',
	'blockclass_jhonse_forum_script_forum' => '论坛版块',

 第三步: 更新缓存

效果如下:

20140626030100

2014年6月编程语言排行榜:Swift能否取代Objective-C?

TIOBE编程语言排行榜发布,这个月的热点无外乎是苹果公司在WWDC 2014上推出的新编程语言Swift,其主要用于iOS 和OS X开发。Swift改变了Objective-C中复杂的语法、保留了Smalltalk动态特性等;Swift支持代码效果实时预览,开发者可以更加快速、高效地构建应用。

目前,Swift并不在TIOBE排名之内,将从下个月起开始计算排名。有人推测,横空出世的Swift将会进入Top 20,究竟态势如何,我们敬请期待!

自2008/2009年之后,iPhone和iPad开始走进人们的视野,其巨大的需求量也促发了移动应用的开发潮流,近25年来,大部分开发者社区开始“被迫”学习并使用Objective-C,Objective-C的流行当归功于iPhone的成功。

如今,苹果公司推出的Swift语法比Objective-C更加优越,Swift能否取代Objective-C?

编程语言排行榜TOP 20榜单:

539512126c38c

 

前10名编程语言长期走势图:

5395122b13ff5

 

以下是21-50编程语言排名:

53951241098c1

 

后50名编程语言如下:

  • (Visual) FoxPro, 4th Dimension/4D, Alice, APL, ATLAS, Automator, Awk, Bash, bc, Bourne shell, C shell, CL (OS/400), Clean, Clojure, Common Lisp, Factor, Felix, Forth, Fortress, Icon, IDL, Inform, Informix-4GL, Ioke, J, JScript.NET, LabVIEW, Ladder Logic, M4, Magic, Modula-2, Modula-3, NATURAL, OCaml, OpenCL, Oz, PILOT, Programming Without Coding Technology, Pure Data, Q, Revolution, S, Seed7, Smalltalk, SPARK, Standard ML, TOM, VBScript, VHDL, X10

必须声明,这个榜单本身采集的是英文世界的数据,虽然在反映趋势上有一些参考意义,但与中国的实际情况不完全符合,而且,这张采样本身也有相当大的局限性。

【说明】

TIOBE编程语言社区排行榜是编程语言流行趋势的一个指标,每月更新,这份排行榜排名基于互联网上有经验的程序员、课程和第三方厂商的数量。排名使用著名的搜索引擎(诸如Google、MSN、Yahoo!、Wikipedia、YouTube以及Baidu等)进行计算。请注意这个排行榜只是反映某个编程语言的热门程度,并不能说明一门编程语言好不好,或者一门语言所编写的代码数量多少。

这个排行榜可以用来考查你的编程技能是否与时俱进,也可以在开发新系统时作为一个语言选择依据。

来源于csdn!

老模板退休了,更换成D8扁平式风格模板

从2012年11月份开始到现在一直用的老模板终于退休了,陪同Jhonse技术博客(http://blog.jhonse.com)足足一年多了。

从今年开始一直想找一个好一点模板来“装修”下博客,或者自己去写一个模板。前者因为没有找到自己心目中的想要的风格模板,所以放弃了,后者就是没有美工来设计。所以一直到现在才开始更换(装修)模板。于是就选择了D8模板,D8扁平化风格以及满屏的效果等等都是我想要的。所以决定用D8来“装修” Jhonse技术博客。

为了“纪念”2年之久的老伙伴(模板),特此将老模板页面截图于此发布。

index page