梦秀博客

@Mengx

不忘初心 · 方得始终

  • Guang Zhou
  • https://mengx.io
  • 网站成立 300 天

Mengx

  • Emlog教程

纯代码实现Emlog自助申请友情链接

如题,不说那么多废话,就是免去插件,在主题上加入访客自助申请友情链接的功能。

首先在主题目录下新建一个文件,例如page_link.php,代码如下:

<?php   
/* 
Custom:page_link
Description:自助申请友链
*/  
if(!defined('EMLOG_ROOT')) {exit('error!');}   
?>

<style type="text/css">
.left_bar {
    display:none;
}
		
#content {
	width: 100%;
}
		
#main_container {
	max-width: 1080px;
}
/*自助申请友情链接*/
@media screen and (max-width: 750px) { 
.row .card  {width: 100%} 
} 
.row .pricing-deco .deco-layer {
	-webkit-transition: -webkit-transform 0.5s;
	transition: transform 0.5s;
}

.row .pricing-deco:hover .deco-layer--1 {
	-webkit-transform: translate3d(15px,0,0);
	transform: translate3d(15px,0,0);
}

.row .pricing-deco:hover .deco-layer--2 {
	-webkit-transform: translate3d(-15px,0,0);
	transform: translate3d(-15px,0,0);
}

.srcdict-yqlj{
	margin-left: -10px;
	margin-right: -10px;
	display: flex;
	background:#fff;
	border-radius: 6px;
	height: 430px;
	box-shadow: 0 4px 12px 0 rgba(52, 73, 94, 0.1);
}

