/** * Render offer javascript for content */ public function showOfferJs() { if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI'])) { return; } if (!preg_match('/^\\/?' . self::OFFER_JS_URL_PREFIX . '(\\d+)(\\?.+)?/', $_SERVER['REQUEST_URI'], $match)) { return; } $id = $match[1]; $post = get_post($id); if (!$post) { return; } $metaString = get_post_meta($post->ID, self::META_NAME, true); $contentSettings = TinypassContentSettings::fromArray($metaString); $content = apply_filters('the_content', $post->post_content); try { $result = self::$tinypass->checkAccessSettings($contentSettings, $content, array($this, 'trimContent'), $this->getResources()); header('HTTP/1.1 200 OK'); header('Content-Type: application/javascript'); echo $result->javascript(); die; } catch (Exception $e) { header('HTTP/1.1 200 OK'); if ($this->canDebug()) { die($e->getMessage()); } } }
/** * Renders the plugin's main setting's page */ public function renderSettingsPage() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'tinypass')); } // Determine on which stage of configuration / or which plugin sub-page is requested $step = $this->determineStep(); // Init array of parameters for the template with the first parameter of empty array of currencies $params = array('currencies' => array()); // Initialize default content settings $contentSettings = TinypassContentSettings::fromArray(self::$default_access_settings); $params['contentSettings'] = $contentSettings; if ($step == 'subscription' && $this->isConfigured()) { // If current page is plugin's main settings page for "hard / keyed paywall" try { // Fetch available currencies $params['currencies'] = self::$tinypass->getCurrencies(); // Get available resources $params['resources'] = self::getResources(); } catch (Exception $e) { // Add error on failure. All exception messages are using i18n before throwing add_settings_error(self::SETTINGS_ERROR_SLUG, self::SETTINGS_ERROR_SLUG, 'Tinypass: '******'s being rendered from settings page $params['isSettingsPage'] = true; // Render the template $this->renderView($step, $params); }