当前位置:首页 » 好文分享 » 详情

    Emlog非插件实现投稿功能

    此方法并不涉及内核代码修改,只需要建立一个文件夹即可,可以把文章放入草稿、待审或者直接发布,具体看下面教程。

    温馨提示:本教程仅在Emlog5.3.1版本下测试正常,其他版本未做测试,不确保能用的哦!!!以下代码均为自用代码,懂html的可自行修改。

    使用步骤:
    1、首先建立文件夹取名为tougao并放入博客的根目录;
    2、在tougao文件夹中建立一个文件index.php放入如下代码:
    <?php
    require_once '../init.php';//emlog程序此文件的路径,如在一级栏目中请去除../
    define('TEMPLATE_PATH', TPLS_PATH.Option::get('nonce_templet').'/');//前台模板路径
    $sl = isset($_GET['sl'])?intval($_GET['sl']):0;
    global $CACHE;
    $options_cache = $CACHE->readCache('options');
    $navibar = unserialize($options_cache['navibar']);
    $blogname = $options_cache['blogname'];?>
    <!DOCTYPE html><html><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>在线投稿 - <?php echo $blogname;?></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <script charset="utf-8" src="<?php echo BLOG_URL;?>admin/editor/kindeditor.js"></script>
    <style>
    body{background:#fff;font:14px/1.5 tahoma,arial,"Microsoft YaHei";margin:0px;padding:0px;font-size:12px;}ul,li,p,h1,h2,h3,h4,h5,h6{padding:0px;margin:0px;list-style:none;}a{color:#444;text-decoration:none;}a:hover{color:#F36;}
    .sltgq{margin:auto;overflow:hidden;clear:both; max-width:800px;}
    .sltgbt{border-bottom:1px dashed #ccc;line-height:30px;height:30px;font-size:16px;padding-left:10px; margin-top:20px;font-weight:bold;color:#F00;}
    .tougao1,.tougao2{margin:0 10px;overflow:hidden;clear:both;}
    .tougao1 li{clear:both; overflow:hidden;}
    .tougao1 li p{line-height:20px;font-weight:bold; margin:5px 0;}
    .tougao1 li input{height:26px;line-height:26px;}
    .tougao1 li b{color:#F00;}
    .tougao2{margin-top:10px; width:90%;}
    .tougao2 li{overflow:hidden;float:left; margin-right:10px;}
    .tougao2 li p{float:left;border:1px solid #999;height:30px;line-height:30px;padding:0 10px; font-weight:bold;}
    .tougao2 li input{height:26px; line-height:26px;}
    .tougao2 li img{ margin-top:5px;}
    .button input{height:32px;float:left;}
    .tougao2 label{height:32px;line-height:32px; float:right;}
    .nr{margin:auto;overflow:hidden;clear:both; margin-bottom:20px;}
    .nr ul{margin:10px; line-height:25px; font-size:14px;}
    .foot{margin:10px auto;text-align:center;clear:both;overflow:hidden;border-top:1px dashed #ccc;padding:10px 0;line-height:22px;font-size:12px;background:#fff;}
    </style>
    </head><body>
    <?php if($sl==0){$Sort_Model = new Sort_Model();$sorts = $Sort_Model->getSorts();?>
    <div class="sltgq"><div class="sltgbt">在线投稿</div>
    <form action="<?php echo BLOG_URL;?>tougao/?sl=1" method="post" enctype="multipart/form-data" name="addlog" >
    <div class="tougao1">
    <li><p>文章标题  <b>*</b> </p><input name="title" maxlength="200" style="width:98%;" placeholder="文章标题大于10字少于30字" /></li>
    <li><p>作者昵称</p><input name="tags" maxlength="200" style="width:98%;" placeholder="作者名称,10字以内," /></li>
    <li><p>原文地址</p><input name="excerpt" maxlength="200" style="width:98%;" placeholder="不加http://,否则无法提交,如本站首发请不要填写任何网址信息" /></li>
    <li><p>注意事项:文章内容不得少于300字,请排版好,去掉没有必要的html代码,内容中的链接自动过滤</p><textarea name="text" style="width:98%;height:400px;" id="text"></textarea><script>loadEditor('text');</script></li></div>
    <div class="tougao2">
    <li><select name="sortid" style="width:100px;height:30px;"><option value="-1">选择分类...</option><?php foreach($sorts as $val){?><option value=<?php echo $val['sid'];?>><?php echo $val['sortname'];?></option><?php }?></select></li>
    <li><p>验 证 码</p><p>SheLi</p></li>
    <li><input name="imgcode" type="text" size="5" tabindex="5" /></li>
    <div class="button"><input type="submit" value="提交" onclick="return checkform();" /></div><label for="sheli"><input type="checkbox" value=9 id="sheli" name="sheli" required autocomplete="on" title="发表评论确认框:请勾选我再发表评论!"><font color="red">请勾选我再提交!</font></label></div>
    </form>
    <div class="nr"><div class="sltgbt">注意事项</div><ul>
    1、要认真写作,写完后多读几遍,注意排版及去除不必要的html代码<br>
    2、请尊重原作者的权益,请注明文章的作者、原文地址;如果不提供这些信息,文章可能不能通过审核;<br>
    3、本站接受稿件的前提是该信息对广大用户有所帮助,或者比较有创意的产品广告宣传;<br>
    4、标题力求简短、醒目、新颖、吸引人,杜绝标题党,标题尽量不少于10个汉字,不多于30个汉字;<br>
    5、文章应避免用 "今天"、"昨天",应改成具体日期;请尽量给文章配上图片(请注意调用的图片是否屏蔽外部调用);
    </ul></div>
    <div class="foot">Copyright © <?php echo date('Y');?> <?php echo $options_cache['blogname'];?> 版权所有</div>
    </div>
    <?php }elseif($sl==1){
    $Log_Model = new Log_Model();
    $Tag_Model = new Tag_Model();
    $title = isset($_POST['title']) ? addslashes(trim($_POST['title'])) : '';
    $content = isset($_POST['text']) ? addslashes(trim($_POST['text'])) : '';
    $excerpt = isset($_POST['excerpt']) ? addslashes(trim($_POST['excerpt'])) : '';
    $tags = isset($_POST['tags']) ? addslashes(trim($_POST['tags'])) : '';
    $imgcode = isset($_POST['imgcode']) ? addslashes(trim(strtoupper($_POST['imgcode']))) : '';
    $slCode = 'SHELI';
    $author = '';
    $sortid = isset($_POST['sortid']) ? intval($_POST['sortid']) : $config['sort'];
    $date = time() + Option::get('timezone') * 3600;
    $sb_title = mysql_query("select title from emlog_blog where title='$title' limit 1");
    $sb_excerpt = mysql_query("select title from emlog_blog where excerpt='$excerpt' limit 1");
    if(empty($title) || strlen($title) < 30 || strlen($title) > 90 || mysql_fetch_array($sb_title)){emMsg('提交失败:标题出错,可能以下原因造成<br />1、少于10个字或多于30个字<br />2、已经存在','javascript:history.back(-1);');
    }elseif(strlen($tags) > 30){emMsg('提交失败:网址名称出错,多于10个字','javascript:history.back(-1);');
    }elseif(!empty($excerpt) && preg_match("/^[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\’:+!]*([^<>\"])*$/",$excerpt) == false){emMsg('提交失败:原文地址出错,可能以下原因造成<br />1、是否加了http://<br />2、网址格式是否正确<br>3、已经存在','javascript:history.back(-1);');
    //}elseif(mysql_fetch_array($sb_excerpt)){emMsg('提交失败:原文地址出错,此网址已经发表过文章','javascript:history.back(-1);');
    }elseif(empty($content) || strlen($content) < 900 ){emMsg('提交失败:内容没有按要求填写,少于300个字','javascript:history.back(-1);');
    }elseif(preg_match("/^[0-9]*[1-9][0-9]*$/",$sortid)==false &&$config["sort"] =='0'){emMsg('提交失败:请选择分类','javascript:history.back(-1);');
    }elseif($imgcode != $slCode){emMsg('提交失败:验证码错误','javascript:history.back(-1);');
    }
    $logData = array(
    'title' => $title,
    'alias' => '',
    'content' => $content,
    'excerpt' => $excerpt,
    'author' => '2',//指定作者ID
    'date' => $date,
    'top'=> 'n',
    'sortop'=> 'n',
    'sortid'=> $sortid,
    'allow_remark' => 'y',
    'hide' => 'y', //n为直接通过,y为放入草稿
    'checked' => 'n',//n不需要审核,y为需要审核
    'password' => ''
    );
    $blogid = $Log_Model->addlog($logData);
    $Tag_Model->addTag($tags, $blogid);
    header('Location:'.BLOG_URL.'tougao/?sl=2');die;}
    elseif($sl==2){emMsg('提交成功,文章将在审核后发布。<br />请耐心等待,非常感谢您的贡献!',''.BLOG_URL.'tougao');}?>
    </body></html>

    打赏
    X
    打赏方式:
    • 支付宝
    • 微信
    • QQ红包

    打开支付宝扫一扫
    日期:2017年09月20日 06:14:19 星期二   分类:好文分享   浏览(31129)
    本文地址:https://www.blogs.hk/post-2576.html   [百度已收录]
    声明:本页信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
    版权所有:《博客之家
    文章标题:《Emlog非插件实现投稿功能
    除非注明,文章均为 《博客之家》 原创
    转载请注明本文短网址:https://www.blogs.hk/post-2576.html  [生成短网址]

    留言咨询

    自动获取QQ

    昵称

    邮箱

    网址

        站点统计

        • 收录网址:3370 个
        • 发布文章:3008 条
        • 在线人数:1人
        • 总访问量:270525225次
        • 本站运行:12年5月3天
        Copyright © 2025 博客之家 版权所有  
        關於本站免責聲明sitemap新站登錄