PluginProbe
wpForo Forum / 1.0.0
wpForo Forum v1.0.0
3.1.6 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 All 138 releases
wpforo / wpf-includes / class-template.php

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

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