Changeset 2398796
- Timestamp:
- 10/13/2020 03:45:55 PM (5 years ago)
- Location:
- quentn-wp/trunk
- Files:
-
- 1 added
- 6 edited
-
admin/class-quentn-wp-admin.php (modified) (5 diffs)
-
admin/partials/quentn-wp-dashboard.php (modified) (2 diffs)
-
includes/class-quentn-wp-rest-api-controller.php (modified) (7 diffs)
-
includes/class-quentn-wp-web-tracking.php (added)
-
includes/class-quentn-wp.php (modified) (2 diffs)
-
quentn-wp.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
quentn-wp/trunk/admin/class-quentn-wp-admin.php
r2371136 r2398796 351 351 $settings = array( 352 352 array( 353 'option_group' => 'web_tracking_options_group',354 'option_name' => 'quentn_web_tracking_enabled'355 ),356 array(357 'option_group' => 'web_tracking_options_group',358 'option_name' => 'quentn_web_tracking_consent_method'359 ),360 array(361 353 'option_group' => 'quentn_tags_options_group', 362 354 'option_name' => 'quentn_tags_wp_user' … … 374 366 //add values for settings api, add_settings_section 375 367 $sections = array( 376 array(377 'id' => 'quentn_web_tracking_option',378 'title' => __( 'Web Tracking Settings', 'quentn-wp'),379 'callback' => '__return_false',380 'page' => 'quentn-dashboard-web-tracking'381 ),382 368 array( 383 369 'id' => 'quentn_tags_option', … … 416 402 $fields = array(); 417 403 $fields[] = array( 418 'id' => 'quentn_web_tracking_enabled',419 'title' => __( 'Web Tracking', 'quentn-wp' ),420 'callback' => array( $this, 'field_quentn_web_tracking' ),421 'page' => 'quentn-dashboard-web-tracking',422 'section' => 'quentn_web_tracking_option',423 );424 425 if( $this->is_confirmation_required_for_web_tracking() ) {426 $fields[] = array(427 'id' => 'quentn_web_tracking_consent_method',428 'title' => __('Consent Method', 'quentn-wp'),429 'callback' => array( $this, 'field_quentn_consent_method' ),430 'page' => 'quentn-dashboard-web-tracking',431 'section' => 'quentn_web_tracking_option',432 );433 }434 435 $fields[] = array(436 404 'id' => 'quentn_auto_login_redirect_url', 437 405 'title' => __( 'Redirect URL', 'quentn-wp' ), … … 814 782 815 783 /** 816 * Display web tracking enabled field 817 * 818 * @since 1.0.0 819 * @access public 820 * @return void 821 */ 822 public function field_quentn_web_tracking() 823 { 824 $value = esc_attr( get_option( 'quentn_web_tracking_enabled' ) ); 825 ?> 826 <input type="checkbox" class="form-control" value="1" name="quentn_web_tracking_enabled" id="quentn_web_tracking_enabled" <?php checked( $value); disabled( ! $this->api_handler->is_connected_with_quentn() || ! $this->api_handler->is_web_tracking_enabled() || ! $this->is_domain_registered( $_SERVER['HTTP_HOST'], $this->api_handler->get_registered_domains() ) ); ?>> 827 <?php 828 } 829 830 /** 831 * Display web tracking consent methods dropdown 832 * 833 * @since 1.0.0 834 * @access public 835 * @return void 836 */ 837 public function field_quentn_consent_method() 838 { 839 $value = esc_attr( get_option( 'quentn_web_tracking_consent_method' ) ); 840 ?> 841 <select name="quentn_web_tracking_consent_method" id="quentn_web_tracking_consent_method" <?php disabled( ! get_option( 'quentn_web_tracking_enabled' ) || ! $this->api_handler->is_connected_with_quentn() || ! $this->api_handler->is_web_tracking_enabled() || ! $this->is_domain_registered( $_SERVER['HTTP_HOST'], $this->api_handler->get_registered_domains() ) ); ?>> 842 <option value="confirm-by-server" <?php selected( $value, 'confirm-by-server' ); ?>><?php _e( 'Confirm By Server', 'quentn-wp' ) ?></option> 843 <option value="cookie-notice" <?php selected( $value, 'cookie-notice' ); disabled( ! Helper::is_cookie_notice_plugin_enabled() ) ?>>Cookie Notice</option> 844 <option value="quentn-overlay" <?php selected( $value, 'quentn-overlay' ); ?>><?php _e('Quentn Overlay', 'quentn-wp' ) ?></option> 845 </select> 846 <?php 847 } 848 849 /** 850 * Display web tracking consent methods dropdown 784 * Display redirect url after auto login 851 785 * 852 786 * @since 1.1.0 … … 1040 974 1041 975 /** 1042 * Searches the array for a given domain and returns the ID of domain if found1043 *1044 * @since 1.0.01045 * @access public1046 * @param string $needle_domain the searched domain1047 * @param array $haystack_domains1048 * @return int|bool1049 */1050 public function get_domain_id( $needle_domain, $haystack_domains ) {1051 1052 foreach( $haystack_domains as $domain ) {1053 if ( $this->compare_domain( $needle_domain, $domain['domain'] ) ) {1054 return $domain['id'];1055 }1056 }1057 return false;1058 }1059 1060 /**1061 * Searches the array for a given value1062 *1063 * @since 1.0.01064 * @access public1065 * @param string $needle_domain the searched domain1066 * @param array $haystack_domains1067 * @return bool1068 */1069 public function is_domain_registered( $needle_domain, $haystack_domains )1070 {1071 foreach ( $haystack_domains as $domain ) {1072 if ( $this->compare_domain( $needle_domain, $domain ) ) {1073 return true;1074 }1075 }1076 return false;1077 }1078 1079 /**1080 * Compare the two domain1081 *1082 * @since 1.0.01083 * @access public1084 * @param string $domain_11085 * @param string $domain_21086 * @param int $level the level upto which the domain will be compared1087 * @return bool1088 */1089 public function compare_domain( $domain_1, $domain_2, $level = 0 ) {1090 1091 //add http:// if needed1092 $domain_1 = ( parse_url( $domain_1, PHP_URL_SCHEME ) ) ? $domain_1 : 'http://'.$domain_1;1093 $domain_2 = ( parse_url( $domain_2, PHP_URL_SCHEME ) ) ? $domain_2 : 'http://'.$domain_2;1094 1095 //skip domain upto specific level1096 $domain_1_host = $this->skip_subdomain_upto_specific_level( parse_url( $domain_1, PHP_URL_HOST ), $level );1097 $domain_2_host = $this->skip_subdomain_upto_specific_level( parse_url( $domain_2, PHP_URL_HOST ), $level );1098 1099 if ( $domain_1_host == $domain_2_host ) {1100 return true;1101 }1102 return false;1103 }1104 1105 /**1106 * Skip domain parts to specifc level1107 *1108 * @since 1.0.01109 * @access public1110 * @param string $host url to skip1111 * @param int $level the level to skip the parts1112 * @return string1113 */1114 public function skip_subdomain_upto_specific_level( $host, $level = 0 ) {1115 1116 $host_data = explode( ".", $host );1117 1118 //if host contains www , ignore it by adding one more level to skip1119 if( $host_data[0] === 'www' ) {1120 $level += 1;1121 }1122 //check if host contains subdomains1123 if ( count( $host_data ) > 2 ) {1124 //skip sudomains upto given level1125 for ( $x = 0; $x < $level; $x++ ) {1126 unset( $host_data[$x] );1127 //keep alteast last two part of host e.g example.com1128 if( count( $host_data ) == 2 ) {1129 break;1130 }1131 }1132 }1133 return implode( ".", $host_data );1134 }1135 1136 1137 /**1138 * Get web tracking code1139 *1140 * @since 1.0.01141 * @access public1142 * @return string1143 */1144 public function get_quentn_web_tracking_code() {1145 //get web tracking response1146 $response = $this->api_handler->get_web_tracking_response();1147 //if domains are not found then return empty string1148 if( ! isset( $response['data']['domains'] ) ) {1149 return '';1150 }1151 //get domain ID1152 $domain_id = $this->get_domain_id( $_SERVER['HTTP_HOST'], $response['data']['domains'] );1153 1154 if ( ! $domain_id ) {1155 return '';1156 }1157 //get array key from domain ID1158 if ( $domain_id ) {1159 $domain_key = array_search($domain_id, array_column($response['data']['domains'], 'id'));1160 }1161 1162 $tracking_host_url = isset( $response['data']['trackingHostUrl'] ) ? $response['data']['trackingHostUrl'] : '';1163 $system_host_url = isset( $response['data']['systemHostUrl'] ) ? $response['data']['systemHostUrl'] : '';1164 $js_source = isset( $response['data']['js_source'] ) ? $response['data']['js_source'] : '';1165 $domain_data = isset( $response['data']['domains'][$domain_key] ) ? $response['data']['domains'][$domain_key] : '';1166 1167 $set_values_data = array(1168 'idSite' => $domain_data['piwik_site_id'],1169 'trackingHostUrl' => "'$tracking_host_url'",1170 'trackAnonymusUser' => $domain_data['track_anonymous'],1171 'creq' => $domain_data['confirmation_required'],1172 'systemHostUrl' => "'$system_host_url'",1173 );1174 1175 //set tracking values in required format for quentn1176 $set_value_string = $this->set_tracking_values( $set_values_data );1177 1178 $web_tracking = "<!-- Quentn tracking code -->1179 <script>1180 var _qntn = _qntn || [];1181 {$set_value_string}1182 (function (d, s, id, q){1183 if (d.readyState === 'complete') {1184 q.push(['domReady']);1185 } else {1186 d.addEventListener('DOMContentLoaded', function () {1187 q.push(['domReady']);1188 });1189 }1190 var js, fjs = d.getElementsByTagName(s)[0];1191 if (d.getElementById(id))1192 return;1193 js = d.createElement(s);1194 js.id = id;1195 js.src = '{$js_source}';1196 fjs.parentNode.insertBefore(js, fjs);1197 }(document, 'script', 'quentn-tracking-jssdk', _qntn));1198 </script><!-- /Quentn tracking code -->";1199 1200 if( $domain_data['confirmation_required'] && get_option( 'quentn_web_tracking_consent_method' ) == 'quentn-overlay' && isset( $domain_data['confirmation_overlay'] ) ) {1201 $web_tracking.= $domain_data['confirmation_overlay'];1202 }elseif($domain_data['confirmation_required'] && get_option('quentn_web_tracking_consent_method')=='cookie-notice' && Helper::is_cookie_notice_plugin_enabled()) {1203 $web_tracking.= "<!-- Quentn bridge to Cookie Notice -->1204 <script>1205 ( function ( $ ) {1206 $( document ).ready( function () {1207 _qntn.push(['getConfirmation', function(status) {1208 if (status && !$.fn.getCookieNotice()) {1209 $.fn.setCookieNotice('accept');1210 }1211 }]);1212 } );1213 $( document ).on( 'setCookieNotice', function ( e) {1214 _qntn.push(['setConfirmation', true]);1215 } );1216 } )( jQuery );1217 </script>1218 <!-- /Quentn bridge to Cookie Notice -->";1219 }1220 return $web_tracking;1221 }1222 1223 /**1224 * Check if web tracking is enabled at Quentn host1225 *1226 * @since 1.0.01227 * @access public1228 * @return bool1229 */1230 public function is_confirmation_required_for_web_tracking()1231 {1232 $return = false;1233 //get web tracking response1234 $response = $this->api_handler->get_web_tracking_response();1235 1236 if( ! isset( $response['data']['domains'] ) ) {1237 return $return;1238 }1239 //get domain ID among all registered domain at quentn host1240 $domain_id = $this->get_domain_id( $_SERVER['HTTP_HOST'], $response['data']['domains'] );1241 //get array index1242 if ( ! $domain_id ) {1243 return $return;1244 }1245 1246 $domain_key = array_search( $domain_id, array_column( $response['data']['domains'], 'id' ) );1247 1248 $domain_data = $response['data']['domains'][$domain_key];1249 1250 if( isset( $domain_data['confirmation_required'] ) && $domain_data['confirmation_required'] ) {1251 $return = true;1252 }1253 1254 return $return;1255 }1256 1257 /**1258 * Convert tracking values into string format to print in web analytics code1259 *1260 * @since 1.0.01261 * @access private1262 * @param array $data1263 * @return string1264 */1265 private function set_tracking_values( $data ) {1266 $return = '';1267 foreach ( $data as $key=>$value ) {1268 if( $value ) {1269 //convert 1 to true for javascript text1270 $val = ( $value==1 ) ? 'true' : $value;1271 $return.= "_qntn.push(['setValue','{$key}', {$val}]);\n";1272 }1273 }1274 return $return;1275 }1276 1277 /**1278 976 * Set screen options 1279 977 * -
quentn-wp/trunk/admin/partials/quentn-wp-dashboard.php
r2371136 r2398796 54 54 echo '</form>'; 55 55 } elseif ( $active_tab == "quentn_web_tracking_tab" ) { //display web tracking options 56 $web_tracking = new Quentn_Wp_Web_Tracking(); 56 57 echo '<form method="post" action="options.php">'; 57 58 if( get_option('quentn_web_tracking_enabled') ) { 58 update_option("quentn_web_tracking_code", $ this->get_quentn_web_tracking_code() );59 update_option("quentn_web_tracking_code", $web_tracking->get_quentn_web_tracking_code() ); 59 60 } else { //if web tracking option is disabled, we will delete previously saved tracking code 60 61 delete_option('quentn_web_tracking_code'); … … 70 71 ); 71 72 } 72 elseif( $this->api_handler->is_connected_with_quentn() && ! $ this->is_domain_registered( $_SERVER['HTTP_HOST'], $this->api_handler->get_registered_domains() ) ) {73 elseif( $this->api_handler->is_connected_with_quentn() && ! $web_tracking->is_domain_registered( $_SERVER['HTTP_HOST'], $this->api_handler->get_registered_domains() ) ) { 73 74 if ( ! empty( $this->api_handler->error_messages ) ) { 74 75 $this->show_errors( $this->api_handler->error_messages ); -
quentn-wp/trunk/includes/class-quentn-wp-rest-api-controller.php
r2371136 r2398796 60 60 */ 61 61 private $get_user_roles; 62 63 /** 64 * The base URL for route to update web tracking code 65 * 66 * @since 1.1.1 67 * @access private 68 * @var string 69 */ 70 private $get_tracking; 62 71 63 72 … … 77 86 $this->get_page_restrictions = '/get-page-restrictions'; 78 87 $this->get_user_roles = '/get-user-roles'; 79 88 $this->get_tracking = '/get-tracking'; 80 89 } 81 90 … … 199 208 // Here we register our callback. The callback is fired when this endpoint is matched by the WP_REST_Server class. 200 209 'callback' => array( $this, 'quentn_create_user' ), 210 // Here we register our permissions callback. The callback is fired before the main callback to check if the current user can access the endpoint. 211 'permission_callback' => array( $this, 'quentn_check_credentials' ), 212 213 'args' => array( 214 'data' => array( 215 'required' => true, 216 'type' => 'string', 217 ), 218 'vu' => array( 219 'required' => true, 220 'type' => 'integer', 221 ), 222 ), 223 224 )); 225 226 //register route to get tracking code when settings is saved in Quentn 227 register_rest_route( $this->namespace, $this->get_tracking, array( 228 // By using this constant we ensure that when the WP_REST_Server changes our readable endpoints will work as intended. 229 'methods' => \WP_REST_Server::CREATABLE, 230 // Here we register our callback. The callback is fired when this endpoint is matched by the WP_REST_Server class. 231 'callback' => array( $this, 'quentn_get_tracking_code' ), 201 232 // Here we register our permissions callback. The callback is fired before the main callback to check if the current user can access the endpoint. 202 233 'permission_callback' => array( $this, 'quentn_check_credentials' ), … … 305 336 } 306 337 return rest_ensure_response( json_encode( $restricted_pages ) ); 307 308 309 338 } 310 339 … … 359 388 //insert user in wordpress 360 389 $user_id = wp_insert_user( $qn_userdata ); 390 // On success, add user meta last login as false 391 if ( ! is_wp_error( $user_id ) ) { 392 update_user_meta( $user_id, 'quentn_last_login', 0 ); 393 } 361 394 } 362 395 … … 385 418 386 419 do_action( 'quentn_user_register', $new_user ); 387 //add user meta last login as false388 update_user_meta( $new_user->ID, 'quentn_last_login', 0 );389 420 390 421 //send email if set by quentn call … … 399 430 400 431 return rest_ensure_response( 'Data Successfully Updated' ); 432 } 433 434 /** 435 * Get list of all wp roles 436 * 437 * @since 1.1.1 438 * @access public 439 * @return array 440 */ 441 public function quentn_get_tracking_code( ) { 442 $web_tracking = new Quentn_Wp_Web_Tracking(); 443 if( ! get_option('quentn_web_tracking_enabled') ) { 444 return rest_ensure_response( array( 'saved' => 0 ) ); 445 } 446 update_option("quentn_web_tracking_code", $web_tracking->get_quentn_web_tracking_code() ); 447 return rest_ensure_response( array( 'saved' => 1 ) ); 401 448 } 402 449 -
quentn-wp/trunk/includes/class-quentn-wp.php
r2371136 r2398796 75 75 $this->version = QUENTN_WP_VERSION; 76 76 } else { 77 $this->version = '1.1. 0';77 $this->version = '1.1.1'; 78 78 } 79 79 $this->plugin_name = 'quentn-wp'; … … 158 158 159 159 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'vendor/autoload.php'; 160 161 /** 162 * The class responsible for handling web tracking code 163 */ 164 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-quentn-wp-web-tracking.php'; 160 165 161 166 /** -
quentn-wp/trunk/quentn-wp.php
r2371136 r2398796 17 17 * Plugin URI: https://docs.quentn.com/de/beta-quentn-wordpress-plugin/installieren-und-verbinden 18 18 * Description: This plugin allows you to restrict access to specific pages, create custom access links and create dynamic page countdowns. Optionally, you can connect your Quentn account to your WordPress installation to share contacts and manage access restrictions through Quentn. 19 * Version: 1.1. 019 * Version: 1.1.1 20 20 * Author: Quentn.com GmbH 21 21 * Author URI: https://quentn.com/ … … 35 35 define( "TABLE_QUENTN_RESTRICTIONS", 'qntn_restrictions' ); 36 36 define( "TABLE_QUENTN_USER_DATA", 'qntn_user_data' ); 37 define( 'QUENTN_WP_VERSION', '1.1. 0' );37 define( 'QUENTN_WP_VERSION', '1.1.1' ); 38 38 39 39 /** -
quentn-wp/trunk/readme.txt
r2371136 r2398796 4 4 Requires at least: 4.6.0 5 5 Tested up to: 5.4.2 6 Stable tag: 1.1. 06 Stable tag: 1.1.1 7 7 Requires PHP: 5.6.0 8 8 License: GPLv2 or later … … 66 66 67 67 == Changelog == 68 = 1.1.1 = 69 * Add: Web tracking code updated in WP when user updates settings in Quentn. 70 68 71 = 1.1.0 = 69 72 * Fix: Error when activate Elementor network wide in multisite. … … 106 109 107 110 == Upgrade Notice == 111 = 1.1.1 = 112 Thanks for using Quentn Plugin! Please update the plugin to update web tracking code in WP when user updates settings in Quentn. 108 113 109 114 = 1.1.0 =
Note: See TracChangeset
for help on using the changeset viewer.