/** @see WP_Widget::widget */ function widget($args, $instance) { $items_page_id = get_option('dbaa_items_page'); if (get_the_ID() == $items_page_id && $items_page_id != 0) { $instance = array_merge($this->defaults, $instance); echo $args['before_widget']; echo $args['before_title']; echo $instance['title']; echo $args['after_title']; if (is_numeric($instance['time_limit']) && $instance['time_limit'] > 0) { $instance['scope'] = date('Y-m-d') . "," . date('Y-m-t', strtotime('+' . ($instance['time_limit'] - 1) . ' month')); } $instance['owner'] = false; $categories = aa_Categories::getCategoriesWithProducts(); echo "<ul>"; $li_wrap = !preg_match('/^<li>/i', trim($instance['format'])); if (count($categories) > 0) { foreach ($categories as $category) { if ($li_wrap) { echo '<li>' . aa_Categories::formatCategory($instance['format'], $category) . '</li>'; } else { echo aa_Categories::formatCategory($instance['format'], $category); } } } else { echo '<li>Keine Produkte in Kategorien vorhanden.</li>'; } if (!empty($instance['all_categories'])) { $categories_link = aa_getCategoriesLink($instance['all_categories_text']); echo '<li>' . $categories_link . '</li>'; } echo '</ul>'; echo $args['after_widget']; } }
function saveItem($post) { global $wpdb; $itemTable = AA_ITEMS_TABLE; $slug = strtolower($post['title']); $umlaute = array("/ä/", "/ö/", "/ü/", "/Ä/", "/Ö/", "/Ü/", "/ß/"); $replace = array("ae", "oe", "ue", "Ae", "Oe", "Ue", "ss"); $slug = preg_replace($umlaute, $replace, $slug); $slug = trim(preg_replace('![^a-z0-9]+!', '-', strtolower($slug)), '-'); $item = array('category_id' => aa_Categories::getCatId($post['productGroup']), 'item_title' => $post['title'], 'item_slug' => $slug, 'item_describition' => $post['desc'], 'item_price' => $post['price'], 'item_url' => $post['url'], 'item_asin' => $post['asin'], 'item_binding' => $post['binding'], 'item_ean' => $post['ean'], 'item_label' => $post['label'], 'item_manufacturer' => $post['manufacturer'], 'item_mpn' => $post['mpn'], 'item_publisher' => $post['publisher'], 'item_studio' => $post['studio'], 'item_author' => $post['author']); $itemFormat = array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s'); $wpdb->insert($itemTable, $item, $itemFormat); $itemId = $wpdb->insert_id; for ($i = 0; $i < $post['countFeature']; $i++) { saveFeature($post['feature' . $i], $itemId); } //saveFeatures($post['features'], $itemId); $pic = new AA_Picture($post['pictureTitleTag'], $post['pictureFilename'], $post['pictureUrl'], $itemId); $pic->download(); for ($i = 0; $i < $post['countVariant']; $i++) { if (isset($post['pictureCheck' . $i])) { $pic = new AA_Picture($post['pictureTitleTag' . $i], $post['pictureFilename'] . '-' . $i, $post['pictureUrl' . $i], $itemId); $pic->download(); } } if ($itemId != 0) { return true; } else { return false; } }
/** * * @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']); } }
function aa_items_page_title($content) { 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)) { // single event page $content = AA_Item::output_single($item->item_id, get_option('dbaa_item_page_title_tag_format')); } elseif (is_object($aa_category) && !empty($aa_category->category_englishname)) { $content = aa_Categories::formatCategory(get_option('dbaa_single_category_title_format'), $aa_category); } elseif (!empty($_REQUEST['item_categories'])) { $content = get_option('dbaa_categories_list_title'); } else { $content = get_option('dbaa_items_page_title'); } return $content . ' | '; } return $content; }
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 aa_admin_categories_save() { $category = aa_Categories::getCategoryByID($_POST['category_id']); $category->germanname = $_POST['germanname']; aa_Categories::updateCategory($category); echo 'Kategorie wurde erfolgreich gespeichert'; }