init_defaults();
$this->init_options();
add_action('after_setup_theme', array($this, 'init_templates'));
}
public function init(){
$this->init_hooks();
$this->init_member_paths();
$this->init_member_tpls();
$this->init_nav_menu();
}
private function init_hooks(){
if( is_wpforo_page() ){
add_filter("mce_external_plugins", array($this, 'add_mce_external_plugins' ), 15);
add_filter("tiny_mce_plugins", array($this, 'filter_tinymce_plugins'), 15);
add_filter("wp_mce_translation", array($this, 'add_tinymce_translations'));
add_filter("wpforo_editor_settings", array($this, 'editor_settings_required_params'), 999);
add_action('wpforo_topic_form_extra_fields_after', array($this, 'add_default_attach_input'));
add_action('wpforo_reply_form_extra_fields_after', array($this, 'add_default_attach_input'), 10, 1);
add_action('wpforo_portable_form_extra_fields_after', array($this, 'add_default_attach_input'));
add_action('wpforo_register_form_end', function(){
echo '';
});
add_action('wpforo_login_form_end', function(){
echo '';
});
add_action('wpforo_profile_account_bottom', function(){
echo '';
});
add_filter('is_wpforo_attach_page_templates', function($templates){ $templates[] = 'add-topic'; return $templates; });
add_filter('wpforo_emoticons_loading_template', function($templates){ $templates[] = 'add-topic'; return $templates; });
add_filter( 'wpforo_content_after', array( $this, 'do_spoilers' ) );
add_action('wp_footer', array($this, 'add_footer_html'), 999999);
//ajax actions hooks
add_action('wp_ajax_wpforo_active_tab_content_ajax', array($this, 'ajx_active_tab_content'));
}
}
private function init_defaults() {
$this->default = new stdClass;
$this->default->slugs = array(
'paged' => 'paged',
'recent' => 'recent',
'tags' => 'tags',
'members' => 'members',
'postid' => 'postid'
);
$this->default->style = array(
'font_size_forum' => 17,
'font_size_topic' => 16,
'font_size_post_content' => 14,
'custom_css' => "#wpforo-wrap {\r\n font-size: 13px; width: 100%; padding:10px 0; margin:0px;\r\n}\r\n"
);
$this->default->forms = array(
'qa_comments_rich_editor' => 0,
'threaded_reply_rich_editor' => 1,
'qa_display_answer_editor' => 1
);
$this->default->editor_settings = array(
'media_buttons' => false,
'textarea_name' => '',
'textarea_rows' => 15,
'tabindex' => '',
'editor_height' => 130,
'editor_css' => '',
'editor_class' => '',
'teeny' => false,
'dfw' => false,
'plugins' => 'hr,lists,textcolor,paste,wpautoresize,fullscreen',
'external_plugins' => array(
'wpforo_pre_button' => WPFORO_URL . '/wpf-assets/js/tinymce-pre.js',
'wpforo_link_button' => WPFORO_URL . '/wpf-assets/js/tinymce-link.js',
'wpforo_spoiler_button' => WPFORO_URL . '/wpf-assets/js/tinymce-spoiler.js',
'wpforo_source_code_button' => WPFORO_URL . '/wpf-assets/js/tinymce-code.js',
'emoticons' => WPFORO_URL . '/wpf-assets/js/tinymce-emoji.js'
),
'tinymce' => array(
'toolbar1' => 'fontsizeselect,bold,italic,underline,strikethrough,forecolor,bullist,numlist,hr,alignleft,aligncenter,alignright,alignjustify,link,unlink,blockquote,pre,wpf_spoil,undo,redo,pastetext,source_code,emoticons,fullscreen',
'toolbar2' => '',
'toolbar3' => '',
'toolbar4' => '',
'content_style' => 'blockquote{border: #cccccc 1px dotted; background: #F7F7F7; padding:10px;font-size:12px; font-style:italic; margin: 20px 10px;}',
'object_resizing' => false,
'autoresize_on_init' => true,
'wp_autoresize_on' => true,
'wp_keep_scroll_position' => true,
'indent' => true,
'add_unload_trigger' => false,
'wpautop' => false,
'setup' => 'wpforo_tinymce_setup',
'content_css' => '',
'extended_valid_elements' => 'i[class|style],span[class|style]',
'custom_elements' => ''
),
'quicktags' => false,
'default_editor' => 'tinymce'
);
$this->default->template = array(
'type' => 'html',
'key' => '',
'menu_shortcode' => '',
'callback_for_can_view_menu' => '',
'ico' => '',
'title' => '',
'callback_for_page' => '',
'callback_for_get_url' => '',
'value' => '',
'status' => 1,
'is_default' => 0,
'callback_for_can' => '',
'can' => '',
'add_in_member_buttons' => 0
);
$this->default->templates = array(
'add-topic' => array(
'type' => 'callback',
'key' => 'add-topic',
'title' => 'Add New Topic',
'is_default' => 1,
'callback_for_page' => function () {
echo '
';
printf('
%1$s
', wpforo_phrase('Add New Topic', false));
$forumid = (int) wpfval( WPF()->current_object['qvars'], 0 );
$this->portable_topic_form($forumid);
echo '';
},
'can' => 'vt_add_topic'
),
'recent' => array(
'type' => 'html',
'key' => 'recent',
'title' => 'Recent Posts',
'is_default' => 1
),
'tags' => array(
'type' => 'html',
'key' => 'tags',
'title' => 'Tags',
'is_default' => 1
),
'members' => array(
'type' => 'html',
'key' => 'members',
'title' => 'Members',
'is_default' => 1,
'can' => 'vmem'
),
'member' => array(
'tabs' => array(
'profile' => array(
'type' => 'callback',
'key' => 'profile',
'menu_shortcode' => 'wpforo-profile-home',
'ico' => '',
'title' => 'Profile',
'is_default' => 1,
'can' => 'vprf',
'add_in_member_buttons' => 1
),
'account' => array(
'type' => 'callback',
'key' => 'account',
'menu_shortcode' => 'wpforo-profile-account',
'ico' => '',
'title' => 'Account',
'is_default' => 1,
'can' => 'em',
'add_in_member_buttons' => 1
),
'activity' => array(
'type' => 'callback',
'key' => 'activity',
'menu_shortcode' => 'wpforo-profile-activity',
'ico' => '',
'title' => 'Activity',
'is_default' => 1,
'can' => 'vpra',
'add_in_member_buttons' => 1
),
'subscriptions' => array(
'type' => 'callback',
'key' => 'subscriptions',
'menu_shortcode' => 'wpforo-profile-subscriptions',
'ico' => '',
'title' => 'Subscriptions',
'is_default' => 1,
'can' => 'vprs',
'add_in_member_buttons' => 1
),
)
)
);
$theme = get_option( 'wpforo_theme_options' );
if ( empty( $theme ) ) {
$theme = $this->find_theme( 'classic' );
}
$this->default->options = $theme;
}
/**
* initialize templates
*/
public function init_templates(){
$this->templates = (array) apply_filters('wpforo_init_templates', $this->default->templates);
if( $templates = $this->get_templates_list(false) ){
foreach ($templates as $template){
$this->default->slugs[$template] = $template;
}
}
$this->default->slugs = (array) apply_filters('wpforo_init_template_slugs', $this->default->slugs);
$this->slugs = (array) get_wpf_option('wpforo_tpl_slugs', $this->default->slugs);
$this->slugs = array_map('wpforo_fix_url', $this->slugs);
}
/**
* initialize templates paths
*/
private function init_paths(){
if( !$this->paths && $this->theme && function_exists('wpftpl') ){
$this->paths = array(
'404' => wpftpl( '404.php' ),
'search' => wpftpl( 'search.php' ),
'recent' => wpftpl( 'recent.php' ),
'tags' => wpftpl( 'tags.php' ),
'register' => wpftpl( 'register.php' ),
'login' => wpftpl( 'login.php' ),
'members' => wpftpl( 'members.php' ),
'profile' => wpftpl( 'profile.php' ),
'account' => wpftpl( 'profile.php' ),
'activity' => wpftpl( 'profile.php' ),
'subscriptions' => wpftpl( 'profile.php' ),
'forum' => wpftpl( 'forum.php' ),
'topic' => wpftpl( 'topic.php' ),
'post' => wpftpl( 'post.php' )
);
$this->paths = apply_filters('wpforo_init_template_paths', $this->paths);
}
}
/**
* initialize member templates paths
*/
private function init_member_paths(){
if( !$this->member_paths && $this->theme && function_exists('wpftpl') ){
$this->member_paths = array(
'account' => wpftpl( 'profile-account.php' ),
'activity' => wpftpl( 'profile-activity.php' ),
'subscriptions' => wpftpl( 'profile-subscriptions.php' )
);
$this->member_paths = apply_filters('wpforo_member_templates_filter', $this->member_paths);
$this->member_paths['profile'] = wpftpl('profile-home.php');
}
}
/**
* initialize member template old properties
*/
public function init_member_tpls(){
if( !WPF()->member_tpls ){
$this->init_member_paths();
WPF()->member_tpls = array();
foreach ( $this->get_member_templates_list() as $v ) WPF()->member_tpls[$v] = $v;
$paths = $this->member_paths;
unset($paths['profile'], $paths['account'], $paths['activity'], $paths['subscriptions']);
WPF()->member_tpls = array_merge(WPF()->member_tpls, $paths);
}
}
/**
* @param array|string $template
*
* @return array
*/
private function fix_template($template){
if( is_string($template) ){
$t = $this->default->template;
$t['key'] = $template;
$t['menu_shortcode'] = $template;
$t['title'] = ucfirst( $template );
return $t;
}else{
$template = wpforo_settype($template, 'array');
if( is_array($template) ) {
unset($template['tabs']);
$template = array_merge( $this->default->template, $template );
if( !$template['ico'] = trim($template['ico']) ) $template['ico'] = '';
return $template;
}
}
return $this->default->template;
}
/**
* @param array $template
*
* @return bool
*/
private function is_template(&$template){
$key = wpfval($template, 'key');
if( wpfval($template, 'type') && $key && is_string($key) ){
$template = $this->fix_template($template);
return true;
}
return false;
}
/**
* @param array|string $template
* @param array $member
* @param bool $default
*
* @return bool
*/
public function can_view_template($template, $member = array(), $default = false){
if( $template = $this->get_template($template) ){
if( (int) $template['status'] ){
if( !is_callable($template['callback_for_can']) ){
if( $template['can'] ){
$userid = wpforo_bigintval( wpfval($member, 'userid') );
if( $userid && $userid === WPF()->current_userid && wpforo_is_member_template($template) ){
return true;
}else{
return (bool) WPF()->perm->usergroup_can($template['can']);
}
}else{
return true;
}
}else{
return (bool) call_user_func($template['callback_for_can'], $template, $member, $default);
}
}
}
return $default;
}
/**
* @param array|string $template
*
* @return string
*/
public function get_key($template = null){
if( !$template ) $template = WPF()->current_object['template'];
return is_string($template) ? $template : (string) wpfval($template, 'key');
}
/**
* @param array|string $template
*
* @return string
*/
private function get_menu_shortcode($template){
$menu_shortcode = '';
if($template = $this->get_template($template)){
$menu_shortcode = sanitize_title( trim($template['menu_shortcode'], '%/') );
if( !$menu_shortcode ) $menu_shortcode = $template['key'];
if( strpos($menu_shortcode, 'wpforo-') !== 0 ) $menu_shortcode = 'wpforo-' . $menu_shortcode;
}
return $menu_shortcode;
}
/**
* @param array|string $template
* @param array $args
* @param string $default
*
* @return string
*/
private function get_url($template, $args = array(), $default = ''){
$return = $default ? $default : '#';
if($template = $this->get_template($template)){
if( is_callable($template['callback_for_get_url']) ){
$return = call_user_func($template['callback_for_get_url'], $template, $args, $default);
}elseif( wpfval($args, 'ID') && wpfval($args, 'user_nicename') && wpforo_is_member_template($template) ){
$return = WPF()->member->profile_url($args, $template['key']);
}elseif( !$default && $slug = wpforo_get_template_slug($template['key']) ){
$return = wpforo_home_url($slug);
}
}
return $return;
}
/**
* @param array|string $template
*
* @return string
*/
public function get_template_path($template){
$this->init_paths();
$path = (string) wpfval($this->paths, $this->get_key($template));
return apply_filters('wpforo_get_template_path', $path, $template);
}
/**
* @param array|string $template
*
* @return string
*/
public function get_member_template_path($template){
$this->init_member_paths();
$path = wpfval($this->member_paths, $this->get_key($template));
return apply_filters('wpforo_get_member_template_path', $path, $template);
}
/**
* @param bool $only_enableds
* @param bool $only_defaults
* @param array $__templates
*
* @return array
*/
public function get_templates($only_enableds = true, $only_defaults = false, $__templates = array()){
$templates = array();
if( !$__templates ) $__templates = $this->templates;
foreach($__templates as $key => $template){
if( $this->is_template($template) ){
if( $only_enableds ){
if( $template['status'] ){
if( $only_defaults ){
if( $template['is_default'] ) $templates[$key] = $template;
}else{
$templates[$key] = $template;
}
}
}else{
if( $only_defaults ){
if( $template['is_default'] ) $templates[$key] = $template;
}else{
$templates[$key] = $template;
}
}
}
if( is_array(wpfval($template, 'tabs')) ){
foreach ($template['tabs'] as $tkey => $tab){
if( $this->is_template($tab) ){
if( $only_enableds ){
if( $tab['status'] ){
if( $only_defaults ){
if( $tab['is_default'] ) $templates[$tkey] = $tab;
}else{
$templates[$tkey] = $tab;
}
}
}else{
if( $only_defaults ){
if( $tab['is_default'] ) $templates[$tkey] = $tab;
}else{
$templates[$tkey] = $tab;
}
}
}
}
}
}
return $templates;
}
/**
* @param bool $only_enableds
* @param bool $only_defaults
*
* @return array
*/
public function get_member_templates($only_enableds = true, $only_defaults = false){
return $this->get_templates($only_enableds, $only_defaults, array('member' => (array) wpfval($this->templates, 'member')));
}
/**
* @param bool $only_enableds
* @param bool $only_defaults
*
* @return array
*/
public function get_templates_list($only_enableds = true, $only_defaults = false){
return array_keys($this->get_templates($only_enableds, $only_defaults));
}
/**
* @param bool $only_enableds
* @param bool $only_defaults
*
* @return array
*/
public function get_member_templates_list($only_enableds = true, $only_defaults = false){
return array_keys($this->get_member_templates($only_enableds, $only_defaults));
}
/**
* @param array|string $template
*
* @return array
*/
public function get_template($template = null){
$return = array();
if( !$template ) $template = WPF()->current_object['template'];
if( is_string($template) ){
$templates = $this->get_templates();
if( $t = (array) wpfval($templates, $template) ){
$return = $t;
}else{
$return = $this->fix_template($template);
}
}elseif( is_array($template) ){
$return = $this->fix_template($template);
}
return ($this->is_template($return) ? $return : array());
}
/**
* show given template
*
* @param array|string $template
*/
public function show_template($template = null){
if( $template = $this->get_template($template) ){
if( $template['type'] === 'callback' && is_callable($template['callback_for_page']) ){ ?>
show_msg(wpforo_phrase('Your template has not found', false));
}
}
public function __old_member_menu(){
$menu = array();
$userid = WPF()->current_object['userid'];
if( $menu = apply_filters('wpforo_member_menu_filter', $menu, $userid) ){
foreach( $menu as $key => $value ) :
?>
get_member_templates() ){
foreach ($templates as $key => $template){
if( $this->can_view_template($template, WPF()->current_object['user']) ){
printf(
'',
WPF()->current_object['template'] === $key ? 'wpforo-active' : '',
esc_url( $this->get_url($template, WPF()->current_object['user'], WPF()->member->profile_url(WPF()->current_object['user'], $key)) ),
$template['ico'],
wpforo_phrase($template['title'], false)
);
}
}
}
/** to call old_member_menu for other custom plugins who use our old hooks */
$this->__old_member_menu();
}
public function member_buttons( $member ){
if( wpforo_bigintval(wpfval($member, 'userid')) && WPF()->perm->usergroup_can('vprf') ){
if( $templates = $this->get_member_templates() ){
foreach ( $templates as $key => $template ){
if( $template['add_in_member_buttons'] && $this->can_view_template($template, $member) ){
printf('%3$s',
wpforo_phrase($template['title'], false),
esc_url($this->get_url($template, $member, WPF()->member->profile_url($member, $template['key']))),
$template['ico']
);
}
}
}
do_action( 'wpforo_member_info_buttons', $member );
}
}
public function member_template($template = null){
if( $template = $this->get_template($template) ){
if( $this->can_view_template($template, WPF()->current_object['user']) ){
if( $path = $this->get_member_template_path($template) ){
/** -START- to be removed in next versions */
extract(WPF()->current_object, EXTR_OVERWRITE);
extract(WPF()->current_object['user'], EXTR_OVERWRITE);
/** -END- to be removed in next versions */
include($path);
}else{
$this->show_template($template);
}
}else{
$this->show_msg( wpforo_phrase('You do not have permission to view this page', false) );
}
}else{
$this->show_msg( wpforo_phrase('Your template has not found', false) );
}
}
public function show_msg($msg){
?>get_template($template) ){
if( $this->can_view_template($template, WPF()->current_user) ){
if( !is_callable($template['callback_for_can_view_menu']) ){
if( wpforo_is_member_template($template) ){
$can_view = (bool) WPF()->current_userid;
}else{
$can_view = true;
}
}else{
$can_view = (bool) call_user_func($template['callback_for_can_view_menu'], $template, $default);
}
}
}
return $can_view;
}
function init_nav_menu(){
$actives = array();
$is_active = in_array( WPF()->current_object['template'], array('forum','topic','post') );
WPF()->menu['wpforo-home'] = array(
'href' => wpforo_home_url(),
'label' => wpforo_phrase( 'forums', false ),
'is_active' => $is_active && !in_array(true, $actives)
);
$actives['wpforo-home'] = $is_active;
$is_active = WPF()->current_object['template'] === 'recent' && wpfval( WPF()->GET, 'view' ) === 'unread';
WPF()->menu['wpforo-unread'] = array(
'href' => wpforo_home_url( wpforo_get_template_slug('recent') . '?view=unread' ),
'label' => wpforo_phrase( 'Unread Posts', false ),
'is_active' => $is_active && !in_array(true, $actives)
);
$actives['wpforo-unread'] = $is_active;
if( !wpforo_is_bot() ){
if( WPF()->current_userid ){
WPF()->menu['wpforo-logout'] = array(
'href' => wpforo_home_url( '?foro=logout' ),
'label' => wpforo_phrase( 'logout', false ),
'is_active' => false
);
}else{
if ( wpforo_feature( 'user-register' ) || WPF()->member->options['register_url'] ) {
$is_active = WPF()->current_object['template'] === 'register';
WPF()->menu['wpforo-register'] = array(
'href' => wpforo_register_url(),
'label' => wpforo_phrase( 'register', false ),
'is_active' => $is_active && !in_array(true, $actives)
);
$actives['wpforo-register'] = $is_active;
}
$is_active = WPF()->current_object['template'] === 'login';
WPF()->menu['wpforo-login'] = array(
'href' => wpforo_login_url(),
'label' => wpforo_phrase( 'login', false ),
'is_active' => $is_active
);
$actives['wpforo-login'] = $is_active;
}
}
if( $templates = $this->get_templates() ){
$cot_is_member_template = wpforo_is_member_template();
foreach ($templates as $key => $template){
if( $this->can_view_nav_menu($template) ){
$is_active = ( $key === WPF()->current_object['template'] && (!$cot_is_member_template || WPF()->current_object['user_is_same_current_user']) ) ||
( $key === 'profile' && $cot_is_member_template && WPF()->current_object['user_is_same_current_user'] );
$default_url = wpforo_is_member_template($template) ? WPF()->member->profile_url(WPF()->current_user, $key) : '';
$shortcode = $this->get_menu_shortcode($template);
WPF()->menu[$shortcode] = array(
'href' => $this->get_url( $template, WPF()->current_user, $default_url ),
'label' => wpforo_phrase( $template['title'], false ),
'is_active' => $is_active && !in_array(true, $actives)
);
if( $key !== 'profile' ) $actives[$shortcode] = $is_active;
}
}
}
WPF()->menu = apply_filters('wpforo_menu_array_filter', WPF()->menu);
}
function has_menu(){
return has_nav_menu( 'wpforo-menu' );
}
function nav_menu(){
if ( has_nav_menu( 'wpforo-menu' ) ){
$defaults = array(
'theme_location' => 'wpforo-menu',
'menu' => '',
'container' => '',
'container_class' => '',
'container_id' => '',
'menu_class' => 'wpf-menu',
'menu_id' => 'wpf-menu',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
}
}
private function init_options(){
$this->style = get_wpf_option('wpforo_style_options', $this->default->style);
$this->options = get_wpf_option('wpforo_theme_options', $this->default->options);
$this->theme = $this->options['folder'];
$this->forms = get_wpf_option('wpforo_form_options', $this->default->forms);
$this->init_defines();
}
private function init_defines(){
define('WPFORO_THEME', $this->theme );
define('WPFORO_TEMPLATE_DIR', wpforo_fix_directory(WPFORO_THEME_DIR . '/' . $this->theme) );
define('WPFORO_TEMPLATE_URL', WPFORO_THEME_URL . '/' . $this->theme );
}
function add_mce_external_plugins( $plugin_array ) {
$plugin_array = array();
$plugin_array['wpforo_pre_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-pre.js';
$plugin_array['wpforo_link_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-link.js';
$plugin_array['wpforo_spoiler_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-spoiler.js';
$plugin_array['wpforo_source_code_button'] = WPFORO_URL . '/wpf-assets/js/tinymce-code.js';
$plugin_array['emoticons'] = WPFORO_URL . '/wpf-assets/js/tinymce-emoji.js';
return $plugin_array;
}
function filter_tinymce_plugins($plugins){
return array('hr','lists','textcolor','paste', 'wpautoresize', 'fullscreen');
}
function add_tinymce_translations($mce_translation){
$mce_translation['Insert link'] = __( 'Insert link' );
$mce_translation['Link Text'] = __( 'Link Text' );
$mce_translation['Open link in a new tab'] = __( 'Open link in a new tab' );
$mce_translation['Insert Spoiler'] = __( 'Insert Spoiler', 'wpforo' );
$mce_translation['Spoiler'] = __( 'Spoiler', 'wpforo' );
return $mce_translation;
}
public function add_default_attach_input($forumid = null){
if( WPF()->perm->can_attach($forumid) ){ ?>
forum->options['layout_threaded_add_topic_button'] && WPF()->perm->forum_can( 'ct', $parent_forumid ) ){
$this->portable_topic_form(null, $parent_forumid);
}
}
public function portable_topic_form( $forumid = null, $parent_forumid = null ){
WPF()->current_object['load_tinymce'] = true;
$uniqid = uniqid();
?>
current_object['forum'];
if( !is_array($forum) && is_scalar($forum) ) $forum = WPF()->forum->get_forum((int)$forum);
if( !$forum ) return;
$forumid = intval($forum['forumid']);
$layout = WPF()->forum->get_layout($forum);
$uniqid = uniqid();
WPF()->data['varname'] = 'topic';
?>
current_object['topic'];
if( !is_array($topic) && is_scalar($topic) ) $topic = wpforo_topic($topic);
if( wpfval($topic, 'topic_closed') ) return;
$layout = $topic['layout'] = WPF()->forum->get_layout($topic);
$uniqid = uniqid();
WPF()->data['varname'] = 'post';
$style = ($layout === 3 && !$this->forms['qa_display_answer_editor']) ? 'style="display: none;"' : '';
$parentid = ($layout === 3 && !WPF()->topic->can_answer($topic['topicid'])) ? wpforo_bigintval( wpfval($topic, 'first_postid') ) : 0;
$v = $values;
if( !trim( wpfval( $v, 'title' ) ) ) $v['title'] = $topic['title'];
?>
forms[ $form_option ] ) {
$this->post_form();
} else {
$this->post_form_simple();
}
}
}
public function post_form_simple(){
if( wpfval(WPF()->current_object, 'topic', 'closed') ) return;
$textareaid = uniqid('wpf_post_body_');
$layout = WPF()->forum->get_layout();
$bodyminlength = ( $layout == 3 ? WPF()->post->options['comment_body_min_length'] : WPF()->post->options['post_body_min_length'] );
$bodymaxlength = ( $layout == 3 ? WPF()->post->options['comment_body_max_length'] : WPF()->post->options['post_body_max_length'] );
$submit_ico = ( $layout == 3 ? '' : '' );
$submit_value = ( $layout == 3 ? wpforo_phrase('Add a comment', false) : wpforo_phrase('Reply', false) );
$uniqid = uniqid();
?>
current_object, 'topic', 'closed') ) return;
$textareaid = uniqid('wpf_post_body_');
$topicid = wpforo_bigintval( wpfval(WPF()->current_object, 'topicid') );
$layout = WPF()->forum->get_layout();
$bodyminlength = ( $layout == 3 ? WPF()->post->options['comment_body_min_length'] : WPF()->post->options['post_body_min_length'] );
$bodymaxlength = ( $layout == 3 ? WPF()->post->options['comment_body_max_length'] : WPF()->post->options['post_body_max_length'] );
$submit_ico = ( $layout == 3 ? '' : '' );
$submit_value = ( $layout == 3 ? wpforo_phrase('Add a comment', false) : wpforo_phrase('Reply', false) );
$uniqid = uniqid();
?>
'', 'id' => '', 'class' => '', 'icon' => '', 'active' => false);
?>
post->get_posts( array('topicid' => WPF()->current_object['topicid']) ) ) return;
if( count($posts) < 2 ) return;
?>
post->get_posts( array('topicid' => WPF()->current_object['topicid']) ) ) return;
if( count($posts) < 2 ) return;
?>
current_object['topicid'])) return;
if(!$topicid) $topicid = WPF()->current_object['topicid'];
?>
post->get_search_fields( (array) wpfval($_GET, 'data') );
?>
current_object['paged'];
if( is_null($items_count) ) $items_count = WPF()->current_object['items_count'];
if( is_null($items_per_page) ) $items_per_page = WPF()->current_object['items_per_page'];
if($items_count <= $items_per_page) return;
$pages_count = ceil($items_count/$items_per_page);
$current_url = ( WPF()->current_url ? WPF()->current_url : wpforo_get_request_uri() );
$sanitized_current_url = trim( WPF()->strip_url_paged_var($current_url), '/' );
if($permalink){
$rtrimed_url = '';
$url_append_vars = '';
if( preg_match('#^(.+?)(/?[\?\&].*)?$#isu', $sanitized_current_url, $match) ){
if( wpfval($match, 1) ) $rtrimed_url = rtrim($match[1], '/\\');
if( wpfval($match, 2) ) $url_append_vars = '?' . trim($match[2], '?&/\\');
}
$url = str_replace('%', '%%', $rtrimed_url . '/'. wpforo_get_template_slug('paged')) .'/%1$d/' . str_replace('%', '%%', $url_append_vars);
}else{
$url = str_replace('%', '%%', $sanitized_current_url) . '&wpfpaged=%1$d';
}
?>
/
0 ): $prev_url = ( ($paged - 1) == 1 ? $sanitized_current_url : sprintf($url, $paged - 1) ); ?>
current_userid) $l_usernames[0]['display_name'] = wpforo_phrase('You', FALSE);
if($l_count == 1){
$return = sprintf( wpforo_phrase('%s liked', FALSE), ''.esc_html($l_usernames[0]['display_name']).'' );
}elseif($l_count == 2){
$return = sprintf( wpforo_phrase('%s and %s liked', FALSE), ''.esc_html($l_usernames[0]['display_name']).'', ''.esc_html($l_usernames[1]['display_name']).'' );
}elseif($l_count == 3){
$return = sprintf( wpforo_phrase('%s, %s and %s liked', FALSE), ''.esc_html($l_usernames[0]['display_name']).'', ''.esc_html($l_usernames[1]['display_name']).'', ''.esc_html($l_usernames[2]['display_name']).'' );
}elseif($l_count >= 4){
$l_count = $l_count - 3;
$return = sprintf( wpforo_phrase('%s, %s, %s and %d people liked', FALSE), ''.esc_html($l_usernames[0]['display_name']).'', ''.esc_html($l_usernames[1]['display_name']).'', ''.esc_html($l_usernames[2]['display_name']).'', $l_count );
}
}
return $return;
}
/**
* Get actions buttons
*
* @since 1.0.0
*
* @param array $buttons names function will return buttons by this array
*
* @param array $forum required
*
* @param array $topic required
*
* @param array $post required
*
* @param bool $is_topic required this is a first post in the loop
*
* @param bool $echo
*
* $buttons = array( 'reply', 'answer', 'comment', 'quote', 'like', 'report', 'sticky', 'close', 'edit', 'delete', 'link' );
*
* @return string
*/
function buttons( $buttons, $forum = array(), $topic = array(), $post = array(), $echo = true ){
$buttons = (array) $buttons;
$is_topic = (bool) wpfval($post, 'is_first_post');
$button_html = array();
$login = is_user_logged_in();
$forumid = (isset($forum['forumid'])) ? $forum['forumid'] : 0;
$topicid = (isset($topic['topicid'])) ? $topic['topicid'] : 0;
$postid = (isset($post['postid'])) ? $post['postid'] : 0;
if( $post ){
$userid = wpforo_bigintval( wpfval($post, 'userid') );
$is_owner = (int) (bool) ( WPF()->current_userid && wpforo_is_owner( $userid ) );
$mention = (string) ( !$is_owner ? wpforo_member($post, 'user_nicename') : '' );
}else{
$userid = 0;
$is_owner = 0;
$mention = '';
}
$is_sticky = (isset($topic['type'])) ? $topic['type'] : 0;
$is_closed = (isset($topic['closed'])) ? $topic['closed'] : 0;
$is_private = (isset($topic['private'])) ? $topic['private'] : 0;
$is_solved = (isset($topic['solved'])) ? $topic['solved'] : 0;
$is_approve = (isset($post['status'])) ? $post['status'] : 0;
foreach($buttons as $button){
switch($button){
case 'reply':
if($is_closed || $is_approve || ($is_topic && !WPF()->post->options['layout_threaded_first_post_reply']) ) break;
if( WPF()->perm->forum_can('cr', $forumid) || (wpforo_is_owner( wpforo_bigintval(wpfval($topic, 'userid')), (string) wpfval($topic, 'email')) && WPF()->perm->forum_can('ocr', $forumid)) ){
$layout = WPF()->forum->get_layout($forumid);
$layout_class = 'wpforo_layout_' . intval($layout);
$button_html[] = '' . wpforo_phrase('Reply', false).'';
}else{
$button_html[] = ( $login ) ? '' : '' . wpforo_phrase('Reply', false).'';
}
break;
case 'answer':
if($is_closed || $is_approve) break;
if( WPF()->perm->forum_can('cr', $forumid) || (wpforo_is_owner( wpforo_bigintval(wpfval($topic, 'userid')), (string) wpfval($topic, 'email')) && WPF()->perm->forum_can('ocr', $forumid)) ){
if( WPF()->topic->can_answer($topicid) ){
$button_html[] = '' . wpforo_phrase('Answer', false).'';
}
} else {
$button_html[] = ( $login ) ? '' : '' . wpforo_phrase('Answer', false).'';
}
break;
case 'comment':
if($is_closed || $is_approve || ($is_topic && !WPF()->post->options['layout_qa_first_post_reply'])) break;
$title = wpforo_phrase('Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.', false);
if( WPF()->perm->forum_can('cr', $forumid) || (wpforo_is_owner( wpforo_bigintval(wpfval($topic, 'userid')), (string) wpfval($topic, 'email')) && WPF()->perm->forum_can('ocr', $forumid)) ) {
$button_html[] = '';
}else{
$button_html[] = ( $login ) ? '' : '' . wpforo_phrase('Add a comment', false).'';
}
break;
case 'comment_raw':
if($is_closed || $is_approve || ($is_topic && !WPF()->post->options['layout_qa_first_post_reply'])) break;
$title = wpforo_phrase('Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.', false);
if( WPF()->perm->forum_can('cr', $forumid) || (wpforo_is_owner( wpforo_bigintval(wpfval($topic, 'userid')), (string) wpfval($topic, 'email')) && WPF()->perm->forum_can('ocr', $forumid)) ) {
$button_html[] = '';
}else{
$button_html[] = ( $login ) ? '' : '' . wpforo_phrase('Add a comment', false, 'lower').'';
}
break;
case 'quote':
if($is_closed || $is_approve) break;
if( WPF()->perm->forum_can('cr', $forumid) || (wpforo_is_owner( wpforo_bigintval(wpfval($topic, 'userid')), (string) wpfval($topic, 'email')) && WPF()->perm->forum_can('ocr', $forumid)) ) {
$button_html[] = '' . wpforo_phrase('Quote', false).'';
}else{
$button_html[] = ( $login ) ? '' : '' . wpforo_phrase('Quote', false).'';
}
break;
case 'like':
if( WPF()->perm->forum_can('l', $forumid) && $login && WPF()->current_userid != $post['userid'] ) {
$like_status = ( WPF()->post->is_liked( $postid, WPF()->current_userid ) === FALSE ? 'wpforo-like' : 'wpforo-unlike' );
$like_icon = ( $like_status == 'wpforo-like') ? 'up' : 'down';
$button_html[] = '' . wpforo_phrase( str_replace('wpforo-', '', $like_status), false) . '';
}
break;
case 'report':
if( WPF()->perm->forum_can('r', $forumid) && $login ) {
$button_html[] = '' . wpforo_phrase('Report', false).'';
}
break;
case 'sticky':
$sticky_status = ( $is_sticky ? 'wpforo-unsticky' : 'wpforo-sticky');
if( WPF()->perm->forum_can('s', $forumid) ) {
$button_html[] = '' . wpforo_phrase( str_replace('wpforo-', '', $sticky_status), false).'';
}
break;
case 'private':
if( $login ){
if( WPF()->perm->forum_can('p', $forumid) || (WPF()->current_userid == $post['userid'] && WPF()->perm->forum_can('op', $forumid)) ) {
$private_status = ( $is_private ? 'wpforo-public' : 'wpforo-private');
$private_icon = ( $private_status == 'wpforo-public') ? 'eye' : 'eye-slash';
$button_html[] = '' . wpforo_phrase( str_replace('wpforo-', '', $private_status), false).'';
}
}
break;
case 'solved':
$solved_status = ( $is_solved ? 'wpforo-unsolved' : 'wpforo-solved');
if( WPF()->perm->forum_can('sv', $forumid) || (WPF()->current_userid == $post['userid'] && WPF()->perm->forum_can('osv', $forumid)) ) {
$button_html[] = '' . wpforo_phrase( str_replace('wpforo-', '', $solved_status), false).'';
}
break;
case 'approved':
if( WPF()->perm->forum_can('au', $forumid) && $login ) {
$approve_status = ( !$is_approve ? 'wpforo-unapprove' : 'wpforo-approve');
$approve_icon = ( $approve_status == 'wpforo-unapprove') ? 'fa-exclamation-circle' : 'fa-check';
$button_html[] = '' . wpforo_phrase( str_replace('wpforo-', '', $approve_status), false).'';
}
break;
case 'close':
if( WPF()->perm->forum_can('cot', $forumid) && $login ) {
$open_status = ( $is_closed ? 'wpforo-open' : 'wpforo-close' );
$open_icon = ($open_status == 'wpforo-open') ? 'unlock' : 'lock';
$button_html[] = '' . wpforo_phrase( str_replace('wpforo-', '', $open_status), false).'';
}
break;
case 'tools':
if( WPF()->perm->forum_can('mt', $forumid) && $login ) {
$button_html[] = '' . wpforo_phrase('Tools', false).' | ';
}
break;
case 'edit':
if($is_closed) break;
$diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
if( !$login && isset($post['email'])
&& wpforo_is_owner($post['userid'], $post['email'])
&& WPF()->perm->forum_can( ($is_topic ? 'eot' : 'eor' ), $forumid )
&& $diff < WPF()->post->options[($is_topic ? 'eot' : 'eor' ).'_durr']
) {
$a = ( $is_topic ) ? 'wpfedittopicpid' : '';
$b = ( $is_topic ) ? $postid : $postid;
$button_html[] = '' . wpforo_phrase('Edit', false).'';
}
elseif( $login ) {
if( WPF()->perm->forum_can( ($is_topic ? 'et' : 'er'), $forumid ) ||
( WPF()->current_userid == $post['userid']
&& WPF()->perm->forum_can( ($is_topic ? 'eot' : 'eor' ), $forumid )
&& ( WPF()->post->options[($is_topic ? 'eot' : 'eor' ).'_durr'] == 0 ||
$diff < WPF()->post->options[($is_topic ? 'eot' : 'eor' ).'_durr'])
)
) {
$a = ( $is_topic ) ? 'wpfedittopicpid' : '';
$b = ( $is_topic ) ? $postid : $postid;
$button_html[] = '' . wpforo_phrase('Edit', false).'';
}
}
break;
case 'delete':
if( $login ){
//if( WPF()->member->current_user_is_new() && $post['status'] ){
//New registered user's unapproved topic/post | No Delete button.
//}
//else{
$diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
if( WPF()->perm->forum_can( ($is_topic ? 'dt' : 'dr' ), $forumid ) ||
(WPF()->current_userid == $post['userid'] &&
WPF()->perm->forum_can( ($is_topic ? 'dot' : 'dor' ), $forumid ) &&
( WPF()->post->options[($is_topic ? 'dot' : 'dor' ).'_durr'] == 0 ||
$diff < WPF()->post->options[($is_topic ? 'dot' : 'dor' ).'_durr'])
)
){
$a = ( $is_topic ) ? 'wpftopicdelete' : 'wpfreplydelete';
$b = ( $is_topic ) ? $topicid : $postid;
$button_html[] = '' . wpforo_phrase('Delete', false).'';
}
//}
}
break;
case 'link':
$full_url = esc_url( wpforo_post( $postid, 'url' ) );
$short_url = esc_url( wpforo_home_url( '/' . wpforo_get_template_slug('postid') . '/' . $postid . '/' ) );
$title = esc_attr(wpforo_phrase('Post link', false));
$button_html[] = sprintf(
'',
$title,
$full_url,
$short_url
);
break;
case 'positivevote':
if( WPF()->perm->forum_can('v', $forumid) && $login ) {
$button_html[] = '';
}else{
$button_html[] = '';
}
break;
case 'negativevote':
if( WPF()->perm->forum_can('v', $forumid) && $login ) {
$button_html[] = '';
}else{
$button_html[] = '';
}
break;
case 'isanswer':
if ( ! $is_topic ) {
$has_is_answer_post = WPF()->topic->has_is_answer_post( $post['topicid'] );
$is_answer = (bool) WPF()->post->is_answered( $postid );
$class = ( $is_answer ) ? '' : '-not';
if ( ! $has_is_answer_post || ( $has_is_answer_post && $is_answer ) ) {
if ( $login ) {
$button_html[] = '
';
} else {
$button_html[] = '
';
}
}
}
break;
} //switch
} //foreach
$before = '';
$after = '';
$html = $before . implode('', $button_html) . $after;
if( !$echo ) return $html;
echo $html; return '';
}
/**
* display QA Layout Votes count for loop current post
* @param array $post loop current post array
* @return void
*/
public function vote_count($post){
$votes = ( !empty($post['votes']) ? $post['votes'] : 0 );
printf('%d', $votes);
}
function breadcrumb( $current_object = null ){
if(!$current_object) $current_object = WPF()->current_object;
$lenght = apply_filters( 'wpforo_breadcrumb_text_length', 19 ); ?>
forum->get_parents($current_object['forumid'], $relative_ids);
foreach( $relative_ids as $key => $rel_forumid ) : ?>
forum->get_parents($current_object['forumid'], $relative_ids);
foreach( $relative_ids as $key => $rel_forumid ) : ?>
topic->is_private($item['topicid'])){
$icon['class'] = 'fas fa-eye-slash';
$icon['color'] = 'wpfcl-1';
$icon['title'] = wpforo_phrase('Private', false);
if($echo) {
$status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title'];
}
else{
return ($data == 'icon') ? implode(' ', $icon) : $icon['title'];
}
}
if( wpforo_topic($item['topicid'], 'solved') ){
$icon['class'] = 'fas fa-check-circle';
$icon['color'] = 'wpfcl-8';
$icon['title'] = wpforo_phrase('Solved', false);
if($echo) {
$status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title'];
}
else{
return ($data == 'icon') ? implode(' ', $icon) : $icon['title'];
}
}
}
if( $item['closed'] && $item['type'] == 1 ){
$icon['class'] = 'fas fa-lock';
$icon['color'] = 'wpfcl-1';
$icon['title'] = wpforo_phrase('Closed', false);
if($echo) { $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
}
elseif( $item['closed'] && $item['type'] != 1 ){
$icon['class'] = 'fas fa-lock';
$icon['color'] = 'wpfcl-1';
$icon['title'] = wpforo_phrase('Closed', false);
if($echo) { $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
}
elseif( !$item['closed'] && $item['type'] == 1 ){
$icon['class'] = 'fas fa-thumbtack';
$icon['color'] = 'wpfcl-5';
$icon['title'] = wpforo_phrase('Sticky', false);
if($echo) { $status = true; echo ($data == 'icon') ? implode(' ', $icon) : $icon['title']; } else{ return ($data == 'icon') ? implode(' ', $icon) : $icon['title']; }
}
if( $status ){
//do nothing
}
else{
if( $type == 'forum' ){
$icon['class'] = 'fas fa-comments';
$icon['color'] = 'wpfcl-2';
}
elseif( $type == 'topic' ){
$icon = $this->icon_status( $item['posts'] );
}
if($echo) {
echo ($data == 'icon') ? implode(' ', $icon) : ( wpfval($icon,'title') ? $icon['title']: '' );
} else{
return ($data == 'icon') ? implode(' ', $icon) : ( wpfval($icon,'title') ? $icon['title']: '' );
}
}
}
else{
return false;
}
}
function icon_status( $item ){
$icon = array();
if( wpfval($item, 'type')){
$icon['sticky']['class'] = 'fas fa-thumbtack';
$icon['sticky']['color'] = 'wpfcl-5';
$icon['sticky']['title'] = wpforo_phrase('Sticky', false);
}
if( wpfval($item,'topicid') && wpforo_topic($item['topicid'], 'solved')){
$icon['is_answer']['class'] = 'fas fa-check-circle';
$icon['is_answer']['color'] = 'wpfcl-8';
$icon['is_answer']['title'] = wpforo_phrase('Solved', false);
}
if( wpfval($item, 'closed')){
$icon['closed']['class'] = 'fas fa-lock';
$icon['closed']['color'] = 'wpfcl-1';
$icon['closed']['title'] = wpforo_phrase('Closed', false);
}
if( wpfval($item, 'status')){
$icon['status']['class'] = 'fas fa-exclamation-circle';
$icon['status']['color'] = 'wpfcl-5';
$icon['status']['title'] = wpforo_phrase('Unapproved', false);
}
if( wpfval($item,'private')){
$icon['private']['class'] = 'fas fa-eye-slash';
$icon['private']['color'] = 'wpfcl-1';
$icon['private']['title'] = wpforo_phrase('Private', false);
}
return $icon;
}
function icon_base( $post_count ){
$icon = array();
if( $post_count < 2 ){
$icon['class'] = 'far fa-file';
$icon['color'] = 'wpfcl-2';
$icon['title'] = wpforo_phrase('Not Replied', false);
}
elseif( $post_count > 1 && $post_count <= 5 ){
$icon['class'] = 'far fa-file-alt';
$icon['color'] = 'wpfcl-2';
$icon['title'] = wpforo_phrase('Replied', false);
}
elseif( $post_count > 5 && $post_count <= 20 ){
$icon['class'] = 'fas fa-file-alt';
$icon['color'] = 'wpfcl-2';
$icon['title'] = wpforo_phrase('Active', false);
}
elseif( $post_count > 20 ){
$icon['class'] = 'fas fa-file-alt';
$icon['color'] = 'wpfcl-5';
$icon['title'] = wpforo_phrase('Hot', false);
}
else{
$icon['class'] = 'far fa-file';
$icon['color'] = 'wpfcl-2';
$icon['title'] = '';
}
return $icon;
}
public function member_social_buttons( $member ){
$socnets = array();
if(empty($member)) return;
$social_access = ( WPF()->perm->usergroup_can('vmsn') ? true : false );
if( $social_access ){
if( isset($member['facebook']) && $member['facebook'] ){
$socnets['facebook']['set'] = $member['facebook'];
$member['facebook'] = ( strpos($member['facebook'], 'facebook.com') === FALSE ) ? 'https://www.facebook.com/' . trim($member['facebook'], '/') : $member['facebook'] ;
$socnets['facebook']['value'] = $member['facebook'];
$socnets['facebook']['protocol'] = 'https://';
$socnets['facebook']['title'] = wpforo_phrase('Facebook', false);
}
if( isset($member['twitter']) && $member['twitter'] ){
$socnets['twitter']['set'] = $member['twitter'];
$member['twitter'] = ( strpos($member['twitter'], 'twitter.com') === FALSE ) ? 'http://twitter.com/' . trim($member['twitter'], '/') : $member['twitter'] ;
$socnets['twitter']['value'] = $member['twitter'];
$socnets['twitter']['protocol'] = 'https://';
$socnets['twitter']['title'] = wpforo_phrase('Twitter', false);
}
if( isset($member['gtalk']) && $member['gtalk'] ){
$socnets['gtalk']['set'] = $member['gtalk'];
$socnets['gtalk']['value'] = $member['gtalk'];
$socnets['gtalk']['protocol'] = 'https://';
$socnets['gtalk']['title'] = wpforo_phrase('Google+', false);
}
if( isset($member['yahoo']) && $member['yahoo'] ){
$socnets['yahoo']['set'] = $member['yahoo'];
$socnets['yahoo']['value'] = $member['yahoo'];
$socnets['yahoo']['protocol'] = 'mailto:';
$socnets['yahoo']['title'] = wpforo_phrase('Yahoo', false);
}
if( isset($member['aim']) && $member['aim'] ){
$socnets['aim']['set'] = $member['aim'];
$socnets['aim']['value'] = $member['aim'];
$socnets['aim']['protocol'] = 'mailto:';
$socnets['aim']['title'] = wpforo_phrase('AOL IM', false);
}
if( isset($member['icq']) && $member['icq'] ){
$socnets['icq']['set'] = $member['icq'];
$socnets['icq']['value'] = 'www.icq.com/whitepages/cmd.php?uin=' . $member['icq'] . '&action=message';
$socnets['icq']['protocol'] = 'https://';
$socnets['icq']['title'] = wpforo_phrase('ICQ', false);
}
if( isset($member['msn']) && $member['msn'] ){
$socnets['msn']['set'] = $member['msn'];
$socnets['msn']['value'] = $member['msn'];
$socnets['msn']['protocol'] = 'mailto:';
$socnets['msn']['title'] = wpforo_phrase('MSN', false);
}
if( isset($member['skype']) && $member['skype'] ){
$socnets['skype']['set'] = $member['skype'];
$socnets['skype']['value'] = $member['skype'];
$socnets['skype']['protocol'] = 'skype:';
$socnets['skype']['title'] = wpforo_phrase('Skype', false);
}
?>
$socnet ): ?>
options['layouts'];
if( $identifier_type == 'id' ){
if( isset($layouts[$identifier]) && !empty($layouts[$identifier])){
return true;
}
else{
return false;
}
}
elseif( $identifier_type = 'name' ){
foreach( $layouts as $id => $layout ){
if( !isset($layout['name']) && $layout['name'] == $identifier ){
return true;
}
}
return false;
}
return false;
}
/**
*
* Finds and returns all layouts information in array from theme's /layouts/ folder
*
* @since 1.0.0
*
* @param string $theme Theme id ( folder name ) e.g. 'classic'
*
* @return array
*
**/
function find_layouts( $theme ){
$layout_data = array();
$layouts = $this->find_themes('/'.$theme.'/layouts', 'php', 'layout');
if(!empty($layouts)){
foreach( $layouts as $layout ){
$lid = trim(basename(dirname( $layout['file']['value'] )), '/');
$layout_data[$lid]['id'] = intval($lid);
$layout_data[$lid]['name'] = esc_html($layout['name']['value']);
$layout_data[$lid]['version'] = $layout['version']['value'];
$layout_data[$lid]['description'] = $layout['description']['value'];
$layout_data[$lid]['author'] = $layout['author']['value'];
$layout_data[$lid]['url'] = $layout['layout_url']['value'];
$layout_data[$lid]['file'] = $layout['file']['value'];
}
}
return $layout_data;
}
function show_layout_selectbox($layoutid = 0){
$layouts = $this->find_layouts( WPFORO_THEME );
if( !empty($layouts) ){
foreach( $layouts as $layout ) : ?>
options, 'style' );
$styles = wpfval( $this->options, 'styles' );
if ( ! empty( $style ) && ! empty( $styles ) ) {
foreach ( $styles[ $style ] as $color_key => $color_value ) {
if ( $color_value ) {
$search[] = '__WPFCOLOR_' . $color_key . '__';
$replace[] = $color_value;
$COLORS[ 'WPFCOLOR_' . $color_key ] = $color_value;
}
}
}
$css_matrix = ( $theme ? WPFORO_THEME_DIR . '/' . $theme : WPFORO_TEMPLATE_DIR ) . '/styles/matrix.css';
if ( file_exists( $css_matrix ) ) {
$css = wpforo_get_file_content( $css_matrix );
}
$dynamic_css = apply_filters( 'wpforo_dynamic_css_filter', '', $COLORS );
$dynamic_css = wpforo_add_wrapper($dynamic_css);
$css .= "\r\n" . $dynamic_css;
$css = apply_filters('wpforo_dynamic_css', $css, $COLORS);
$css = str_replace( $search, $replace, $css );
return trim( $css );
}
/**
*
* Finds and returns styles array from theme's /styles/colors.php file
*
* @since 1.0.0
*
* @param string $theme Theme id ( folder name ) e.g. 'classic'
*
* @return array
*
**/
function find_styles( $theme ){
$colors = array();
$color_file = WPFORO_THEME_DIR . '/' . $theme . '/styles/colors.php';
if( file_exists($color_file) ){
include( $color_file );
}
return $colors;
}
/**
*
* Scans certain theme directory and returns all information in array ( theme header, layouts, styles ).
*
* @since 1.0.0
*
* @param string $theme_file Theme folder name or main css file base path ( 'classic' OR classic/style.css' )
*
* @return array
*
**/
function find_theme( $theme_file ){
$theme = array();
$theme_file = trim(trim($theme_file, '/'));
if( preg_match('|\.[\w\d]{2,4}$|is', $theme_file) ){
$theme_folder = trim(basename(dirname($theme_file)), '/');
}
else{
$theme_folder = $theme_file;
$theme_file = $theme_file . '/style.css';
}
if( !is_readable( WPFORO_THEME_DIR . '/' . $theme_file ) ){
$theme['error'] = __('Theme file not readable', 'wpforo') .' ('.$theme_file.')';
}
else{
$theme_data = $this->find_theme_headers( WPFORO_THEME_DIR . '/' . $theme_file );
$theme['id'] = $theme_folder;
$theme['name'] = $theme_data['name']['value'];
$theme['version'] = $theme_data['version']['value'];
$theme['description'] = $theme_data['description']['value'];
$theme['author'] = $theme_data['author']['value'];
$theme['url'] = $theme_data['theme_url']['value'];
$theme['file'] = $theme_file;
$theme['folder'] = $theme_folder;
$theme['layouts'] = $this->find_layouts( $theme_folder );
$styles = $this->find_styles( $theme_folder );
if(!empty($styles)){
reset($styles);
$theme['style'] = key($styles);
$theme['styles'] = $styles;
}
}
return $theme;
}
/**
*
* Scans wpForo themes (wpf-themes) folder, reads main files' headers and returns information about all themes in array.
* This function can also be used to scan and get information about layouts in each theme /layouts/ folder.
*
* @since 1.0.0
*
* @param string $base_dir Absolute path to scan directory (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/)
* @param string $ext File extension which may contain header information
* @param string $mode 'theme' or 'layout'
*
* @return array
*
**/
function find_themes( $base_dir = '', $ext = 'css', $mode = 'theme' ){
$themes = array ();
$themes_dir = @opendir( WPFORO_THEME_DIR . $base_dir );
$theme_files = array();
if( $themes_dir ){
while( ($file = readdir( $themes_dir )) !== false ){
if( substr($file, 0, 1) == '.' ) continue;
if( is_dir( WPFORO_THEME_DIR . $base_dir .'/'.$file ) ){
$themes_subdir = @opendir( WPFORO_THEME_DIR . $base_dir .'/'.$file );
if( $themes_subdir ){
while(($subfile = readdir( $themes_subdir ) ) !== false ){
if( substr($subfile, 0, 1) == '.' ) continue;
if( substr($subfile, -4) == '.' . $ext ) $theme_files[] = "$file/$subfile";
}
closedir( $themes_subdir );
}
}
else{
if( substr($file, -4) == '.' . $ext ) $theme_files[] = $file;
}
}
closedir( $themes_dir );
}
if( empty($theme_files) ) return $themes;
foreach( $theme_files as $theme_file ){
if( !is_readable( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file ) ) continue;
if( $mode == 'theme' ){
$theme_data = $this->find_theme_headers( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file );
}
elseif( $mode == 'layout' ){
$theme_data = $this->find_layout_headers( WPFORO_THEME_DIR . $base_dir . '/' . $theme_file );
}
if( empty($theme_data['name']['value']) ) continue;
$themes[wpforo_clear_basename($theme_file)] = $theme_data;
}
return $themes;
}
/**
*
* Reads theme main file's header variables and returns information in array.
*
* @since 1.0.0
*
* @param string $file Absolute path to file (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/style.css)
*
* @return array
*
**/
function find_theme_headers( $file ){
$theme_headers = array();
$headers = array(
'name' => 'Theme Name',
'version' => 'Version',
'description' => 'Description',
'author' => 'Author',
'theme_url' => 'Theme URI',
);
$fp = fopen( $file, 'r' );
$data = fread( $fp, 8192 );
fclose( $fp );
$data = str_replace( "\r", "\n", $data );
foreach ( $headers as $header_key => $header_name ){
if ( preg_match( '|^[\s\t\/*#@]*' . preg_quote( $header_name, '|' ) . ':(.*)$|mi', $data, $match ) && $match[1] ){
$theme_headers[$header_key]['name'] = $header_name;
$theme_headers[$header_key]['value'] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
}
else{
$theme_headers[$header_key]['name'] = $header_name;
$theme_headers[$header_key]['value'] = '';
}
}
$theme_headers['file']['name'] = 'file';
$theme_headers['file']['value'] = $file;
return $theme_headers;
}
/**
*
* Reads layout main file's header variables and returns information in array.
*
* @since 1.0.0
*
* @param string $file Absolute path to file (e.g. /home/public_html/wp-content/plugins/wpforo/wpf-themes/layouts/1/forum.php)
*
* @return array
*
**/
function find_layout_headers( $file ){
$theme_headers = array();
$headers = array(
'name' => 'layout',
'version' => 'version',
'description' => 'description',
'author' => 'author',
'layout_url' => 'url',
);
$fp = fopen( $file, 'r' );
$data = fread( $fp, 8192 );
fclose( $fp );
$data = str_replace( "\r", "\n", $data );
foreach ( $headers as $header_key => $header_name ){
if ( preg_match( '|^[\s\t\/*#@]*' . preg_quote( $header_name, '|' ) . ':(.*)$|mi', $data, $match ) && $match[1] ){
$theme_headers[$header_key]['name'] = $header_name;
$theme_headers[$header_key]['value'] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1]));
}
else{
$theme_headers[$header_key]['name'] = $header_name;
$theme_headers[$header_key]['value'] = '';
}
}
$theme_headers['file']['name'] = 'file';
$theme_headers['file']['value'] = trim(str_replace( WPFORO_THEME_DIR, '', $file), '/');
return $theme_headers;
}
public function copyright(){
if( wpforo_feature('copyright') ): ?>
current_userid || WPF()->current_user_email ): ?>
current_object, 'forumid') && WPF()->perm->forum_can('sb', WPF()->current_object['forumid']) ): ?>
WPF()->current_userid, "itemid" => WPF()->current_object['forumid'], "type" => "forum", 'user_email' => WPF()->current_user_email );
$subscribe = WPF()->sbscrb->get_subscribe( $args );
if( isset( $subscribe['subid'] ) ): ?>
current_userid || WPF()->current_user_email ){
if( wpfval( WPF()->current_object, 'forumid') && WPF()->perm->forum_can('sb', WPF()->current_object['forumid']) ){
$args = array( "userid" => WPF()->current_userid , "itemid" => WPF()->current_object['topicid'], "type" => "topic", 'user_email' => WPF()->current_user_email );
$subscribe = WPF()->sbscrb->get_subscribe( $args );
if( isset( $subscribe['subid'] ) ): ?>
topic_merge_form();
exit();
break;
case 'reply_move_form':
$this->reply_move_form();
exit();
break;
case 'topic_split_form':
$this->topic_split_form();
exit();
break;
case 'topic_move_form':
$this->topic_move_form();
exit();
break;
}
}
echo 0;
exit();
}
public function add_footer_html(){
$this->dialog();
$this->spinner();
if( apply_filters( 'wpforo_message_bubble', true ) ) $this->msg_box();
if( WPF()->current_object['template'] === 'post' ) $this->report_form();
}
public function posts_ordering_dropdown($orderby = null, $topicid = null){
if( is_null($topicid) ) $topicid = wpforo_bigintval( wpfval(WPF()->current_object, 'topicid') );
if( $topicid && $topic_url = wpforo_topic( $topicid, 'url' ) ){
if( is_null($orderby) ) $orderby = WPF()->current_object['orderby'];
?>
registered, 'wpforo-font-awesome')) && ($fa_rtl = wpfval($wp_styles->registered, 'wpforo-font-awesome-rtl')) ){
$content_css = $fa->src . ( is_rtl() ? ',' . $fa_rtl->src : '' );
}else{
$content_css = '';
}
$settings = array(
'topic' => array(
'media_buttons' => false,
'textarea_name' => 'topic[body]',
'textarea_rows' => get_option( 'default_post_edit_rows', 20 ),// rows = "..."
'tabindex' => '',
'editor_height' => 180,
'editor_css' => '',
'editor_class' => '',
'teeny' => false,
'dfw' => false,
'tinymce' => array(
'toolbar1' => 'fontsizeselect,bold,italic,underline,strikethrough,forecolor,bullist,numlist,hr,alignleft,aligncenter,alignright,alignjustify,link,unlink,blockquote,pre,wpf_spoil,undo,redo,pastetext,source_code,emoticons,fullscreen',
'toolbar2' => '',
'toolbar3' => '',
'toolbar4' => '',
'content_style' => 'blockquote{border: #cccccc 1px dotted; background: #F7F7F7; padding:10px;font-size:12px; font-style:italic; margin: 20px 10px;}',
'object_resizing' => false,
'autoresize_on_init' => true,
'wp_autoresize_on' => true,
'wp_keep_scroll_position' => true,
'indent' => true,
'add_unload_trigger' => false,
'wpautop' => false,
'setup' => 'wpforo_tinymce_setup',
'content_css' => $content_css,
'extended_valid_elements' => 'i[class|style],span[class|style]',
'custom_elements' => ''
),
'quicktags' => false,
'default_editor' => 'tinymce'
),
'post' => array(
'media_buttons' => false,
'textarea_name' => 'post[body]',
'textarea_rows' => get_option( 'default_post_edit_rows', 5 ),
'editor_class' => 'wpeditor',
'teeny' => false,
'dfw' => false,
'editor_height' => 150,
'tinymce' => array(
'toolbar1' => 'fontsizeselect,bold,italic,underline,strikethrough,forecolor,bullist,numlist,hr,alignleft,aligncenter,alignright,alignjustify,link,unlink,blockquote,pre,wpf_spoil,undo,redo,pastetext,source_code,emoticons,fullscreen',
'toolbar2' => '',
'toolbar3' => '',
'toolbar4' => '',
'content_style' => 'blockquote{border: #cccccc 1px dotted; background: #F7F7F7; padding:10px;font-size:12px; font-style:italic; margin: 20px 10px;}',
'object_resizing' => false,
'autoresize_on_init' => true,
'wp_autoresize_on' => true,
'wp_keep_scroll_position' => true,
'indent' => true,
'add_unload_trigger' => false,
'wpautop' => false,
'setup' => 'wpforo_tinymce_setup',
'content_css' => $content_css,
'extended_valid_elements' => 'i[class|style],span[class|style]',
'custom_elements' => ''
),
'quicktags' => false,
'default_editor' => 'tinymce'
)
);
return array_merge( $this->default->editor_settings, apply_filters( 'wpforo_editor_settings', $settings[ $editor ], $editor ) );
}
public function editor_settings_required_params($settings){
if( !wpfkey($settings, 'tinymce') ) $settings['tinymce'] = array();
$settings['tinymce']['setup'] = 'wpforo_tinymce_setup';
return $settings;
}
public function add_topic_button( $forumid = null ) {
$phrase = ( WPF()->forum->get_layout( $forumid ) == 3 ? wpforo_phrase( 'Ask a question', false ) : wpforo_phrase( 'Add Topic', false ) );
if( WPF()->current_object['template'] == 'forum' ) :
if( WPF()->forum->options['layout_threaded_add_topic_button'] ): ?>
perm->forum_can( 'ct', $forumid) ): WPF()->current_object['load_tinymce'] = true; ?>
current_user_groupid == 4 ) : ?>
perm->forum_can( 'ct', $forumid ) ): ?>
current_user_groupid == 4 ) : ?>
]*?)?>[\r\n\t\s\0]*)\[[\r\n\t\s\0]*spoiler(?:[\r\n\t\s\0]*title[\r\n\t\s\0]*=[\r\n\t\s\0]*\"([^\"]+)\")?[\r\n\t\s\0]*\](?:[\r\n\t\s\0]*\1>)#isu', ''. wpforo_phrase('Spoiler', false) .'$2
', $text, -1, $count1);
$text = preg_replace('#\[[\r\n\t\s\0]*spoiler(?:[\r\n\t\s\0]*title[\r\n\t\s\0]*=[\r\n\t\s\0]*\"([^\"]+)\")?[\r\n\t\s\0]*\]#isu', '
'. wpforo_phrase('Spoiler', false) .'$1
', $text, -1, $count2);
$text = preg_replace('#(?:<(p|a|span|blockquote|b|i|pre|font|del|strike|strong|em|div|u|center|marquee|table|tr|td|th|tt|sup|sub|s|ul|ol|li|small|code|h\d)(?:[\r\n\t\s\0]+[^<>]*?)?>[\r\n\t\s\0]*)\[[\r\n\t\s\0]*/[\r\n\t\s\0]*spoiler[\r\n\t\s\0]*\](?:[\r\n\t\s\0]*\1>)#isu', '
', $text, $count1);
$text = preg_replace('#\[[\r\n\t\s\0]*/[\r\n\t\s\0]*spoiler[\r\n\t\s\0]*\]#isu', '
', $text, $count2);
return $text;
}
public function please_login(){
if( !wpforo_is_bot() ){
$html = sprintf( '%1$s %2$s
',
wpforo_get_login_or_register_notice_text(),
wpforo_phrase('to reply to this topic.', false, 'lower')
);
echo apply_filters('wpforo_login_message_in_topic', $html);
}
}
}