2006-12-02 04:36:16 +00:00
< ? php
/*
2013-03-18 14:18:47 +01:00
* e107 website system
*
* Copyright ( C ) 2008 - 2013 e107 Inc ( e107 . org )
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
*/
2006-12-02 04:36:16 +00:00
require_once ( " ../class2.php " );
2009-05-08 21:50:19 +00:00
if ( ! getperms ( " B " ))
{
2016-01-13 19:17:37 -08:00
e107 :: redirect ( 'admin' );
2006-12-02 04:36:16 +00:00
exit ;
}
2009-08-30 08:23:51 +00:00
2015-08-31 15:28:17 -07:00
// include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_prefs.php');
e107 :: lan ( 'core' , 'comment' );
e107 :: lan ( 'core' , 'prefs' , true );
e107 :: css ( 'inline' , " td.status span.label { display:block; width: 100%; padding: 6px 6px; } " );
2009-11-23 04:03:40 +00:00
2009-11-04 03:07:44 +00:00
class comments_admin extends e_admin_dispatcher
{
protected $modes = array (
'main' => array (
'controller' => 'comments_admin_ui' ,
'path' => null ,
'ui' => 'comments_admin_form_ui' ,
'uipath' => null
)
);
protected $adminMenu = array (
2013-03-18 14:18:47 +01:00
'main/list' => array ( 'caption' => LAN_MANAGE , 'perm' => '0' ),
2009-11-04 03:07:44 +00:00
// 'main/create' => array('caption'=> LAN_CREATE, 'perm' => '0'),
2013-03-18 14:18:47 +01:00
'main/prefs' => array ( 'caption' => LAN_PREFS , 'perm' => '0' ),
2009-11-04 03:07:44 +00:00
// 'main/custom' => array('caption'=> 'Custom Page', 'perm' => '0')
);
protected $adminMenuAliases = array (
'main/edit' => 'main/list'
);
protected $menuTitle = 'Comments' ;
}
class comments_admin_ui extends e_admin_ui
{
protected $pluginTitle = LAN_COMMENTMAN ;
2009-11-05 17:32:19 +00:00
protected $pluginName = 'core' ;
2015-02-09 02:21:41 -08:00
protected $eventName = 'comment' ;
2009-11-04 03:07:44 +00:00
protected $table = " comments " ;
2009-11-05 17:32:19 +00:00
2012-08-04 19:07:00 +00:00
protected $listQry = " SELECT c.*,u.user_name FROM #comments as c LEFT JOIN #user AS u ON c.comment_author_id = u.user_id " ;
2015-02-05 00:18:58 -08:00
protected $listOrder = " comment_id desc " ;
2009-11-06 18:37:23 +00:00
//protected $editQry = "SELECT * FROM #comments WHERE comment_id = {ID}";
2009-11-05 17:32:19 +00:00
2009-11-04 03:07:44 +00:00
protected $pid = " comment_id " ;
2009-11-04 03:37:56 +00:00
protected $perPage = 10 ;
2009-11-04 03:07:44 +00:00
protected $batchDelete = true ;
2009-11-06 18:37:23 +00:00
//TODO - finish 'user' type, set 'data' to all editable fields, set 'noedit' for all non-editable fields
2009-11-04 03:07:44 +00:00
protected $fields = array (
2009-11-07 11:20:34 +00:00
'checkboxes' => array ( 'title' => '' , 'type' => null , 'width' => '5%' , 'forced' => TRUE , 'thclass' => 'center' , 'class' => 'center' ),
2015-03-09 18:45:04 -07:00
'comment_id' => array ( 'title' => LAN_ID , 'type' => null , 'width' => '5%' , 'forced' => TRUE ),
2015-08-31 15:28:17 -07:00
'comment_blocked' => array ( 'title' => LAN_STATUS , 'type' => 'method' , 'inline' => false , /*'writeParms' => array("approved","blocked","pending"), */ 'data' => 'int' , 'thclass' => 'center' , 'class' => 'status center' , 'filter' => true , 'batch' => true , 'width' => 'auto' ), // Photo
2013-03-07 22:54:48 -08:00
2013-03-18 14:18:47 +01:00
'comment_type' => array ( 'title' => LAN_TYPE , 'type' => 'method' , 'width' => '10%' , 'filter' => TRUE ),
2012-06-15 12:50:18 +00:00
2015-08-31 15:28:17 -07:00
'comment_item_id' => array ( 'title' => " item id " , 'type' => 'text' , 'readonly' => 2 , 'data' => 'int' , 'width' => '5%' ),
'comment_subject' => array ( 'title' => " subject " , 'type' => 'text' , 'width' => 'auto' , 'thclass' => 'left first' , 'writeParms' => array ( 'size' => 'xxlarge' )), // Display name
2009-11-11 20:57:34 +00:00
'comment_comment' => array ( 'title' => " comment " , 'type' => 'bbarea' , 'width' => '30%' , 'readParms' => 'expand=...&truncate=50&bb=1' ), // Display name
2013-03-18 14:18:47 +01:00
'comment_author_id' => array ( 'title' => LAN_AUTHOR , 'type' => 'user' , 'data' => 'int' , 'width' => 'auto' , 'writeParms' => 'nameField=comment_author_name' ), // User id
2009-11-11 20:57:34 +00:00
'comment_author_name' => array ( 'title' => " authorName " , 'type' => 'user' , 'width' => 'auto' , 'readParms' => 'idField=comment_author_id&link=1' , 'noedit' => true , 'forceSave' => true ), // User name
'u.user_name' => array ( 'title' => " System user " , 'type' => 'user' , 'width' => 'auto' , 'readParms' => 'idField=comment_author_id&link=1' , 'noedit' => true ), // User name
2012-06-15 12:50:18 +00:00
'comment_datestamp' => array ( 'title' => LAN_DATESTAMP , 'type' => 'datestamp' , 'width' => 'auto' ), // User date
2013-03-22 10:48:49 +01:00
'comment_ip' => array ( 'title' => LAN_IP , 'type' => 'ip' , 'width' => '10%' , 'thclass' => 'center' ), // Real name (no real vetting)
2009-11-07 11:20:34 +00:00
'comment_lock' => array ( 'title' => " Lock " , 'type' => 'boolean' , 'data' => 'int' , 'thclass' => 'center' , 'class' => 'center' , 'filter' => true , 'batch' => true , 'width' => 'auto' ),
'options' => array ( 'title' => LAN_OPTIONS , 'type' => null , 'forced' => TRUE , 'width' => '10%' , 'thclass' => 'center last' , 'class' => 'center' )
2009-11-04 03:07:44 +00:00
);
//required (but should be optional) - default column user prefs
2009-11-04 03:37:56 +00:00
protected $fieldpref = array ( 'checkboxes' , 'comment_id' , 'comment_item_id' , 'comment_author_id' , 'comment_author_name' , 'comment_subject' , 'comment_comment' , 'comment_type' , 'options' );
2009-11-04 03:07:44 +00:00
// optional, if $pluginName == 'core', core prefs will be used, else e107::getPluginConfig($pluginName);
2009-11-23 04:03:40 +00:00
protected $prefs = array (
2015-04-08 14:51:06 -07:00
'comments_engine' => array ( 'title' => " Engine " , 'type' => 'dropdown' , 'writeParms' => array ()),
2015-02-06 11:26:22 -08:00
'comments_disabled' => array ( 'title' => PRFLAN_161 , 'type' => 'boolean' , 'writeParms' => 'inverse=1' ), // Same as 'writeParms'=>'reverse=1&enabled=LAN_DISABLED&disabled=LAN_ENABLED'
2009-11-23 04:03:40 +00:00
'anon_post' => array ( 'title' => PRFLAN_32 , 'type' => 'boolean' ),
'comments_icon' => array ( 'title' => PRFLAN_89 , 'type' => 'boolean' ),
'nested_comments' => array ( 'title' => PRFLAN_88 , 'type' => 'boolean' ),
2013-03-18 14:18:47 +01:00
'allowCommentEdit' => array ( 'title' => PRFLAN_90 , 'type' => 'boolean' ),
2009-11-23 04:03:40 +00:00
'comments_emoticons' => array ( 'title' => PRFLAN_166 , 'type' => 'boolean' )
2009-11-04 03:07:44 +00:00
);
2015-03-09 18:45:04 -07:00
2015-04-08 14:51:06 -07:00
public function init ()
{
$engine = e107 :: pref ( 'core' , 'comments_engine' );
if ( $engine != 'e107' ) // Hide all other prefs.
{
$this -> prefs = array (
'comments_engine' => array ( 'title' => " Engine " , 'type' => 'dropdown' , 'writeParms' => array ()),
'comments_disabled' => array ( 'title' => PRFLAN_161 , 'type' => 'boolean' , 'writeParms' => 'inverse=1' ),
);
}
$this -> prefs [ 'comments_engine' ][ 'writeParms' ][ 'optArray' ] = array ( 'e107' => 'e107' );
$addons = e107 :: getAddonConfig ( 'e_comment' );
foreach ( $addons as $plugin => $config )
{
foreach ( $config as $val )
{
$id = $plugin . " :: " . $val [ 'function' ];
$this -> prefs [ 'comments_engine' ][ 'writeParms' ][ 'optArray' ][ $id ] = $val [ 'name' ];
}
}
// print_a($addons);
}
2015-03-09 18:45:04 -07:00
public function afterUpdate ( $new_data , $old_data , $id )
{
if (( $new_data [ 'comment_type' ] == 0 || $new_data [ 'comment_type' ] == 'news' ))
{
$total = e107 :: getDb () -> select ( 'comments' , 'comment_id' , " (comment_type = 0 OR comment_type = 'news') AND comment_item_id = " . $new_data [ 'comment_item_id' ] . " AND comment_blocked = 0 " );
e107 :: getDb () -> update ( " news " , " news_comment_total= " . intval ( $total ) . " WHERE news_id= " . intval ( $new_data [ 'comment_item_id' ]));
// e107::getMessage()->addInfo("Total Comments for this item: ".$total);
}
}
2009-11-23 04:03:40 +00:00
2015-02-05 00:18:58 -08:00
public function beforeDelete ( $data , $id )
{
return true ;
}
/**
* User defined after - delete logic
*/
public function afterDelete ( $deleted_data , $id , $deleted_check )
{
$sql = e107 :: getDb ();
switch ( $deleted_data [ 'comment_type' ])
{
case '0' :
case 'news' : // Need to update count in news record as well
$sql -> update ( 'news' , 'news_comment_total = CAST(GREATEST(CAST(news_comment_total AS SIGNED) - 1, 0) AS UNSIGNED) WHERE news_id=' . $deleted_data [ 'comment_item_id' ]);
break ;
}
}
2009-11-04 03:07:44 +00:00
}
2009-11-04 03:37:56 +00:00
//TODO Block and Unblock buttons, moderated comments?
2009-11-04 03:07:44 +00:00
class comments_admin_form_ui extends e_admin_form_ui
{
function comment_type ( $curVal , $mode ) // not really necessary since we can use 'dropdown' - but just an example of a custom function.
2009-11-04 23:47:15 +00:00
{
2009-11-05 00:11:56 +00:00
if ( $mode == 'read' )
2009-11-04 03:07:44 +00:00
{
return e107 :: getComment () -> getTable ( $curVal );
2015-08-31 15:28:17 -07:00
// return $curVal.' (custom!)';
2009-11-04 03:07:44 +00:00
}
if ( $mode == 'filter' ) // Custom Filter List for release_type
{
$sql = e107 :: getDb ();
2015-08-31 15:28:17 -07:00
$sql -> gen ( 'SELECT * FROM #comments GROUP BY comment_type' );
while ( $row = $sql -> fetch ())
2009-11-04 03:07:44 +00:00
{
$id = $row [ 'comment_type' ];
$list [ $id ] = e107 :: getComment () -> getTable ( $id );
}
2012-12-08 15:52:40 +01:00
return vartrue ( $list );
2009-11-04 03:07:44 +00:00
}
if ( $mode == 'batch' )
{
$types = e107 :: getComment () -> known_types ;
2009-11-07 11:20:34 +00:00
asort ( $types );
2009-11-04 03:07:44 +00:00
return $types ;
}
}
2012-06-15 12:50:18 +00:00
2013-03-07 22:54:48 -08:00
function comment_blocked ( $curVal , $mode , $parms ) // not really necessary since we can use 'dropdown' - but just an example of a custom function.
2012-06-15 12:50:18 +00:00
{
2013-03-07 22:54:48 -08:00
$frm = e107 :: getForm ();
2012-06-15 12:50:18 +00:00
2015-08-31 15:28:17 -07:00
// $blocked = array("approved", "blocked", "pending");
$blocked = array ( COMLAN_400 , COMLAN_401 , COMLAN_402 );
2013-03-07 22:54:48 -08:00
if ( $mode == 'filter' || $mode == 'batch' || $mode == 'inline' ) // Custom Filter List for release_type
{
return $blocked ;
}
2012-06-15 12:50:18 +00:00
if ( $mode == 'read' )
{
2013-03-07 22:54:48 -08:00
// $blocked = array("","blocked","pending");
2015-08-31 15:28:17 -07:00
$blockedDisp = array (
" <span class='label label-success'> " . COMLAN_400 . " </span> " ,
" <span class='label label-danger'> " . COMLAN_401 . " </span> " ,
" <span class='label label-warning'> " . COMLAN_402 . " </span> "
);
return varset ( $blockedDisp [ $curVal ], '' ); // $blocked[$curVal];
2012-06-15 12:50:18 +00:00
}
2013-03-07 22:54:48 -08:00
if ( $mode == 'write' )
2012-06-15 12:50:18 +00:00
{
2013-04-25 17:29:46 -07:00
return $frm -> select ( " comment_blocked " , $blocked , $curVal );
2012-06-15 12:50:18 +00:00
}
2013-03-07 22:54:48 -08:00
2012-06-15 12:50:18 +00:00
}
2009-11-04 03:07:44 +00:00
}
new comments_admin ();
require_once ( e_ADMIN . " auth.php " );
2009-08-30 08:23:51 +00:00
2009-11-04 03:07:44 +00:00
e107 :: getAdminUI () -> runPage ();
2009-08-30 08:23:51 +00:00
2009-11-04 03:07:44 +00:00
require_once ( e_ADMIN . " footer.php " );
exit ;
2009-08-30 08:23:51 +00:00
2009-11-04 03:07:44 +00:00
/*
2009-05-08 21:50:19 +00:00
if ( e_QUERY )
{
2006-12-02 04:36:16 +00:00
$temp = explode ( " - " , e_QUERY );
$action = $temp [ 0 ];
$id = intval ( $temp [ 1 ]);
$item = $temp [ 2 ];
$c_item = $temp [ 3 ];
2009-05-08 21:50:19 +00:00
if ( $sql -> select ( 'comments' , '*' , 'comment_id=' . $id ))
{
$comment = $sql -> db_Fetch ();
if ( $action == " block " )
{
$sql -> db_Update ( " comments " , " comment_blocked='1' WHERE comment_id= " . $id );
2006-12-02 04:36:16 +00:00
}
2009-05-08 21:50:19 +00:00
if ( $action == " unblock " )
{
$sql -> db_Update ( " comments " , " comment_blocked='0' WHERE comment_id= " . $id );
}
if ( $action == " delete " )
{
$sql -> db_Delete ( " comments " , " comment_id= " . $id );
switch ( $comment [ 'comment_type' ])
{
case '0' :
case 'news' : // Need to update count in news record as well
$sql2 -> db_Update ( 'news' , 'news_comment_total = CAST(GREATEST(CAST(news_comment_total AS SIGNED) - 1, 0) AS UNSIGNED) WHERE news_id=' . $comment [ 'comment_item_id' ]);
break ;
2006-12-02 04:36:16 +00:00
}
}
2009-05-08 21:50:19 +00:00
if ( ! $e107cache -> clear ( $item ))
{
2006-12-02 04:36:16 +00:00
$tmp = explode ( " ? " , $item );
$item = $tmp [ 0 ] . " ?news. " . $c_item ;
$e107cache -> clear ( $item );
2009-05-08 21:50:19 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
2009-08-30 08:23:51 +00:00
else
{
2009-11-04 03:07:44 +00:00
// $cm= new comment_manager;
// $cm->commentList();
2009-08-30 08:23:51 +00:00
}
// echo "<script type='text/javascript'>window.history.go(-1);</script>\n";
2009-11-04 03:07:44 +00:00
*/
2009-08-30 08:23:51 +00:00
2006-12-02 04:36:16 +00:00
?>