Skip to content

Commit

Permalink
Introduce Navigation Bar Modularisation
Browse files Browse the repository at this point in the history
This will consist of the Navbar Content Module, and a bunch of Sub Modules
  • Loading branch information
gburton committed Feb 22, 2016
1 parent aff8539 commit af86f42
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 132 deletions.
@@ -0,0 +1,13 @@
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2016 osCommerce
Released under the GNU General Public License
*/

define('MODULE_CFG_MODULE_CONTENT_NAVBAR_TITLE', 'Navbar Modules');
25 changes: 25 additions & 0 deletions admin/includes/modules/cfg_modules/cfgm_navbar_modules.php
@@ -0,0 +1,25 @@
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2016 osCommerce
Released under the GNU General Public License
*/

class cfgm_navbar_modules {
var $code = 'navbar_modules';
var $directory;
var $language_directory = DIR_FS_CATALOG_LANGUAGES;
var $key = 'MODULE_CONTENT_NAVBAR_INSTALLED';
var $title;
var $template_integration = false;

function cfgm_navbar_modules() {
$this->directory = DIR_FS_CATALOG_MODULES . 'navbar_modules/';
$this->title = MODULE_CFG_MODULE_CONTENT_NAVBAR_TITLE;
}
}
Expand Up @@ -5,36 +5,11 @@
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Copyright (c) 2016 osCommerce
Released under the GNU General Public License
*/

define('MODULE_CONTENT_NAVBAR_TITLE', 'Navigation Bar');
define('MODULE_CONTENT_NAVBAR_DESCRIPTION', 'Show the Navigation Bar on your site.');

//header titles
define('HEADER_CART_CONTENTS', '<i class="fa fa-shopping-cart"></i> %s item(s) <span class="caret"></span>');
define('HEADER_CART_NO_CONTENTS', '<i class="fa fa-shopping-cart"></i> 0 items');
define('HEADER_ACCOUNT_LOGGED_OUT', '<i class="fa fa-user"></i><span class="hidden-sm"> My Account</span> <span class="caret"></span>');
define('HEADER_ACCOUNT_LOGGED_IN', '<i class="fa fa-user"></i> %s <span class="caret"></span>');
define('HEADER_SITE_SETTINGS', '<i class="fa fa-cog"></i><span class="hidden-sm"> Site Settings</span> <span class="caret"></span>');
define('HEADER_TOGGLE_NAV', 'Toggle Navigation');
define('HEADER_HOME', '<i class="fa fa-home"></i><span class="hidden-sm"> Home</span>');
define('HEADER_WHATS_NEW', '<i class="fa fa-certificate"></i><span class="hidden-sm"> New Products</span>');
define('HEADER_SPECIALS', '<i class="fa fa-fire"></i><span class="hidden-sm"> Special Offers</span>');
define('HEADER_REVIEWS', '<i class="fa fa-comment"></i><span class="hidden-sm"> Reviews</span>');
// header dropdowns
define('HEADER_ACCOUNT_LOGIN', '<i class="fa fa-sign-in"></i> Log In');
define('HEADER_ACCOUNT_LOGOFF', '<i class="fa fa-sign-out"></i> Log Off');
define('HEADER_ACCOUNT', 'My Account');
define('HEADER_ACCOUNT_HISTORY', 'My Orders');
define('HEADER_ACCOUNT_EDIT', 'My Details');
define('HEADER_ACCOUNT_ADDRESS_BOOK', 'My Address Book');
define('HEADER_ACCOUNT_PASSWORD', 'My Password');
define('HEADER_ACCOUNT_REGISTER', '<i class="fa fa-pencil"></i> Register');
define('HEADER_CART_HAS_CONTENTS', '%s item(s), %s');
define('HEADER_CART_VIEW_CART', 'View Cart');
define('HEADER_CART_CHECKOUT', '<i class="fa fa-angle-right"></i> Checkout');
define('USER_LOCALIZATION', '<abbr title="Selected Language">L:</abbr> %s <abbr title="Selected Currency">C:</abbr> %s');

