PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
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 beta-4, at wpf-includes/class-template.php

1,070 lines 47.2 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 'close':
338 if( $this->wpforo->perm->forum_can($forumid, 'cot') ) {
339 $open_status = ( $this->wpforo->topic->is_closed($topicid) ? 'wpforo-open' : 'wpforo-close' );
340 $open_icon = ($open_status == 'wpforo-open') ? 'unlock' : 'lock';
341 $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>';
342 }
343 break;
344 case 'move':
345 if( $this->wpforo->perm->forum_can($forumid, 'mt') ) {
346 $button_html[] = '<span class="wpf-action wpforo-move"><i class="fa fa-share-square-o fa-0x"></i>' . wpforo_phrase('Move', false).'</span>';
347 }
348 break;
349 case 'edit':
350 $post = $this->wpforo->post->get_post($postid);
351 $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
352 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'] ) ) {
353 $a = ( $is_topic ) ? 'wpfedittopicpid' : '';
354 $b = ( $is_topic ) ? $postid : $postid;
355 $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>';
356 }
357 break;
358 case 'delete':
359 $post = $this->wpforo->post->get_post($postid);
360 $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
361 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']) ){
362 $a = ( $is_topic ) ? 'wpftopicdelete' : 'wpfreplydelete';
363 $b = ( $is_topic ) ? $topicid : $postid;
364 $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>';
365 }
366 break;
367 case 'link':
368 $url = ( $is_topic ) ? $this->wpforo->topic->get_topic_url( $topicid ) : $this->wpforo->post->get_post_url( $postid );
369 $button_html[] = '<a href="'. esc_url($url) .'"><i class="fa fa-link fa-0x"></i></a>';
370 break;
371 case 'positivevote':
372 if( $this->wpforo->perm->forum_can($forumid, 'v') ) {
373 $button_html[] = '<i itemtype="' . ( $is_topic ? 'topic' : 'reply' ) . '" id="wpfvote-up-'. intval($postid) .'" class="voteup fa fa-play fa-rotate-270 wpfcl-0"></i>';
374 }else{
375 $button_html[] = '<i class="not_reg_user fa fa-play fa-rotate-270 wpfcl-0"></i>';
376 }
377 break;
378 case 'negativevote':
379 if( $this->wpforo->perm->forum_can($forumid, 'v') ) {
380 $button_html[] = '<i itemtype="' . ( $is_topic ? 'topic' : 'reply' ) . '" id="wpfvote-down-'. intval($postid) .'" class="votedown fa fa-play fa-rotate-90 wpfcl-0"></i>';
381 }else{
382 $button_html[] = '<i class="not_reg_user fa fa-play fa-rotate-90 wpfcl-0"></i>';
383 }
384 break;
385 case 'isanswer':
386 $is_answer = $this->wpforo->post->is_answered( $postid );
387 $is_answer = ( $is_answer == 0 ) ? '-not' : '';
388 if( is_user_logged_in() ){
389 $button_html[] = '<div id="wpf-answer-'. intval($postid) .'" class="wpf-toggle'. esc_attr($is_answer) .'-answer"><i class="fa fa-check"></i></div>';
390 }else{
391 $button_html[] = '<div class="wpf-toggle'. esc_attr($is_answer) .'-answer not_reg_user"><i class="fa fa-check"></i></div>';
392 }
393 break;
394 } //switch
395 } //foreach
396
397 echo implode('', $button_html);
398
399 }
400
401 function breadcrumb($url_data){
402 extract($url_data, EXTR_OVERWRITE);
403
404 switch($template) :
405 case 'search': ?>
406
407 <div class="wpf-breadcrumb">
408 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i></a>
409
410 <a href="#" class="active"><?php wpforo_phrase('Search') ?></a>
411
412 <a href="#" class="wpf-end">&nbsp;</a>
413 </div>
414
415 <?php break;
416 case 'register': ?>
417
418 <div class="wpf-breadcrumb">
419 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i></a>
420
421 <a href="#" class="active"><?php wpforo_phrase('Register') ?></a>
422
423 <a href="#" class="wpf-end">&nbsp;</a>
424 </div>
425
426 <?php break;
427 case 'login': ?>
428
429 <div class="wpf-breadcrumb">
430 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i></a>
431
432 <a href="#" class="active"><?php wpforo_phrase('Login') ?></a>
433
434 <a href="#" class="wpf-end">&nbsp;</a>
435 </div>
436
437 <?php break;
438 case 'members': ?>
439
440 <div class="wpf-breadcrumb">
441 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i></a>
442
443 <?php if(isset($_GET['wpfms'])) : ?>
444
445 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
446 <a href="#" class="active"><?php wpforo_phrase('Search') ?></a>
447
448 <?php else : ?>
449
450 <a href="#" class="active"><?php wpforo_phrase('Members') ?></a>
451
452 <?php endif ?>
453
454 <a href="#" class="wpf-end">&nbsp;</a>
455 </div>
456
457 <?php break;
458 case 'profile': ?>
459
460 <div class="wpf-breadcrumb">
461 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i></a>
462
463 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
464 <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>
465
466 <a href="#" class="wpf-end">&nbsp;</a>
467 </div>
468
469 <?php break;
470 case 'account': ?>
471
472 <div class="wpf-breadcrumb">
473 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i>
474
475 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
476 <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>
477 <a href="#" class="active"><?php wpforo_phrase('Account') ?></a>
478
479 <a href="#" class="wpf-end">&nbsp;</a>
480 </div>
481
482 <?php break;
483 case 'activity': ?>
484
485 <div class="wpf-breadcrumb">
486 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i>
487
488 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
489 <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>
490 <a href="#" class="active"><?php wpforo_phrase('Activity') ?></a>
491
492 <a href="#" class="wpf-end">&nbsp;</a>
493 </div>
494
495 <?php break;
496 case 'subscriptions': ?>
497
498 <div class="wpf-breadcrumb">
499 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i>
500
501 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
502 <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>
503 <a href="#" class="active"><?php wpforo_phrase('Subscriptions') ?></a>
504
505 <a href="#" class="wpf-end">&nbsp;</a>
506 </div>
507
508 <?php break;
509 // TODO: move code to pm plugin
510 case 'messages': ?>
511
512 <div class="wpf-breadcrumb">
513 <a href="<?php echo WPFORO_BASE_URL ?>" class="wpf-root" title="<?php wpforo_phrase('Forums') ?>"><i class="fa fa-home"></i>
514
515 <a href="<?php echo WPFORO_BASE_URL ?>members/"><?php wpforo_phrase('Members') ?></a>
516
517 <?php if(!empty($user)) : ?>
518
519 <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>
520
521 <?php endif ?>
522
523 <a href="#" class="active"><?php wpforo_phrase('Messages') ?></a>
524
525 <a href="#" class="wpf-end">&nbsp;</a>
526 </div>
527
528 <?php break;
529 case 'topic': ?>
530
531 <div class="wpf-breadcrumb">
532 <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>
533
534 <?php if(isset($forumid)) : ?>
535 <?php $relative_ids = array();
536 $this->wpforo->forum->get_all_relative_ids($forumid, $relative_ids);
537 foreach( $relative_ids as $key => $rel_forumid ) : ?>
538 <?php $forum = $this->wpforo->forum->get_forum($rel_forumid) ?>
539 <?php if( $key != ( count($relative_ids) - 1 ) ) : ?>
540
541 <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>
542
543 <?php else : ?>
544
545 <a href="#" class="active" title="<?php echo esc_html($forum['title']) ?>"><?php wpforo_text($forum['title'], 19) ?></a>
546
547 <?php endif ?>
548 <?php endforeach ?>
549 <?php endif ?>
550
551 <a href="#" class="wpf-end">&nbsp;</a>
552 </div>
553
554 <?php break;
555 case 'post': ?>
556
557 <div class="wpf-breadcrumb">
558 <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>
559
560 <?php if(isset($forumid)) : ?>
561 <?php $relative_ids = array();
562 $this->wpforo->forum->get_all_relative_ids($forumid, $relative_ids);
563 foreach( $relative_ids as $key => $rel_forumid ) : ?>
564 <?php $forum = $this->wpforo->forum->get_forum($rel_forumid) ?>
565
566 <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>
567
568 <?php endforeach ?>
569 <?php endif ?>
570 <?php if(isset($topicid)) : ?>
571 <?php $topic = $this->wpforo->topic->get_topic($topicid) ?>
572
573 <a href="#" class="active" title="<?php echo esc_html($forum['title']) ?>"><?php wpforo_text($topic['title'], 19) ?></a>
574
575 <?php endif ?>
576 <a href="#" class="wpf-end">&nbsp;</a>
577 </div>
578
579 <?php break;
580 default: ?>
581
582 <div class="wpf-breadcrumb">
583 <a href="#" class="wpf-root active"><?php wpforo_phrase('Forums') ?></a>
584 <a href="#" class="wpf-end">&nbsp;</a>
585 </div>
586
587 <?php
588 endswitch;
589
590 }
591
592 function icon($type, $item = array(), $echo = true ){
593
594 $icon = array();
595 $status = false;
596 if(isset($item['type'])){
597
598 if( $item['closed'] && $item['type'] == 1 ){
599 $icon['class'] = 'fa-lock';
600 $icon['color'] = 'wpfcl-1';
601 if($echo) { $status = true; echo implode(' ', $icon); } else{ return implode(' ', $icon); }
602 }
603 elseif( $item['closed'] && $item['type'] != 1 ){
604 $icon['class'] = 'fa-lock';
605 $icon['color'] = 'wpfcl-1';
606 if($echo) { $status = true; echo implode(' ', $icon); } else{ return implode(' ', $icon); }
607 }
608 elseif( !$item['closed'] && $item['type'] == 1 ){
609 $icon['class'] = 'fa-thumb-tack';
610 $icon['color'] = 'wpfcl-5';
611 if($echo) { $status = true; echo implode(' ', $icon); } else{ return implode(' ', $icon); }
612 }
613
614 if( $status ){
615 //do nothing
616 }
617 else{
618 if( $type == 'forum' ){
619 $icon['class'] = 'fa-comments';
620 $icon['color'] = 'wpfcl-2';
621 }
622 elseif( $type == 'topic' ){
623 if( $item['posts'] == 1 ){
624 $icon['class'] = 'fa-file-text-o';
625 $icon['color'] = 'wpfcl-2';
626 }
627 elseif( $item['posts'] > 1 && $item['posts'] <= 5 ){
628 $icon['class'] = 'fa-file-text';
629 $icon['color'] = 'wpfcl-2';
630 }
631 elseif( $item['posts'] > 5 && $item['posts'] <= 20 ){
632 $icon['class'] = 'fa-file-text';
633 $icon['color'] = 'wpfcl-5';
634 }
635 elseif( $item['posts'] > 20 && $item['posts'] <= 100 ){
636 $icon['class'] = 'fa-file-text';
637 $icon['color'] = 'wpfcl-5';
638 }
639 elseif( $item['posts'] > 100 ){
640 $icon['class'] = 'fa-file-text';
641 $icon['color'] = 'wpfcl-5';
642 }
643 else{
644 $icon['class'] = 'fa-file-o';
645 $icon['color'] = 'wpfcl-2';
646 }
647 }
648 if($echo) { echo implode(' ', $icon); } else{ return implode(' ', $icon); }
649 }
650
651 }
652 else{
653 return false;
654 }
655
656 }
657
658 public function init_member_templates(){
659 $this->wpforo->member_tpls = array(
660 'account' => wpftpl('profile-account.php'),
661 'activity' => wpftpl('profile-activity.php'),
662 'subscriptions' => wpftpl('profile-subscriptions.php')
663 );
664 $this->wpforo->member_tpls = apply_filters('wpforo_member_templates_filter', $this->wpforo->member_tpls);
665 $this->wpforo->member_tpls['profile'] = wpftpl('profile-home.php');
666 }
667
668 function has_menu(){
669 return has_nav_menu( 'wpforo-menu' );
670 }
671
672 function nav_menu(){
673 if ( has_nav_menu( 'wpforo-menu' ) ){
674 $defaults = array(
675 'theme_location' => 'wpforo-menu',
676 'menu' => '',
677 'container' => '',
678 'container_class' => '',
679 'container_id' => '',
680 'menu_class' => 'wpf-menu',
681 'menu_id' => 'wpf-menu',
682 'echo' => true,
683 'fallback_cb' => 'wp_page_menu',
684 'before' => '',
685 'after' => '',
686 'link_before' => '',
687 'link_after' => '',
688 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
689 'depth' => 0,
690 'walker' => ''
691 );
692 wp_nav_menu( $defaults );
693 }
694 }
695
696 function init_nav_menu(){
697
698 if(isset($this->wpforo->current_object) && !empty($this->wpforo->current_object)){
699
700 extract($this->wpforo->current_object, EXTR_OVERWRITE);
701
702 $this->wpforo->menu['wpforo-home'] = array(
703 'href' => WPFORO_BASE_URL,
704 'label' => wpforo_phrase('forums', FALSE),
705 'attr' => ((($template == 'forum' || $template == 'topic' || $template == 'post') && !isset($_GET['wpforo'])) ? ' class="wpforo-active"' : '' ),
706 'submenues' => array()
707 );
708 $this->wpforo->menu['wpforo-members'] = array(
709 'href' => WPFORO_BASE_URL . 'members/',
710 'label' => wpforo_phrase('members', FALSE),
711 'attr' => ( $template == 'members' ? ' class="wpforo-active"' : '' ),
712 'submenues' => array()
713 );
714
715 if( is_user_logged_in() ){
716
717 $this->wpforo->menu['wpforo-profile-home'] = array(
718 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid),
719 'label' => wpforo_phrase('my profile', FALSE),
720 'attr' => ( isset($this->wpforo->member_tpls[$template]) && $this->wpforo->member_tpls[$template] ? ' class="wpforo-active"' : '' ),
721 'submenues' => array()
722 );
723 $this->wpforo->menu['wpforo-profile-account'] = array(
724 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid, 'account'),
725 'label' => wpforo_phrase('account', FALSE),
726 'attr' => ( $template == 'account' ? ' class="wpforo-active"' : '' ),
727 'submenues' => array()
728 );
729 $this->wpforo->menu['wpforo-profile-activity'] = array(
730 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid, 'activity'),
731 'label' => wpforo_phrase('activity', FALSE),
732 'attr' => ( $template == 'activity' ? ' class="wpforo-active"' : '' ),
733 'submenues' => array()
734 );
735 $this->wpforo->menu['wpforo-profile-subscriptions'] = array(
736 'href' => $this->wpforo->member->get_profile_url($this->wpforo->current_userid, 'subscriptions'),
737 'label' => wpforo_phrase('subscriptions', FALSE),
738 'attr' => ( $template == 'subscriptions' ? ' class="wpforo-active"' : '' ),
739 'submenues' => array()
740 );
741 $this->wpforo->menu['wpforo-logout'] = array(
742 'href' => WPFORO_BASE_URL . '?wpforo=logout',
743 'label' => wpforo_phrase('logout', FALSE),
744 'attr' => '',
745 'submenues' => array()
746 );
747
748 }else{
749
750 $this->wpforo->menu['wpforo-register'] = array(
751 'href' => wpforo_register_url(),
752 'label' => wpforo_phrase('register', FALSE),
753 'attr' => ( isset($_GET['wpforo']) && $_GET['wpforo'] == 'register' ? ' class="wpforo-active"' : '' ),
754 'submenues' => array()
755 );
756 $this->wpforo->menu['wpforo-login'] = array(
757 'href' => wpforo_login_url(),
758 'label' => wpforo_phrase('login', FALSE),
759 'attr' => ( isset($_GET['wpforo']) && $_GET['wpforo'] == 'login' ? ' class="wpforo-active"' : '' ),
760 'submenues' => array()
761 );
762 }
763
764 $this->wpforo->menu = apply_filters('wpforo_menu_array_filter', $this->wpforo->menu);
765 }
766 }
767
768 /**
769 *
770 * Checks in current active theme options if certain layout exists.
771 *
772 * @since 1.0.0
773 *
774 * @param mixed $identifier Layout id (folder name) OR @layout variable in header ( 1 or Extended )
775 * @param string $identifier_type The type of first parameter 'id' OR 'name' (@layout)
776 *
777 * @return boolean true/false
778 *
779 **/
780 function layout_exists( $identifier, $identifier_type = 'id' ){
781
782 $layouts = $this->wpforo->theme_options['layouts'];
783
784 if( $identifier_type == 'id' ){
785 if( isset($layouts[$identifier]) && !empty($layouts[$identifier])){
786 return true;
787 }
788 else{
789 return false;
790 }
791 }
792 elseif( $identifier_type = 'name' ){
793 foreach( $layouts as $id => $layout ){
794 if( !isset($layout['name']) && $layout['name'] == $identifier ){
795 return true;
796 }
797 }
798 return false;
799 }
800 }
801
802 /**
803 *
804 * Finds and returns all layouts information in array from theme's /layouts/ folder
805 *
806 * @since 1.0.0
807 *
808 * @param string $theme Theme id ( folder name ) e.g. 'classic'
809 *
810 * @return array
811 *
812 **/
813 function find_layouts( $theme ){
814 $layout_data = array();
815 $layouts = $this->find_themes('/'.$theme.'/layouts', 'php', 'layout');
816 if(!empty($layouts)){
817 foreach( $layouts as $layout ){
818 $lid = trim(basename(dirname( $layout['file']['value'] )), '/');
819 $layout_data[$lid]['id'] = $lid;
820 $layout_data[$lid]['name'] = $layout['name']['value'];
821 $layout_data[$lid]['version'] = $layout['version']['value'];
822 $layout_data[$lid]['description'] = $layout['description']['value'];
823 $layout_data[$lid]['author'] = $layout['author']['value'];
824 $layout_data[$lid]['url'] = $layout['layout_url']['value'];
825 $layout_data[$lid]['file'] = $layout['file']['value'];
826 }
827 }
828 return $layout_data;
829 }
830
831 function show_layout_selectbox($layoutid = 0){
832 $layouts = $this->find_layouts( WPFORO_THEME );
833 if( !empty($layouts) ){
834 foreach( $layouts as $layout ) : ?>
835 <option value="<?php echo esc_attr(trim($layout['id'])) ?>" <?php echo ( $layoutid == $layout['id'] ? 'selected' : '' ); ?> ><?php echo esc_html($layout['name']) ?></option>
836 <?php
837 endforeach;
838 }
839 }
840
841 /**
842 *
843 * Finds and returns styles array from theme's /styles/colors.php file
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_styles( $theme ){
853 $colors = array();
854 $color_file = WPFORO_THEME_DIR . '/' . $theme . '/styles/colors.php';
855 if( file_exists($color_file) ){
856 include( $color_file );
857 }
858 return $colors;
859 }
860
861 /**
862 *
863 * Scans certain theme directory and returns all information in array ( theme header, layouts, styles ).
864 *
865 * @since 1.0.0
866 *
867 * @param string $theme_file Theme folder name or main css file base path ( 'classic' OR classic/style.css' )
868 *
869 * @return array
870 *
871 **/
872 function find_theme( $theme_file ){
873 $theme = array();
874 $theme_file = trim(trim($theme_file, '/'));
875
876 if( preg_match('|\.[\w\d]{2,4}$|is', $theme_file) ){
877 $theme_folder = trim(basename(dirname($theme_file)), '/');
878 }
879 else{
880 $theme_folder = $theme_file;
881 $theme_file = $theme_file . '/style.css';
882 }
883
884 if( !is_readable( WPFORO_THEME_DIR . '/' . $theme_file ) ){
885 return $theme['error'] = __('Theme file not readable', 'wpforo') .' ('.$theme_file.')';
886 }
887 else{
888 $theme_data = $this->find_theme_headers( WPFORO_THEME_DIR . '/' . $theme_file );
889 $theme['id'] = $theme_folder;
890 $theme['name'] = $theme_data['name']['value'];
891 $theme['version'] = $theme_data['version']['value'];
892 $theme['description'] = $theme_data['description']['value'];
893 $theme['author'] = $theme_data['author']['value'];
894 $theme['url'] = $theme_data['theme_url']['value'];
895 $theme['file'] = $theme_file;
896 $theme['folder'] = $theme_folder;
897 $theme['layouts'] = $this->find_layouts( $theme_folder );
898 $styles = $this->find_styles( $theme_folder );
899 if(!empty($styles)){
900 reset($styles);
901 $theme['style'] = key($styles);
902 $theme['styles'] = $styles;
903 }
904 return $theme;
905 }
906
907 }
908
909 /**
910 *
911 * Scans wpForo themes (wpf-themes) folder, reads main files' headers and returns information about all themes in array.
912 * This function can also be used to scan and get information about layouts in each theme /layouts/ folder.
913 *
914 * @since 1.0.0
915 *
916 * @param string $base_dir Absolute path to scan directory (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/)
917 * @param string $ext File extension which may contain header information
918 * @param string $mode 'theme' or 'layout'
919 *
920 * @return array
921 *
922 **/
923 function find_themes( $base_dir = '', $ext = 'css', $mode = 'theme' ){
924 $themes = array ();
925 $themes_dir = @opendir( WPFORO_THEME_DIR . $base_dir );
926 $theme_files = array();
927 if( $themes_dir ){
928 while( ($file = readdir( $themes_dir )) !== false ){
929 if( substr($file, 0, 1) == '.' ) continue;
930 if( is_dir( WPFORO_THEME_DIR . $base_dir .'/'.$file ) ){
931 $themes_subdir = @opendir( WPFORO_THEME_DIR . $base_dir .'/'.$file );
932 if( $themes_subdir ){
933 while(($subfile = readdir( $themes_subdir ) ) !== false ){
934 if( substr($subfile, 0, 1) == '.' ) continue;
935 if( substr($subfile, -4) == '.' . $ext ) $theme_files[] = "$file/$subfile";
936 }
937 closedir( $themes_subdir );
938 }
939 }
940 else{
941 if( substr($file, -4) == '.' . $ext ) $theme_files[] = $file;
942 }
943 }
944 closedir( $themes_dir );
945 }
946 if( empty($theme_files) ) return $themes;
947 foreach( $theme_files as $theme_file ){
948 if( !is_readable( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file ) ) continue;
949 if( $mode == 'theme' ){
950 $theme_data = $this->find_theme_headers( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file );
951 }
952 elseif( $mode == 'layout' ){
953 $theme_data = $this->find_layout_headers( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file );
954 }
955 if( empty($theme_data['name']['value']) ) continue;
956 $themes[wpforo_clear_basename($theme_file)] = $theme_data;
957 }
958 return $themes;
959 }
960
961 /**
962 *
963 * Reads theme main file's header variables and returns information in array.
964 *
965 * @since 1.0.0
966 *
967 * @param string $file Absolute path to file (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/style.css)
968 *
969 * @return array
970 *
971 **/
972 function find_theme_headers( $file ){
973 $theme_headers = array();
974 $headers = array(
975 'name' => 'Theme Name',
976 'version' => 'Version',
977 'description' => 'Description',
978 'author' => 'Author',
979 'theme_url' => 'Theme URI',
980 );
981 $fp = fopen( $file, 'r' );
982 $data = fread( $fp, 8192 );
983 fclose( $fp );
984 $data = str_replace( "\r", "\n", $data );
985 foreach ( $headers as $header_key => $header_name ){
986 if ( preg_match( '|^[\s\t\/*#@]*' . preg_quote( $header_name, '|' ) . ':(.*)$|mi', $data, $match ) && $match[1] ){
987 $theme_headers[$header_key]['name'] = $header_name;
988 $theme_headers[$header_key]['value'] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
989 }
990 else{
991 $theme_headers[$header_key]['name'] = $header_name;
992 $theme_headers[$header_key]['value'] = '';
993 }
994 }
995 $theme_headers['file']['name'] = 'file';
996 $theme_headers['file']['value'] = $file;
997 return $theme_headers;
998 }
999
1000 /**
1001 *
1002 * Reads layout 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/layouts/1/forum.php)
1007 *
1008 * @return array
1009 *
1010 **/
1011 function find_layout_headers( $file ){
1012 $theme_headers = array();
1013 $headers = array(
1014 'name' => 'layout',
1015 'version' => 'version',
1016 'description' => 'description',
1017 'author' => 'author',
1018 'layout_url' => 'url',
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'] = trim(str_replace( WPFORO_THEME_DIR, '', $file), '/');
1036 return $theme_headers;
1037 }
1038
1039 public function copyright(){ ?>
1040 <span onclick='javascript:document.getElementById("bywpforo").style.display = "inline";document.getElementById("awpforo").style.display = "none";' id="awpforo"> <img align="absmiddle" 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($this->wpforo->version) ?></a>
1041 <?php
1042 }
1043
1044 public function member_menu( $userid, $menu = array() ){
1045 if( empty($menu) ) $menu = array('profile' => 'fa-user', 'account' => 'fa-cog', 'activity' => 'fa-comments-o', 'subscriptions' => 'fa-rss');
1046 $menu = apply_filters('wpforo_member_menu_filter', $menu);
1047 if( !($userid == $this->wpforo->current_userid || $this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'em' )) ) unset($menu['account']);
1048 foreach( $menu as $key => $value ) : ?>
1049 <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)) ?>">
1050 <i style="font-size:14px; padding-right:3px;" class="fa <?php echo sanitize_html_class($value) ?>"></i> <?php wpforo_phrase($key) ?>
1051 </a>
1052 <?php
1053 endforeach;
1054 }
1055
1056 public function member_template(){
1057 global $wpforo;
1058 extract($this->wpforo->current_object, EXTR_OVERWRITE);
1059 extract($user, EXTR_OVERWRITE);
1060
1061 include( (isset($this->wpforo->member_tpls[$template]) && $this->wpforo->member_tpls[$template] ? $this->wpforo->member_tpls[$template] : $this->wpforo->member_tpls['profile']) );
1062 }
1063
1064 public function member_error(){
1065 echo apply_filters('wpforo_member_error_filter', wpforo_phrase('Members not found', FALSE));
1066 }
1067
1068 }
1069
1070 ?>