二级域名综合插件
修复
1.修复下一页列表错误:
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links LIMIT ".($page-1).",".$ye; 改为
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links LIMIT ".($page-1)*$ye.",".$ye;
2.添加二级域名重复功能
源码
<script type="text/javascript">
$('#ajaxsubdomain').keydown(function(){
$('#ajaxsubdomain').css('background-color','#FFFFCC');
var title = $(this).val();
$.post("<?php echo BLOG_URL; ?>content/plugins/misaka_sub_domain/misaka_sub_domain_do.php",{title:title});
console.log('hello2');
});
$('#ajaxsubdomain').focusout(function(){
console.log('hellod');
var title = $(this).val();
$.post("<?php echo BLOG_URL; ?>content/plugins/misaka_sub_domain/misaka_sub_domain_do.php", {title : title},
function(data){
if(data==1){
$('.actived').hide();
$('#ajaxsubdomain').css('border','1px red solid');
$('#msg').append('<span class="actived" style="background:url(views/images/icon_error.gif) no-repeat 10px #FDFFCE; margin-left:60px;">二级域名重复</span>');
setTimeout(hideActived,2600);
$("form").submit( function () {
hideActived();
$('#ajaxsubdomain').focus();
$('#msg').append('<span class="actived" style="background:url(views/images/icon_error.gif) no-repeat 10px #FDFFCE; left:30px;margin-left:60px;">二级域名重复</span>');
return false;
});
}else{
console.log('hah');
$('#ajaxsubdomain').css('border-color','#339900');
$("form").unbind();
}
}
);
});
</script>
misaka_sub_domain_do.php
源码
<?php
if (!defined('EMLOG_ROOT')) {
require_once('../../../init.php');
}
$this_get_title = isset($_POST['title'])?addslashes($_POST['title']):'';
if(!empty($this_get_title)){
$DB = MySql::getInstance();
$sql = "SELECT subdomain FROM ".DB_PREFIX."misaka_sub_domain where subdomain = '".$this_get_title."' limit 1";
$res = $DB->query($sql);
$is_exists = $DB->num_rows($res);
if($is_exists>0){
exit('1');
}else{
exit('0');
}
}else {
exit('0');
}
需求说明
1.后台添加二级域名管理.可查看列表,增加,修改,删除.查看
2.内容包括搜索词,二级域名,网站标题,网站关键字,网站描述,前台二级域名下需要显示对应的设置项
3.二级域名下可添加友情链接,需要按照对应二级域名下查看,前台的友情链接需要显示对应的友情链接
4.二级域名的友链功能同样需要有查看,增加,修改,删除功能,且需要有有效期功能(这里偷懒暂时没写)
插件效果
插件说明
该插件需要域名泛解析,且需要修改模板文件header.php来实现显示设置项(或许可以插件内实现?),修改module.php的友链方法来实现不同二级域名显示追加插件友链功能(要么用钩子,要么改function,我选择了后者).
插件代码实现
misaka_sub_domain_callback.php
源码
<?php
!defined('EMLOG_ROOT') && exit('操作禁止!');
//激活插件
function callback_init(){
//如果数据表不存在,则添加数据表
global $CACHE;
$DB = MySql::getInstance();
$misaka_sub_domain = $DB->query('show tables like "'.DB_PREFIX.'misaka_sub_domain"');
if($DB->num_rows($misaka_sub_domain) == 0){
$dbcharset = 'utf8';
$type = 'MYISAM';
$add = $DB->getMysqlVersion() > '4.1' ? "ENGINE=".$type." DEFAULT CHARSET=".$dbcharset.";" : "TYPE=".$type.";";
$sql = "
CREATE TABLE `".DB_PREFIX."misaka_sub_domain` (
`id` int(10) unsigned NOT NULL auto_increment,
`searchword` varchar(25) NOT NULL,
`subdomain` varchar(50) NOT NULL,
`webtitle` varchar(50) NOT NULL,
`webkey` varchar(20) NOT NULL,
`webdiscription` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ".$add;
$DB->query($sql);
}else{
//既然存在,不做处理!
}
$misaka_sub_domain = $DB->query('show tables like "'.DB_PREFIX.'misaka_sub_domain_links"');
if($DB->num_rows($misaka_sub_domain) == 0){
$dbcharset = 'utf8';
$type = 'MYISAM';
$add = $DB->getMysqlVersion() > '4.1' ? "ENGINE=".$type." DEFAULT CHARSET=".$dbcharset.";" : "TYPE=".$type.";";
$sql = "
CREATE TABLE `".DB_PREFIX."misaka_sub_domain_links` (
`id` int(10) unsigned NOT NULL auto_increment,
`domainid` int(10) unsigned NOT NULL,
`linkname` varchar(25) NOT NULL,
`linkurl` varchar(50) NOT NULL,
`starttime` int(10) unsigned NOT NULL,
`outtime` int(10) unsigned NOT NULL,
`status` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ".$add;
$DB->query($sql);
}else{
//既然存在,不做处理!
}
}
//卸载插件
function callback_rm(){
}
misaka_sub_domain_show.php
源码
<?php
!defined('EMLOG_ROOT') && exit('操作禁止!');
?>
<style>
a:link,a:active,a:visited{text-decoration:none;}
#sub_domain{border:1px solid #ddd;width:800px;}
.sub_domain_opt .ul{}
.sub_domain_opt .ul .li{float:left;text-align:center;padding:0px 15px;border-right:1px solid #ddd;border-bottom:1px solid #ddd;height:28px;line-height:28px;}
.sub_domain_opt .ul .li:nth-child(1){width:5%;}
.sub_domain_opt .ul .li:nth-child(2){width:10%;}
.sub_domain_opt .ul .li:nth-child(3){width:30%;}
.sub_domain_opt .ul .li:nth-child(4){width:5%;}
.sub_domain_opt .ul .li:nth-child(5){width:8%;}
.sub_domain_opt .ul .li:nth-child(6){width:10%;height:28px;}
.sub_domain_opt .ul:last-child .li{border-bottom:0px;}
</style>
<div id="sub_domain">
<div class="sub_domain_opt">
<?php
$DB = MySql::getInstance();
$ye = 10;
$page = intval($_GET['page']) ? $_GET['page'] : 1;
$pageurl = '?plugin=sub_domain&page=';
echo '<div class="ul"><div class="li">序号</div><div class="li">搜索词</div><div class="li">二级域名</div><div class="li">查看</div><div style="clear:both;"></div></div>';
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain";
$strs = $DB->query($sql);
$zon = $DB->num_rows($strs);
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain order by id desc LIMIT ".($page-1).",".$ye;
$strs = $DB->query($sql);
while($row = $DB->fetch_array($strs)){
echo '<div class="ul"><div class="li">'.$row['id'].'</div><div class="li">'.$row['searchword'].'</div><div class="li"><a href="//'.$row['subdomain'].'.'.str_replace('www.','',$_SERVER['HTTP_HOST']).'" title="'.$row['webtitle'].'" target="_blank">'.$row['subdomain'].'.'.str_replace('www.','',$_SERVER['HTTP_HOST']).'</a></div><div class="li"><a href="//'.$row['subdomain'].'.'.str_replace('www.','',$_SERVER['HTTP_HOST']).'" title="'.$row['webtitle'].'" target="_blank">≡</a></div><div style="clear:both;"></div></div>';
}
echo '<style>#msk_pagenavi .box .pages{float:left;padding:5px;}</style><div id="msk_pagenavi"><div class="box">'.misakapage($zon,$ye,$page,$pageurl).'<div style="clear:both;"></div></div></div>';
?>
</div>
</div>
<?php
function misakapage($lognum,$index_lognum,$page,$pageurl){
//echo '总数'.$lognum.' 每页'.$index_lognum.'当前页'.$page.'总页数'.ceil($lognum/$index_lognum);
$urlHome = preg_replace("|[\?&/][^\./\?&=]*page[=/\-]|", "", $pageurl);
if($page == 0){
$re = '';
}elseif($page == 1){
$re .= '<div class="pages red">1</div>';
for($i = 2; $i <= 5 && $i <= ceil($lognum/$index_lognum); $i++){
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif($page <= 3){
$re .= '<div class="pages"><a href="'.$pageurl.($page - 1).'">上一页</a></div>';
for($i = 1; $i <= 5 && $i <= ceil($lognum/$index_lognum); $i++){
if($i == $page){
$re .= '<div class="pages red">'.$i.'</div>';
}else{
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif($page <= ceil($lognum/$index_lognum) - 2){
$re .= '<div class="pages"><a href="'.$pageurl.($page - 1).'">上一页</a></div>';
for($i = $page - 2; $i <= $page + 2 && $i <= ceil($lognum/$index_lognum); $i++){
if($i == $page){
$re .= '<div class="pages red">'.$i.'</div>';
}else{
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif($page <= ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page - 1).'">上一页</a></div>';
for($i = ceil($lognum/$index_lognum) - 2; $i > 0 && $i <= ceil($lognum/$index_lognum); $i++){
if($i == $page){
$re .= '<div class="pages red">'.$i.'</div>';
}else{
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif(ceil($lognum/$index_lognum) <= 1){
$re = '';
}else{
}
return $re;
}
?>
misaka_sub_domain.php
源码
<?php
/*
Plugin Name: 二级域名综合插件
Version: 1.0
Plugin URL: http://www.neurallinker.com
Description: 1.单独对每个二级域名进行设置和管理。2.增加和管理二级域名下的友情链接 前台调用 get_domain_link($id),$id为友联序号,0为全部显示
Author: 御坂网络
Author URL: http://www.neurallinker.com
*/
!defined('EMLOG_ROOT') && exit('操作禁止!');
error_reporting(0);//屏蔽所有错误信息
function sub_domain_side(){//写入插件导航
echo '<div class="sidebarsubmenu"><a href="./plugin.php?plugin=misaka_sub_domain"><span style="color:#66ccff;">二级域名综合插件</span></a></div>';
}
addAction('adm_sidebar_ext','sub_domain_side');
addAction('misaka_header2','misaka_header2');
addAction('misaka_footer','sub_domain_footer');
function misaka_header(){
if(preg_match_all('/(.*?)\./uis',$_SERVER['HTTP_HOST'],$match)){//图片匹配还需要继续判断
$subdomain = $match[1][0];
}
//判断插件是否使用
global $CACHE;
$DB = MySql::getInstance();
$misaka_sub_domain = $DB->query('show tables like "'.DB_PREFIX.'misaka_sub_domain"');
if($DB->num_rows($misaka_sub_domain) != 0){
//echo '插件已开启';
//获得所有的二级域名
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain WHERE subdomain = '{$subdomain}'";
$strs = $DB->query($sql);
$row = $DB->fetch_array($strs);
$ret = array();
if($logid){
$ret['site_title'] = $log_title.' - '.$row['webtitle'];
}elseif($tag){
$ret['site_title'] = stripslashes($tag).' - '.$row['webtitle'];
}else{
if($row['webdiscription']){
$ret['site_description'] = $row['webdiscription'];
}
if($row['webkey']){
$ret['site_key'] = $row['webkey'];
}
if($row['webtitle']){
$ret['site_title'] = $row['webtitle'];
}
}
$ret['webtitle'] = $row['webtitle'];
$ret['domainid'] = $row['id'];
//var_dump($ret);
return $ret;
}
}
function misaka_header2(){
if(preg_match_all('/(.*?)\./uis',$_SERVER['HTTP_HOST'],$match)){//图片匹配还需要继续判断
$subdomain = $match[1][0];
}
//echo $_SERVER['HTTP_HOST'].substr_count($_SERVER['HTTP_HOST'],'.');
//判断插件是否使用
global $CACHE;
$DB = MySql::getInstance();
$misaka_sub_domain = $DB->query('show tables like "'.DB_PREFIX.'misaka_sub_domain"');
if($DB->num_rows($misaka_sub_domain) != 0){
//echo '插件已开启';
//获得所有的二级域名
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain WHERE subdomain = '{$subdomain}'";
$strs = $DB->query($sql);
$row = $DB->fetch_array($strs);
//var_dump($row);
if((!$row['subdomain'] and $subdomain != 'www' and $subdomain != '' and $_SERVER['HTTP_HOST'] != 'xinsop.com') or (substr_count($_SERVER['HTTP_HOST'],'.') > 2 and $_SERVER['HTTP_HOST'] != 'xinsop.com')){
//ps:如果默认不带www可能会有问题
show_404_page();
//header("HTTP/1.1 404 Not Found");
exit;
}else{
if(!$_GET['keyword'] and !substr_count($_SERVER['REQUEST_URI'],'/t/') and substr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],-2) == 'm/'){
//只有在不是搜索、不是微语、且网址最后是 .com/ 结尾才 HOOK 搜索结果
//获得关键字
//var_dump($row);
$Log_Model = new Log_Model();
$options_cache = Option::getAll();
extract($options_cache);
$page = isset($params[4]) && $params[4] == 'page' ? abs(intval($params[5])) : 1;
$keyword = addslashes(htmlspecialchars(urldecode($row['searchword'])));
$keyword = str_replace(array('%', '_'), array('\%', '\_'), $keyword);
$pageurl = '';
$sqlSegment = "and (title like '%{$keyword}%' or content like '%{$keyword}%') order by date desc";
$lognum = $Log_Model->getLogNum('n', $sqlSegment);
$total_pages = ceil($lognum / $index_lognum);
if ($page > $total_pages) {
$page = $total_pages;
}
$pageurl .= BLOG_URL.'?keyword='.urlencode($keyword).'&page=';
$logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
$page_url = pagination($lognum, $index_lognum, $page, $pageurl);
//include View::getView('header');
include View::getView('log_list');
exit;
}
}
}
}
function sub_domain_footer(){//写入插件导航
if(preg_match_all('/(.*?)\./uis',$_SERVER['HTTP_HOST'],$match)){//图片匹配还需要继续判断
$subdomain = $match[1][0];
}
if($subdomain != 'xinsop'){
echo "<script>
var i = 0;
$('a').each(function(){
var href = $(this).attr('href');
if(href){
if(href.indexOf('www.xinsop')!=-1 && href.indexOf('.html')!=-1){
  href=href.replace(/www.xinsop/g,'".$subdomain.".xinsop');
$(this).attr('href',href);
i++;
  }
}
});
</script>";
}
}
function get_domain_link($domainid){
$domainid = $domainid ? $domainid : 0;
$DB = MySql::getInstance();
if($domainid == 0){
$sql ="SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links";
}else{
$sql ="SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links WHERE domainid = ".$domainid;
}
$strs = $DB->query($sql);
//echo ' id='.$domainid;
while($row = $DB->fetch_array($strs)){
echo '<li><a href="'.$row['linkurl'].'" title="'.$row['linkname'].'" target="_blank">'.$row['linkname'].'</a></li>';
}
}
//自动更新有效期到期时间
//功能未实现
misaka_sub_domain_setting.php
源码
<?php
!defined('EMLOG_ROOT') && exit('操作禁止');
date_default_timezone_set('Etc/GMT-8');
?>
<?php
$DB = MySql::getInstance();
$opt = $_GET['opt'];
$st = $_GET['st'];
$id = $_GET['id'];
?>
<style>
#sub_domain{border:1px solid #ddd;padding:20px;}
.sub_domain_option{margin-top:15px;border:1px solid #ddd;line-height:28px;height:28px;padding-left:10px;}
.sub_domain_option .li{float:left;margin-right:20px;}
.sub_domain_opt{border:1px solid #ddd;border-top:0px;}
.sub_domain_opt .ul{}
.sub_domain_opt .ul .li{float:left;text-align:center;padding:0px 15px;border-right:1px solid #ddd;border-bottom:1px solid #ddd;height:28px;line-height:28px;}
.sub_domain_opt .ul .li:nth-child(1){width:5%;}
.sub_domain_opt .ul .li:nth-child(2){width:10%;}
.sub_domain_opt .ul .li:nth-child(3){width:28%;}
.sub_domain_opt .ul .li:nth-child(4){width:5%;}
.sub_domain_opt .ul .li:nth-child(5){width:5%;}
.sub_domain_opt .ul .li:nth-child(6){width:8%;}
.sub_domain_opt .ul .li:nth-child(7){width:10%;height:28px;}
.sub_domain_opt .ul:last-child .li{border-bottom:0px;}
.sub_domain_opt .ul2 .li2{float:left;text-align:center;padding:0px 15px;border-right:1px solid #ddd;border-bottom:1px solid #ddd;height:28px;line-height:28px;}
.sub_domain_opt .ul2 .li2:nth-child(1){width:10%;}
.sub_domain_opt .ul2 .li2:nth-child(2){width:20%;}
.sub_domain_opt .ul2 .li2 input{height:28px;border:0px;padding:0;outline:none;}
.sub_domain_opt .ul2 input[type='submit']{background:none;border:none;text-align:center;margin:5px;margin-left:15%;}
</style>
<div id="sub_domain">
<div style="font-size:22px;line-height:30px;">二级域名综合插件</div>
<div class="sub_domain_option">
<div class="li"><a href="?plugin=misaka_sub_domain">列表</a></div>
<div class="li"><a href="?plugin=misaka_sub_domain&opt=add">增加二级域名</a></div>
<div class="li"><a href="<?php echo BLOG_URL; ?>?plugin=misaka_sub_domain" target="_blank">查看二级域名前台列表</a></div>
<div class="li"><a href="?plugin=misaka_sub_domain&opt=links">查看友联链接</a></div>
</div>
<div class="sub_domain_opt">
<?php
$pluginblogurl = str_replace('http://www.','',BLOG_URL);
$pluginblogurl = str_replace('https://www.','',BLOG_URL);//替换https
$pluginblogurl = str_replace('/','',$pluginblogurl);
if(!$opt){
$ye = 10;
$page = intval($_GET['page']) ? $_GET['page'] : 1;
$pageurl = '?plugin=sub_domain&page=';
echo '<div class="ul"><div class="li">序号</div><div class="li">搜索词</div><div class="li">二级域名</div><div class="li">查看</div><div class="li">操作</div><div class="li">友情链接</div><div class="li"> </div><div style="clear:both;"></div></div>';
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain";
$strs = $DB->query($sql);
$zon = $DB->num_rows($strs);
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain order by id desc LIMIT ".($page-1).",".$ye;
$strs = $DB->query($sql);
while($row = $DB->fetch_array($strs)){
echo '<div class="ul"><div class="li">'.$row['id'].'</div><div class="li">'.$row['searchword'].'</div><div class="li"><a href="//'.$row['subdomain'].'.'.$pluginblogurl.'" title="'.$row['webtitle'].'" target="_blank">'.$row['subdomain'].'.'.$pluginblogurl.'</a></div><div class="li"><a href="//'.$row['subdomain'].'.'.$pluginblogurl.'" title="'.$row['webtitle'].'" target="_blank">≡</a></div><div class="li"><a href="?plugin=misaka_sub_domain&opt=edit&id='.$row['id'].'">修改</a></div><div class="li"><a href="?plugin=misaka_sub_domain&opt=link&st=add&id='.$row['id'].'">添加</a> <a href="?plugin=misaka_sub_domain&opt=link&st=look&id='.$row['id'].'">查看</a></div><div class="li"><a href="?plugin=misaka_sub_domain&opt=del&id='.$row['id'].'">删除</a></div><div style="clear:both;"></div></div>';
}
echo '<style>#msk_pagenavi .box .pages{float:left;padding:5px;}</style><div id="msk_pagenavi"><div class="box">'.misakapage($zon,$ye,$page,$pageurl).'<div style="clear:both;"></div></div></div>';
}elseif($opt == 'links'){
//友情链接显示列表
$ye = 10;
$page = intval($_GET['page']) ? $_GET['page'] : 1;
$pageurl = '?plugin=sub_domain&opt=links&page=';
echo '<div class="ul"><div class="li" style="width:20%;">有效期</div><div class="li">名称</div><div class="li">网址</div><div class="li" style="width:10%;">操作</div><div style="clear:both;"></div></div>';
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links";
$strs = $DB->query($sql);
$zon = $DB->num_rows($strs);
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links LIMIT ".($page-1).",".$ye;
$strs = $DB->query($sql);
while($row = $DB->fetch_array($strs)){
//var_dump($row);
echo '<div class="ul">
<div class="li" style="width:20%;">剩余'.(($row['outtime']-$row['starttime'])/3600/24).'天</div>
<div class="li">'.$row['linkname'].'</div>
<div class="li">'.$row['linkurl'].'</div>
<div class="li" style="width:10%;">
<a href="?plugin=misaka_sub_domain&opt=link&st=edit&id='.$row['id'].'">修改</a>
<a href="?plugin=misaka_sub_domain&opt=link&st=del&id='.$row['id'].'">删除</a>
</div>
<div style="clear:both;"></div>
</div>';
}
echo '<style>#msk_pagenavi .box .pages{float:left;padding:5px;}</style><div id="msk_pagenavi"><div class="box">'.misakapage($zon,$ye,$page,$pageurl).'<div style="clear:both;"></div></div></div>';
}elseif($opt == 'link' and $st){
if($_GET['st'] == 'add'){
if($_POST['st'] == 'add'){
$domainid = $_GET['id'] ? $_GET['id'] : 0;
$linkname = $_POST['name'] ? $_POST['name'] : '';
$linkurl = $_POST['weburl'] ? $_POST['weburl'] : '';
$starttime = time();
$outtime = $_POST['outtime'] ? (($_POST['outtime']*365*24*3600)+time()) : 0;
$status = $_POST['status'];
$DB->query("INSERT INTO ".DB_PREFIX."misaka_sub_domain_links (domainid,linkname,linkurl,starttime,outtime,status) VALUES (".$domainid.",'".$linkname."','".$linkurl."',".$starttime.",".$outtime.",'".$status."')");
//不做重复性判断
echo'<script>alert(\'添加成功\');window.location.href="./plugin.php?plugin=misaka_sub_domain&opt=links";</script>';
exit;
}
sub_domain_opt_link_add($id,$domainid);
}
if($_GET['st'] == 'edit'){
var_dump($_POST);
echo 'id='.$id;
if($_POST['st'] == 'edit'){
$domainid = $_POST['domainid'] ? $_POST['domainid'] : '';
$linkname = $_POST['name'] ? $_POST['name'] : '';
$linkurl = $_POST['weburl'] ? $_POST['weburl'] : '';
$starttime = time();
$outtime = $_POST['outtime'] ? (($_POST['outtime']*365*24*3600)+time()) : 0;
//$status = $_POST['status'];
$sql = "UPDATE ".DB_PREFIX."misaka_sub_domain_links SET domainid='".$domainid."',linkname='".$linkname."',linkurl='".$linkurl."',starttime='".$starttime."',outtime='".$outtime."' WHERE id=".$id;
$DB->query($sql);
//不做重复性判断
echo'<script>alert(\'修改成功\');window.location.href="./plugin.php?plugin=misaka_sub_domain&opt=links";</script>';
exit;
}
sub_domain_opt_link_edit($id,$domainid);
}
if($_GET['st'] == 'del'){
if(intval($id)){
$id = intval($id);
$DB->query("DELETE FROM ".DB_PREFIX."misaka_sub_domain_links WHERE id={$id}");
header("Location:./plugin.php?plugin=misaka_sub_domain&opt=links");
exit;
}
}
if($_GET['st'] == 'look'){
if(intval($id)){
sub_domain_opt_link_look($id);
//echo 'id='.$id;
}
}
}elseif($opt == 'add'){
if($_POST['acc'] == 'add'){
$searchword = $_POST['searchword'] ? $_POST['searchword'] : '';
$subdomain = $_POST['subdomain'] ? $_POST['subdomain'] : '';
//$subdomain .= '.'.str_replace('www.','',$_SERVER['HTTP_HOST']);
$webtitle = $_POST['webtitle'] ? $_POST['webtitle'] : '';
$webkey = $_POST['webkey'] ? $_POST['webkey'] : '';
$webdiscription = $_POST['webdiscription'] ? $_POST['webdiscription'] : '';
//查看二级域名是否重复
$result = $DB->query("SELECT * FROM ".DB_PREFIX."misaka_sub_domain WHERE subdomain = '{$subdomain}'");
$t = $DB->fetch_array($result);
if(!$t['subdomain']){
$DB->query("INSERT INTO ".DB_PREFIX."misaka_sub_domain (searchword,subdomain,webtitle,webkey,webdiscription) VALUES ('".$searchword."','".$subdomain."','".$webtitle."','".$webkey."','".$webdiscription."')");
}else{
echo'<script>alert(\'二级域名重复\');window.location.href="./plugin.php?plugin=misaka_sub_domain&&opt=add";</script>';
exit;
}
echo'<script>alert(\'添加成功\');window.location.href="./plugin.php?plugin=misaka_sub_domain";</script>';
exit;
}
sub_domain_opt_add($pluginblogurl);
}elseif($opt == 'edit'){
if($_POST['acc'] == 'edit' and $id){
$webid = $id;
$searchword = $_POST['searchword'] ? $_POST['searchword'] : '';
$subdomain = $_POST['subdomain'] ? $_POST['subdomain'] : '';
//$subdomain .= '.'.str_replace('www.','',$_SERVER['HTTP_HOST']);
$webtitle = $_POST['webtitle'] ? $_POST['webtitle'] : '';
$webkey = $_POST['webkey'] ? $_POST['webkey'] : '';
$webdiscription = $_POST['webdiscription'] ? $_POST['webdiscription'] : '';
$sql = "UPDATE ".DB_PREFIX."misaka_sub_domain SET searchword='".$searchword."',subdomain='".$subdomain."',webtitle='".$webtitle."',webkey='".$webkey."',webdiscription='".$webdiscription."' WHERE id=".$webid;
$DB->query($sql);
echo'<script>alert(\'修改成功\');window.location.href="./plugin.php?plugin=misaka_sub_domain";</script>';
exit;
}
sub_domain_opt_edit($id,$pluginblogurl);
}elseif($opt == 'del'){
if(intval($id)){
$id = intval($id);
$DB->query("DELETE FROM ".DB_PREFIX."misaka_sub_domain WHERE id={$id}");
header("Location:./plugin.php?plugin=misaka_sub_domain");
//echo'<script>window.location.href="./plugin.php?plugin=sub_domain";</script>';
exit;
}
}
?>
</div>
<?php
function sub_domain_opt_link_look($id){
$DB = MySql::getInstance();
$ye = 10;
$page = intval($_GET['page']) ? $_GET['page'] : 1;
$pageurl = '?plugin=sub_domain&opt=links&page=';
echo '<div class="ul"><div class="li" style="width:20%;">有效期</div><div class="li">名称</div><div class="li">网址</div><div class="li" style="width:10%;">操作</div><div style="clear:both;"></div></div>';
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links WHERE domainid = ".$id;
$strs = $DB->query($sql);
$zon = $DB->num_rows($strs);
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links WHERE domainid = ".$id." LIMIT ".($page-1).",".$ye;
$strs = $DB->query($sql);
while($row = $DB->fetch_array($strs)){
//var_dump($row);
echo '<div class="ul">
<div class="li" style="width:20%;">剩余'.(($row['outtime']-$row['starttime'])/3600/24).'天</div>
<div class="li">'.$row['linkname'].'</div>
<div class="li">'.$row['linkurl'].'</div>
<div class="li" style="width:10%;">
<a href="?plugin=misaka_sub_domain&opt=link&st=edit&id='.$row['id'].'">修改</a>
<a href="?plugin=misaka_sub_domain&opt=link&st=del&id='.$row['id'].'">删除</a>
</div>
<div style="clear:both;"></div>
</div>';
}
echo '<style>#msk_pagenavi .box .pages{float:left;padding:5px;}</style><div id="msk_pagenavi"><div class="box">'.misakapage($zon,$ye,$page,$pageurl).'<div style="clear:both;"></div></div></div>';
}
function sub_domain_opt_link_add($id,$domainid,$status = '有效'){
$DB = MySql::getInstance();
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links WHERE id=".$id;
$strs = $DB->query($sql);
$row = $DB->fetch_array($strs);
echo '<form name="keyform" method="post" action="">';
echo '<input name="st" type="hidden" value="add"/>';
echo '<input name="status" type="hidden" value="'.$status.'"/>';
echo '<div class="ul2"><div class="li2">添加二级友链</div><div class="li2"></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">名称</div><div class="li2"><input name="name" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">链接</div><div class="li2"><input name="weburl" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">有效期</div><div class="li2"><input name="outtime" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><input type="submit" value="提交"></div>';
echo '</form>';
}
function sub_domain_opt_link_edit($id){
$DB = MySql::getInstance();
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain_links WHERE id=".$id;
$strs = $DB->query($sql);
$row = $DB->fetch_array($strs);
echo '<form name="keyform" method="post" action="">';
echo '<input name="st" type="hidden" value="edit"/>';
echo '<input name="domain" type="hidden" value="'.$row['domainid'].'"/>';
echo '<div class="ul2"><div class="li2">修改二级友链</div><div class="li2"></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">名称</div><div class="li2"><input name="name" type="text" value="'.$row['linkname'].'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">链接</div><div class="li2"><input name="weburl" type="text" value="'.$row['linkurl'].'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">有效期</div><div class="li2"><input name="outtime" type="text" value="'.ceil(($row['outtime']-$row['starttime'])/86400/365).'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><input type="submit" value="提交"></div>';
echo '</form>';
}
function sub_domain_opt_add($pluginblogurl){
echo '<form name="keyform" method="post" action="">';
echo '<input name="acc" type="hidden" value="add"/>';
echo '<div class="ul2"><div class="li2">新建二级域名</div><div class="li2">ver.20180323</div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">搜索词</div><div class="li2"><input name="searchword" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">二级域名</div><div class="li2"><input name="subdomain" type="text" /></div><span>.'.$pluginblogurl.'</span><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">网站标题</div><div class="li2"><input name="webtitle" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">网站关键字</div><div class="li2"><input name="webkey" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">网站描述</div><div class="li2"><input name="webdiscription" type="text" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><input type="submit" value="提交"></div>';
echo '</form>';
}
function sub_domain_opt_edit($webid,$pluginblogurl){
$DB = MySql::getInstance();
$sql = "SELECT * FROM ".DB_PREFIX."misaka_sub_domain WHERE id=".$webid;
$strs = $DB->query($sql);
$row = $DB->fetch_array($strs);
echo '<form name="keyform" method="post" action="">';
echo '<input name="acc" type="hidden" value="edit"/>';
echo '<div class="ul2"><div class="li2">编辑二级域名</div><div class="li2">ver.20180323</div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">搜索词</div><div class="li2"><input name="searchword" type="text" value="'.$row['searchword'].'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">二级域名</div><div class="li2"><input name="subdomain" type="text" value="'.$row['subdomain'].'" /></div><span>.'.$pluginblogurl.'</span><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">网站标题</div><div class="li2"><input name="webtitle" type="text" value="'.$row['webtitle'].'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">网站关键字</div><div class="li2"><input name="webkey" type="text" value="'.$row['webkey'].'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><div class="li2">网站描述</div><div class="li2"><input name="webdiscription" type="text" value="'.$row['webdiscription'].'" /></div><div style="clear:both;"></div></div>';
echo '<div class="ul2"><input type="submit" value="提交"></div>';
echo '</form>';
}
function misakapage($lognum,$index_lognum,$page,$pageurl){
//echo '总数'.$lognum.' 每页'.$index_lognum.'当前页'.$page.'总页数'.ceil($lognum/$index_lognum);
$urlHome = preg_replace("|[\?&/][^\./\?&=]*page[=/\-]|", "", $pageurl);
if($page == 0){
$re = '';
}elseif($page == 1){
$re .= '<div class="pages red">1</div>';
for($i = 2; $i <= 5 && $i <= ceil($lognum/$index_lognum); $i++){
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif($page <= 3){
$re .= '<div class="pages"><a href="'.$pageurl.($page - 1).'">上一页</a></div>';
for($i = 1; $i <= 5 && $i <= ceil($lognum/$index_lognum); $i++){
if($i == $page){
$re .= '<div class="pages red">'.$i.'</div>';
}else{
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif($page <= ceil($lognum/$index_lognum) - 2){
$re .= '<div class="pages"><a href="'.$pageurl.($page - 1).'">上一页</a></div>';
for($i = $page - 2; $i <= $page + 2 && $i <= ceil($lognum/$index_lognum); $i++){
if($i == $page){
$re .= '<div class="pages red">'.$i.'</div>';
}else{
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif($page <= ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page - 1).'">上一页</a></div>';
for($i = ceil($lognum/$index_lognum) - 2; $i > 0 && $i <= ceil($lognum/$index_lognum); $i++){
if($i == $page){
$re .= '<div class="pages red">'.$i.'</div>';
}else{
$re .= '<div class="pages"><a href="'.$pageurl.$i.'">'.$i.'</a></div>';
}
}
if($page < ceil($lognum/$index_lognum)){
$re .= '<div class="pages"><a href="'.$pageurl.($page + 1).'">下一页</a></div>';
}
}elseif(ceil($lognum/$index_lognum) <= 1){
$re = '';
}else{
}
return $re;
}
?>
涉及模板的修改部分
header.php开头部分
源码
<?php
if(function_exists(misaka_header)){
$msk_row = misaka_header();
extract($msk_row);
}
if($tag){
if($webtitle){
$site_title = stripslashes($tag).' - '.$webtitle;
}else{
$site_title = stripslashes($tag).' - '.$blogname;
}
}
?>
footer.php结尾部分添加了钩子
module.php的widget_link方法修改为如下
源码
//widget:链接
function widget_link($title) {
global $CACHE;
if(function_exists(misaka_header)){
$msk_row = misaka_header();
extract($msk_row);
}
$link_cache = $CACHE->readCache('link');if (!tool_ishome()) {return;}?><div class="sidebar-box"><h5 class="sidebar-title"><?php echo $title; ?></h5><div class="sidebar-link"><ul class="clearfix"><?php foreach ($link_cache as $value): ?><li><a href="<?php echo $value['url']; ?>" title="<?php echo $value['des']; ?>" target="_blank"><?php echo $value['link']; ?></a></li><?php endforeach;?>
<?php echo get_domain_link($domainid); ?>
</ul></div></div><?php
}
以上插件是用业余时间断断续续的写的,价格是自愿给的.(给了160块)
如果你对这篇文章有什么改进意见,请点击这里告诉我。
热门
随机
御坂网络 - 任何足夠先進的技術,初看皆與魔法無異!