/** * Sets the default option values for the setting form. * @callback filter `options_{class name}` * @return array The options array. */ public function setOptions($aOptions) { $_oUtil = new AmazonAutoLinks_WPUtility(); $_iPostID = $_oUtil->getCurrentPostID(); $_aUnitOptions = $_iPostID ? $_oUtil->getPostMeta($_GET['post']) : array(); return $aOptions + $_aUnitOptions + self::$aStructure_AutoInsertDefaultOptions; }
/** * @return array */ private function _getSanitizedInputs($aInput) { $_oOption = AmazonAutoLinks_Option::getInstance(); $_oUtil = new AmazonAutoLinks_WPUtility(); add_filter('safe_style_css', array($this, 'replyToAddAllowedInlineCSSProperties')); $_aAllowedHTMLTags = $_oUtil->convertStringToArray($_oOption->get('form_options', 'allowed_html_tags'), ','); $aInput['item_format'] = $_oUtil->escapeKSESFilter($aInput['item_format'], $_aAllowedHTMLTags); $aInput['image_format'] = $_oUtil->escapeKSESFilter($aInput['image_format'], $_aAllowedHTMLTags); $aInput['title_format'] = $_oUtil->escapeKSESFilter($aInput['title_format'], $_aAllowedHTMLTags); remove_filter('safe_style_css', array($this, 'replyToAddAllowedInlineCSSProperties')); // Drop unnecessary items. unset($aInput['_submit_convert'], $aInput['_show_unit_counts'], $aInput['_scheduled_tasks'], $aInput['_separator'], $aInput['unit_types']); return $aInput; }
/** * Validates submitted form data. */ public function validate($aInput, $aOriginal, $oFactory) { $_oOption = AmazonAutoLinks_Option::getInstance(); $_oUtil = new AmazonAutoLinks_WPUtility(); add_filter('safe_style_css', array($this, 'replyToAddAllowedInlineCSSProperties')); $_aAllowedHTMLTags = $_oUtil->convertStringToArray($_oOption->get('form_options', 'allowed_html_tags'), ','); $aInput['item_format'] = $_oUtil->escapeKSESFilter($aInput['item_format'], $_aAllowedHTMLTags); $aInput['image_format'] = $_oUtil->escapeKSESFilter($aInput['image_format'], $_aAllowedHTMLTags); $aInput['title_format'] = $_oUtil->escapeKSESFilter($aInput['title_format'], $_aAllowedHTMLTags); remove_filter('safe_style_css', array($this, 'replyToAddAllowedInlineCSSProperties')); // Schedule pre-fetch for the unit if the options have been changed. if ($aInput !== $aOriginal) { AmazonAutoLinks_Event_Scheduler::prefetch(AmazonAutoLinks_PluginUtility::getCurrentPostID()); } return $aInput; }
/** * * @since 3 */ protected function _createAutoInsert($iNewPostID) { // Construct a meta array. $_aAutoInsertOptions = array('unit_ids' => array($iNewPostID)) + AmazonAutoLinks_AutoInsertAdminPage::$aStructure_AutoInsertDefaultOptions; // Insert a post. AmazonAutoLinks_WPUtility::insertPost($_aAutoInsertOptions, AmazonAutoLinks_Registry::$aPostTypes['auto_insert']); }
public function getRemainedAllowedUnits($iNumberOfUnits = null) { if (!isset($iNumberOfUnits)) { $_oNumberOfUnits = AmazonAutoLinks_WPUtility::countPosts(AmazonAutoLinks_Registry::$aPostTypes['unit']); $iNumberOfUnits = $_oNumberOfUnits->publish + $_oNumberOfUnits->private + $_oNumberOfUnits->trash; } return 3 - $iNumberOfUnits; }
/** * * @remark Will redirect the user to the next page and exits the script. */ private function _goToNextPage($aInput) { // Format the submitted data. $aInput['transient_id'] = isset($_GET['transient_id']) ? $_GET['transient_id'] : uniqid(); $aInput['bounce_url'] = add_query_arg(array('transient_id' => $aInput['transient_id'], 'aal_action' => 'select_category', 'page' => $this->sPageSlug, 'tab' => $this->sTabSlug) + $_GET, admin_url($GLOBALS['pagenow'])); return $aInput; // Save the data in a temporary area of the databse. $_bSucceed = AmazonAutoLinks_WPUtility::setTransient(AmazonAutoLinks_Registry::TRANSIENT_PREFIX . '_CreateUnit_' . $aInput['transient_id'], $aInput, 60 * 10 * 6 * 24); // Go to the next page. exit(wp_safe_redirect(add_query_arg(array('transient_id' => $aInput['transient_id'], 'aal_action' => 'select_category', 'tab' => 'second') + $_GET, admin_url($GLOBALS['pagenow'])))); }
/** * Clears all the plugin caches. * @since 3 * @return void */ private function _clearAllCaches($oFactory) { // Clear transients. AmazonAutoLinks_WPUtility::cleanTransients(AmazonAutoLinks_Registry::TRANSIENT_PREFIX); AmazonAutoLinks_WPUtility::cleanTransients('apf_'); $_oCacheTable = new AmazonAutoLinks_DatabaseTable_request_cache(AmazonAutoLinks_Registry::$aDatabaseTables['request_cache']); $_oCacheTable->delete(); $_oProductTable = new AmazonAutoLinks_DatabaseTable_product(AmazonAutoLinks_Registry::$aDatabaseTables['product']); $_oProductTable->delete(); $oFactory->setSettingNotice(__('Caches have been cleared.', 'amazon-auto-links')); }
/** * Sets the default option values for the setting form. * @callback filter `options_{class name}` * @return array The options array. */ public function setOptions($aOptions) { $_aUnitOptions = array(); if (isset($_GET['post'])) { $_aUnitOptions = AmazonAutoLinks_WPUtility::getPostMeta($_GET['post']); } // Set some items for the edit mode. $_iMode = !isset($_GET['post']); // 0: edit, 1: new $_aOptions = array('mode' => $_iMode); if (!$_iMode) { $_aOptions['bounce_url'] = AmazonAutoLinks_WPUtility::getPostDefinitionEditPageURL($_GET['post'], AmazonAutoLinks_Registry::$aPostTypes['unit']); } $_aOptions = $aOptions + $_aOptions + $_aUnitOptions + $this->_getLastUnitInputs(); return $_aOptions; }
/** * Checks whether the meta box should be registered or not in the loading page. */ public function _isInThePage() { if (!parent::_isInThePage()) { return false; } // Register custom filed type. new AmazonAutoLinks_RevealerCustomFieldType($this->oProp->sClassName); // At this point, it is TRUE evaluated by the framework. // but we need to evaluate it for the plugin. // Get the post ID. $_iPostID = AmazonAutoLinks_WPUtility::getCurrentPostID(); // Maybe post-new.php if (!$_iPostID) { return true; } $_sUnitType = get_post_meta($_iPostID, 'unit_type', true); return in_array($_sUnitType, $this->aUnitTypes); }
protected function handleCustomActions() { if (!isset($_GET['custom_action'], $_GET['nonce'], $_GET['post'])) { return; } $_sNonce = AmazonAutoLinks_WPUtility::getTransient('AAL_Nonce_' . $_GET['nonce']); if (false === $_sNonce) { add_action('admin_notices', array($this, 'replyToNotifyNonceFailed')); return; } AmazonAutoLinks_WPUtility::deleteTransient('AAL_Nonce_' . $_GET['nonce']); // Currently only the status toggle is supported. if ('toggle_status' === $_GET['custom_action'] && $_GET['post']) { $_aUnitIDs = get_post_meta($_GET['post'], 'unit_ids', true); // if this field is empty, the post must be the wrong post type. if (empty($_aUnitIDs)) { return; } $_bIsEnabled = get_post_meta($_GET['post'], 'status', true); update_post_meta($_GET['post'], 'status', !$_bIsEnabled); } }
/** * The plugin activation callback method. */ public function replyToPluginDeactivation() { // Clean transients. AmazonAutoLinks_WPUtility::cleanTransients(AmazonAutoLinks_Registry::TRANSIENT_PREFIX); AmazonAutoLinks_WPUtility::cleanTransients('apf_'); }
/** * Creates a post of amazon_auto_links custom post type with unit option meta fields. * * @return integer the post(unit) id. */ private function _postUnitByCategory($aUnitOptions, $aOptions) { $_iPostID = 0; // Create a custom post if it's a new unit. if (!isset($_GET['post']) || !$_GET['post']) { $_iPostID = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $GLOBALS['user_ID'], 'post_title' => $aOptions['unit_title'], 'post_status' => 'publish', 'post_type' => AmazonAutoLinks_Registry::$aPostTypes['unit'])); } // Add meta fields. $_iPostID = 1 == $aOptions['mode'] ? $_iPostID : $_GET['post']; // Remove unnecessary items. // The unit title was converted to post_title above. unset($aUnitOptions['unit_title'], $aUnitOptions['is_preview']); $_oOption = AmazonAutoLinks_Option::getInstance(); $_oTemplateOption = AmazonAutoLinks_TemplateOption::getInstance(); $aUnitOptions['template_id'] = $_oTemplateOption->getDefaultTemplateIDByUnitType('category'); AmazonAutoLinks_WPUtility::updatePostMeta($_iPostID, $aUnitOptions); // Create an auto insert - the 'auto_insert' key will be removed when creating a post.s if (isset($aOptions['auto_insert']) && $aOptions['auto_insert'] && 1 == $aOptions['mode']) { AmazonAutoLinks_PluginUtility::createAutoInsert($_iPostID); } return $_iPostID; }
public function unlink() { unset($GLOBALS['aSimplePieCacheModTimestamps'][$this->sPluginKey][$this->sFileID]); AmazonAutoLinks_WPUtility::deleteTransient($this->sTransientName); return true; }
public function content($sOutput) { return $sOutput . "<h4>" . __('Unit Options', 'amazon-auto-links') . "</h4>" . $this->oDebug->get(AmazonAutoLinks_WPUtility::getPostMeta($GLOBALS['post']->ID)); }
/** * * @callback filter column_ + description */ public function column_description($aItem) { // Action Links $aActions = array('version' => sprintf(__('Version', 'amazon-auto-links') . ' ' . $aItem['version']), 'author' => sprintf('<a href="%s">' . $aItem['author'] . '</a>', $aItem['author_uri']), 'css' => sprintf('<a href="%s">' . __('CSS', 'amazon-auto-links') . '</a>', AmazonAutoLinks_WPUtility::getSRCFromPath($aItem['dir_path'] . DIRECTORY_SEPARATOR . 'style.css'))); return sprintf('%1$s <div class="active second">%2$s</div>', $aItem['description'], $this->row_actions($aActions)); }
/** * A callback for the accessSiteAtShutDown() method. * * @since 1.0.0 */ public static function _replyToAccessSite() { // Retrieve the plugin scheduled tasks array. $_sTransientName = md5(get_class()); $_aTasks = AmazonAutoLinks_WPUtility::getTransient($_sTransientName); $_aTasks = $_aTasks ? $_aTasks : array(); $_nNow = microtime(true); // Check the excessive background call protection interval if (!self::$_fIgnoreLock) { $_nCalled = isset($_aTasks['called']) ? $_aTasks['called'] : 0; if ($_nCalled + self::$_iLockBackgroundCallInterval > $_nNow) { return; // if it's called within 10 seconds from the last time of calling this method, do nothing to avoid excessive calls. } } // Renew the called time. $_aFlagKeys = array('called' => $_nNow); // set a locked key so it prevents duplicated function calls due to too many calls caused by simultaneous accesses. AmazonAutoLinks_WPUtility::setTransient($_sTransientName, $_aFlagKeys + $_aTasks, self::getAllowedMaxExecutionTime()); // Compose a GET query array $_aGet = self::$_aGet; if (defined('WP_DEBUG')) { $_aGet['debug'] = WP_DEBUG; } unset($_aGet[0]); // Load the site in the background. wp_remote_get(site_url('?' . http_build_query($_aGet)), array('timeout' => 0.1, 'sslverify' => false, 'cookies' => $_aFlagKeys + array($_sTransientName => true))); }
/** * * * @access protected as the ..._New class extends this class and acess this method. */ protected function updatePostMeta($iPostID, $aMeta) { AmazonAutoLinks_WPUtility::insertPost($aMeta, AmazonAutoLinks_Registry::$aPostTypes['auto_insert']); }
/** * A wrapper method for the get_transient() function. * * This method does retrieves the transient with the given transient key. In addition, it checks if it is an array; otherwise, it makes it an array. * * @access public * @since 2.0.0 * @since 3 Changed to use a custom database. * @remark The scope is public as the event method uses it. */ public function getCache($sTransientKey) { if ($this->bUseCacheTable) { $_oCacheTable = new AmazonAutoLinks_DatabaseTable_request_cache(AmazonAutoLinks_Registry::$aDatabaseTables['request_cache']); $_aData = $_oCacheTable->getCache($sTransientKey); $vData = $_aData['data']; } else { $vData = AmazonAutoLinks_WPUtility::getTransient($sTransientKey); } // if it's false, no transient is stored. Otherwise, some values are in there. if (in_array($vData, array(false, ''), true)) { return false; } // If it's array, okay. if (is_array($vData)) { return $vData; } // Maybe it's encoded if (is_string($vData) && is_serialized($vData)) { return unserialize($vData); } // Maybe it's an object. In that case, convert it to an associative array. if (is_object($vData)) { return get_object_vars($vData); } // It's an unknown type, then cast array. return (array) $vData; }
/** * * @access protected as the ..._New class extends this class and acess this method. * @return array */ protected function getSanitizedAutoInsertMeta($aMeta) { $_oUtil = new AmazonAutoLinks_WPUtility(); $_aDefinedKeys = array_keys(AmazonAutoLinks_AutoInsertAdminPage::$aStructure_AutoInsertDefaultOptions); // Drop keys not defined in the default structure. foreach ($aMeta as $_sKey => $_mValue) { if (in_array($_sKey, $_aDefinedKeys)) { continue; } unset($aMeta[$_sKey]); } $aMeta['filter_hooks'] = $_oUtil->trimDelimitedElements($aMeta['filter_hooks'], ','); $aMeta['action_hooks'] = $_oUtil->trimDelimitedElements($aMeta['action_hooks'], ','); $aMeta['enable_post_ids'] = $_oUtil->trimDelimitedElements($aMeta['enable_post_ids'], ','); $aMeta['diable_post_ids'] = $_oUtil->trimDelimitedElements($aMeta['diable_post_ids'], ','); return $aMeta; }
/** * @return string */ private function _getFormattedDescription($aItem) { $_aAttribuetes = array('href' => $aItem['link'], 'rel' => 'nofollow', 'class' => 'button button-secondary', 'target' => '_blank', 'title' => esc_attr(__('Get it Now', 'amazon-auto-links'))); return "<h4>" . $aItem['title'] . "</h4>" . $aItem['description'] . "<div class='get-now'>" . "<a " . AmazonAutoLinks_WPUtility::generateAttributes($_aAttribuetes) . ">" . __('Get it Now', 'amazon-auto-links') . "</a>" . "</div>"; }
public function cell_aal_auto_insert_area($sCell, $iPostID) { $_oUtil = new AmazonAutoLinks_WPUtility(); $_aList = array(); $aSelectedAreas = (array) get_post_meta($iPostID, 'built_in_areas', true) + (array) get_post_meta($iPostID, 'static_areas', true); $aSelectedAreas = array_filter($aSelectedAreas); $aAreasLabel = $_oUtil->getPredefinedFilters() + $_oUtil->getPredefinedFiltersForStatic(false); foreach ($aSelectedAreas as $sArea => $fEnable) { if (isset($aAreasLabel[$sArea])) { $_aList[] = $aAreasLabel[$sArea]; } } $aFilters = $_oUtil->convertStringToArray(get_post_meta($iPostID, 'filter_hooks', true), ','); $aActions = $_oUtil->convertStringToArray(get_post_meta($iPostID, 'action_hooks', true), ','); $_aList = array_merge($aFilters, $aActions, $_aList); return '<p>' . implode(', ', $_aList) . '</p>'; }