/**
  * 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}"));
     }
 }
Пример #2
0
 /**
  * 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') . " -->";
     }
 }
 /**
  * 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();
 }
 /**
  * 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();
     }
 }