/**
 *
 * @global <type> $item
 * @global <type> $aa_category
 * Checks if a single Item or Category is called and saves it in a global variable
 */
function aa_load_item()
{
    define('AA_URI', get_permalink(get_option("dbaa_items_page")));
    //PAGE URI OF AA
    global $item, $aa_category;
    if (!empty($_REQUEST['item_id']) && is_numeric($_REQUEST['item_id'])) {
        // single Item page
        $item = AA_Item::getSingleItemByID($_REQUEST['item_id']);
    } elseif (isset($_REQUEST['item_slug'])) {
        $item = AA_Item::getSingleItemBySlug($_REQUEST['item_slug']);
    } elseif (!empty($_REQUEST['category_id']) && is_numeric($_REQUEST['category_id'])) {
        $aa_category = aa_Categories::getCategoryByID($_REQUEST['category_id']);
    } elseif (isset($_REQUEST['category_slug'])) {
        $aa_category = aa_Categories::getCategoryBySlug($_REQUEST['category_slug']);
    }
}
 /**
  * will redirect old links to new link structures.
  * @return mixed
  */
 function redirection()
 {
     global $wp_rewrite, $post, $wp_query;
     if ($wp_rewrite->using_permalinks() && !is_admin()) {
         //is this a querystring url?
         $items_page_id = get_option('dbaa_items_page');
         if (is_object($post) && $post->ID == $items_page_id && $items_page_id != 0) {
             $page = !empty($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : '';
             if (!empty($_GET['item_id']) && is_numeric($_GET['item_id'])) {
                 //single item page
                 $item = AA_Item::getSingleItemByID($_GET['item_id']);
                 wp_redirect(self::url('item', $item->item_slug), 301);
                 exit;
             }
         }
     }
 }
 function output($cat_id = null)
 {
     $items = self::get($cat_id);
     $output = "";
     $item_count = count($items);
     if (count($items) > 0) {
         foreach ($items as $item) {
             $output .= AA_Item::output($item, get_option('dbaa_item_list_item_format'));
         }
     } elseif (count($items) == 0 && is_numeric($cat_id) && $cat_id != null) {
         /**
          * @todo generated Option für keine Produkte in Kategorie
          */
         $output = 'Keine Produkte in dieser Kategorie vorhanden';
     } else {
         $output = get_option('dbaa_no_items_message');
     }
     return $output;
 }
function aa_seometa_add_meta()
{
    global $post, $item, $aa_category;
    $page_id = get_option('dbaa_items_page');
    if ($post->ID == $page_id && $page_id != 0) {
        if (is_object($item) && !empty($item->item_title)) {
            $content = AA_Item::output_single($item->item_id, get_option('dbaa_item_page_meta_desc_format'));
        } elseif (is_object($aa_category) && !empty($aa_category->category_englishname)) {
            $content = 'Produkte zur Kategorie ' . $aa_category->category_germanname;
        } elseif (!empty($_REQUEST['item_categories'])) {
            $content = get_option('dbaa_categories_list_title');
        } else {
            $content = get_option('dbaa_items_page_title');
        }
        ?>
        <meta name="description" content="<?php 
        echo $content;
        ?>
"/>
    <?php 
    }
}
Exemple #5
0
function aa_admin_item_page()
{
    if (empty($_REQUEST['item_id'])) {
        echo aa_admin_items_page();
    } elseif ($_REQUEST['action'] == 'item_edit') {
        $item = AA_Item::getSingleItemByID($_REQUEST['item_id']);
        if (is_object($item) && !empty($item->item_title)) {
            ?>
       <script type="text/javascript">
       function addFeatureRow(id) {
           var counter = document.getElementById('countFeature');
           var counterValue =  document.getElementById('countFeature').value;
           counterValue = parseInt(counterValue) + 1;
           counter.value = counterValue;
              var CATTR = document.getElementById('category_row');
              var TABLE = document.getElementById('item_table');
              var BODY=TABLE.getElementsByTagName('tbody')[0];
              var TR = document.createElement('tr');
              var TD1 = document.createElement('th');
              var TD2 = document.createElement('td');
              var TD3 = document.createElement('td');
              id = id +1;
              name = 'feature_'+id;
              TD1.innerHTML = 'Feature ' + id;
              TD2.innerHTML = '<input type="text" style="width:95%" size="45" name='+name+' id="'+name+'" value="" />';
              TD3.innerHTML = '<input type="button" value="+" onclick="addFeatureRow('+id+')"/>';
              TR.appendChild (TD1);
              TR.appendChild (TD2);
              TR.appendChild (TD3);
              BODY.insertBefore(TR,CATTR);

      }
     </script>
            <h2><?php 
            echo $item->item_title;
            ?>
</h2>
            <form id="item-form" method="post" action="">
               <table class="form-table" id="item_table">
                    <input type="hidden" name="item_id" value="<?php 
            echo $item->item_id;
            ?>
"/>
                    <?php 
            aa_input_text('Produktname:', 'item_title', $item->item_title);
            aa_textarea('Beschreibung:', 'item_desc', $item->item_describition);
            aa_input_text('Label:', 'item_label', $item->item_label);
            aa_input_text('Hersteller:', 'item_manufacturer', $item->item_manufacturer);
            aa_input_text('Publisher:', 'item_publisher', $item->item_publisher);
            aa_input_text('Studio:', 'item_studio', $item->item_studio);
            aa_input_text('Author:', 'item_author', $item->item_author);
            aa_input_text('Preis:', 'item_price', $item->item_price, '', TRUE);
            aa_input_text('ASIN:', 'item_asin', $item->item_asin, '', TRUE);
            aa_input_text('EAN:', 'item_ean', $item->item_ean, '', TRUE);
            $i = 1;
            if (count($item->features) != 0) {
                foreach ($item->features as $feature) {
                    aa_features_input_text('Feature ' . $i . ':', 'feature_' . $i, $feature, count($item->features));
                    $i++;
                }
            } else {
                aa_features_input_text('Feature ' . $i . ':', 'feature_' . $i, '');
            }
            echo '</div>';
            $categories = aa_Categories::getCategoryOptions();
            aa_select('Kategorie', 'category', $categories, $item->category_id);
            ?>
                    </table>

                    <input type="hidden" id="countFeature" name="countFeature" value="<?php 
            echo count($item->features);
            ?>
"/>
                    <input type="submit" id="dbaa_item_submit" name="Submit" value="speichern"/>
                    <input type="hidden" name="aa-item-submitted" value="1" />

            </form>
        <?php 
        } else {
            echo 'Das von Ihnen ausgewählte Produkt kann nicht gefunden werden.';
        }
    } elseif ($_REQUEST['action'] == 'item_delete') {
        global $wpdb;
        $wpdb->query("DELETE FROM " . AA_FEATURES_TABLE . " WHERE item_id=" . $_REQUEST['item_id']);
        $wpdb->query("DELETE FROM " . AA_PICTURES_TABLE . " WHERE item_id=" . $_REQUEST['item_id']);
        $wpdb->query("DELETE FROM " . AA_ITEMS_TABLE . " WHERE item_id=" . $_REQUEST['item_id']);
        echo aa_admin_items_page();
    }
}
/**
 * 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);
                }
            }
        }
    }
}