Jump to content

How do you change the breadcrumbs or sidebar code?


yggdrasil

Recommended Posts

I need to make some minor HTML adjustments in the breadcrumb and sidebars, like colors or icons, this was in the v5 code and now its gone.

 

Is it encoded now? I cannot seem to find the code in v7 anymore. Its gone !

 

EDIT: You can't anymore. Its encoded ! You can't change theme/template files anymore. The code was removed from the theme and now its closed source.

Edited by yggdrasil
Link to comment
Share on other sites

- Remove or change the link for a specific option

- Change the font awesome icon

- Add before or after a link or text HTML entities

- Pass language or smarty variables in the text or link

 

Just 3 examples, but probably others. I just need access to the code just like you have in template files. I know you are going to probably tell me to pass this with hooks but this is very stupid if I need to do this for all links, I would need to pass a lot of hooks, and I'm sure HTML or PHP code can't be send with hooks. (and add for breadcrumb the same again...)

Link to comment
Share on other sites

I just need access to the code just like you have in template files. I know you are going to probably tell me to pass this with hooks but this is very stupid if I need to do this for all links, I would need to pass a lot of hooks, and I'm sure HTML or PHP code can't be send with hooks.

there's a lot to ground to cover here, but i'll start by saying that hooks are the most flexible way to do this - not least, because once written, you won't need to re-add the code each time you update WHMCS... and also because there are loads of examples in the forum of nav/sidebar hooks written by myself and sentq - probably whatever you want to do has been posted previously (or is a variation of something already posted)... the downside to hooks is get them wrong, and you can blank out the client area - or sometimes even the admin area!

 

now, having said all that, what you are really asking is: can I make these example changes in the templates? to which the answer is YES! - the coding could get tricky down the road, but if you really want to, it's an option (at least for most things).

 

personally, my first thought would be to change something using a hook, but if I think a hook solution is going to take a while to code/test, then as my father would say, "Sod this for a game of soldiers!" and i'd fix it in the template! :idea:

 

so as best I can, i'm going to work though your brief example list and show you how to do them using hooks and/or template tweaks...

 

- Remove or change the link for a specific option

if I start with removing a navbar child - and I appreciate your questions are really about sidebars, and i'll get to them, but the hook principles are the same whether you're talking about navbars, sidebars or even the homepage panels.

 

so, let's remove the "Home" button from the navbar - as a hook, it would be...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Home'))) {
           $primaryNavbar->removeChild('Home');
   }
});

if you want to do it in the template, then you would simply add a bit of Smarty (if statement) to the includes/navbar.tpl template...

 

{foreach $navbar as $item}
   {if $item->getName() neq 'Home'}
   <li menuItemName="{$item->getName()}"{if $item->hasChildren()} class="dropdown"{elseif $item->getClass()} class="{$item->getClass()}"{/if} id="{$item->getId()}">
       <a {if $item->hasChildren()}class="dropdown-toggle" data-toggle="dropdown" href="#"{else}href="{$item->getUri()}"{/if}{if $item->getAttribute('target')} target="{$item->getAttribute('target')}"{/if}>
           {if $item->hasIcon()}<i class="{$item->getIcon()}"></i> {/if}
           {$item->getLabel()}
           {if $item->hasBadge()} <span class="badge">{$item->getBadge()}</span>{/if}
           {if $item->hasChildren()} <b class="caret"></b>{/if}
       </a>
       {if $item->hasChildren()}
           <ul class="dropdown-menu">
           {foreach $item->getChildren() as $childItem}
               <li menuItemName="{$childItem->getName()}"{if $childItem->getClass()} class="{$childItem->getClass()}"{/if} id="{$childItem->getId()}">
                   <a href="{$childItem->getUri()}"{if $childItem->getAttribute('target')} target="{$childItem->getAttribute('target')}"{/if}>
                       {if $childItem->hasIcon()}<i class="{$childItem->getIcon()}"></i> {/if}
                       {$childItem->getLabel()}
                       {if $childItem->hasBadge()} <span class="badge">{$childItem->getBadge()}</span>{/if}
                   </a>
               </li>
           {/foreach}
           </ul>
       {/if}
   </li>
   {/if}
{/foreach}

next, let's change the link of the "Home" button on the navbar from index.php to Google - firstly as a hook...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar)
{
   if (!is_null($primaryNavbar->getChild('Home'))) {
           $primaryNavbar->getChild('Home')
                       ->setURI('http://www.google.com');
   }
});

... or as a template tweak, you would change line 3 of navbar.tpl from...

 

        <a {if $item->hasChildren()}class="dropdown-toggle" data-toggle="dropdown" href="#"{else}href="{$item->getUri()}"{/if}{if $item->getAttribute('target')} target="{$item->getAttribute('target')}"{/if}>

to...

        <a {if $item->hasChildren()}class="dropdown-toggle" data-toggle="dropdown" href="#"{else}href="{if $item->getName() eq 'Home'}http://www.google.com{else}{$item->getUri()}{/if}"{/if}{if $item->getAttribute('target')} target="{$item->getAttribute('target')}"{/if}>

technically, you might run into an issue if you have a child with the same name in both primary and secondary navbars (or sidebars), but I don't think that will occur by default, you'd likely have to engineer the problem to see it! if it ever occurred, it could be easily coded around, but i'm trying to keep the coding simple in these examples. :)

 

now, your question was really about sidebars, and I assume changing links of a specific child in a sidebar... so let's take the support sidebar shown in the Knowledgebase page...

 

Ya6YqxN.png

 

again, i'm going to change the link of the 'Knowledgebase' child to Google - you could change it to another page of your site or whatever you like... so as a hook, it would be...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (!is_null($secondarySidebar->getChild('Support'))) {
            $secondarySidebar->getChild('Support')
                           ->getChild('Knowledgebase')
                           ->setURI('http://www.google.com');             
   }         
});

or as a template tweak to six/includes/sidebar.tpl ~ line19...

 

                        <a menuItemName="{$childItem->getName()}" href="{if $childItem->getName() eq 'Knowledgebase'}http://www.google.com{else}{$childItem->getUri()}{/if}" class="list-group-item{if $childItem->isDisabled()} disabled{/if}{if $childItem->getClass()} {$childItem->getClass()}{/if}{if $childItem->isCurrent()} active{/if}"{if $childItem->getAttribute('dataToggleTab')} data-toggle="tab"{/if}{if $childItem->getAttribute('target')} target="{$childItem->getAttribute('target')}"{/if} id="{$childItem->getId()}">

in these template examples, i'm just changing one link... but if you were changing a lot of sidebar links, then you just follow the standard {if} {elseif} and {else} method of checking your conditions.

 

- Change the font awesome icon

for continuity, i'll stick with using the Knowledgebase child, and now we'll change it's icon to a book as a hook...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (!is_null($secondarySidebar->getChild('Support'))) {
            $secondarySidebar->getChild('Support')
                           ->getChild('Knowledgebase')
                           ->setIcon('fa-book fa-fw');          
   }         
});

or as a tweak to sidebar.tpl ~ line21...

 

                            {if $childItem->hasIcon()}<i class="{if $childItem->getName() eq 'Knowledgebase'}fa fa-book fa-fw{else}{$childItem->getIcon()}{/if}"></i> {/if}

fI5gse9.png

 

- Add before or after a link or text HTML entities

