/** * * @global <type> $wp_query * @global <type> $item * @global <type> $aa_category * @global <type> $wpdb * @param <type> $page_content * @return string * overrinding existing Content on page with requested page content */ function aa_content($page_content) { $items_page_id = get_option('dbaa_items_page'); global $wp_query, $item, $aa_category; if (get_the_ID() == $items_page_id && $items_page_id != 0) { global $wpdb; $content = apply_filters('aa_content_pre', '', $page_content); if (empty($content)) { ob_start(); if (is_object($item) && !empty($item->item_title)) { // single item page echo AA_Item::output_single($item->item_id, get_option('dbaa_single_item_format')); } elseif (is_object($aa_category) && !empty($aa_category->category_englishname)) { echo aa_Categories::outputSingle($aa_category); } elseif (!empty($_REQUEST['item_categories'])) { echo aa_Categories::outputAll(); } else { echo AA_Items::output(); } $content = ob_get_clean(); } return '<div id="aa-wrapper">' . $content . '</div>'; } return $page_content; }
function formatCategory($format, $category) { $output = $format; preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders); foreach ($placeholders[0] as $result) { $replace = ''; switch ($result) { case '#_GERMANNAME': $replace = $category->category_germanname; break; case '#_ENGLISHNAME': $replace = $category->category_englishname; break; case '#_CATLINK': $AA_URI = AA_URI; $joiner = stristr($AA_URI, "?") ? "&" : "?"; $cat_link = $AA_URI . $joiner . "category_id=" . $category->category_id; $replace = "<a href='{$cat_link}' title='{$category->category_germanname}'>{$category->category_germanname}</a>"; break; case '#_CATITEMS': $replace = AA_Items::output($category->category_id); break; } $replace = apply_filters('aa_category_output_placeholder', $replace, $category, $result, $target); $output = str_replace($result, $replace, $output); } return $output; }
function aa_admin_items_page() { global $wpdb, $item; $items = AA_Items::get(); if (empty($items)) { echo 'Keine Produkte in Datenbank importiert'; } else { ?> <table class="widefat"> <thead> <tr> <th>Titel</th> <th>Hersteller</th> <th>Preis</th> </tr> </thead> <tbody> <?php $rowno = 0; $event_count = 0; foreach ($items as $item) { $rowno++; $class = $rowno % 2 ? 'alternate' : ''; ?> <tr class="<?php echo trim($class); ?> " id="item_<?php echo $item->item_id; ?> "> <td> <strong> <a class="row-title" href="<?php bloginfo('wpurl'); ?> /wp-admin/admin.php?page=aa_edit_item&action=item_edit&item_id=<?php echo $item->item_id; ?> "><?php echo $item->item_title; ?> </a> </strong> <div class="row-actions"> <span class="trash"><a href="<?php bloginfo('wpurl'); ?> /wp-admin/admin.php?page=aa_edit_item&action=item_delete&item_id=<?php echo $item->item_id; ?> ">löschen</a></span> </div> </td> <td> <?php echo $item->item_manufacturer; ?> </td> <td> <?php echo $item->item_price; ?> </td> </tr> <?php } ?> </tbody> </table> <?php } }
/** * function executed every hour on cron job */ function updateItemsDataHourly() { $appid = get_option('dbaa_amazon_appid'); $coutryCode = get_option('dbaa_amazon_coutnrycode'); $secretKey = get_option('dbaa_amazon_secretkey'); $associatetag = get_option('dbaa_amazon_associatetag'); if ($appid != '' && $coutryCode != '' && $secretKey != '') { $amazon = new Zend_clicks_Service_Amazon($appid, $coutryCode, $secretKey); $results = AA_Items::get(); foreach ($results as $result) { $amazonresults = $amazon->itemLookup($result->item_asin, array('AssociateTag' => $associatetag, 'ResponseGroup' => 'Small, OfferFull, ItemAttributes')); foreach ($amazonresults as $amazonresult) { $vk = 'bla'; if (isset($amazonresult->Offers->Offers)) { $vk = $amazonresult->Offers->Offers[0]->FormattedPrice; } elseif (isset($amazonresult->FormattedPrice)) { $vk = $amazonresult->FormattedPrice; } if ($result->item_price != $vk) { AA_Item::updatePrice($vk, $result->item_id); } } } } }