| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* wpForo Classic Theme Functions |
| 7 |
* @hook: action - 'init' |
| 8 |
* @description: only for wpForo theme functions. For WordPress theme functions use functions-wp.php file. |
| 9 |
* @theme: Classic |
| 10 |
*/ |
| 11 |
|
| 12 |
include_once( wpftpl( 'layouts/4/forum-thread.php' ) ); |
| 13 |
include_once( wpftpl( 'layouts/4/topic-thread.php' ) ); |
| 14 |
include_once( wpftpl( 'layouts/4/post-thread.php' ) ); |
| 15 |
|
| 16 |
function wpforo_thread_reply( $post, $topic = [], $forum = [], $level = 0, $parents = [] ) { |
| 17 |
if( wpfval( $post, 'postid' ) ) { |
| 18 |
$post = wpforo_post( $post['postid'] ); |
| 19 |
wpforo_thread_reply_template( $post, $topic, $forum, $level, $parents ); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
function wpforo_classic_reply_form_head( $string, $args ) { |
| 24 |
if( $args['layout'] === 3 && WPF()->tpl->layout_exists( 3 ) ) { |
| 25 |
$string = wpforo_phrase( 'Your Answer', false, 'default' ); |
| 26 |
} |
| 27 |
|
| 28 |
return $string; |
| 29 |
} |
| 30 |
|
| 31 |
add_filter( 'wpforo_reply_form_head', 'wpforo_classic_reply_form_head', 1, 2 ); |
| 32 |
|
| 33 |
function wpforo_forum_layout_editors( $settings, $editor ) { |
| 34 |
if( $editor === 'post' && 4 === wpfval( WPF()->current_object, 'layout' ) ) { |
| 35 |
$settings['tinymce']['toolbar1'] = 'fontsizeselect,bold,italic,underline,forecolor,bullist,numlist,alignleft,aligncenter,alignright,link,unlink,blockquote,pre,wpf_spoil,pastetext,source_code,emoticons'; |
| 36 |
$settings['editor_height'] = 100; |
| 37 |
} |
| 38 |
|
| 39 |
return $settings; |
| 40 |
} |
| 41 |
|
| 42 |
add_filter( 'wpforo_editor_settings', 'wpforo_forum_layout_editors', 1, 2 ); |
| 43 |
|
| 44 |
function wpforo_get_topic_overview_chunk( $topicid, $row_count = 5, $offset = 0 ) { |
| 45 |
$roots = WPF()->post->get_posts( [ 'topicid' => $topicid, 'is_first_post' => 0, 'parentid' => 0, 'offset' => $offset, 'row_count' => $row_count ], $roots_count ); |
| 46 |
$tree = []; |
| 47 |
foreach( $roots as $root ) { |
| 48 |
$tree[ wpforo_bigintval( $root['postid'] ) ] = wpforo_bigintval( $root['parentid'] ); |
| 49 |
$posts = WPF()->post->get_posts( [ 'root' => $root['postid'] ] ); |
| 50 |
foreach( $posts as $post ) $tree[ wpforo_bigintval( $post['postid'] ) ] = wpforo_bigintval( $post['parentid'] ); |
| 51 |
} |
| 52 |
|
| 53 |
return [ 'html' => ( $tree ? wpforo_thread_tree( 0, $tree ) : '' ), 'roots_count' => intval( $roots_count ), 'nomore' => ! ( $roots_count > ( $offset + $row_count ) ) ]; |
| 54 |
} |
| 55 |
|
| 56 |
function wpforo_topic_head_top( $forum, $topic ) { |
| 57 |
?> |
| 58 |
<div class="wpf-post-info"> |
| 59 |
<span class="wpf-post-info-forum"><i style="color: <?php echo $forum['color'] ?>;" class="<?php echo $forum['icon'] ?>"></i> <?php echo $forum['title'] ?></span> |
| 60 |
<div> |
| 61 |
<a href="<?php echo esc_url( (string) wpforo_post( $topic['last_post'], 'url' ) ); ?>"> |
| 62 |
<svg style="height: 14px; margin-right: 5px; vertical-align: text-top;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> |
| 63 |
<path d="M18.656.93,6.464,13.122A4.966,4.966,0,0,0,5,16.657V18a1,1,0,0,0,1,1H7.343a4.966,4.966,0,0,0,3.535-1.464L23.07,5.344a3.125,3.125,0,0,0,0-4.414A3.194,3.194,0,0,0,18.656.93Zm3,3L9.464,16.122A3.02,3.02,0,0,1,7.343,17H7v-.343a3.02,3.02,0,0,1,.878-2.121L20.07,2.344a1.148,1.148,0,0,1,1.586,0A1.123,1.123,0,0,1,21.656,3.93Z"/> |
| 64 |
<path d="M23,8.979a1,1,0,0,0-1,1V15H18a3,3,0,0,0-3,3v4H5a3,3,0,0,1-3-3V5A3,3,0,0,1,5,2h9.042a1,1,0,0,0,0-2H5A5.006,5.006,0,0,0,0,5V19a5.006,5.006,0,0,0,5,5H16.343a4.968,4.968,0,0,0,3.536-1.464l2.656-2.658A4.968,4.968,0,0,0,24,16.343V9.979A1,1,0,0,0,23,8.979ZM18.465,21.122a2.975,2.975,0,0,1-1.465.8V18a1,1,0,0,1,1-1h3.925a3.016,3.016,0,0,1-.8,1.464Z"/> |
| 65 |
</svg> |
| 66 |
<span class=""><?php wpforo_phrase( 'Last Post' ); ?></span> |
| 67 |
</a> |
| 68 |
<span><?php wpforo_phrase( 'by', true, 'lower' ) ?></span> <?php wpforo_member_link( wpforo_member( wpforo_post( $topic['last_post'], 'userid' ) ) ) ?> <span |
| 69 |
class="wpforo-date wpforo-date-ago"><?php wpforo_date( wpforo_post( $topic['last_post'], 'created' ) ) ?></span> |
| 70 |
<?php do_action( 'wpforo_topic_head_left', $forum, $topic ) ?> |
| 71 |
</div> |
| 72 |
</div> |
| 73 |
<div class="wpf-post-stat"> |
| 74 |
<div class="wpf-post-stat-box"> |
| 75 |
<span class="wpf-tstat"> |
| 76 |
<svg style="height: 16px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g id="_01_align_center" data-name="01 align center"><path |
| 77 |
d="M24,24H12.018A12,12,0,1,1,24,11.246l0,.063ZM12.018,2a10,10,0,1,0,0,20H22V11.341A10.018,10.018,0,0,0,12.018,2Z"/><rect x="7" y="7" width="6" height="2"/><rect |
| 78 |
x="7" y="11" width="10" height="2"/><rect x="7" y="15" width="10" height="2"/></g></svg> |
| 79 |
<?php echo wpforo_print_number( $topic['posts'] ) ?> |
| 80 |
</span> |
| 81 |
<span class="wpf-tlabel"><?php wpforo_phrase( 'posts' ) ?></span> |
| 82 |
</div> |
| 83 |
<div class="wpf-post-stat-box"> |
| 84 |
<span class="wpf-tstat"> |
| 85 |
<svg style="height: 17px;" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" data-name="Layer 1"><path |
| 86 |
d="m7.5 13a4.5 4.5 0 1 1 4.5-4.5 4.505 4.505 0 0 1 -4.5 4.5zm0-7a2.5 2.5 0 1 0 2.5 2.5 2.5 2.5 0 0 0 -2.5-2.5zm7.5 14a5.006 5.006 0 0 0 -5-5h-5a5.006 5.006 0 0 0 -5 5v4h2v-4a3 3 0 0 1 3-3h5a3 3 0 0 1 3 3v4h2zm2.5-11a4.5 4.5 0 1 1 4.5-4.5 4.505 4.505 0 0 1 -4.5 4.5zm0-7a2.5 2.5 0 1 0 2.5 2.5 2.5 2.5 0 0 0 -2.5-2.5zm6.5 14a5.006 5.006 0 0 0 -5-5h-4v2h4a3 3 0 0 1 3 3v4h2z"/></svg> |
| 87 |
<?php echo wpforo_get_users_count_for_topic( $topic['topicid'] ) ?> |
| 88 |
</span> |
| 89 |
<span class="wpf-tlabel"><?php wpforo_phrase( 'users', 'lower' ) ?></span> |
| 90 |
</div> |
| 91 |
<div class="wpf-post-stat-box"> |
| 92 |
<span class="wpf-tstat"> |
| 93 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g id="_01_align_center" data-name="01 align center"><path |
| 94 |
d="M15.021,7l.336-2.041a3.044,3.044,0,0,0-4.208-3.287A3.139,3.139,0,0,0,9.582,3.225L7.717,7H3a3,3,0,0,0-3,3v9a3,3,0,0,0,3,3H22.018L24,10.963,24.016,7ZM2,19V10A1,1,0,0,1,3,9H7V20H3A1,1,0,0,1,2,19Zm20-8.3L20.33,20H9V8.909l2.419-4.9A1.07,1.07,0,0,1,13.141,3.8a1.024,1.024,0,0,1,.233.84L12.655,9H22Z"/></g></svg> |
| 95 |
<?php echo wpforo_get_likes_for_topic( $topic['topicid'] ) ?> |
| 96 |
</span> |
| 97 |
<span class="wpf-tlabel"><?php wpforo_phrase( 'Reactions', 'lower' ) ?></span> |
| 98 |
</div> |
| 99 |
<div class="wpf-post-stat-box"> |
| 100 |
<span class="wpf-tstat"> |
| 101 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g id="_01_align_center" data-name="01 align center"><path |
| 102 |
d="M23.821,11.181v0C22.943,9.261,19.5,3,12,3S1.057,9.261.179,11.181a1.969,1.969,0,0,0,0,1.64C1.057,14.739,4.5,21,12,21s10.943-6.261,11.821-8.181A1.968,1.968,0,0,0,23.821,11.181ZM12,19c-6.307,0-9.25-5.366-10-6.989C2.75,10.366,5.693,5,12,5c6.292,0,9.236,5.343,10,7C21.236,13.657,18.292,19,12,19Z"/><path |
| 103 |
d="M12,7a5,5,0,1,0,5,5A5.006,5.006,0,0,0,12,7Zm0,8a3,3,0,1,1,3-3A3,3,0,0,1,12,15Z"/></g></svg> |
| 104 |
<?php echo wpforo_print_number( $topic['views'] ) ?> |
| 105 |
</span> |
| 106 |
<span class="wpf-tlabel"><?php wpforo_phrase( 'views' ) ?></span> |
| 107 |
</div> |
| 108 |
<div class="wpf-post-stat-box wpf-pb-more" wpf-tooltip="<?php wpforo_phrase( 'Topic overview and more...' ) ?>" wpf-tooltip-size="middle"> |
| 109 |
<i class="fas fa-chevron-down" style="font-size: 18px;"></i> |
| 110 |
<span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="30" height="30"><circle cx="21.517" cy="12.066" r="2.5"/><circle cx="12" cy="12" r="2.5"/><circle |
| 111 |
cx="2.5" cy="12" |
| 112 |
r="2.5"/></svg></span> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
<?php |
| 116 |
} |
| 117 |
|
| 118 |
function wpforo_topic_active_participants( $topicid ) { |
| 119 |
if( ! $users_stats_for_topic = WPF()->post->get_users_stats_for_topic( $topicid, 40 ) ) return ''; |
| 120 |
$html = ''; |
| 121 |
foreach( $users_stats_for_topic as $users_stats ) { |
| 122 |
$user = wpforo_member( $users_stats['userid'] ); |
| 123 |
if( $user && WPF()->usergroup->can( 'va' ) && wpforo_setting( 'profiles', 'avatars' ) ) { |
| 124 |
$html .= sprintf( |
| 125 |
'<div class="wpf-tmi-user-avatar">%1$s<div class="wpf-tmi-user-posts">%2$d</div></div>', |
| 126 |
wpforo_member_link( $user, '', 96, '', false, 'avatar' ), |
| 127 |
$users_stats['posts'] |
| 128 |
); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
return sprintf( |
| 133 |
'<div class="wpf-tmi wpf-tmi-users"><h3>%1$s</h3><div class="wpf-tmi-users-data">%2$s</div></div>', |
| 134 |
wpforo_phrase( 'Active Participants', false ), |
| 135 |
$html |
| 136 |
); |
| 137 |
} |
| 138 |
|
| 139 |
function wpforo_topic_overview( $topicid ) { |
| 140 |
if( ! ( $first_postid = wpforo_bigintval( wpforo_topic( $topicid, 'first_postid' ) ) ) ) return ''; |
| 141 |
$chunk_size = apply_filters( 'wpforo_topic_overview_chunk_size', 5 ); |
| 142 |
$chunk = wpforo_get_topic_overview_chunk( $topicid, $chunk_size ); |
| 143 |
|
| 144 |
return sprintf( |
| 145 |
'<div class="wpf-tmi wpf-tmi-overview"> |
| 146 |
<h3>%1$s</h3> |
| 147 |
<ul class="wpf-topic-overview-tree" data-offset="0" data-chunksize="%2$s" data-nomore="%3$d">%4$s %5$s</ul> |
| 148 |
<div class="wpf-topic-overview-load-more wpf-action">%6$s</div> |
| 149 |
</div>', |
| 150 |
wpforo_phrase( 'Topic Overview', false ), |
| 151 |
$chunk_size, |
| 152 |
intval( $chunk['nomore'] ), |
| 153 |
wpforo_thread_tree_item( $first_postid, 0 ), |
| 154 |
$chunk['html'], |
| 155 |
wpforo_phrase( 'Load more replies...', false ) |
| 156 |
); |
| 157 |
} |
| 158 |
|
| 159 |
function wpforo_topic_head( $forum, $topic ) { |
| 160 |
?> |
| 161 |
<div class="wpforo-topic-head-wrap" |
| 162 |
data-forumid="<?php echo intval( $forum['forumid'] ) ?>" |
| 163 |
data-topicid="<?php echo wpforo_bigintval( $topic['topicid'] ) ?>" |
| 164 |
data-userid="<?php echo wpforo_bigintval( $topic['userid'] ) ?>" |
| 165 |
data-isowner="<?php echo intval( ( wpforo_bigintval( $topic['userid'] ) === WPF()->current_userid ) ) ?>" |
| 166 |
> |
| 167 |
<?php if( wpforo_setting( 'topics', 'topic_head' ) ): ?> |
| 168 |
<div class="wpf-post-head-top"><?php wpforo_topic_head_top( $forum, $topic ); ?></div> |
| 169 |
<div class="wpf-topic-more-info" <?php echo( wpforo_setting( 'topics', 'topic_head_expanded' ) ? 'style="display: block;"' : 'style="display: none;"' ) ?>></div> |
| 170 |
<?php endif; ?> |
| 171 |
<div class="wpf-post-head-bottom"> |
| 172 |
<div class="wpf-left"> |
| 173 |
<div class="wpf-manage-link"> |
| 174 |
<?php wpforo_post_buttons( 'icon-text', [ 'solved', 'sticky', 'close', 'private', 'delete' ], $forum, $topic, wpforo_post( $topic['first_postid'] ) ); ?> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
<div class="wpf-right"> |
| 178 |
<?php do_action( 'wpforo_topic_head_right', $forum, $topic ) ?> |
| 179 |
<?php wpforo_post_buttons( 'icon-text', [ 'tools' ], $forum ); ?> |
| 180 |
<?php wpforo_feed_link(); ?> |
| 181 |
</div> |
| 182 |
</div> |
| 183 |
</div> |
| 184 |
<?php |
| 185 |
} |
| 186 |
|
| 187 |
function wpforo_thread_tree( $root, $tree, $level = 1 ) { |
| 188 |
$html = ''; |
| 189 |
if( ! is_null( $tree ) && count( $tree ) > 0 ) { |
| 190 |
$html .= '<ul>'; |
| 191 |
foreach( $tree as $child => $parent ) { |
| 192 |
if( $parent === $root ) { |
| 193 |
unset( $tree[ $child ] ); |
| 194 |
$html .= wpforo_thread_tree_item( $child, $level ); |
| 195 |
$html .= wpforo_thread_tree( $child, $tree, $level + 1 ); |
| 196 |
$html .= '</li>'; |
| 197 |
} |
| 198 |
} |
| 199 |
$html .= '</ul>'; |
| 200 |
} |
| 201 |
|
| 202 |
return $html; |
| 203 |
} |
| 204 |
|
| 205 |
function wpforo_thread_tree_item( $postid, $level, $post = [], $member = [] ) { |
| 206 |
$level = intval( $level ); |
| 207 |
if( $level < 0 ) $level = 0; |
| 208 |
$repeate = $level - 1; |
| 209 |
if( $repeate < 0 ) $repeate = 0; |
| 210 |
if( empty( $post ) ) if( ! $post = wpforo_post( $postid ) ) return ''; |
| 211 |
if( empty( $member ) ) $member = wpforo_member( $post ); |
| 212 |
|
| 213 |
return '<li><div class="wpf-tmi-item">' . ( $level > 0 ? '<span class="wpf-tmi-boxh"> └ ─</span>' : '' ) . str_repeat( |
| 214 |
'<span class="wpf-tmi-boxh"> ┴ ─</span>', |
| 215 |
$repeate |
| 216 |
) . wpforo_user_avatar( $member, 20 ) . ' ' . wpforo_member_link( $member, '', 7, 'wpfto-author', false ) . ' <span class="wpfto-date">' . wpforo_date( |
| 217 |
$post['created'], |
| 218 |
'ago-date', |
| 219 |
false |
| 220 |
) . ' • </span>' . '<span class="wpf-link wpf-tmi-item-body-excerpt" data-postid="' . $postid . '">' . wpforo_text( $post['body'], 70, false ) . '</span>' . '</div>'; |
| 221 |
} |
| 222 |
|
| 223 |
function wpforo_l2_print_avatars( $userids ) { |
| 224 |
$ulimit = (int) apply_filters( 'wpforo_item_participant_avatars_count', 3 ); |
| 225 |
if( ! $ulimit ) $ulimit = 7; |
| 226 |
if( $ucount = count( $userids ) ) { |
| 227 |
foreach( $userids as $k => $userid ) { |
| 228 |
if( ! ( $k < $ulimit ) ) break; |
| 229 |
$user = wpforo_member( $userid ); |
| 230 |
if( wpforo_setting( 'profiles', 'avatars' ) && WPF()->usergroup->can( 'va' ) ) { |
| 231 |
echo wpforo_user_avatar( $user, 40 ); |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
if( ! $ucount || $ucount > $ulimit ) { |
| 236 |
printf( |
| 237 |
'<div class="wpf-sbd-count">%1$s</div>', |
| 238 |
( $ucount ? "+" . ( $ucount - $ulimit ) : wpforo_phrase( 'No Participants', false ) ) |
| 239 |
); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
function wpforo_l2_forum_users( $forumid ) { |
| 244 |
wpforo_l2_print_avatars( WPF()->post->get_userids_for_forum( $forumid ) ); |
| 245 |
} |
| 246 |
|
| 247 |
function wpforo_l2_topic_users( $topicid ) { |
| 248 |
wpforo_l2_print_avatars( WPF()->post->get_userids_for_topic( $topicid ) ); |
| 249 |
} |
| 250 |
|