PluginProbe
Convertful – Your Ultimate On-Site Conversion Tool / 1.6
Convertful – Your Ultimate On-Site Conversion Tool v1.6
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.6, at convertful.php

232 lines 7.2 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.6
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_domain;
16 //$conv_domain = 'http://convertful.local';
17 $conv_domain = 'https://app.convertful.com';
18 $conv_file = __FILE__;
19 $conv_dir = plugin_dir_path( __FILE__ );
20 $conv_uri = plugins_url( '', __FILE__ );
21 $conv_version = preg_match( '~Version\: ([^\n]+)~', file_get_contents( __FILE__, NULL, NULL, 82, 150 ), $conv_matches ) ? $conv_matches[1] : FALSE;
22 unset( $conv_matches );
23
24 add_action( 'init', 'conv_init' );
25 function conv_init() {
26 if ( get_option( 'optinguru_owner_id' ) ) {
27 update_option( 'convertful_owner_id', get_option( 'optinguru_owner_id' ), TRUE );
28 update_option( 'convertful_site_id', get_option( 'optinguru_site_id', get_option( 'optinguru_website_id' ) ), FALSE );
29 update_option( 'convertful_token', get_option( 'optinguru_token' ), FALSE );
30 }
31 $owner_id = get_option( 'convertful_owner_id' );
32 if ( ! is_admin() AND $owner_id !== FALSE ) {
33 add_action( 'wp_enqueue_scripts', 'conv_enqueue_scripts' );
34 add_filter( 'script_loader_tag', 'conv_script_loader_tag', 10, 2 );
35 add_filter( 'the_content', 'conv_after_post_content' );
36 }
37 }
38
39 if ( is_admin() ) {
40 require $conv_dir . 'functions/admin_pages.php';
41 }
42
43 // Shortcodes
44 require $conv_dir . 'functions/shortcodes.php';
45
46 function conv_enqueue_scripts() {
47 global $conv_domain, $conv_version;
48 wp_enqueue_script( 'convertful-api', $conv_domain . '/Convertful.js', array(), $conv_version, TRUE );
49
50 $tags = array();
51 $the_tags = get_the_tags();
52 if ( is_array( $the_tags ) ) {
53 foreach ( $the_tags as $tag ) {
54 $tags[] = $tag->slug;
55 }
56 }
57
58 $categories = array();
59 $the_categories = get_the_category();
60 if ( is_array($the_categories)) {
61 foreach ( $the_categories as $category ) {
62 $categories[] = $category->slug;
63 }
64 }
65
66 $user_meta = wp_get_current_user();
67
68 wp_localize_script( 'convertful-api', 'convPlatformVars', array(
69 'postType' => get_post_type(),
70 'categories' => $categories,
71 'tags' => $tags,
72 'userRoles' => ( $user_meta instanceof WP_User AND ! empty($user_meta->roles) ) ? $user_meta->roles : array( 'guest' ),
73 ) );
74 }
75
76 function conv_script_loader_tag( $tag, $handle ) {
77 if ( $handle !== 'convertful-api' ) {
78 return $tag;
79 }
80 global $conv_domain;
81
82 return '<script type="text/javascript" id="convertful-api" src="' . $conv_domain . '/Convertful.js" data-owner="' . get_option( 'convertful_owner_id' ) . '" async="async"></script>';
83 }
84
85 add_action( 'admin_enqueue_scripts', 'conv_admin_enqueue_scripts' );
86 function conv_admin_enqueue_scripts( $hook ) {
87 if ( $hook !== 'tools_page_conv-settings' ) {
88 return;
89 }
90
91 global $conv_uri, $conv_version;
92 wp_enqueue_style( 'conv-main', $conv_uri . '/css/main.css', array(), $conv_version );
93 wp_enqueue_script( 'conv-main', $conv_uri . '/js/main.js', array( 'jquery' ), $conv_version );
94 }
95
96 add_action( 'activated_plugin', 'conv_activated_plugin' );
97 function conv_activated_plugin( $plugin ) {
98 global $conv_file;
99 if ( $plugin !== plugin_basename( $conv_file ) ) {
100 return;
101 }
102 // Taking into account promotional links
103 $ref_data = get_transient( 'convertful-ref' );
104 if ( $ref_data AND strpos( $ref_data, '|' ) !== FALSE ) {
105 $ref_data = explode( '|', $ref_data );
106 // Preventing violations with lifetime values
107 if ( time() - intval( $ref_data[1] ) < DAY_IN_SECONDS ) {
108 update_option( 'convertful_ref', $ref_data[0], FALSE );
109 }
110 delete_transient( 'convertful-ref' );
111 }
112 $owner_id = get_option( 'convertful_owner_id' );
113 if ( $owner_id === FALSE ) {
114 $redirect_location = admin_url( 'tools.php?page=conv-settings' );
115 if ( wp_doing_ajax() ) {
116 wp_send_json_success(
117 array(
118 'location' => $redirect_location,
119 )
120 );
121 }
122 wp_redirect( $redirect_location );
123 exit;
124 }
125 }
126
127 function conv_after_post_content( $content ) {
128 if ( is_single() ) {
129 $content .= '<div class="conv-place conv-place_after_post"></div>';
130 }
131
132 return $content;
133 }
134
135 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'conv_plugin_action_links' );
136 function conv_plugin_action_links( $links ) {
137 return array_merge(
138 array(
139 '<a href="' . admin_url( 'tools.php?page=conv-settings' ) . '">' . __( 'Settings' ) . '</a>',
140 ), $links
141 );
142 }
143
144
145 register_uninstall_hook( $conv_file, 'conv_uninstall' );
146 function conv_uninstall() {
147 // Options cleanup
148 foreach ( array( 'owner_id', 'site_id', 'website_id', 'token', 'ref' ) as $option_name ) {
149 delete_option( 'optinguru_' . $option_name );
150 delete_option( 'convertful_' . $option_name );
151 }
152 }
153
154 if ( wp_doing_ajax() OR defined( 'DOING_AJAX' ) ) {
155
156 add_action( 'wp_ajax_conv_get_info', 'conv_get_info' );
157 add_action( 'wp_ajax_nopriv_conv_get_info', 'conv_get_info' );
158 function conv_get_info() {
159
160 if ( $_POST['access_token'] !== get_option( 'convertful_token' )) {
161 wp_send_json_error( array(
162 'access_token' => 'Wrong access token',
163 ) );
164 }
165
166 $tags = array();
167 foreach ( get_tags() as $tag ) {
168 $tags[ $tag->slug ] = $tag->name;
169 }
170
171 $categories = array();
172 foreach ( get_categories() as $category ) {
173 $categories[ $category->slug ] = $category->name;
174 }
175
176 $post_types = array();
177 foreach ( get_post_types( array( 'public' => TRUE ), 'objects' ) as $post_type ) {
178 $post_type_name = isset($post_type->name) ? $post_type->name : NULL;
179 $post_type_title = (isset($post_type->labels) AND isset($post_type->labels->singular_name)) ? $post_type->labels->singular_name : $post_type['name'];
180 if ($post_type_name AND $post_type_title)
181 {
182 $post_types[ $post_type_name ] = $post_type_title;
183 }
184 }
185
186 global $wp_roles;
187 $user_roles = array();
188 foreach ( apply_filters('editable_roles', $wp_roles->roles) as $user_role_name => $user_role ) {
189 $user_roles[ $user_role_name ] = isset($user_role['name']) ? $user_role['name'] : $user_role_name;
190 }
191 $user_roles['guest'] = 'Guest (Unauthenticated)';
192
193 $result = array(
194 'tags' => $tags,
195 'categories' => $categories,
196 'post_types' => $post_types,
197 'user_roles' => $user_roles,
198 );
199
200 wp_send_json_success($result);
201 }
202
203
204 add_action( 'wp_ajax_conv_complete_authorization', 'conv_complete_authorization' );
205 add_action( 'wp_ajax_nopriv_conv_complete_authorization', 'conv_complete_authorization' );
206 function conv_complete_authorization() {
207
208 if ( $_POST['access_token'] !== get_option( 'convertful_token' )) {
209 wp_send_json_error( array(
210 'access_token' => 'Wrong access token',
211 ) );
212 }
213
214 foreach ( array( 'owner_id', 'site_id' ) as $key ) {
215 if ( ! isset( $_POST[ $key ] ) OR empty( $_POST[ $key ] ) ) {
216 wp_send_json_error( array(
217 $key => 'Wrong parameters for authorization (owner_id or site_id missing)',
218 ) );
219 }
220 }
221
222 update_option( 'convertful_owner_id', (int) $_POST['owner_id'], TRUE );
223 update_option( 'convertful_site_id', (int) $_POST['site_id'], FALSE );
224
225 wp_send_json_success();
226 }
227
228
229 }
230
231
232