Example #1
0
 /**
  * Displays pro updater.
  *
  * @since 141111 First documented version.
  */
 protected function proUpdaterX()
 {
     if (!IS_PRO) {
         return '';
         // Pro only.
     }
     $_this = $this;
     $form_field_args = ['ns_id_suffix' => '-pro-updater-form', 'ns_name_suffix' => '[pro_update]', 'class_prefix' => 'pmp-pro-updater-form-'];
     $form_fields = new FormFields($form_field_args);
     $current_value_for = function ($key) use($_this) {
         if (strpos($key, 'template__') === 0 && isset($_this->plugin->options[$key])) {
             if ($_this->plugin->options[$key]) {
                 return $_this->plugin->options[$key];
             }
             $data = Template::optionKeyData($key);
             $default_template = new Template($data->file, $data->type, true);
             return $default_template->fileContents();
         }
         return isset($_this->plugin->options[$key]) ? $_this->plugin->options[$key] : null;
     };
     echo '<div class="' . esc_attr(SLUG_TD . '-menu-page ' . SLUG_TD . '-menu-page-pro-updater ' . SLUG_TD . '-menu-page-area') . '">' . "\n";
     echo '   <form method="post" enctype="multipart/form-data" autocomplete="off" action="' . esc_attr($this->plugin->utils_url->pageNonceOnly()) . '" novalidate="novalidate">' . "\n";
     echo '     ' . $this->heading(__('Pro Updater', 'comment-mail'), 'logo.png') . '     ' . $this->notes();
     // Heading/notifications.
     echo '     <div class="pmp-body">' . "\n";
     /* ----------------------------------------------------------------------------------------- */
     $_panel_body = '<i class="fa fa-user fa-4x" style="float:right; margin: 0 0 0 25px;"></i>' . "\n";
     $_panel_body .= '<p style="margin-top:0;">' . sprintf(__('From this page you can update to the latest version of %1$s Pro for WordPress. %1$s Pro is a premium product available for purchase @ <a href="%2$s" target="_blank">%3$s</a>. In order to connect with our update servers, we ask that you supply your account login details for <a href="%2$s" target="_blank">%3$s</a>. If you prefer not to provide your password, you can use your License Key in place of your password. Your License Key is located under "My Account" when you log in @ <a href="%2$s" target="_blank">%3$s</a>. This will authenticate your copy of %1$s Pro; providing you with access to the latest version. You only need to enter these credentials once. %1$s Pro will save them in your WordPress database.', 'comment-mail'), esc_html(NAME), esc_attr($this->plugin->utils_url->productPage()), esc_html(DOMAIN)) . '</p>' . "\n";
     $_panel_body .= ' <table>' . '   <tbody>' . $form_fields->inputRow(['name' => 'username', 'label' => __('Customer Username', 'comment-mail'), 'placeholder' => __('e.g., johndoe22', 'comment-mail'), 'current_value' => $current_value_for('pro_update_username'), 'other_attrs' => 'autocomplete="new-password"']) . '   </tbody>' . ' </table>';
     $_panel_body .= ' <table>' . '   <tbody>' . $form_fields->inputRow(['type' => 'password', 'name' => 'password', 'label' => __('Customer Password or Product License Key', 'comment-mail'), 'current_value' => $current_value_for('pro_update_password'), 'other_attrs' => 'autocomplete="new-password"']) . '   </tbody>' . ' </table>';
     echo $this->panel(__('Update Credentials', 'comment-mail'), $_panel_body, ['icon' => '<i class="fa fa-key"></i>', 'open' => true, 'pro_only' => true]);
     unset($_panel_body);
     // Housekeeping.
     /* ----------------------------------------------------------------------------------------- */
     $_panel_body = ' <table>' . '   <tbody>' . $form_fields->selectRow(['name' => 'check', 'label' => '', 'placeholder' => __('Select an Option...', 'comment-mail'), 'current_value' => $current_value_for('pro_update_check'), 'allow_arbitrary' => false, 'options' => ['1' => __('Yes, display a notification in my WordPress Dashboard when a new version is available.', 'comment-mail'), '0' => __('No, do not display any update notifications in my WordPress Dashboard.', 'comment-mail')], 'notes_after' => '<p>' . sprintf(__('When a new version of %1$s Pro becomes available, %1$s Pro can display a notification in your WordPress Dashboard prompting you to return to this page and perform an upgrade.', 'comment-mail'), esc_html(NAME)) . '</p>']) . '   </tbody>' . ' </table>';
     echo $this->panel(__('Update Notifier', 'comment-mail'), $_panel_body, ['icon' => '<i class="fa fa-bullhorn"></i>', 'open' => true, 'pro_only' => true]);
     unset($_panel_body);
     // Housekeeping.
     /* ----------------------------------------------------------------------------------------- */
     echo '         <div class="pmp-save">' . "\n";
     echo '            <button type="submit">' . __('Update Now', 'comment-mail') . ' <i class="fa fa-magic"></i></button>' . "\n";
     echo '         </div>' . "\n";
     /* ----------------------------------------------------------------------------------------- */
     echo '     </div>';
     echo '   </form>';
     echo '</div>';
 }
