���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /proc/self/root/var/www/html/tien-dien/code/pages/ |
<?php $menu_ftitle = $CORE->input['menu_ftitle']??''; //$menu_id = isset($CORE->input['menu_id']) ? intval($CORE->input['menu_id']) : 0; if($menu_ftitle==''){ header('Location: /?act=404'); exit(); } $row_check_menu = $DB->fetch_row($DB->query("SELECT * FROM `tb_menus` WHERE `menus_fname` = '$menu_ftitle' ")); $menu_bg = ''; if($row_check_menu and !empty($row_check_menu['menus_img'])){ $menu_bg = 'upload/logos/'.$row_check_menu['menus_img'].'.png'; } $menu_id = 0; if($row_check_menu){ $menu_id = $row_check_menu['menus_id']; }else{ header('Location: /?act=404'); exit(); } // ID của mục "Sản phẩm" (ví dụ: 8) $idChaChoSanPham = 8; // Hoặc lấy ID này một cách động nếu cần // (Tùy chọn) Lấy slug của danh mục hiện tại để highlight // Bạn cần có logic để lấy $current_category_slug từ URL hoặc biến nào đó // Ví dụ: $current_category_slug = $CORE->input['menu_ftitle'] ?? ''; $current_category_slug = $menu_ftitle; // Thay thế bằng slug thực tế của trang hiện tại switch ($row_check_menu['menus_type']){ default: include 'list.php'; break; case 'page': include 'page.php'; break; case 'url': header('Location: '.$row_check_menu['menus_url']); exit(); break; } function isDescendantOfProductCategory($all_categories, $current_category_slug, $product_root_id) { if (empty($all_categories) || !is_array($all_categories) || empty($current_category_slug)) { return false; } $currentItem = null; // Tìm mục menu hiện tại dựa trên slug foreach ($all_categories as $category) { if (isset($category['menus_fname']) && $category['menus_fname'] == $current_category_slug) { $currentItem = $category; break; } } // Nếu không tìm thấy slug hiện tại trong danh sách if ($currentItem === null) { return false; } // Nếu slug hiện tại chính là danh mục gốc "Sản phẩm" if (isset($currentItem['menus_id']) && $currentItem['menus_id'] == $product_root_id) { return true; // Sửa đổi: Trả về true nếu là chính danh mục sản phẩm } // Bắt đầu truy ngược lên cây danh mục từ mục hiện tại $parentId = $currentItem['menus_parentid'] ?? 0; // Lặp cho đến khi lên đến cấp gốc (parentid = 0) while ($parentId != 0) { // Nếu tìm thấy ID của danh mục "Sản phẩm" trong chuỗi cha if ($parentId == $product_root_id) { return true; } // Tìm mục cha trong mảng $all_categories $parentItem = null; foreach ($all_categories as $category) { if (isset($category['menus_id']) && $category['menus_id'] == $parentId) { $parentItem = $category; break; } } // Nếu không tìm thấy mục cha (có thể do dữ liệu không nhất quán) if ($parentItem === null) { return false; } // Di chuyển lên cấp cha tiếp theo $parentId = $parentItem['menus_parentid'] ?? 0; } // Nếu đã duyệt hết lên cấp gốc mà không tìm thấy $product_root_id return false; } function render_product_sidebar_categories($all_categories, $parent_id_to_start_from, $level = 0, $current_active_slug = '') { $html_output = ''; $direct_children = []; // 1. Kiểm tra đầu vào cơ bản if (empty($all_categories) || !is_array($all_categories)) { return ''; // Không có dữ liệu hoặc dữ liệu không hợp lệ } // 2. Tìm các con trực tiếp của $parent_id_to_start_from foreach ($all_categories as $category_item) { // Đảm bảo các key cần thiết tồn tại trong $category_item if (isset($category_item['menus_parentid'], $category_item['menus_id'], $category_item['menus_name'])) { if ($category_item['menus_parentid'] == $parent_id_to_start_from) { $direct_children[] = $category_item; } } } // 3. Sắp xếp các con theo 'menus_pos' nếu có if (!empty($direct_children)) { // Kiểm tra xem 'menus_pos' có tồn tại ở ít nhất một phần tử con không để tránh lỗi $has_pos_key = false; if (isset($direct_children[0]['menus_pos'])) { $has_pos_key = true; } if ($has_pos_key) { usort($direct_children, function($a, $b) { $posA = isset($a['menus_pos']) ? floatval($a['menus_pos']) : PHP_INT_MAX; $posB = isset($b['menus_pos']) ? floatval($b['menus_pos']) : PHP_INT_MAX; if ($posA == $posB) { return 0; } return ($posA < $posB) ? -1 : 1; }); } } if (!empty($direct_children)) { $ul_class = ($level > 0) ? ' class="sub-menu"' : ''; $html_output .= "<ul{$ul_class}>"; foreach ($direct_children as $item) { $item_id = $item['menus_id']; $item_name = $item['menus_name']; $item_fname = $item['menus_fname'] ?? ''; // Slug của mục $item_url = $item['menus_url'] ?? ''; // URL trực tiếp nếu có $item_has_children = false; foreach ($all_categories as $potential_child) { if (isset($potential_child['menus_parentid']) && $potential_child['menus_parentid'] == $item_id) { $item_has_children = true; break; } } $li_classes = []; if ($item_has_children) { $li_classes[] = 'menu-item-has-children'; } if (!empty($current_active_slug) && $item_fname == $current_active_slug) { $li_classes[] = 'active'; } $li_class_attribute = !empty($li_classes) ? ' class="' . implode(' ', $li_classes) . '"' : ''; // Tạo URL $link_href = '#'; // Mặc định if (!empty($item_url)) { // Ưu tiên URL được cung cấp sẵn $link_href = $item_url; } elseif (!empty($item_fname)) { // Giả sử $GLOBALS['INFO']['home_url'] tồn tại và đúng // Bạn CẦN ĐIỀU CHỈNH logic này cho phù hợp với cấu trúc URL của bạn $base_url = rtrim($GLOBALS['INFO']['home_url'] ?? '', '/'); if ($item_fname == 'trang-chu' && $base_url != '') { // Trường hợp đặc biệt cho trang chủ $link_href = $base_url . '/'; } else { // Ví dụ: http://domain.com/danh-muc-slug/ $link_href = $base_url . '/' . trim($item_fname, '/') . '/'; } // Dọn dẹp dấu // thừa, nhưng giữ lại http:// $link_href = preg_replace('~(?<!:)/{2,}~', '/', $link_href); } $html_output .= "<li{$li_class_attribute}>"; $html_output .= '<a href="' . htmlspecialchars($link_href) . '">' . htmlspecialchars($item_name) . '</a>'; if ($item_has_children) { // Gọi đệ quy để render các cấp con tiếp theo $html_output .= render_product_sidebar_categories($all_categories, $item_id, $level + 1, $current_active_slug); } $html_output .= '</li>'; } $html_output .= '</ul>'; } return $html_output; } function breadcrumb($DB,$menu_id,$arr=array(),$class='breadcrumb-item'){ $row_check_menu = $DB->fetch_row($DB->query("SELECT * FROM `tb_menus` WHERE `menus_id` = '$menu_id' LIMIT 1")); if($row_check_menu['menus_parentid']==0){ $arr[] = array('title'=>$row_check_menu['menus_name'],'breadcrumb'=>'<li class="'.$class.'"><a href="/'.$row_check_menu['menus_fname'].'/">'.$row_check_menu['menus_name'].'</a></li>'); }else{ $arr[] = array('title'=>$row_check_menu['menus_name'],'breadcrumb'=>'<li class="'.$class.'"><a href="'.$row_check_menu['menus_fname'].'/">'.$row_check_menu['menus_name'].'</a></li>'); return breadcrumb($DB,$row_check_menu['menus_parentid'],$arr,$class); } if(isset($arr)){ return $arr; } return []; } $arr_br = breadcrumb($DB,$menu_id,[],$class='bd-items'); $arr_bread = array_reverse($arr_br,true); $CORE->title_page = ''; foreach ($arr_bread as $val) { $CORE->title_page .= $val['title'].' | '; } //$CORE->title_page = $func->remove_lastchar($CORE->title_page,3); include 'layout/'.$INFO['path_skin'].'/header.php'; include 'layout/'.$INFO['path_skin'].'/menu.php'; ?> <?php switch ($row_check_menu['menus_type']){ default: $is_productcat = isDescendantOfProductCategory($categories_data, $current_category_slug, $idChaChoSanPham); //echo $row_check_menu['menus_id'].','.$idChaChoSanPham; if($is_productcat===true){ include 'list_san_pham_tpl.php'; }else { include 'list_tpl.php'; } break; case 'page': include 'page_tpl.php'; break; } ?> <?php include 'layout/'.$INFO['path_skin'].'/footer.php'; ?>