define('MODULE_CONTENT_NAVBAR_DESCRIPTION', 'Show the Navigation Bar on your site. <div class="secWarning">This module has a number of Sub Modules which must also be installed.<br><br>Admin > Modules > Navbar Modules</div>');

43 changes: 32 additions & 11 deletions includes/modules/content/navigation/cm_navbar.php
Expand Up @@ -5,7 +5,7 @@
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Copyright (c) 2016 osCommerce
Released under the GNU General Public License
*/
Expand All @@ -32,14 +32,36 @@ function cm_navbar() {
}

function execute() {
global $PHP_SELF, $cart, $lng, $language, $currencies, $HTTP_GET_VARS, $request_type, $currency, $oscTemplate;
global $customer_first_name;
global $language, $oscTemplate;

if ( defined('MODULE_CONTENT_NAVBAR_INSTALLED') && tep_not_null(MODULE_CONTENT_NAVBAR_INSTALLED) ) {
$nav_array = explode(';', MODULE_CONTENT_NAVBAR_INSTALLED);

ob_start();
include(DIR_WS_MODULES . 'content/' . $this->group . '/templates/navbar.php');
$template = ob_get_clean();
$navbar_modules = array();

$oscTemplate->addContent($template, $this->group);
foreach ( $nav_array as $nbm ) {
$class = substr($nbm, 0, strrpos($nbm, '.'));

if ( !class_exists($class) ) {
include(DIR_WS_LANGUAGES . $language . '/modules/navbar_modules/' . $nbm);
require(DIR_WS_MODULES . 'navbar_modules/' . $class . '.php');
}

$nav = new $class();

if ( $nav->isEnabled() ) {
$navbar_modules[] = $nav->getOutput();
}
}

if ( !empty($navbar_modules) ) {
ob_start();
include(DIR_WS_MODULES . 'content/' . $this->group . '/templates/navbar.php');
$template = ob_get_clean();

$oscTemplate->addContent($template, $this->group);
}
}
}

function isEnabled() {
Expand All @@ -51,16 +73,15 @@ function check() {
}

function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Navbar Module', 'MODULE_CONTENT_NAVBAR_STATUS', 'True', 'Should the Navbar be shown? ', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_NAVBAR_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Navbar Module', 'MODULE_CONTENT_NAVBAR_STATUS', 'True', 'Should the Navbar be shown? ', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
tep_db_query("insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_CONTENT_NAVBAR_SORT_ORDER', '10', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
}

function remove() {
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
tep_db_query("delete from configuration where configuration_key in ('" . implode("', '", $this->keys()) . "')");
}

function keys() {
return array('MODULE_CONTENT_NAVBAR_STATUS', 'MODULE_CONTENT_NAVBAR_SORT_ORDER');
}
}