.clearfix{
	color: #bebebe;
	background-color: #f1f3f4;
	margin-top: 1rem;
	padding: 1rem 1.5rem;
	border: 1px solid transparent;
	border-radius: .375rem;
	max-width: 100%;
}
p{color:#565656;}
.mt20{
	margin-top: 20px;
	margin-bottom: 15px;
}
.form-group{
	margin-top: 35px;
	margin-left: 55px;
}
input[type=text]{
	padding: 7px 10px;
}
.submit{
	background: -webkit-gradient(linear,left top,right top,from(#9c51ff),to(#816bff));
    background: -webkit-linear-gradient(90deg,#9c51ff,#816bff);
    background: linear-gradient(90deg,#9c51ff,#816bff);
    color: #fff;
    padding: 15px 30px;
    border: none;
    cursor: pointer;
    outline:none;
}
.card-header
{
    padding: 1.25rem 1.5rem;
    font-size: 1.0625rem;
    background-color: #fff;
}
.card-header:first-child
{
    border-radius: calc(.375rem - 1px) calc(.375rem - 1px) 0 0;
}
	</style>
<div id="main_container" class="main_loop_content">
<div class="left_bar">
	
	<?php include View::getView('left-user');?>

	<div class="alteration shadow round" style="background: #fff;">
	<?php include View::getView('side-left');?>
	</div>

</div>

<div id="content" class="site-content ">
	<?php if(!blog_tool_ishome()):include View::getView('cat-nav');?><?php endif;?>
		
	<div class="page_container full-page">
	
	<header class="page-header" style="background-image: url(<?php echo TEMPLATE_URL; ?>img/default.jpg);">
		<div class="page_meta">
			<h1 class="entry-title"><?php echo $log_title; ?></h1>		</div>	
	</header><!-- .page-header -->
		
	<div class="entry-content">
		<div class="srcdict-yqlj">
<div class="col-lg-6 col-12" style="width:500px;">
<!--表单开始-->
<form method="post" class="mt20" action="">
 
<div class="form-group">
<label for="blink_name"><font color="red">*</font> 站点名称:</label>
<input type="text" size="40" value="" class="form-control" id="blink_name" placeholder="网站名称 不超过7个字" name="link_name">
</div>
 
<div class="form-group">
<label for="blink_url"><font color="red">*</font> 网站地址:</label>
<input type="text" size="40" value="" class="form-control" id="blink_url" placeholder="要求:带http://或https://" name="link_url">
</div>
 
<div class="form-group">
<label for="blink_lianxi"><font color="red">*</font> 站点描述:</label><br>
<textarea name="link_des" style="width:423px;height:103px;margin-top:10px;margin-bottom:15px;margin-left:10px;padding: 7px 10px;" placeholder="在这里填写您的网站描述!"></textarea>
</div>
 
<div style="margin-left:150px">
<input type="hidden" value="send" name="blink_form">
<button type="submit" class="submit">提交申请</button>
<button type="reset" class="submit">重填</button><br>
<p style="font-size:14px">温馨提示:带有<font color="red">*</font>,表示必填项~</p>
</div>
</form>
<!--表单结束-->
</div>
 
<div class="col-lg-6 col-12" style="width:450px;margin-left:18px">
<article class="col-md-10 mt20 col-md-offset-2 view clearfix">
 
<p class="mt20"><strong>申请条件如下</strong></p> <!--根据自身修改-->
 
<p>✔ 有权重有排名,收录良好的,内容健康,内容相关更佳;</p> <!--根据自身修改-->
 
<p>✔ 稳定更新,网站简洁无广告,不接受有广告的资源站点;</p> <!--根据自身修改-->
 
<p>✔ 网站内容不违反法律,不触犯道德底线,即可添加本站;</p> <!--根据自身修改-->
 

 
<p><font color="#FF5809">如果您是妹子可直接发照片到管理员邮箱,无视以上条件。</font> 
 
</p> <!--根据自身修改-->
 
<p>建议您在本页面直接申请!管理员邮箱:124878@qq.com</p> <!--根据自身修改-->

<p class="mt20"><strong>本站链接信息:Name:Mengx Blog    URL:https://Mengx.io</strong></p> <!--根据自身修改-->

</article></div>
 

</div>
	</div>

</div>

</div>

<?php
 include View::getView('footer');
?>
<?php
if(!empty($_POST)){
	do_link();
}

function do_link(){
$link_name = htmlspecialchars($_POST['link_name']);
$link_url = htmlspecialchars($_POST['link_url']);
$link_des = htmlspecialchars($_POST['link_des']);
$link_hide = 'y';

// 表单项数据验证
if ( empty($link_name) || mb_strlen($link_name) > 20 ){
	echo '<div class="c-tips animate bounceIn" style="display: block;margin-top:300px"><p class="c-tips-message shadow gradient"><i class="iconfont icon-weibiaoti1"></i>链接名称必须填写,且长度不得超过30字</p></div>';
	echo '<script>window.onload = function(){
    setTimeout("history.back()", 3000);
}</script>';
}elseif( empty($link_url) || strlen($link_url) > 60 || !preg_match("/^(https?:\/\/)?(((www\.)?[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)?\.([a-zA-Z]+))|(([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5]))(\:\d{0,4})?)(\/[\w- .\/?%&=]*)?$/i", $link_url)) { //验证url
	echo '<div class="c-tips animate bounceIn" style="display: block;margin-top:300px"><p class="c-tips-message shadow gradient"><i class="iconfont icon-weibiaoti1"></i>链接地址必须填写!</p></div>';
	echo '<script>window.onload = function(){
    setTimeout("history.back()", 3000);
}</script>';
}else{
	addlinks($link_name,$link_url,$link_des,$link_hide);
	echo '<div class="c-tips animate bounceIn" style="display: block;margin-top:300px"><p class="c-tips-message shadow gradient"><i class="iconfont icon-weibiaoti1"></i>申请成功,等待站长审核!</p></div>';
	echo '<script>window.onload = function(){
    setTimeout("history.back()", 3000);
}</script>';
	
}

}

function addlinks($link_name,$link_url,$link_des,$hide,$taxis='0'){
$DB = Database::getInstance();
$sql = "insert into ".DB_PREFIX."link (sitename,siteurl,description,hide,taxis) values('$link_name','$link_url','$link_des','$hide', $taxis)";
echo $sql;
$list = $DB->query($sql);
}?>

以上CSS样式是根据 Emlog主题EASTER来写的 可能和你们的主题会有冲突错位等,这些需要自己去修改了!

调用只需要在后台->新建页面->页面模板 填写为我们新建的这个文件名(不需要带.php): page_link

Comments | 0 条评论

  游客,你好 修改资料

*邮箱和昵称必须填写