2022-03-24 22:42:29 +01:00
|
|
|
<?php
|
|
|
|
|
2022-03-25 10:58:33 +01:00
|
|
|
# Config
|
|
|
|
$wordpress_site="https://dev.arc-hive.zone";
|
|
|
|
$wordpress_endpoint="https://dev.arc-hive.zone/wp-json/menus/v1/menus/4";
|
|
|
|
|
2022-03-24 22:42:29 +01:00
|
|
|
use Zend\Http\Client;
|
|
|
|
|
2022-03-25 10:20:12 +01:00
|
|
|
$items = new ArrayObject;
|
2022-03-25 10:58:33 +01:00
|
|
|
$items[0] = new ArrayObject(); // top level menu items go here
|
2022-03-24 22:42:29 +01:00
|
|
|
|
2022-03-25 10:58:33 +01:00
|
|
|
if ($wordpress_endpoint) {
|
|
|
|
$client = new Client($wordpress_endpoint);
|
|
|
|
$client->setOptions(array("timeout"=>1));
|
|
|
|
$response = $client->send();
|
|
|
|
$response_data = json_decode($response->getBody());
|
|
|
|
|
|
|
|
if (!$response->isClientError() && $response_data) {
|
|
|
|
foreach ($response_data as $menu_item) {
|
|
|
|
$item_url = $menu_item->url;
|
|
|
|
if (strtolower($menu_item->title) == 'login') {
|
|
|
|
$item_url = "/login";
|
|
|
|
}
|
|
|
|
$item_title = $menu_item->title;
|
|
|
|
if (strtolower($menu_item->title) == 'collections') {
|
|
|
|
$item_title = "Project";
|
|
|
|
$item_url = $wordpress_site;
|
|
|
|
}
|
|
|
|
$item = [
|
|
|
|
"id" => $menu_item->ID,
|
|
|
|
"title" => $item_title,
|
|
|
|
"url" => $item_url
|
|
|
|
];
|
|
|
|
if (!array_key_exists($menu_item->menu_item_parent, $items)) {
|
|
|
|
$items[$menu_item->menu_item_parent] = new ArrayObject();
|
|
|
|
}
|
|
|
|
$items[$menu_item->menu_item_parent][$menu_item->ID] =$item;
|
2022-03-25 10:20:12 +01:00
|
|
|
}
|
2022-03-24 22:42:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//print_r($items);
|
|
|
|
|
2022-03-25 10:58:33 +01:00
|
|
|
function render_menu($items, $level_id) {
|
|
|
|
echo '<ul>' . PHP_EOL;
|
|
|
|
foreach ($items[$level_id] as $menu_item) {
|
|
|
|
echo '<li>' . PHP_EOL;
|
|
|
|
echo '<a href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>' . PHP_EOL;
|
|
|
|
if (array_key_exists($menu_item['id'], $items)) {
|
|
|
|
render_menu($items, $menu_item['id']); // render sub menu
|
2022-03-24 22:42:29 +01:00
|
|
|
}
|
2022-03-25 10:58:33 +01:00
|
|
|
echo '</li>' . PHP_EOL;
|
2022-03-24 22:42:29 +01:00
|
|
|
}
|
2022-03-25 10:58:33 +01:00
|
|
|
echo '</ul>' . PHP_EOL;
|
2022-03-24 22:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render_menu($items, 0);
|
|
|
|
|
|
|
|
?>
|