Exemple #1
0
/**
 * Echoes or returns the output of Amazon product links.
 * @since       1
 * @since       3       Added the second parameter to let the user choose whether it should echo or return the output.
 */
function AmazonAutoLinks($aArguments, $bEcho = true)
{
    if ($bEcho) {
        AmazonAutoLinks_Output::getInstance($aArguments)->render();
        return;
    }
    return AmazonAutoLinks_Output::getInstance($aArguments)->get();
}
 /**
  * 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();
 }
 /**
  * 
  * @callback        action        aal_action_unit_prefetch
  */
 public function doAction()
 {
     $_aParams = func_get_args() + array(null);
     $iUnitID = $_aParams[0];
     $_sUnitType = get_post_meta($iUnitID, 'unit_type', true);
     if (!$_sUnitType) {
         return;
     }
     // Just call the output.
     $_sUnitOptionClassName = "AmazonAutoLinks_UnitOption_" . $_sUnitType;
     $_oUnitOptions = new $_sUnitOptionClassName($iUnitID);
     $_aUnitOptions = $_oUnitOptions->get();
     AmazonAutoLinks_Output::getInstance($_aUnitOptions)->get();
 }
 /**
  * Handles static insertion for posts.
  * 
  * @remark            Only category taxonomy allow/deny check is supported. Other types post_tags and custom taxonomies are not supported yet.
  */
 public function doFilterForStaticInsertion($aPostContent, $aPostMeta = array())
 {
     // if the publish key exists, it means it is an update
     if (isset($aPostMeta['save']) && $aPostMeta['save'] == 'Update') {
         return $aPostContent;
     }
     // If it's auto-draft saving feature, do nothing.
     if (isset($aPostContent['post_status']) && $aPostContent['post_status'] != 'publish') {
         return $aPostContent;
     }
     // The default disabled post types.
     if (in_array($aPostContent['post_type'], array(AmazonAutoLinks_Registry::$aPostTypes['unit'], AmazonAutoLinks_Registry::$aPostTypes['auto_insert'], 'revision', 'attachment', 'nav_menu_item'))) {
         return $aPostContent;
     }
     /*    $aPostMeta structure
               [ID] => 278
               [post_category] => Array (
                   [0] => 0
                   [1] => 10
                   [2] => 9
                   [3] => 1
               )
               [tax_input] => Array(
                   [post_tag] => test
               )
           */
     $aSubjectPostInfo = array('post_id' => $aPostMeta['ID'], 'post_type' => $aPostContent['post_type'], 'term_ids' => $aPostMeta['post_category']) + self::$aStructure_SubjectPageInfo;
     $sPre = '';
     $sPost = '';
     foreach ($this->aFilterHooks['wp_insert_post_data'] as $iAutoInsertID) {
         if (!$this->isAutoInsertEnabledPage($iAutoInsertID, $aSubjectPostInfo)) {
             continue;
         }
         $aAutoInsertOptions = $this->aAutoInsertOptions[$iAutoInsertID];
         // position - above, below, or both,
         $sPosition = $aAutoInsertOptions['static_position'];
         if ($sPosition == 'above' || $sPosition == 'both') {
             $oUnits = new AmazonAutoLinks_Output(array('id' => $aAutoInsertOptions['unit_ids']));
             $sPre .= $oUnits->get();
         }
         if ($sPosition == 'below' || $sPosition == 'both') {
             $oUnits = new AmazonAutoLinks_Output(array('id' => $aAutoInsertOptions['unit_ids']));
             $sPost .= $oUnits->get();
         }
     }
     $aPostContent['post_content'] = $sPre . $aPostContent['post_content'] . $sPost;
     return $aPostContent;
 }