/**
  * Sets up registered hooks and store hooks in the property array.
  */
 public function _replyToSetUpHooks()
 {
     if (0 == count($this->arrAutoInsertIDs)) {
         return;
     }
     // Retrieve all the options.
     foreach ($this->arrAutoInsertIDs as $intID) {
         $this->arrAutoInsertOptions[$intID] = AmazonAutoLinks_Option::getUnitOptionsByPostID($intID) + AmazonAutoLinks_Form_AutoInsert::$arrStructure_AutoInsertOptions;
         // convert comma delimited stings to array
         $this->arrAutoInsertOptions[$intID]['diable_post_ids'] = AmazonAutoLinks_Utilities::convertStringToArray($this->arrAutoInsertOptions[$intID]['diable_post_ids'], ',');
         $this->arrAutoInsertOptions[$intID]['enable_post_ids'] = AmazonAutoLinks_Utilities::convertStringToArray($this->arrAutoInsertOptions[$intID]['enable_post_ids'], ',');
     }
     // Find out used filters - user-defined and built-in(plugin's predefined) filters.
     $this->arrFilterHooks = $this->getFilters($this->arrAutoInsertOptions);
     // Find out used actions - get user-defined custom filters
     $this->arrActionHooks = $this->getHooks($this->arrAutoInsertOptions, 'action_hooks');
     // Add hooks!
     foreach ($this->arrFilterHooks as $strFilter => $arrAutoInsertIDs) {
         if ($strFilter == 'wp_insert_post_data') {
             add_filter($strFilter, array($this, "callback_filter_{$strFilter}"), '99', 2);
         } else {
             add_filter($strFilter, array($this, "callback_filter_{$strFilter}"));
         }
     }
     foreach ($this->arrActionHooks as $strAction => $arrAutoInsertIDs) {
         add_action($strAction, array($this, "callback_action_{$strAction}"));
     }
 }
 /**
  * @return      string
  */
 private function _getAffiliateInfo()
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_bJoindAffiliate = $_oOption->get('miunosoft_affiliate', 'affiliate_id');
     $_sLink = 'http://store.michaeluno.jp/wp-signup.php';
     return $_bJoindAffiliate ? '' : "<h4>" . __('Join Affiliate Program ', 'admin-page-framework-loader') . "</h4>" . "<p>" . __('Earn 20% commissions by setting a credit link in the unit output.', 'amazon-auto-links') . ' ' . sprintf(__('<a href="%1$s" target="_blank">Sing up</a> for the affiliate program first.', 'amazon-auto-links'), $_sLink) . "</p>" . "<a href='{$_sLink}' target='_blank'>" . "<img style='max-width:100%; max-width: 250px;' src='" . esc_url(AmazonAutoLinks_Registry::getPluginURL('asset/image/tip/credit_link.jpg')) . "' alt='" . __('Credit Link', 'amazon-auto-links') . "'/>" . "</a>";
 }
 /**
  * 
  * @callback        filter      validation + _ + page slug
  */
 public function validate($aInput, $aOldInput, $oFactory, $aSubmitInfo)
 {
     $_bVerified = true;
     $_aErrors = array();
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_oTemplateOption = AmazonAutoLinks_TemplateOption::getInstance();
     $_oUtil = new AmazonAutoLinks_PluginUtility();
     // Check the limitation.
     if ($_oOption->isUnitLimitReached()) {
         $oFactory->setSettingNotice(sprintf(__('Please upgrade to <A href="%1$s">Pro</a> to add more units! Make sure to empty the <a href="%2$s">trash box</a> to delete the units completely!', 'amazon-auto-links'), 'http://en.michaeluno.jp/amazon-auto-links-pro/', admin_url('edit.php?post_status=trash&post_type=' . AmazonAutoLinks_Registry::$aPostTypes['unit'])));
         return $aOldInput;
     }
     // If specified and the customer ID is not 13 characters,
     $aInput['customer_id'] = trim($aInput['customer_id']);
     if ($aInput['customer_id'] && strlen($aInput['customer_id']) != 13) {
         $_aErrors['customer_id'] = __('The customer ID must consist of 13 characters.', 'amazon-auto-links') . ' ';
         $_bVerified = false;
     }
     if (empty($aInput['tags']) && empty($aInput['customer_id'])) {
         $_aErrors['tags'] = __('Either tags or customer ID has to be entered.', 'amazon-auto-links');
         $_sMessage = __('Either tags or customer ID has to be entered.', 'amazon-auto-links');
         $_aErrors['customer_id'] = isset($_aErrors['customer_id']) ? $_aErrors['customer_id'] . $_sMessage : $_sMessage;
         $_bVerified = false;
     }
     if (empty($aInput['associate_id'])) {
         $_aErrors['associate_id'] = __('The associate ID cannot be empty.', 'amazon-auto-links');
         $_bVerified = false;
     }
     // An invalid value is found.
     if (!$_bVerified) {
         // Set the error array for the input fields.
         $oFactory->setFieldErrors($_aErrors);
         $oFactory->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links'));
         return $aInput;
     }
     // Sanitize the tag input
     $aInput['tags'] = trim($_oUtil->trimDelimitedElements($aInput['tags'], ','));
     $_bDoAutoInsert = $aInput['auto_insert'];
     // Format the unit options to sanitize the data.
     $_oUnitOptions = new AmazonAutoLinks_UnitOption_tag(null, $aInput);
     $aInput = $_oUnitOptions->get();
     $aInput['template_id'] = $_oTemplateOption->getDefaultTemplateIDByUnitType('tag');
     // Create a unit post
     $_iNewPostID = $_oUtil->insertPost($aInput, AmazonAutoLinks_Registry::$aPostTypes['unit']);
     // Create an auto insert
     if ($_bDoAutoInsert) {
         $_oUtil->createAutoInsert($_iNewPostID);
     }
     // Clean the temporary form options data.
     $_oUtil->deleteTransient($GLOBALS['aal_transient_id']);
     // Schedule pre-fetching the unit feed in the background
     // so that by the time the user opens the unit page, the cache will be ready.
     AmazonAutoLinks_Event_Scheduler::prefetch($_iNewPostID);
     // Store the inputs for the next time.
     update_option(AmazonAutoLinks_Registry::$aOptionKeys['last_input'], $aInput, false);
     // Go to the post editing page and exit. This way the framework won't create a new form transient row.
     $_oUtil->goToPostDefinitionPage($_iNewPostID, AmazonAutoLinks_Registry::$aPostTypes['unit']);
     // This won't be reached.
     return $aInput;
 }
 /**
  * 
  * @callback        filter      validation_{page slug}_{tab slug}
  */
 public function validate($aInput, $aOldInput, $oFactory, $aSubmitInfo)
 {
     $_bVerified = !$oFactory->hasFieldError();
     $_aErrors = array();
     $_oOption = AmazonAutoLinks_Option::getInstance();
     // Check the limitation.
     if ($_oOption->isUnitLimitReached()) {
         // must set an field error array which does not yield empty so that it won't be redirected.
         $oFactory->setFieldErrors(array('error'));
         $oFactory->setSettingNotice(sprintf(__('Please upgrade to <A href="%1$s">Pro</a> to add more units! Make sure to empty the <a href="%2$s">trash box</a> to delete the units completely!', 'amazon-auto-links'), 'http://en.michaeluno.jp/amazon-auto-links-pro/', admin_url('edit.php?post_status=trash&post_type=' . AmazonAutoLinks_Registry::$aPostTypes['unit'])));
         return $aOldInput;
     }
     // An invalid value is found. Set a field error array and an admin notice and return the old values.
     if (!$_bVerified) {
         $oFactory->setFieldErrors($_aErrors);
         $oFactory->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links'));
         return $aInput;
     }
     // $aInput[ 'transient_id' ] = isset( $_REQUEST[ 'transient_id' ] )
     // ? $_REQUEST[ 'transient_id' ]
     // : AmazonAutoLinks_Registry::TRANSIENT_PREFIX . '_CreateUnit_' . 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']));
     $oFactory->setSettingNotice(__('Select a category from the below list.', 'amazon-auto-links'), 'updated');
     // Store the inputs for the next time.
     update_option(AmazonAutoLinks_Registry::$aOptionKeys['last_input'], $aInput, false);
     return $aInput;
 }
 /**
  * Returns the unit output by post (unit) ID.
  */
 private function _getOutputByID($iPostID)
 {
     $_aUnitOptions = AmazonAutoLinks_Option::getUnitOptionsByPostID($iPostID);
     /**
      * The auto-insert sets the 'id' as array storing multiple ids. But this method is called per ID so the ID should be discarded.
      */
     $_aSetArgs = $this->aArgs;
     unset($_aSetArgs['id']);
     $_aUnitOptions = $_aSetArgs + $_aUnitOptions + array('unit_type' => null, 'id' => $iPostID);
     // if the unit gets deleted, auto-insert causes an error for not finding the options
     switch ($_aUnitOptions['unit_type']) {
         case 'category':
             $_oAALCat = new AmazonAutoLinks_Unit_Category($_aUnitOptions);
             return $_oAALCat->getOutput();
         case 'tag':
             $_oAALTag = new AmazonAutoLinks_Unit_Tag($_aUnitOptions);
             return $_oAALTag->getOutput();
         case 'search':
             $_oAALSearch = new AmazonAutoLinks_Unit_Search($_aUnitOptions);
             return $_oAALSearch->getOutput();
         case 'item_lookup':
             $_oAALSearch = new AmazonAutoLinks_Unit_Search_ItemLookup($_aUnitOptions);
             return $_oAALSearch->getOutput();
         case 'similarity_lookup':
             $_oAALSearch = new AmazonAutoLinks_Unit_Search_SimilarityLookup($_aUnitOptions);
             return $_oAALSearch->getOutput();
         default:
             return "<!-- " . AmazonAutoLinks_Commons::$strPluginName . ': ' . __('Could not identify the unit type. Please make sure to update the auto-insert definition if you have deleted the unit.', 'amazon-auto-links') . " -->";
     }
 }
 /**
  * Form field validation.
  * 
  * @callback        validation_{page slug}_{tab_slug}
  */
 public function validate($aInput, $aOldInput, $oFactory, $aSubmitInfo)
 {
     // $_bVerified = ! $oFactory->hasFieldError();
     $_bVerified = true;
     $_aErrors = array();
     $_oOption = AmazonAutoLinks_Option::getInstance();
     // Check invalid values
     // Check necessary settings.
     if (!array_filter($aInput['built_in_areas'] + $aInput['static_areas']) && !$aInput['filter_hooks'] && !$aInput['action_hooks']) {
         $_sMessage = __('At least one area must be set.', 'amazon-auto-links');
         $_aErrors['autoinsert_built_in_areas'] = $_sMessage;
         $_aErrors['autoinsert_static_areas'] = $_sMessage;
         $_aErrors['autoinsert_filter_hooks'] = $_sMessage;
         $_aErrors['autoinsert_action_hooks'] = $_sMessage;
         $_bVerified = false;
     }
     if (!isset($aInput['unit_ids'])) {
         // if no item is selected, the select input with the multiple attribute does not send the key.
         $_aErrors['autoinsert_unit_ids'] = __('A unit must be selected.', 'amazon-auto-links');
         $_bVerified = false;
     }
     // An invalid value is found. Set a field error array and an admin notice and return the old values.
     if (!$_bVerified) {
         $oFactory->setFieldErrors($_aErrors);
         $oFactory->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links'));
         return $aOldInput;
     }
     // Update an auto-insert post.
     $this->updatePostMeta(isset($aInput['post_id']) ? $aInput['post_id'] : 0, $this->getSanitizedAutoInsertMeta($aInput));
     return $aInput;
 }
 /**
  * 
  * @callback        filter      validation_{page slug}_{tab slug}
  */
 public function validate($aInput, $aOldInput, $oFactory, $aSubmitInfo)
 {
     $_bVerified = !$oFactory->hasFieldError();
     $_aErrors = array();
     $_oOption = AmazonAutoLinks_Option::getInstance();
     // Check the limitation.
     if ($_oOption->isUnitLimitReached()) {
         // must set an field error array which does not yield empty so that it won't be redirected.
         $oFactory->setFieldErrors(array('error'));
         $oFactory->setSettingNotice(sprintf(__('Please upgrade to <A href="%1$s">Pro</a> to add more units! Make sure to empty the <a href="%2$s">trash box</a> to delete the units completely!', 'amazon-auto-links'), 'http://en.michaeluno.jp/amazon-auto-links-pro/', admin_url('edit.php?post_status=trash&post_type=' . AmazonAutoLinks_Registry::$aPostTypes['unit'])));
         return $aOldInput;
     }
     if (empty($aInput['associate_id'])) {
         $_aErrors['associate_id'] = __('The associate ID cannot be empty.', 'amazon-auto-links');
         $_bVerified = false;
     }
     // An invalid value is found. Set a field error array and an admin notice and return the old values.
     if (!$_bVerified) {
         $oFactory->setFieldErrors($_aErrors);
         $oFactory->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links'));
         return $aInput;
     }
     // This should be the last check in the entire page validation checks.
     if ($oFactory->oUtil->hasSuffix('submit_proceed', $aSubmitInfo['field_id'])) {
         // Will exit the script.
         unset($aInput['submit_proceed']);
         $this->_goToNextPage($aInput);
     }
     return $aInput;
 }
 /**
  * Sets up properties.
  */
 public function __construct($bRefNosim = false, $sAssociateID = '', $sLocale = 'US')
 {
     $this->bRefNosim = $bRefNosim;
     $this->sAssociateID = $sAssociateID;
     $this->sLocale = $sLocale;
     $this->oOption = AmazonAutoLinks_Option::getInstance();
     $this->oEncrypt = new AmazonAutoLinks_Encrypt();
 }
 public function replyToDoAfterPage($oFactory)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isDebug()) {
         return;
     }
     echo "<p>Debug</p>" . $oFactory->oDebug->get($oFactory->oProp->aOptions);
 }
 /**
  * Checks whether the meta box should be registered or not in the loading page.
  */
 public function _isInThePage()
 {
     if (!parent::_isInThePage()) {
         return false;
     }
     $_oOption = AmazonAutoLinks_Option::getInstance();
     return $_oOption->isDebug();
 }
 public function replyToDoAfterPage($oFactory)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isDebug()) {
         return;
     }
     echo "<h3>" . __('Debug', 'amazon-auto-links') . ": " . __('Form Options', 'amazon-auto-links') . "</h3>" . $oFactory->oDebug->get($oFactory->getSavedOptions());
 }
 /**
  * Prints debug information at the bottom of the page.
  */
 public function replyToDoAfterPage($oFactory)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isDebug()) {
         return;
     }
     echo "<h3 style='display:block; clear:both;'>" . __('Debug Info', 'amazon-auto-links') . "</h3>";
     $oFactory->oDebug->dump($oFactory->getValue());
 }
 /**
  * Redirects the user to the vendor site.
  */
 private function _goToVendor()
 {
     $_sURL = AmazonAutoLinks_Registry::PLUGIN_URI;
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_isAffiliateID = $_oOption->get('miunosoft_affiliate', 'affiliate_id');
     if (strlen($_isAffiliateID)) {
         $_sURL = add_query_arg(array('ref' => $_isAffiliateID), AmazonAutoLinks_Registry::STORE_URI_PRO);
     }
     exit(wp_redirect($_sURL));
 }
 public function replyToDoAfterTab($oFactory)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isDebug()) {
         return;
     }
     echo "<h3>" . __('Debug', 'amazon-auto-links') . "</h3>";
     echo "<h4>" . __('Raw Template Option Values', 'amazon-auto-links') . "</h4>";
     echo $oFactory->oDebug->get(get_option(AmazonAutoLinks_Registry::$aOptionKeys['template'], array()));
     echo "<h4>" . __('Data of Active Templates', 'amazon-auto-links') . "</h4>";
     echo $oFactory->oDebug->get(AmazonAutoLinks_TemplateOption::getInstance()->get());
 }
 /**
  * A user constructor.
  * 
  * @since       3
  * @return      void
  */
 public function construct($oFactory)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     // Tabs
     new AmazonAutoLinks_HelpAdminPage_Help_Support($this->oFactory, $this->sPageSlug, array('tab_slug' => 'support', 'title' => __('Support', 'amazon-auto-links')));
     new AmazonAutoLinks_HelpAdminPage_Help_FAQ($this->oFactory, $this->sPageSlug, array('tab_slug' => 'faq', 'title' => __('FAQ', 'amazon-auto-links')));
     new AmazonAutoLinks_HelpAdminPage_Help_Tips($this->oFactory, $this->sPageSlug, array('tab_slug' => 'tips', 'title' => __('Tips', 'amazon-auto-links')));
     new AmazonAutoLinks_HelpAdminPage_Help_ChangeLog($this->oFactory, $this->sPageSlug, array('tab_slug' => 'change_log', 'title' => __('Change Log', 'amazon-auto-links')));
     if (!$_oOption->isAdvancedAllowed()) {
         new AmazonAutoLinks_HelpAdminPage_Help_GetPro($this->oFactory, $this->sPageSlug, array('tab_slug' => 'get_pro', 'title' => __('Get Pro', 'amazon-auto-links')));
     }
 }
 /**
  * Prints out the fetched product links.
  * 
  * @remark          Used for the post type single page that functions as preview the result.
  * @since           3       Changed the name from `_replytToPrintPreviewProductLinks()`.
  * */
 public function content($sContent)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isPreviewVisible()) {
         return $sContent;
     }
     $_sUnitType = get_post_meta($GLOBALS['post']->ID, 'unit_type', true);
     $_sUnitType = $_sUnitType ? $_sUnitType : 'category';
     $_sUnitOptionClassName = "AmazonAutoLinks_UnitOption_" . $_sUnitType;
     $_oUnitOptions = new $_sUnitOptionClassName($GLOBALS['post']->ID);
     $_aUnitOptions = $_oUnitOptions->get();
     return $sContent . AmazonAutoLinks_Output::getInstance($_aUnitOptions)->get();
 }
