yf_manage_comments admin moduleComments management module.
| File | plugins/comments/admin_modules/yf_manage_comments.class.php |
|---|---|
| Use | admin URL ?object=manage_comments |
A site sets them in its config with $PROJECT_CONF['manage_comments']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$TEXT_PREVIEW_LENGTH |
0 |
|
$_comments_actions |
|
public function active()
public function active()
{
$_GET['id'] = (int) (($_GET['id'] ?? null));
if ( ! empty($_GET['id'])) {
$a = db()->query_fetch('SELECT * FROM ' . db('comments') . ' WHERE id=' . (int) (($_GET['id'] ?? null)));
}
if ( ! empty($a)) {
db()->update('comments', ['active' => (int) ! $a['active']], 'id=' . (int) (($_GET['id'] ?? null)));
}
if (is_ajax()) {
main()->NO_GRAPHICS = true;
echo $a['active'] ? 0 : 1;
} else {
return js_redirect('./?object=' . ($_GET['object'] ?? null));
}
}
public function delete()
public function delete()
{
$_GET['id'] = (int) (($_GET['id'] ?? null));
if ( ! empty($_GET['id'])) {
db()->query('DELETE FROM ' . db('comments') . ' WHERE id=' . (int) (($_GET['id'] ?? null)) . ' LIMIT 1');
}
if (is_ajax()) {
main()->NO_GRAPHICS = true;
echo $_GET['id'] ?? null;
} else {
return js_redirect('./?object=' . ($_GET['object'] ?? null));
}
}
public function edit()
public function edit()
{
$_GET['id'] = (int) (($_GET['id'] ?? null));
$a = db()->query_fetch('SELECT * FROM ' . db('comments') . ' WHERE id=' . (int) (($_GET['id'] ?? null)));
if (empty($a)) {
return _e('No such record');
}
if (main()->is_post()) {
if (empty($_POST['text'])) {
_re('Comment text required');
}
if ( ! common()->_error_exists()) {
db()->update_safe('comments', ['text' => ($_POST['text'] ?? null)], 'id=' . (int) ($a['id']));
return js_redirect('');
}
}
return form($a + [
'back_link' => './?object=' . ($_GET['object'] ?? null),
])
->info_date('add_date', 'full')
->info('object_name')
->info('object_id')
->user_info('user_id')
->textarea('text')
->save_and_back();
}
public function filter_save()
public function filter_save()
{
return _class('admin_methods')->filter_save();
}
public function redirect_view()
public function redirect_view()
{
$_GET['id'] = (int) (($_GET['id'] ?? null));
$a = db()->get('SELECT * FROM ' . db('comments') . ' WHERE id=' . (int) (($_GET['id'] ?? null)));
if (empty($a) || ! $a['object_name'] || ! $a['object_id']) {
return js_redirect('./?object=' . ($_GET['object'] ?? null));
}
return js_redirect('./?object=' . $a['object_name'] . '&action=' . (($this->_comments_actions[$a['object_name']] ?? null) ?: 'edit') . '&id=' . $a['object_id']);
}
public function show()
public function show()
{
$filter_name = ($_GET['object'] ?? null) . '__' . ($_GET['action'] ?? null);
$default_filter = [
'order_by' => 'add_date',
'order_direction' => 'desc',
];
$sql = 'SELECT * FROM ' . db('comments');
return table($sql, [
'filter' => (array) ($_SESSION[$filter_name] ?? null) + $default_filter,
'filter_params' => [
'text' => 'like',
],
])
// ->check_box('id')
->date('add_date', ['format' => 'full', 'nowrap' => 1])
->text('object_name', ['link' => './?object=' . ($_GET['object'] ?? null) . '&action=redirect_view&id=%d', 'link_field_name' => 'id'])
->text('object_id', 'oid')
->text('text', ['max_length' => $this->TEXT_PREVIEW_LENGTH])
->user('user_id')
->text('ip', ['link' => './?object=' . ($_GET['object'] ?? null) . '&action=filter_save&page=clear&filter=ip:%d'])
->btn_active()
->btn_edit()
->btn_delete();
}
_ hooks and helpers; not routable as page actionspublic function _show_filter()
public function _show_filter()
{
if ( ! in_array(($_GET['action'] ?? null), ['show'])) {
return false;
}
$filter_name = ($_GET['object'] ?? null) . '__' . ($_GET['action'] ?? null);
$r = [
'form_action' => './?object=' . ($_GET['object'] ?? null) . '&action=filter_save&id=' . $filter_name,
'clear_url' => './?object=' . ($_GET['object'] ?? null) . '&action=filter_save&id=' . $filter_name . '&page=clear',
];
$order_fields = [];
foreach (explode('|', 'user_id|add_date|ip|object_name|object_id|user_name|user_email|active') as $f) {
$order_fields[$f] = $f;
}
$object_names = null;
foreach ((array) $this->_comments_actions as $k => $v) {
$object_names[$k] = $k;
}
return form($r, [
'selected' => ($_SESSION[$filter_name] ?? null),
])
->number('user_id')
->text('ip')
->select_box('object_name', $object_names, ['show_text' => 1])
->number('object_id')
->text('text')
->active_box()
->select_box('order_by', $order_fields, ['show_text' => 1])
->radio_box('order_direction', ['asc' => 'Ascending', 'desc' => 'Descending'])
->save_and_clear();
}