/** * 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') . " -->"; } }
protected function printPreviewTable($arrComponents, $arrArgs) { // Instantiate the core object - the fetching process should be done while rendering the HTML output // because it takes some time so the flush() function is used in the middle. $arrArgs['template_path'] = AmazonAutoLinks_Commons::$strPluginDirPath . '/template/preview/template.php'; $arrArgs['is_preview'] = true; // this disables the global ASIN blacklist. $oAALCatPreview = new AmazonAutoLinks_Unit_Category($arrArgs); $oAALUnitPreview = new AmazonAutoLinks_Unit_Category($arrArgs); echo "<!-- page url:{$arrComponents['strPageURL']}-->"; echo "<!-- preview url:{$arrComponents['strRSSURL']}-->"; // Buttons $fReachedLimit = $this->isReachedLimit($arrArgs); $fIsAlreadyAdded = $this->isAddedCategory($arrComponents['strBreadcrumb'], $arrArgs['categories']); $fIsAlreadyAddedExcludingCategory = $this->isAddedCategory($arrComponents['strBreadcrumb'], $arrArgs['categories_exclude']); $fIsSubCategoryOfAddedItems = $this->isSubCategoryOfAddedItems($arrComponents['strBreadcrumb'], $arrArgs['categories']); $strAddDisabled = empty($arrComponents['strRSSURL']) || $fIsAlreadyAdded || $fIsAlreadyAddedExcludingCategory ? "disabled='Disabled'" : ""; $strExcludeDisabled = empty($arrArgs['categories']) || $fIsAlreadyAdded || $fIsAlreadyAddedExcludingCategory || !$fIsSubCategoryOfAddedItems ? "disabled='Disabled'" : ""; $strRemoveDisabled = empty($arrArgs['categories']) ? "disabled='Disabled'" : ""; $strCreateDisabled = empty($arrArgs['categories']) ? "disabled='Disabled'" : ""; $strCreateOrSave = $arrComponents['fNew'] ? __('Create', 'amazon-auto-links') : __('Save', 'amazon-auto-links'); // Arrows $strAddArrow = $arrComponents['fNew'] && !empty($arrComponents['strRSSURL']) && empty($arrArgs['categories']) ? "<img class='category-select-right-arrow' title='" . __('Add the current selection!', 'amazon-auto-links') . "' src='" . AmazonAutoLinks_Commons::getPluginURL('asset/image/arrow_right.png') . "'/>" : ""; $strCreateArrow = $arrComponents['fNew'] && !empty($arrComponents['strRSSURL']) && !empty($arrArgs['categories']) ? "<img class='category-select-right-arrow' title='" . __('Create the unit!', 'amazon-auto-links') . "' src='" . AmazonAutoLinks_Commons::getPluginURL('asset/image/arrow_right.png') . "'/>" : ""; $strSelectArrow = $arrComponents['fNew'] && empty($arrComponents['strRSSURL']) && empty($arrArgs['categories']) ? "<img class='category-select-left-bottom-arrow' title='" . __('Select a category from the links!', 'amazon-auto-links') . "' src='" . AmazonAutoLinks_Commons::getPluginURL('asset/image/arrow_left_bottom.png') . "'/>" : ""; ?> <form action="" method="post"> <?php if (function_exists('wp_nonce_field')) { wp_nonce_field(AmazonAutoLinks_Commons::AdminOptionKey, 'nonce'); } ?> <input type="hidden" name="amazon_auto_links_cat_select[category][breadcrumb]" value="<?php echo $this->oEncrypt->encode($arrComponents['strBreadcrumb']); ?> " /> <input type="hidden" name="amazon_auto_links_cat_select[category][feed_url]" value="<?php echo $arrComponents['strRSSURL']; ?> " /> <input type="hidden" name="amazon_auto_links_cat_select[category][page_url]" value="<?php echo $arrComponents['strPageURL']; ?> " /> <table class="category-select-table"> <tbody> <tr> <td class="category-select-first-column"> <h3><?php _e('Current Selection', 'amazon-auto-links'); ?> </h3> <p class="category-select-breadcrumb"><?php echo $arrComponents['strBreadcrumb']; ?> </p> </td> <td class="category-select-second-column" colspan="2"> <div class="category-select-submit-buttons"> <span><a class="button button-primary" href="<?php echo $arrComponents['strBounceURL']; ?> "><?php _e('Go Back', 'amazon-auto-links'); ?> </a></span> <span><?php echo $strCreateArrow; ?> <input type="submit" name="amazon_auto_links_cat_select[save]" class="button button-primary" value="<?php echo $strCreateOrSave; ?> " <?php echo $strCreateDisabled; ?> /></span> <span><?php echo $strAddArrow; ?> <input type="submit" name="amazon_auto_links_cat_select[add]" class="button button-secondary" value="<?php _e('Add Category', 'amazon-auto-links'); ?> " <?php echo $strAddDisabled; ?> /></span> <span><input type="submit" name="amazon_auto_links_cat_select[exclude]" class="button button-secondary" value="<?php _e('Add Excluding Category', 'amazon-auto-links'); ?> " <?php echo $strExcludeDisabled; ?> /></span> <span><input type="submit" name="amazon_auto_links_cat_select[remove]" class="button button-secondary" value="<?php _e('Remove Checked', 'amazon-auto-links'); ?> " <?php echo $strRemoveDisabled; ?> /></span> </div> <div> <h3><?php _e('Added Categories', 'amazon-auto-links'); ?> </h3> <?php echo $arrComponents['strSelectedCategories']; ?> <h3><?php _e('Added Excluding Sub-categories', 'amazon-auto-links'); ?> </h3> <?php echo $arrComponents['strSelectedExcludingCategories']; ?> </div> </td> </tr> <tr> <td class="category-select-first-column"> <h3><?php _e('Select Category', 'amazon-auto-links'); ?> </h3> <?php echo $strSelectArrow; ?> <?php echo $arrComponents['strSidebarHTML']; ?> </td> <td class="category-select-second-column category-select-preview-left"> <h3> <?php echo $arrComponents['strRSSURL'] ? __('Preview of This Category', 'amazon-auto-links') : __('No Preview', 'amazon-auto-links'); ?> </h3> <div class="widthfixer" style="width:<?php echo $arrArgs['image_size']; ?> px;"></div> <?php if ($arrComponents['strRSSURL']) { $oAALCatPreview->render(array($arrComponents['strRSSURL'])); // flush(); } else { _e('Please select a category from the list on the left.', 'amazon-auto-links'); } ?> </td> <td class="category-select-third-column category-select-preview-right"> <h3><?php _e('Unit Preview', 'amazon-auto-links'); ?> </h3> <div class="widthfixer" style="width:<?php echo $arrArgs['image_size']; ?> px;"></div> <?php if (!empty($arrComponents['arrSelectedRSSURLs'])) { $oAALUnitPreview->render($arrComponents['arrSelectedRSSURLs']); flush(); } else { _e('Please add a category from the list after selecting it.', 'amazon-auto-links'); } ?> </td> </tr> </tbody> </table> </form> <?php }