Example #2
0
    /**
     * Upgrading from a Pro version prior to changes that broke back. compat. w/ Advanced Templates
     *
     * @since 160618 First documented version.
     */
    protected function fromLteV160213()
    {
        if (version_compare($this->prev_version, '160213', '<=') && IS_PRO) {
            $_marker = '<?php /* --------------------------- Legacy Template Backup ---------------------------
 * Comment Mail v160618 included changes that were not backwards compatible with your
 * customized Advanced Template. To prevent problems with the upgrade to v160618, we reset
 * the Advanced Templates to their (new) default and backed up your customized template, a
 * copy of which is included below. You can reference your original template below to reapply
 * those changes to the new default template above. When you are ready to discard this backup,
 * simply delete this comment, and everything below it, and save the template. If you leave
 * this comment here and save the options, your backup below will be also saved.
 *
 * Note: Everything below this comment is not parsed by Comment Mail; it is only here for
 * your reference so that you can re-apply your modifications to the new template above.
 */ ?>';
            foreach ($this->plugin->options as $_key => &$_value) {
                if (strpos($_key, 'template__type_a__') === 0) {
                    $_key_data = Template::optionKeyData($_key);
                    $_default_template = new Template($_key_data->file, $_key_data->type, true);
                    $_option_template_contents = $_value;
                    // A copy of the option value (potentially incompatible, modified template).
                    $_default_template_contents = $_default_template->fileContents();
                    // New (safe) default template
                    $_option_template_nws = preg_replace('/\\s+/', '', $_option_template_contents);
                    // Strip whitespace for comparison
                    $_default_template_nws = preg_replace('/\\s+/', '', $_default_template_contents);
                    // Strip whitespace for comparison
                    if (!$_option_template_nws || $_option_template_nws === $_default_template_nws) {
                        continue;
                        // Skip this one, because it's empty, or it's no different from the default template.
                    }
                    $_options_reset[] = $_key;
                    // Save this so that we can let the site owner know which keys were reset.
                    // Add note and append the modified (incompatible) template to the bottom of the new default template
                    $_value = $_default_template_contents . "\n\n" . $_marker . "\n\n" . $_option_template_contents;
                }
            }
            unset($_marker, $_key, $_key_data, $_value);
            // Housekeeping.
            unset($_default_template, $_default_template_nws, $_new_and_old_template);
            if (isset($_options_reset) && is_array($_options_reset) && count($_options_reset) >= 1) {
                $this->plugin->optionsSave($this->plugin->options);
                $_options_to_menu_map = ['template__type_a__site__header___php' => 'Comment Mail → Config Options → Site Templates → Site Header', 'template__type_a__site__header_styles___php' => 'Comment Mail → Config Options → Site Templates → Site Header Styles', 'template__type_a__site__header_scripts___php' => 'Comment Mail → Config Options → Site Templates → Site Header Scripts', 'template__type_a__site__header_tag___php' => 'Comment Mail → Config Options → Site Templates → Site Header Tag', 'template__type_a__site__footer_tag___php' => 'Comment Mail → Config Options → Site Templates → Site Footer Tag', 'template__type_a__site__footer___php' => 'Comment Mail → Config Options → Site Templates → Site Footer', 'template__type_a__site__comment_form__sso_ops___php' => 'Comment Mail → Config Options → Site Templates → Comment Form SSO Options', 'template__type_a__site__comment_form__sso_op_scripts___php' => 'Comment Mail → Config Options → Site Templates → Comment Form Scripts for SSO Options', 'template__type_a__site__login_form__sso_ops___php' => 'Comment Mail → Config Options → Site Templates → Login Form SSO Options', 'template__type_a__site__login_form__sso_op_scripts___php' => 'Comment Mail → Config Options → Site Templates → Login Form Scripts for SSO Options', 'template__type_a__site__sso_actions__complete___php' => 'Comment Mail → Config Options → Site Templates → Single Sign-on Registration Complete', 'template__type_a__site__comment_form__sub_ops___php' => 'Comment Mail → Config Options → Site Templates → Comment Form Subscr. Options', 'template__type_a__site__comment_form__sub_op_scripts___php' => 'Comment Mail → Config Options → Site Templates → Comment Form Scripts for Subscr. Options', 'template__type_a__site__sub_actions__confirmed___php' => 'Comment Mail → Config Options → Site Templates → Subscr. Confirmed', 'template__type_a__site__sub_actions__unsubscribed___php' => 'Comment Mail → Config Options → Site Templates → Unsubscribed', 'template__type_a__site__sub_actions__unsubscribed_all___php' => 'Comment Mail → Config Options → Site Templates → Unsubscribed All', 'template__type_a__site__sub_actions__manage_summary___php' => 'Comment Mail → Config Options → Site Templates → Summary', 'template__type_a__site__sub_actions__manage_sub_form___php' => 'Comment Mail → Config Options → Site Templates → Add/Edit Form', 'template__type_a__site__sub_actions__manage_sub_form_comment_id_row_via_ajax___php' => 'Comment Mail → Config Options → Site Templates → Comment ID Row via AJAX', 'template__type_a__email__header___php' => 'Comment Mail → Config Options → Email Templates → Email Header', 'template__type_a__email__header_styles___php' => 'Comment Mail → Config Options → Email Templates → Email Header Styles', 'template__type_a__email__header_scripts___php' => 'Comment Mail → Config Options → Email Templates → Email Header Scripts', 'template__type_a__email__header_tag___php' => 'Comment Mail → Config Options → Email Templates → Email Header Tag', 'template__type_a__email__footer_tag___php' => 'Comment Mail → Config Options → Email Templates → Email Footer Tag', 'template__type_a__email__footer___php' => 'Comment Mail → Config Options → Email Templates → Email Footer', 'template__type_a__email__sub_confirmation__subject___php' => 'Comment Mail → Config Options → Email Templates → Subscr. Confirmation Subject', 'template__type_a__email__sub_confirmation__message___php' => 'Comment Mail → Config Options → Email Templates → Subscr. Confirmation Message Body', 'template__type_a__email__comment_notification__subject___php' => 'Comment Mail → Config Options → Email Templates → Comment Notification Subject', 'template__type_a__email__comment_notification__message___php' => 'Comment Mail → Config Options → Email Templates → Comment Notification Message Body'];
                $_options_reset_html = '';
                // Initialize
                foreach ($_options_reset as $_key => $_option) {
                    // Build list of menu paths to templates that have been reset
                    $_options_reset_html .= '<li>' . $_options_to_menu_map[$_option] . '</li>' . "\n";
                }
                // Let the site owner know we've reset their customized Advanced Templates
                $_notice = sprintf(__('<p><strong>%1$s has detected that your customized Advanced Templates are incompatible with this version.</strong></p>', 'comment-mail'), esc_html(NAME));
                $_notice .= '<p><strong>To retain your template customizations, please read the following message carefully.</strong></p>';
                $_notice .= sprintf(__('<p>%1$s v%2$s was released with a rewritten and improved codebase. This came with the unfortunate side effect of breaking backwards compatibility with any Advanced Templates that had been customized in a previous version.</p>', 'comment-mail'), esc_html(NAME), $this->plugin->options['version']);
                $_notice .= '<p>All of your customized Advanced Templates have been reset to their new default and your customizations have been backed up. You will find the backup of your old customized template appended to the bottom of the new template, separated with a  <code>Legacy Template Backup</code> PHP comment. The following templates have been reset:</p>';
                $_notice .= '<ul style="margin:0 0 1.3em 3em; list-style:disc;">' . $_options_reset_html . '</ul>';
                $_notice .= '<p><strong>Please review the above templates and re-apply your customizations.</strong></p>';
                $_notice .= '<p><em>Note: Once this message has been dismissed, the above list will will no longer be accessible.</em></p>';
                $this->plugin->enqueueNotice($_notice, ['persistent' => true, 'persistent_id' => 'vs-upgrade-advanced-templates-reset', 'type' => 'warning']);
            }
            unset($_key, $_option, $_notice);
            unset($_options_reset, $_options_to_menu_map, $_options_reset_html);
        }
    }
