diff --git a/functions.php b/functions.php index 888c8f8..16834d7 100644 --- a/functions.php +++ b/functions.php @@ -231,31 +231,7 @@ function cbsonline_date_format($format) } // for wpforo -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; -} +// - helper funcitons for template customization - used by wpforo/layouts/2/*.php function cbsonline_wpforo_get_topic_fields_list() { static $ret = []; @@ -286,6 +262,32 @@ function cbsonline_wpforo_get_topic_custom_fields($topic_id) 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) { $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 'read' => null, // true / false 'where' => null, - 'join' => null, // join clause + 'join' => null, // join clause ]; $args = wpforo_parse_args($args, $default); @@ -486,3 +488,16 @@ function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count 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; +}