[ PHPXref.com ] [ Generated: Sun Jul 20 16:35:25 2008 ] [ bBlog 0.7.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/bblog/bBlog_plugins/ -> admin.comments.php (source)

   1  <?php
   2  // admin.comments.php - administer comments
   3  /*
   4  ** bBlog Weblog http://www.bblog.com/
   5  ** Copyright (C) 2003  Eaden McKee <email@eadz.co.nz>
   6  **
   7  ** This program is free software; you can redistribute it and/or modify
   8  ** it under the terms of the GNU General Public License as published by
   9  ** the Free Software Foundation; either version 2 of the License, or
  10  ** (at your option) any later version.
  11  **
  12  ** This program is distributed in the hope that it will be useful,
  13  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  ** GNU General Public License for more details.
  16  **
  17  ** You should have received a copy of the GNU General Public License
  18  ** along with this program; if not, write to the Free Software
  19  ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  */
  21  
  22  function identify_admin_comments () {
  23      return array (
  24      'name'           =>'comments',
  25      'type'             =>'admin',
  26      'nicename'     =>'Comments',
  27      'description'   =>'Remove, Approve or Edit comments',
  28      'authors'        =>'Eaden McKee <eadz@bblog.com>',
  29      'licence'         =>'GPL',
  30      'template'     => 'comments_admin.html',
  31      'help'        => ''
  32    );
  33  }
  34  
  35  function admin_plugin_comments_run(&$bBlog) {
  36    // Again, the plugin API needs work.
  37    $commentAmount = 50;
  38    if(isset($_GET['commentdo']))  { $commentdo = $_GET['commentdo']; }
  39    elseif (isset($_POST['commentdo'])) { $commentdo = $_POST['commentdo']; }
  40    else { $commentdo = ""; }
  41    
  42    switch($commentdo) {
  43      case "Delete" : // delete comments
  44          if(is_array($_POST['commentid'])){
  45            foreach($_POST['commentid'] as $key=>$val){
  46              deleteComment(&$bBlog, $val);
  47          }
  48        }
  49        break;
  50      case "Edit" :
  51        $commentid = intval($_GET['editComment']);
  52        $postid = intval($_GET['postid']);
  53        editComment(&$bBlog, $commentid, $postid);
  54        break;
  55      case "editsave" :
  56        saveEdit(&$bBlog);
  57        break;
  58      case "Approve":
  59        if(is_array($_POST['commentid'])){
  60          foreach($_POST['commentid'] as $key=>$val)
  61            $bBlog->query("UPDATE ".T_COMMENTS." SET onhold='0' WHERE commentid='".intval($val)."'");
  62        }
  63        break;
  64      case "25":
  65      case "50":
  66      case "100":
  67      case "150":
  68      case "200":
  69        $commentAmount = intval($commentdo);
  70        break;
  71      default : // show form
  72        break;
  73      }
  74      
  75      retrieveComments(&$bBlog, $commentAmount);
  76      populateSelectList(&$bBlog);
  77      
  78  }
  79  
  80  function deleteComment(&$bBlog, $id){
  81    $id = intval($id);
  82    $postid = $bBlog->get_var('select postid from '.T_COMMENTS.' where commentid="'.$id.'"');
  83    $childcount = $bBlog->get_var('select count(*) as c from '.T_COMMENTS .' where parentid="'.$id.'" group by commentid');
  84    if($childcount > 0) { // there are replies to the comment so we can't delete it.
  85      $bBlog->query('update '.T_COMMENTS.' set deleted="true", postername="", posteremail="", posterwebsite="", pubemail=0, pubwebsite=0, commenttext="Deleted Comment" where commentid="'.$val.'"');
  86    } else { // just delete the comment
  87      $bBlog->query('delete from '.T_COMMENTS.' where commentid="'.$id.'"');
  88    }
  89    $newnumcomments = $bBlog->get_var('SELECT count(*) as c FROM '.T_COMMENTS.' WHERE postid="'.$postid.'" and deleted="false" group by postid');
  90    $bBlog->query('update '.T_POSTS.' set commentcount="'.$newnumcomments.'" where postid="'.$postid.'"');
  91    $bBlog->modifiednow();
  92  }
  93  
  94  function editComment(&$bBlog, $commentid, $postid){
  95    $rval = true;
  96    if(!(is_numeric($commentid) && is_numeric($postid)))
  97      $rval = false;
  98    $comment = $bBlog->get_comment($postid,$commentid);
  99    if(!$comment)
 100      $rval = false;
 101    if($rval === true){
 102      $bBlog->assign('showeditform',TRUE);
 103      $bBlog->assign('comment',$comment[0]);
 104    }
 105    return $rval;
 106  }
 107  
 108  function saveEdit(&$bBlog){
 109    $rval = true;
 110    if(!(is_numeric($_POST['commentid'])))
 111      $rval = false;
 112    $title = my_addslashes($_POST['title']);
 113    $author = my_addslashes($_POST['author']);
 114    $email  = my_addslashes($_POST['email']);
 115    $websiteurl = my_addslashes($_POST['websiteurl']);
 116    $body = my_addslashes($_POST['body']);
 117    if($rval === true){
 118      $q = "update ".T_COMMENTS." set title='$title', postername='$author', posterwebsite='$websiteurl', posteremail='$email', commenttext='$body' where commentid='{$_POST['commentid']}'";
 119      if($bBlog->query($q) === true)
 120        $bBlog->assign('message', 'Comment <em>'.$title.'</em> saved');
 121    }
 122    return $rval;
 123  }
 124  
 125  function retrieveComments(&$bBlog, $amount){
 126    if ((isset($_POST['post_comments'])) && (is_numeric($_POST['post_comments']))) {
 127      $post_comments_q = "SELECT * FROM `".T_COMMENTS."` , `".T_POSTS."` WHERE `".T_POSTS."`.`postid`=`".T_COMMENTS."`.`postid` and deleted='false' and `".T_COMMENTS."`.`postid`='".$_POST['post_comments']."' order by `".T_COMMENTS."`.`posttime` desc";
 128      $bBlog->assign('comments',$bBlog->get_results($post_comments_q));
 129      $bBlog->assign('message','Showing comments for PostID '.$_POST['post_comments']); //.'.<br /><a href="index.php?b=plugins&amp;p=comments">Click here to show 50 most recent comments</a>.');
 130    } else {
 131      //$bBlog->assign('message','Showing '.$amount.' most recent comments across all posts. ');
 132      $bBlog->assign('comments',$bBlog->get_results("SELECT * FROM `".T_COMMENTS."` , `".T_POSTS."` WHERE `".T_POSTS."`.`postid`=`".T_COMMENTS."`.`postid` and deleted='false' order by `".T_COMMENTS."`.`posttime` desc limit 0,".$amount));
 133      $bBlog->assign('commentAmount', $amount);
 134    }
 135  }
 136  
 137  function populateSelectList(&$bBlog){
 138    $posts_with_comments_q = "SELECT ".T_POSTS.".postid, ".T_POSTS.".title, count(*) c FROM ".T_COMMENTS.",  ".T_POSTS."     WHERE ".T_POSTS.".postid = ".T_COMMENTS.".postid GROUP BY ".T_POSTS.".postid ORDER BY ".T_POSTS.".posttime DESC ";
 139  
 140  // previously function populateSelectList(&$bBlog){
 141  //  $posts_with_comments_q = "SELECT ".T_POSTS.".postid, ".T_POSTS.".title, count(*) c FROM ".T_COMMENTS.",  ".T_POSTS."     WHERE ".T_POSTS.".postid = ".T_COMMENTS.".postid GROUP BY ".T_POSTS.".postid ORDER BY ".T_POSTS.".posttime DESC  LIMIT 0 , 30 ";  
 142  //removed the LIMIT parameter as it was unnecessary
 143    
 144    $posts_with_comments = $bBlog->get_results($posts_with_comments_q,ARRAY_A);
 145    $bBlog->assign("postselect",$posts_with_comments);
 146  }
 147  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]