Compare commits

..

15 Commits

5 changed files with 122 additions and 9 deletions

View File

@ -33,6 +33,15 @@ chown -R www-data:www-data ./
## Arc-hive theme notes ## Arc-hive theme notes
### Configure
The main menu can be retrieved from a wordpress site and rendered. To configure this, edit `view/common/wordpress-menu.phtml`. Optional.
```
# Config
$wordpress_site="https://my.wordpress.site";
$wordpress_endpoint="https://my.wordpress.site/wp-json/menus/v1/menus/4";
```
For more advanced use, such as customizing the theme with Sass, you'll need to install the tools with [NodeJS](https://nodejs.org/en/) (0.12 or greater). Navigate to your theme directory and run `npm install`. For more advanced use, such as customizing the theme with Sass, you'll need to install the tools with [NodeJS](https://nodejs.org/en/) (0.12 or greater). Navigate to your theme directory and run `npm install`.

1
asset/js/app.js.map Normal file

File diff suppressed because one or more lines are too long

View File

@ -18,12 +18,13 @@
</main> </main>
<nav> <nav>
<menu class=""> <menu class="">
<?php /*
<?php
echo $site->publicNav() echo $site->publicNav()
->menu() ->menu()
->setPartial('common/foundation-navigation.phtml') ->setPartial('common/wordpress-menu.phtml')
->renderPartialWithParams(['layout' => 'dropdown']); ->renderPartialWithParams(['layout' => 'dropdown']);
*/
?> ?>
</menu> </menu>
</nav> </nav>

View File

@ -42,12 +42,10 @@ $img_src = null;
<nav> <nav>
<menu class=""> <menu class="">
<?php // <?php //
// Segun el diseño, este menu no existe echo $site->publicNav()
// ---------- ->menu()
// echo $site->publicNav() ->setPartial('common/wordpress-menu.phtml')
// ->menu() ->renderPartialWithParams(['layout' => 'dropdown']);
// ->setPartial('common/foundation-navigation.phtml')
// ->renderPartialWithParams(['layout' => 'dropdown']);
?> ?>
</menu> </menu>
</nav> </nav>

View File

@ -0,0 +1,104 @@
<?php
# Config
$wordpress_site="https://dev.arc-hive.zone";
$wordpress_endpoint="https://dev.arc-hive.zone/wp-json/menus/v1/menus/4";
use Zend\Http\Client;
$items = new ArrayObject;
$items[0] = new ArrayObject(); // top level menu items go here
if ($wordpress_endpoint) {
try {
$client = new Client($wordpress_endpoint);
$client->setOptions(array("timeout"=>1));
$response = $client->send();
}
catch (exception $e) {
$response = null;
}
if ($response) {
$response_data = json_decode($response->getBody());
if (!$response->isClientError() && $response_data) {
foreach ($response_data as $menu_item) {
$lowered_title = strtolower($menu_item->title);
$item_url = $menu_item->url;
if ($lowered_title == 'login') {
// manipulate login url
$item_url = "/login";
}
$item_title = $menu_item->title;
if ($lowered_title == 'collections') {
if ($wordpress_site) {
// change Collections item
$item_title = "Project";
$item_url = $wordpress_site;
} else {
continue; // do not render the Collections item
}
}
$item = [
"id" => $menu_item->ID,
"title" => $item_title,
"url" => $item_url
];
if (!isset($items[$menu_item->menu_item_parent])) {
//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;
}
}
}
}
if (count($items[0]) == 0) {
// we did not retrieve a menu from the wordpress site
// let's create a default menu
if ($wordpress_site) {
$project_item = [
"id" => 1,
"title" => "Project",
"url" => $wordpress_site
];
$items[0][1] = $project_item;
}
$login_item = [
"id" => 2,
"title" => "Login",
"url" => "/login"
];
$items[0][2] = $login_item;
}
//print_r($items);
if (!function_exists('render_menu')) {
function render_menu($items, $level_id) {
if ($level_id == 0) {
echo '<ul id="" class="dropdown menu" data-dropdown-menu="dropdown-menu" role="menubar">'.
PHP_EOL;
} else {
echo '<ul class="dropdown menu vertical submenu is-dropdown-submenu first-sub" data-toggle="" data-submenu="" role="">'.
PHP_EOL;
}
foreach ($items[$level_id] as $menu_item) {
if ($level_id == 0) {
echo '<li id="" class="" role="">'.PHP_EOL;
} else {
echo '<li id="" class="is-submenu-item is-dropdown-submenu-item" role="">'.PHP_EOL;
}
echo '<a role="" href="'.$menu_item['url'].'">'.$menu_item['title'].'</a>'.PHP_EOL;
if (isset($items[$menu_item['id']])) {
//if (array_key_exists($menu_item['id'], $items)) {
render_menu($items, $menu_item['id']); // render sub menu
}
echo '</li>' . PHP_EOL;
}
echo '</ul>' . PHP_EOL;
}
}
render_menu($items, 0);
?>