Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 82 |
|
0.00% |
0 / 6 |
CRAP | n/a |
0 / 0 |
|
| jpcrm_admin_nag_footer | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
380 | |||
| jpcrm_show_admin_nag_modal | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| jpcrm_verify_license_with_server | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| jpcrm_is_license_valid | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| jpcrm_multisite_get_site_list | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 | |||
| jpcrm_tidy_multisite_site | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
| 2 | /** |
| 3 | ! |
| 4 | * Jetpack CRM |
| 5 | * https://jetpackcrm.com |
| 6 | * V2.4+ |
| 7 | * |
| 8 | * Copyright 2020 Automattic |
| 9 | * |
| 10 | * Date: 05/02/2017 |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ZEROBSCRM_PATH' ) ) { |
| 14 | exit( 0 ); |
| 15 | } |
| 16 | |
| 17 | // System Nag messages for license key and upgrades |
| 18 | |
| 19 | add_action( 'wp_after_admin_bar_render', 'jpcrm_admin_nag_footer', 12 ); |
| 20 | /** |
| 21 | * This will nag if there's anytihng amiss with the settings. |
| 22 | */ |
| 23 | function jpcrm_admin_nag_footer() { |
| 24 | |
| 25 | global $zbs; |
| 26 | |
| 27 | // only nag if paid extensions are active |
| 28 | if ( $zbs->extensionCount( true ) > 0 ) { |
| 29 | // if transient already set, nothing to do |
| 30 | if ( get_transient( 'jpcrm-license-modal' ) ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | // if not in dev mode (as we can't add a key in dev mode currently) |
| 35 | if ( ! zeroBSCRM_isLocal( true ) ) { |
| 36 | |
| 37 | // on one of our pages except settings |
| 38 | if ( zeroBSCRM_isAdminPage() && ( ( isset( $_GET['page'] ) && $_GET['page'] !== 'zerobscrm-plugin-settings' ) || ( ! isset( $_GET['page'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 39 | |
| 40 | // retrieve license |
| 41 | $license = zeroBSCRM_getSetting( 'license_key' ); |
| 42 | if ( isset( $license ) && ! empty( $license ) ) { |
| 43 | |
| 44 | // License key is empty |
| 45 | if ( ( isset( $license['key'] ) && $license['key'] === '' ) || ! isset( $license['key'] ) ) { |
| 46 | |
| 47 | // build message |
| 48 | $message = '<h3>' . __( 'License Key Needed', 'zero-bs-crm' ) . '</h3>'; |
| 49 | $message .= '<p>' . __( 'To continue to use CRM extensions you need will need to enter your Jetpack CRM license key.', 'zero-bs-crm' ) . '</p>'; |
| 50 | $message .= '<p><a href="' . esc_url_raw( $zbs->urls['licensekeys'] ) . '" class="ui button green" target="_blank">' . __( 'Retrieve License Key', 'zero-bs-crm' ) . '</a> <a href="' . jpcrm_esc_link( $zbs->slugs['settings'] . '&tab=license' ) . '" class="ui button blue">' . __( 'License Settings', 'zero-bs-crm' ) . '</a></p>'; |
| 51 | |
| 52 | // output modal |
| 53 | jpcrm_show_admin_nag_modal( $message ); |
| 54 | return; |
| 55 | |
| 56 | } |
| 57 | |
| 58 | // License key is not valid |
| 59 | if ( ! $license['validity'] && $license['extensions_updated'] ) { |
| 60 | |
| 61 | // build message |
| 62 | $message = '<h3>' . __( 'License Key Incorrect', 'zero-bs-crm' ) . '</h3>'; |
| 63 | $message .= '<p>' . __( 'Please update your license key. You can get your license key from your account and enter it in settings.', 'zero-bs-crm' ) . '</p>'; |
| 64 | $message .= '<p><a href="' . $zbs->urls['kblicensefaq'] . '" class="ui button blue" target="_blank">' . __( 'Read about license keys', 'zero-bs-crm' ) . '</a> <a href="' . $zbs->urls['licensekeys'] . '" target="_blank" class="ui button green">' . __( 'Retrieve License Key', 'zero-bs-crm' ) . '</a></p>'; |
| 65 | |
| 66 | // output modal |
| 67 | jpcrm_show_admin_nag_modal( $message ); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | // Extensions need updating |
| 72 | if ( isset( $license['extensions_updated'] ) && ! $license['extensions_updated'] ) { |
| 73 | |
| 74 | // build message |
| 75 | $message = '<h3>' . __( 'Extension Update Required', 'zero-bs-crm' ) . '</h3>'; |
| 76 | if ( $license['validity'] === 'empty' ) { |
| 77 | |
| 78 | // no license |
| 79 | $message .= '<p>' . __( 'You are running extension versions which are not supported. Please enter your license key to enable updates.', 'zero-bs-crm' ) . '</p>'; |
| 80 | $message .= '<p><a href="' . $zbs->urls['licensekeys'] . '" class="ui button green" target="_blank">' . __( 'Retrieve License Key', 'zero-bs-crm' ) . '</a> <a href="' . jpcrm_esc_link( $zbs->slugs['settings'] . '&tab=license' ) . '" class="ui button blue">' . __( 'License Settings', 'zero-bs-crm' ) . '</a></p>'; |
| 81 | |
| 82 | // output modal |
| 83 | jpcrm_show_admin_nag_modal( $message ); |
| 84 | return; |
| 85 | |
| 86 | } elseif ( ! $license['validity'] ) { |
| 87 | |
| 88 | // invalid license |
| 89 | $message .= '<p>' . __( 'You are running extension versions which are not supported. Please enter a valid license key to enable updates.', 'zero-bs-crm' ) . '</p>'; |
| 90 | $message .= '<p><a href="' . $zbs->urls['kblicensefaq'] . '" class="ui button blue" target="_blank">' . __( 'Read about license keys', 'zero-bs-crm' ) . '</a> <a href="' . $zbs->urls['licensekeys'] . '" target="_blank" class="ui button green">' . __( 'Retrieve License Key', 'zero-bs-crm' ) . '</a></p>'; |
| 91 | |
| 92 | // output modal |
| 93 | jpcrm_show_admin_nag_modal( $message ); |
| 94 | return; |
| 95 | |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } // / is not local/devmode (normal) |
| 101 | |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Show admin nag modal (e.g. if no license, but extensions) |
| 107 | * |
| 108 | * @param string $message The message to display in the modal. |
| 109 | */ |
| 110 | function jpcrm_show_admin_nag_modal( $message = '' ) { |
| 111 | |
| 112 | if ( ! get_transient( 'jpcrm-license-modal' ) ) { |
| 113 | |
| 114 | ?> |
| 115 | <script type="text/javascript">var jpcrm_modal_message_licensing_nonce = <?php echo wp_json_encode( wp_create_nonce( 'jpcrm-set-transient-nonce' ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?>;</script> |
| 116 | <div class="zbs_overlay" id="jpcrm-modal-message-licensing"> |
| 117 | <div class='close_nag_modal'> |
| 118 | <span id="jpcrm-close-licensing-modal">x</span> |
| 119 | </div> |
| 120 | <div class='zbs-message-body'> |
| 121 | <img style="max-width:350px;margin-bottom:1.4em" src="<?php echo esc_url( jpcrm_get_logo( false, 'white' ) ); ?>" alt="" style="cursor:pointer;" /> |
| 122 | <div class='zbs-message'> |
| 123 | <?php |
| 124 | echo $message; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 125 | ?> |
| 126 | </div> |
| 127 | </div> |
| 128 | </div> |
| 129 | <?php |
| 130 | |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * License related funcs |
| 136 | */ |
| 137 | |
| 138 | /** |
| 139 | * Force an update check (and update keys) |
| 140 | */ |
| 141 | function jpcrm_verify_license_with_server() { |
| 142 | global $zbs; |
| 143 | $plugin_updater = new zeroBSCRM_Plugin_Updater( $zbs->urls['api'], $zbs->api_ver, 'zero-bs-crm' ); |
| 144 | $zbs_transient = new stdClass(); |
| 145 | $plugin_updater->check_update( $zbs_transient ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Checks if license is valid based on stored settings. |
| 150 | * |
| 151 | * Best used for simple checks like upsells. |
| 152 | * |
| 153 | * @return bool Whether license is valid. |
| 154 | */ |
| 155 | function jpcrm_is_license_valid() { |
| 156 | $license_info = zeroBSCRM_getSetting( 'license_key' ); |
| 157 | $is_valid = isset( $license_info['validity'] ) && $license_info['validity'] === 'true'; |
| 158 | return $is_valid; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Gets a list of multi site |
| 163 | */ |
| 164 | function jpcrm_multisite_get_site_list() { |
| 165 | global $wpdb; |
| 166 | $sites = array(); |
| 167 | $table = $wpdb->prefix . 'blogs'; |
| 168 | if ( $wpdb->get_var( "SHOW TABLES LIKE '$table'" ) === $table ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching |
| 169 | $sql = "SELECT * FROM $table"; |
| 170 | $sites = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared |
| 171 | } |
| 172 | |
| 173 | // clean up (reduce bandwidth of pass/avoid overburdening) |
| 174 | if ( is_array( $sites ) && count( $sites ) > 0 ) { |
| 175 | $ret = array(); |
| 176 | foreach ( $sites as $site ) { |
| 177 | $ret[] = jpcrm_tidy_multisite_site( $site ); |
| 178 | } |
| 179 | $sites = $ret; |
| 180 | } |
| 181 | |
| 182 | return $sites; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Tidies up a multisite site row for processing. |
| 187 | * |
| 188 | * @param object $site_row The site row data to tidy up. |
| 189 | * @return array|false The tidied site data or false if invalid. |
| 190 | */ |
| 191 | function jpcrm_tidy_multisite_site( $site_row ) { |
| 192 | |
| 193 | if ( isset( $site_row->blog_id ) ) { |
| 194 | |
| 195 | // active if not archived, spam, deleted |
| 196 | $is_active = 1; |
| 197 | if ( $site_row->archived ) { |
| 198 | $is_active = -1; |
| 199 | } |
| 200 | if ( $site_row->spam ) { |
| 201 | $is_active = -1; |
| 202 | } |
| 203 | if ( $site_row->deleted ) { |
| 204 | $is_active = -1; |
| 205 | } |
| 206 | |
| 207 | return array( |
| 208 | |
| 209 | // not req. always same?? |
| 210 | 'site_id' => $site_row->site_id, |
| 211 | 'blog_id' => $site_row->blog_id, |
| 212 | |
| 213 | 'domain' => $site_row->domain, |
| 214 | 'path' => $site_row->path, |
| 215 | |
| 216 | // active if not archived, spam, deleted |
| 217 | 'active' => $is_active, |
| 218 | |
| 219 | // log these (useful) |
| 220 | 'deleted' => $site_row->deleted, |
| 221 | 'archived' => $site_row->archived, |
| 222 | 'spam' => $site_row->spam, |
| 223 | 'lang_id' => $site_row->lang_id, |
| 224 | |
| 225 | ); |
| 226 | |
| 227 | } |
| 228 | |
| 229 | return false; |
| 230 | } |