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