Plugin Directory

Changeset 2741024


Ignore:
Timestamp:
06/12/2022 03:39:33 AM (4 years ago)
Author:
pushnami
Message:

Adds advanced option for alternate worker path.

Location:
pushnami-web-push-notifications
Files:
14 added
4 edited

Legend:

Unmodified
Added
Removed
  • pushnami-web-push-notifications/trunk/includes/class-pushnami.php

    r2739514 r2741024  
    3737        add_action('wp_print_scripts', array($this, 'pushnami_print_scripts'));
    3838        add_action('wp_head', array($this, 'manifestFile'), 1, 1);
     39        add_action('parse_request',  array($this, 'my_plugin_parse_request'));
    3940
    4041        $pluginDirName = basename( plugin_dir_path(  dirname( __FILE__ , 1 ) ) );
    4142        $settingsPath = 'plugin_action_links_' . $pluginDirName . '/pushnami.php';
    4243        add_filter($settingsPath, array($this, 'settingsLink'));
     44        add_filter('query_vars', array($this, 'my_plugin_query_vars'));
    4345    }
    4446
     
    102104
    103105    /**
    104      * ServiceWorker file (service-worker.js) creation
     106     * ServiceWorker file (service-worker.js) Render Template
     107     * @return void
     108     */
     109    public static function renderServiceWorker()
     110    {
     111        $api_url = get_option('pushnami_api_url');
     112        if (!$api_url) $api_url = PUSHNAMI_DEFAULT_API_URL;
     113
     114        $tmp_sw = file_get_contents(PUSHNAMI_PLUGIN_DIR . 'assets/tmp/service-worker.js.tmp');
     115        $tmp_sw = str_replace('KEY', get_option('pushnami_api_key'), $tmp_sw);
     116        $tmp_sw = str_replace('API_PATH', $api_url, $tmp_sw);
     117
     118        return $tmp_sw;
     119    }
     120
     121    /**
     122     * ServiceWorker file (service-worker.js) Write File
    105123     * @return void
    106124     */
     
    111129        if ($useCustomManifest) return;
    112130
    113         $api_url = get_option('pushnami_api_url');
    114         if (!$api_url) $api_url = PUSHNAMI_DEFAULT_API_URL;
    115 
    116         $tmp_sw = file_get_contents(PUSHNAMI_PLUGIN_DIR . 'assets/tmp/service-worker.js.tmp');
    117         $tmp_sw = str_replace('KEY', get_option('pushnami_api_key'), $tmp_sw);
    118         $tmp_sw = str_replace('API_PATH', $api_url, $tmp_sw);
     131        $tmp_sw = self::renderServiceWorker();
    119132        $form_url = 'admin.php?page=pushnami-settings';
    120133
     
    580593        self::writeManifestJson(true);
    581594    }
     595
     596    public function my_plugin_parse_request($wp) {
     597        $swPathsStr = get_option('pushnami_sw_paths');
     598        if ($swPathsStr) {
     599            $swPathsArr = explode(",", $swPathsStr);
     600            foreach ($swPathsArr as $swPath) {
     601                $swPathKeyValue = explode("=", trim($swPath));
     602                $count = count($swPathKeyValue);
     603                if ($count < 2) continue; // skip non query param paths
     604
     605                $key = preg_replace('/^\?{1}/', '', $swPathKeyValue[0]);
     606                $val = $swPathKeyValue[1];
     607                if (array_key_exists($key, $wp->query_vars)
     608                        && $wp->query_vars[$key] == $val) {
     609
     610                    $worker = self::renderServiceWorker();
     611                    die($worker);
     612                }
     613            }
     614        }
     615    }
     616
     617    public function my_plugin_query_vars($vars) {
     618        $swPathsStr = get_option('pushnami_sw_paths');
     619        if ($swPathsStr) {
     620            $swPathsArr = explode(",", $swPathsStr);
     621
     622            foreach ($swPathsArr as $swPath) {
     623                $swPathKeyValue = explode("=", trim($swPath));
     624                $count = count($swPathKeyValue);
     625                if ($count < 2) continue; // skip non query param paths
     626
     627                $key = preg_replace('/^\?{1}/', '', $swPathKeyValue[0]);
     628                $vars[] = $key;
     629            }
     630        }
     631
     632        return $vars;
     633    }
    582634}
  • pushnami-web-push-notifications/trunk/pushnami.php

    r2739514 r2741024  
    77Plugin URI: https://wordpress.org/plugins/pushnami-web-push-notifications
    88Description: Capture & Monetize Your Audience. The leader for web push, mobile push notifications, and email. Trusted by more than 20K brands to send 10 billion messages per month.
    9 Version: 1.0.7
     9Version: 1.0.8
    1010Author: Pushnami
    1111Author URI: https://www.pushnami.com
  • pushnami-web-push-notifications/trunk/readme.txt

    r2739514 r2741024  
    5959== Changelog ==
    6060
     61= 1.0.8 =
     62* Adds advanced option for setting extra service-worker query parameter paths.
     63
    6164= 1.0.7 =
    6265* Bug fix to reset script collision flags when proper files are detected again.
  • pushnami-web-push-notifications/trunk/views/admin/pushnami-settings.php

    r2388400 r2741024  
    214214                }
    215215
     216                if(isset($_POST['pushnami_sw_paths']) ) {
     217                    if(!empty($_POST['pushnami_sw_paths'])) {
     218                        update_option('pushnami_sw_paths', sanitize_text_field($_POST['pushnami_sw_paths']));
     219                    } else if(empty($_POST['pushnami_sw_paths'])) {
     220                        delete_option('pushnami_sw_paths');
     221                    }
     222                }
     223
    216224                if(isset($_POST['pushnami_api_url']) ) {
    217225                    if(!empty($_POST['pushnami_api_url'])) {
     
    495503                <td><input type="checkbox" name="pushnami_ab" value="true" <?php //checked(get_option('pushnami_ab')); ?> /></td>
    496504            </tr> -->
     505            <tr valign="top" class="advanced_option">
     506                <th scope="row">Extra Worker Path</th>
     507                <td><input type="text" size="64" name="pushnami_sw_paths" value="<?php echo esc_attr( get_option('pushnami_sw_paths') ); ?>" placeholder="service-worker.js"/></td>
     508            </tr>
    497509            <tr valign="top" class="debug_option" style="<?php if (!get_option('pushnami_debug')) echo 'display:none;'; ?>">
    498510                <th scope="row"><h3>Debug Options</h3></th>
Note: See TracChangeset for help on using the changeset viewer.