as a hook...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $secondarySidebar)
{
   if (!is_null($secondarySidebar->getChild('Support'))) {
            $secondarySidebar->getChild('Support')
                           ->getChild('Knowledgebase')
                           ->setLabel('<b><u>Brian</u></b>');             
   }         
});

and as a sidebar tweak in sidebar.tpl ~ line 22...

 

                            {if $childItem->getName() eq 'Knowledgebase'}<b><u>Brian</u></b>{else}{$childItem->getLabel()}{/if}

Lkf5WfN.png

 

- Pass language or smarty variables in the text or link

let's assume the client is logged in and then we'd have access to the $clientsdetails array - in the sidebar template, you could do this to show their firstname in the child label...

 

                            {if $childItem->getName() eq 'Knowledgebase'}Hello {$clientsdetails.firstname}{else}{$childItem->getLabel()}{/if}

SOsC9RZ.png

 

and similarly, you could use a language string in the same way as in any other template... in a hook, you'd use the Lang::trans method.

 

(and add for breadcrumb the same again...)

https://forum.whmcs.com/showthread.php?114986-Changing-Breadcrumbs-display-EVERY-step-of-the-Navigation

https://forum.whmcs.com/showthread.php?124946-template-THEMENAME-includes-pageheader-tpl-and-FA

 

in summary, if you want to edit navbars/sidebars in the templates...

 

to edit navbars, you can edit six (or your custom)/includes/navbar.tpl

to edit sidebar, you can edit six (or your custom)/includes/sidebar.tpl

 

I would imagine if you're previously experienced in modifying the old templates, then the principles will be the same in the new templates - you might just have to tweak the precise code to achieve the same outcomes.

 

there's no need to create a new hook file each time you want to change some minor thing - perhaps just have one hook file for navbars and put all your navbar changes in there, a similar one for sidebars etc... and as can be seen above in the very basic examples, hooks can pass HTML, PHP, JS or whatever and there are many ways to do it depending on what you're trying to do and where. :idea:

 

and the golden rule - if WHMCS support tell you something can't be done, don't automatically assume that they're right! :roll:

I can still remember, in the first few months of buying WHMCS, being told definitively by Support that something couldn't be done - after a cup of tea and an hour, i'd figured the solution - and I knew nothing about Smarty or WHMCS software in those days.

 

why they didn't just point you in the direction in the includes/ templates, I simply don't know. :?:

Link to comment
Share on other sites

Hi Brian, I really appreciate your posts and they add tons of value and while you are correct this is possible don’t you honestly think it’s a bit overkill just to do simple HTML changes?

 

Deleting a menu in the templates is one line. With hooks, several. Changing a link or text is something anyone can do, again a hook, you just need to get 1 character wrong to break WHMCS. I really like that you posted an example on how to do this in the template instead of a hook as well and I even think that is preferable for the simple reason that it’s still in the same template files as opposed to a separate hooks folder.

 

The point about the updates is negligent if you already have changes in templates. Example, your developer or designer is going to manually merge changes on updates anyway, so having one more change involving a sidebar or menu is one more click to merge. So, hooks are not saving time here on upgrades, but the opposite. Creating and modifying hooks is more time consuming than just going straight to the templates. To simplify, all the changes you make are in a theme folder. But hooks are not. So how you have different design elements spread in different folders. That is not unified or consistent. If someone is working on templates, the code that shows in templates, should be in the template files or at least in a folder inside the theme, not in the hooks folder that is usually used by modules.

Don’t get me wrong. I like hooks, but I think they are being overused on this case.

 

You are right on that the last part, sometimes WHMCS tells you something is possible and you can actually do it with a bit of hacking or sometimes it’s even build in, so yes, you are completely correct on that.

 

Now, between not having the option and at least having a more complex one, of course the last on is preferred but you must admit that if you need to frequently make small changes to sidebar or elements, this will get annoying and fast. I’m will have to test the code examples in v7 because support actually told me it’s not possible to change the links with hooks either on the newer version anymore, (like your Home or Knowledgebase to Google), if this is true, then no this is not even possible anymore or maybe like you said they are wrong again.

 

My concern about performance hit stands, rendering a whole smarty file is faster than having to render that smarty file and then a PHP code that reads a hooks folder and then executes PHP to insert the HTML output into that template.

 

Because some of those would be loaded almost everywhere and every single time. You see the issue here?

 

If you have a hook, let’s say that is executed only when invoices are paid, then that hook action code is only executed when invoices are paid, normally used with a module. But if you create a hook that for example modifies the Home link you mentioned, it would be executed everywhere, assuming it’s even in the breadcrumb, every single visitor and every single page they hit, you would get execute the hook.

 

Logic tells you here that this can’t be possible fast and personally I think it’s a complete waste of computing resources. I understand most people are not going to notice any issue, but this would mean WHMCS can’t scale in traffic in the future, not at least without putting more hardware to solve the problem. As far as I understand, hooks are not catched, but smarty templates are. So, this leads to my final question?

 

Can you restrict one of the hooks example to be executed only on a specific WHMCS file and be ignored otherwise? I know this would probably not be a real performance saver but I’m still curious if it would make any difference at all. A hook crashes the whole WHMCS site if something goes wrong, so if I can avoid them I do.

Link to comment
Share on other sites

I have found out something you can't change that is encoded and there does not seem to be hooks. Support told me this is not possible.

 

The hooks and your code examples mostly talk about Primary and Secondary sidebars.

 

What about this?

 

Go to your installation knowledgebase.php page, right in the top over the Secondary "Support" sidebar you have a Categories sidebar. If you then click on any knowledge base category, this sidebar helps you with navigation and shows the proper Categories.

 

You cannot modify it with hooks. You can't change this menu, or the item icons, or links or add or edit the HTML code on the sidebar at all. It seems excluded from hooks because I tried variations using PrimarySidebar and they don't work.

 

Support told me to open a feature request if I need to modify this.

 

So this is at least one side bar that you can't modify and are forced to use the default HTML and looks WHMCS provides.

Link to comment
Share on other sites

Hi,

Hi Brian, I really appreciate your posts and they add tons of value and while you are correct this is possible don’t you honestly think it’s a bit overkill just to do simple HTML changes?

yes, but what can we do? WHMCS is what it is and none of us are in control of how WHMCS design their code - all we can do is make the best of it... or, if it gets to the stage where it's no longer worth the effort (and that time will come for each of us), then we move on and use something else.

 

in many ways, I like v5 better than 6 or 7 - but maybe a part of that is because I learned WHMCS using v5 and so I know it inside out.

 

Deleting a menu in the templates is one line. With hooks, several.

at best, it's 2 lines with a hook - technically just 1 if you want to put it on the same line... those hooks above just do one thing, if you were writing it to do multiple things, then you don't need the preamble and it's just another if statement in the code.

 

Changing a link or text is something anyone can do, again a hook, you just need to get 1 character wrong to break WHMCS.

the same applies to Smarty to a degree - when I was testing the above Smarty code, I occasionally missed out a closing {/if}... it has a similar effect of partially blanking the page.

 

I really like that you posted an example on how to do this in the template instead of a hook as well and I even think that is preferable for the simple reason that it’s still in the same template files as opposed to a separate hooks folder.

pre v6, I would probably have agreed with that statement, but having spent over a year with these navigation hooks, I don't mind them - I find it easier to leave the templates untouched where possible and just tweak via hooks.

 