Example #3
0
 /**
  * Saves new plugin options.
  *
  * @since 141111 First documented version.
  *
  * @param array $options An array of new plugin options.
  */
 public function optionsSave(array $options)
 {
     $this->options = array_merge($this->default_options, $this->options, $options);
     foreach (!IS_PRO ? $this->pro_only_option_keys : [] as $_key) {
         $this->options[$_key] = $this->default_options[$_key];
     }
     // Force default pro-only option keys in lite version.
     unset($_key);
     // Housekeeping.
     $this->options = array_intersect_key($this->options, $this->default_options);
     $this->options = array_map('strval', $this->options);
     // Force strings.
     foreach ($this->options as $_key => &$_value) {
         if (strpos($_key, 'template__') === 0) {
             $_key_data = Template::optionKeyData($_key);
             if (!IS_PRO && $_key_data->type === 'a') {
                 continue;
                 // Not possible in lite version.
             }
             $_default_template = new Template($_key_data->file, $_key_data->type, true);
             $_default_template_nws = preg_replace('/\\s+/', '', $_default_template->fileContents());
             $_option_template_nws = preg_replace('/\\s+/', '', $_value);
             if ($_option_template_nws === $_default_template_nws) {
                 $_value = '';
                 // Empty; it's a default value.
             }
         }
     }
     unset($_key, $_key_data, $_value);
     // Housekeeping.
     unset($_default_template, $_option_template_nws, $_default_template_nws);
     update_option(GLOBAL_NS . '_options', $this->options);
     // DB update.
 }