示例#17
0
 /**
  * 
  * @since       3.1.0
  */
 private function _handleQueryURL()
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_sQueryKey = $_oOption->get('query', 'cloak');
     if (!isset($_GET[$_sQueryKey])) {
         return;
     }
     if ('feed' === $_GET[$_sQueryKey]) {
         new AmazonAutoLinks_Event_Feed();
         return;
     }
     new AmazonAutoLinks_Event_Redirect($_sQueryKey);
 }
 /**
  * 
  * @callback        action        aal_action_api_transient_renewal
  */
 public function doAction()
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isAPIConnected()) {
         return;
     }
     $_aParams = func_get_args() + array(null);
     $aRequestInfo = $_aParams[0];
     $_sLocale = $aRequestInfo['locale'];
     $_aParameters = $aRequestInfo['parameters'];
     $_oAmazonAPI = new AmazonAutoLinks_ProductAdvertisingAPI($_sLocale, $_oOption->get(array('authentication_keys', 'access_key'), ''), $_oOption->get(array('authentication_keys', 'access_key_secret'), ''));
     $_oAmazonAPI->request($_aParameters, $_sLocale, null);
 }
 /**
  * The define Auto Insert page.
  */
 public function validation_aal_define_auto_insert($arrInput, $arrOldInput)
 {
     // Drop the sections.
     $arrNewFields = array();
     foreach ($arrInput['aal_define_auto_insert'] as $strSection => $arrFields) {
         $arrNewFields = $arrNewFields + $arrFields;
     }
     // Remove the search_ prefix in the keys.
     $arrSanitizedFields = array();
     foreach ($arrNewFields as $strKey => $vValue) {
         $arrSanitizedFields[preg_replace('/^autoinsert_/', '', $strKey)] = $vValue;
     }
     $fVerified = true;
     $arrErrors = array();
     // Check necessary settings.
     if (!array_filter($arrSanitizedFields['built_in_areas'] + $arrSanitizedFields['static_areas']) && !$arrSanitizedFields['filter_hooks'] && !$arrSanitizedFields['action_hooks']) {
         $arrErrors['autoinsert_area']['autoinsert_built_in_areas'] = __('At least one area must be set.', 'amazon-auto-links');
         $arrErrors['autoinsert_static_insertion']['autoinsert_static_areas'] = __('At least one area must be set.', 'amazon-auto-links');
         $arrErrors['autoinsert_area']['autoinsert_filter_hooks'] = __('At least one area must be set.', 'amazon-auto-links');
         $arrErrors['autoinsert_area']['autoinsert_action_hooks'] = __('At least one area must be set.', 'amazon-auto-links');
         $fVerified = false;
     }
     if (!isset($arrSanitizedFields['unit_ids'])) {
         // if no item is selected, the select input with the multiple attribute does not send the key.
         $arrErrors['autoinsert_area']['autoinsert_unit_ids'] = __('A unit must be selected.', 'amazon-auto-links');
         $fVerified = false;
     }
     // An invalid value is found.
     if (!$fVerified) {
         // Set the error array for the input fields.
         $this->setFieldErrors($arrErrors);
         $this->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links'));
         return $arrOldInput;
     }
     $arrSanitizedFields['filter_hooks'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['filter_hooks'], ',');
     $arrSanitizedFields['action_hooks'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['action_hooks'], ',');
     $arrSanitizedFields['enable_post_ids'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['enable_post_ids'], ',');
     $arrSanitizedFields['diable_post_ids'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['diable_post_ids'], ',');
     // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields );
     // Edit - Update the post.
     $fIsEdit = isset($_POST['mode'], $_POST['post']) && $_POST['post'] && $_POST['mode'] == 'edit';
     if ($fIsEdit) {
         AmazonAutoLinks_Option::updatePostMeta($_POST['post'], $arrSanitizedFields);
     } else {
         // New - Create a post.
         $intNewPostID = AmazonAutoLinks_Option::insertPost($arrSanitizedFields, AmazonAutoLinks_Commons::PostTypeSlugAutoInsert);
     }
     // e.g. http://.../wp-admin/edit.php?post_type=aal_auto_insert
     die(wp_redirect($fIsEdit ? admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlug . '&page=aal_define_auto_insert&mode=edit&post=' . $_POST['post']) : admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlugAutoInsert)));
 }
 /**
  * Schedules an action of getting product information in the background.
  * 
  * @since       3
  * @action      schedule        aal_action_api_get_product_info
  */
 public static function getProductInfo($sAssociateID, $sASIN, $sLocale, $iCacheDuration)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     if (!$_oOption->isAPIConnected()) {
         return false;
     }
     $_bScheduled = self::_scheduleTask('aal_action_api_get_product_info', array($sAssociateID, $sASIN, $sLocale, $iCacheDuration));
     if (!$_bScheduled) {
         return $_bScheduled;
     }
     // Loads the site in the background. The method takes care of doing it only once in the entire page load.
     AmazonAutoLinks_Shadow::see();
     return true;
 }
 /**
  * @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;
 }
 public function setUp()
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $this->setArguments(array('labels' => array('name' => AmazonAutoLinks_Registry::NAME, 'menu_name' => apply_filters('aal_filter_admin_menu_name', AmazonAutoLinks_Registry::NAME), 'all_items' => __('Manage Units', 'amazon-auto-links'), 'singular_name' => __('Amazon Auto Links Unit', 'amazon-auto-links'), 'add_new' => __('Add Unit by Category', 'amazon-auto-links'), 'add_new_item' => __('Add New Unit', 'amazon-auto-links'), 'edit' => __('Edit', 'amazon-auto-links'), 'edit_item' => __('Edit Unit', 'amazon-auto-links'), 'new_item' => __('New Unit', 'amazon-auto-links'), 'view' => __('View', 'amazon-auto-links'), 'view_item' => __('View Product Links', 'amazon-auto-links'), 'search_items' => __('Search Units', 'amazon-auto-links'), 'not_found' => __('No unit found for Amazon Auto Links', 'amazon-auto-links'), 'not_found_in_trash' => __('No Unit Found for Amazon Auto Links in Trash', 'amazon-auto-links'), 'parent' => 'Parent Unit', 'plugin_listing_table_title_cell_link' => __('Manage Units', 'amazon-auto-links')), 'public' => !$_oOption->isCustomPreviewPostTypeSet(), 'publicly_queryable' => !$_oOption->isCustomPreviewPostTypeSet() && $_oOption->isPreviewVisible(), 'has_archive' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_in_menu' => true, 'menu_position' => 110, 'supports' => array('title'), 'taxonomies' => array(''), 'menu_icon' => $this->oProp->bIsAdmin ? AmazonAutoLinks_Registry::getPluginURL('asset/image/menu_icon_16x16.png') : null, 'hierarchical' => false, 'show_admin_column' => true, 'can_export' => $_oOption->canExport(), 'exclude_from_search' => !$_oOption->get('unit_preview', 'searchable')));
     $this->addTaxonomy(AmazonAutoLinks_Registry::$aTaxonomies['tag'], array('labels' => array('name' => __('Label', 'amazon-auto-links'), 'add_new_item' => __('Add New Label', 'amazon-auto-links'), 'new_item_name' => __('New Label', 'amazon-auto-links')), 'show_ui' => true, 'show_tagcloud' => false, 'hierarchical' => false, 'show_admin_column' => true, 'show_in_nav_menus' => false, 'show_table_filter' => true, 'show_in_sidebar_menus' => true));
     if ($this->_isInThePage()) {
         $this->setAutoSave(false);
         $this->setAuthorTableFilter(false);
         add_filter('months_dropdown_results', '__return_empty_array');
         add_filter('enter_title_here', array($this, 'replyToModifyTitleMetaBoxFieldLabel'));
         add_action('edit_form_after_title', array($this, 'replyToAddTextAfterTitle'));
         $this->enqueueStyles(AmazonAutoLinks_Registry::$sDirPath . '/asset/css/admin.css');
     }
     parent::setUp();
 }
 /**
  * Sets up properties and hooks.
  */
 public function setUp()
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $this->setArguments(array('labels' => array('name' => __('Auto-insert', 'amazon-auto-links'), 'singular_name' => __('Auto-insert', 'amazon-auto-links'), 'menu_name' => __('Manage Auto-insert', 'amazon-auto-links'), 'add_new' => __('Add New Auto-insert', 'amazon-auto-links'), 'add_new_item' => __('Add New Auto-insert', 'amazon-auto-links'), 'edit' => __('Edit', 'amazon-auto-links'), 'edit_item' => __('Edit Auto-insert', 'amazon-auto-links'), 'new_item' => __('New Auto-insert', 'amazon-auto-links'), 'view' => __('View', 'amazon-auto-links'), 'view_item' => __('View Auto-insert', 'amazon-auto-links'), 'search_items' => __('Search Auto-insert Definitions', 'amazon-auto-links'), 'not_found' => __('No definitions found for Auto-insert', 'amazon-auto-links'), 'not_found_in_trash' => __('No definitions Found for Auto-insert in Trash', 'amazon-auto-links'), 'parent' => __('Parent Auto-insert', 'amazon-auto-links'), 'plugin_listing_table_title_cell_link' => __('Auto-insert', 'amazon-auto-links')), 'public' => false, 'menu_position' => 120, 'supports' => array('title'), 'taxonomies' => array(''), 'menu_icon' => AmazonAutoLinks_Registry::getPluginURL('asset/image/menu_icon_16x16.png'), 'has_archive' => false, 'hierarchical' => false, 'show_admin_column' => true, 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_in_nav_menus' => false, 'show_ui' => true, 'show_in_menu' => 'edit.php?post_type=' . AmazonAutoLinks_Registry::$aPostTypes['unit'], 'can_export' => $_oOption->canExport()));
     // Check custom actions
     if ($this->_isInThePage()) {
         $this->setAuthorTableFilter(false);
         add_filter('months_dropdown_results', '__return_empty_array');
     }
     // If a unit is deleted, check auto-insert items if there are empty items. If so, delete them as well.
     if (is_admin()) {
         add_action('before_delete_post', array($this, 'replyToCheckEmptyAutoInsert'));
     }
     parent::setUp();
 }
 /**
  * Prints out the fetched product links.
  * 
  * @remark            Used for the post type single page that functions as preview the result.
  * */
 public function _replytToPrintPreviewProductLinks($sContent)
 {
     if (!is_singular()) {
         return $sContent;
     }
     if (!isset($GLOBALS['post']->post_type) || $GLOBALS['post']->post_type != $this->oProps->strPostType) {
         return $sContent;
     }
     if (!$GLOBALS['oAmazonAutoLinks_Option']->isPreviewVisible()) {
         return $sContent;
     }
     $_aUnitOptions = AmazonAutoLinks_Option::getUnitOptionsByPostID($GLOBALS['post']->ID);
     $_aUnitOptions['id'] = $GLOBALS['post']->ID;
     return $sContent . AmazonAutoLinks_Units::getInstance($_aUnitOptions)->getOutput();
 }
 /**
  * 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;
 }
 /**
  * Sets up the form.
  * 
  * Alternatively you may use load_{instantiated class name} method.
  */
 public function load($oAdminWidget)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_bAPIConnected = $_oOption->isAPIConnected();
     if (!$_bAPIConnected) {
         $this->addSettingField(array('field_id' => '_message_dummy_id', 'type' => '_message', 'description' => array(sprintf(__('Please set up API keys first from <a href="%1$s">this page</a>.', 'amazon-auto-links'), AmazonAutoLinks_PluginUtility::getAPIAuthenticationPageURL())), 'attributes' => array('name' => '')));
         return;
     }
     $_aClasses = array('AmazonAutoLinks_FormFields_Widget_ContxtualProduct', 'AmazonAutoLinks_FormFields_Unit_CommonAdvanced', 'AmazonAutoLinks_FormFields_Button_Selector', 'AmazonAutoLinks_FormFields_Unit_Cache', 'AmazonAutoLinks_FormFields_Unit_Template', 'AmazonAutoLinks_FormFields_Widget_Visibility');
     $this->_addFieldsByFieldClass($_aClasses);
     // Product filters
     $this->addSettingSections(array('title' => __('Product Filters', 'amazon-auto-links'), 'section_id' => 'product_filters', 'collapsible' => array('collapsed' => true, 'type' => 'button', 'container' => 'section')));
     // Set the target section.
     $this->addSettingFields('product_filters');
     // Add fields
     $this->_addFieldsByFieldClass(array('AmazonAutoLinks_FormFields_ProductFilter', 'AmazonAutoLinks_FormFields_ProductFilter_Image'));
 }
 /**
  * Returns the field array with the given section ID.
  * 
  * Pass an empty string to the parameter for meta box options. 
  * 
  */
 public function getFields($strSectionID = '', $strPrefix = 'autoinsert_')
 {
     $this->arrAutoInsertOptions = ($this->intPostID = $this->isEdit($_GET)) ? AmazonAutoLinks_Option::getUnitOptionsByPostID($this->intPostID) + self::$arrStructure_AutoInsertOptions : self::$arrStructure_AutoInsertOptions;
     $this->strMode = empty($this->intPostID) ? 'new' : 'edit';
     switch ($strSectionID) {
         case 'autoinsert_status':
             return $this->getFieldsOfStatus($strSectionID, $strPrefix);
         case 'autoinsert_area':
             return $this->getFieldsOfArea($strSectionID, $strPrefix);
         case 'autoinsert_static_insertion':
             return $this->getFieldsOfStaticInsertion($strSectionID, $strPrefix);
         case 'autoinsert_enable':
             return $this->getFieldsOfEnable($strSectionID, $strPrefix);
         case 'autoinsert_disable':
             return $this->getFieldsOfDisable($strSectionID, $strPrefix);
         default:
             return array();
     }
 }
 /**
  * Creates a search unit type
  * 
  * @since       2.0.2
  * @return      integer     A newly created post id.
  */
 protected function _createSearchUnit($aInput)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_oTemplateOption = AmazonAutoLinks_TemplateOption::getInstance();
     $_oUtil = new AmazonAutoLinks_PluginUtility();
     $_bDoAutoInsert = $aInput['auto_insert'];
     // Sanitize the unit options
     $_sClassName = "AmazonAutoLinks_UnitOption_{$aInput['unit_type']}";
     $_oUnitOptions = new $_sClassName(null, $aInput);
     $aInput = $_oUnitOptions->get();
     // will format the options.
     $aInput['template_id'] = $_oTemplateOption->getDefaultTemplateIDByUnitType($aInput['unit_type']);
     // Create a post.
     $_iNewPostID = $_oUtil->insertPost($aInput, AmazonAutoLinks_Registry::$aPostTypes['unit']);
     // Create an auto insert
     if ($_bDoAutoInsert) {
         $this->_createAutoInsert($_iNewPostID);
     }
     return $_iNewPostID;
 }
 /**
  * Sets up properties and hooks.
  */
 public function __construct($aoUnitOptions, $sUnitType = '')
 {
     $this->sUnitType = $sUnitType ? $sUnitType : $this->sUnitType;
     $_sUnitOptionClassName = "AmazonAutoLinks_UnitOption_{$this->sUnitType}";
     $this->oUnitOption = is_object($aoUnitOptions) ? $aoUnitOptions : new $_sUnitOptionClassName(null, $aoUnitOptions);
     $this->oOption = AmazonAutoLinks_Option::getInstance();
     $this->oProductTable = new AmazonAutoLinks_DatabaseTable_product(AmazonAutoLinks_Registry::$aDatabaseTables['product']);
     $this->sCharEncoding = get_bloginfo('charset');
     $this->bIsSSL = is_ssl();
     $this->oDOM = new AmazonAutoLinks_DOM();
     $this->oEncrypt = new AmazonAutoLinks_Encrypt();
     $this->oGlobalProductFilter = new AmazonAutoLinks_ProductFilter($this->getAsArray($this->oOption->get('product_filters')));
     $this->oUnitProductFilter = new AmazonAutoLinks_ProductFilter($this->getAsArray($this->oUnitOption->get('product_filters')));
     if ($this->oUnitOption->get('is_preview')) {
         $this->oGlobalProductFilter->bNoDuplicate = false;
         $this->oUnitProductFilter->bNoDuplicate = false;
     }
     $this->bDBTableAccess = $this->_hasCustomVariable($this->oUnitOption->get('item_format'), array('%price%', '%review%', '%rating%', '%image_set%'));
     // Sanitize product title for sorting.
     add_filter('aal_filter_unit_product_raw_title', array($this, 'replyToModifyRawTitle'), 10, 2);
 }
 public function setUp()
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $this->setArguments(array('labels' => array('name' => __('Buttons', 'amazon-auto-links'), 'singular_name' => __('Button', 'amazon-auto-links'), 'menu_name' => __('Manage Buttons', 'amazon-auto-links'), 'add_new' => __('Add New Button', 'amazon-auto-links'), 'add_new_item' => __('Add New Button', 'amazon-auto-links'), 'edit' => __('Edit', 'amazon-auto-links'), 'edit_item' => __('Edit Button', 'amazon-auto-links'), 'new_item' => __('New Button', 'amazon-auto-links'), 'view' => __('View', 'amazon-auto-links'), 'view_item' => __('View Button', 'amazon-auto-links'), 'search_items' => __('Search Button Definitions', 'amazon-auto-links'), 'not_found' => __('No definitions found for Button', 'amazon-auto-links'), 'not_found_in_trash' => __('No definitions Found for Button in Trash', 'amazon-auto-links'), 'parent' => __('Parent Button', 'amazon-auto-links'), 'plugin_listing_table_title_cell_link' => __('Button', 'amazon-auto-links')), 'menu_position' => 120, 'supports' => array('title'), 'taxonomies' => array(''), 'menu_icon' => AmazonAutoLinks_Registry::getPluginURL('asset/image/menu_icon_16x16.png'), 'has_archive' => false, 'hierarchical' => false, 'show_admin_column' => true, 'exclude_from_search' => true, 'publicly_queryable' => false, 'show_in_nav_menus' => false, 'show_ui' => true, 'public' => false, 'show_in_menu' => 'edit.php?post_type=' . AmazonAutoLinks_Registry::$aPostTypes['unit'], 'can_export' => $_oOption->canExport()));
     if ($this->_isInThePage()) {
         $this->setAutoSave(false);
         $this->setAuthorTableFilter(false);
         add_filter('months_dropdown_results', '__return_empty_array');
         // add_filter( 'enter_title_here', array( $this, 'replyToModifyTitleMetaBoxFieldLabel' ) );
         // add_action( 'edit_form_after_title', array( $this, 'replyToAddTextAfterTitle' ) );
         add_filter('post_updated_messages', array($this, 'replyToModifyPostUpdatedMessages'));
         $this->enqueueStyles(AmazonAutoLinks_Registry::$sDirPath . '/asset/css/admin.css');
         $this->enqueueStyles(AmazonAutoLinks_Registry::$sDirPath . '/asset/css/edit.aal-button.css');
         // unit listing table columns
         add_filter('columns_' . AmazonAutoLinks_Registry::$aPostTypes['button'], array($this, 'replyToModifyColumnHeader'));
     }
     if (is_admin()) {
         add_action('save_post', array($this, 'replyToUpdateButtonCSSOnSavingPost'));
         add_action('transition_post_status', array($this, 'replyToUpdateButtonCSSOnPostStatusChange'), 10, 3);
     }
 }