The point about the updates is negligent if you already have changes in templates. Example, your developer or designer is going to manually merge changes on updates anyway, so having one more change involving a sidebar or menu is one more click to merge. So, hooks are not saving time here on upgrades, but the opposite. Creating and modifying hooks is more time consuming than just going straight to the templates. To simplify, all the changes you make are in a theme folder. But hooks are not. So how you have different design elements spread in different folders. That is not unified or consistent. If someone is working on templates, the code that shows in templates, should be in the template files or at least in a folder inside the theme, not in the hooks folder that is usually used by modules. Don’t get me wrong. I like hooks, but I think they are being overused on this case.

I hear what you're saying, but if you go down the road of thinking "I wish WHMCS worked like x or y" then down that road lies madness my friend (or at least utter frustration)... i've seen it with over the years with new users who expect WHMCS to be a responsive company that reacts quickly to suggestions; adds features requests in a timely manner etc and not years later... the reality is very different.

 

I will never work for WHMCS, but the only thing that has always tempted me (though it would now also need a MASSIVE financial package too lol) would be if I thought I could change the attitude of the company from within and improve the service provided to its users (of which I am one)... of course, I know that I could brown nose myself into a position working in Support or running the forums*, but if it's not to fundamentally change the company, then really what's the point ? i'm just papering over the cracks and becoming another internal apologist for the software.

 

* - for the avoidance of doubt, I have absolutely no problem with Chris' running of the forums - he's doing a good job and, on paper, is far more experienced running forums than I... but, if i'd had the time or inclination to do it, it would have been used as a trojan horse to get inside the company to see if my external impression of it is in fact true... and if so, try to do something about it.

 

I deeply suspect there's a lot of groupthink @ WHMCS where senior people are convincing each other of what a great job they're doing... and it's been going on for years.

 

Now, between not having the option and at least having a more complex one, of course the last on is preferred but you must admit that if you need to frequently make small changes to sidebar or elements, this will get annoying and fast.

actually, I don't - i've been writing these nav hooks for so long, that if I need to tweak something, I can do the hook in seconds... I suspect I could write a nav/sidebar hook now faster than modify the template.

 

whether we should need to is another question - I don't see WHMCS changing this in the short-term... and i'd be surprised if we're still not using them with v8.

 

never forget, WHMCS didn't invent this navbar/sidebar code.

 

I’m will have to test the code examples in v7 because support actually told me it’s not possible to change the links with hooks either on the newer version anymore, (like your Home or Knowledgebase to Google), if this is true, then no this is not even possible anymore or maybe like you said they are wrong again.

wow - just wow - that a support operative could reply like that?!? :mad:

 

perhaps it depends on how you phrased your question to them, but when you get the feedback invitation from support, i'd be seriously tempted to give them a low score because, I can guarantee you 154.5%, the above code works on v7.1.2 - as I was writing/testing both hook and Smarty code on a v7.1.2 dev as I was writing the post.

 

My concern about performance hit stands, rendering a whole smarty file is faster than having to render that smarty file and then a PHP code that reads a hooks folder and then executes PHP to insert the HTML output into that template.

if we takes sidebars as an example, all these hooks are doing is modifying the array - it's not outputting anything directly itself... so the hook(s) modify the array, which is then outputted in a foreach loop in the sidebar template.

 

I wouldn't have thought there was much difference, on a performance level, from doing that as a hook or slapping multiple {if} statements into the foreach loop of the template.

 

Because some of those would be loaded almost everywhere and every single time. You see the issue here?

as would each tweak to the sidebar template.

 

Can you restrict one of the hooks example to be executed only on a specific WHMCS file and be ignored otherwise? I know this would probably not be a real performance saver but I’m still curious if it would make any difference at all. A hook crashes the whole WHMCS site if something goes wrong, so if I can avoid them I do.

yes - there have been many hooks posted in the forum that will only work on a specific page, or even specific template file.

 

I have found out something you can't change that is encoded and there does not seem to be hooks. Support told me this is not possible.

red rag to a bull time... :)

 

The hooks and your code examples mostly talk about Primary and Secondary sidebars.

What about this?

Go to your installation knowledgebase.php page, right in the top over the Secondary "Support" sidebar you have a Categories sidebar. If you then click on any knowledge base category, this sidebar helps you with navigation and shows the proper Categories.

You cannot modify it with hooks. You can't change this menu, or the item icons, or links or add or edit the HTML code on the sidebar at all. It seems excluded from hooks because I tried variations using PrimarySidebar and they don't work.

Support told me to open a feature request if I need to modify this.

So this is at least one side bar that you can't modify and are forced to use the default HTML and looks WHMCS provides.

I try not to swear in these forums, but that's sounds like the droppings from cattle to me. :)

 

let me say this so that all of support can hear... it is just a normal sidebar, it CAN be modified by hooks - you CAN identify a child, therefore you CAN change the icons, you CAN change the links, you CAN change the HTML.

yes, depending on exactly what you want to do, potentially the coding might be a bit more involved - but for support to say it can't be done is absolute nonsense. :mad:

 

ok, to prove the point, let's say the KB Categories sidebar has 1 Category with 1 article within it...

mfSDFK2.png

 

... why don't we try to modify it with a hook - probably pointless I know, because apparently it can't be done, but let's give it a go anyway...

 

<?php

use WHMCS\View\Menu\Item as MenuItem;

add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
   if (!is_null($primarySidebar->getChild('Support Knowledgebase Categories'))) {
            $primarySidebar->getChild('Support Knowledgebase Categories')
                           ->getChild('Support Knowledgebase Category 1')
                           ->setLabel('Anything Is Possible!')
                           ->setIcon('fa-book fa-fw')
                           ->setURI('https://www.google.com')
                           ->setBadge('Brian!');          
   }         
});

2opoOmP.png

 

wtf, that's not possible - i've somehow changed the icon, the label, the link and even the badge value.... what magic is this? :-P

 

now, in practice and depending on exactly what changes you wanted to make, for a more complicated set of categories, you could either use a foreach loop and work through the children array, or just create a new sidebar designed how you want it.

 

while the file that creates this sidebar is indeed encoded, it's obviously just querying the database to get a list of KB categories, sorting in alphabetical order and getting the article count of each category and then outputting the resulting array via a foreach loop to generate the sidebar. :idea:

 

it's not rocket science to do that and i've previously posted code that will query the db and then output the result using a loop to generate the children of the sidebar... it ultimately comes down to what you think is easier, modifying the existing children or starting again from scratch... and again, that depends on exactly what you want to do... ultimately, you could do it using the above hook without the need for looping if you wanted to.

 

if you open a feature request for this, you might see it before the end of the decade.... if you ask me in the forums, I can usually show you the same day. :lol:

 

when v6 was launched, the utter frustration was that the code that generated these sidebars was encrypted, so you had no idea how they were being created, nor was the documentation any help at all (in fact, usually the opposite!).

 

as I said previously - the golden rule is not to let Support suck you into believing something isn't possible... sometimes a solution might need some effort, but nothing is impossible (apart from getting a feature request added in your lifetime!). :idea:

Link to comment
Share on other sites

I understand what you mean with support. Yesterday I send them a bug report and the person argued this was not a bug and what I was trying to do. I tried to explain as much as I could with text, screenshots, etc. Then he said completely something different not even related and I had to point it him out to the WHMCS documentation of what that specific feature is supposed to do when turned on.

 

After a few exchanges where I was frustrated already (he didn’t read my ticket or just don’t know how WHMCS works), he admitted it was indeed a bug introduced some version back and it was reported already. Instead of reading and testing the first time...

 

