PluginProbe
wpForo Forum / 1.1.0
wpForo Forum v1.1.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / class-template.php

class-template.php in wpForo Forum 1.1.0, at wpf-includes/class-template.php

1,115 lines 50.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 class wpForoTemplate{
7
8 private $wpforo;
9
10 function __construct( $wpForo ){
11 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
12 if( is_wpforo_page() ){
13 add_filter("mce_external_plugins", array(&$this, 'add_tinymce_buttons'), 15);
14 add_filter("tiny_mce_plugins", array(&$this, 'filter_tinymce_plugins'), 15);
15 add_filter("wp_mce_translation", array(&$this, 'add_tinymce_translations'));
16 }
17 }
18
19 function add_tinymce_buttons($plugin_array) {
20 $plugin_array = array();
21 $plugin_array['wpforo_pre_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-pre.js';
22 $plugin_array['wpforo_link_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-link.js';
23 $plugin_array['wpforo_source_code_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-code.js';
24 return $plugin_array;
25 }
26
27 function filter_tinymce_plugins($plugins){
28 return array('hr','lists','textcolor');
29 }
30
31 function add_tinymce_translations($mce_translation){
32 $mce_translation['Insert link'] = __( 'Insert link' );
33 $mce_translation['Link Text'] = __( 'Link Text' );
34 $mce_translation['Open link in a new tab'] = __( 'Open link in a new tab' );
35 return $mce_translation;
36 }
37
38 function topic_form($forumid){
39 if(!isset($this->wpforo->post_options['max_upload_size']) || !$this->wpforo->post_options['max_upload_size']){ $server_mus = wpforo_human_size_to_bytes(ini_get('upload_max_filesize')); if( !$server_mus || $server_mus > 10485760 ) $server_mus = 10485760; $this->wpforo->post_options['max_upload_size'] = $server_mus;}
40 ?>
41 <div id="wpf-topic-create" class="wpf-topic-create">
42 <form name="topic" action="" enctype="multipart/form-data" method="POST">
43 <?php wp_nonce_field( 'wpforo_verify_form', 'wpforo_form' ); ?>
44 <input type="hidden" name="topic[action]" value="add"/>
45 <input type="hidden" id="parent" name="topic[forumid]" value="<?php echo intval($forumid) ?>" />
46
47 <label style="padding-left: 8px;"> <?php wpforo_phrase('Topic Title') ?>:&nbsp; </label>
48 <input required="true" autofocus type="text" name="topic[title]" class="wpf-subject" value="" id="title" autocomplete="off" placeholder="<?php wpforo_phrase('Enter title here') ?>">
49 <?php
50 $content = '';
51 $editor_id = 'postbody';
52 $settings = array(
53 'wpautop' => true,// use wpautop?
54 'media_buttons'=> FALSE,// show insert / upload button(s)
55 'textarea_name'=> $editor_id,// set the textarea name to something different, square brackets [] can be used here
56 'textarea_rows'=> get_option('default_post_edit_rows', 20),// rows = "..."
57 'tabindex'=> '',
58 'editor_height' => '180',
59 'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the < style > tags, can use "scoped".
60 'editor_class'=> '', // add extra class(es) to the editor textarea
61 'teeny'=> FALSE, // output the minimal editor config used in Press This
62 'dfw'=> false, // replace the default fullscreen with DFW (supported on the front - end in WordPress 3.4)
63 'tinymce'=> array(
64 'toolbar1' => 'bold,italic,underline,strikethrough,forecolor,bullist,numlist,hr,alignleft,aligncenter,alignright,alignjustify,link,unlink,blockquote,pre,undo,redo,source_code',
65 'toolbar2' => '',
66 'toolbar3' => '',
67 'toolbar4' => ''
68 ), // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
69 'quicktags'=> true, // load Quicktags, can be used to pass settings directly to Quicktags using an array()
70 'default_editor' => 'tinymce'
71 );
72 wp_editor( $content, $editor_id, $settings );
73 ?>
74 <div class="wpf-extra-fields">
75 <?php if($this->wpforo->perm->forum_can('s', $forumid)) : ?>
76 <input id="t_sticky" name="topic[type]" type="checkbox" value="0">&nbsp;&nbsp;
77 <i class="fa fa-exclamation fa-0x"></i>&nbsp;&nbsp;<label for="t_sticky" style="padding-bottom:2px; cursor: pointer;"><?php wpforo_phrase('Set Topic Sticky'); ?>&nbsp;</label>
78 <?php endif ?>
79 &nbsp;&nbsp;|&nbsp;&nbsp;<?php do_action('wpforo_topic_form_buttons_hook'); ?>&nbsp;&nbsp;
80 <?php if(!defined('WPFOROATTACH_BASENAME') && $this->wpforo->perm->forum_can('a', $forumid)): ?>
81 <div class="wpf-default-attachment" style="padding-top:5px;">
82 <label for="file"><?php wpforo_phrase('Attach file:') ?> </label> <input id="file" type="file" name="attachfile" />
83 <p><?php wpforo_phrase('Maximum allowed file size is'); echo ' ' . wpforo_print_size($this->wpforo->post_options['max_upload_size']); ?></p>
84 </div>
85 <?php endif; ?>
86 </div>
87 <?php if( wpforo_feature('subscribe_checkbox_on_post_editor', $this->wpforo) ) : ?>
88 <div class="wpf-topic-sbs" style="float:left;"><input id="wpf-topic-sbs" type="checkbox" name="wpforo_topic_subs" value="1" <?php echo ( wpforo_feature('subscribe_checkbox_default_status', $this->wpforo) ) ? 'checked="true" ' : ''; ?>/>&nbsp;<label for="wpf-topic-sbs"><?php wpforo_phrase('Subscribe to this topic.') ?></label></div>
89 <?php endif; ?>
90 <input id="formbutton" type="submit" name="topic[save]" class="button button-primary forum_submit" value="<?php wpforo_phrase('Save') ?>">
91 <div class="wpf-clear"></div>
92 </form>
93 </div>
94
95 <?php
96 }
97
98 /**
99 *
100 * @param array $args
101 *
102 * Please note that all array elements are required!
103 * example of args
104 * $default = array(
105 * "topic_closed" => $topic['closed'], // is topic closed or opened (values 1 or 0)
106 * "topicid" => $topic['topicid'], // the id of topic
107 * "forumid" => $forum_data['forumid'],
108 * "layout" => $cat_layout,
109 * "topic_title" => $topic['title'] // the title of topic
110 * );
111 *
112 * @return html form
113 */
114
115 function reply_form($args){
116 extract($args, EXTR_OVERWRITE); ?>
117 <!-- Report Dialog -->
118
119 <div id="reportdialog" title="<?php esc_attr( wpforo_phrase('Report to Administration') ) ?>" style="display: none">
120 <form id="reportform">
121 <input type="hidden" id="reportpostid" value=""/>
122 <textarea required style="width:100%; height:105px;" id="reportmessagecontent" placeholder="<?php wpforo_phrase('Write message') ?>"></textarea>
123 </form>
124 <input style="float: right;" id="sendreport" type="submit" value="<?php wpforo_phrase('Send Report') ?>"/>
125 </div>
126
127 <!-- Report Dialog end -->
128
129 <!-- Move Dialog -->
130
131 <div id="movedialog" title="<?php esc_attr( wpforo_phrase('Move topic') ) ?>" style="display: none">
132 <div class="form-field">
133 <label for="parent"><?php wpforo_phrase('Choose target forum') ?></label>
134 <form id="topicmoveform" method="POST">
135 <?php wp_nonce_field( 'wpforo_verify_form', 'wpforo_form' ); ?>
136 <input type="hidden" name="movetopicid" value="<?php echo intval($topicid) ?>"/>
137 <input type="hidden" name="post[save]" value="move"/>
138 <select id="parent" name="topic[forumid]" class="postform">
139 <?php $this->wpforo->forum->tree('select_box', FALSE, $topicid ); ?>
140 </select>
141 <input type="submit" value="<?php wpforo_phrase('Move') ?>"/>
142 </form>
143 </div>
144 </div>
145
146 <!-- move Dialog end -->
147 <?php
148 if( $topic_closed ) return;
149
150 $head_html = '<p id="wpf-reply-form-title">'.wpforo_phrase('Leave a reply', false).'</p>';
151 $head_html = apply_filters( 'wpforo_reply_form_head', $head_html, $args );
152 if(!isset($this->wpforo->post_options['max_upload_size']) || !$this->wpforo->post_options['max_upload_size']){$server_mus = wpforo_human_size_to_bytes(ini_get('upload_max_filesize')); if( !$server_mus || $server_mus > 10485760 ) $server_mus = 10485760; $this->wpforo->post_options['max_upload_size'] = $server_mus;}
153 ?>
154 <div id="wpf-form-wrapper">
155 <?php echo $head_html; //this is a HTML content ?>
156 <div id="wpf-post-create" class="wpf-post-create">
157 <form name="post" action="" enctype="multipart/form-data" method="POST" class="editor">
158 <?php wp_nonce_field( 'wpforo_verify_form', 'wpforo_form' ); ?>
159 <input type="hidden" id="formaction" name="post[action]" value="add"/>
160 <input type="hidden" id="formtopicid" name="post[topicid]" value="<?php echo intval($topicid) ?>"/>
161 <input type="hidden" id="postparentid" name="post[parentid]" value="0"/>
162 <input type="hidden" id="formpostid" name="post[postid]" value=""/>
163 <input type="hidden" id="parent" name="post[forumid]" value="<?php echo intval($forumid) ?>" />
164 <?php
165 $reply_title = wpforo_phrase('RE', false) . ': '. $topic_title;
166 $reply_title = apply_filters( 'wpforo_reply_form_field_title', $reply_title, $args );
167 $reply_title = esc_attr($reply_title);
168 ?>
169 <input id="title" required="true" type="text" name="post[title]" class="wpf-subject" value="<?php if($reply_title) echo esc_attr($reply_title); ?>" autocomplete="off" placeholder="<?php if($reply_title) echo esc_attr($reply_title); ?>"><br/>
170 <?php
171 $content = '';
172 $editor_id = 'postbody';
173 $settings = array(
174 'wpautop' => true,// use wpautop?
175 'media_buttons'=> FALSE,// show insert / upload button(s)
176 'textarea_name'=> $editor_id,// set the textarea name to something different, square brackets [] can be used here
177 'textarea_rows'=> get_option('default_post_edit_rows', 5),// rows = "..."
178 'editor_class'=> 'wpeditor', // add extra class(es) to the editor textarea
179 'teeny'=> false, // output the minimal editor config used in Press This
180 'dfw'=> false, // replace the default fullscreen with DFW (supported on the front - end in WordPress 3.4)
181 'editor_height' => '180',
182 'tinymce'=> array(
183 'toolbar1' => 'bold,italic,underline,strikethrough,forecolor,bullist,numlist,hr,alignleft,aligncenter,alignright,alignjustify,link,unlink,blockquote,pre,undo,redo,source_code',
184 'toolbar2' => '',
185 'toolbar3' => '',
186 'toolbar4' => ''
187 ), // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
188 'quicktags'=> true, // load Quicktags, can be used to pass settings directly to Quicktags using an array()
189 'default_editor' => 'tinymce' // load Quicktags, can be used to pass settings directly to Quicktags using an array()
190 );
191 wp_editor( $content, $editor_id, $settings );
192 ?>
193 <div class="wpf-extra-fields">
194 <?php do_action('wpforo_reply_form_buttons_hook'); ?>&nbsp;&nbsp;
195 <?php if(!defined('WPFOROATTACH_BASENAME') && $this->wpforo->perm->forum_can('a', $forumid)): ?>
196 <div class="wpf-default-attachment">
197 <label for="file"><?php wpforo_phrase('Attach file:') ?> </label> <input id="file" type="file" name="attachfile" />
198 <p><?php wpforo_phrase('Maximum allowed file size is'); echo ' ' . wpforo_print_size($this->wpforo->post_options['max_upload_size']); ?></p>
199 </div>
200 <?php endif; ?>
201 </div>
202 <?php if( wpforo_feature('subscribe_checkbox_on_post_editor', $this->wpforo) ) :
203 $args = array( "userid" => $this->wpforo->current_userid , "itemid" => intval($topicid), "type" => "topic" );
204 $subscribe = $this->wpforo->sbscrb->get_subscribe( $args );
205 if( !isset($subscribe['subid']) ) : ?>
206 <div class="wpf-topic-sbs"><input id="wpf-topic-sbs" type="checkbox" name="wpforo_topic_subs" value="1" <?php echo ( wpforo_feature('subscribe_checkbox_default_status', $this->wpforo) ) ? 'checked="true" ' : ''; ?> />&nbsp;<label for="wpf-topic-sbs"><?php wpforo_phrase('Subscribe to this topic.') ?></label></div>
207 <?php endif;
208 endif; ?>
209 <input id="formbutton" type="submit" name="post[save]" class="button button-primary forum_submit" value="<?php wpforo_phrase('Save') ?>">
210 <div class="wpf-clear"></div>
211 </form>
212 </div>
213 </div>
214 <?php
215 }
216
217 function pagenavi($paged, $items_count, $permalink = TRUE){
218 if($items_count <= $this->wpforo->post_options['posts_per_page']) return;
219
220 $pages_count = ceil($items_count/$this->wpforo->post_options['posts_per_page']);
221
222 if($permalink){
223 $url = trim( preg_replace('#\/paged\/[\d]+\/*.*$#is', '', wpforo_full_url()), '/' ) . '/paged/';
224 }else{
225 $url = trim( preg_replace('#[\&\?]wpfpaged=[\d]*.*$#is', '', wpforo_full_url()), '/' );
226 $url .= (strpos($url, '?') === FALSE ? '?' : '&') . 'wpfpaged=';
227 }
228 ?>
229
230 <div class="wpf-navi">
231 <div class="wpf-navi-wrap">
232 <span class="wpf-page-info"><?php wpforo_phrase('Page') ?> <?php echo intval($paged) ?> / <?php echo intval($pages_count) ?></span>
233 <?php if( $paged - 1 > 0 ): ?><a href="<?php echo esc_url($url) . ($paged - 1) ?>" class="wpf-prev-button"><i class="fa fa-chevron-left fa-sx"></i> <?php wpforo_phrase('prev') ?></a><?php endif ?>
234 <select class="wpf-navi-dropdown" onchange="if (this.value) window.location.href=this.value" title="<?php esc_attr( wpforo_phrase('Select Page') ) ?>">
235 <?php for($i = 1; $i <= $pages_count; $i++) : ?>
236 <option value="<?php echo esc_url($url) . $i ?>" <?php echo $paged == $i ? ' selected="selected"' : '' ?>><?php echo intval($i); ?></option>
237 <?php endfor; ?>
238 </select>
239 <?php if( $paged + 1 <= $pages_count ): ?><a href="<?php echo esc_url($url) . ($paged + 1) ?>" class="wpf-prev-button"><?php wpforo_phrase('next') ?> <i class="fa fa-chevron-right fa-sx"></i></a><?php endif ?>
240 </div>
241 </div>
242
243 <?php
244 }
245
246 function likers($postid){
247 if(!$postid) return '';
248
249 $return = '';
250 if( $l_count = $this->wpforo->post->get_post_likes_count($postid) ){
251 $l_usernames = $this->wpforo->post->get_likers_usernames($postid);
252 if($l_usernames[0]['ID'] == $this->wpforo->current_userid) $l_usernames[0]['display_name'] = wpforo_phrase('You', FALSE);
253 if($l_count == 1){
254 $return = sprintf( wpforo_phrase('%s liked', FALSE), '<a href="' . esc_url($this->wpforo->member->get_profile_url($l_usernames[0]['ID'])) . '">'.esc_html($l_usernames[0]['display_name']).'</a>' );
255 }elseif($l_count == 2){
256 $return = sprintf( wpforo_phrase('%s and %s liked', FALSE), '<a href="' . esc_url($this->wpforo->member->get_profile_url($l_usernames[0]['ID'])) . '">'.esc_html($l_usernames[0]['display_name']).'</a>', '<a href="'.esc_url($this->wpforo->member->get_profile_url($l_usernames[1]['ID'])).'">'.esc_html($l_usernames[1]['display_name']).'</a>' );
257 }elseif($l_count == 3){
258 $return = sprintf( wpforo_phrase('%s, %s and %s liked', FALSE), '<a href="' . esc_url($this->wpforo->member->get_profile_url($l_usernames[0]['ID'])) .'">'.esc_html($l_usernames[0]['display_name']).'</a>', '<a href="'.esc_url($this->wpforo->member->get_profile_url($l_usernames[1]['ID'])).'">'.esc_html($l_usernames[1]['display_name']).'</a>', '<a href="'.esc_url($this->wpforo->member->get_profile_url($l_usernames[2]['ID'])).'">'.esc_html($l_usernames[2]['display_name']).'</a>' );
259 }elseif($l_count >= 4){
260 $l_count = $l_count - 3;
261 $return = sprintf( wpforo_phrase('%s, %s, %s and %d people liked', FALSE), '<a href="' . esc_url($this->wpforo->member->get_profile_url($l_usernames[0]['ID'])) .'">'.esc_html($l_usernames[0]['display_name']).'</a>', '<a href="'.esc_url($this->wpforo->member->get_profile_url($l_usernames[1]['ID'])).'">'.esc_html($l_usernames[1]['display_name']).'</a>', '<a href="'.esc_url($this->wpforo->member->get_profile_url($l_usernames[2]['ID'])).'">'.esc_html($l_usernames[2]['display_name']).'</a>', $l_count );
262 }
263 }
264 return $return;
265 }
266
267
268 /**
269 * Get actions buttons
270 *
271 * @since 1.0.0
272 *
273 * @param array buttons names function will return buttons by this array
274 *
275 * @param int $forumid required
276 *
277 * @param int $topicid required
278 *
279 * @param int $postid required
280 *
281 * @param int $is_topic required this is a first post in the loop
282 *
283 * $buttons = array( 'reply', 'answer', 'comment', 'quote', 'like', 'report', 'sticky', 'close', 'move', 'edit', 'delete', 'link' );
284 *
285 * @return html ( buttons )
286 */
287
288 function buttons( $buttons, $forumid, $topicid, $postid, $is_topic = FALSE ){
289
290 $button_html = array();
291
292 foreach($buttons as $button){
293
294 switch($button){
295
296 case 'reply':
297 if($this->wpforo->topic->is_closed($topicid)) break;
298 if( $this->wpforo->perm->forum_can('cr', $forumid) ){
299 $button_html[] = '<span class="wpforo-reply wpf-action add_post_button"><i class="fa fa-reply fa-rotate-180"></i>' . wpforo_phrase('Reply', false).'</span>';
300 }else{
301 $button_html[] = '<span class="wpf-action not_reg_user"><i class="fa fa-reply fa-rotate-180"></i> ' . wpforo_phrase('Reply', false).'</span>';
302 }
303 break;
304 case 'answer':
305 if( $this->wpforo->perm->forum_can('cr', $forumid) ){
306 $button_html[] = '<span class="wpforo-answer wpf-button add_post_button"><i class="fa fa-pencil"></i> ' . wpforo_phrase('Answer', false).'</span>';
307 }else{
308 $button_html[] = '<span class="wpf-button not_reg_user"><i class="fa fa-pencil"></i> ' . wpforo_phrase('Answer', false).'</span>';
309 }
310 break;
311 case 'comment':
312 if($this->wpforo->topic->is_closed($topicid)) break;
313 $title = wpforo_phrase('Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.', false);
314 if( $this->wpforo->perm->forum_can('cr', $forumid) ) {
315 $button_html[] = '<span id="parentpostid'.intval($postid).'" class="wpforo-childreply wpf-button add_post_button" title="'.esc_attr($title).'"><i class="fa fa-comment"></i> ' . wpforo_phrase('Add a comment', false).'</span>';
316 }else{
317 $button_html[] = '<span class="not_reg_user wpf-button add_post_button" title="'.esc_attr($title).'"><i class="fa fa-comment"></i> ' . wpforo_phrase('Add a comment', false).'</span>';
318 }
319 break;
320 case 'quote':
321 if($this->wpforo->topic->is_closed($topicid)) break;
322 if( $this->wpforo->perm->forum_can('cr', $forumid) ) {
323 $button_html[] = '<span id="wpfquotepost'.intval($postid).'" class="wpforo-quote wpf-action"><i class="fa fa-quote-left fa-0x"></i>' . wpforo_phrase('Quote', false).'</span>';
324 }else{
325 $button_html[] = '<span class="wpf-action not_reg_user"><i class="fa fa-quote-left fa-0x"></i>' . wpforo_phrase('Quote', false).'</span>';
326 }
327 break;
328 case 'like':
329 if( $this->wpforo->perm->forum_can('l', $forumid) ) {
330 $like_status = ( $this->wpforo->post->is_liked( $postid, $this->wpforo->current_userid ) === FALSE ? 'wpforo-like' : 'wpforo-unlike' );
331 $like_icode = ( $like_status == 'wpforo-like') ? 'up' : 'down';
332 $button_html[] = '<span id="wpf'. intval($postid) .'" class="wpf-action '. sanitize_html_class($like_status) .'"><i id="like'. intval($postid) .'" class="fa fa-thumbs-o-'. esc_attr($like_icode) .' fa-0x"></i><span id="liketext'. intval($postid) .'">' . wpforo_phrase( str_replace('wpforo-', '', $like_status), false) . '</span></span>';
333 }
334 break;
335 case 'report':
336 if( $this->wpforo->perm->forum_can('r', $forumid) ) {
337 $button_html[] = '<span id="wpfreport'. intval($postid) .'" class="wpf-action wpforo-report"><i class="fa fa-exclamation-triangle"></i>' . wpforo_phrase('Report', false).'</span>';
338 }
339 break;
340 case 'sticky':
341 if( $this->wpforo->perm->forum_can('s', $forumid) ) {
342 $sticky_status = ( $this->wpforo->topic->is_sticky($topicid ) ? 'wpforo-unsticky' : 'wpforo-sticky');
343 $button_html[] = '<span id="wpfsticky'. intval($topicid) .'" class="wpf-action '. sanitize_html_class($sticky_status) .'"><i class="fa fa-exclamation fa-0x"></i><span id="stickytext'. intval($topicid) .'">' . wpforo_phrase( str_replace('wpforo-', '', $sticky_status), false).'</span></span>';
344 }
345 break;
346 case 'solved':
347 $post = $this->wpforo->post->get_post($postid);
348 if( $this->wpforo->perm->forum_can('sv', $forumid) || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can('osv', $forumid)) ) {
349 $solved_status = ( $this->wpforo->topic->is_solved($topicid) ? 'wpforo-unsolved' : 'wpforo-solved');
350 $button_html[] = '<span id="wpfsolved'. intval($postid) .'" class="wpf-action '. sanitize_html_class($solved_status) .'"><i class="fa fa-check-circle fa-0x"></i><span id="solvedtext'. intval($postid) .'">' . wpforo_phrase( str_replace('wpforo-', '', $solved_status), false).'</span></span>';
351 }
352 break;
353 case 'close':
354 if( $this->wpforo->perm->forum_can('cot', $forumid) ) {
355 $open_status = ( $this->wpforo->topic->is_closed($topicid) ? 'wpforo-open' : 'wpforo-close' );
356 $open_icon = ($open_status == 'wpforo-open') ? 'unlock' : 'lock';
357 $button_html[] = '<span id="wpfclose'. intval($topicid) .'" class="wpf-action '. sanitize_html_class($open_status) .'"><i id="closeicon'. intval($topicid) .'" class="fa fa-'. esc_attr($open_icon) .' fa-0x"></i><span id="closetext'. intval($topicid) .'">' . wpforo_phrase( str_replace('wpforo-', '', $open_status), false).'</span></span>';
358 }
359 break;
360 case 'move':
361 if( $this->wpforo->perm->forum_can('mt', $forumid) ) {
362 $button_html[] = '<span class="wpf-action wpforo-move"><i class="fa fa-share-square-o fa-0x"></i>' . wpforo_phrase('Move', false).'</span>';
363 }
364 break;
365 case 'edit':
366 if($this->wpforo->topic->is_closed($topicid)) break;
367 $post = $this->wpforo->post->get_post($postid);
368 $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
369 if( $this->wpforo->perm->forum_can( ($is_topic ? 'et' : 'er'), $forumid ) || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can( ($is_topic ? 'eot' : 'eor' ), $forumid ) && $diff < $this->wpforo->post_options[($is_topic ? 'eot' : 'eor' ).'_durr'] ) ) {
370 $a = ( $is_topic ) ? 'wpfedittopicpid' : '';
371 $b = ( $is_topic ) ? $postid : $postid;
372 $button_html[] = '<span id="'. esc_attr( $a . $b ) .'" class="wpforo-edit wpf-action"><i class="fa fa-edit fa-0x"></i>' . wpforo_phrase('Edit', false).'</span>';
373 }
374 break;
375 case 'delete':
376 $post = $this->wpforo->post->get_post($postid);
377 $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
378 if( $this->wpforo->perm->forum_can( ($is_topic ? 'dt' : 'dr' ), $forumid ) || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can( ($is_topic ? 'dot' : 'dor' ), $forumid ) && $diff < $this->wpforo->post_options[($is_topic ? 'dot' : 'dor' ).'_durr']) ){
379 $a = ( $is_topic ) ? 'wpftopicdelete' : 'wpfreplydelete';
380 $b = ( $is_topic ) ? $topicid : $postid;
381 $button_html[] = '<span id="'. esc_attr( $a . $b ) .'" class="wpf-action wpforo-delete"><i class="fa fa-times fa-0x"></i>' . wpforo_phrase('Delete', false).'</span>';
382 }
383 break;
384 case 'link':
385 $url = ( $is_topic ) ? $this->wpforo->topic->get_topic_url( $topicid ) : $this->wpforo->post->get_post_url( $postid );
386 $button_html[] = '<a href="'. esc_url($url) .'"><i class="fa fa-link fa-0x"></i></a>';
387 break;
388 case 'positivevote':
389 if( $this->wpforo->perm->forum_can('v', $forumid) ) {
390 $button_html[] = '<i itemtype="' . ( $is_topic ? 'topic' : 'reply' ) . '" id="wpfvote-up-'. intval($postid) .'" class="voteup fa fa-play fa-rotate-270 wpfcl-0"></i>';
391 }else{
392 $button_html[] = '<i class="not_reg_user fa fa-play fa-rotate-270 wpfcl-0"></i>';
393 }
394 break;
395 case 'negativevote':
396 if( $this->wpforo->perm->forum_can('v', $forumid) ) {
397 $button_html[] = '<i itemtype="' . ( $is_topic ? 'topic' : 'reply' ) . '" id="wpfvote-down-'. intval($postid) .'" class="votedown fa fa-play fa-rotate-90 wpfcl-0"></i>';
398 }else{
399 $button_html[] = '<i class="not_reg_user fa fa-play fa-rotate-90 wpfcl-0"></i>';
400 }
401 break;
402 case 'isanswer':
403 $is_answer = $this->wpforo->post->is_answered( $postid );
404 $is_answer = ( $is_answer == 0 ) ? '-not' : '';
405 if( is_user_logged_in() ){
406 $button_html[] = '<div id="wpf-answer-'. intval($postid) .'" class="wpf-toggle'. esc_attr($is_answer) .'-answer"><i class="fa fa-check"></i></div>';
407 }else{
408 $button_html[] = '<div class="wpf-toggle'. esc_attr($is_answer) .'-answer not_reg_user"><i class="fa fa-check"></i></div>';
409 }
410 break;
411 } //switch
412 } //foreach
413
414 echo implode('', $button_html);
415
416 }
417
418 function breadcrumb($url_data){
419 extract($url_data, EXTR_OVERWRITE);
420
421 switch($template) :
422 case 'search': ?>
423
424 <div class="wpf-breadcrumb">
425 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
426
427 <a href="#" class="active"><?php wpforo_phrase('Search') ?></a>
428
429 <a href="#" class="wpf-end">&nbsp;</a>
430 </div>
431
432 <?php break;
433 case 'signup': ?>
434
435 <div class="wpf-breadcrumb">
436 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
437
438 <a href="#" class="active"><?php wpforo_phrase('Register') ?></a>
439
440 <a href="#" class="wpf-end">&nbsp;</a>
441 </div>
442
443 <?php break;
444 case 'signin': ?>
445
446 <div class="wpf-breadcrumb">
447 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
448
449 <a href="#" class="active"><?php wpforo_phrase('Login') ?></a>
450
451 <a href="#" class="wpf-end">&nbsp;</a>
452 </div>
453
454 <?php break;
455 case 'members': ?>
456
457 <div class="wpf-breadcrumb">
458 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
459
460 <?php if(isset($_GET['wpfms'])) : ?>
461
462 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
463 <a href="#" class="active"><?php wpforo_phrase('Search') ?></a>
464
465 <?php else : ?>
466
467 <a href="#" class="active"><?php wpforo_phrase('Members') ?></a>
468
469 <?php endif ?>
470
471 <a href="#" class="wpf-end">&nbsp;</a>
472 </div>
473
474 <?php break;
475 case 'profile': ?>
476
477 <div class="wpf-breadcrumb">
478 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
479
480 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
481 <a href="#" class="active"><?php wpforo_text( !empty($user['display_name']) ? esc_html($user['display_name']) : !empty($user['user_nicename']) ? esc_html(urldecode($user['user_nicename'])) : '', 19 ) ?></a>
482
483 <a href="#" class="wpf-end">&nbsp;</a>
484 </div>
485
486 <?php break;
487 case 'account': ?>
488
489 <div class="wpf-breadcrumb">
490 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i>
491
492 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
493 <a href="<?php echo esc_url($user['profile_url']) ?>"><?php wpforo_text( !empty($user['display_name']) ? esc_html($user['display_name']) : !empty($user['user_nicename']) ? esc_html(urldecode($user['user_nicename'])) : '', 19 ) ?></a>
494 <a href="#" class="active"><?php wpforo_phrase('Account') ?></a>
495
496 <a href="#" class="wpf-end">&nbsp;</a>
497 </div>
498
499 <?php break;
500 case 'activity': ?>
501
502 <div class="wpf-breadcrumb">
503 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i>
504
505 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
506 <a href="<?php echo esc_url($user['profile_url']) ?>"><?php wpforo_text( !empty($user['display_name']) ? esc_html($user['display_name']) : !empty($user['user_nicename']) ? esc_html(urldecode($user['user_nicename'])) : '', 19 ) ?></a>
507 <a href="#" class="active"><?php wpforo_phrase('Activity') ?></a>
508
509 <a href="#" class="wpf-end">&nbsp;</a>
510 </div>
511
512 <?php break;
513 case 'subscriptions': ?>
514
515 <div class="wpf-breadcrumb">
516 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i>
517
518 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
519 <a href="<?php echo esc_url($user['profile_url']) ?>"><?php wpforo_text( !empty($user['display_name']) ? esc_html($user['display_name']) : !empty($user['user_nicename']) ? esc_html(urldecode($user['user_nicename'])) : '', 19 ) ?></a>
520 <a href="#" class="active"><?php wpforo_phrase('Subscriptions') ?></a>
521
522 <a href="#" class="wpf-end">&nbsp;</a>
523 </div>
524
525 <?php break;
526 // TODO: move code to pm plugin
527 case 'messages': ?>
528
529 <div class="wpf-breadcrumb">
530 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i>
531
532 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
533
534 <?php if(!empty($user)) : ?>
535
536 <a href="<?php echo esc_url($user['profile_url']) ?>"><?php wpforo_text( !empty($user['display_name']) ? esc_html($user['display_name']) : !empty($user['user_nicename']) ? esc_html(urldecode($user['user_nicename'])) : '', 19 ) ?></a>
537
538 <?php endif ?>
539
540 <a href="#" class="active"><?php wpforo_phrase('Messages') ?></a>
541
542 <a href="#" class="wpf-end">&nbsp;</a>
543 </div>
544
545 <?php break;
546 case 'topic': ?>
547
548 <div class="wpf-breadcrumb">
549 <a href="<?php echo ( !isset($forumid) ? '#' : WPFORO_BASE_URL ) ?>" class="wpf-root<?php echo ( !isset($forumid) ? ' active' : '' ) ?>" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
550
551 <?php if(isset($forumid)) : ?>
552 <?php $relative_ids = array();
553 $this->wpforo->forum->get_all_relative_ids($forumid, $relative_ids);
554 foreach( $relative_ids as $key => $rel_forumid ) : ?>
555 <?php $forum = $this->wpforo->forum->get_forum($rel_forumid) ?>
556 <?php if( $key != ( count($relative_ids) - 1 ) ) : ?>
557
558 <a href="<?php echo esc_url($this->wpforo->forum->get_forum_url($rel_forumid)) ?>" title="<?php echo esc_attr($forum['title']) ?>"><?php wpforo_text($forum['title'], 19) ?></a>
559
560 <?php else : ?>
561
562 <a href="#" class="active" title="<?php echo esc_attr($forum['title']) ?>"><?php wpforo_text($forum['title'], 19) ?></a>
563
564 <?php endif ?>
565 <?php endforeach ?>
566 <?php endif ?>
567
568 <a href="#" class="wpf-end">&nbsp;</a>
569 </div>
570
571 <?php break;
572 case 'post': ?>
573
574 <div class="wpf-breadcrumb">
575 <a href="<?php echo ( !isset($forumid) ? '#' : WPFORO_BASE_URL ) ?>" class="wpf-root<?php echo ( !isset($forumid) ? ' active' : '' ) ?>" title="<?php esc_attr( wpforo_phrase('Forums') ) ?>"><i class="fa fa-home"></i></a>
576
577 <?php if(isset($forumid)) : ?>
578 <?php $relative_ids = array();
579 $this->wpforo->forum->get_all_relative_ids($forumid, $relative_ids);
580 foreach( $relative_ids as $key => $rel_forumid ) : ?>
581 <?php $forum = $this->wpforo->forum->get_forum($rel_forumid) ?>
582
583 <a href="<?php echo esc_url($this->wpforo->forum->get_forum_url($rel_forumid)) ?>" title="<?php echo esc_attr($forum['title']) ?>"><?php wpforo_text($forum['title'], 19) ?></a>
584
585 <?php endforeach ?>
586 <?php endif ?>
587 <?php if(!empty($topic)) : ?>
588
589 <a href="#" class="active" title="<?php echo esc_attr($topic['title']) ?>"><?php wpforo_text($topic['title'], 19) ?></a>
590
591 <?php endif ?>
592 <a href="#" class="wpf-end">&nbsp;</a>
593 </div>
594
595 <?php break;
596 default: ?>
597
598 <div class="wpf-breadcrumb">
599 <a href="#" class="wpf-root active"><?php wpforo_phrase('Forums') ?></a>
600 <a href="#" class="wpf-end">&nbsp;</a>
601 </div>
602
603 <?php
604 endswitch;
605
606 }
607
608 function icon($type, $item = array(), $echo = true, $data = 'icon' ){
609
610 $icon = array();
611 $status = false;
612 if(isset($item['type'])){
613
614 if( $type == 'topic' ){
615 if($this->wpforo->topic->is_solved($item['topicid'])){
616 $icon['class'] = 'fa-check-circle';
617 $icon['color'] = 'wpfcl-8';
618 $icon['title'] = wpforo_phrase('Solved', false);
619 if($echo) {
620 $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title'];
621 }
622 else{
623 return ($data == 'icon') ? implode(' ', $icon) : $icon['title'];
624 }
625 }
626 }
627
628 if( $item['closed'] && $item['type'] == 1 ){
629 $icon['class'] = 'fa-lock';
630 $icon['color'] = 'wpfcl-1';
631 $icon['title'] = wpforo_phrase('Closed', false);
632 if($echo) { $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
633 }
634 elseif( $item['closed'] && $item['type'] != 1 ){
635 $icon['class'] = 'fa-lock';
636 $icon['color'] = 'wpfcl-1';
637 $icon['title'] = wpforo_phrase('Closed', false);
638 if($echo) { $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
639 }
640 elseif( !$item['closed'] && $item['type'] == 1 ){
641 $icon['class'] = 'fa-thumb-tack';
642 $icon['color'] = 'wpfcl-5';
643 $icon['title'] = wpforo_phrase('Sticky', false);
644 if($echo) { $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
645 }
646
647 if( $status ){
648 //do nothing
649 }
650 else{
651 if( $type == 'forum' ){
652 $icon['class'] = 'fa-comments';
653 $icon['color'] = 'wpfcl-2';
654 }
655 elseif( $type == 'topic' ){
656 if( $item['posts'] == 1 ){
657 $icon['class'] = 'fa-file-o';
658 $icon['color'] = 'wpfcl-2';
659 $icon['title'] = '';
660 }
661 elseif( $item['posts'] > 1 && $item['posts'] <= 5 ){
662 $icon['class'] = 'fa-file-text-o';
663 $icon['color'] = 'wpfcl-2';
664 $icon['title'] = '';
665 }
666 elseif( $item['posts'] > 5 && $item['posts'] <= 20 ){
667 $icon['class'] = 'fa-file-text';
668 $icon['color'] = 'wpfcl-2';
669 $icon['title'] = '';
670 }
671 elseif( $item['posts'] > 20 ){
672 $icon['class'] = 'fa-file-text';
673 $icon['color'] = 'wpfcl-5';
674 $icon['title'] = '';
675 }
676 else{
677 $icon['class'] = 'fa-file-o';
678 $icon['color'] = 'wpfcl-2';
679 $icon['title'] = '';
680 }
681 }
682 if($echo) { echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
683 }
684
685 }
686 else{
687 return false;
688 }
689
690 }
691
692 public function init_member_templates(){
693 $this->wpforo->member_tpls = array(
694 'account' => wpftpl('profile-account.php'),
695 'activity' => wpftpl('profile-activity.php'),
696 'subscriptions' => wpftpl('profile-subscriptions.php')
697 );
698 $this->wpforo->member_tpls = apply_filters('wpforo_member_templates_filter', $this->wpforo->member_tpls);
699 $this->wpforo->member_tpls['profile'] = wpftpl('profile-home.php');
700 }
701
702 function has_menu(){
703 return has_nav_menu( 'wpforo-menu' );
704 }
705
706 function nav_menu(){
707 if ( has_nav_menu( 'wpforo-menu' ) ){
708 $defaults = array(
709 'theme_location' => 'wpforo-menu',
710 'menu' => '',
711 'container' => '',
712 'container_class' => '',
713 'container_id' => '',
714 'menu_class' => 'wpf-menu',
715 'menu_id' => 'wpf-menu',
716 'echo' => true,
717 'fallback_cb' => 'wp_page_menu',
718 'before' => '',
719 'after' => '',
720 'link_before' => '',
721 'link_after' => '',
722 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
723 'depth' => 0,
724 'walker' => ''
725 );
726 wp_nav_menu( $defaults );
727 }
728 }
729
730 function init_nav_menu(){
731
732 if(isset($this->wpforo->current_object) && !empty($this->wpforo->current_object)){
733
734 extract($this->wpforo->current_object, EXTR_OVERWRITE);
735
736 $this->wpforo->menu['wpforo-home'] = array(
737 'href' => WPFORO_BASE_URL,
738 'label' => wpforo_phrase('forums', FALSE),
739 'attr' => ((($template == 'forum' || $template == 'topic' || $template == 'post') && !isset($_GET['wpforo'])) ? ' class="wpforo-active"' : '' ),
740 'submenues' => array()
741 );
742
743 if($this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'vmem')){
744 $this->wpforo->menu['wpforo-members'] = array(
745 'href' => WPFORO_BASE_URL . 'members/',
746 'label' => wpforo_phrase('members', FALSE),
747 'attr' => ( $template == 'members' ? ' class="wpforo-active"' : '' ),
748 'submenues' => array()
749 );
750 }
751
752 if( is_user_logged_in() ){
753
754 $this->wpforo->menu['wpforo-profile-home'] = array(
755 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid),
756 'label' => wpforo_phrase('my profile', FALSE),
757 'attr' => ( isset($this->wpforo->member_tpls[$template]) && $this->wpforo->member_tpls[$template] ? ' class="wpforo-active"' : '' ),
758 'submenues' => array()
759 );
760 $this->wpforo->menu['wpforo-profile-account'] = array(
761 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid, 'account'),
762 'label' => wpforo_phrase('account', FALSE),
763 'attr' => ( $template == 'account' ? ' class="wpforo-active"' : '' ),
764 'submenues' => array()
765 );
766 $this->wpforo->menu['wpforo-profile-activity'] = array(
767 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid, 'activity'),
768 'label' => wpforo_phrase('activity', FALSE),
769 'attr' => ( $template == 'activity' ? ' class="wpforo-active"' : '' ),
770 'submenues' => array()
771 );
772 $this->wpforo->menu['wpforo-profile-subscriptions'] = array(
773 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid, 'subscriptions'),
774 'label' => wpforo_phrase('subscriptions', FALSE),
775 'attr' => ( $template == 'subscriptions' ? ' class="wpforo-active"' : '' ),
776 'submenues' => array()
777 );
778 $this->wpforo->menu['wpforo-logout'] = array(
779 'href' => WPFORO_BASE_URL . '?wpforo=logout',
780 'label' => wpforo_phrase('logout', FALSE),
781 'attr' => '',
782 'submenues' => array()
783 );
784
785 }else{
786
787 if( wpforo_feature('user-register', $this->wpforo) ){
788 $this->wpforo->menu['wpforo-register'] = array(
789 'href' => wpforo_register_url(),
790 'label' => wpforo_phrase('register', FALSE),
791 'attr' => ( isset($_GET['wpforo']) && $_GET['wpforo'] == 'signup' ? ' class="wpforo-active"' : '' ),
792 'submenues' => array()
793 );
794 }
795 $this->wpforo->menu['wpforo-login'] = array(
796 'href' => wpforo_login_url(),
797 'label' => wpforo_phrase('login', FALSE),
798 'attr' => ( isset($_GET['wpforo']) && $_GET['wpforo'] == 'signin' ? ' class="wpforo-active"' : '' ),
799 'submenues' => array()
800 );
801 }
802
803 $this->wpforo->menu = apply_filters('wpforo_menu_array_filter', $this->wpforo->menu);
804 }
805 }
806
807 /**
808 *
809 * Checks in current active theme options if certain layout exists.
810 *
811 * @since 1.0.0
812 *
813 * @param mixed $identifier Layout id (folder name) OR @layout variable in header ( 1 or Extended )
814 * @param string $identifier_type The type of first parameter 'id' OR 'name' (@layout)
815 *
816 * @return boolean true/false
817 *
818 **/
819 function layout_exists( $identifier, $identifier_type = 'id' ){
820
821 $layouts = $this->wpforo->theme_options['layouts'];
822
823 if( $identifier_type == 'id' ){
824 if( isset($layouts[$identifier]) && !empty($layouts[$identifier])){
825 return true;
826 }
827 else{
828 return false;
829 }
830 }
831 elseif( $identifier_type = 'name' ){
832 foreach( $layouts as $id => $layout ){
833 if( !isset($layout['name']) && $layout['name'] == $identifier ){
834 return true;
835 }
836 }
837 return false;
838 }
839 }
840
841 /**
842 *
843 * Finds and returns all layouts information in array from theme's /layouts/ folder
844 *
845 * @since 1.0.0
846 *
847 * @param string $theme Theme id ( folder name ) e.g. 'classic'
848 *
849 * @return array
850 *
851 **/
852 function find_layouts( $theme ){
853 $layout_data = array();
854 $layouts = $this->find_themes('/'.$theme.'/layouts', 'php', 'layout');
855 if(!empty($layouts)){
856 foreach( $layouts as $layout ){
857 $lid = trim(basename(dirname( $layout['file']['value'] )), '/');
858 $layout_data[$lid]['id'] = $lid;
859 $layout_data[$lid]['name'] = $layout['name']['value'];
860 $layout_data[$lid]['version'] = $layout['version']['value'];
861 $layout_data[$lid]['description'] = $layout['description']['value'];
862 $layout_data[$lid]['author'] = $layout['author']['value'];
863 $layout_data[$lid]['url'] = $layout['layout_url']['value'];
864 $layout_data[$lid]['file'] = $layout['file']['value'];
865 }
866 }
867 return $layout_data;
868 }
869
870 function show_layout_selectbox($layoutid = 0){
871 $layouts = $this->find_layouts( WPFORO_THEME );
872 if( !empty($layouts) ){
873 foreach( $layouts as $layout ) : ?>
874 <option value="<?php echo esc_attr(trim($layout['id'])) ?>" <?php echo ( $layoutid == $layout['id'] ? 'selected' : '' ); ?> ><?php echo esc_html($layout['name']) ?></option>
875 <?php
876 endforeach;
877 }
878 }
879
880 /**
881 *
882 * Finds and returns styles array from theme's /styles/colors.php file
883 *
884 * @since 1.0.0
885 *
886 * @param string $theme Theme id ( folder name ) e.g. 'classic'
887 *
888 * @return array
889 *
890 **/
891 function find_styles( $theme ){
892 $colors = array();
893 $color_file = WPFORO_THEME_DIR . '/' . $theme . '/styles/colors.php';
894 if( file_exists($color_file) ){
895 include( $color_file );
896 }
897 return $colors;
898 }
899
900 /**
901 *
902 * Scans certain theme directory and returns all information in array ( theme header, layouts, styles ).
903 *
904 * @since 1.0.0
905 *
906 * @param string $theme_file Theme folder name or main css file base path ( 'classic' OR classic/style.css' )
907 *
908 * @return array
909 *
910 **/
911 function find_theme( $theme_file ){
912 $theme = array();
913 $theme_file = trim(trim($theme_file, '/'));
914
915 if( preg_match('|\.[\w\d]{2,4}$|is', $theme_file) ){
916 $theme_folder = trim(basename(dirname($theme_file)), '/');
917 }
918 else{
919 $theme_folder = $theme_file;
920 $theme_file = $theme_file . '/style.css';
921 }
922
923 if( !is_readable( WPFORO_THEME_DIR . '/' . $theme_file ) ){
924 return $theme['error'] = __('Theme file not readable', 'wpforo') .' ('.$theme_file.')';
925 }
926 else{
927 $theme_data = $this->find_theme_headers( WPFORO_THEME_DIR . '/' . $theme_file );
928 $theme['id'] = $theme_folder;
929 $theme['name'] = $theme_data['name']['value'];
930 $theme['version'] = $theme_data['version']['value'];
931 $theme['description'] = $theme_data['description']['value'];
932 $theme['author'] = $theme_data['author']['value'];
933 $theme['url'] = $theme_data['theme_url']['value'];
934 $theme['file'] = $theme_file;
935 $theme['folder'] = $theme_folder;
936 $theme['layouts'] = $this->find_layouts( $theme_folder );
937 $styles = $this->find_styles( $theme_folder );
938 if(!empty($styles)){
939 reset($styles);
940 $theme['style'] = key($styles);
941 $theme['styles'] = $styles;
942 }
943 return $theme;
944 }
945
946 }
947
948 /**
949 *
950 * Scans wpForo themes (wpf-themes) folder, reads main files' headers and returns information about all themes in array.
951 * This function can also be used to scan and get information about layouts in each theme /layouts/ folder.
952 *
953 * @since 1.0.0
954 *
955 * @param string $base_dir Absolute path to scan directory (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/)
956 * @param string $ext File extension which may contain header information
957 * @param string $mode 'theme' or 'layout'
958 *
959 * @return array
960 *
961 **/
962 function find_themes( $base_dir = '', $ext = 'css', $mode = 'theme' ){
963 $themes = array ();
964 $themes_dir = @opendir( WPFORO_THEME_DIR . $base_dir );
965 $theme_files = array();
966 if( $themes_dir ){
967 while( ($file = readdir( $themes_dir )) !== false ){
968 if( substr($file, 0, 1) == '.' ) continue;
969 if( is_dir( WPFORO_THEME_DIR . $base_dir .'/'.$file ) ){
970 $themes_subdir = @opendir( WPFORO_THEME_DIR . $base_dir .'/'.$file );
971 if( $themes_subdir ){
972 while(($subfile = readdir( $themes_subdir ) ) !== false ){
973 if( substr($subfile, 0, 1) == '.' ) continue;
974 if( substr($subfile, -4) == '.' . $ext ) $theme_files[] = "$file/$subfile";
975 }
976 closedir( $themes_subdir );
977 }
978 }
979 else{
980 if( substr($file, -4) == '.' . $ext ) $theme_files[] = $file;
981 }
982 }
983 closedir( $themes_dir );
984 }
985 if( empty($theme_files) ) return $themes;
986 foreach( $theme_files as $theme_file ){
987 if( !is_readable( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file ) ) continue;
988 if( $mode == 'theme' ){
989 $theme_data = $this->find_theme_headers( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file );
990 }
991 elseif( $mode == 'layout' ){
992 $theme_data = $this->find_layout_headers( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file );
993 }
994 if( empty($theme_data['name']['value']) ) continue;
995 $themes[wpforo_clear_basename($theme_file)] = $theme_data;
996 }
997 return $themes;
998 }
999
1000 /**
1001 *
1002 * Reads theme main file's header variables and returns information in array.
1003 *
1004 * @since 1.0.0
1005 *
1006 * @param string $file Absolute path to file (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/style.css)
1007 *
1008 * @return array
1009 *
1010 **/
1011 function find_theme_headers( $file ){
1012 $theme_headers = array();
1013 $headers = array(
1014 'name' => 'Theme Name',
1015 'version' => 'Version',
1016 'description' => 'Description',
1017 'author' => 'Author',
1018 'theme_url' => 'Theme URI',
1019 );
1020 $fp = fopen( $file, 'r' );
1021 $data = fread( $fp, 8192 );
1022 fclose( $fp );
1023 $data = str_replace( "\r", "\n", $data );
1024 foreach ( $headers as $header_key => $header_name ){
1025 if ( preg_match( '|^[\s\t\/*#@]*' . preg_quote( $header_name, '|' ) . ':(.*)$|mi', $data, $match ) && $match[1] ){
1026 $theme_headers[$header_key]['name'] = $header_name;
1027 $theme_headers[$header_key]['value'] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
1028 }
1029 else{
1030 $theme_headers[$header_key]['name'] = $header_name;
1031 $theme_headers[$header_key]['value'] = '';
1032 }
1033 }
1034 $theme_headers['file']['name'] = 'file';
1035 $theme_headers['file']['value'] = $file;
1036 return $theme_headers;
1037 }
1038
1039 /**
1040 *
1041 * Reads layout main file's header variables and returns information in array.
1042 *
1043 * @since 1.0.0
1044 *
1045 * @param string $file Absolute path to file (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/layouts/1/forum.php)
1046 *
1047 * @return array
1048 *
1049 **/
1050 function find_layout_headers( $file ){
1051 $theme_headers = array();
1052 $headers = array(
1053 'name' => 'layout',
1054 'version' => 'version',
1055 'description' => 'description',
1056 'author' => 'author',
1057 'layout_url' => 'url',
1058 );
1059 $fp = fopen( $file, 'r' );
1060 $data = fread( $fp, 8192 );
1061 fclose( $fp );
1062 $data = str_replace( "\r", "\n", $data );
1063 foreach ( $headers as $header_key => $header_name ){
1064 if ( preg_match( '|^[\s\t\/*#@]*' . preg_quote( $header_name, '|' ) . ':(.*)$|mi', $data, $match ) && $match[1] ){
1065 $theme_headers[$header_key]['name'] = $header_name;
1066 $theme_headers[$header_key]['value'] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
1067 }
1068 else{
1069 $theme_headers[$header_key]['name'] = $header_name;
1070 $theme_headers[$header_key]['value'] = '';
1071 }
1072 }
1073 $theme_headers['file']['name'] = 'file';
1074 $theme_headers['file']['value'] = trim(str_replace( WPFORO_THEME_DIR, '', $file), '/');
1075 return $theme_headers;
1076 }
1077
1078 public function copyright(){
1079 if( wpforo_feature('copyright', $this->wpforo) ): ?>
1080 <div id="wpforo-poweredby">
1081 <p class="wpf-by">
1082 <span onclick='javascript:document.getElementById("bywpforo").style.display = "inline";document.getElementById("awpforo").style.display = "none";' id="awpforo"> <img align="absmiddle" title="<?php esc_attr( wpforo_phrase('Powered by') ) ?> wpForo version <?php echo esc_html(WPFORO_VERSION) ?>" alt="Powered by wpForo" class="wpdimg" src="<?php echo WPFORO_URL ?>/wpf-assets/images/wpforo-info.png" alt="wpForo"> </span><a id="bywpforo" target="_blank" href="http://wpforo.com/">&nbsp;<?php wpforo_phrase('Powered by') ?> wpForo version <?php echo esc_html(WPFORO_VERSION) ?></a>
1083 </p>
1084 </div>
1085 <?php
1086 endif;
1087 }
1088
1089 public function member_menu( $userid, $menu = array() ){
1090 if( empty($menu) ) $menu = array('profile' => 'fa-user', 'account' => 'fa-cog', 'activity' => 'fa-comments-o', 'subscriptions' => 'fa-rss');
1091 $menu = apply_filters('wpforo_member_menu_filter', $menu);
1092 if( !($userid == $this->wpforo->current_userid || $this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'em' )) ) unset($menu['account']);
1093 foreach( $menu as $key => $value ) : ?>
1094 <a class="wpf-profile-menu <?php echo ( $this->wpforo->current_object['template'] == $key ? ' wpforo-active' : '' ) ?>" href="<?php echo esc_url($this->wpforo->member->get_profile_url($userid, $key)) ?>">
1095 <i style="font-size:14px; padding-right:3px;" class="fa <?php echo sanitize_html_class($value) ?>"></i> <?php wpforo_phrase($key) ?>
1096 </a>
1097 <?php
1098 endforeach;
1099 }
1100
1101 public function member_template(){
1102 global $wpforo;
1103 extract($this->wpforo->current_object, EXTR_OVERWRITE);
1104 extract($user, EXTR_OVERWRITE);
1105
1106 include( (isset($this->wpforo->member_tpls[$template]) && $this->wpforo->member_tpls[$template] ? $this->wpforo->member_tpls[$template] : $this->wpforo->member_tpls['profile']) );
1107 }
1108
1109 public function member_error(){
1110 echo apply_filters('wpforo_member_error_filter', wpforo_phrase('Members not found', FALSE));
1111 }
1112
1113 }
1114
1115 ?>