你现在的位置:首页 > PHP网站建设知识库 > phpcms > 正文

phpcms v9会员投稿预览(未审核)功能实现


phpcms v9会员投稿预览(未审核)功能实现。很多使用phpcms v9的站长反映,会员投稿后,看不到发布的稿子,也不知道投稿的效果如何,很希望能做到想模板超市的会员系统那样,投稿后,即使未审核会员中心也可以预览。

下面讲解如何实现phpcms v9会员投稿预览(未审核):

1.在phpcms\modules\member/content.php加增加以下函数

//文章预览
public function public_preview() {
  $catid = intval($_GET['catid']);
  $id = intval($_GET['id']);
 
  if(!$catid || !$id) showmessage(L('missing_part_parameters'),'blank');
  $page = intval($_GET['page']);
  $page = max($page,1);
  $CATEGORYS = getcache('category_content_'.$this->get_siteid(),'commons');
 
  if(!isset($CATEGORYS[$catid]) || $CATEGORYS[$catid]['type']!=0) showmessage(L('missing_part_parameters'),'blank');
  define('HTML', true);
  $CAT = $CATEGORYS[$catid];
 
  $siteid = $CAT['siteid'];
  $MODEL = getcache('model','commons');
  $modelid = $CAT['modelid'];

  $this->db->table_name = $this->db->db_tablepre.$MODEL[$modelid]['tablename'];
  $r = $this->db->get_one(array('id'=>$id));
  if(!$r) showmessage(L('information_does_not_exist'));
  $this->db->table_name = $this->db->table_name.'_data';
  $r2 = $this->db->get_one(array('id'=>$id));
  $rs = $r2 ? array_merge($r,$r2) : $r;

  //再次重新赋值,以数据库为准
  $catid = $CATEGORYS[$r['catid']]['catid'];
  $modelid = $CATEGORYS[$catid]['modelid'];
 
  require_once CACHE_MODEL_PATH.'content_output.class.php';
  $content_output = new content_output($modelid,$catid,$CATEGORYS);
  $data = $content_output->get($rs);
  extract($data);
  $CAT['setting'] = string2array($CAT['setting']);
  $template = $template ? $template : $CAT['setting']['show_template'];
  $allow_visitor = 1;
  //SEO
  $SEO = seo($siteid, $catid, $title, $description);
 
  define('STYLE',$CAT['setting']['template_list']);
  if(isset($rs['paginationtype'])) {
   $paginationtype = $rs['paginationtype'];
   $maxcharperpage = $rs['maxcharperpage'];
  }
  $pages = $titles = '';
  if($rs['paginationtype']==1) {
   //自动分页
   if($maxcharperpage < 10) $maxcharperpage = 500;
   $contentpage = pc_base::load_app_class('contentpage');
   $content = $contentpage->get_data($content,$maxcharperpage);
  }
  if($rs['paginationtype']!=0) {
   //手动分页
   $CONTENT_POS = strpos($content, '[page]');
   if($CONTENT_POS !== false) {
    $this->url = pc_base::load_app_class('url', 'content');
    $contents = array_filter(explode('[page]', $content));
    $pagenumber = count($contents);
    for($i=1; $i<=$pagenumber; $i++) {
     $pageurls[$i] = $this->url->show($id, $i, $catid, $rs['inputtime']);
    }
    $END_POS = strpos($content, '[/page]');
    if($END_POS !== false) {
     if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) {
      foreach($m[1] as $k=>$v) {
       $p = $k+1;
       $titles[$p]['title'] = strip_tags($v);
       $titles[$p]['url'] = $pageurls[$p][0];
      }
     }
    } else {
     //当不存在 [/page]时,则使用下面分页
     $pages = content_pages($pagenumber,$page, $pageurls);
    }
    //判断[page]出现的位置是否在第一位
    if($CONTENT_POS<7) {
     $content = $contents[$page];
    } else {
     $content = $contents[$page-1];
    }
    if($titles) {
     list($title, $content) = explode('[/page]', $content);
     $content = trim($content);
     if(strpos($content,'</p>')===0) {
      $content = '<p>'.$content;
     }
     if(stripos($content,'<p>')===0) {
      $content = $content.'</p>';
     }
    }
   }
  }
  include template('content',$template);
}

2.打开phpcms\templates\default\member\content_publish.html

<input name="dosubmit" type="submit" id="dosubmit" value="{L('submit')}" class="button">

后增加

<input type="button" name="preview" value=" 预览 " class="button" onclick="preview_content();">

同样的文件

{template 'member', 'footer'}

之上增加

 

<script LANGUAGE="javascript">
<!--
function preview_content()
{
myform.action = "{APP_PATH}index.php?m=member&c=content&a=public_preview";
myform.target = "_blank";
myform.submit();
myform.action = "{APP_PATH}index.php?m=member&c=content&a=public_preview&action={$action}&catid={$catid}&modelid={$modelid}&contentid={$contentid}";
myform.target="_self";
}
//-->
</script>