Granted, he was Level 1, but I had the impression his job was just to argue that this was normal and not a bug. Some people told they had the same experience before so they don't bother to report bugs anymore. (it was a bug because I was using the feature in v5), it was specific to the blocking order feature in WHMCS if a domain already exists, now it can be bypassed by selecting the domain transfer option.

 

As for the other support person telling me this was not possible, maybe I was not entirely clear here. What I need is to re-link the categories in the sidebar, besides other visual changes.

 

For example currently WHMCS links them like this:

/knowledgebase.php?action=displaycat&catid=1

 

Or with SEO friendly urls on like this:

knowledgebase/1/category

 

This can be changed in the templates files, but not in the sidebar. Example, I modified the code in the template files to use:

 

/my-file.php?action=displaycat&catid=1

 

Or if the SEO switch is on:

 

my-url/1/category

 

The code is there in the templates. And the code was there for the sidebar in breadcrumb in v5.

 

But now this shows correctly except in the sidebar links. The sidebar and breadcrumb will default to use “/knowledgebase/” and knowledgebase.php always.

 

Of course, we can’t do anything if something can’t be changed or does not work. Every software has bugs, you can’t escape that but maybe my whole frustration is because support keeps telling me this is not possible, not anymore at least in the new version and I should open a feature request for this.

 

My only option would be to completely remove that categories sidebar in that case vs presenting a broken link to users or wait 3 years until they decide to add the option. This is similar to the WHOIS bug that is not falling back to the local JSON Whois if the TLD does not exist in a registrar, they don't fix things in weeks, but months or years. In the mean time your business is hurt and in a tech world where everyone is moving at light speed I can't afford not to sell something for months.

About the rest of the things you said, I don’t want to change how WHMCS works as a company, but I would wish some code was more open and they would be more active with their customers about feedback. cPanel is for example. The workflow of WHMCS is report this, or add that as a feature. Why even have a community then? Why not put a category in the forums to report suggested features and ideas. I don't want to be going to another system just to do that, and the forum software they are using, allows that. They can put a voting system in place and even a bug system in place as well just by hacking a bit the forum code. They are segregating different parts instead of unification. Features is one thing, bug is another. Sometimes a bug is a feature and the opposite. This is why you need to understand how the software is actually used in a real world or production system.

 

You could argue what I'm trying to do is a feature not a bug. But how come it was possible in v5? So it's a feature that was removed? I would say that is a bug. If you remove something that was in place and was possible before and now its gone, you don't call it a new feature again. Otherwise a developer would just release a new version, remove a bunch of stuff, then release a new version adding back things and call them new features. If you remove something that was working before, you don't consider that a feature if its added back in the future. That would be very deceiving from any software company or developer.

 

I don’t have a problems with developers protecting their work, they are entitled to that, but they should not be encoding HTML output. The only exception is buying the non branded version because the user is aware that a link back to WHMCS will be displayed. But my complain goes above WHMCS, I even saw some external module developers encoding CSS or JS, why? That is visible and public in the browser in the first place and to the irony it was even open source code. IonCube is very advanced and lets you only encode specific files or parts in a project, I don’t get it why someone would be encoding HTML parts or even put HTML parts inside server code.

 

I’m not a developer (unless you consider me a newbie one) but this causes frustration to people that are mostly designers and not coders, in particular if they cannot change the design code. Sometimes 1 single line can break or fix things in a design. If I have some issues with this I really feel sorry for those that are starting with design or HTML, they are probably hitting their heads against the monitor trying to find where that mysterious code is that shows in their pages.

 

There seems a bit of a disconnection between support and their customers, if I was WHMCS I would just hire you instead (assuming they can afford you). Why? Because you seem to understand WHMCS better than some of the support persons working with WHMCS and you seem to be active around the forums. There is no point in having a business community if the company behind it will not actively participate or at least pay people to do so. There is a reason why someone comes to the forum, because it creates a community bond and ecosystem around the product, that creates immense value for a company/product. Some people will make their entire purchase decision on a software just based on the community around it (reason why WordPress and open source is popular). Some business owners close their community or hide some things (like bugs) because they think it can lead to potential loss of sales or bad reputation. Exactly the opposite. If you do that, people can still go to other communities and places you have absolutely no control, like Facebook, Reddit, or just any other forum. The best approach is always to be very open and try to deal with problems. Every software will have bugs and nobody is perfect.

 

You have my vote if they want to hire you. Actually they should to be honest just based on the value you create with your posts.

 

EDIT: Can you use smarty in the hooks? Maybe I can re-create the code that way.

Edited by yggdrasil
Link to comment
Share on other sites

I understand what you mean with support. Yesterday I send them a bug report and the person argued this was not a bug and what I was trying to do. I tried to explain as much as I could with text, screenshots, etc. Then he said completely something different not even related and I had to point it him out to the WHMCS documentation of what that specific feature is supposed to do when turned on.

 

After a few exchanges where I was frustrated already (he didn’t read my ticket or just don’t know how WHMCS works), he admitted it was indeed a bug introduced some version back and it was reported already. Instead of reading and testing the first time...

 

Granted, he was Level 1, but I had the impression his job was just to argue that this was normal and not a bug. Some people told they had the same experience before so they don't bother to report bugs anymore. (it was a bug because I was using the feature in v5), it was specific to the blocking order feature in WHMCS if a domain already exists, now it can be bypassed by selecting the domain transfer option.

aah the old bug vs design intention debate.... WHMCS tends to define bugs as the software doing things it's not supposed to do... even when they've designed it to do stupid things!

 

As for the other support person telling me this was not possible, maybe I was not entirely clear here. What I need is to re-link the categories in the sidebar, besides other visual changes.

But now this shows correctly except in the sidebar links. The sidebar and breadcrumb will default to use “/knowledgebase/” and knowledgebase.php always.

i'd class the sidebar issue as poor coding on WHMCS' part - partly because they must be hard coded links that don't adjust for SEO, and also because the originating code is encrypted... I don't see the need for that, and makes things like this a bugger to fix.

 

Of course, we can’t do anything if something can’t be changed or does not work. Every software has bugs, you can’t escape that but maybe my whole frustration is because support keeps telling me this is not possible, not anymore at least in the new version and I should open a feature request for this.

remember what I said previously - never get sucked into thinking something can't be done... yes, it might need some effort, or by throwing some money towards a developer, but the situations where you can just give up are never as frequent as Support might tell you.

 

My only option would be to completely remove that categories sidebar in that case vs presenting a broken link to users or wait 3 years until they decide to add the option.

your real options are...

 

a) modify the sidebar links using an action hook. (doable)

b) remove the existing sidebar and add a new customised sidebar manually in the template. (doable)

c) submit a feature request. (doable - but you might as well just throw a coin in a pond and make a wish)

d) report it as a bug, hope they agree and then it might get fixed in the fullness of time... but it's not really a bug (as it's working as intended), it's just badly designed.

 

This is similar to the WHOIS bug that is not falling back to the local JSON Whois if the TLD does not exist in a registrar, they don't fix things in weeks, but months or years. In the mean time your business is hurt and in a tech world where everyone is moving at light speed I can't afford not to sell something for months.

again, technically isn't a bug, just WHMCS removing functionality - which unfortunately a lot of users didn't notice until after they'd upgraded.

 