112 changes: 19 additions & 93 deletions includes/modules/content/navigation/templates/navbar.php
@@ -1,99 +1,25 @@
<nav class="navbar navbar-inverse navbar-no-corners navbar-no-margin" role="navigation">
<div class="<?php echo BOOTSTRAP_CONTAINER; ?>">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-navbar-collapse-core-nav">
<span class="sr-only"><?php echo HEADER_TOGGLE_NAV; ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<?php
if ($oscTemplate->hasBlocks('navbar_modules_home')) {
echo '<div class="navbar-header">' . PHP_EOL;
echo $oscTemplate->getBlocks('navbar_modules_home');
echo '</div>' . PHP_EOL;
}
?>
<div class="collapse navbar-collapse" id="bs-navbar-collapse-core-nav">
<ul class="nav navbar-nav">
<?php echo '<li><a class="store-brand" href="' . tep_href_link(FILENAME_DEFAULT) . '">' . HEADER_HOME . '</a></li>'; ?>
<?php echo '<li><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW) . '">' . HEADER_WHATS_NEW . '</a></li>'; ?>
<?php echo '<li><a href="' . tep_href_link(FILENAME_SPECIALS) . '">' . HEADER_SPECIALS . '</a></li>'; ?>
<?php echo '<li><a href="' . tep_href_link(FILENAME_REVIEWS) . '">' . HEADER_REVIEWS . '</a></li>'; ?>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php
if (substr(basename($PHP_SELF), 0, 8) != 'checkout') {
?>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo HEADER_SITE_SETTINGS; ?></a>
<ul class="dropdown-menu">
<li class="text-center text-muted bg-primary"><?php echo sprintf(USER_LOCALIZATION, ucwords($language), $currency); ?></li>
<?php
// languages
if (!isset($lng) || (isset($lng) && !is_object($lng))) {
include(DIR_WS_CLASSES . 'language.php');
$lng = new language;
}
if (count($lng->catalog_languages) > 1) {
echo '<li class="divider"></li>';
reset($lng->catalog_languages);
while (list($key, $value) = each($lng->catalog_languages)) {
echo '<li><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language', 'currency')) . 'language=' . $key, $request_type) . '">' . tep_image(DIR_WS_LANGUAGES . $value['directory'] . '/images/' . $value['image'], $value['name'], null, null, null, false) . ' ' . $value['name'] . '</a></li>';
}
}
// currencies
if (isset($currencies) && is_object($currencies) && (count($currencies->currencies) > 1)) {
echo '<li class="divider"></li>';
reset($currencies->currencies);
$currencies_array = array();
while (list($key, $value) = each($currencies->currencies)) {
$currencies_array[] = array('id' => $key, 'text' => $value['title']);
echo '<li><a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('language', 'currency')) . 'currency=' . $key, $request_type) . '">' . $value['title'] . '</a></li>';
}
}
?>
</ul>
</li>
<?php
}
?>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo (tep_session_is_registered('customer_id')) ? sprintf(HEADER_ACCOUNT_LOGGED_IN, $customer_first_name) : HEADER_ACCOUNT_LOGGED_OUT; ?></a>
<ul class="dropdown-menu">
<?php
if (tep_session_is_registered('customer_id')) {
echo '<li><a href="' . tep_href_link(FILENAME_LOGOFF, '', 'SSL') . '">' . HEADER_ACCOUNT_LOGOFF . '</a>';
}
else {
echo '<li><a href="' . tep_href_link(FILENAME_LOGIN, '', 'SSL') . '">' . HEADER_ACCOUNT_LOGIN . '</a>';
echo '<li><a href="' . tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL') . '">' . HEADER_ACCOUNT_REGISTER . '</a>';
}
?>
<li class="divider"></li>
<li><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT, '', 'SSL') . '">' . HEADER_ACCOUNT . '</a>'; ?></li>
<li><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY, '', 'SSL') . '">' . HEADER_ACCOUNT_HISTORY . '</a>'; ?></li>
<li><?php echo '<a href="' . tep_href_link(FILENAME_ADDRESS_BOOK, '', 'SSL') . '">' . HEADER_ACCOUNT_ADDRESS_BOOK . '</a>'; ?></li>
<li><?php echo '<a href="' . tep_href_link(FILENAME_ACCOUNT_PASSWORD, '', 'SSL') . '">' . HEADER_ACCOUNT_PASSWORD . '</a>'; ?></li>
</ul>
</li>
<?php
if ($cart->count_contents() > 0) {
?>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo sprintf(HEADER_CART_CONTENTS, $cart->count_contents()); ?></a>
<ul class="dropdown-menu">
<li><?php echo '<a href="' . tep_href_link(FILENAME_SHOPPING_CART) . '">' . sprintf(HEADER_CART_HAS_CONTENTS, $cart->count_contents(), $currencies->format($cart->show_total())) . '</a>'; ?></li>
<?php
if ($cart->count_contents() > 0) {
echo '<li class="divider"></li>';
echo '<li><a href="' . tep_href_link(FILENAME_SHOPPING_CART) . '">' . HEADER_CART_VIEW_CART . '</a></li>';
}
?>
</ul>
</li>
<?php
echo '<li><a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . HEADER_CART_CHECKOUT . '</a></li>';
}
else {
echo '<li class="nav navbar-text">' . HEADER_CART_NO_CONTENTS . '</li>';
}
?>
</ul>
<?php
if ($oscTemplate->hasBlocks('navbar_modules_left')) {
echo '<ul class="nav navbar-nav">' . PHP_EOL;
echo $oscTemplate->getBlocks('navbar_modules_left');
echo '</ul>' . PHP_EOL;
}
if ($oscTemplate->hasBlocks('navbar_modules_right')) {
echo '<ul class="nav navbar-nav navbar-right">' . PHP_EOL;
echo $oscTemplate->getBlocks('navbar_modules_right');
echo '</ul>' . PHP_EOL;
}
?>
</div>
</div>
</nav>

