PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.6
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.6
8.0.5 8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 All 47 releases
gamipress / integrations / wpforo / includes / functions.php

functions.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.6, at integrations/wpforo/includes/functions.php

195 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package GamiPress\wpForo\Functions
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Overrides GamiPress AJAX Helper for selecting posts
13 *
14 * @since 1.0.0
15 */
16 function gamipress_wpforo_ajax_get_posts() {
17 // Security check, forces to die if not security passed
18 check_ajax_referer( 'gamipress_admin', 'nonce' );
19 global $wpdb;
20
21 if( isset( $_REQUEST['post_type'] ) ) {
22
23 // Get the user input
24 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( $_REQUEST['q'] ) : '';
25
26 if( in_array( 'wpforo_forum', $_REQUEST['post_type'] ) ) {
27 // Forums
28
29 $table = WPF()->tables->forums;
30 $boards = WPF()->tables->boards;
31
32 // Get the boards
33 $results_boards = $wpdb->get_results( $wpdb->prepare(
34 "SELECT boardid FROM {$boards}"
35 ) );
36
37 // Try to find the forums
38 $forums = $wpdb->get_results( $wpdb->prepare(
39 "SELECT * FROM {$table}
40 " . ( ! empty( $search ) ? "WHERE ( title LIKE '%{$search}%' OR title LIKE '{$search}%' )" : '' )
41 ) );
42
43 // Build the results array
44 $results = array();
45
46 foreach ( $forums as $forum ) {
47
48 // Results should meet same structure like posts
49 $results[] = array(
50 'ID' => $forum->forumid,
51 'post_title' => $forum->title,
52 );
53
54 }
55
56 if ( count( $results_boards ) > 1 ) {
57 foreach ( $results_boards as $board ){
58 if ( $board->boardid !== '0' ){
59 $table = $wpdb->prefix . 'wpforo_' . $board->boardid . '_forums';
60 // Get the forums
61 $results_forums = $wpdb->get_results( $wpdb->prepare(
62 "SELECT * FROM {$table}
63 " . ( ! empty( $search ) ? "WHERE ( title LIKE '%{$search}%' OR title LIKE '{$search}%' )" : '' )
64 ) );
65
66 foreach ($results_forums as $forum ) {
67 $forum_id = $board->boardid . '-' . $forum->forumid;
68 $results[] = array(
69 'ID' => $forum_id,
70 'post_title' => $forum->title,
71 );
72 }
73 }
74 }
75 }
76
77 // Return our results
78 wp_send_json_success( $results );
79 die;
80 } else if( in_array( 'wpforo_topic', $_REQUEST['post_type'] ) ) {
81 // Topics
82
83 $table = WPF()->tables->topics;
84 $boards = WPF()->tables->boards;
85
86 // Get the boards
87 $results_boards = $wpdb->get_results( $wpdb->prepare(
88 "SELECT boardid FROM {$boards}"
89 ) );
90
91 // Try to find the topics
92 $topics = $wpdb->get_results( $wpdb->prepare(
93 "SELECT * FROM {$table}
94 " . ( ! empty( $search ) ? "WHERE ( title LIKE '%{$search}%' OR title LIKE '{$search}%' )" : '' )
95 ) );
96
97 // Build the results array
98 $results = array();
99
100 foreach ( $topics as $topic ) {
101
102 // Results should meet same structure like posts
103 $results[] = array(
104 'ID' => $topic->topicid,
105 'post_title' => $topic->title,
106 'post_type' => gamipress_wpforo_get_forum_title( $topic->forumid ),
107 );
108
109 }
110
111 if ( count( $results_boards ) > 1 ) {
112 foreach ( $results_boards as $board ){
113 if ( $board->boardid !== '0' ){
114 $table = $wpdb->prefix . 'wpforo_' . $board->boardid . '_topics';
115 // Get the topics
116 $results_topics = $wpdb->get_results( $wpdb->prepare(
117 "SELECT * FROM {$table}
118 " . ( ! empty( $search ) ? "WHERE ( title LIKE '%{$search}%' OR title LIKE '{$search}%' )" : '' )
119 ) );
120
121 foreach ($results_topics as $topic ) {
122 $forum_id = $board->boardid . '-' . $topic->forumid;
123 $results[] = array(
124 'ID' => $board->boardid . '-' . $topic->topicid,
125 'post_title' => $topic->title,
126 'post_type' => gamipress_wpforo_get_forum_title( $forum_id ),
127 );
128 }
129 }
130 }
131 }
132
133 $response = array(
134 'results' => $results,
135 'more_results' => false,
136 );
137
138 // Return our results
139 wp_send_json_success( $response );
140 die;
141
142 }
143
144 }
145
146
147 }
148 add_action( 'wp_ajax_gamipress_wpforo_get_posts', 'gamipress_wpforo_ajax_get_posts', 5 );
149
150
151 function gamipress_wpforo_forum_options(){
152
153 }
154
155 // Helper function to get the forum title
156 function gamipress_wpforo_get_forum_title( $forum_id ) {
157
158 global $wpdb;
159
160 if ( strpos( $forum_id, '-' ) ) {
161 $board = explode('-', $forum_id)[0];
162 $forum_id = explode('-', $forum_id)[1];
163 $table = $table = $wpdb->prefix . 'wpforo_' . $board . '_forums';
164
165 } else {
166 $table = WPF()->tables->forums;
167 }
168
169 return $wpdb->get_var( $wpdb->prepare(
170 "SELECT f.title FROM {$table} AS f WHERE f.forumid = %d",
171 $forum_id
172 ) );
173
174 }
175
176 // Helper function to get the topic title
177 function gamipress_wpforo_get_topic_title( $topic_id ) {
178
179 global $wpdb;
180
181 if ( strpos( $topic_id, '-' ) ) {
182 $board = explode('-', $topic_id)[0];
183 $topic_id = explode('-', $topic_id)[1];
184 $table = $table = $wpdb->prefix . 'wpforo_' . $board . '_topics';
185
186 } else {
187 $table = WPF()->tables->topics;
188 }
189
190 return $wpdb->get_var( $wpdb->prepare(
191 "SELECT f.title FROM {$table} AS f WHERE f.topicid = %d",
192 $topic_id
193 ) );
194
195 }