About the rest of the things you said, I don’t want to change how WHMCS works as a company, but I would wish some code was more open and they would be more active with their customers about feedback. cPanel is for example. The workflow of WHMCS is report this, or add that as a feature. Why even have a community then? Why not put a category in the forums to report suggested features and ideas. I don't want to be going to another system just to do that, and the forum software they are using, allows that. They can put a voting system in place and even a bug system in place as well just by hacking a bit the forum code. They are segregating different parts instead of unification. Features is one thing, bug is another. Sometimes a bug is a feature and the opposite. This is why you need to understand how the software is actually used in a real world or production system.

I vaguely remember the feature requests used to be in the forums...

 

https://blog.whmcs.com/?t=65394

 

Previously, Feature Requests for WHMCS were submitted by users through a Forum Category which lacked the ability to really isolate the communities view on a request. For example, if a user submitted a Feature Request, there was no real way to gauge the community's desire or distain for it to be included into WHMCS. Unless every viewing user made a "+1" or similar comment, we could only make guess work out of it.

now we have a separate requests site, where it's difficult to search for existing requests, so users end up creating a new one - which then only gets 1 or 2 votes... and nobody else knows about the request - unless you get to the ridiculous situation of creating a new sub-forum so that users can post links to the feature requests they've just started... though that would likely slowly get abused and users will start just posting feature requests directly in the sub-forum.

 

the minute I see a reply suggesting to submit a feature request, that's all it is - a reply... it's not an answer; it's not a solution - it's passing the buck and either sending the user away without a solution, or giving them false hope that WHMCS will solve it at some future point... e.g years down the road when the problem has probably resolved itself by being no longer relevant. :roll:

 

if I do nothing else here, I try to ANSWER the question and not just reply to a thread for the sake of it.

 

You could argue what I'm trying to do is a feature not a bug. But how come it was possible in v5? So it's a feature that was removed? I would say that is a bug. If you remove something that was in place and was possible before and now its gone, you don't call it a new feature again. Otherwise a developer would just release a new version, remove a bunch of stuff, then release a new version adding back things and call them new features. If you remove something that was working before, you don't consider that a feature if its added back in the future. That would be very deceiving from any software company or developer.

welcome to WHMCS.

 

I don’t have a problems with developers protecting their work, they are entitled to that, but they should not be encoding HTML output. The only exception is buying the non branded version because the user is aware that a link back to WHMCS will be displayed. But my complain goes above WHMCS, I even saw some external module developers encoding CSS or JS, why? That is visible and public in the browser in the first place and to the irony it was even open source code. IonCube is very advanced and lets you only encode specific files or parts in a project, I don’t get it why someone would be encoding HTML parts or even put HTML parts inside server code.

I get WHMCS encoding their proprietary stuff, but why not make the internal navbar/sidebar generation stuff available... anyway, pointless moaning about it... the people who will suffer ultimately will be WHMCS themselves.

 

There seems a bit of a disconnection between support and their customers, if I was WHMCS I would just hire you instead (assuming they can afford you). Why? Because you seem to understand WHMCS better than some of the support persons working with WHMCS and you seem to be active around the forums.

you probably see me here running at about 15% capacity - I intentionally try to do as little as possible to help WHMCS as a company, but as much as I can to help fellow users... I think i'm beyond helping WHMCS to improve now, too much has happened over the years - as it says in the film... i'm not the Messiah, just a very naughty boy. :)

 

 

EDIT: Can you use smarty in the hooks? Maybe I can re-create the code that way.

yes... but if you're doing something in a hook, you have access to possibly more useful variables - but yes you can access Smarty variables and arrays (if they exist).

 

as you prefer to do things in the templates, perhaps it might be useful if I explained how to add a sidebar using Smarty - without the need to use a sidebar hook?

 

let's stick with Mission Impossible and recreate the Categories sidebar in the template and allow you to change the URL of each link...

 

at the end of sidebar.tpl, after the {/foreach}, you could add the following code...

 

{if $sidebar eq $primarySidebar and $filename eq "knowledgebase"}
   <div menuItemName="Support Knowledgebase Categories" class="panel panel-default hidden-sm hidden-xs">
       <div class="panel-heading">
           <h3 class="panel-title">
               <i class="fa fa-info"></i>  Brian's Categories
           </h3>
       </div>
       {foreach from=$kbcats item=v}
           <div class="list-group">
               <a menuItemName="Support Knowledgebase Category {$v.id}" href="knowledgebase.php?action=displaycat&catid={$v.id}" class="list-group-item {if $catid eq $v.id or $kbarticle.categoryid eq $v.id}active{/if}" id="Primary_Sidebar-Support_Knowledgebase_Categories-Support_Knowledgebase_Category_{$v.id}">
               <span class="badge">{$v.numarticles}</span><i class="fa fa-info-circle"></i>  {$v.name}</a>
           </div>
       {/foreach}
   </div>
   <div class="panel hidden-lg hidden-md panel-default">
       <div class="panel-heading">
           <h3 class="panel-title">
               <i class="fa fa-info"></i>  Brian's Categories
           </h3>
       </div>
   <div class="panel-body">
       <form role="form">
           <select class="form-control" onchange="selectChangeNavigate(this)">
               {foreach from=$kbcats item=v}
                   <option menuItemName="Support Knowledgebase Category {$v.id}" value="knowledgebase.php?action=displaycat&catid={$v.id}" class="list-group-item" >{$v.name} ({$v.numarticles})</option>
               {/foreach}
           </select>
       </form>
   </div>
</div>
{/if}

so this code will add an additional primary sidebar ONLY on the knowledgebase pages... in the image below, top is the original sidebar generated automatically (which you can remove later either via hook or template tweak), and the bottom, "Brian's Categories", is the one being generated by the sidebar template tweak.

Kohr9Zt.png

 

as you can see, they are the same... however, when you click on the links (original sidebar or new custom one), you'll spot an issue...

 

 

kHvlR0H.png

 

... the $kbcats Smarty array doesn't contain any data in the kbarticle or kbcat templates - so the template has nothing to output on these pages. :mad:

 

the way around that would be to write an action hook to recreate the array on all kb pages - it's a little kinky to use a hook, just to pass an array to generate a sidebar in a template, rather than just doing everything in the sidebar hook, but that's maybe how you prefer it. :)

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_kbcats($vars) 
{
   $kbcategories = Capsule::table('tblknowledgebasecats')
               ->join('tblknowledgebaselinks', 'tblknowledgebasecats.id', '=', 'tblknowledgebaselinks.categoryid')
               ->where('tblknowledgebasecats.hidden', '<>', 'on')
               ->select('tblknowledgebasecats.id','tblknowledgebasecats.name','tblknowledgebasecats.description', Capsule::raw('COUNT(tblknowledgebasecats.id) as numarticles'))
               ->groupBy('tblknowledgebasecats.name')
               ->get();

   $encodedata = json_encode($kbcategories);
   $decodedata = json_decode($encodedata, true);
   return array("kbcats" => $decodedata);                

}
add_hook("ClientAreaPageKnowledgebase", 1, "hook_kbcats");
?>

with the above hook in place in the /includes/hooks folder, the template sidebar should then work on all kb pages... and now you have access to the URL (knowledgebase.php?action=displaycat&catid={$v.id}) in the code, you can edit it in the normal way and change it to your custom path. :idea:

Link to comment
Share on other sites

Hi Brian,

 

Sorry for not replying sooner. Bad weekend :)

 

So, the hell may take me. This is possible after all with some hacks, I didn’t tested extensively your code yet but it seems this is possible. I don't think its valuable to keep replying WHMCS support anymore based on this.

 

