| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | * The Wincher route prefix. |
| 20 | 20 | * |
| 21 | 21 | * @var string |
| 22 | 22 | */ |
| 23 | - const ROUTE_PREFIX = 'wincher'; | |
| 23 | + public const ROUTE_PREFIX = 'wincher'; | |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * The authorize route constant. |
| 27 | 27 | * |
| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | * The authorize route constant. |
| 27 | 27 | * |
| 28 | 28 | * @var string |
| 29 | 29 | */ |
| 30 | - const AUTHORIZATION_URL_ROUTE = self::ROUTE_PREFIX . '/authorization-url'; | |
| 30 | + public const AUTHORIZATION_URL_ROUTE = self::ROUTE_PREFIX . '/authorization-url'; | |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The authenticate route constant. |
| 34 | 34 | * |
| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | * The authenticate route constant. |
| 34 | 34 | * |
| 35 | 35 | * @var string |
| 36 | 36 | */ |
| 37 | - const AUTHENTICATION_ROUTE = self::ROUTE_PREFIX . '/authenticate'; | |
| 37 | + public const AUTHENTICATION_ROUTE = self::ROUTE_PREFIX . '/authenticate'; | |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * The track bulk keyphrases route constant. |
| 41 | 41 | * |
| @@ -40,9 +40,9 @@ | ||
| 40 | 40 | * The track bulk keyphrases route constant. |
| 41 | 41 | * |
| 42 | 42 | * @var string |
| 43 | 43 | */ |
| 44 | - const KEYPHRASES_TRACK_ROUTE = self::ROUTE_PREFIX . '/keyphrases/track'; | |
| 44 | + public const KEYPHRASES_TRACK_ROUTE = self::ROUTE_PREFIX . '/keyphrases/track'; | |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The keyphrases route constant. |
| 48 | 48 | * |
| @@ -47,9 +47,9 @@ | ||
| 47 | 47 | * The keyphrases route constant. |
| 48 | 48 | * |
| 49 | 49 | * @var string |
| 50 | 50 | */ |
| 51 | - const TRACKED_KEYPHRASES_ROUTE = self::ROUTE_PREFIX . '/keyphrases'; | |
| 51 | + public const TRACKED_KEYPHRASES_ROUTE = self::ROUTE_PREFIX . '/keyphrases'; | |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * The untrack keyphrase route constant. |
| 55 | 55 | * |
| @@ -54,11 +54,25 @@ | ||
| 54 | 54 | * The untrack keyphrase route constant. |
| 55 | 55 | * |
| 56 | 56 | * @var string |
| 57 | 57 | */ |
| 58 | - const UNTRACK_KEYPHRASE_ROUTE = self::ROUTE_PREFIX . '/keyphrases/untrack'; | |
| 58 | + public const UNTRACK_KEYPHRASE_ROUTE = self::ROUTE_PREFIX . '/keyphrases/untrack'; | |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | + * The check limit route constant. | |
| 62 | + * | |
| 63 | + * @var string | |
| 64 | + */ | |
| 65 | + public const CHECK_LIMIT_ROUTE = self::ROUTE_PREFIX . '/account/limit'; | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * The upgrade campaign route constant. | |
| 69 | + * | |
| 70 | + * @var string | |
| 71 | + */ | |
| 72 | + public const UPGRADE_CAMPAIGN_ROUTE = self::ROUTE_PREFIX . '/account/upgrade-campaign'; | |
| 73 | + | |
| 74 | + /** | |
| 61 | 75 | * The login action. |
| 62 | 76 | * |
| 63 | 77 | * @var Wincher_Login_Action |
| 64 | 78 | */ |
| @@ -158,8 +172,11 @@ | ||
| 158 | 172 | ], |
| 159 | 173 | 'permalink' => [ |
| 160 | 174 | 'required' => false, |
| 161 | 175 | ], |
| 176 | + 'startAt' => [ | |
| 177 | + 'required' => false, | |
| 178 | + ], | |
| 162 | 179 | ], |
| 163 | 180 | ]; |
| 164 | 181 | |
| 165 | 182 | \register_rest_route( Main::API_V1_NAMESPACE, self::TRACKED_KEYPHRASES_ROUTE, $get_keyphrases_route_args ); |
| @@ -170,8 +187,24 @@ | ||
| 170 | 187 | 'permission_callback' => [ $this, 'can_use_wincher' ], |
| 171 | 188 | ]; |
| 172 | 189 | |
| 173 | 190 | \register_rest_route( Main::API_V1_NAMESPACE, self::UNTRACK_KEYPHRASE_ROUTE, $delete_keyphrase_route_args ); |
| 191 | + | |
| 192 | + $check_limit_route_args = [ | |
| 193 | + 'methods' => 'GET', | |
| 194 | + 'callback' => [ $this, 'check_limit' ], | |
| 195 | + 'permission_callback' => [ $this, 'can_use_wincher' ], | |
| 196 | + ]; | |
| 197 | + | |
| 198 | + \register_rest_route( Main::API_V1_NAMESPACE, self::CHECK_LIMIT_ROUTE, $check_limit_route_args ); | |
| 199 | + | |
| 200 | + $get_upgrade_campaign_route_args = [ | |
| 201 | + 'methods' => 'GET', | |
| 202 | + 'callback' => [ $this, 'get_upgrade_campaign' ], | |
| 203 | + 'permission_callback' => [ $this, 'can_use_wincher' ], | |
| 204 | + ]; | |
| 205 | + | |
| 206 | + \register_rest_route( Main::API_V1_NAMESPACE, self::UPGRADE_CAMPAIGN_ROUTE, $get_upgrade_campaign_route_args ); | |
| 174 | 207 | } |
| 175 | 208 | |
| 176 | 209 | /** |
| 177 | 210 | * Returns the authorization URL. |
| @@ -225,9 +258,9 @@ | ||
| 225 | 258 | * |
| 226 | 259 | * @return WP_REST_Response The response. |
| 227 | 260 | */ |
| 228 | 261 | public function get_tracked_keyphrases( WP_REST_Request $request ) { |
| 229 | - $data = $this->keyphrases_action->get_tracked_keyphrases( $request['keyphrases'], $request['permalink'] ); | |
| 262 | + $data = $this->keyphrases_action->get_tracked_keyphrases( $request['keyphrases'], $request['permalink'], $request['startAt'] ); | |
| 230 | 263 | |
| 231 | 264 | return new WP_REST_Response( $data, $data->status ); |
| 232 | 265 | } |
| 233 | 266 | |
| @@ -235,9 +268,9 @@ | ||
| 235 | 268 | * Untracks the tracked keyphrase. |
| 236 | 269 | * |
| 237 | 270 | * @param WP_REST_Request $request The request. This request should have a code param set. |
| 238 | 271 | * |
| 239 | - * @return object The response. | |
| 272 | + * @return WP_REST_Response The response. | |
| 240 | 273 | */ |
| 241 | 274 | public function untrack_keyphrase( WP_REST_Request $request ) { |
| 242 | 275 | $data = $this->keyphrases_action->untrack_keyphrase( $request['keyphraseID'] ); |
| 243 | 276 | |
| @@ -244,8 +277,29 @@ | ||
| 244 | 277 | return new WP_REST_Response( $data, $data->status ); |
| 245 | 278 | } |
| 246 | 279 | |
| 247 | 280 | /** |
| 281 | + * Checks the account limit. | |
| 282 | + * | |
| 283 | + * @return WP_REST_Response The response. | |
| 284 | + */ | |
| 285 | + public function check_limit() { | |
| 286 | + $data = $this->account_action->check_limit(); | |
| 287 | + return new WP_REST_Response( $data, $data->status ); | |
| 288 | + } | |
| 289 | + | |
| 290 | + /** | |
| 291 | + * Gets the upgrade campaign. | |
| 292 | + * If it's not a free user, no campaign is returned. | |
| 293 | + * | |
| 294 | + * @return WP_REST_Response The response. | |
| 295 | + */ | |
| 296 | + public function get_upgrade_campaign() { | |
| 297 | + $data = $this->account_action->get_upgrade_campaign(); | |
| 298 | + return new WP_REST_Response( $data, $data->status ); | |
| 299 | + } | |
| 300 | + | |
| 301 | + /** | |
| 248 | 302 | * Checks if a valid code was returned. |
| 249 | 303 | * |
| 250 | 304 | * @param string $code The code to check. |
| 251 | 305 | * |
| @@ -262,9 +316,9 @@ | ||
| 262 | 316 | * |
| 263 | 317 | * @return bool Whether the website_id is valid. |
| 264 | 318 | */ |
| 265 | 319 | public function has_valid_website_id( $website_id ) { |
| 266 | - return ! empty( $website_id ) && is_int( $website_id ); | |
| 320 | + return ! empty( $website_id ) && \is_int( $website_id ); | |
| 267 | 321 | } |
| 268 | 322 | |
| 269 | 323 | /** |
| 270 | 324 | * Whether the current user is allowed to publish post/pages and thus use the Wincher integration. |