PluginProbe
Convertful – Your Ultimate On-Site Conversion Tool / 1.7
Convertful – Your Ultimate On-Site Conversion Tool v1.7
trunk 1.0 1.1 1.3 1.4 1.5 1.6 1.7 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
convertful / convertful.php

convertful.php in Convertful – Your Ultimate On-Site Conversion Tool 1.7, at convertful.php

273 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
2
3 /**
4 * Plugin Name: Convertful - Your Ultimate On-Site Conversion Tool
5 * Version: 1.7
6 * Plugin URI: https://convertful.com/
7 * Description: All the modern on-site conversion solutions, natively integrates with all modern Email Marketing Platforms.
8 * Author: Convertful
9 * License: GPLv2 or later
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: convertful
12 */
13
14 // Global variables for plugin usage (global declaration is needed here for WP CLI compatibility)
15 global $conv_file, $conv_dir, $conv_uri, $conv_version, $conv_config;
16 $conv_file = __FILE__;
17 $conv_dir = plugin_dir_path( __FILE__ );
18 $conv_uri = plugins_url( '', __FILE__ );
19 $conv_version = preg_match( '~Version\: ([^\n]+)~', file_get_contents( __FILE__, NULL, NULL, 82, 150 ), $conv_matches ) ? $conv_matches[1] : FALSE;
20 unset( $conv_matches );
21
22 if (file_exists($conv_dir.'config.php'))
23 {
24 $conv_config = require $conv_dir.'config.php';
25 }
26
27 /**
28 * Get script id
29 * @return string
30 */
31 function conv_get_script_id()
32 {
33 global $conv_config;
34 $url = wp_parse_url($conv_config['host']);
35 if ( ! preg_match('/^(.*?)(convertful|devcf)\.[a-z]{3,5}$/', $url['host']))
36 {
37 return 'optin-api';
38 }
39 return 'convertful-api';
40 }
41
42 /**
43 * Get script file name
44 * @return string
45 */
46 function conv_get_script_filename()
47 {
48 return conv_get_script_id() === 'convertful-api'
49 ? 'Convertful.js'
50 : 'optin.js';
51 }
52
53 add_action( 'init', 'conv_init' );
54 function conv_init() {
55 if ( get_option( 'optinguru_owner_id' ) ) {
56 update_option( 'conv_owner_id', get_option( 'optinguru_owner_id' ), TRUE );
57 update_option( 'conv_site_id', get_option( 'optinguru_site_id', get_option( 'optinguru_website_id' ) ), FALSE );
58 update_option( 'conv_token', get_option( 'optinguru_token' ), FALSE );
59 }
60 if ( get_option( 'convertful_owner_id' ) ) {
61 update_option( 'conv_owner_id', get_option( 'convertful_owner_id' ), TRUE );
62 update_option( 'conv_site_id', get_option( 'convertful_site_id' ), FALSE );
63 update_option( 'conv_token', get_option( 'convertful_token' ), FALSE );
64 }
65 $owner_id = get_option( 'conv_owner_id' );
66 if ( ! is_admin() AND $owner_id !== FALSE ) {
67 add_action( 'wp_enqueue_scripts', 'conv_enqueue_scripts' );
68 add_filter( 'script_loader_tag', 'conv_script_loader_tag', 10, 2 );
69 add_filter( 'the_content', 'conv_after_post_content' );
70 }
71 }
72
73 if ( is_admin() ) {
74 require $conv_dir . 'functions/admin_pages.php';
75 }
76
77 // Shortcodes
78 require $conv_dir . 'functions/shortcodes.php';
79
80 function conv_enqueue_scripts() {
81 global $conv_config, $conv_version;
82 $script_id = conv_get_script_id();
83 wp_enqueue_script( $script_id, $conv_config['host'].'/'.conv_get_script_filename(), array(), $conv_version, TRUE );
84
85 $tags = array();
86 $the_tags = get_the_tags();
87 if ( is_array( $the_tags ) ) {
88 foreach ( $the_tags as $tag ) {
89 $tags[] = $tag->slug;
90 }
91 }
92
93 $categories = array();
94 $the_categories = get_the_category();
95 if ( is_array($the_categories)) {
96 foreach ( $the_categories as $category ) {
97 $categories[] = $category->slug;
98 }
99 }
100
101 $user_meta = wp_get_current_user();
102
103 wp_localize_script( $script_id, 'convPlatformVars', array(
104 'postType' => get_post_type(),
105 'categories' => $categories,
106 'tags' => $tags,
107 'userRoles' => ( $user_meta instanceof WP_User AND ! empty($user_meta->roles) ) ? $user_meta->roles : array( 'guest' ),
108 ) );
109 }
110
111 function conv_script_loader_tag( $tag, $handle ) {
112 global $conv_config;
113 $script_id = conv_get_script_id();
114 if ( $handle !== $script_id ) {
115 return $tag;
116 }
117 $script = sprintf( '%s/%s?owner=%s', $conv_config['host'], conv_get_script_filename(), get_option( 'conv_owner_id' ) );
118 return sprintf(
119 '<script type="text/javascript" id="%s" src="%s" async="async"></script>',
120 $script_id,
121 $script
122 );
123 }
124
125 add_action( 'admin_enqueue_scripts', 'conv_admin_enqueue_scripts' );
126 function conv_admin_enqueue_scripts( $hook ) {
127 if ( $hook !== 'tools_page_conv-settings' ) {
128 return;
129 }
130
131 global $conv_uri, $conv_version;
132 wp_enqueue_style( 'conv-main', $conv_uri . '/css/main.css', array(), $conv_version );
133 wp_enqueue_script( 'conv-main', $conv_uri . '/js/main.js', array( 'jquery' ), $conv_version );
134 }
135
136 add_action( 'activated_plugin', 'conv_activated_plugin' );
137 function conv_activated_plugin( $plugin ) {
138 global $conv_file;
139 if ( $plugin !== plugin_basename( $conv_file ) ) {
140 return;
141 }
142 // Taking into account promotional links
143 $ref_data = get_transient( 'conv-ref' );
144 if ( $ref_data AND strpos( $ref_data, '|' ) !== FALSE ) {
145 $ref_data = explode( '|', $ref_data );
146 // Preventing violations with lifetime values
147 if ( time() - intval( $ref_data[1] ) < DAY_IN_SECONDS ) {
148 update_option( 'conv_ref', $ref_data[0], FALSE );
149 }
150 delete_transient( 'conv-ref' );
151 }
152 $owner_id = get_option( 'conv_owner_id' );
153 if ( $owner_id === FALSE ) {
154 $redirect_location = admin_url( 'tools.php?page=conv-settings' );
155 if ( wp_doing_ajax() ) {
156 wp_send_json_success(
157 array(
158 'location' => $redirect_location,
159 )
160 );
161 }
162 wp_redirect( $redirect_location );
163 exit;
164 }
165 }
166
167 function conv_after_post_content( $content ) {
168 if ( is_single() ) {
169 $content .= '<div class="conv-place conv-place_after_post"></div>';
170 }
171
172 return $content;
173 }
174
175 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'conv_plugin_action_links' );
176 function conv_plugin_action_links( $links ) {
177 return array_merge(
178 array(
179 '<a href="' . admin_url( 'tools.php?page=conv-settings' ) . '">' . __( 'Settings' ) . '</a>',
180 ), $links
181 );
182 }
183
184
185 register_uninstall_hook( $conv_file, 'conv_uninstall' );
186 function conv_uninstall() {
187 // Options cleanup
188 foreach ( array( 'owner_id', 'site_id', 'website_id', 'token', 'ref' ) as $option_name ) {
189 delete_option( 'optinguru_' . $option_name );
190 delete_option( 'convertful_' . $option_name );
191 delete_option( 'conv_' . $option_name );
192 }
193 }
194
195 if ( wp_doing_ajax() OR defined( 'DOING_AJAX' ) ) {
196
197 add_action( 'wp_ajax_conv_get_info', 'conv_get_info' );
198 add_action( 'wp_ajax_nopriv_conv_get_info', 'conv_get_info' );
199 function conv_get_info() {
200
201 if ( $_POST['access_token'] !== get_option( 'conv_token' )) {
202 wp_send_json_error( array(
203 'access_token' => 'Wrong access token',
204 ) );
205 }
206
207 $tags = array();
208 foreach ( get_tags() as $tag ) {
209 $tags[ $tag->slug ] = $tag->name;
210 }
211
212 $categories = array();
213 foreach ( get_categories() as $category ) {
214 $categories[ $category->slug ] = $category->name;
215 }
216
217 $post_types = array();
218 foreach ( get_post_types( array( 'public' => TRUE ), 'objects' ) as $post_type ) {
219 $post_type_name = isset($post_type->name) ? $post_type->name : NULL;
220 $post_type_title = (isset($post_type->labels) AND isset($post_type->labels->singular_name)) ? $post_type->labels->singular_name : $post_type['name'];
221 if ($post_type_name AND $post_type_title)
222 {
223 $post_types[ $post_type_name ] = $post_type_title;
224 }
225 }
226
227 global $wp_roles;
228 $user_roles = array();
229 foreach ( apply_filters('editable_roles', $wp_roles->roles) as $user_role_name => $user_role ) {
230 $user_roles[ $user_role_name ] = isset($user_role['name']) ? $user_role['name'] : $user_role_name;
231 }
232 $user_roles['guest'] = 'Guest (Unauthenticated)';
233
234 $result = array(
235 'tags' => $tags,
236 'categories' => $categories,
237 'post_types' => $post_types,
238 'user_roles' => $user_roles,
239 );
240
241 wp_send_json_success($result);
242 }
243
244
245 add_action( 'wp_ajax_conv_complete_authorization', 'conv_complete_authorization' );
246 add_action( 'wp_ajax_nopriv_conv_complete_authorization', 'conv_complete_authorization' );
247 function conv_complete_authorization() {
248
249 if ( $_POST['access_token'] !== get_option( 'conv_token' )) {
250 wp_send_json_error( array(
251 'access_token' => 'Wrong access token',
252 ) );
253 }
254
255 foreach ( array( 'owner_id', 'site_id' ) as $key ) {
256 if ( ! isset( $_POST[ $key ] ) OR empty( $_POST[ $key ] ) ) {
257 wp_send_json_error( array(
258 $key => 'Wrong parameters for authorization (owner_id or site_id missing)',
259 ) );
260 }
261 }
262
263 update_option( 'conv_owner_id', (int) $_POST['owner_id'], TRUE );
264 update_option( 'conv_site_id', (int) $_POST['site_id'], FALSE );
265
266 wp_send_json_success();
267 }
268
269
270 }
271
272
273