The approach may be a bit messy to use in templates and then pass a hook back to it. I don’t mind using completely hooks now after I see what you did. The hook does seem to cause some bugs and I think you are correct, it would be better just to stick with hooks completely here. It may also be more complicated recreating the whole sidebar in a template and then passing variables in a hook and then removing the original with another one...To messy.

 

Isn't this possible just with 1 single clean hook file?

 

The thing I need to replace is this:

 

{$WEB_ROOT}/knowledgebase/{$kbcat.id}/{$kbcat.urlfriendlyname}

 

For:

{$WEB_ROOT}{my-custom-lang-variable}/{$kbcat.id}/{$kbcat.urlfriendlyname}

 

Is there any reason why you recreated the KB id’s in your code instead of just using $kbcat.id? Also $kbcat.urlfriendlyname is not available with this approach.

 

EDIT: It seems you used $v.name that can be used for $kbcat.urlfriendlyname

Edited by yggdrasil
Link to comment
Share on other sites

Isn't this possible just with 1 single clean hook file?

didn't I say that in the first place? :idea:

 

Is there any reason why you recreated the KB id’s in your code instead of just using $kbcat.id?

well $kbcats doesn't exist in the articles/categories pages, so there was nothing for me to use in the sidebar... so I had to query the database to get the info - it wasn't done for fun! :)

 

Also $kbcat.urlfriendlyname is not available with this approach.

that was intentional, or to be more precise - I did spot it was missing from my query comparing it to the original array, but assumed that you could fix it in the template... e.g if you were doing this in the sidebar template, then it's just a basic Smarty replace of $kbcat.name

 

{$kbcat.name|replace:' ':'-'|replace:'amp;':'and'}

unfortunately, the friendlyname is not a field that exists in the database - it will be created by the default hook based on the value of the name field.

if you wanted to re-create the existing sidebar hook, then you'd also need to recreate that additional coding... this is where you have the disadvantage of not seeing the original code, because you can only hazard a guess as to how extensive the tweaking of friendlyname is. :roll:

 

EDIT: It seems you used $v.name that can be used for $kbcat.urlfriendlyname

though it might not necessarily be url friendly. :)

Link to comment
Share on other sites

I understand, thank you. The only problem with this approach is the array seems to have some bug with nested categories, if a Category exists inside a Category, for example:

 

Domains > Manage > Articles

Server > Articles

 

It will for some reason display the Manage folder in every menu while the original WHMCS menu would only display the ones where you are on the navigation, so it would only display the Manage option if you already clicked on Domains.

Link to comment
Share on other sites

let me have a play with that tomorrow morning, and i'll get back to you.

 

Don't worry, but I think we agree that something like this should not be encoded by WHMCS. I will try to play with your code later tonight and see if it's a viable solution to replace the original WHMCS menu that is currently encoded.

Link to comment
Share on other sites

Don't worry, but I think we agree that something like this should not be encoded by WHMCS.

absolutely.

 

I will try to play with your code later tonight and see if it's a viable solution to replace the original WHMCS menu that is currently encoded.

I hadn't considered nested categories when I threw the SQL code together... but the relationship between cats and subcats is there in the database table, so yes it can be done.

Link to comment
Share on other sites

the quick fix to only show parent categories would be to tweak the hook query...

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_kbcats($vars) 
{
   $kbcategories = Capsule::table('tblknowledgebasecats')
               ->join('tblknowledgebaselinks', 'tblknowledgebasecats.id', '=', 'tblknowledgebaselinks.categoryid')
               ->where('tblknowledgebasecats.hidden', '<>', 'on')
               ->where('tblknowledgebasecats.parentid', '0')
               ->select('tblknowledgebasecats.id','tblknowledgebasecats.name','tblknowledgebasecats.description', Capsule::raw('COUNT(tblknowledgebasecats.id) as numarticles'))
               ->groupBy('tblknowledgebasecats.name')
               ->get();

   $encodedata = json_encode($kbcategories);
   $decodedata = json_decode($encodedata, true);
   return array("kbcats" => $decodedata);                

}
add_hook("ClientAreaPageKnowledgebase", 1, "hook_kbcats");
?>

the downside is that is messes up the article count because the default sidebar is counting the subcats articles too, whereas mine doesn't - which means my quick query isn't the same as WHMCS...

 

rsoR3XP.png

 

when I get more time, I may take a closer look at that query, but for now, i'd just remove the count from the query as the number of articles in each category isn't really relevant to the client.

Link to comment
Share on other sites

So if WHMCS admits this is encoded, would it not be easier just to ask them for the original code that does this to be able to recreate it? Its still part of the HTML theme if you ask me but currently encoded. (was open in v5).

 

They gave me encoded modules before after I signed a NDA and paid some money. But if this is a bug in terms that it can't be easily changed by the user, I'm sure they would be open to provide the code to users so they can correctly recreate the KB categories menu temporarily.

EDIT:

 

I had a chance to test your code tonight and the last hook update you posted fixes the nested categories issue. It seems to be working nicely, except the count bug you mentioned.

Edited by yggdrasil
Link to comment
Share on other sites

I found another bug. This one more nasty.

 

In your hook you have:

 

add_hook("ClientAreaPageKnowledgebase", 1, "hook_kbcats");

 

The hook_kbcats is causing some strange bugs with categories function and linking in WHMCS.

 

It removes the friendly name in the links folders (not the sidebar) but every category and you can't open them anymore. It will just load the same page again.

 

If you remove it or rename it, example:

 

add_hook("ClientAreaPageKnowledgebase", 1, "hook_RENAME");

 

Then the links in the categories work again and you can click and open then, but then of course you have the same bug in the sidebar again that is displaying an incorrect nested category.

 

So the problem is in the hook file code. Test this with SEO friendly urls enabled in your WHMCS and you will see what I mean, the friendly name is removed when you use hook_kbcats

 

So basically folders that are linked like this:

whmcs.com/knowledgebase/1/Domains

 

Show incorrectly as:

whmcs.com/knowledgebase/1/

 

Not even the directly link works in that case, example:

knowledgebase.php?action=displaycat&catid=1

 

So this is causing some type of internally conflict in WHMCS.

 

When you remove your hook or rename it, they work again.

 

I was also curious why do you repeat the side bar in your sidebar.tpl code.

 

It seems to me that you don't need the second part of your code. It works without it fine.

 

What exactly is this for?

 

   <div class="panel hidden-lg hidden-md panel-default">
       <div class="panel-heading">
           <h3 class="panel-title">
               <i class="fa fa-info"></i>  Brian's Categories
           </h3>
       </div>
       <div class="panel-body">
           <form role="form">
               <select class="form-control" onchange="selectChangeNavigate(this)">
                   {foreach from=$kbcats item=v}
                       <option menuItemName="Support Knowledgebase Category {$v.id}" value="knowledgebase.php?action=displaycat&catid={$v.id}" class="list-group-item" >{$v.name} ({$v.numarticles})</option>
                   {/foreach}
               </select>
           </form>
       </div>
   </div>

 

I removed that code in your sidebar.tpl code. Not sure where it appears because it seems to work fine otherwise with just the first sidebar code. So that code seems to work, it recreates the KB sidebar.

 

That alone achieves the link changing or path I wanted, since you can links code in the sidebar.tpl

 

But your hook is another story. Without it, the sidebar of course is not the same as the original in WHMCS as it doesn't display anything when viewing articles or when browsing folders it doesn't show the proper navigation, but either way, at least all categories display there and work. Something is still better than nothing.

 

