| @@ -1,237 +1,250 @@ | ||
| 1 | -<?php | |
| 2 | -namespace admin\Elementor; | |
| 3 | - | |
| 4 | -use Elementor\Controls_Manager; | |
| 5 | -use Elementor\Group_Control_Border; | |
| 6 | -use Elementor\Group_Control_Typography; | |
| 7 | -use Elementor\Widget_Base; | |
| 8 | -use WP_Query; | |
| 9 | - | |
| 10 | -// Exit if accessed directly | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; | |
| 13 | -} | |
| 14 | - | |
| 15 | -class Single_forum extends Widget_Base | |
| 16 | -{ | |
| 17 | - | |
| 18 | - public function get_name () | |
| 19 | - { | |
| 20 | - return 'ama_single_forum'; | |
| 21 | - } | |
| 22 | - | |
| 23 | - public function get_title () | |
| 24 | - { | |
| 25 | - return __('BBPC Single Forum', 'bbp-core'); | |
| 26 | - } | |
| 27 | - | |
| 28 | - public function get_icon () | |
| 29 | - { | |
| 30 | - return 'bbpc_icon_ama_single_forum'; | |
| 31 | - } | |
| 32 | - | |
| 33 | - public function get_categories () | |
| 34 | - { | |
| 35 | - return [ 'bbp-core' ]; | |
| 36 | - } | |
| 37 | - | |
| 38 | - public function get_style_depends () | |
| 39 | - { | |
| 40 | - return [ 'bbpc-el-widgets' ]; | |
| 41 | - } | |
| 42 | - | |
| 43 | - protected function register_controls () | |
| 44 | - { | |
| 45 | - | |
| 46 | - //-------- Select Style ---------- // | |
| 47 | - $this->start_controls_section( | |
| 48 | - 'style_sec', | |
| 49 | - [ | |
| 50 | - 'label' => esc_html__('Preset Skins', 'bbp-core'), | |
| 51 | - ] | |
| 52 | - ); | |
| 53 | - | |
| 54 | - $this->add_control( | |
| 55 | - 'forum_id', [ | |
| 56 | - 'label' => esc_html__('Select Forum', 'bbp-core'), | |
| 57 | - 'type' => Controls_Manager::SELECT, | |
| 58 | - 'options' => bbp_core_get_posts('forum') | |
| 59 | - ] | |
| 60 | - ); | |
| 61 | - | |
| 62 | - $this->add_control( | |
| 63 | - 'style', | |
| 64 | - [ | |
| 65 | - 'label' => esc_html__('Forums Style', 'bbp-core'), | |
| 66 | - 'type' => Controls_Manager::CHOOSE, | |
| 67 | - 'options' => [ | |
| 68 | - '1' => [ | |
| 69 | - 'icon' => 'single_forum_1', | |
| 70 | - 'title' => esc_html__('01 : Single Forum With Topics', 'bbp-core'), | |
| 71 | - ], | |
| 72 | - '2' => [ | |
| 73 | - 'icon' => 'single_forum_2', | |
| 74 | - 'title' => esc_html__('02 : Single Forum', 'bbp-core'), | |
| 75 | - ], | |
| 76 | - ], | |
| 77 | - 'default' => '1', | |
| 78 | - 'toggle' => false, | |
| 79 | - ] | |
| 80 | - ); | |
| 81 | - | |
| 82 | - $this->end_controls_section(); // End Style | |
| 83 | - | |
| 84 | - | |
| 85 | - $this->start_controls_section( | |
| 86 | - 'forum_thumb', [ | |
| 87 | - 'label' => __('Thumbnail', 'bbp-core'), | |
| 88 | - ] | |
| 89 | - ); | |
| 90 | - | |
| 91 | - $this->add_control( | |
| 92 | - 'cover_image', [ | |
| 93 | - 'label' => __('Custom Cover Image', 'bbp-core'), | |
| 94 | - 'type' => Controls_Manager::MEDIA, | |
| 95 | - 'description' => __('If this is not set, the featured image will be used by default', 'bbp-core') | |
| 96 | - ] | |
| 97 | - ); | |
| 98 | - | |
| 99 | - $this->end_controls_section(); | |
| 100 | - | |
| 101 | - // --- Filter Options | |
| 102 | - $this->start_controls_section( | |
| 103 | - 'filter_opt', [ | |
| 104 | - 'label' => __('Filter Options', 'bbp-core'), | |
| 105 | - ] | |
| 106 | - ); | |
| 107 | - | |
| 108 | - $this->add_control( | |
| 109 | - 'ppp', [ | |
| 110 | - 'label' => esc_html__('Topics', 'bbp-core'), | |
| 111 | - 'description' => esc_html__('Maximum number of topics.', 'bbp-core'), | |
| 112 | - 'type' => Controls_Manager::NUMBER, | |
| 113 | - 'default' => 3 | |
| 114 | - ] | |
| 115 | - ); | |
| 116 | - | |
| 117 | - $this->add_control( | |
| 118 | - 'order', [ | |
| 119 | - 'label' => esc_html__('Order', 'bbp-core'), | |
| 120 | - 'type' => Controls_Manager::SELECT, | |
| 121 | - 'options' => [ | |
| 122 | - 'ASC' => 'ASC', | |
| 123 | - 'DESC' => 'DESC' | |
| 124 | - ], | |
| 125 | - 'default' => 'ASC' | |
| 126 | - ] | |
| 127 | - ); | |
| 128 | - | |
| 129 | - $this->add_control( | |
| 130 | - 'word_length', | |
| 131 | - [ | |
| 132 | - 'label' => __('Number of Words', 'bbp-core'), | |
| 133 | - 'type' => Controls_Manager::NUMBER, | |
| 134 | - 'description' => __('Number of words to show as forum content', 'bbp-core'), | |
| 135 | - 'default' => 12 | |
| 136 | - ] | |
| 137 | - ); | |
| 138 | - | |
| 139 | - $this->add_control( | |
| 140 | - 'read_more', | |
| 141 | - [ | |
| 142 | - 'label' => esc_html__('Read More Text', 'bbp-core'), | |
| 143 | - 'type' => Controls_Manager::TEXT, | |
| 144 | - 'label_block' => true, | |
| 145 | - 'default' => __('View All', 'bbp-core'), | |
| 146 | - ] | |
| 147 | - ); | |
| 148 | - | |
| 149 | - $this->end_controls_section(); | |
| 150 | - | |
| 151 | - /**============== Background shape Image =====================**/ | |
| 152 | - $this->start_controls_section( | |
| 153 | - 'single_forum_style', [ | |
| 154 | - 'label' => __('Single Forum Style', 'bbp-core'), | |
| 155 | - 'tab' => Controls_Manager::TAB_STYLE, | |
| 156 | - ] | |
| 157 | - ); | |
| 158 | - | |
| 159 | - $this->add_group_control( | |
| 160 | - Group_Control_Border::get_type(), | |
| 161 | - [ | |
| 162 | - 'name' => 'border', | |
| 163 | - 'selector' => '{{WRAPPER}} .forum-card, {{WRAPPER}} .forum-with-topics .topic-table .topic-heading, {{WRAPPER}} .forum-with-topics .topic-table .topic-contents', | |
| 164 | - ] | |
| 165 | - ); | |
| 166 | - | |
| 167 | - $this->add_group_control( | |
| 168 | - Group_Control_Typography::get_type(), | |
| 169 | - [ | |
| 170 | - 'name' => 'title_typography', | |
| 171 | - 'label' => __('Title Typography', 'bbp-core'), | |
| 172 | - 'separator' => 'before', | |
| 173 | - 'selector' => '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title h3, {{WRAPPER}} .forum-card .card-title h3', | |
| 174 | - ] | |
| 175 | - ); | |
| 176 | - | |
| 177 | - $this->add_control( | |
| 178 | - 'title_color', | |
| 179 | - [ | |
| 180 | - 'label' => __('Title Color', 'bbp-core'), | |
| 181 | - 'type' => Controls_Manager::COLOR, | |
| 182 | - 'separator' => 'after', | |
| 183 | - 'selectors' => [ | |
| 184 | - '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title h3' => 'color: {{VALUE}}', | |
| 185 | - '{{WRAPPER}} .forum-card .card-title h3' => 'color: {{VALUE}}' | |
| 186 | - ], | |
| 187 | - ] | |
| 188 | - ); | |
| 189 | - | |
| 190 | - $this->add_group_control( | |
| 191 | - Group_Control_Typography::get_type(), | |
| 192 | - [ | |
| 193 | - 'name' => 'excerpt_typography', | |
| 194 | - 'label' => __('Excerpt Typography', 'bbp-core'), | |
| 195 | - 'selector' => '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title p, {{WRAPPER}} .forum-card .card-body', | |
| 196 | - ] | |
| 197 | - ); | |
| 198 | - | |
| 199 | - $this->add_control( | |
| 200 | - 'excerpt_color', | |
| 201 | - [ | |
| 202 | - 'label' => __('Excerpt Color', 'bbp-core'), | |
| 203 | - 'type' => Controls_Manager::COLOR, | |
| 204 | - 'selectors' => [ | |
| 205 | - '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title p' => 'color: {{VALUE}}', | |
| 206 | - '{{WRAPPER}} .forum-card .card-body' => 'color: {{VALUE}}' | |
| 207 | - ], | |
| 208 | - ] | |
| 209 | - ); | |
| 210 | - | |
| 211 | - $this->end_controls_section(); | |
| 212 | - } | |
| 213 | - | |
| 214 | - protected function render (): void | |
| 215 | - { | |
| 216 | - $settings = $this->get_settings(); | |
| 217 | - $forum_id = !empty($settings[ 'forum_id' ]) ? $settings[ 'forum_id' ] : ''; | |
| 218 | - $cover_image = $settings[ 'cover_image' ]; | |
| 219 | - $post_thumbnail_url = !empty($cover_image[ 'url' ]) ? $cover_image[ 'url' ] : get_the_post_thumbnail_url($forum_id); | |
| 220 | - | |
| 221 | - $topics = new WP_Query(array( | |
| 222 | - 'post_type' => bbp_get_topic_post_type(), | |
| 223 | - 'order' => !empty($settings['order']) ? $settings['order'] : 'DESC', | |
| 224 | - 'posts_per_page' => !empty($settings['ppp']) ? $settings['ppp'] : 3, | |
| 225 | - 'post_parent' => $forum_id, | |
| 226 | - )); | |
| 227 | - | |
| 228 | - if ($forum_id) { | |
| 229 | - include "inc/single-forum/single-forum-{$settings['style']}.php"; | |
| 230 | - } else { ?> | |
| 231 | - <div class="alert alert-warning" role="alert"> | |
| 232 | - <?php _e('Please select a forum.', 'bbp-core'); ?> | |
| 233 | - </div> | |
| 234 | - <?php | |
| 235 | - } | |
| 236 | - } | |
| 1 | +<?php | |
| 2 | +namespace admin\Elementor; | |
| 3 | + | |
| 4 | +use Elementor\Controls_Manager; | |
| 5 | +use Elementor\Group_Control_Border; | |
| 6 | +use Elementor\Group_Control_Typography; | |
| 7 | +use Elementor\Widget_Base; | |
| 8 | +use WP_Query; | |
| 9 | + | |
| 10 | +// Exit if accessed directly | |
| 11 | +if (!defined('ABSPATH')) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 15 | +class Single_forum extends Widget_Base | |
| 16 | +{ | |
| 17 | + | |
| 18 | + // public function get_name () | |
| 19 | + // { | |
| 20 | + // return 'ama_single_forum'; | |
| 21 | + // } | |
| 22 | + public function get_name() | |
| 23 | + { | |
| 24 | + // return 'forumax_docy_single_forum'; | |
| 25 | + $theme = wp_get_theme(); | |
| 26 | + $theme_name = strtolower($theme->get('Name')); | |
| 27 | + if ($theme_name == 'docy') { | |
| 28 | + return 'docy_single_forum'; | |
| 29 | + } | |
| 30 | + return 'ama_single_forum'; | |
| 31 | + } | |
| 32 | + | |
| 33 | + public function get_title () | |
| 34 | + { | |
| 35 | + return __('Forumax Single Forum', 'forumax'); | |
| 36 | + } | |
| 37 | + | |
| 38 | + public function get_icon () | |
| 39 | + { | |
| 40 | + return 'bbpc_icon_ama_single_forum'; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public function get_categories () | |
| 44 | + { | |
| 45 | + return [ 'forumax' ]; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public function get_style_depends () | |
| 49 | + { | |
| 50 | + return [ 'bbpc-el-widgets' ]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + protected function register_controls () | |
| 54 | + { | |
| 55 | + | |
| 56 | + //-------- Select Style ---------- // | |
| 57 | + $this->start_controls_section( | |
| 58 | + 'style_sec', | |
| 59 | + [ | |
| 60 | + 'label' => esc_html__('Preset Skins', 'forumax'), | |
| 61 | + ] | |
| 62 | + ); | |
| 63 | + | |
| 64 | + $this->add_control( | |
| 65 | + 'forum_id', [ | |
| 66 | + 'label' => esc_html__('Select Forum', 'forumax'), | |
| 67 | + 'type' => Controls_Manager::SELECT, | |
| 68 | + 'options' => forumax_get_posts('forum') | |
| 69 | + ] | |
| 70 | + ); | |
| 71 | + | |
| 72 | + $this->add_control( | |
| 73 | + 'style', | |
| 74 | + [ | |
| 75 | + 'label' => esc_html__('Forums Style', 'forumax'), | |
| 76 | + 'type' => Controls_Manager::VISUAL_CHOICE, | |
| 77 | + 'options' => [ | |
| 78 | + '1' => [ | |
| 79 | + 'image' => FORUMAX_IMG . 'forums3.jpg', | |
| 80 | + 'title' => esc_html__('01 : Single Forum With Topics', 'forumax'), | |
| 81 | + ], | |
| 82 | + '2' => [ | |
| 83 | + 'image' => FORUMAX_IMG . 'forums4.png', | |
| 84 | + 'title' => esc_html__('02 : Single Forum', 'forumax'), | |
| 85 | + ], | |
| 86 | + ], | |
| 87 | + 'default' => '1', | |
| 88 | + 'toggle' => false, | |
| 89 | + ] | |
| 90 | + ); | |
| 91 | + | |
| 92 | + $this->end_controls_section(); // End Style | |
| 93 | + | |
| 94 | + | |
| 95 | + $this->start_controls_section( | |
| 96 | + 'forum_thumb', [ | |
| 97 | + 'label' => __('Thumbnail', 'forumax'), | |
| 98 | + ] | |
| 99 | + ); | |
| 100 | + | |
| 101 | + $this->add_control( | |
| 102 | + 'cover_image', [ | |
| 103 | + 'label' => __('Custom Cover Image', 'forumax'), | |
| 104 | + 'type' => Controls_Manager::MEDIA, | |
| 105 | + 'description' => __('If this is not set, the featured image will be used by default', 'forumax') | |
| 106 | + ] | |
| 107 | + ); | |
| 108 | + | |
| 109 | + $this->end_controls_section(); | |
| 110 | + | |
| 111 | + // --- Filter Options | |
| 112 | + $this->start_controls_section( | |
| 113 | + 'filter_opt', [ | |
| 114 | + 'label' => __('Filter Options', 'forumax'), | |
| 115 | + ] | |
| 116 | + ); | |
| 117 | + | |
| 118 | + $this->add_control( | |
| 119 | + 'ppp', [ | |
| 120 | + 'label' => esc_html__('Topics', 'forumax'), | |
| 121 | + 'description' => esc_html__('Maximum number of topics.', 'forumax'), | |
| 122 | + 'type' => Controls_Manager::NUMBER, | |
| 123 | + 'default' => 3 | |
| 124 | + ] | |
| 125 | + ); | |
| 126 | + | |
| 127 | + $this->add_control( | |
| 128 | + 'order', [ | |
| 129 | + 'label' => esc_html__('Order', 'forumax'), | |
| 130 | + 'type' => Controls_Manager::SELECT, | |
| 131 | + 'options' => [ | |
| 132 | + 'ASC' => 'ASC', | |
| 133 | + 'DESC' => 'DESC' | |
| 134 | + ], | |
| 135 | + 'default' => 'ASC' | |
| 136 | + ] | |
| 137 | + ); | |
| 138 | + | |
| 139 | + $this->add_control( | |
| 140 | + 'word_length', | |
| 141 | + [ | |
| 142 | + 'label' => __('Number of Words', 'forumax'), | |
| 143 | + 'type' => Controls_Manager::NUMBER, | |
| 144 | + 'description' => __('Number of words to show as forum content', 'forumax'), | |
| 145 | + 'default' => 12 | |
| 146 | + ] | |
| 147 | + ); | |
| 148 | + | |
| 149 | + $this->add_control( | |
| 150 | + 'read_more', | |
| 151 | + [ | |
| 152 | + 'label' => esc_html__('Read More Text', 'forumax'), | |
| 153 | + 'type' => Controls_Manager::TEXT, | |
| 154 | + 'label_block' => true, | |
| 155 | + 'default' => __('View All', 'forumax'), | |
| 156 | + ] | |
| 157 | + ); | |
| 158 | + | |
| 159 | + $this->end_controls_section(); | |
| 160 | + | |
| 161 | + /**============== Background shape Image =====================**/ | |
| 162 | + $this->start_controls_section( | |
| 163 | + 'single_forum_style', [ | |
| 164 | + 'label' => __('Single Forum Style', 'forumax'), | |
| 165 | + 'tab' => Controls_Manager::TAB_STYLE, | |
| 166 | + ] | |
| 167 | + ); | |
| 168 | + | |
| 169 | + $this->add_group_control( | |
| 170 | + Group_Control_Border::get_type(), | |
| 171 | + [ | |
| 172 | + 'name' => 'border', | |
| 173 | + 'selector' => '{{WRAPPER}} .forum-card, {{WRAPPER}} .forum-with-topics .topic-table .topic-heading, {{WRAPPER}} .forum-with-topics .topic-table .topic-contents', | |
| 174 | + ] | |
| 175 | + ); | |
| 176 | + | |
| 177 | + $this->add_group_control( | |
| 178 | + Group_Control_Typography::get_type(), | |
| 179 | + [ | |
| 180 | + 'name' => 'title_typography', | |
| 181 | + 'label' => __('Title Typography', 'forumax'), | |
| 182 | + 'separator' => 'before', | |
| 183 | + 'selector' => '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title h3, {{WRAPPER}} .forum-card .card-title h3', | |
| 184 | + ] | |
| 185 | + ); | |
| 186 | + | |
| 187 | + $this->add_control( | |
| 188 | + 'title_color', | |
| 189 | + [ | |
| 190 | + 'label' => __('Title Color', 'forumax'), | |
| 191 | + 'type' => Controls_Manager::COLOR, | |
| 192 | + 'separator' => 'after', | |
| 193 | + 'selectors' => [ | |
| 194 | + '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title h3' => 'color: {{VALUE}}', | |
| 195 | + '{{WRAPPER}} .forum-card .card-title h3' => 'color: {{VALUE}}' | |
| 196 | + ], | |
| 197 | + ] | |
| 198 | + ); | |
| 199 | + | |
| 200 | + $this->add_group_control( | |
| 201 | + Group_Control_Typography::get_type(), | |
| 202 | + [ | |
| 203 | + 'name' => 'excerpt_typography', | |
| 204 | + 'label' => __('Excerpt Typography', 'forumax'), | |
| 205 | + 'selector' => '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title p, {{WRAPPER}} .forum-card .card-body', | |
| 206 | + ] | |
| 207 | + ); | |
| 208 | + | |
| 209 | + $this->add_control( | |
| 210 | + 'excerpt_color', | |
| 211 | + [ | |
| 212 | + 'label' => __('Excerpt Color', 'forumax'), | |
| 213 | + 'type' => Controls_Manager::COLOR, | |
| 214 | + 'selectors' => [ | |
| 215 | + '{{WRAPPER}} .forum-with-topics .topic-table .topic-contents .title p' => 'color: {{VALUE}}', | |
| 216 | + '{{WRAPPER}} .forum-card .card-body' => 'color: {{VALUE}}' | |
| 217 | + ], | |
| 218 | + ] | |
| 219 | + ); | |
| 220 | + | |
| 221 | + $this->end_controls_section(); | |
| 222 | + } | |
| 223 | + | |
| 224 | + protected function render (): void | |
| 225 | + { | |
| 226 | + $settings = $this->get_settings(); | |
| 227 | + $forum_id = !empty($settings[ 'forum_id' ]) ? $settings[ 'forum_id' ] : ''; | |
| 228 | + $cover_image = $settings[ 'cover_image' ]; | |
| 229 | + $post_thumbnail_url = !empty($cover_image[ 'url' ]) ? $cover_image[ 'url' ] : get_the_post_thumbnail_url($forum_id); | |
| 230 | + | |
| 231 | + $topics = new WP_Query(array( | |
| 232 | + 'post_type' => bbp_get_topic_post_type(), | |
| 233 | + 'order' => !empty($settings['order']) ? $settings['order'] : 'DESC', | |
| 234 | + 'posts_per_page' => !empty($settings['ppp']) ? $settings['ppp'] : 3, | |
| 235 | + 'post_parent' => $forum_id, | |
| 236 | + )); | |
| 237 | + | |
| 238 | + if ($forum_id) { | |
| 239 | + // Whitelist valid style values to prevent Local File Inclusion | |
| 240 | + $allowed_styles = array( '1', '2' ); | |
| 241 | + $style = isset( $settings['style'] ) && in_array( $settings['style'], $allowed_styles, true ) ? $settings['style'] : '1'; | |
| 242 | + include __DIR__ . "/inc/single-forum/single-forum-{$style}.php"; | |
| 243 | + } else { ?> | |
| 244 | + <div class="alert alert-warning" role="alert"> | |
| 245 | + <?php esc_html_e('Please select a forum.', 'forumax'); ?> | |
| 246 | + </div> | |
| 247 | + <?php | |
| 248 | + } | |
| 249 | + } | |
| 237 | 250 | } |