Plugin Directory

Changeset 3313743


Ignore:
Timestamp:
06/18/2025 09:54:47 AM (10 months ago)
Author:
wonderpush
Message:

v1.12.0

Location:
wonderpush-web-push-notifications
Files:
24 added
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wonderpush-web-push-notifications/tags/1.12.0/init.php

    r2922221 r3313743  
    22
    33// WonderPush\Util
    4 require(dirname(__FILE__) . '/lib/Util/JsonSerializable.php');
    5 require(dirname(__FILE__) . '/lib/Util/Logger.php');
    6 require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php');
    7 require(dirname(__FILE__) . '/lib/Util/ArrayUtil.php');
    8 require(dirname(__FILE__) . '/lib/Util/StringUtil.php');
    9 require(dirname(__FILE__) . '/lib/Util/TimeUnit.php');
    10 require(dirname(__FILE__) . '/lib/Util/TimeUtil.php');
    11 require(dirname(__FILE__) . '/lib/Util/TimeValue.php');
    12 require(dirname(__FILE__) . '/lib/Util/UrlUtil.php');
     4if (!interface_exists('WonderPush\Util\JsonSerializable')) require(dirname(__FILE__) . '/lib/Util/JsonSerializable.php');
     5if (!interface_exists('WonderPush\Util\Logger')) require(dirname(__FILE__) . '/lib/Util/Logger.php');
     6if (!class_exists('WonderPush\Util\DefaultLogger')) require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php');
     7if (!class_exists('WonderPush\Util\ArrayUtil')) require(dirname(__FILE__) . '/lib/Util/ArrayUtil.php');
     8if (!class_exists('WonderPush\Util\StringUtil')) require(dirname(__FILE__) . '/lib/Util/StringUtil.php');
     9if (!class_exists('WonderPush\Util\TimeUnit')) require(dirname(__FILE__) . '/lib/Util/TimeUnit.php');
     10if (!class_exists('WonderPush\Util\TimeUtil')) require(dirname(__FILE__) . '/lib/Util/TimeUtil.php');
     11if (!class_exists('WonderPush\Util\TimeValue')) require(dirname(__FILE__) . '/lib/Util/TimeValue.php');
     12if (!class_exists('WonderPush\Util\UrlUtil')) require(dirname(__FILE__) . '/lib/Util/UrlUtil.php');
    1313
    1414// WonderPush
    15 require(dirname(__FILE__) . '/lib/WonderPush.php');
     15if (!class_exists('WonderPush\WonderPush')) require(dirname(__FILE__) . '/lib/WonderPush.php');
    1616
    1717// WonderPush\Obj
    18 require(dirname(__FILE__) . '/lib/Obj/BaseObject.php');
    19 require(dirname(__FILE__) . '/lib/Obj/SuccessResponse.php');
    20 require(dirname(__FILE__) . '/lib/Obj/DeliveriesCreateResponse.php');
    21 require(dirname(__FILE__) . '/lib/Obj/Pagination.php');
    22 require(dirname(__FILE__) . '/lib/Obj/NullObject.php');
    23 require(dirname(__FILE__) . '/lib/Obj/Application.php');
    24 require(dirname(__FILE__) . '/lib/Obj/Segment.php');
    25 require(dirname(__FILE__) . '/lib/Obj/GeoLocation.php');
    26 require(dirname(__FILE__) . '/lib/Obj/User.php');
    27 require(dirname(__FILE__) . '/lib/Obj/Collection.php');
    28 require(dirname(__FILE__) . '/lib/Obj/ApplicationCollection.php');
    29 require(dirname(__FILE__) . '/lib/Obj/SegmentCollection.php');
    30 require(dirname(__FILE__) . '/lib/Obj/Installation.php');
    31 require(dirname(__FILE__) . '/lib/Obj/InstallationCollection.php');
    32 require(dirname(__FILE__) . '/lib/Obj/InstallationApplicationApple.php');
    33 require(dirname(__FILE__) . '/lib/Obj/InstallationApplication.php');
    34 require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceCapabilities.php');
    35 require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceConfiguration.php');
    36 require(dirname(__FILE__) . '/lib/Obj/InstallationDevice.php');
    37 require(dirname(__FILE__) . '/lib/Obj/InstallationPreferences.php');
    38 require(dirname(__FILE__) . '/lib/Obj/InstallationPushToken.php');
    39 require(dirname(__FILE__) . '/lib/Obj/Event.php');
    40 require(dirname(__FILE__) . '/lib/Obj/FrequentFieldValues.php');
    41 require(dirname(__FILE__) . '/lib/Obj/NotificationButton.php');
    42 require(dirname(__FILE__) . '/lib/Obj/NotificationButtonAction.php');
    43 require(dirname(__FILE__) . '/lib/Obj/NotificationButtonActionEvent.php');
    44 require(dirname(__FILE__) . '/lib/Obj/Notification.php');
    45 require(dirname(__FILE__) . '/lib/Obj/NotificationAlert.php');
    46 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroid.php');
    47 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroidButton.php');
    48 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIos.php');
    49 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosAttachment.php');
    50 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosForeground.php');
    51 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWeb.php');
    52 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWebButton.php');
    53 require(dirname(__FILE__) . '/lib/Obj/NotificationInApp.php');
    54 require(dirname(__FILE__) . '/lib/Obj/NotificationInAppButton.php');
    55 require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMap.php');
    56 require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMapPlace.php');
    57 require(dirname(__FILE__) . '/lib/Obj/NotificationPush.php');
    58 require(dirname(__FILE__) . '/lib/Obj/NotificationPushAndroid.php');
    59 require(dirname(__FILE__) . '/lib/Obj/NotificationPushIos.php');
    60 require(dirname(__FILE__) . '/lib/Obj/NotificationPushWeb.php');
    61 require(dirname(__FILE__) . '/lib/Obj/WebSdkInitOptions.php');
     18if (!class_exists('WonderPush\Obj\BaseObject')) require(dirname(__FILE__) . '/lib/Obj/BaseObject.php');
     19if (!class_exists('WonderPush\Obj\SuccessResponse')) require(dirname(__FILE__) . '/lib/Obj/SuccessResponse.php');
     20if (!class_exists('WonderPush\Obj\CampaignSuccessResponse')) require(dirname(__FILE__) . '/lib/Obj/CampaignSuccessResponse.php');
     21if (!class_exists('WonderPush\Obj\DeliveriesCreateResponse')) require(dirname(__FILE__) . '/lib/Obj/DeliveriesCreateResponse.php');
     22if (!class_exists('WonderPush\Obj\Pagination')) require(dirname(__FILE__) . '/lib/Obj/Pagination.php');
     23if (!class_exists('WonderPush\Obj\NullObject')) require(dirname(__FILE__) . '/lib/Obj/NullObject.php');
     24if (!class_exists('WonderPush\Obj\Application')) require(dirname(__FILE__) . '/lib/Obj/Application.php');
     25if (!class_exists('WonderPush\Obj\Segment')) require(dirname(__FILE__) . '/lib/Obj/Segment.php');
     26if (!class_exists('WonderPush\Obj\GeoLocation')) require(dirname(__FILE__) . '/lib/Obj/GeoLocation.php');
     27if (!class_exists('WonderPush\Obj\User')) require(dirname(__FILE__) . '/lib/Obj/User.php');
     28if (!class_exists('WonderPush\Obj\Collection')) require(dirname(__FILE__) . '/lib/Obj/Collection.php');
     29if (!class_exists('WonderPush\Obj\CampaignCollection')) require(dirname(__FILE__) . '/lib/Obj/CampaignCollection.php');
     30if (!class_exists('WonderPush\Obj\ApplicationCollection')) require(dirname(__FILE__) . '/lib/Obj/ApplicationCollection.php');
     31if (!class_exists('WonderPush\Obj\SegmentCollection')) require(dirname(__FILE__) . '/lib/Obj/SegmentCollection.php');
     32if (!class_exists('WonderPush\Obj\Installation')) require(dirname(__FILE__) . '/lib/Obj/Installation.php');
     33if (!class_exists('WonderPush\Obj\InstallationCollection')) require(dirname(__FILE__) . '/lib/Obj/InstallationCollection.php');
     34if (!class_exists('WonderPush\Obj\InstallationApplicationApple')) require(dirname(__FILE__) . '/lib/Obj/InstallationApplicationApple.php');
     35if (!class_exists('WonderPush\Obj\InstallationApplication')) require(dirname(__FILE__) . '/lib/Obj/InstallationApplication.php');
     36if (!class_exists('WonderPush\Obj\InstallationDeviceCapabilities')) require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceCapabilities.php');
     37if (!class_exists('WonderPush\Obj\InstallationDeviceConfiguration')) require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceConfiguration.php');
     38if (!class_exists('WonderPush\Obj\InstallationDevice')) require(dirname(__FILE__) . '/lib/Obj/InstallationDevice.php');
     39if (!class_exists('WonderPush\Obj\InstallationPreferences')) require(dirname(__FILE__) . '/lib/Obj/InstallationPreferences.php');
     40if (!class_exists('WonderPush\Obj\InstallationPushToken')) require(dirname(__FILE__) . '/lib/Obj/InstallationPushToken.php');
     41if (!class_exists('WonderPush\Obj\Event')) require(dirname(__FILE__) . '/lib/Obj/Event.php');
     42if (!class_exists('WonderPush\Obj\FrequentFieldValues')) require(dirname(__FILE__) . '/lib/Obj/FrequentFieldValues.php');
     43if (!class_exists('WonderPush\Obj\NotificationButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationButton.php');
     44if (!class_exists('WonderPush\Obj\NotificationButtonAction')) require(dirname(__FILE__) . '/lib/Obj/NotificationButtonAction.php');
     45if (!class_exists('WonderPush\Obj\NotificationButtonActionEvent')) require(dirname(__FILE__) . '/lib/Obj/NotificationButtonActionEvent.php');
     46if (!class_exists('WonderPush\Obj\Notification')) require(dirname(__FILE__) . '/lib/Obj/Notification.php');
     47if (!class_exists('WonderPush\Obj\NotificationAlert')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlert.php');
     48if (!class_exists('WonderPush\Obj\NotificationAlertAndroid')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroid.php');
     49if (!class_exists('WonderPush\Obj\NotificationAlertAndroidButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroidButton.php');
     50if (!class_exists('WonderPush\Obj\NotificationAlertIos')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIos.php');
     51if (!class_exists('WonderPush\Obj\NotificationAlertIosAttachment')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosAttachment.php');
     52if (!class_exists('WonderPush\Obj\NotificationAlertIosForeground')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosForeground.php');
     53if (!class_exists('WonderPush\Obj\NotificationAlertWeb')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWeb.php');
     54if (!class_exists('WonderPush\Obj\NotificationAlertWebButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWebButton.php');
     55if (!class_exists('WonderPush\Obj\NotificationInApp')) require(dirname(__FILE__) . '/lib/Obj/NotificationInApp.php');
     56if (!class_exists('WonderPush\Obj\NotificationInAppButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationInAppButton.php');
     57if (!class_exists('WonderPush\Obj\NotificationInAppMap')) require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMap.php');
     58if (!class_exists('WonderPush\Obj\NotificationInAppMapPlace')) require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMapPlace.php');
     59if (!class_exists('WonderPush\Obj\NotificationPush')) require(dirname(__FILE__) . '/lib/Obj/NotificationPush.php');
     60if (!class_exists('WonderPush\Obj\NotificationPushAndroid')) require(dirname(__FILE__) . '/lib/Obj/NotificationPushAndroid.php');
     61if (!class_exists('WonderPush\Obj\NotificationPushIos')) require(dirname(__FILE__) . '/lib/Obj/NotificationPushIos.php');
     62if (!class_exists('WonderPush\Obj\NotificationPushWeb')) require(dirname(__FILE__) . '/lib/Obj/NotificationPushWeb.php');
     63if (!class_exists('WonderPush\Obj\Campaign')) require(dirname(__FILE__) . '/lib/Obj/Campaign.php');
     64if (!class_exists('WonderPush\Obj\CampaignSchedule')) require(dirname(__FILE__) . '/lib/Obj/CampaignSchedule.php');
     65if (!class_exists('WonderPush\Obj\CampaignSchedulePressure')) require(dirname(__FILE__) . '/lib/Obj/CampaignSchedulePressure.php');
     66if (!class_exists('WonderPush\Obj\CampaignScheduleUrlCriterion')) require(dirname(__FILE__) . '/lib/Obj/CampaignScheduleUrlCriterion.php');
     67if (!class_exists('WonderPush\Obj\CampaignStats')) require(dirname(__FILE__) . '/lib/Obj/CampaignStats.php');
     68if (!class_exists('WonderPush\Obj\CampaignUrlFilters')) require(dirname(__FILE__) . '/lib/Obj/CampaignUrlFilters.php');
     69if (!class_exists('WonderPush\Obj\CampaignCapping')) require(dirname(__FILE__) . '/lib/Obj/CampaignCapping.php');
     70
     71if (!class_exists('WonderPush\Obj\WebSdkInitOptions')) require(dirname(__FILE__) . '/lib/Obj/WebSdkInitOptions.php');
    6272
    6373// WonderPush\Params
    64 require(dirname(__FILE__) . '/lib/Params/CollectionParams.php');
    65 require(dirname(__FILE__) . '/lib/Params/DeliveriesCreateParams.php');
    66 require(dirname(__FILE__) . '/lib/Params/FrequentFieldValuesParams.php');
    67 require(dirname(__FILE__) . '/lib/Params/AllInstallationsParams.php');
    68 require(dirname(__FILE__) . '/lib/Params/PatchInstallationParams.php');
    69 require(dirname(__FILE__) . '/lib/Params/TrackEventParams.php');
     74if (!class_exists('WonderPush\Params\CollectionParams')) require(dirname(__FILE__) . '/lib/Params/CollectionParams.php');
     75if (!class_exists('WonderPush\Params\DeliveriesCreateParams')) require(dirname(__FILE__) . '/lib/Params/DeliveriesCreateParams.php');
     76if (!class_exists('WonderPush\Params\FrequentFieldValuesParams')) require(dirname(__FILE__) . '/lib/Params/FrequentFieldValuesParams.php');
     77if (!class_exists('WonderPush\Params\AllInstallationsParams')) require(dirname(__FILE__) . '/lib/Params/AllInstallationsParams.php');
     78if (!class_exists('WonderPush\Params\PatchInstallationParams')) require(dirname(__FILE__) . '/lib/Params/PatchInstallationParams.php');
     79if (!class_exists('WonderPush\Params\TrackEventParams')) require(dirname(__FILE__) . '/lib/Params/TrackEventParams.php');
     80if (!class_exists('WonderPush\Params\PatchCampaignParams')) require(dirname(__FILE__) . '/lib/Params/PatchCampaignParams.php');
     81if (!class_exists('WonderPush\Params\CreateCampaignParams')) require(dirname(__FILE__) . '/lib/Params/CreateCampaignParams.php');
    7082
    7183// WonderPush\Net
    72 require(dirname(__FILE__) . '/lib/Net/Request.php');
    73 require(dirname(__FILE__) . '/lib/Net/Response.php');
    74 require(dirname(__FILE__) . '/lib/Net/HttpClientInterface.php');
    75 require(dirname(__FILE__) . '/lib/Net/CurlHttpClient.php');
     84if (!class_exists('WonderPush\Net\Request')) require(dirname(__FILE__) . '/lib/Net/Request.php');
     85if (!class_exists('WonderPush\Net\Response')) require(dirname(__FILE__) . '/lib/Net/Response.php');
     86if (!interface_exists('WonderPush\Net\HttpClientInterface')) require(dirname(__FILE__) . '/lib/Net/HttpClientInterface.php');
     87if (!class_exists('WonderPush\Net\CurlHttpClient')) require(dirname(__FILE__) . '/lib/Net/CurlHttpClient.php');
    7688
    7789// WonderPush\Errors
    78 require(dirname(__FILE__) . '/lib/Errors/Base.php');
    79 require(dirname(__FILE__) . '/lib/Errors/Parsing.php');
    80 require(dirname(__FILE__) . '/lib/Errors/Server.php');
    81 require(dirname(__FILE__) . '/lib/Errors/Network.php');
     90if (!class_exists('WonderPush\Errors\Base')) require(dirname(__FILE__) . '/lib/Errors/Base.php');
     91if (!class_exists('WonderPush\Errors\Parsing')) require(dirname(__FILE__) . '/lib/Errors/Parsing.php');
     92if (!class_exists('WonderPush\Errors\Server')) require(dirname(__FILE__) . '/lib/Errors/Server.php');
     93if (!class_exists('WonderPush\Errors\Network')) require(dirname(__FILE__) . '/lib/Errors/Network.php');
    8294
    8395// WonderPush\Api
    84 require(dirname(__FILE__) . '/lib/Api/Rest.php');
    85 require(dirname(__FILE__) . '/lib/Api/Deliveries.php');
    86 require(dirname(__FILE__) . '/lib/Api/Applications.php');
    87 require(dirname(__FILE__) . '/lib/Api/Segments.php');
    88 require(dirname(__FILE__) . '/lib/Api/Stats.php');
    89 require(dirname(__FILE__) . '/lib/Api/Installations.php');
    90 require(dirname(__FILE__) . '/lib/Api/Events.php');
     96if (!class_exists('WonderPush\Api\Rest')) require(dirname(__FILE__) . '/lib/Api/Rest.php');
     97if (!class_exists('WonderPush\Api\Deliveries')) require(dirname(__FILE__) . '/lib/Api/Deliveries.php');
     98if (!class_exists('WonderPush\Api\Applications')) require(dirname(__FILE__) . '/lib/Api/Applications.php');
     99if (!class_exists('WonderPush\Api\Segments')) require(dirname(__FILE__) . '/lib/Api/Segments.php');
     100if (!class_exists('WonderPush\Api\Stats')) require(dirname(__FILE__) . '/lib/Api/Stats.php');
     101if (!class_exists('WonderPush\Api\Installations')) require(dirname(__FILE__) . '/lib/Api/Installations.php');
     102if (!class_exists('WonderPush\Api\Campaigns')) require(dirname(__FILE__) . '/lib/Api/Campaigns.php');
     103if (!class_exists('WonderPush\Api\Events')) require(dirname(__FILE__) . '/lib/Api/Events.php');
  • wonderpush-web-push-notifications/tags/1.12.0/lib/Api/Rest.php

    r2481484 r3313743  
    3838    $rtn->setPath($path);
    3939    $rtn->setParams($params);
    40     $rtn->setQsParams(array_filter(array(
    41         'accessToken' => $this->wp->getAccessToken(),
    42         'applicationId' => $this->wp->getApplicationId(), // filtered if null
    43     )));
     40    $rtn->setQsParam('applicationId', $this->wp->getApplicationId()); // filtered if null
     41    if ($this->wp->getCredentials()) {
     42      $this->wp->getCredentials()->authenticate($rtn);
     43    }
    4444    return $rtn;
    4545  }
  • wonderpush-web-push-notifications/tags/1.12.0/lib/Net/CurlHttpClient.php

    r3097137 r3313743  
    99 */
    1010class CurlHttpClient implements HttpClientInterface {
     11
     12  public static $logging = false;
     13  public static $loggingResponses = false;
    1114
    1215  /**
     
    5356      case Request::GET:
    5457      case Request::DELETE:
    55         $qsParams = array_merge($qsParams, $request->getParams());
     58        $qsParams = array_merge($qsParams ?: array(), $request->getParams());
    5659        break;
    5760      case Request::PUT:
     
    5962      case Request::PATCH:
    6063        $body = $request->getParams();
    61         if (empty($body)) {
     64        $files = $request->getFiles();
     65        if (count($files)) {
     66          $body = $request->getParams() ?: array();
     67          foreach ($files as $name => $file) {
     68            $body[$name] = new \CURLFile($file['tmp_name'], $file['type'], $file['name']);
     69          }
     70        } else if (empty($body)) {
    6271          $body = null;
    6372        } else {
     
    133142
    134143    // Execute cURL request
     144    $start = microtime(true);
    135145    $rawResponse = curl_exec($ch);
     146    if (self::$logging) {
     147      error_log('--> ' . $request->getMethod() . ' ' . $url . ' ' . $body . (empty($headers) ? '' : ' ' . json_encode($headers)) . ' (' . intval(1000 * (microtime(true) - $start)) . 'ms)');
     148    }
    136149
    137150    // Parse response
     
    155168    }
    156169
     170    if (self::$logging && self::$loggingResponses) {
     171      error_log('<-- (' . $response->getStatusCode() . ') ' . ($response->getRawBody() ?: '<no body>') . (empty($response->getHeaders()) ? '' : ' ' . json_encode($response->getHeaders())));
     172    }
     173
    157174    // Cleanup
    158175    curl_close($ch);
  • wonderpush-web-push-notifications/tags/1.12.0/lib/Net/Request.php

    r2481484 r3313743  
    7878
    7979  /**
     80   * An associative array of 'paramName' => ['tmp_name' => '/full/path','name' => 'filename.png', 'type' => 'image/png'].
     81   * @var mixed
     82   */
     83  private $files = array();
     84
     85  /**
    8086   * HTTP headers.
    8187   * @var mixed[]
     
    174180
    175181  /**
     182   * @param $key
     183   * @param $value
     184   * @return $this
     185   */
     186  public function setQsParam($key, $value) {
     187    if ($key === null) return $this;
     188    if (!$this->qsParams) {
     189      $this->qsParams = array();
     190    }
     191    if ($value === null) {
     192      unset($this->qsParams[$key]);
     193    } else {
     194      $this->qsParams[$key] = $value;
     195    }
     196    return $this;
     197  }
     198
     199  public function addFile($paramName, $filename, $path, $type) {
     200    $this->files[$paramName] = array(
     201      'name' => $filename,
     202      'tmp_name' => $path,
     203      'type' => $type,
     204    );
     205    return $this;
     206  }
     207
     208  public function removeFile($paramName) {
     209    unset($this->files[$paramName]);
     210    return $this;
     211  }
     212
     213  public function getFiles() {
     214    return $this->files;
     215  }
     216
     217  /**
    176218   * The body parameters.
    177219   *
     
    215257  }
    216258
     259  /**
     260   * @param $key
     261   * @param $value
     262   * @return $this
     263   */
     264  public function setHeader($key, $value) {
     265    if ($key === null) return $this;
     266    if (!$this->headers) {
     267      $this->headers = array();
     268    }
     269    if ($value === null) {
     270      unset($this->headers[$key]);
     271    } else {
     272      $this->headers[$key] = $value;
     273    }
     274    return $this;
     275  }
    217276}
  • wonderpush-web-push-notifications/tags/1.12.0/lib/Obj/Application.php

    r2588630 r3313743  
    2727  /** @var object */
    2828  private $urlParameters;
     29  /** @var string */
     30  private $status;
     31  /** @var integer */
     32  private $subscribers;
     33  /** @var array */
     34  private $pushDisabledPlatforms;
     35  /** @var boolean */
     36  private $wordPressSnippetDeactivated;
    2937
    3038  /**
     
    140148    return $this;
    141149  }
     150
     151  /**
     152   * @return string|null
     153   */
     154  public function getStatus()
     155  {
     156    return $this->status ?: null;
     157  }
     158
     159  /**
     160   * @param string $status
     161   * @return Application
     162   */
     163  public function setStatus($status)
     164  {
     165    $this->status = $status;
     166    return $this;
     167  }
     168
     169  /**
     170   * @return int
     171   */
     172  public function getSubscribers()
     173  {
     174    return $this->subscribers ?: 0;
     175  }
     176
     177  /**
     178   * @param int $subscribers
     179   * @return Application
     180   */
     181  public function setSubscribers( $subscribers )
     182  {
     183    $this->subscribers = $subscribers;
     184    return $this;
     185  }
     186
     187  /**
     188   * @return array
     189   */
     190  public function getPushDisabledPlatforms()
     191  {
     192    return $this->pushDisabledPlatforms;
     193  }
     194
     195  /**
     196   * @param array $pushDisabledPlatforms
     197   * @return Application
     198   */
     199  public function setPushDisabledPlatforms($pushDisabledPlatforms)
     200  {
     201    $this->pushDisabledPlatforms = (array)$pushDisabledPlatforms;
     202    return $this;
     203  }
     204
     205  public function getWordPressSnippetDeactivated()
     206  {
     207    return (bool)$this->wordPressSnippetDeactivated;
     208  }
     209
     210  public function setWordPressSnippetDeactivated($wordPressSnippetDeactivated)
     211  {
     212    $this->wordPressSnippetDeactivated = (bool)$wordPressSnippetDeactivated;
     213    return $this;
     214  }
    142215}
  • wonderpush-web-push-notifications/tags/1.12.0/lib/Obj/WebSdkInitOptions.php

    r2481484 r3313743  
    1919  /** @var string */
    2020  private $manifestUrl;
     21  /** @var bool */
     22  private $resubscribe;
     23
     24  /** @var array */
     25  private $allowedSubscriptionDomains;
     26  /** @var mixed */
     27  private $subscriptionNative;
     28  /** @var mixed */
     29  private $subscriptionDialog;
     30  /** @var mixed */
     31  private $subscriptionBell;
     32  /** @var mixed */
     33  private $subscriptionBlurb;
     34  /** @var mixed */
     35  private $optInOptions;
     36  /** @var mixed */
     37  private $plugins;
     38  /** @var string */
     39  private $serviceWorkerUrl;
     40  /** @var string */
     41  private $frameUrl;
    2142
    2243  /**
     
    125146    return null;
    126147  }
     148
     149  /**
     150   * @return bool
     151   */
     152  public function getResubscribe() {
     153    return $this->resubscribe !== false; // A missing value means "true"
     154  }
     155
     156  /**
     157   * @param bool $resubscribe
     158   * @return WebSdkInitOptions
     159   */
     160  public function setResubscribe($resubscribe) {
     161    $this->resubscribe = $resubscribe !== false;
     162    return $this;
     163  }
     164
     165  /**
     166   * @return array
     167   */
     168  public function getAllowedSubscriptionDomains() {
     169    return $this->allowedSubscriptionDomains;
     170  }
     171
     172  /**
     173   * @param array $allowedSubscriptionDomains
     174   * @return WebSdkInitOptions
     175   */
     176  public function setAllowedSubscriptionDomains($allowedSubscriptionDomains) {
     177    $this->allowedSubscriptionDomains = $allowedSubscriptionDomains;
     178    return $this;
     179  }
     180
     181  /**
     182   * @return mixed
     183   */
     184  public function getSubscriptionNative() {
     185    return $this->subscriptionNative;
     186  }
     187
     188  /**
     189   * @param mixed $subscriptionNative
     190   * @return WebSdkInitOptions
     191   */
     192  public function setSubscriptionNative($subscriptionNative) {
     193    $this->subscriptionNative = $subscriptionNative;
     194    return $this;
     195  }
     196
     197  /**
     198   * @return mixed
     199   */
     200  public function getSubscriptionDialog() {
     201    return $this->subscriptionDialog;
     202  }
     203
     204  /**
     205   * @param mixed $subscriptionDialog
     206   * @return WebSdkInitOptions
     207   */
     208  public function setSubscriptionDialog($subscriptionDialog) {
     209    $this->subscriptionDialog = $subscriptionDialog;
     210    return $this;
     211  }
     212
     213  /**
     214   * @return mixed
     215   */
     216  public function getSubscriptionBell() {
     217    return $this->subscriptionBell;
     218  }
     219
     220  /**
     221   * @param mixed $subscriptionBell
     222   * @return WebSdkInitOptions
     223   */
     224  public function setSubscriptionBell($subscriptionBell) {
     225    $this->subscriptionBell = $subscriptionBell;
     226    return $this;
     227  }
     228
     229  /**
     230   * @return mixed
     231   */
     232  public function getSubscriptionBlurb() {
     233    return $this->subscriptionBlurb;
     234  }
     235
     236  /**
     237   * @param mixed $subscriptionBlurb
     238   * @return WebSdkInitOptions
     239   */
     240  public function setSubscriptionBlurb($subscriptionBlurb) {
     241    $this->subscriptionBlurb = $subscriptionBlurb;
     242    return $this;
     243  }
     244
     245  /**
     246   * @return mixed
     247   */
     248  public function getOptInOptions() {
     249    return $this->optInOptions;
     250  }
     251
     252  /**
     253   * @param mixed $optInOptions
     254   * @return WebSdkInitOptions
     255   */
     256  public function setOptInOptions($optInOptions) {
     257    $this->optInOptions = $optInOptions;
     258    return $this;
     259  }
     260
     261  /**
     262   * @return mixed
     263   */
     264  public function getPlugins() {
     265    return $this->plugins;
     266  }
     267
     268  /**
     269   * @param mixed $plugins
     270   * @return WebSdkInitOptions
     271   */
     272  public function setPlugins($plugins) {
     273    $this->plugins = $plugins;
     274    return $this;
     275  }
     276
     277  /**
     278   * @return string
     279   */
     280  public function getServiceWorkerUrl() {
     281    return $this->serviceWorkerUrl;
     282  }
     283
     284  /**
     285   * @param string $serviceWorkerUrl
     286   * @return WebSdkInitOptions
     287   */
     288  public function setServiceWorkerUrl($serviceWorkerUrl) {
     289    $this->serviceWorkerUrl = $serviceWorkerUrl;
     290    return $this;
     291  }
     292
     293  /**
     294   * @return string
     295   */
     296  public function getFrameUrl() {
     297    return $this->frameUrl;
     298  }
     299
     300  /**
     301   * @param string $frameUrl
     302   * @return WebSdkInitOptions
     303   */
     304  public function setFrameUrl($frameUrl) {
     305    $this->frameUrl = $frameUrl;
     306    return $this;
     307  }
     308
    127309}
  • wonderpush-web-push-notifications/tags/1.12.0/lib/Params/DeliveriesCreateParams.php

    r2663493 r3313743  
    117117
    118118  /**
     119   * @param int|int[] $segmentId A single id, an array of ids, or multiple id parameters.
     120   * @return $this
     121   */
     122  public function setTargetBrevoSegmentIds($segmentId) {
     123    $this->targetType = 'targetBrevoSegmentIds';
     124    $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args());
     125    return $this;
     126  }
     127
     128  /**
     129   * @param int|int[] $listId A single id, an array of ids, or multiple id parameters.
     130   * @return $this
     131   */
     132  public function setTargetBrevoListIds($segmentId) {
     133    $this->targetType = 'targetBrevoListIds';
     134    $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args());
     135    return $this;
     136  }
     137
     138  /**
    119139   * @param array $segment A segment definition
    120140   * @return $this
  • wonderpush-web-push-notifications/tags/1.12.0/lib/WonderPush.php

    r2922221 r3313743  
    22
    33namespace WonderPush;
     4
     5use WonderPush\Net\Request;
    46
    57if (count(get_included_files()) === 1) { http_response_code(403); exit(); } // Prevent direct access
     
    1113
    1214  /**
    13    * API base URL.
     15   * WonderPush Management API base URL.
    1416   *
    1517   * Must contain scheme, host and optional port.
     
    1921   * @see getApiRoot()
    2022   */
    21   const API_BASE = 'https://management-api.wonderpush.com'; // DO NOT END WITH SLASH
     23  const WONDERPUSH_MANAGEMENT_API_BASE = 'https://management-api.wonderpush.com'; // DO NOT END WITH SLASH
     24
     25  /**
     26   * @deprecated
     27   */
     28  const API_BASE = self::WONDERPUSH_MANAGEMENT_API_BASE;
     29
     30  /**
     31   * Brevo Management API base URL.
     32   *
     33   * Must contain scheme, host and optional port.
     34   * Can contain an additional path.
     35   * Must not end with a slash.
     36   * @see getApiBase()
     37   * @see getApiRoot()
     38   */
     39  const BREVO_API_BASE = 'https://api.brevo.com/v3/wonderpush'; // DO NOT END WITH SLASH
    2240
    2341  /**
     
    3856  const VERSION = '2.1.2-dev';
    3957
    40   /** @var string */
    41   private $accessToken;
     58  /** @var Credentials */
     59  private $credentials;
    4260  /** @var string */
    4361  private $applicationId;
     
    88106
    89107  /**
     108   * Lazily initialized Campaigns endpoints.
     109   * @var Api\Campaigns
     110   */
     111  private $campaigns;
     112
     113  /**
    90114   * Lazily initialized Installations endpoints.
    91115   * @var Api\Installations
     
    115139   * You can find your credentials in the _Settings_ / _Configuration_ page of {@link https://dashboard.wonderpush.com/ your project dashboard}.
    116140   *
    117    * @param string $accessToken
     141   * @param string|Credentials A credentials object, or a WonderPush access token string
    118142   *    The Management API access token used to perform API calls.
    119143   * @param string $applicationId
    120144   *    The application id corresponding to the access token.
    121145   */
    122   public function __construct($accessToken, $applicationId = null) {
    123     $this->accessToken = $accessToken;
     146  public function __construct($credentials, $applicationId = null) {
     147    $this->credentials = is_string($credentials) ? new AccessTokenCredentials($credentials) : $credentials;
    124148    $this->applicationId = $applicationId;
     149  }
     150
     151  public function getCredentials() {
     152    return $this->credentials;
    125153  }
    126154
     
    198226   *
    199227   * @return string
    200    * @see API_BASE
     228   * @see WONDERPUSH_MANAGEMENT_API_BASE
    201229   */
    202230  public function getApiBase() {
    203     return $this->apiBase ?: self::API_BASE;
     231    if ($this->apiBase) {
     232      return $this->apiBase;
     233    }
     234    if ($this->credentials instanceof BrevoAPIKeyV3Credentials) {
     235      return self::BREVO_API_BASE;
     236    }
     237    return self::WONDERPUSH_MANAGEMENT_API_BASE;
    204238  }
    205239
     
    285319
    286320  /**
     321   * Campaigns endpoints
     322   * @return Api\Campaigns
     323   */
     324  public function campaigns() {
     325    if ($this->campaigns === null) {
     326      $this->campaigns = new Api\Campaigns($this);
     327    }
     328    return $this->campaigns;
     329  }
     330
     331  /**
    287332   * Stats endpoints
    288333   * @return Api\Stats
     
    308353}
    309354
     355interface Credentials {
     356  /**
     357   * @param Request $request
     358   * @return mixed
     359   */
     360  public function authenticate($request);
     361}
     362
     363class AccessTokenCredentials implements Credentials {
     364
     365  /** @var string */
     366  var $accessToken;
     367
     368  public function __construct($accessToken = null) {
     369    $this->accessToken = $accessToken;
     370  }
     371
     372  public function authenticate($request) {
     373    $request->setQsParam('accessToken', $this->accessToken);
     374  }
     375
     376}
     377
     378class BrevoAPIKeyV3Credentials implements Credentials {
     379
     380  /** @var string */
     381  var $apiKey;
     382
     383  public function __construct($apiKey = null) {
     384    $this->apiKey = $apiKey;
     385  }
     386
     387  public function authenticate($request) {
     388    $request->setHeader('api-key', $this->apiKey);
     389  }
     390
     391}
     392
    310393WonderPush::setGlobalLogger(new Util\DefaultLogger());
  • wonderpush-web-push-notifications/tags/1.12.0/readme.txt

    r3306411 r3313743  
    55Requires at least: 5.0
    66Tested up to: 6.8.1
    7 Stable tag: 1.11.6
     7Stable tag: 1.12.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9090
    9191== Changelog ==
     92= 1.12.0 =
     93- Fixed compatibility with Brevo WordPress plugin
     94
    9295= 1.11.6 =
    9396- Tested support for latest WordPress version
  • wonderpush-web-push-notifications/tags/1.12.0/wonderpush-admin-page.css

    r3097137 r3313743  
    9494  margin-left: 5px;
    9595}
    96 .metric {
    97   display: inline-block;
    98   text-align: center;
    99   padding: 0 10px;
    100 }
    101 .metric span {
    102   display: block;
    103 }
    104 .metric .legend {
    105   font-size: 0.8em;
    106 }
    107 .metric .number {
    108   font-size: 2em;
    109   padding: 5px;
    110 }
    11196.configuration-form {
    11297  text-align: left;
     
    145130  padding: 50px 0;
    146131}
     132.metric {
     133  display: inline-block;
     134  text-align: center;
     135  padding: 0 10px;
     136}
     137.metric span {
     138  display: block;
     139}
     140.metric .legend {
     141  font-size: 0.8em;
     142}
     143.metric .number {
     144  font-size: 2em;
     145  padding: 5px;
     146}
  • wonderpush-web-push-notifications/tags/1.12.0/wonderpush-admin.php

    r3306411 r3313743  
    33
    44class WonderPushAdmin {
    5   const RESOURCES_VERSION = '1.11.6';
     5  const RESOURCES_VERSION = '1.12.0';
    66  const MENU_SLUG = 'wonderpush';
    77  const META_BOX_ID = 'wonderpush_meta_box';
  • wonderpush-web-push-notifications/tags/1.12.0/wonderpush-public.php

    r3306411 r3313743  
    66  static function init() {
    77    add_action('wp_head', array(__CLASS__, 'wonderpush_snippet'), 10);
    8     // For AMP
    98    add_filter( 'the_content', array(__CLASS__, 'the_content'), 10);
    109    if (WonderPushUtils::get_woocommerce()
  • wonderpush-web-push-notifications/tags/1.12.0/wonderpush.php

    r3306411 r3313743  
    88Author: WonderPush
    99Author URI: https://www.wonderpush.com/
    10 Version: 1.11.6
     10Version: 1.12.0
    1111License: GPLv2 or later
    1212*/
  • wonderpush-web-push-notifications/trunk/init.php

    r2922221 r3313743  
    22
    33// WonderPush\Util
    4 require(dirname(__FILE__) . '/lib/Util/JsonSerializable.php');
    5 require(dirname(__FILE__) . '/lib/Util/Logger.php');
    6 require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php');
    7 require(dirname(__FILE__) . '/lib/Util/ArrayUtil.php');
    8 require(dirname(__FILE__) . '/lib/Util/StringUtil.php');
    9 require(dirname(__FILE__) . '/lib/Util/TimeUnit.php');
    10 require(dirname(__FILE__) . '/lib/Util/TimeUtil.php');
    11 require(dirname(__FILE__) . '/lib/Util/TimeValue.php');
    12 require(dirname(__FILE__) . '/lib/Util/UrlUtil.php');
     4if (!interface_exists('WonderPush\Util\JsonSerializable')) require(dirname(__FILE__) . '/lib/Util/JsonSerializable.php');
     5if (!interface_exists('WonderPush\Util\Logger')) require(dirname(__FILE__) . '/lib/Util/Logger.php');
     6if (!class_exists('WonderPush\Util\DefaultLogger')) require(dirname(__FILE__) . '/lib/Util/DefaultLogger.php');
     7if (!class_exists('WonderPush\Util\ArrayUtil')) require(dirname(__FILE__) . '/lib/Util/ArrayUtil.php');
     8if (!class_exists('WonderPush\Util\StringUtil')) require(dirname(__FILE__) . '/lib/Util/StringUtil.php');
     9if (!class_exists('WonderPush\Util\TimeUnit')) require(dirname(__FILE__) . '/lib/Util/TimeUnit.php');
     10if (!class_exists('WonderPush\Util\TimeUtil')) require(dirname(__FILE__) . '/lib/Util/TimeUtil.php');
     11if (!class_exists('WonderPush\Util\TimeValue')) require(dirname(__FILE__) . '/lib/Util/TimeValue.php');
     12if (!class_exists('WonderPush\Util\UrlUtil')) require(dirname(__FILE__) . '/lib/Util/UrlUtil.php');
    1313
    1414// WonderPush
    15 require(dirname(__FILE__) . '/lib/WonderPush.php');
     15if (!class_exists('WonderPush\WonderPush')) require(dirname(__FILE__) . '/lib/WonderPush.php');
    1616
    1717// WonderPush\Obj
    18 require(dirname(__FILE__) . '/lib/Obj/BaseObject.php');
    19 require(dirname(__FILE__) . '/lib/Obj/SuccessResponse.php');
    20 require(dirname(__FILE__) . '/lib/Obj/DeliveriesCreateResponse.php');
    21 require(dirname(__FILE__) . '/lib/Obj/Pagination.php');
    22 require(dirname(__FILE__) . '/lib/Obj/NullObject.php');
    23 require(dirname(__FILE__) . '/lib/Obj/Application.php');
    24 require(dirname(__FILE__) . '/lib/Obj/Segment.php');
    25 require(dirname(__FILE__) . '/lib/Obj/GeoLocation.php');
    26 require(dirname(__FILE__) . '/lib/Obj/User.php');
    27 require(dirname(__FILE__) . '/lib/Obj/Collection.php');
    28 require(dirname(__FILE__) . '/lib/Obj/ApplicationCollection.php');
    29 require(dirname(__FILE__) . '/lib/Obj/SegmentCollection.php');
    30 require(dirname(__FILE__) . '/lib/Obj/Installation.php');
    31 require(dirname(__FILE__) . '/lib/Obj/InstallationCollection.php');
    32 require(dirname(__FILE__) . '/lib/Obj/InstallationApplicationApple.php');
    33 require(dirname(__FILE__) . '/lib/Obj/InstallationApplication.php');
    34 require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceCapabilities.php');
    35 require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceConfiguration.php');
    36 require(dirname(__FILE__) . '/lib/Obj/InstallationDevice.php');
    37 require(dirname(__FILE__) . '/lib/Obj/InstallationPreferences.php');
    38 require(dirname(__FILE__) . '/lib/Obj/InstallationPushToken.php');
    39 require(dirname(__FILE__) . '/lib/Obj/Event.php');
    40 require(dirname(__FILE__) . '/lib/Obj/FrequentFieldValues.php');
    41 require(dirname(__FILE__) . '/lib/Obj/NotificationButton.php');
    42 require(dirname(__FILE__) . '/lib/Obj/NotificationButtonAction.php');
    43 require(dirname(__FILE__) . '/lib/Obj/NotificationButtonActionEvent.php');
    44 require(dirname(__FILE__) . '/lib/Obj/Notification.php');
    45 require(dirname(__FILE__) . '/lib/Obj/NotificationAlert.php');
    46 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroid.php');
    47 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroidButton.php');
    48 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIos.php');
    49 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosAttachment.php');
    50 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosForeground.php');
    51 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWeb.php');
    52 require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWebButton.php');
    53 require(dirname(__FILE__) . '/lib/Obj/NotificationInApp.php');
    54 require(dirname(__FILE__) . '/lib/Obj/NotificationInAppButton.php');
    55 require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMap.php');
    56 require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMapPlace.php');
    57 require(dirname(__FILE__) . '/lib/Obj/NotificationPush.php');
    58 require(dirname(__FILE__) . '/lib/Obj/NotificationPushAndroid.php');
    59 require(dirname(__FILE__) . '/lib/Obj/NotificationPushIos.php');
    60 require(dirname(__FILE__) . '/lib/Obj/NotificationPushWeb.php');
    61 require(dirname(__FILE__) . '/lib/Obj/WebSdkInitOptions.php');
     18if (!class_exists('WonderPush\Obj\BaseObject')) require(dirname(__FILE__) . '/lib/Obj/BaseObject.php');
     19if (!class_exists('WonderPush\Obj\SuccessResponse')) require(dirname(__FILE__) . '/lib/Obj/SuccessResponse.php');
     20if (!class_exists('WonderPush\Obj\CampaignSuccessResponse')) require(dirname(__FILE__) . '/lib/Obj/CampaignSuccessResponse.php');
     21if (!class_exists('WonderPush\Obj\DeliveriesCreateResponse')) require(dirname(__FILE__) . '/lib/Obj/DeliveriesCreateResponse.php');
     22if (!class_exists('WonderPush\Obj\Pagination')) require(dirname(__FILE__) . '/lib/Obj/Pagination.php');
     23if (!class_exists('WonderPush\Obj\NullObject')) require(dirname(__FILE__) . '/lib/Obj/NullObject.php');
     24if (!class_exists('WonderPush\Obj\Application')) require(dirname(__FILE__) . '/lib/Obj/Application.php');
     25if (!class_exists('WonderPush\Obj\Segment')) require(dirname(__FILE__) . '/lib/Obj/Segment.php');
     26if (!class_exists('WonderPush\Obj\GeoLocation')) require(dirname(__FILE__) . '/lib/Obj/GeoLocation.php');
     27if (!class_exists('WonderPush\Obj\User')) require(dirname(__FILE__) . '/lib/Obj/User.php');
     28if (!class_exists('WonderPush\Obj\Collection')) require(dirname(__FILE__) . '/lib/Obj/Collection.php');
     29if (!class_exists('WonderPush\Obj\CampaignCollection')) require(dirname(__FILE__) . '/lib/Obj/CampaignCollection.php');
     30if (!class_exists('WonderPush\Obj\ApplicationCollection')) require(dirname(__FILE__) . '/lib/Obj/ApplicationCollection.php');
     31if (!class_exists('WonderPush\Obj\SegmentCollection')) require(dirname(__FILE__) . '/lib/Obj/SegmentCollection.php');
     32if (!class_exists('WonderPush\Obj\Installation')) require(dirname(__FILE__) . '/lib/Obj/Installation.php');
     33if (!class_exists('WonderPush\Obj\InstallationCollection')) require(dirname(__FILE__) . '/lib/Obj/InstallationCollection.php');
     34if (!class_exists('WonderPush\Obj\InstallationApplicationApple')) require(dirname(__FILE__) . '/lib/Obj/InstallationApplicationApple.php');
     35if (!class_exists('WonderPush\Obj\InstallationApplication')) require(dirname(__FILE__) . '/lib/Obj/InstallationApplication.php');
     36if (!class_exists('WonderPush\Obj\InstallationDeviceCapabilities')) require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceCapabilities.php');
     37if (!class_exists('WonderPush\Obj\InstallationDeviceConfiguration')) require(dirname(__FILE__) . '/lib/Obj/InstallationDeviceConfiguration.php');
     38if (!class_exists('WonderPush\Obj\InstallationDevice')) require(dirname(__FILE__) . '/lib/Obj/InstallationDevice.php');
     39if (!class_exists('WonderPush\Obj\InstallationPreferences')) require(dirname(__FILE__) . '/lib/Obj/InstallationPreferences.php');
     40if (!class_exists('WonderPush\Obj\InstallationPushToken')) require(dirname(__FILE__) . '/lib/Obj/InstallationPushToken.php');
     41if (!class_exists('WonderPush\Obj\Event')) require(dirname(__FILE__) . '/lib/Obj/Event.php');
     42if (!class_exists('WonderPush\Obj\FrequentFieldValues')) require(dirname(__FILE__) . '/lib/Obj/FrequentFieldValues.php');
     43if (!class_exists('WonderPush\Obj\NotificationButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationButton.php');
     44if (!class_exists('WonderPush\Obj\NotificationButtonAction')) require(dirname(__FILE__) . '/lib/Obj/NotificationButtonAction.php');
     45if (!class_exists('WonderPush\Obj\NotificationButtonActionEvent')) require(dirname(__FILE__) . '/lib/Obj/NotificationButtonActionEvent.php');
     46if (!class_exists('WonderPush\Obj\Notification')) require(dirname(__FILE__) . '/lib/Obj/Notification.php');
     47if (!class_exists('WonderPush\Obj\NotificationAlert')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlert.php');
     48if (!class_exists('WonderPush\Obj\NotificationAlertAndroid')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroid.php');
     49if (!class_exists('WonderPush\Obj\NotificationAlertAndroidButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertAndroidButton.php');
     50if (!class_exists('WonderPush\Obj\NotificationAlertIos')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIos.php');
     51if (!class_exists('WonderPush\Obj\NotificationAlertIosAttachment')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosAttachment.php');
     52if (!class_exists('WonderPush\Obj\NotificationAlertIosForeground')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertIosForeground.php');
     53if (!class_exists('WonderPush\Obj\NotificationAlertWeb')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWeb.php');
     54if (!class_exists('WonderPush\Obj\NotificationAlertWebButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationAlertWebButton.php');
     55if (!class_exists('WonderPush\Obj\NotificationInApp')) require(dirname(__FILE__) . '/lib/Obj/NotificationInApp.php');
     56if (!class_exists('WonderPush\Obj\NotificationInAppButton')) require(dirname(__FILE__) . '/lib/Obj/NotificationInAppButton.php');
     57if (!class_exists('WonderPush\Obj\NotificationInAppMap')) require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMap.php');
     58if (!class_exists('WonderPush\Obj\NotificationInAppMapPlace')) require(dirname(__FILE__) . '/lib/Obj/NotificationInAppMapPlace.php');
     59if (!class_exists('WonderPush\Obj\NotificationPush')) require(dirname(__FILE__) . '/lib/Obj/NotificationPush.php');
     60if (!class_exists('WonderPush\Obj\NotificationPushAndroid')) require(dirname(__FILE__) . '/lib/Obj/NotificationPushAndroid.php');
     61if (!class_exists('WonderPush\Obj\NotificationPushIos')) require(dirname(__FILE__) . '/lib/Obj/NotificationPushIos.php');
     62if (!class_exists('WonderPush\Obj\NotificationPushWeb')) require(dirname(__FILE__) . '/lib/Obj/NotificationPushWeb.php');
     63if (!class_exists('WonderPush\Obj\Campaign')) require(dirname(__FILE__) . '/lib/Obj/Campaign.php');
     64if (!class_exists('WonderPush\Obj\CampaignSchedule')) require(dirname(__FILE__) . '/lib/Obj/CampaignSchedule.php');
     65if (!class_exists('WonderPush\Obj\CampaignSchedulePressure')) require(dirname(__FILE__) . '/lib/Obj/CampaignSchedulePressure.php');
     66if (!class_exists('WonderPush\Obj\CampaignScheduleUrlCriterion')) require(dirname(__FILE__) . '/lib/Obj/CampaignScheduleUrlCriterion.php');
     67if (!class_exists('WonderPush\Obj\CampaignStats')) require(dirname(__FILE__) . '/lib/Obj/CampaignStats.php');
     68if (!class_exists('WonderPush\Obj\CampaignUrlFilters')) require(dirname(__FILE__) . '/lib/Obj/CampaignUrlFilters.php');
     69if (!class_exists('WonderPush\Obj\CampaignCapping')) require(dirname(__FILE__) . '/lib/Obj/CampaignCapping.php');
     70
     71if (!class_exists('WonderPush\Obj\WebSdkInitOptions')) require(dirname(__FILE__) . '/lib/Obj/WebSdkInitOptions.php');
    6272
    6373// WonderPush\Params
    64 require(dirname(__FILE__) . '/lib/Params/CollectionParams.php');
    65 require(dirname(__FILE__) . '/lib/Params/DeliveriesCreateParams.php');
    66 require(dirname(__FILE__) . '/lib/Params/FrequentFieldValuesParams.php');
    67 require(dirname(__FILE__) . '/lib/Params/AllInstallationsParams.php');
    68 require(dirname(__FILE__) . '/lib/Params/PatchInstallationParams.php');
    69 require(dirname(__FILE__) . '/lib/Params/TrackEventParams.php');
     74if (!class_exists('WonderPush\Params\CollectionParams')) require(dirname(__FILE__) . '/lib/Params/CollectionParams.php');
     75if (!class_exists('WonderPush\Params\DeliveriesCreateParams')) require(dirname(__FILE__) . '/lib/Params/DeliveriesCreateParams.php');
     76if (!class_exists('WonderPush\Params\FrequentFieldValuesParams')) require(dirname(__FILE__) . '/lib/Params/FrequentFieldValuesParams.php');
     77if (!class_exists('WonderPush\Params\AllInstallationsParams')) require(dirname(__FILE__) . '/lib/Params/AllInstallationsParams.php');
     78if (!class_exists('WonderPush\Params\PatchInstallationParams')) require(dirname(__FILE__) . '/lib/Params/PatchInstallationParams.php');
     79if (!class_exists('WonderPush\Params\TrackEventParams')) require(dirname(__FILE__) . '/lib/Params/TrackEventParams.php');
     80if (!class_exists('WonderPush\Params\PatchCampaignParams')) require(dirname(__FILE__) . '/lib/Params/PatchCampaignParams.php');
     81if (!class_exists('WonderPush\Params\CreateCampaignParams')) require(dirname(__FILE__) . '/lib/Params/CreateCampaignParams.php');
    7082
    7183// WonderPush\Net
    72 require(dirname(__FILE__) . '/lib/Net/Request.php');
    73 require(dirname(__FILE__) . '/lib/Net/Response.php');
    74 require(dirname(__FILE__) . '/lib/Net/HttpClientInterface.php');
    75 require(dirname(__FILE__) . '/lib/Net/CurlHttpClient.php');
     84if (!class_exists('WonderPush\Net\Request')) require(dirname(__FILE__) . '/lib/Net/Request.php');
     85if (!class_exists('WonderPush\Net\Response')) require(dirname(__FILE__) . '/lib/Net/Response.php');
     86if (!interface_exists('WonderPush\Net\HttpClientInterface')) require(dirname(__FILE__) . '/lib/Net/HttpClientInterface.php');
     87if (!class_exists('WonderPush\Net\CurlHttpClient')) require(dirname(__FILE__) . '/lib/Net/CurlHttpClient.php');
    7688
    7789// WonderPush\Errors
    78 require(dirname(__FILE__) . '/lib/Errors/Base.php');
    79 require(dirname(__FILE__) . '/lib/Errors/Parsing.php');
    80 require(dirname(__FILE__) . '/lib/Errors/Server.php');
    81 require(dirname(__FILE__) . '/lib/Errors/Network.php');
     90if (!class_exists('WonderPush\Errors\Base')) require(dirname(__FILE__) . '/lib/Errors/Base.php');
     91if (!class_exists('WonderPush\Errors\Parsing')) require(dirname(__FILE__) . '/lib/Errors/Parsing.php');
     92if (!class_exists('WonderPush\Errors\Server')) require(dirname(__FILE__) . '/lib/Errors/Server.php');
     93if (!class_exists('WonderPush\Errors\Network')) require(dirname(__FILE__) . '/lib/Errors/Network.php');
    8294
    8395// WonderPush\Api
    84 require(dirname(__FILE__) . '/lib/Api/Rest.php');
    85 require(dirname(__FILE__) . '/lib/Api/Deliveries.php');
    86 require(dirname(__FILE__) . '/lib/Api/Applications.php');
    87 require(dirname(__FILE__) . '/lib/Api/Segments.php');
    88 require(dirname(__FILE__) . '/lib/Api/Stats.php');
    89 require(dirname(__FILE__) . '/lib/Api/Installations.php');
    90 require(dirname(__FILE__) . '/lib/Api/Events.php');
     96if (!class_exists('WonderPush\Api\Rest')) require(dirname(__FILE__) . '/lib/Api/Rest.php');
     97if (!class_exists('WonderPush\Api\Deliveries')) require(dirname(__FILE__) . '/lib/Api/Deliveries.php');
     98if (!class_exists('WonderPush\Api\Applications')) require(dirname(__FILE__) . '/lib/Api/Applications.php');
     99if (!class_exists('WonderPush\Api\Segments')) require(dirname(__FILE__) . '/lib/Api/Segments.php');
     100if (!class_exists('WonderPush\Api\Stats')) require(dirname(__FILE__) . '/lib/Api/Stats.php');
     101if (!class_exists('WonderPush\Api\Installations')) require(dirname(__FILE__) . '/lib/Api/Installations.php');
     102if (!class_exists('WonderPush\Api\Campaigns')) require(dirname(__FILE__) . '/lib/Api/Campaigns.php');
     103if (!class_exists('WonderPush\Api\Events')) require(dirname(__FILE__) . '/lib/Api/Events.php');
  • wonderpush-web-push-notifications/trunk/lib/Api/Rest.php

    r2481484 r3313743  
    3838    $rtn->setPath($path);
    3939    $rtn->setParams($params);
    40     $rtn->setQsParams(array_filter(array(
    41         'accessToken' => $this->wp->getAccessToken(),
    42         'applicationId' => $this->wp->getApplicationId(), // filtered if null
    43     )));
     40    $rtn->setQsParam('applicationId', $this->wp->getApplicationId()); // filtered if null
     41    if ($this->wp->getCredentials()) {
     42      $this->wp->getCredentials()->authenticate($rtn);
     43    }
    4444    return $rtn;
    4545  }
  • wonderpush-web-push-notifications/trunk/lib/Net/CurlHttpClient.php

    r3097137 r3313743  
    99 */
    1010class CurlHttpClient implements HttpClientInterface {
     11
     12  public static $logging = false;
     13  public static $loggingResponses = false;
    1114
    1215  /**
     
    5356      case Request::GET:
    5457      case Request::DELETE:
    55         $qsParams = array_merge($qsParams, $request->getParams());
     58        $qsParams = array_merge($qsParams ?: array(), $request->getParams());
    5659        break;
    5760      case Request::PUT:
     
    5962      case Request::PATCH:
    6063        $body = $request->getParams();
    61         if (empty($body)) {
     64        $files = $request->getFiles();
     65        if (count($files)) {
     66          $body = $request->getParams() ?: array();
     67          foreach ($files as $name => $file) {
     68            $body[$name] = new \CURLFile($file['tmp_name'], $file['type'], $file['name']);
     69          }
     70        } else if (empty($body)) {
    6271          $body = null;
    6372        } else {
     
    133142
    134143    // Execute cURL request
     144    $start = microtime(true);
    135145    $rawResponse = curl_exec($ch);
     146    if (self::$logging) {
     147      error_log('--> ' . $request->getMethod() . ' ' . $url . ' ' . $body . (empty($headers) ? '' : ' ' . json_encode($headers)) . ' (' . intval(1000 * (microtime(true) - $start)) . 'ms)');
     148    }
    136149
    137150    // Parse response
     
    155168    }
    156169
     170    if (self::$logging && self::$loggingResponses) {
     171      error_log('<-- (' . $response->getStatusCode() . ') ' . ($response->getRawBody() ?: '<no body>') . (empty($response->getHeaders()) ? '' : ' ' . json_encode($response->getHeaders())));
     172    }
     173
    157174    // Cleanup
    158175    curl_close($ch);
  • wonderpush-web-push-notifications/trunk/lib/Net/Request.php

    r2481484 r3313743  
    7878
    7979  /**
     80   * An associative array of 'paramName' => ['tmp_name' => '/full/path','name' => 'filename.png', 'type' => 'image/png'].
     81   * @var mixed
     82   */
     83  private $files = array();
     84
     85  /**
    8086   * HTTP headers.
    8187   * @var mixed[]
     
    174180
    175181  /**
     182   * @param $key
     183   * @param $value
     184   * @return $this
     185   */
     186  public function setQsParam($key, $value) {
     187    if ($key === null) return $this;
     188    if (!$this->qsParams) {
     189      $this->qsParams = array();
     190    }
     191    if ($value === null) {
     192      unset($this->qsParams[$key]);
     193    } else {
     194      $this->qsParams[$key] = $value;
     195    }
     196    return $this;
     197  }
     198
     199  public function addFile($paramName, $filename, $path, $type) {
     200    $this->files[$paramName] = array(
     201      'name' => $filename,
     202      'tmp_name' => $path,
     203      'type' => $type,
     204    );
     205    return $this;
     206  }
     207
     208  public function removeFile($paramName) {
     209    unset($this->files[$paramName]);
     210    return $this;
     211  }
     212
     213  public function getFiles() {
     214    return $this->files;
     215  }
     216
     217  /**
    176218   * The body parameters.
    177219   *
     
    215257  }
    216258
     259  /**
     260   * @param $key
     261   * @param $value
     262   * @return $this
     263   */
     264  public function setHeader($key, $value) {
     265    if ($key === null) return $this;
     266    if (!$this->headers) {
     267      $this->headers = array();
     268    }
     269    if ($value === null) {
     270      unset($this->headers[$key]);
     271    } else {
     272      $this->headers[$key] = $value;
     273    }
     274    return $this;
     275  }
    217276}
  • wonderpush-web-push-notifications/trunk/lib/Obj/Application.php

    r2588630 r3313743  
    2727  /** @var object */
    2828  private $urlParameters;
     29  /** @var string */
     30  private $status;
     31  /** @var integer */
     32  private $subscribers;
     33  /** @var array */
     34  private $pushDisabledPlatforms;
     35  /** @var boolean */
     36  private $wordPressSnippetDeactivated;
    2937
    3038  /**
     
    140148    return $this;
    141149  }
     150
     151  /**
     152   * @return string|null
     153   */
     154  public function getStatus()
     155  {
     156    return $this->status ?: null;
     157  }
     158
     159  /**
     160   * @param string $status
     161   * @return Application
     162   */
     163  public function setStatus($status)
     164  {
     165    $this->status = $status;
     166    return $this;
     167  }
     168
     169  /**
     170   * @return int
     171   */
     172  public function getSubscribers()
     173  {
     174    return $this->subscribers ?: 0;
     175  }
     176
     177  /**
     178   * @param int $subscribers
     179   * @return Application
     180   */
     181  public function setSubscribers( $subscribers )
     182  {
     183    $this->subscribers = $subscribers;
     184    return $this;
     185  }
     186
     187  /**
     188   * @return array
     189   */
     190  public function getPushDisabledPlatforms()
     191  {
     192    return $this->pushDisabledPlatforms;
     193  }
     194
     195  /**
     196   * @param array $pushDisabledPlatforms
     197   * @return Application
     198   */
     199  public function setPushDisabledPlatforms($pushDisabledPlatforms)
     200  {
     201    $this->pushDisabledPlatforms = (array)$pushDisabledPlatforms;
     202    return $this;
     203  }
     204
     205  public function getWordPressSnippetDeactivated()
     206  {
     207    return (bool)$this->wordPressSnippetDeactivated;
     208  }
     209
     210  public function setWordPressSnippetDeactivated($wordPressSnippetDeactivated)
     211  {
     212    $this->wordPressSnippetDeactivated = (bool)$wordPressSnippetDeactivated;
     213    return $this;
     214  }
    142215}
  • wonderpush-web-push-notifications/trunk/lib/Obj/WebSdkInitOptions.php

    r2481484 r3313743  
    1919  /** @var string */
    2020  private $manifestUrl;
     21  /** @var bool */
     22  private $resubscribe;
     23
     24  /** @var array */
     25  private $allowedSubscriptionDomains;
     26  /** @var mixed */
     27  private $subscriptionNative;
     28  /** @var mixed */
     29  private $subscriptionDialog;
     30  /** @var mixed */
     31  private $subscriptionBell;
     32  /** @var mixed */
     33  private $subscriptionBlurb;
     34  /** @var mixed */
     35  private $optInOptions;
     36  /** @var mixed */
     37  private $plugins;
     38  /** @var string */
     39  private $serviceWorkerUrl;
     40  /** @var string */
     41  private $frameUrl;
    2142
    2243  /**
     
    125146    return null;
    126147  }
     148
     149  /**
     150   * @return bool
     151   */
     152  public function getResubscribe() {
     153    return $this->resubscribe !== false; // A missing value means "true"
     154  }
     155
     156  /**
     157   * @param bool $resubscribe
     158   * @return WebSdkInitOptions
     159   */
     160  public function setResubscribe($resubscribe) {
     161    $this->resubscribe = $resubscribe !== false;
     162    return $this;
     163  }
     164
     165  /**
     166   * @return array
     167   */
     168  public function getAllowedSubscriptionDomains() {
     169    return $this->allowedSubscriptionDomains;
     170  }
     171
     172  /**
     173   * @param array $allowedSubscriptionDomains
     174   * @return WebSdkInitOptions
     175   */
     176  public function setAllowedSubscriptionDomains($allowedSubscriptionDomains) {
     177    $this->allowedSubscriptionDomains = $allowedSubscriptionDomains;
     178    return $this;
     179  }
     180
     181  /**
     182   * @return mixed
     183   */
     184  public function getSubscriptionNative() {
     185    return $this->subscriptionNative;
     186  }
     187
     188  /**
     189   * @param mixed $subscriptionNative
     190   * @return WebSdkInitOptions
     191   */
     192  public function setSubscriptionNative($subscriptionNative) {
     193    $this->subscriptionNative = $subscriptionNative;
     194    return $this;
     195  }
     196
     197  /**
     198   * @return mixed
     199   */
     200  public function getSubscriptionDialog() {
     201    return $this->subscriptionDialog;
     202  }
     203
     204  /**
     205   * @param mixed $subscriptionDialog
     206   * @return WebSdkInitOptions
     207   */
     208  public function setSubscriptionDialog($subscriptionDialog) {
     209    $this->subscriptionDialog = $subscriptionDialog;
     210    return $this;
     211  }
     212
     213  /**
     214   * @return mixed
     215   */
     216  public function getSubscriptionBell() {
     217    return $this->subscriptionBell;
     218  }
     219
     220  /**
     221   * @param mixed $subscriptionBell
     222   * @return WebSdkInitOptions
     223   */
     224  public function setSubscriptionBell($subscriptionBell) {
     225    $this->subscriptionBell = $subscriptionBell;
     226    return $this;
     227  }
     228
     229  /**
     230   * @return mixed
     231   */
     232  public function getSubscriptionBlurb() {
     233    return $this->subscriptionBlurb;
     234  }
     235
     236  /**
     237   * @param mixed $subscriptionBlurb
     238   * @return WebSdkInitOptions
     239   */
     240  public function setSubscriptionBlurb($subscriptionBlurb) {
     241    $this->subscriptionBlurb = $subscriptionBlurb;
     242    return $this;
     243  }
     244
     245  /**
     246   * @return mixed
     247   */
     248  public function getOptInOptions() {
     249    return $this->optInOptions;
     250  }
     251
     252  /**
     253   * @param mixed $optInOptions
     254   * @return WebSdkInitOptions
     255   */
     256  public function setOptInOptions($optInOptions) {
     257    $this->optInOptions = $optInOptions;
     258    return $this;
     259  }
     260
     261  /**
     262   * @return mixed
     263   */
     264  public function getPlugins() {
     265    return $this->plugins;
     266  }
     267
     268  /**
     269   * @param mixed $plugins
     270   * @return WebSdkInitOptions
     271   */
     272  public function setPlugins($plugins) {
     273    $this->plugins = $plugins;
     274    return $this;
     275  }
     276
     277  /**
     278   * @return string
     279   */
     280  public function getServiceWorkerUrl() {
     281    return $this->serviceWorkerUrl;
     282  }
     283
     284  /**
     285   * @param string $serviceWorkerUrl
     286   * @return WebSdkInitOptions
     287   */
     288  public function setServiceWorkerUrl($serviceWorkerUrl) {
     289    $this->serviceWorkerUrl = $serviceWorkerUrl;
     290    return $this;
     291  }
     292
     293  /**
     294   * @return string
     295   */
     296  public function getFrameUrl() {
     297    return $this->frameUrl;
     298  }
     299
     300  /**
     301   * @param string $frameUrl
     302   * @return WebSdkInitOptions
     303   */
     304  public function setFrameUrl($frameUrl) {
     305    $this->frameUrl = $frameUrl;
     306    return $this;
     307  }
     308
    127309}
  • wonderpush-web-push-notifications/trunk/lib/Params/DeliveriesCreateParams.php

    r2663493 r3313743  
    117117
    118118  /**
     119   * @param int|int[] $segmentId A single id, an array of ids, or multiple id parameters.
     120   * @return $this
     121   */
     122  public function setTargetBrevoSegmentIds($segmentId) {
     123    $this->targetType = 'targetBrevoSegmentIds';
     124    $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args());
     125    return $this;
     126  }
     127
     128  /**
     129   * @param int|int[] $listId A single id, an array of ids, or multiple id parameters.
     130   * @return $this
     131   */
     132  public function setTargetBrevoListIds($segmentId) {
     133    $this->targetType = 'targetBrevoListIds';
     134    $this->targetValues = \WonderPush\Util\ArrayUtil::flatten(func_get_args());
     135    return $this;
     136  }
     137
     138  /**
    119139   * @param array $segment A segment definition
    120140   * @return $this
  • wonderpush-web-push-notifications/trunk/lib/WonderPush.php

    r2922221 r3313743  
    22
    33namespace WonderPush;
     4
     5use WonderPush\Net\Request;
    46
    57if (count(get_included_files()) === 1) { http_response_code(403); exit(); } // Prevent direct access
     
    1113
    1214  /**
    13    * API base URL.
     15   * WonderPush Management API base URL.
    1416   *
    1517   * Must contain scheme, host and optional port.
     
    1921   * @see getApiRoot()
    2022   */
    21   const API_BASE = 'https://management-api.wonderpush.com'; // DO NOT END WITH SLASH
     23  const WONDERPUSH_MANAGEMENT_API_BASE = 'https://management-api.wonderpush.com'; // DO NOT END WITH SLASH
     24
     25  /**
     26   * @deprecated
     27   */
     28  const API_BASE = self::WONDERPUSH_MANAGEMENT_API_BASE;
     29
     30  /**
     31   * Brevo Management API base URL.
     32   *
     33   * Must contain scheme, host and optional port.
     34   * Can contain an additional path.
     35   * Must not end with a slash.
     36   * @see getApiBase()
     37   * @see getApiRoot()
     38   */
     39  const BREVO_API_BASE = 'https://api.brevo.com/v3/wonderpush'; // DO NOT END WITH SLASH
    2240
    2341  /**
     
    3856  const VERSION = '2.1.2-dev';
    3957
    40   /** @var string */
    41   private $accessToken;
     58  /** @var Credentials */
     59  private $credentials;
    4260  /** @var string */
    4361  private $applicationId;
     
    88106
    89107  /**
     108   * Lazily initialized Campaigns endpoints.
     109   * @var Api\Campaigns
     110   */
     111  private $campaigns;
     112
     113  /**
    90114   * Lazily initialized Installations endpoints.
    91115   * @var Api\Installations
     
    115139   * You can find your credentials in the _Settings_ / _Configuration_ page of {@link https://dashboard.wonderpush.com/ your project dashboard}.
    116140   *
    117    * @param string $accessToken
     141   * @param string|Credentials A credentials object, or a WonderPush access token string
    118142   *    The Management API access token used to perform API calls.
    119143   * @param string $applicationId
    120144   *    The application id corresponding to the access token.
    121145   */
    122   public function __construct($accessToken, $applicationId = null) {
    123     $this->accessToken = $accessToken;
     146  public function __construct($credentials, $applicationId = null) {
     147    $this->credentials = is_string($credentials) ? new AccessTokenCredentials($credentials) : $credentials;
    124148    $this->applicationId = $applicationId;
     149  }
     150
     151  public function getCredentials() {
     152    return $this->credentials;
    125153  }
    126154
     
    198226   *
    199227   * @return string
    200    * @see API_BASE
     228   * @see WONDERPUSH_MANAGEMENT_API_BASE
    201229   */
    202230  public function getApiBase() {
    203     return $this->apiBase ?: self::API_BASE;
     231    if ($this->apiBase) {
     232      return $this->apiBase;
     233    }
     234    if ($this->credentials instanceof BrevoAPIKeyV3Credentials) {
     235      return self::BREVO_API_BASE;
     236    }
     237    return self::WONDERPUSH_MANAGEMENT_API_BASE;
    204238  }
    205239
     
    285319
    286320  /**
     321   * Campaigns endpoints
     322   * @return Api\Campaigns
     323   */
     324  public function campaigns() {
     325    if ($this->campaigns === null) {
     326      $this->campaigns = new Api\Campaigns($this);
     327    }
     328    return $this->campaigns;
     329  }
     330
     331  /**
    287332   * Stats endpoints
    288333   * @return Api\Stats
     
    308353}
    309354
     355interface Credentials {
     356  /**
     357   * @param Request $request
     358   * @return mixed
     359   */
     360  public function authenticate($request);
     361}
     362
     363class AccessTokenCredentials implements Credentials {
     364
     365  /** @var string */
     366  var $accessToken;
     367
     368  public function __construct($accessToken = null) {
     369    $this->accessToken = $accessToken;
     370  }
     371
     372  public function authenticate($request) {
     373    $request->setQsParam('accessToken', $this->accessToken);
     374  }
     375
     376}
     377
     378class BrevoAPIKeyV3Credentials implements Credentials {
     379
     380  /** @var string */
     381  var $apiKey;
     382
     383  public function __construct($apiKey = null) {
     384    $this->apiKey = $apiKey;
     385  }
     386
     387  public function authenticate($request) {
     388    $request->setHeader('api-key', $this->apiKey);
     389  }
     390
     391}
     392
    310393WonderPush::setGlobalLogger(new Util\DefaultLogger());
  • wonderpush-web-push-notifications/trunk/readme.txt

    r3306411 r3313743  
    55Requires at least: 5.0
    66Tested up to: 6.8.1
    7 Stable tag: 1.11.6
     7Stable tag: 1.12.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9090
    9191== Changelog ==
     92= 1.12.0 =
     93- Fixed compatibility with Brevo WordPress plugin
     94
    9295= 1.11.6 =
    9396- Tested support for latest WordPress version
  • wonderpush-web-push-notifications/trunk/wonderpush-admin-page.css

    r3097137 r3313743  
    9494  margin-left: 5px;
    9595}
    96 .metric {
    97   display: inline-block;
    98   text-align: center;
    99   padding: 0 10px;
    100 }
    101 .metric span {
    102   display: block;
    103 }
    104 .metric .legend {
    105   font-size: 0.8em;
    106 }
    107 .metric .number {
    108   font-size: 2em;
    109   padding: 5px;
    110 }
    11196.configuration-form {
    11297  text-align: left;
     
    145130  padding: 50px 0;
    146131}
     132.metric {
     133  display: inline-block;
     134  text-align: center;
     135  padding: 0 10px;
     136}
     137.metric span {
     138  display: block;
     139}
     140.metric .legend {
     141  font-size: 0.8em;
     142}
     143.metric .number {
     144  font-size: 2em;
     145  padding: 5px;
     146}
  • wonderpush-web-push-notifications/trunk/wonderpush-admin.php

    r3306411 r3313743  
    33
    44class WonderPushAdmin {
    5   const RESOURCES_VERSION = '1.11.6';
     5  const RESOURCES_VERSION = '1.12.0';
    66  const MENU_SLUG = 'wonderpush';
    77  const META_BOX_ID = 'wonderpush_meta_box';
  • wonderpush-web-push-notifications/trunk/wonderpush-public.php

    r3306411 r3313743  
    66  static function init() {
    77    add_action('wp_head', array(__CLASS__, 'wonderpush_snippet'), 10);
    8     // For AMP
    98    add_filter( 'the_content', array(__CLASS__, 'the_content'), 10);
    109    if (WonderPushUtils::get_woocommerce()
  • wonderpush-web-push-notifications/trunk/wonderpush.php

    r3306411 r3313743  
    88Author: WonderPush
    99Author URI: https://www.wonderpush.com/
    10 Version: 1.11.6
     10Version: 1.12.0
    1111License: GPLv2 or later
    1212*/
Note: See TracChangeset for help on using the changeset viewer.