With your hook enabled, the hook that tries to replicate the sidebar category navigation, then the sidebar visually displays correctly, but something breaks because you can't open the categories anymore. So the hook seems to be the issue. And this is why I dislike hooks so much.

 

I had a problem before where a hook was supposed to execute on new account registration and with that enabled it didn't show the success page on WHMCS on registration (accounts still registered ok) but there was a blank page. Why? Because WHMCS support after investigation we discovered the hook was executed first and not after, so it stopped all other actions in WHMCS from finishing. Not exactly a bug (or yes) depending on who you ask. But hooks are problematic, I had tons of issues with them before depending on the order they are executed they can stop other things from rendering or displaying. No wonder the code in the template works fine, zero issues, the hook not. So my point about disliking hooks persist.

Edited by yggdrasil
Link to comment
Share on other sites

So if WHMCS admits this is encoded, would it not be easier just to ask them for the original code that does this to be able to recreate it? Its still part of the HTML theme if you ask me but currently encoded. (was open in v5).

I look forward to hearing their response if you ask them this in a support ticket!

 

They gave me encoded modules before after I signed a NDA and paid some money. But if this is a bug in terms that it can't be easily changed by the user, I'm sure they would be open to provide the code to users so they can correctly recreate the KB categories menu temporarily.

I think the WHMCS logic will be...

 

1. WHMCS created the kb cats to do a specific task.

2. if you want to change the task, then modify the children array or create a new one - at which stage, they'll just point you in the direction of the documentation and hope you can figure it out.

 

therefore, in their eyes, it's not a bug.

 

i'd have much preferred it if they had made these codes available, such as they did with the feeds, reports etc.

 

even if we ignore the concept of one of us giving money to WHMCS (shudders), if I sign a NDA, but then effectively reveal the code in a solution published here, have I broken the NDA ?

 

anyway, if I was desperate enough to find out the code, I daresay there would be quicker ways than signing a NDA... but let's not go down that road!

 

with regards to the friendly issue, i'll take a look tomorrow... basically it's being caused by having to use a clientarepage hook to rewrite the array for the sidebar template... you wouldn't get this issue if i'd done everything in the sidebar properly!

you could probably even get around it by changing the variable name in the hook, and then using that variable in the foreach - that would leave $kbcats untouched and the other parts working.

Link to comment
Share on other sites

Sure but why re-invent the wheel? Some things are in WHMCS, some we could ask them.

 

For example, I asked you this before in this post, in your sidebar you used for example things like:

 

{$v.id}

{$v.name}

 

But why?

 

If you change your code?

{foreach from=$kbcats item=v}

 

To the original used for example in knowledgebase.tpl for:

{foreach from=$kbcats name=kbcats item=kbcat}

 

You then can use the same variables in WHMCS templates, for example:

 

{$kbcat.id}

instead of

{$v.id}

and

{$kbcat.name}

instead of

{$v.name}

 

Why tap into the database when the variables are available. :)

 

Now, your side bar code could be made more simple and that alone actually achieves what I asked. Without any needs for the hook.

 

Now, we don't have the exactly navigation like the original WHMCS KB sidebar, but I'm sure this does not need a hook either. You could probably do this in the same file, sidebar.tpl, and detect if the category is active to highlight the navigation or the current category. I'm not a developer in anyway, just playing around but I was able to replicate your code by replacing yours with some of the original WHMCS smarty variables and it works. The hook, I have no idea what it does except tapping the database but seems over complicated just to replicate a navigation menu.

 

The only hook needed would be the one that removes the original KB side bar which I did as its now in the sidebar.tpl file.

Edited by yggdrasil
Link to comment
Share on other sites

Sure but why re-invent the wheel?

because you want to change the wheel, and WHMCS have covered the nuts in superglue... so it's going to take a bit of effort. :)

 

Some things are in WHMCS, some we could ask them.

good luck with that.

 

For example, I asked you this before in this post, in your sidebar you used for example things like:

But why?

If you change your code?

You then can use the same variables in WHMCS templates, for example:

Why tap into the database when the variables are available. :)

that's irrelevant - the array that contains the info is $kbcats - the foreach loop is simply accessing that array to output it a row at a time... the access variable could be called anything you like... $v, $brian, $kbcat - they'll all contain the same values... but if you prefer to call it kbcat, go for it.

 

it's perfectly true that you don't need to query the db for the opening kb page - but you will for the rest of the kb pages... in any event, if you were doing this properly as a sidebar hook, then you would definitely need to.

 

Now, your side bar code could be made more simple and that alone actually achieves what I asked. Without any needs for the hook.

except, as I have mentioned previously, when you get to the categories or articles pages, and then $kbcats doesn't contain the parent categories... so the sidebar code becomes useless without the hook - unless you're going down the road of using the categories sidebar to show only the subcats of the chosen category on those pages - you could certainly do that in the template... but that's not what you originally asked about.

 

Ag3idxu.png

 

where are "Domains" or "Hosting & VPS" in the array - they aren't there (anywhere in the entire array!)... so I wish you well generating a list of parent categories without querying the database on the articles and category pages.

 

I don't even need to add the code to sidebar.tpl to test this, as I previously posted a screenshot of what happens without the hook...

 

kHvlR0H.png

 

Now, we don't have the exactly navigation like the original WHMCS KB sidebar, but I'm sure this does not need a hook either. You could probably do this in the same file, sidebar.tpl, and detect if the category is active to highlight the navigation or the current category. I'm not a developer in anyway, just playing around but I was able to replicate your code by replacing yours with some of the original WHMCS smarty variables and it works. The hook, I have no idea what it does except tapping the database but seems over complicated just to replicate a navigation menu.

it is overcomplicated, but I suspect necessary, if you're doing down the ridiculous path of tweaking it in the template.

 

The only hook needed would be the one that removes the original KB side bar which I did as its now in the sidebar.tpl file.

no - the point is that the sidebar template doesn't have access to the parent categories on all 3 kb pages - only the first.... now you can move the goalposts and say that you no longer need the parent categories to be shown, fair enough - but you can't make variables appear from nowhere... if they don't exist, you must create them.

 

I was also curious why do you repeat the side bar in your sidebar.tpl code.

It seems to me that you don't need the second part of your code. It works without it fine.

What exactly is this for?

the first foreach is used to display the sidebar on the normal website, the second half (that you've removed) is used to display the sidebar on a mobile website.

Link to comment
Share on other sites

good luck with that.

 

I tend to find WHMCS is very open and flexible as a company in general :). I could try.

 

that's irrelevant - the array that contains the info is $kbcats - the foreach loop is simply accessing that array to output it a row at a time... the access variable could be called anything you like... $v, $brian, $kbcat - they'll all contain the same values... but if you prefer to call it kbcat, go for it.

 

I see, you right, just sticking to the same naming convention was easier to me because it's the same variables in the rest of the templates.

 

it's perfectly true that you don't need to query the db for the opening kb page - but you will for the rest of the kb pages... in any event, if you were doing this properly as a sidebar hook, then you would definitely need to.

 

Can't this be done from the template directly or is there a reason why a querying the DB from a hook is a better approach?

 

except, as I have mentioned previously, when you get to the categories or articles pages, and then $kbcats doesn't contain the parent categories... so the sidebar code becomes useless without the hook - unless you're going down the road of using the categories sidebar to show only the subcats of the chosen category on those pages - you could certainly do that in the template... but that's not what you originally asked about.

 

