add wpforo customization for seminar event.

This commit is contained in:
2020-12-02 18:34:47 +09:00
parent efad602546
commit 656800c92f
5 changed files with 467 additions and 5 deletions

View File

@ -17,7 +17,7 @@ function cbsonline_disable_parent_defines()
// remove buggy biz_vector script
remove_action('wp_head', 'biz_vektor_addJScripts');
// remove pingback css
remove_action('wp_enqueue_scripts','biz_vektor_addPingback');
remove_action('wp_enqueue_scripts', 'biz_vektor_addPingback');
}
// disable emoji
@ -217,13 +217,272 @@ function cbsonline_add_page_to_tag_archive($obj)
// override date_format option
add_filter('option_date_format', 'cbsonline_date_format');
function cbsonline_date_format($format) {
function cbsonline_date_format($format)
{
$lang = get_query_var('lang', '');
switch($lang) {
switch ($lang) {
case 'ja':
return 'Y年n月j日';
return 'Y年n月j日';
case 'en_US':
return 'D, d M Y';
return 'D, d M Y';
}
return $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;
}
function cbsonline_wpforo_get_topic_fields_list()
{
static $ret = [];
if (!empty($ret)) {
return $ret;
}
$fields = WPF()->post->get_topic_fields_list();
foreach ($fields as $name) {
$ret[$name] = WPF()->post->get_field($name);
}
return $ret;
}
function cbsonline_wpforo_get_topic_custom_fields($topic_id)
{
$fields = cbsonline_wpforo_get_topic_fields_list();
$postmetas = WPF()->postmeta->get_postmeta($topic_id, '', true);
$ret = [];
foreach ($fields as $name => $field) {
if ($postmeta = wpfval($postmetas, $name)) {
if (!(int) wpfval($fields[$name], 'isDefault')) {
$field['value'] = $postmeta;
$field = WPF()->form->prepare_values(WPF()->form->esc_field($field));
$ret[$name] = wpfval($field, 'value');
}
}
}
return $ret;
}
function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count = true)
{
$cache = WPF()->cache->on('object_cashe');
$default = [
'include' => [], // array( 2, 10, 25 )
'exclude' => [], // array( 2, 10, 25 )
'forumids' => [],
'forumid' => null,
'userid' => null, // user id in DB
'type' => null, // 0, 1, etc . . .
'solved' => null,
'closed' => null,
'status' => null, // 0, 1, etc . . .
'private' => null, // 0, 1, etc . . .''
'pollid' => null,
'orderby' => 'type, topicid', // type, topicid, modified, created
'order' => 'DESC', // ASC DESC
'offset' => null, // this use when you give row_count
'row_count' => null, // 4 or 1 ...
'permgroup' => null, // Checks permissions based on attribute value not on current user usergroup
'read' => null, // true / false
'where' => null,
'join' => null, // join clause
];
$args = wpforo_parse_args($args, $default);
if (is_array($args) && !empty($args)) {
extract($args, EXTR_OVERWRITE);
if (0 === $row_count) {
return [];
}
$include = wpforo_parse_args($include);
$exclude = wpforo_parse_args($exclude);
$forumids = wpforo_parse_args($forumids);
$guest = [];
$wheres = [];
if (!is_null($read)) {
$last_read_postid = WPF()->log->get_all_read('post');
if ($read) {
if ($last_read_postid) {
$wheres[] = '`last_post` <= '.intval($last_read_postid);
}
$include_read = WPF()->log->get_read();
$include = array_merge($include, $include_read);
} else {
if ($last_read_postid) {
$wheres[] = '`last_post` > '.intval($last_read_postid);
}
$exclude_read = WPF()->log->get_read();
$exclude = array_merge($exclude, $exclude_read);
}
}
if (!empty($include)) {
$wheres[] = '`topicid` IN('.implode(', ', array_map('intval', $include)).')';
}
if (!empty($exclude)) {
$wheres[] = '`topicid` NOT IN('.implode(', ', array_map('intval', $exclude)).')';
}
if (!empty($forumids)) {
$wheres[] = '`forumid` IN('.implode(', ', array_map('intval', $forumids)).')';
}
if (!is_null($forumid)) {
$wheres[] = '`forumid` = '.intval($forumid);
}
if (!is_null($userid)) {
$wheres[] = '`userid` = '.wpforo_bigintval($userid);
}
if (!is_null($solved)) {
$wheres[] = '`solved` = '.intval($solved);
}
if (!is_null($closed)) {
$wheres[] = '`closed` = '.intval($closed);
}
if (!is_null($type)) {
$wheres[] = '`type` = '.intval($type);
}
if (!is_null($where)) {
$wheres[] = $where;
}
if (!is_user_logged_in()) {
$guest = WPF()->member->get_guest_cookies();
}
if (empty($forumids)) {
if (isset($forumid) && !WPF()->perm->forum_can('vf', $forumid, $permgroup)) {
return [];
}
}
if (isset($forumid) && $forumid) {
if (WPF()->perm->forum_can('vp', $forumid, $permgroup)) {
if (!is_null($private)) {
$wheres[] = ' `private` = '.intval($private);
}
} elseif (isset(WPF()->current_userid) && WPF()->current_userid) {
$wheres[] = ' ( `private` = 0 OR (`private` = 1 AND `userid` = '.intval(WPF()->current_userid).') )';
} elseif (wpfval($guest, 'email')) {
$wheres[] = " ( `private` = 0 OR (`private` = 1 AND `email` = '".sanitize_email($guest['email'])."') )";
} else {
$wheres[] = ' `private` = 0';
}
} else {
if (!is_null($private)) {
$wheres[] = ' `private` = '.intval($private);
}
}
if (isset($forumid) && $forumid) {
if (WPF()->perm->forum_can('au', $forumid, $permgroup)) {
if (!is_null($status)) {
$wheres[] = ' `status` = '.intval($status);
}
} elseif (isset(WPF()->current_userid) && WPF()->current_userid) {
$wheres[] = ' ( `status` = 0 OR (`status` = 1 AND `userid` = '.intval(WPF()->current_userid).') )';
} elseif (wpfval($guest, 'email')) {
$wheres[] = " ( `status` = 0 OR (`status` = 1 AND `email` = '".sanitize_email($guest['email'])."') )";
} else {
$wheres[] = ' `status` = 0';
}
} else {
if (!is_null($status)) {
$wheres[] = ' `status` = '.intval($status);
}
}
if (function_exists('WPF_POLL')) {
if (!is_null($pollid)) {
$wheres[] = ' `pollid` <> 0';
}
}
$sql = 'SELECT `'.WPF()->tables->topics.'`.* FROM `'.WPF()->tables->topics.'`';
if (!is_null($join)) {
$sql .= $join;
}
if (!empty($wheres)) {
$sql .= ' WHERE '.implode(' AND ', $wheres);
}
if ($count) {
$item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
if ($item_count_sql) {
$items_count = WPF()->db->get_var($item_count_sql);
}
}
$sql .= ' ORDER BY '.str_replace(',', ' '.esc_sql($order).',', esc_sql($orderby)).' '.esc_sql($order);
if (!is_null($row_count)) {
if (!is_null($offset)) {
$sql .= esc_sql(" LIMIT $offset,$row_count");
} else {
$sql .= esc_sql(" LIMIT $row_count");
}
}
if (!is_null($join)) {
$keys = ['topics', 'forumid', 'first_postid', 'userid', 'title', 'slug', 'created', 'modified', 'last_post', 'posts', 'votes', 'answers', 'views', 'meta_key', 'meta_desc', 'type', 'solved', 'closed', 'has_attach', 'private', 'status', 'name', 'email', 'prefix', 'tags'];
foreach ($keys as $key) {
$sql = str_replace(' `'.$key.'`', ' `'.WPF()->tables->topics.'`.`'.$key.'`', $sql);
}
}
if ($cache) {
$object_key = md5($sql.WPF()->current_user_groupid);
$object_cache = WPF()->cache->get($object_key);
if (!empty($object_cache)) {
if (!empty($object_cache['items'])) {
$access_filter = apply_filters('wpforo_topic_access_filter_cache', true);
if ($access_filter) {
return WPF()->topic->access_filter($object_cache['items'], $permgroup);
} else {
return $object_cache['items'];
}
}
}
}
$topics = WPF()->db->get_results($sql, ARRAY_A);
$topics = apply_filters('wpforo_get_topics', $topics);
if ($cache && isset($object_key) && !empty($topics)) {
wpForoTopic::$cache['topics'][$object_key]['items'] = $topics;
wpForoTopic::$cache['topics'][$object_key]['items_count'] = $items_count;
}
if (!empty($forumids) || !$forumid) {
$topics = WPF()->topic->access_filter($topics, $permgroup);
}
return $topics;
}
}