PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.33
OttoKit: All-in-One Automation Platform v1.1.33
1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Integrations / wpforo / actions / wf-create-topic.php
suretriggers / src / Integrations / wpforo / actions Last commit date
add-user-to-group.php 10 months ago remove-user-from-group.php 10 months ago set-user-reputation.php 10 months ago wf-create-topic.php 10 months ago wf-delete-topic.php 10 months ago
wf-create-topic.php
194 lines
1 <?php
2 /**
3 * WfCreateTopic.
4 * php version 5.6
5 *
6 * @category WfCreateTopic
7 * @package SureTriggers
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers\Integrations\wpForo\Actions;
15
16 use SureTriggers\Integrations\AutomateAction;
17 use SureTriggers\Traits\SingletonLoader;
18 use SureTriggers\Integrations\WordPress\WordPress;
19 use Exception;
20 use wpforo\classes\Members;
21 use wpforo\classes\Permissions;
22
23 /**
24 * WfCreateTopic
25 *
26 * @category WfCreateTopic
27 * @package SureTriggers
28 * @author BSF <username@example.com>
29 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
30 * @link https://www.brainstormforce.com/
31 * @since 1.0.0
32 */
33 class WfCreateTopic extends AutomateAction {
34
35
36 /**
37 * Integration type.
38 *
39 * @var string
40 */
41 public $integration = 'wpForo';
42
43 /**
44 * Action name.
45 *
46 * @var string
47 */
48 public $action = 'wp_foro_create_topic';
49
50 use SingletonLoader;
51
52 /**
53 * Register an action.
54 *
55 * @param array $actions actions.
56 * @return array
57 */
58 public function register( $actions ) {
59 $actions[ $this->integration ][ $this->action ] = [
60 'label' => __( 'Create Topic', 'suretriggers' ),
61 'action' => $this->action,
62 'function' => [ $this, 'action_listener' ],
63 ];
64 return $actions;
65 }
66
67 /**
68 * Action listener.
69 *
70 * @param int $user_id user id.
71 * @param int $automation_id automation_id.
72 * @param array $fields template fields.
73 * @param array $selected_options saved template data.
74 * @throws Exception Exception.
75 *
76 * @return bool|array
77 */
78 public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
79
80 $user_email = $selected_options['wp_user_email'];
81
82 if ( ! function_exists( 'WPF' ) || ! class_exists( 'wpforo\classes\Members' ) || ! function_exists( 'wpfkey' ) ||
83 ! function_exists( 'wpfval' ) || ! function_exists( 'wpforo_length' ) || ! function_exists( 'wpforo_setting' ) || ! class_exists( 'wpforo\classes\Permissions' ) ) {
84 return false;
85 }
86
87 if ( is_email( $user_email ) ) {
88 $user = get_user_by( 'email', $user_email );
89 if ( $user ) {
90 $user_id = $user->ID;
91 WPF()->current_user = $user;
92 WPF()->current_userid = $user->ID;
93 WPF()->current_user_login = $user->user_login;
94 WPF()->current_user_email = $user->user_email;
95 WPF()->current_user_display_name = $user->display_name;
96 $member = new Members();
97 $user = $member->get_member( $user->ID );
98 if ( ! wpfkey( $user, 'groupid' ) || ! method_exists( $member, 'get_member' ) || ! method_exists( $member, 'synchronize_user' ) ) {
99 $member->synchronize_user( $user->ID );
100 $user = $member->get_member( $user->ID );
101 }
102 $user_meta = get_user_meta( $user->ID );
103 WPF()->current_user = $user;
104 WPF()->current_usermeta = $user_meta;
105 WPF()->current_user_groupid = WPF()->current_user['groupid'];
106 WPF()->current_user_secondary_groupids = WPF()->current_user['secondary_groupids'];
107 WPF()->current_user_groupids = array_unique( array_filter( array_merge( (array) WPF()->current_user_groupid, (array) WPF()->current_user_secondary_groupids ) ) );
108 WPF()->current_user_status = (string) wpfval( $user, 'status' );
109 $user_permissions = new Permissions();
110 WPF()->current_user_accesses = $user_permissions->get_forum_accesses_by_usergroup();
111 if ( function_exists( 'WPF' ) ) {
112 $forum_id = $selected_options['forum_id'];
113 $args['forumid'] = $forum_id;
114 $args['title'] = $selected_options['title'];
115 $args['body'] = preg_replace( '#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", (string) $selected_options['content'] );
116 $args['userid'] = $user_id;
117 $args['tags'] = $selected_options['topic_tags'];
118 $args['private'] = ( isset( $selected_options['topic_private'] ) && $selected_options['topic_private'] ? 1 : 0 );
119 WPF()->member->set_guest_cookies( $args );
120 $min = wpforo_setting( 'posting', 'topic_body_min_length' );
121 if ( $min ) {
122 if ( wpfkey( $args, 'body' ) && (int) $min > wpforo_length( $args['body'] ) ) {
123 return [
124 'status' => 'error',
125 'message' => 'The content is too short',
126 ];
127 }
128 }
129 if ( ! isset( $args['forumid'] ) ) {
130 return [
131 'status' => 'error',
132 'message' => 'Add Topic error: No forum selected',
133 ];
134 }
135
136 if ( ! WPF()->forum->get_forum( $args['forumid'] ) ) {
137 return [
138 'status' => 'error',
139 'message' => 'Add Topic error: No forum selected',
140 ];
141 }
142
143 if ( ! WPF()->perm->forum_can( 'ct', $args['forumid'] ) ) {
144 return [
145 'status' => 'error',
146 'message' => 'You don\'t have permission to create topic into this forum',
147 ];
148 }
149
150 if ( ! WPF()->perm->can_post_now() ) {
151 return [
152 'status' => 'error',
153 'message' => 'You are posting too quickly. Slow down.',
154 ];
155 }
156 $topicid = WPF()->topic->add( $args );
157 if ( $topicid ) {
158 return [
159 'topic' => WPF()->topic->get_topic( $topicid ),
160 'user' => WordPress::get_user_context( $args['userid'] ),
161 ];
162 } else {
163 return [
164 'status' => 'error',
165 'message' => 'Topic not created.',
166 ];
167 }
168 } else {
169 return [
170 'status' => 'error',
171 'message' => 'Can not create topic.',
172 ];
173 }
174 } else {
175 return [
176 'status' => 'error',
177 'message' => 'User not found.',
178 ];
179 }
180 } else {
181 $error = [
182 'status' => esc_attr__( 'Error', 'suretriggers' ),
183 'response' => esc_attr__( 'Please enter valid email address.', 'suretriggers' ),
184
185 ];
186
187 return $error;
188 }
189 }
190
191 }
192
193 WfCreateTopic::get_instance();
194