Changeset 1985825
- Timestamp:
- 12/05/2018 10:25:45 AM (7 years ago)
- Location:
- satoshipay
- Files:
-
- 8 edited
-
assets/banner-1544x500.png (modified) (previous)
-
assets/banner-772x250.png (modified) (previous)
-
trunk/assets/js/script_post.js (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/satoshipay.php (modified) (2 diffs)
-
trunk/src/SatoshiPay/SatoshiPayAdminPlugin.php (modified) (15 diffs)
-
trunk/src/SatoshiPay/SatoshiPayPlugin.php (modified) (5 diffs)
-
trunk/views/admin/options/page.phtml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
satoshipay/trunk/assets/js/script_post.js
r1948680 r1985825 14 14 Rates.prototype.fetch = function() { 15 15 var self = this; 16 jQuery.get('https://api .coinmarketcap.com/v1/ticker/stellar/?convert=EUR', function(res) {17 self.rate.resolve(res [0].price_eur);16 jQuery.get('https://api-dev.satoshipay.io/staging/testnet/coinmarketcap/v1/cryptocurrency/quotes/latest?convert=EUR&symbol=XLM', function(res) { 17 self.rate.resolve(res.data.XLM.quote.EUR.price); 18 18 }); 19 19 }; -
satoshipay/trunk/readme.txt
r1959692 r1985825 5 5 Requires at least: 4.4.5 6 6 Tested up to: 4.9.8 7 Stable tag: 1. 57 Stable tag: 1.6 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 79 79 80 80 == Changelog == 81 82 = 1.6 = 83 84 * Improved plugin performance. 85 * Improved API communication. 81 86 82 87 = 1.5 = -
satoshipay/trunk/satoshipay.php
r1959692 r1985825 11 11 * Plugin Name: SatoshiPay 12 12 * Plugin URI: https://wordpress.org/plugins/satoshipay/ 13 * Description: Integrates SatoshiPay into WordPress. Quick start: 1) Select SatoshiPay from the left-hand admin menu, 2) add SatoshiPay API credentials, 3) edit a post, 4) activate "Paid Post" in SatoshiPay meta box, 5) set a price, 6) publish and view post. The SatoshiPay widget will appear and allow readers to pay for the post.14 * Version: 1. 513 * Description: Integrates SatoshiPay's micropayment system into WordPress. 14 * Version: 1.6 15 15 * Author: SatoshiPay 16 16 * Author URI: https://satoshipay.io … … 30 30 // Plugin version, used in user-agent string for API calls; keep in sync with 31 31 // version in plugin description above! 32 define('SATOSHIPAY_VERSION', '1. 5');32 define('SATOSHIPAY_VERSION', '1.6'); 33 33 34 34 // Plugin root file -
satoshipay/trunk/src/SatoshiPay/SatoshiPayAdminPlugin.php
r1951997 r1985825 13 13 require_once __DIR__ . '/Api/Client.php'; 14 14 require_once __DIR__ . '/Plugin/PluginAbstract.php'; 15 require_once __DIR__ . '/Plugin/PluginAbstract.php';16 15 require_once __DIR__ . '/SatoshiPayException.php'; 17 16 … … 26 25 { 27 26 /** 27 * Ajax actions used in tinymce.util.XHR requests in tinemce JS 28 28 * @var array 29 29 */ … … 243 243 */ 244 244 public function onEditPost(){ 245 if(!isset($_GET['post'])) { 246 return; 247 } 245 248 246 249 // get the post id … … 345 348 346 349 /** 347 * Callback function for sanitize API settings.348 *349 * @param array $input350 * @return array351 */352 public function onSanitizeApiSettings($input)353 {354 $output = array();355 356 if (isset($input['auth_key'])) {357 $output['auth_key'] = strip_tags(stripslashes($input['auth_key']));358 } else {359 add_settings_error(360 'auth_key',361 'auth_key',362 '<span class="satoshipay-settings-error">Please enter an API Key.</span>',363 'error'364 );365 }366 367 if (isset($input['auth_secret'])) {368 $output['auth_secret'] = strip_tags(stripslashes($input['auth_secret']));369 }370 else {371 add_settings_error(372 'auth_secret',373 'auth_secret',374 '<span class="satoshipay-settings-error">Please enter an API Secret.</span>',375 'error'376 );377 }378 379 if (false == $this->validCredentials($output)) {380 add_settings_error(381 'auth_validcredentials',382 'auth_validcredentials',383 '<span class="satoshipay-settings-error">The new API key/secret credentials are invalid and were not saved.</span>',384 'error'385 );386 387 // remove the non working settings388 if(is_array(get_option('satoshipay_api'))){389 // there are settings. Use them390 $output = get_option('satoshipay_api');391 } else {392 // there are no settings. We return an empty array393 $output = array();394 }395 }396 397 return $output;398 }399 400 /**401 * Callback function for sanitize API settings.402 *403 * @param array $input404 * @return array405 */406 public function onSanitizeClientSettings($input)407 {408 $output = array();409 410 if (isset($input['client_url'])) {411 $output['client_url'] = esc_url_raw(strip_tags(stripslashes($input['client_url'])));412 }413 414 return $output;415 }416 417 /**418 350 * Callback function for rendering meta box. 419 351 */ … … 457 389 public function onUpdatedOptions($optionName, $oldValue = null, $newValue = null) 458 390 { 459 switch ($optionName) {460 case 'satoshipay_ad_blocker_detection':461 // If configured NOT to use ad blocker detection feature462 if (!SATOSHIPAY_USE_AD_BLOCKER_DETECTION) {463 break;464 }465 case 'satoshipay_api':466 $this->updateMetadata();467 break;468 case 'validCredentials':469 break;470 default:471 break;472 }473 391 } 474 392 … … 478 396 public function addSatoshiPayError($message) 479 397 { 480 add_settings_error( 'sp_errors', 'sp_errors', $message ); 398 add_settings_error( 'sp_messages', 'sp_error', $message ); 399 } 400 401 /** 402 * Add new success 403 */ 404 public function addSatoshiPaySuccess($message) 405 { 406 add_settings_error( 'sp_messages', 'sp_success', $message, 'updated' ); 481 407 } 482 408 … … 708 634 $pricingEnabled = $pricing['enabled']; 709 635 $pricingPrice = $pricing['satoshi']; 710 711 // If configured to use ad blocker detection feature712 if (SATOSHIPAY_USE_AD_BLOCKER_DETECTION) {713 // Check for ad blocker detection settings for disabled paid content pricing714 if (!$pricingEnabled) {715 // Get SatoshiPay settings for `satoshipay_ad_blocker_detection`716 $adBlockerDetectionOptions = get_option('satoshipay_ad_blocker_detection');717 $pricingEnabled = (bool)$this->validateAdBlockerDetectionOption($adBlockerDetectionOptions);718 $pricingPrice = (int)$this->validateAdBlockerDetectionPrice($adBlockerDetectionOptions);719 $metaData['adblock'] = ($pricingEnabled ? true : false);720 }721 }722 636 723 637 // If pricing (paid content || ad blocker detection) is enabled && price is valid … … 873 787 $result = array( 874 788 'enabled' => false, 789 'price' => 0, 790 'satoshi' => 0 875 791 ); 876 792 … … 979 895 980 896 /** 981 * Adds and updates metadata for all revelant posts.982 *983 * @return $this984 */985 protected function updateMetadata()986 {987 $this->addSecretMetadata();988 $this->updateProviderApiMetadata();989 990 return $this;991 }992 993 /**994 * Adds secret metadata for all relevant posts.995 *996 * @return $this997 */998 protected function addSecretMetadata()999 {1000 global $wpdb;1001 1002 $sqlQuery =1003 "SELECT " .1004 " `" . $wpdb->posts . "`.`ID` " .1005 "FROM " .1006 " `" . $wpdb->posts . "` " .1007 "LEFT JOIN " .1008 " `" . $wpdb->postmeta . "` " .1009 "ON " .1010 " (" .1011 " `" . $wpdb->posts . "`.`ID` = `" . $wpdb->postmeta . "`.`post_id` AND " .1012 " `" . $wpdb->postmeta . "`.`meta_key` = '%s'" .1013 " ) " .1014 "WHERE " .1015 " `" . $wpdb->posts . "`.`post_type` IN ('attachment', 'page', 'post') AND " .1016 " `" . $wpdb->posts . "`.`post_status` != 'auto-draft' AND " .1017 " `" . $wpdb->postmeta . "`.`post_id` IS NULL"1018 ;1019 1020 // Get all IDs for posts without `_satoshipay_secret` metadata.1021 $postIds = $wpdb->get_col($wpdb->prepare($sqlQuery, '_satoshipay_secret'));1022 if ($postIds) {1023 foreach ($postIds as $postId) {1024 // Add metadata `_satoshipay_secret` to posts1025 add_post_meta($postId, '_satoshipay_secret', $this->generateSecret(), true);1026 }1027 }1028 1029 return $this;1030 }1031 1032 /**1033 897 * Checks if api settings are existant 1034 898 * … … 1060 924 // get the _satoshipay_pricing metadata 1061 925 $postSatoshipayMetadata = get_post_meta($post->ID,'_satoshipay_pricing'); 926 if(!$postSatoshipayMetadata){ 927 return; 928 } 1062 929 1063 930 if(strstr($post->post_content,'<!--satoshipay:start-->')){ … … 1141 1008 } 1142 1009 1143 /**1144 * Updates provider API metadata for all relevant posts.1145 *1146 * @return $this1147 */1148 protected function updateProviderApiMetadata()1149 {1150 global $wpdb;1151 1152 // Get SatoshiPay settings for `satoshipay_ad_blocker_detection`1153 $adBlockerDetectionOptions = get_option('satoshipay_ad_blocker_detection');1154 $enabled = $this->validateAdBlockerDetectionOption($adBlockerDetectionOptions);1155 $price = $this->validateAdBlockerDetectionPrice($adBlockerDetectionOptions);1156 1157 // Get SatoshiPay settings for `satoshipay_api`1158 $apiCredentials = get_option('satoshipay_api');1159 1160 // If api credentials are valid && ad blocker detection is enabled && price is valid1161 if ($this->validCredentials($apiCredentials) && ($enabled === 1) && ($price !== false)) {1162 $sqlQuery =1163 "SELECT " .1164 " `" . $wpdb->posts . "`.`ID` " .1165 "FROM " .1166 " `" . $wpdb->posts . "` " .1167 "WHERE " .1168 " `" . $wpdb->posts . "`.`post_type` IN ('attachment', 'page', 'post') AND " .1169 " `" . $wpdb->posts . "`.`post_status` != 'auto-draft'"1170 ;1171 1172 // Get all IDs for posts with `post_type` ('attachment', 'post' OR 'page').1173 $postIds = $wpdb->get_col($sqlQuery);1174 if ($postIds) {1175 $metaData = array(1176 'adblock' => true,1177 'homeUrl' => get_home_url(),1178 );1179 1180 // All batch objects for provider API1181 $batchObjects = array();1182 1183 foreach ($postIds as $postId) {1184 // Get pricing setting for this post (if available)1185 $paidContentPricing = get_post_meta($postId, '_satoshipay_pricing', true);1186 // Ignore posts with enabled "paid content" pricing1187 if (isset($paidContentPricing['enabled']) && $paidContentPricing['enabled'] === true) {1188 continue;1189 }1190 1191 // Instantiate a WP_Post object1192 // ATTENTION: Don't use global $post for that!1193 $post = WP_Post::get_instance($postId);1194 1195 // Get post metadata1196 $satoshiPaySecret = get_post_meta($post->ID, '_satoshipay_secret', true);1197 $satoshiPayId = get_post_meta($post->ID, '_satoshipay_id', true);1198 1199 // Batch object will be created as default1200 $method = "POST";1201 $path = "/goods";1202 1203 // Batch object will be updated if post has `_satoshipay_id` metadata1204 if ($satoshiPayId) {1205 $method = "PUT";1206 $path = "/goods/" . (string)$satoshiPayId;1207 }1208 1209 // Add a batch request for provider API1210 $batchObjects[] = array(1211 "method" => $method,1212 "path" => $path,1213 "body" => array(1214 'goodId' => $post->ID,1215 'price' => $price,1216 'sharedSecret' => $satoshiPaySecret,1217 'title' => $post->post_title,1218 'url' => get_permalink($post->ID),1219 'spmeta' => $metaData1220 ),1221 );1222 }1223 1224 try {1225 $apiClient = new ApiClient($apiCredentials);1226 $batchResponses = $apiClient->batch($batchObjects);1227 foreach ($batchResponses as $response) {1228 // Ignore response data without 'status' and 'body' fields1229 if (!isset($response['status']) || !isset($response['body'])) {1230 continue;1231 }1232 1233 $status = (int)$response['status'];1234 $body = $response['body'];1235 1236 // Ignore unsuccessful response data1237 if ($status !== 200) {1238 continue;1239 }1240 1241 // Ignore response data with invalid body (missing 'id' and 'secret' fields)1242 if (!isset($body['id']) || !isset($body['secret'])) {1243 continue;1244 }1245 1246 $satoshiPayId = $body['id'];1247 $satoshiPaySecret = $body['secret'];1248 1249 // Get the post ID with metadata '_satoshipay_secret' = $satoshiPaySecret.1250 $postMeta = $wpdb->get_row(1251 $wpdb->prepare(1252 "SELECT " .1253 " `" . $wpdb->postmeta . "`.`post_id` " .1254 "FROM " .1255 " `" . $wpdb->postmeta . "` " .1256 "WHERE " .1257 " `" . $wpdb->postmeta . "`.`meta_key` = '_satoshipay_secret' AND " .1258 " `" . $wpdb->postmeta . "`.`meta_value` = %s",1259 $satoshiPaySecret1260 )1261 );1262 1263 // Ignore missing post meta results1264 if (!$postMeta) {1265 continue;1266 }1267 1268 // Update / add metadata `_satoshipay_id` for post with ID $postId1269 update_post_meta($postMeta->post_id, '_satoshipay_id', $satoshiPayId, true);1270 }1271 } catch (Exception $e) {1272 $this->apiError($e->getMessage());1273 }1274 }1275 }1276 1277 return $this;1278 }1279 1280 /**1281 * Adds 'Browser Detection' section to 'SatoshiPay' options submenu.1282 *1283 * @return $this1284 */1285 protected function addBrowserDetectionSettingsSection()1286 {1287 if (false == get_option('satoshipay_browser_detection')) {1288 add_option('satoshipay_browser_detection', $this->defaultBrowserDetectionSettings);1289 }1290 1291 add_settings_section(1292 'satoshipay_browser_detection_settings_section',1293 __('Browser Detection', $this->textdomain),1294 array($this, 'onRenderBrowserDetectionSectionDescription'),1295 'satoshipay_options_page'1296 );1297 1298 add_settings_field(1299 'browser_detection_list',1300 __('Select a browser', $this->textdomain),1301 array($this, 'onRenderBrowserDetectionSettings'),1302 'satoshipay_options_page',1303 'satoshipay_browser_detection_settings_section'1304 );1305 1306 register_setting(1307 'satoshipay_settings_section',1308 'satoshipay_browser_detection',1309 array($this, 'onSanitizeBrowserDetectionSettings')1310 );1311 1312 return $this;1313 }1314 1315 /**1316 * Callback function for rendering Browser Detection section description.1317 */1318 public function onRenderBrowserDetectionSectionDescription()1319 {1320 require_once __DIR__ . '/../../views/admin/options/browser_detection_section/description.phtml';1321 }1322 1323 /**1324 * Callback function for rendering Browser Detection settings (options and fields).1325 */1326 public function onRenderBrowserDetectionSettings()1327 {1328 $options = get_option('satoshipay_browser_detection');1329 $enabledBrowsers = array();1330 if (isset($options['enabled']) && is_array($options['enabled'])) {1331 $enabledBrowsers = $options['enabled'];1332 }1333 require_once __DIR__ . '/../../views/admin/options/browser_detection_section/settings.phtml';1334 }1335 1336 /**1337 * Callback function for sanitize Browser Detection settings.1338 *1339 * @param array $input1340 * @return array1341 */1342 public function onSanitizeBrowserDetectionSettings($input)1343 {1344 $output = array();1345 1346 // Get current database values1347 $currentValues = get_option('satoshipay_browser_detection');1348 1349 // Validate satoshipay_browser_detection['enabled'] input1350 $output['enabled'] = $this->validateBrowserDetectionOption($input);1351 if ($output['enabled'] === false) {1352 $errorMessage = 'The option you choosed for browser detection is not valid.';1353 add_settings_error('enabled', 'enabled', $errorMessage, 'error');1354 $output['enabled'] = $currentValues['enabled'];1355 }1356 1357 return $output;1358 }1359 1360 1010 protected function addAdminMenu() 1361 1011 { … … 1364 1014 $capability = 'manage_options'; 1365 1015 $menu_slug = 'satoshipay_settings_page'; 1366 $function = array($this, 'render NewAdminPage');1016 $function = array($this, 'renderAdminPage'); 1367 1017 $icon_url = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyAgIHhtbG5zOm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aW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIgICAgICAgc3R5bGU9ImZpbGw6I2ZmZmZmZiIgLz48L2c+PC9zdmc+'; 1368 1018 … … 1370 1020 } 1371 1021 1372 public function render NewAdminPage()1022 public function renderAdminPage() 1373 1023 { 1374 1024 $api = $this->handleApiSection(); 1375 //$browserDetection = $this->handleBrowserDetectionSection();1376 //$adBlocker = $this->handleAdBlockerDetectionSection();1377 //$adBlockerMaxPrice = $this->getAdBlockerMaxPrice();1378 1025 1379 1026 require_once __DIR__ . '/../../views/admin/options/page.phtml'; … … 1394 1041 if($this->validateApiSection($values) === true){ 1395 1042 update_option('satoshipay_api', $values); 1043 $this->addSatoshiPaySuccess('API credentials were successfully updated'); 1396 1044 return $values; 1397 1045 } … … 1429 1077 return true; 1430 1078 } 1431 1432 /**1433 * handle browser detection updates, and return the enabled browsers1434 * @return Array Enabled browsers1435 */1436 public function handleBrowserDetectionSection()1437 {1438 if(isset($_POST['submit'])){1439 $value = $_POST['satoshipay_browser_detection'] ?: array();1440 update_option('satoshipay_browser_detection', $value);1441 }1442 1443 $options = get_option('satoshipay_browser_detection');1444 $browserDetection = array();1445 if (isset($options['enabled']) && is_array($options['enabled'])) {1446 $browserDetection = $options['enabled'];1447 }1448 1449 return $browserDetection;1450 }1451 1452 /**1453 * Check for ad blocker detection updates, and return the value1454 * @return Array Ad Blocker Detection config1455 */1456 public function handleAdBlockerDetectionSection()1457 {1458 if(isset($_POST['submit'])){1459 $value = $_POST['satoshipay_ad_blocker_detection']1460 && (bool)$_POST['satoshipay_ad_blocker_detection']['enabled']1461 && $this->validateAdBlockerDetectionSection($_POST['satoshipay_ad_blocker_detection'])1462 ? array(1463 'enabled' => (bool)$_POST['satoshipay_ad_blocker_detection']['enabled'],1464 'price' => $_POST['satoshipay_ad_blocker_detection']['price']1465 )1466 : $this->defaultAdBlockerDetectionSettings;1467 update_option('satoshipay_ad_blocker_detection', $value);1468 }1469 return get_option('satoshipay_ad_blocker_detection');1470 }1471 1472 public function validateAdBlockerDetectionSection($input)1473 {1474 if((bool)$input['enabled'] && !$input['price']){1475 $this->addSatoshiPayError('The price you entered does not appear to be valid. Please enter a whole number for lumens per post/page.');1476 return false;1477 }1478 1479 return true;1480 }1481 1482 /**1483 * Get Ad blocker maxPrice1484 */1485 public function getAdBlockerMaxPrice()1486 {1487 $maxPrice = SATOSHIPAY_DEFAULT_MAX_PRODUCT_PRICE / 10000000;1488 1489 // Get publisher max product price from API1490 $apiCredentials = get_option('satoshipay_api');1491 if ($this->validCredentials($apiCredentials, true)) {1492 try {1493 $apiClient = new ApiClient($apiCredentials);1494 $maxPrice = (int)$apiClient->getPublisherMaxProductPrice($apiCredentials['auth_key']) / 10000000;1495 } catch (Exception $e) {1496 $this->apiError($e->getMessage());1497 }1498 }1499 1500 return $maxPrice;1501 }1502 1079 } -
satoshipay/trunk/src/SatoshiPay/SatoshiPayPlugin.php
r1948680 r1985825 141 141 $response = new FileResponse( 142 142 get_attached_file($post->ID), 143 $post->post_mime_type, 144 $_SERVER['HTTP_RANGE'] 143 $post->post_mime_typeg 145 144 ); 146 145 $response->send(); … … 435 434 'autoplay' => $matches[9], 436 435 'preview' => $matches[11], 437 'asset' => $matches[13]436 'asset' => isset($matches[13]) ? $matches[13] : '' 438 437 ); 439 438 $placeholder = SatoshiPayPlugin::getPlaceholderById($attachmentId, $attachmentAttributes); … … 467 466 { 468 467 global $post; 469 470 $browserDetectionCode = '';471 $browserDetectionCookie = '';472 $browserDetectionWhitelist = array();473 474 if (SATOSHIPAY_USE_BROWSER_DETECTION) {475 $browserDetectionOptions = get_option('satoshipay_browser_detection');476 $browserDetectionWhitelist = $this->validateBrowserDetectionOption($browserDetectionOptions);477 if ($browserDetectionWhitelist !== false) {478 $cookieName = 'browserName';479 $browserDetectionCode = str_replace('{{cookie_name}}', $cookieName, file_get_contents(__DIR__ . '/../../views/templates/browser_detection.tpl'));480 $browserDetectionCookie = $this->filterBrowserDetectionCookie($_COOKIE[$cookieName]);481 }482 }483 if (in_array($browserDetectionCookie, $browserDetectionWhitelist)) {484 return $browserDetectionCode . $content;485 }486 487 468 $pricing = self::getPricingData($post); 488 469 489 $adBlockerBaitCode = '';490 $adBlockerCookie = true;491 492 if (SATOSHIPAY_USE_AD_BLOCKER_DETECTION && $pricing === false) {493 $adBlockerDetectionOptions = get_option('satoshipay_ad_blocker_detection');494 495 if ((bool)$this->validateAdBlockerDetectionOption($adBlockerDetectionOptions) === true) {496 $cookieName = 'enabledAdBlocker';497 $adBlockerBaitCode = str_replace('{{cookie_name}}', $cookieName, file_get_contents(__DIR__ . '/../../views/templates/ad_blocker_bait.tpl'));498 $adBlockerCookie = ($_COOKIE[$cookieName] === 'true') ? true : false;499 $pricing['price'] = (int)$this->validateAdBlockerDetectionPrice($adBlockerDetectionOptions);500 }501 }502 503 if ($adBlockerCookie === false) {504 return $browserDetectionCode . $adBlockerBaitCode . $content;505 }506 507 470 if ($pricing === false) { 508 // there is no price (hence no start tag handling)509 // we just replace mediaTags510 return $browserDetectionCode .$this->replaceMediaTags($content);471 // there is no price (hence no start tag handling) 472 // we just replace mediaTags 473 return $this->replaceMediaTags($content); 511 474 } 512 475 … … 524 487 $html = $intro . $this->placeholderText($pricing, $goodData) . $this->scriptTag(); 525 488 526 return $ browserDetectionCode . $adBlockerBaitCode . $html;489 return $html; 527 490 } 528 491 … … 558 521 return substr($content, $offset); 559 522 } 560 561 /**562 * Validate Ad Blocker Detection option.563 *564 * @param array $input565 * @return boolean|integer566 */567 protected function validateAdBlockerDetectionOption($input)568 {569 $validatedValue = false;570 571 // Check for existing input field572 if (isset($input['enabled'])) {573 $inputValue = trim($input['enabled']);574 // Check for integer value575 if (ctype_digit($inputValue)) {576 $inputValue = (int)$inputValue;577 // Check for valid value578 if (($inputValue >= 0) && ($inputValue <= 1)) {579 $validatedValue = $inputValue;580 }581 }582 }583 584 return $validatedValue;585 }586 587 /**588 * Validate Ad Blocker Detection price.589 *590 * @param array $input591 * @return boolean|integer592 */593 protected function validateAdBlockerDetectionPrice($input)594 {595 $validatedValue = false;596 597 // Check for existing input field598 if (isset($input['price'])) {599 $inputValue = trim(strip_tags(stripslashes($input['price'])));600 // Check for integer value601 if (ctype_digit($inputValue)) {602 $inputValue = (int)$inputValue;603 // Check for valid value604 if ($inputValue > 0) {605 $validatedValue = $inputValue;606 }607 }608 }609 610 return $validatedValue;611 }612 613 /**614 * Filter browser detection cookie.615 *616 * @param string $cookie617 * @return string618 */619 protected function filterBrowserDetectionCookie($cookie)620 {621 $filteredValue = '';622 if (is_string($cookie)) {623 $cookie = trim(filter_var($cookie, FILTER_SANITIZE_STRING));624 if ($this->isValidBrowserName($cookie)) {625 $filteredValue = $cookie;626 }627 }628 629 return $filteredValue;630 }631 523 } -
satoshipay/trunk/views/admin/options/page.phtml
r1951997 r1985825 1 1 <div class="wrap sp__settings-page"> 2 2 <h2 class="sp__settings-page__title"><?php _e('SatoshiPay', $this->textdomain); ?></h2> 3 <?php settings_errors( 'sp_ errors' ); ?>3 <?php settings_errors( 'sp_messages' ); ?> 4 4 <div class="sp__settings-page__content"> 5 5 <form class="sp__settings-page__form" method="post"> 6 6 <!-- API Section --> 7 7 <?php require_once __DIR__ . '/sections/api_section.phtml'; ?> 8 9 <!-- Browser Detection Section -->10 <?php // require_once __DIR__ . '/sections/browser_detection_section.phtml'; ?>11 12 <!-- Ad Blocker Detection Section -->13 <?php // require_once __DIR__ . '/sections/ad_blocker_detection_section.phtml'; ?>14 8 15 9 <!-- Submit Button -->
Note: See TracChangeset
for help on using the changeset viewer.