16 comments on commit af86f42

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is the start of sub modularisation for the Navigation Bar.

This will allow easy "editing" of the Navigation Bar, but the flip-side of that is it makes it much harder to add in new items (as they have to be a module rather than a simple change to the main template file).

@katapofatico
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the kymation addon "Modular Navigation Bar (Bootstrap)" and my opinion was that I prefer the simplest way: because that flip-side. But maybe because I don't need it: maybe other stores need modular control. Harder from easy coding but coherent with modularized design store.
Welcome anyway :)

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know there was an addon for it 🔮
Would have saved me some time and effort.

Off to test it now...

@katapofatico
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I'm glad I mentioned that! :D

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @katapofatico thanks for the heads-up

@katapofatico
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, tested kymations addon - and it does exactly what I had plans for in this branch.
Allows the shopowner to turn off/on navbar items, swap them around and so on.

My idea is pretty much the same.
I believe it can be done a little bit cleaner than the Addon, so I will carry on and see where it goes.

Thanks for the heads-up @katapofatico - appreciated much.

@Kymation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm conflicted. I'd like to keep compatiblility for the modules, as keeping two differnt versions of each one would be a pain. (There are already four additional modules for my addon that are not in the stock collection.)

On the other hand, I'd really like to see how you would simplify this. I could stand to learn how to do that.

And if you'd like to save some more time, the front page modules have also been done and are available as an addon.

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kymation the basis of my thought is to use a similar approach as is done at the "social bookmarks" module. This has an extra page in admin for add/edit/delete the submodules (which make up the main module). It's basically the same as you have done...just a little bit cleaner. Keep an eye on this Branch - as you have already done some work in this area I woud be grateful for any pointers if I run into problems. Thanks.

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's done so far, bear in mind untested !

Addition of new cfgm module to add the link into the modules sidebox in admin.
Update the main navbar content module to pull in submodules.
Update the main navbar template file to pull in getBlocks

which leaves:

make a bunch of submodules that plug into the oscTemplate->getblocks

I'll make 1 or 2 today/tomorrow...for testing...

@Kymation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what I did: I copied the approach used in the Social Bookmarks module. No cfgm module needed. Compare the structure and you'll see what I did.

bm_product_social_bookmarks.php => cm_modular_navbar.php
social_bookmarks/{any module file} => content/navbar/{any module file}

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've committed a couple of sub modules.
Feel free to test - any feedback would be appreciated.

@Kymation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, Github is being mean to me. Where are the submodules?

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40db14b
1d22fe2
should do it

@Kymation
Copy link

@Kymation Kymation commented on af86f42 Feb 22, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gburton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All commits now completed, this should take the Navbar fully modular; https://github.com/gburton/Responsive-osCommerce/commits/ModNav

Please sign in to comment.