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 " ))
{
2006-12-02 04:36:16 +00:00
header ( " location: " . e_BASE . " index.php " );
exit ;
}
2009-08-30 08:23:51 +00:00
2009-11-23 04:03:40 +00:00
include_lan ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_prefs.php' );
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' ;
2009-11-04 03:07:44 +00:00
protected $table = " comments " ;
2009-11-05 17:32:19 +00:00
/**
* If present this array will be used to build your list query
* You can link fileds from $field array with 'table' parameter , which should equal to a key ( table ) from this array
* 'leftField' , 'rightField' and 'fields' attributes here are required , the rest is optional
*
* @ var array [ optional ]
*/
2012-08-04 19:07:00 +00:00
// protected $tableJoin = array (
// 'u.user' => array('leftField' => 'comment_author_id', 'rightField' => 'user_id', 'fields' => '*'/*, 'leftTable' => '', 'joinType' => 'LEFT JOIN', 'whereJoin' => 'AND u.user_ban=0', 'where' => ''*/)
// );
2009-11-05 17:32:19 +00:00
//protected $listQry = "SELECT SQL_CALC_FOUND_ROWS * FROM #comments"; // without any Order or Limit.
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 " ;
2009-11-05 17:32:19 +00:00
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' ),
2009-11-11 20:57:34 +00:00
'comment_id' => array ( 'title' => LAN_ID , 'type' => 'number' , 'width' => '5%' , 'forced' => TRUE ),
2013-08-31 16:42:23 +03:00
'comment_blocked' => array ( 'title' => LAN_STATUS , 'type' => 'method' , 'inline' => true , /*'writeParms' => array("approved","blocked","pending"), */ 'data' => 'int' , 'thclass' => 'center' , 'class' => '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
'comment_item_id' => array ( 'title' => " item id " , 'type' => 'number' , 'width' => '5%' ),
2009-11-07 11:20:34 +00:00
'comment_subject' => array ( 'title' => " subject " , 'type' => 'text' , 'width' => 'auto' , 'thclass' => 'left first' ), // 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 (
2013-07-15 12:28:19 +02:00
'comments_disabled' => array ( 'title' => PRFLAN_161 , 'type' => 'boolean' ), // TODO reverse this setting somehow? ie. 'Allow comments' instead of 'Disable comments' (Moc)
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
);
2009-11-23 04:03:40 +00:00
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 );
return $curVal . ' (custom!)' ;
}
if ( $mode == 'filter' ) // Custom Filter List for release_type
{
$sql = e107 :: getDb ();
$sql -> db_Select_gen ( 'SELECT * FROM #comments GROUP BY comment_type' );
while ( $row = $sql -> db_Fetch ())
{
$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
2013-08-31 16:42:23 +03:00
$blocked = array ( " approved " , " blocked " , " pending " );
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");
return varset ( $blocked [ $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
?>