HDwiki 源代码 - 互动百科开源
昨日3.15,在曝光的企业中出现了一家让我好奇的企业(互动百科),一直不敢想百科能独立出来做成一家公司。出于对网站的好奇,今日进入该网站,惊讶的是此公司已经上市(股票代码:835799),在网站的底部看到 “Powered by HDwiki”。进入HDwiki,赫然写着合作用户“移动”、“华为”。。。而且 “免费开源”。故此下载下来看一下 HDwiki 里面的源代码。很简陋的架构,有 MVC 的样子。几分钟看完,虽然谈不上很有吸引力的项目,也在此留一段里面的代码做个脚印。
<?php
class template{
var $tplname;
var $tpldir;
var $objdir;
var $tplfile;
var $objfile;
var $vars=array();
var $force =0;
var $var_regexp = "\@?\\\$[a-z_][\\\$\w]*(?:\[[\w\-\.\"\'\[\]\$]+\])*";
var $vtag_regexp = "\<\?php echo (\@?\\\$[a-zA-Z_][\\\$\w]*(?:\[[\w\-\.\"\'\[\]\$]+\])*)\?\>";
var $const_regexp = "\{([\w]+)\}";
var $lang = array();
function template($tplname='default') {
$this->tplname = ($tplname!=='default'&&is_dir(HDWIKI_ROOT.'/view/'.$tplname))?$tplname:'default';
$this->tpldir = HDWIKI_ROOT.'/view/'.$this->tplname;
$this->objdir = HDWIKI_ROOT.'/data/view';
}
function assign($k, $v) {
$this->vars[$k] = $v;
}
function setlang($langtype='zh',$filename){
include HDWIKI_ROOT.'/lang/'.$langtype.'/'.$filename.'.php';
$this->lang = &$lang;
}
function display($file){
GLOBAL $starttime,$mquerynum;
$mtime = explode(' ', microtime());
$this->assign('runtime', number_format($mtime[1] + $mtime[0] - $starttime,6));
$this->assign('querynum',$mquerynum);
extract($this->vars, EXTR_SKIP);
include $this->gettpl($file);
}
function gettpl($file){
if(substr($file,0,7)=="file://"){
$ppos=strrpos($file,"/");
$dir_name=explode('/',substr($file,7));
$this->tplfile = HDWIKI_ROOT."/".substr($file,7).'.htm';
$this->objfile = $this->objdir.'/'.$dir_name[1].'_'.substr($file,$ppos+1).'.tpl.php';
}else{
if($this->tplname!=='default'&&is_file($this->tpldir.'/'.$file.'.htm')){
$this->tplfile = $this->tpldir.'/'.$file.'.htm';
$this->objfile = $this->objdir.'/'.$this->tplname."_".$file.'.tpl.php';
}else{
$this->tplfile = HDWIKI_ROOT.'/view/default/'.$file.'.htm';
$this->objfile = $this->objdir.'/'.$file.'.tpl.php';
}
}
if(!file_exists($this->tplfile)){
exit;
}
if($this->force || @filemtime($this->objfile) < @filemtime($this->tplfile)){
$this->compile();
}
return $this->objfile;
}
function compile() {
$template = file::readfromfile($this->tplfile);
$template = preg_replace("/\{block:([^\}]+?)\/\}/ies", "\$this->block('\\1')", $template);
$template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template);
$template = preg_replace("/\{lang.(\w+?)\}/ise", "\$this->lang('\\1')", $template);
if('1'==$this->vars['setting']['seo_type'] && '1'==$this->vars['setting']['seo_type_doc']){
$template = preg_replace("/\{url.doc\-view\-(.+?)\['did'\]\}/ise", "\$this->stripvtag('{url doc-view-{eval echo rawurlencode(\\1[\'rawtitle\']);}}')", $template);
}
$template = preg_replace("/\{($this->var_regexp)\}/", "<?php echo \\1?>", $template);
$template = preg_replace("/\{($this->const_regexp)\}/", "<?php echo \\1?>", $template);
$template = preg_replace("/(?<!\<\?php echo |\\\\)$this->var_regexp/", "<?php echo \\0?>", $template);
$template = preg_replace("/\{\{eval (.*?)\}\}/ies", "\$this->stripvtag('<?php \\1?>')", $template);
$template = preg_replace("/\{eval (.*?)\}/ies", "\$this->stripvtag('<?php \\1?>')", $template);
$template = preg_replace("/\{for (.*?)\}/ies", "\$this->stripvtag('<?php for(\\1) {?>')", $template);
$template = preg_replace("/\{elseif\s+(.+?)\}/ies", "\$this->stripvtag('<?php } elseif(\\1) { ?>')", $template);
$template = preg_replace("/\{hdwiki:([^\}]+?)\/\}/ies", "\$this->hdwiki('\\1')", $template);
for($i=0; $i<2; $i++) {
$template = preg_replace("/\{hdwiki:(.+?)\}(.+?)\{\/hdwiki\}/ies", "\$this->hdwiki('\\1', '\\2')", $template);
$template = preg_replace("/\{loop\s+$this->vtag_regexp\s+$this->vtag_regexp\s+$this->vtag_regexp\}(.+?)\{\/loop\}/ies", "\$this->loopsection('\\1', '\\2', '\\3', '\\4')", $template);
$template = preg_replace("/\{loop\s+$this->vtag_regexp\s+$this->vtag_regexp\}(.+?)\{\/loop\}/ies", "\$this->loopsection('\\1', '', '\\2', '\\3')", $template);
}
$template = preg_replace("/\{if\s+(.+?)\}/ies", "\$this->stripvtag('<?php if(\\1) { ?>')", $template);
$template = preg_replace("/\{template\s+(\w+?)\}/is", "<?php include \$this->gettpl('\\1');?>", $template);
$template = preg_replace("/\{template\s+(.+?)\}/ise", "\$this->stripvtag('<?php include \$this->gettpl(\\1); ?>')", $template);
$template = preg_replace("/\{else\}/is", "<?php } else { ?>", $template);
$template = preg_replace("/\{\/if\}/is", "<?php } ?>", $template);
$template = preg_replace("/\{\/for\}/is", "<?php } ?>", $template);
$template = preg_replace("/$this->const_regexp/", "<?php echo \\1?>", $template);
$template = "<?php if(!defined('HDWIKI_ROOT')) exit('Access Denied');?>\r\n$template";
$template = preg_replace("/(\\\$[a-zA-Z_]\w+\[)([a-zA-Z_]\w+)\]/i", "\\1'\\2']", $template);
$template = preg_replace("/\{url.(.+?)\}/ise", "\$this->url('\\1')", $template);
$template = preg_replace("/\{datacall:([^\}]+?)\/\}/ies", "\$this->datacall('\\1')", $template);
$fp = fopen($this->objfile, 'w');
fwrite($fp, $template);
fclose($fp);
}
function stripvtag($s) {
return preg_replace("/$this->vtag_regexp/is", "\\1", str_replace("\\\"", '"', $s));
}
function loopsection($arr, $k, $v, $statement){
$arr = $this->stripvtag($arr);
$k = $this->stripvtag($k);
$v = $this->stripvtag($v);
$statement = str_replace("\\\"", '"', $statement);
return $k ? "<?php foreach((array)$arr as $k=>$v) {?>$statement<?php }?>" : "<?php foreach((array)$arr as $v) {?>$statement<?php } ?>";
}
function lang($k){
return !empty($this->lang[$k]) ? stripslashes($this->lang[$k]) : "{ $k }";
}
function url($u){
if(substr($u,0,10)=='user-login'||substr($u,0,11)=='user-logout'||substr($u,0,13)=='user-register'||substr($u,0,9)=='user-code'
|| substr($u,0,10)=='pic-search'|| substr($u,0,7)=='search-'){
return 'index.php?'.$u;
}elseif('1'==$this->vars['setting']['seo_type'] &&'1'==$this->vars['setting']['seo_type_doc'] && 'doc-view-'==substr($u,0,9)){
return "wiki/".substr($u,9);
}else{
return $this->vars['setting']['seo_prefix'].$u.$this->vars['setting']['seo_suffix'];
}
}
function hdwiki($taglist, $statement=''){
$tag=preg_split("/\s+/",trim($taglist));//接收到参数按空格分开。
$taglist = str_replace("'", "\'", $taglist);
if(''!=$statement){
$statement = str_replace("\\\"", '"', $statement);
$statement = preg_replace_callback("/\[field:([^\]]+?)\/\]/is", array($this,'callback'), $statement);
return "<?php foreach((array)\$_ENV['tag']->$tag[0]('$taglist') as \$data) {?>$statement<?php } ?>" ;
}else{
return "<?php echo \$_ENV['tag']->$tag[0]('$taglist');?>" ;
}
}
function callback($matches){
$cmd=trim($matches[1]);
$firstspace=strpos($cmd,' ');
if(!$firstspace){
return '<?php echo $data['.$cmd.']?>';
}else{
$field=substr($cmd,0,$firstspace);
$func=substr($cmd,$firstspace);
return '<?php echo '.str_replace('@me','$data['.$field.']',$func)." ?>";
}
}
function datacall($datatag){
$datatag = trim($datatag);
return "<?php \$_ENV['datacall']->call('$datatag');?>" ;
}
function block($area){
$area = trim($area);
$datastr='';
if(!empty($GLOBALS['blocklist'][$area])) {
foreach((array)$GLOBALS['blocklist'][$area] as $block){
$datastr.='{eval $data= $GLOBALS[\'blockdata\']['.$block['id'].'];$bid="'.$block['id'].'"}';
$tplfile=HDWIKI_ROOT.'/block/'.$block['theme'].'/'.$block['block'].'/'.$block['tpl'];
if(!file_exists($tplfile)){
$tplfile=HDWIKI_ROOT.'/block/default/'.$block['block'].'/'.$block['tpl'];
}
$datastr.=file::readfromfile($tplfile);
}
}
return $datastr;
}
}
?>
HDwiki 源代码 - 互动百科开源的更多相关文章
- 我发起了一个用 .Net 编写的 源代码管理工具 开源项目 SourceKit
发起这个 项目 的 起因 是 GitHub . Github 的 使用技能 俨然已经成了 一项新技术 , 这不是 工具 的 本意 . 我用过的 源代码 管理工具 不多, SVN 我觉得不错 . 常用 ...
- Ninesky源代码从Codeplex迁移到开源中国
原来Ninesky代码一直发在Codeplex.com上,最近两三个星期了代码一直迁入不上去,网站访问也经常出错. 所以把代码放到开源中国去了,项目地址https://git.oschina.net/ ...
- GitHub开源:升讯威微信营销系统(第三方微信平台)完整源代码
GitHub:https://github.com/iccb1013/Sheng.WeixinConstruction 升讯威微信营销系统开发实践系列升讯威微信营销系统开发实践:(1)功能设计与架构设 ...
- 用Mediawiki做百科网站资源大参考
MediaWiki简易安装教程**关于mediawiki 一些好的资料: http://codex.wordpress.org.cn/Mediawiki%E5%BB%BA%E7%AB%99%E7%BB ...
- GPL协议中国第一案尘埃落定,相关开源软件应如何风控?
导读:2019年11月6日,数字天堂(北京)网络技术有限公司(以下简称 “数字天堂公司”)诉柚子(北京)科技有限公司.柚子(北京)移动技术有限公司(以下简称 “柚子公司”)侵犯计算机软件著作权纠纷一案 ...
- AgileEAS.NET SOA 中间件平台5.2版本下载、配置学习(四):开源的Silverlight运行容器的编译、配置
一.前言 AgileEAS.NET SOA 中间件平台是一款基于基于敏捷并行开发思想和Microsoft .Net构件(组件)开发技术而构建的一个快速开发应用平台.用于帮助中小型软件企业建立一条适合市 ...
- 百科编辑器ueditor应用笔记
最近项目上要用到文本编辑器,选了百科开源的ueditor,使用过程中虽然有些问题,但是一个个都解决了,记录如下: 开发的项目环境是vs2012:.net4.0: 1:百度js编辑器,编辑器加载到项目中 ...
- 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT) – 整理
当Adobe.Microsoft.Sun等一系列巨头开始表现出对”开源”的青睐时,”开源”的时代即将到来! 最初来自:sinoprise.com/read.php?tid-662-page-e-fpa ...
- 优分享VR开源啦,优分享VR是基于Google VR开发的一款手机VR视频资源的聚合软件
欢迎来到优分享VR开源项目 优分享VR 开源中国Git地址: http://git.oschina.net/xumingwang/youkes_vr 优分享VR是 优分享安卓APP VR视频播放开源部 ...
随机推荐
- Redis中的LRU淘汰策略分析
Redis作为缓存使用时,一些场景下要考虑内存的空间消耗问题.Redis会删除过期键以释放空间,过期键的删除策略有两种: 惰性删除:每次从键空间中获取键时,都检查取得的键是否过期,如果过期的话,就删除 ...
- Vim相关问题
1.vim格式修改 进入配置文件: $ sudo vim /etc/vim/vimrc 在文件末尾添加: #默认查找忽略大小写 set ignorecase #如果有一个大写字母,则切换到大小姐敏感查 ...
- Maven的学习资料收集--(五)使用Maven构建Struts2项目
在前两篇博客中,使用Maven构建了Web项目,在这篇博客中写一下,怎样构建一个简单的Struts2项目. 在准备过程中发现,要使用好Maven,个人觉得要好好利用这两个网站: http://mvnr ...
- spring数组注入
数组注入 public class MyCollection { private String[]array; private List<String>list; ...
- vue resource patch方法的传递数据 form data 为 [object Object]
今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...
- visual studio2010中C#生成的,ArcGIS二次开发的basetool的dll,注册为COM组件tlb文件,并在arcmap中加载使用
写了个标题好长啊~~~~ 这两天又认识了一个新玩意,记录一下下,啦啦啦~~~~~ 话说,认识arcgis快十年了,从桌面版到engine的二次开发,其实不过才认识到它的冰山一角, 它总是能带来很多还未 ...
- js对jsonArray的操作
上一篇写了关于java中Gson对jsonArray的排序处理,这里介绍js中对jsonArray处理, <!DOCTYPE html> <html> <head> ...
- 微信公众平台网页开发实战--3.利用JSSDK在网页中获取地理位置(HTML5+jQuery)
复制一份JSSDK环境,创建一份index.html文件,结构如图7.1所示. 图7.1 7.1节文件结构 在location.js中,封装“getLocation”接口,如下: 01 wxJSSD ...
- linux下mysql多实例安装(转)
转自:http://www.cnblogs.com/xuchenliang/p/6843990.html 1.MySQL多实例介绍 1.1.什么是MySQL多实例 MySQL多实例就是在一台机器上 ...
- LNA与PA
LNA是低噪声放大器,主要用于接收电路设计中.因为接收电路中的信噪比通常是很低的,往往信号远小于噪声,通过放大器的时候,信号和噪声一起被放大的话非常不利于后续处理,这就要求放大器能够抑制噪声.PA(功 ...