Plugin Directory

Changeset 1985825


Ignore:
Timestamp:
12/05/2018 10:25:45 AM (7 years ago)
Author:
satoshipay
Message:

update to 1.6

Location:
satoshipay
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • satoshipay/trunk/assets/js/script_post.js

    r1948680 r1985825  
    1414Rates.prototype.fetch = function() {
    1515  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);
    1818  });
    1919};
  • satoshipay/trunk/readme.txt

    r1959692 r1985825  
    55Requires at least: 4.4.5
    66Tested up to: 4.9.8
    7 Stable tag: 1.5
     7Stable tag: 1.6
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    7979
    8080== Changelog ==
     81
     82= 1.6 =
     83
     84* Improved plugin performance.
     85* Improved API communication.
    8186
    8287= 1.5 =
  • satoshipay/trunk/satoshipay.php

    r1959692 r1985825  
    1111 * Plugin Name:       SatoshiPay
    1212 * 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.5
     13 * Description:       Integrates SatoshiPay's micropayment system into WordPress.
     14 * Version:           1.6
    1515 * Author:            SatoshiPay
    1616 * Author URI:        https://satoshipay.io
     
    3030// Plugin version, used in user-agent string for API calls; keep in sync with
    3131// version in plugin description above!
    32 define('SATOSHIPAY_VERSION', '1.5');
     32define('SATOSHIPAY_VERSION', '1.6');
    3333
    3434// Plugin root file
  • satoshipay/trunk/src/SatoshiPay/SatoshiPayAdminPlugin.php

    r1951997 r1985825  
    1313require_once __DIR__ . '/Api/Client.php';
    1414require_once __DIR__ . '/Plugin/PluginAbstract.php';
    15 require_once __DIR__ . '/Plugin/PluginAbstract.php';
    1615require_once __DIR__ . '/SatoshiPayException.php';
    1716
     
    2625{
    2726    /**
     27     * Ajax actions used in tinymce.util.XHR requests in tinemce JS
    2828     * @var array
    2929     */
     
    243243     */
    244244    public function onEditPost(){
     245        if(!isset($_GET['post'])) {
     246          return;
     247        }
    245248
    246249        // get the post id
     
    345348
    346349    /**
    347      * Callback function for sanitize API settings.
    348      *
    349      * @param array $input
    350      * @return array
    351      */
    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 settings
    388             if(is_array(get_option('satoshipay_api'))){
    389                 // there are settings. Use them
    390                 $output = get_option('satoshipay_api');
    391             } else {
    392                 // there are no settings. We return an empty array
    393                 $output = array();
    394             }
    395         }
    396 
    397         return $output;
    398     }
    399 
    400     /**
    401      * Callback function for sanitize API settings.
    402      *
    403      * @param array $input
    404      * @return array
    405      */
    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     /**
    418350     * Callback function for rendering meta box.
    419351     */
     
    457389    public function onUpdatedOptions($optionName, $oldValue = null, $newValue = null)
    458390    {
    459         switch ($optionName) {
    460             case 'satoshipay_ad_blocker_detection':
    461                 // If configured NOT to use ad blocker detection feature
    462                 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         }
    473391    }
    474392
     
    478396    public function addSatoshiPayError($message)
    479397    {
    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' );
    481407    }
    482408
     
    708634            $pricingEnabled = $pricing['enabled'];
    709635            $pricingPrice = $pricing['satoshi'];
    710 
    711             // If configured to use ad blocker detection feature
    712             if (SATOSHIPAY_USE_AD_BLOCKER_DETECTION) {
    713                 // Check for ad blocker detection settings for disabled paid content pricing
    714                 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             }
    722636
    723637            // If pricing (paid content || ad blocker detection) is enabled && price is valid
     
    873787        $result = array(
    874788            'enabled' => false,
     789            'price' => 0,
     790            'satoshi' => 0
    875791        );
    876792
     
    979895
    980896    /**
    981      * Adds and updates metadata for all revelant posts.
    982      *
    983      * @return $this
    984      */
    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 $this
    997      */
    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 posts
    1025                 add_post_meta($postId, '_satoshipay_secret', $this->generateSecret(), true);
    1026             }
    1027         }
    1028 
    1029         return $this;
    1030     }
    1031 
    1032     /**
    1033897     * Checks if api settings are existant
    1034898     *
     
    1060924        // get the _satoshipay_pricing metadata
    1061925        $postSatoshipayMetadata = get_post_meta($post->ID,'_satoshipay_pricing');
     926        if(!$postSatoshipayMetadata){
     927          return;
     928        }
    1062929
    1063930        if(strstr($post->post_content,'<!--satoshipay:start-->')){
     
    11411008    }
    11421009
    1143     /**
    1144      * Updates provider API metadata for all relevant posts.
    1145      *
    1146      * @return $this
    1147      */
    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 valid
    1161         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 API
    1181                 $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" pricing
    1187                     if (isset($paidContentPricing['enabled']) && $paidContentPricing['enabled'] === true) {
    1188                         continue;
    1189                     }
    1190 
    1191                     // Instantiate a WP_Post object
    1192                     // ATTENTION: Don't use global $post for that!
    1193                     $post = WP_Post::get_instance($postId);
    1194 
    1195                     // Get post metadata
    1196                     $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 default
    1200                     $method = "POST";
    1201                     $path = "/goods";
    1202 
    1203                     // Batch object will be updated if post has `_satoshipay_id` metadata
    1204                     if ($satoshiPayId) {
    1205                         $method = "PUT";
    1206                         $path = "/goods/" . (string)$satoshiPayId;
    1207                     }
    1208 
    1209                     // Add a batch request for provider API
    1210                     $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' => $metaData
    1220                         ),
    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' fields
    1229                         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 data
    1237                         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                                 $satoshiPaySecret
    1260                             )
    1261                         );
    1262 
    1263                         // Ignore missing post meta results
    1264                         if (!$postMeta) {
    1265                             continue;
    1266                         }
    1267 
    1268                         // Update / add metadata `_satoshipay_id` for post with ID $postId
    1269                         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 $this
    1284      */
    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 $input
    1340      * @return array
    1341      */
    1342     public function onSanitizeBrowserDetectionSettings($input)
    1343     {
    1344         $output = array();
    1345 
    1346         // Get current database values
    1347         $currentValues = get_option('satoshipay_browser_detection');
    1348 
    1349         // Validate satoshipay_browser_detection['enabled'] input
    1350         $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 
    13601010    protected function addAdminMenu()
    13611011    {
     
    13641014        $capability = 'manage_options';
    13651015        $menu_slug = 'satoshipay_settings_page';
    1366         $function = array($this, 'renderNewAdminPage');
     1016        $function = array($this, 'renderAdminPage');
    13671017        $icon_url = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIgICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgICB4bWxuczpzb2RpcG9kaT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBvZ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AwMDIsMjYyLjUgLTExMi44NzYxLDAgYyAtNi4zNDU0Myw2OS45NSAtNjUuNDU2ODIsMTI1IC0xMzcuMTIxNDEsMTI1IC03MS42NjQ1OCwwIC0xMzAuNzc1OTcsLTU1LjA1IC0xMzcuMTIxNCwtMTI1IEggMC4wMDI1MDUyNSBDIDYuNTMwOTE2LDM5NC43NjI1IDExNS45NTk5Niw1MDAgMjUwLjAwMjUxLDUwMCAzODQuMDQ1MDcsNTAwIDQ5My40NjkzNiwzOTQuNzU3NSA1MDAuMDAyNTIsMjYyLjUgeiIgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIgICAgICAgc3R5bGU9ImZpbGw6I2ZmZmZmZiIgLz48cGF0aCAgICAgICBpZD0icGF0aDMwOTciICAgICAgIGQ9Im0gMjUwLjAwMDAxLDEzNy41IGMgLTYyLjM1Nzk1LDAgLTExMi42NDA4LDUwLjIyIC0xMTIuNjQwOCwxMTIuNSAwLDYyLjI4IDUwLjI4Mjg1LDExMi41IDExMi42NDA4LDExMi41IDYyLjM1Nzk1LDAgMTEyLjY0MDgxLC01MC4yMiAxMTIuNjQwODEsLTExMi41IDAsLTYyLjI4IC01MC4yODI4NiwtMTEyLjUgLTExMi42NDA4MSwtMTEyLjUgeiIgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIgICAgICAgc3R5bGU9ImZpbGw6I2ZmZmZmZiIgLz48L2c+PC9zdmc+';
    13681018
     
    13701020    }
    13711021
    1372     public function renderNewAdminPage()
     1022    public function renderAdminPage()
    13731023    {
    13741024        $api = $this->handleApiSection();
    1375         //$browserDetection = $this->handleBrowserDetectionSection();
    1376         //$adBlocker = $this->handleAdBlockerDetectionSection();
    1377         //$adBlockerMaxPrice = $this->getAdBlockerMaxPrice();
    13781025
    13791026        require_once __DIR__ . '/../../views/admin/options/page.phtml';
     
    13941041            if($this->validateApiSection($values) === true){
    13951042                update_option('satoshipay_api', $values);
     1043                $this->addSatoshiPaySuccess('API credentials were successfully updated');
    13961044                return $values;
    13971045            }
     
    14291077        return true;
    14301078    }
    1431 
    1432     /**
    1433     * handle browser detection updates, and return the enabled browsers
    1434     * @return Array Enabled browsers
    1435     */
    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 value
    1454     * @return Array Ad Blocker Detection config
    1455     */
    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 maxPrice
    1484      */
    1485     public function getAdBlockerMaxPrice()
    1486     {
    1487         $maxPrice = SATOSHIPAY_DEFAULT_MAX_PRODUCT_PRICE / 10000000;
    1488 
    1489         // Get publisher max product price from API
    1490         $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     }
    15021079}
  • satoshipay/trunk/src/SatoshiPay/SatoshiPayPlugin.php

    r1948680 r1985825  
    141141        $response = new FileResponse(
    142142            get_attached_file($post->ID),
    143             $post->post_mime_type,
    144             $_SERVER['HTTP_RANGE']
     143            $post->post_mime_typeg
    145144        );
    146145        $response->send();
     
    435434                    'autoplay' => $matches[9],
    436435                    'preview' => $matches[11],
    437                     'asset' => $matches[13]
     436                    'asset' => isset($matches[13]) ? $matches[13] : ''
    438437                );
    439438                $placeholder = SatoshiPayPlugin::getPlaceholderById($attachmentId, $attachmentAttributes);
     
    467466    {
    468467        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 
    487468        $pricing = self::getPricingData($post);
    488469
    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 
    507470        if ($pricing === false) {
    508             // there is no price (hence no start tag handling)
    509             // we just replace mediaTags
    510             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);
    511474        }
    512475
     
    524487        $html = $intro . $this->placeholderText($pricing, $goodData) . $this->scriptTag();
    525488
    526         return $browserDetectionCode . $adBlockerBaitCode . $html;
     489        return $html;
    527490    }
    528491
     
    558521        return substr($content, $offset);
    559522    }
    560 
    561     /**
    562      * Validate Ad Blocker Detection option.
    563      *
    564      * @param array $input
    565      * @return boolean|integer
    566      */
    567     protected function validateAdBlockerDetectionOption($input)
    568     {
    569         $validatedValue = false;
    570 
    571         // Check for existing input field
    572         if (isset($input['enabled'])) {
    573             $inputValue = trim($input['enabled']);
    574             // Check for integer value
    575             if (ctype_digit($inputValue)) {
    576                 $inputValue = (int)$inputValue;
    577                 // Check for valid value
    578                 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 $input
    591      * @return boolean|integer
    592      */
    593     protected function validateAdBlockerDetectionPrice($input)
    594     {
    595         $validatedValue = false;
    596 
    597         // Check for existing input field
    598         if (isset($input['price'])) {
    599             $inputValue = trim(strip_tags(stripslashes($input['price'])));
    600             // Check for integer value
    601             if (ctype_digit($inputValue)) {
    602                 $inputValue = (int)$inputValue;
    603                 // Check for valid value
    604                 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 $cookie
    617      * @return string
    618      */
    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     }
    631523}
  • satoshipay/trunk/views/admin/options/page.phtml

    r1951997 r1985825  
    11<div class="wrap sp__settings-page">
    22  <h2 class="sp__settings-page__title"><?php _e('SatoshiPay', $this->textdomain); ?></h2>
    3   <?php settings_errors( 'sp_errors' ); ?>
     3  <?php settings_errors( 'sp_messages' ); ?>
    44  <div class="sp__settings-page__content">
    55      <form class="sp__settings-page__form" method="post">
    66          <!-- API Section -->
    77          <?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'; ?>
    148
    159          <!-- Submit Button -->
Note: See TracChangeset for help on using the changeset viewer.