diff --git a/page-goods.php b/page-goods.php index e4209d5..b7bcf00 100644 --- a/page-goods.php +++ b/page-goods.php @@ -1,64 +1,118 @@ - -need('header.php'); ?> +if (!defined('__TYPECHO_ROOT_DIR__')) exit; +$this->need('header.php'); +?> +
-
-

title() ?>

-

content(); ?>

-
-
+
+

title() ?>

+
+ +
+ content; + $goods = parseGoodsTable($content); + + if (!empty($goods)) { + foreach ($goods as $item): ?> +
+
+ + <?php echo htmlspecialchars($item['name']); ?> + +
+
+
+ · +
+ +
+
+ 暂无商品数据,请按照格式填写商品信息。
'; + } + ?> +
+ -fields->memos ? $this->fields->memos : 'https://memos.imsun.org'; - $memosID = $this->fields->memosID ? $this->fields->memosID : '1'; - $memostag = $this->fields->memostag ? $this->fields->memostag : '好物'; - ?> - -need('footer.php'); ?> \ No newline at end of file +.brand { + font-weight: 500; + margin-bottom: 5px; +} +.no-goods { + grid-column: 1 / -1; + text-align: center; + padding: 20px; + background: #f5f5f5; + border-radius: 8px; +} + + +loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); + libxml_clear_errors(); + + // 查找表格 + $tables = $dom->getElementsByTagName('table'); + + if ($tables->length > 0) { + $table = $tables->item(0); // 获取第一个表格 + $rows = $table->getElementsByTagName('tr'); + + // 跳过表头行 + for ($i = 1; $i < $rows->length; $i++) { + $row = $rows->item($i); + $cells = $row->getElementsByTagName('td'); + + // 确保有足够的单元格 + if ($cells->length >= 5) { + $item = array( + 'image' => trim($cells->item(0)->textContent), + 'name' => trim($cells->item(1)->textContent), + 'price' => trim($cells->item(2)->textContent), + 'link' => trim($cells->item(3)->textContent), + 'description' => trim($cells->item(4)->textContent) + ); + + // 确保必要字段不为空 + if (!empty($item['image']) && !empty($item['name'])) { + $goods[] = $item; + } + } + } + } + + return $goods; +} + +$this->need('footer.php'); +?> \ No newline at end of file