Yes, while showing only the subcats is ok the better approach is to replicate completely what the original WHMCS sidebar does. Yes, I noticed it doesn't display everything.

 

no - the point is that the sidebar template doesn't have access to the parent categories on all 3 kb pages - only the first.... now you can move the goalposts and say that you no longer need the parent categories to be shown, fair enough - but you can't make variables appear from nowhere... if they don't exist, you must create them.

 

You are correct, sorry, I didn't figured this out until I added more categories to my test installation, I only had 2 so I was not able to see the full effect. I added more dummy ones as well folders inside of them and see what you mean.

 

the first foreach is used to display the sidebar on the normal website, the second half (that you've removed) is used to display the sidebar on a mobile website.

 

Ouch :(, so I just killed the menu drop list in the mobile or resized version. Going back to add it...

Link to comment
Share on other sites

Hi Brian,

 

I was looking at your code again from the first page. This in particular:

 

 

[color=#0000BB][font=monospace]<?php

[/font][/color][color=#007700][font=monospace]use [/font][/color][color=#0000BB][font=monospace]WHMCS[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]View[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]Menu[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]Item [/font][/color][color=#007700][font=monospace]as [/font][/color][color=#0000BB][font=monospace]MenuItem[/font][/color][color=#007700][font=monospace];

[/font][/color][color=#0000BB][font=monospace]add_hook[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'ClientAreaPrimarySidebar'[/font][/color][color=#007700][font=monospace], [/font][/color][color=#0000BB][font=monospace]1[/font][/color][color=#007700][font=monospace], function([/font][/color][color=#0000BB][font=monospace]MenuItem $primarySidebar[/font][/color][color=#007700][font=monospace])
{
   if (![/font][/color][color=#0000BB][font=monospace]is_null[/font][/color][color=#007700][font=monospace]([/font][/color][color=#0000BB][font=monospace]$primarySidebar[/font][/color][color=#007700][font=monospace]->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Categories'[/font][/color][color=#007700][font=monospace]))) {
            [/font][/color][color=#0000BB][font=monospace]$primarySidebar[/font][/color][color=#007700][font=monospace]->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Categories'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Category 1'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setLabel[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Anything Is Possible!'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setIcon[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'fa-book fa-fw'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setURI[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'https://www.google.com'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setBadge[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Brian!'[/font][/color][color=#007700][font=monospace]);          
   }         
});[/font][/color]

 

Would it not be possible just to use this code to change the original KB menu but apply it to all categories?

 

Something maybe like this?

 

[color=#0000BB][font=monospace]<?php

[/font][/color][color=#007700][font=monospace]use [/font][/color][color=#0000BB][font=monospace]WHMCS[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]View[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]Menu[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]Item [/font][/color][color=#007700][font=monospace]as [/font][/color][color=#0000BB][font=monospace]MenuItem[/font][/color][color=#007700][font=monospace];

[/font][/color][color=#0000BB][font=monospace]add_hook[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'ClientAreaPrimarySidebar'[/font][/color][color=#007700][font=monospace], [/font][/color][color=#0000BB][font=monospace]1[/font][/color][color=#007700][font=monospace], function([/font][/color][color=#0000BB][font=monospace]MenuItem $primarySidebar[/font][/color][color=#007700][font=monospace])
{
   if (![/font][/color][color=#0000BB][font=monospace]is_null[/font][/color][color=#007700][font=monospace]([/font][/color][color=#0000BB][font=monospace]$primarySidebar[/font][/color][color=#007700][font=monospace]->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Categories'[/font][/color][color=#007700][font=monospace]))) {
            [/font][/color][color=#0000BB][font=monospace]$primarySidebar[/font][/color][color=#007700][font=monospace]->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Categories'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Category *.*'[/font][/color][color=#007700][font=monospace])[/font][/color][color=#007700][font=monospace]
                           ->[/font][/color][color=#0000BB][font=monospace]setIcon[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'fa-book fa-fw'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setURI[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'https://www.google.com'[/font][/color][color=#007700][font=monospace])[/font][/color][color=#007700][font=monospace]       
   }         
});[/font][/color]

 

Or maybe if there is no *.* operator then at least manually add all ID's in order?

 

[color=#0000BB][font=monospace]<?php

[/font][/color][color=#007700][font=monospace]use [/font][/color][color=#0000BB][font=monospace]WHMCS[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]View[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]Menu[/font][/color][color=#007700][font=monospace]\[/font][/color][color=#0000BB][font=monospace]Item [/font][/color][color=#007700][font=monospace]as [/font][/color][color=#0000BB][font=monospace]MenuItem[/font][/color][color=#007700][font=monospace];

[/font][/color][color=#0000BB][font=monospace]add_hook[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'ClientAreaPrimarySidebar'[/font][/color][color=#007700][font=monospace], [/font][/color][color=#0000BB][font=monospace]1[/font][/color][color=#007700][font=monospace], function([/font][/color][color=#0000BB][font=monospace]MenuItem $primarySidebar[/font][/color][color=#007700][font=monospace])
{
   if (![/font][/color][color=#0000BB][font=monospace]is_null[/font][/color][color=#007700][font=monospace]([/font][/color][color=#0000BB][font=monospace]$primarySidebar[/font][/color][color=#007700][font=monospace]->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Categories'[/font][/color][color=#007700][font=monospace]))) {
            [/font][/color][color=#0000BB][font=monospace]$primarySidebar[/font][/color][color=#007700][font=monospace]->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Categories'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Category 1'[/font][/color][color=#007700][font=monospace])
[/font][/color][color=#007700][font=monospace]                            ->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Category 2'[/font][/color][color=#007700][font=monospace])
[/font][/color][color=#007700][font=monospace]                            ->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Category 3'[/font][/color][color=#007700][font=monospace])
[/font][/color][color=#007700][font=monospace]                            ->[/font][/color][color=#0000BB][font=monospace]getChild[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Support Knowledgebase Category 4'[/font][/color][color=#007700][font=monospace])[/font][/color][color=#007700][font=monospace]
                           ->[/font][/color][color=#0000BB][font=monospace]setLabel[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Anything Is Possible!'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setIcon[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'fa-book fa-fw'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setURI[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'https://www.google.com'[/font][/color][color=#007700][font=monospace])
                           ->[/font][/color][color=#0000BB][font=monospace]setBadge[/font][/color][color=#007700][font=monospace]([/font][/color][color=#DD0000][font=monospace]'Brian!'[/font][/color][color=#007700][font=monospace]);          
   }         
});[/font][/color]

 

Of course none of that works but creating a new code for every single category would be a pain in the butt, even if they are all in the same file hook, maybe there is an easier way to apply the same parameter all of them with one single code. That at least would work for things like the setIcon or setURI and some other basic things as they would be all equal to all categories.

 

Just an idea.

Edited by yggdrasil
Link to comment
Share on other sites

Hell yes, this seems to work so far :)

 

I added multiple getChild instances for each category on the hook file.

 

Except of course, that if a Category does not exist in WHMCS, the downsides of hooks, it will break the page completely as the getChild finds nothing. You need to match exactly. I will try to see if its possible to check for the getChild and if finds none, it skips that one.

 

This way it will not break WHMCS and you can add multiple ones regardless if the category exists or not. Example, you could just add 100 in the hook, and even if you have 30 it should work as you keep adding it.

 

Could this work? I think so :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated