set hostname when annonymous user add topic data.
This commit is contained in:
parent
50334dac6e
commit
1553ff91e5
@ -231,31 +231,7 @@ function cbsonline_date_format($format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for wpforo
|
// for wpforo
|
||||||
add_filter('wpforo_after_init_current_object', 'cbsonline_wpforo_after_init_current_object', 10, 2);
|
// - helper funcitons for template customization - used by wpforo/layouts/2/*.php
|
||||||
function cbsonline_wpforo_after_init_current_object($current_object, $wpf_url_parse)
|
|
||||||
{
|
|
||||||
if (wpfval($current_object, 'forum_slug')) {
|
|
||||||
$topic = wpfval($current_object, 'topic_slug') ? WPF()->topic->get_topic(['slug' => $current_object['topic_slug']], false) : false;
|
|
||||||
$args = (empty($topic) ? ['slug' => $current_object['forum_slug']] : $topic['forumid']);
|
|
||||||
if ($forum = WPF()->forum->get_forum($args)) {
|
|
||||||
if ('topic' === $current_object['template']) {
|
|
||||||
$args = [
|
|
||||||
'offset' => ($current_object['paged'] - 1) * $current_object['items_per_page'],
|
|
||||||
'row_count' => $current_object['items_per_page'],
|
|
||||||
'forumid' => $current_object['forumid'],
|
|
||||||
'orderby' => 'type, metavalue, modified',
|
|
||||||
'order' => 'DESC',
|
|
||||||
'join' => ' INNER JOIN `'.WPF()->tables->postmeta.'` AS `m1` ON `m1`.`postid`=`'.WPF()->tables->topics.'`.`first_postid` AND `m1`.`metakey`=\'seminar_date\'',
|
|
||||||
];
|
|
||||||
$current_object['topics'] = cbsonline_wpforo_topic_get_topics($args, $current_object['items_count']);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$current_object['is_404'] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $current_object;
|
|
||||||
}
|
|
||||||
function cbsonline_wpforo_get_topic_fields_list()
|
function cbsonline_wpforo_get_topic_fields_list()
|
||||||
{
|
{
|
||||||
static $ret = [];
|
static $ret = [];
|
||||||
@ -286,6 +262,32 @@ function cbsonline_wpforo_get_topic_custom_fields($topic_id)
|
|||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
// - sort topics by seminar date
|
||||||
|
add_filter('wpforo_after_init_current_object', 'cbsonline_wpforo_after_init_current_object', 10, 2);
|
||||||
|
function cbsonline_wpforo_after_init_current_object($current_object, $wpf_url_parse)
|
||||||
|
{
|
||||||
|
if (wpfval($current_object, 'forum_slug')) {
|
||||||
|
$topic = wpfval($current_object, 'topic_slug') ? WPF()->topic->get_topic(['slug' => $current_object['topic_slug']], false) : false;
|
||||||
|
$args = (empty($topic) ? ['slug' => $current_object['forum_slug']] : $topic['forumid']);
|
||||||
|
if ($forum = WPF()->forum->get_forum($args)) {
|
||||||
|
if ('topic' === $current_object['template']) {
|
||||||
|
$args = [
|
||||||
|
'offset' => ($current_object['paged'] - 1) * $current_object['items_per_page'],
|
||||||
|
'row_count' => $current_object['items_per_page'],
|
||||||
|
'forumid' => $current_object['forumid'],
|
||||||
|
'orderby' => 'type, metavalue, modified',
|
||||||
|
'order' => 'DESC',
|
||||||
|
'join' => ' INNER JOIN `'.WPF()->tables->postmeta.'` AS `m1` ON `m1`.`postid`=`'.WPF()->tables->topics.'`.`first_postid` AND `m1`.`metakey`=\'seminar_date\'',
|
||||||
|
];
|
||||||
|
$current_object['topics'] = cbsonline_wpforo_topic_get_topics($args, $current_object['items_count']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$current_object['is_404'] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $current_object;
|
||||||
|
}
|
||||||
function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count = true)
|
function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count = true)
|
||||||
{
|
{
|
||||||
$cache = WPF()->cache->on('object_cashe');
|
$cache = WPF()->cache->on('object_cashe');
|
||||||
@ -309,7 +311,7 @@ function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count
|
|||||||
'permgroup' => null, // Checks permissions based on attribute value not on current user usergroup
|
'permgroup' => null, // Checks permissions based on attribute value not on current user usergroup
|
||||||
'read' => null, // true / false
|
'read' => null, // true / false
|
||||||
'where' => null,
|
'where' => null,
|
||||||
'join' => null, // join clause
|
'join' => null, // join clause
|
||||||
];
|
];
|
||||||
|
|
||||||
$args = wpforo_parse_args($args, $default);
|
$args = wpforo_parse_args($args, $default);
|
||||||
@ -486,3 +488,16 @@ function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count
|
|||||||
return $topics;
|
return $topics;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// - set hostname if annoymous user add topic data
|
||||||
|
add_filter('wpforo_add_topic_data_filter', 'cbsonline_wpforo_add_topic_data_filter');
|
||||||
|
function cbsonline_wpforo_add_topic_data_filter($args)
|
||||||
|
{
|
||||||
|
if ($args['name'] == wpforo_phrase('Anonymous', false)) {
|
||||||
|
$host = gethostbyaddr($_SERVER['REMOTE_ADDR'] ?? '127.0.0.1');
|
||||||
|
if (false !== $host) {
|
||||||
|
$args['name'] = $host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user