PHP Menu Grab and Convert (Mgac) is a small library that makes it easy to clone, convert, and render another site's navigation menu. Uses sunra/php-simple-html-dom-parser/, an adaptation of the PHP Simple HTML DOM Parser.
This project was born as a quick, simple solution to replicate a navigation menu on a top-level domain to a set of static pages underneath, each of which may be in a different style or front-end framework yet need to contain the same menu items and hyperlinks.
Please be free to utilize the suggestion box or read the documentation.
composer.phar
{
"repositories": [
{
"url": "https://github.com/chrisvogt/php-menu-grab-and-convert.git",
"type": "git"
}
],
"require": {
"chrisvogt/php-menu-grab-and-convert": "*"
}
}
use \MenuGrabAndConvert;
require_once __DIR__ . '/vendor/autoload.php';
$target = array( // Required
'url' => 'http://sandbox-php.dev/demo/',
'element' => 'ul[id=topnav]'
);
$options = array( // Optional, for Bootstrap conversion
'validateBaseUrl' => true,
'convertToBootstrap' => true,
'selectors' => array(
'top-nav' => 'ul[id=topnav]',
'li-with-child' => 'li.menu-item-has-children',
'submenu-ul' => 'ul.sub-menu'
)
);
$config = new \MenuGrabAndConvert\Configuration($target, $options);
$mgac = new \MenuGrabAndConvert\Mgac($config);