很久没有更新百科系统程序了;应该有几个月了;今天就接着之前的更新内容;继续发布;本章节是单语言/多语言仿百度HDwiki百科网站源码开发 第五篇。
程序源码;不加密;开源
程序开源;PHP;mysql;thinkPHP框架
程序演示;http://baike.yetukeji.cn, 账户18127950266 ;密码QQ2360248666
先上几张效果图先
这个是手机版
这部分是代码区
<?php namespace appindexcontroller; use appBase; use thinkApp; use thinkfacadeCache; use thinkRequest; use thinkfacadeView; use thinkfacadeDb; class Common extends Base { public function __construct() { parent::__construct(); $this->loading_language(); $this->personal_nav(); } //设置默认语言 function loading_language(){ if(cookie(;lang;) == null){ cookie(;lang;,config(;lang;)[;default_lang;]); //echo ;<script language=JavaScript> location.replace(location.href);</script>;; } } function personal_nav($id=0){ $personal_nav = [ [ ;id; => ;10001;, ;name; => ;个人中心;, ;lang_key; => ;nav_personal_center;, ;url; => ;/buyer/index;, ;status; => 1 ], [ ;id; => ;10002;, ;name; => ;我的收藏;, ;lang_key; => ;nav_my_collection;, ;url; => ;/buyer/collection;, ;status; => 1 ], [ ;id; => ;10003;, ;name; => ;个人资料;, ;lang_key; => ;nav_personal_data;, ;url; => ;/buyer/data;, ;status; => 1 ] ]; if($id != 0){ foreach ($personal_nav as $item) { if($item[;id;] == $id){ return $item; } } } View::assign(;personal_nav;,$personal_nav); return [ ;id; => ;10000;, ;name; => ;页面不存在;, ;lang_key; => ;;, ;url; => ;/buyer/error;, ;status; => 1 ]; }
语言包切换
public function langSwitch(){ $lang = input(;lang;); if($lang != ;;){ if($this->is_language($lang)){ cookie(;lang;,$lang); //cookie(;think_lang;,$lang); return $this->success(;设置成功;); } } return $this->error(;设置失败;); }
判断是否存在语言
function is_language($lang=0){ $language_list = config(;console;)[;lang;]; foreach($language_list as $key => $value){ if($key == $lang){ return true; } } return false; }
验证邮箱
function is_email($email){ $chars = ;/w;([-;.]w;)*;w;([-.]w;)*.w;([-.]w;)*/;; if (preg_match($chars, $email)){ return true; }else{ return false; } } public function info($url=;;){ $top_info_id = get_info_id($url); if(input(;cid/d;) == ;;){ $info = get_nav_info($top_info_id); }else{ $info = get_nav_info(input(;cid/d;)); } return $info; } public function topInfo($url=;;){ $top_info_id = get_info_id($url); return get_nav_info($top_info_id); } public function assign($info,$top_info=;;){ if($top_info == ;;){ $top_info = [ ;id; => -1, ;name; => ;;, ;url; => ;; ]; } if(empty($info[;name;])){ $info[;name;] = ;;; } if(empty($info[;keywords;])){ $info[;keywords;] = ;;; } if(empty($info[;description;])){ $info[;description;] = ;;; } if(empty($info[;lang_key;])){ $info[;lang_key;] = ;;; } View::assign(;seo_keywords;,$info[;keywords;]); //View::assign(;seo_title;,$info[;name;].;-;.setting(;web_name;)); View::assign(;seo_title;,l($info[;lang_key;]).; - ;.l(;web_name;)); View::assign(;seo_description;,$info[;description;]); View::assign(;top_info;,$top_info); View::assign(;info;,$info); } public function success($msg = ;;, $data = ;;){ return json([;code; => 1, ;msg; => $msg, ;data; => $data]); } public function error($msg = ;;, $data = ;;){ return json([;code; => 0, ;msg; => $msg, ;data; => $data]); }
后面持续更新;大家可以关注我的个人博客主页就行。