/** * Shows a list of books * */ function bookx_listItems() { $link = get_page_link($this->var->options["page_id"]); if ($_POST["order"]) { $order = $_POST["order"]; } else { if ($_GET["order"]) { $order = $_GET["order"]; } else { $order = $this->var->options['list_order_default']; } } if ($_POST["sort"]) { $sort = $_POST["sort"]; } else { if ($_GET["sort"]) { $sort = $_GET["sort"]; } else { $sort = $this->var->options['list_sort_default']; } } $text = "<div id=\"bookx_content\">"; if ($this->var->options["list_filter"] == 1) { $text .= "<div id=\"bookx_filter\">"; $text .= "<form id=\"bookx_filter\" action=\"{$link}\" method=\"post\">"; $text .= "Field: <select name=\"order\">"; foreach (array_keys($this->var->fieldArray) as $f) { if ($f == $order) { $s = "selected"; } else { $s = ''; } $text .= "<option value=\"{$f}\" {$s}>" . $this->var->fieldArray[$f] . "</option>"; } $text .= "</select>"; $text .= " Order: <select name=\"sort\">"; foreach (array_keys($this->var->sortArray) as $f) { if ($f == $sort) { $s = "selected"; } else { $s = ''; } $text .= "<option value=\"{$f}\" {$s}>" . $this->var->sortArray[$f] . "</option>"; } $text .= "</select>"; $text .= "<input type=\"submit\" value=\"Set\" />"; $text .= "</form>"; $text .= "</div>"; } if ($_GET["limit"]) { $limit = $_GET["limit"]; } else { $limit = 0; } $count = $this->wpdb->get_var("select count(bx_item_id) from " . $this->wpdb->prefix . "bx_item"); $setnum = $this->var->options["per_page"]; if ($this->var->options["per_page"] != 0 && $count > $setnum) { $paging = true; require_once BOOKX_DIR . 'suitex/suitex_list.php'; $listObj = new suitex_list(); $listObj->setNum = $setnum; $url = $link . "?&order={$order}&sort={$sort}"; $pager = $listObj->createPaging($limit, $count, $url); $text .= "<div id=\"bookx_pager\">{$pager}</div>"; } $sql = "select bx_item_publisher, bx_item_price, bx_item_date, bx_item_summary, bx_item_comments, "; $sql .= "bx_item_id, bx_item_name, bx_item_isbn, bx_item_format, bx_item_pages, bx_item_author, bx_item_image"; $sql .= " from " . $this->wpdb->prefix . "bx_item "; $sql .= "order by {$order} {$sort}"; $sql .= " limit {$limit}, {$setnum}"; $results = $this->wpdb->get_results($sql); if (substr_count($this->var->options["listTemplate"], "::IMAGE::")) { $doImage = true; } foreach ($results as $row) { $image = $row->bx_item_image; if ($doImage && $image != '') { $sourceWidth = substr($image, strpos($image, "width=\"") + 7); $sourceWidth = substr($sourceWidth, 0, strpos($sourceWidth, "\"")); $sourceHeight = substr($image, strpos($image, "height=\"") + 8); $sourceHeight = substr($sourceHeight, 0, strpos($sourceHeight, "\"")); if ($sourceWidth > $this->var->options["list_image_width"]) { $newWidth = $this->var->options["list_image_width"]; $newHeight = (int) ($sourceHeight * ($this->var->options["list_image_width"] / $sourceWidth)); } else { if ($sourceHeight > $this->var->options["list_image_height"]) { $newWidth = (int) ($sourceWidth * ($this->var->options["list_image_height"] / $sourceHeight)); $newHeight = $this->var->options["list_image_height"]; } else { $newWidth = $sourceWidth; $newHeight = $sourceHeight; } } $image = str_replace('width="' . $sourceWidth . '"', 'width="' . $newWidth . '"', $image); $image = str_replace('height="' . $sourceHeight . '"', 'height="' . $newHeight . '"', $image); if ($this->var->options["list_image_align"] != '') { $image = str_replace("src", "align=\"" . $this->var->options['list_image_align'] . "\" src", $image); } } $trans["::ELINK::"] = $row->bx_item_link; $trans["::TITLE::"] = $row->bx_item_name; $trans["::AUTHOR::"] = $row->bx_item_author; $trans["::ISBN::"] = $row->bx_item_isbn; $trans["::PUBLISHER::"] = $row->bx_item_publisher; $trans["::DATE::"] = $row->bx_item_date; $trans["::PAGES::"] = $row->bx_item_pages; $trans["::FORMAT::"] = $row->bx_item_format; $trans["::LINK::"] = $link . "?&book_id=" . $row->bx_item_id; $trans["::IMAGE::"] = $image; $trans["::PRICE::"] = $row->bx_item_price; $trans["::SUMMARY::"] = substr(strip_tags($row->bx_item_summary), 0, $this->var->options["list_characters"]) . "..."; $trans["::COMMENTS::"] = substr(strip_tags($row->bx_item_comments), 0, $this->var->options["list_characters"]) . "..."; $trans["::MORE::"] = " <a href=\"" . $link . "?&book_id=" . $row->bx_item_id . "\">More</a>"; $text .= "<div class=\"bookx_list_entry\">" . strtr(stripslashes($this->var->options["listTemplate"]), $trans) . "</div>"; } if ($pager) { $text .= "<div id=\"bookx_pager\">{$pager}</div>"; } $text .= "</div>"; $this->text = $text; }