Jump to content
kongondo

Menu Builder

Recommended Posts

The answer here below:

The menu-id can be found in the browser-url, e.g.: processwire/setup/menu-builder/edit/?id=1035 when you are editing your menu.

To render the menu

<?php

 //load the module
$menu = $modules->get('MarkupMenuBuilder');//Load the module. $menu is an example
//render by name, title or id
echo $menu->render(1035,array('default_title' => 1));  //render by ID   default title = 1 and you get ML-support
?>
 
In de Readme  you find echo $menu->render('1234');//render by ID but with brackets you get an error so, it should be echo $menu->render(1234);//render by ID
  • Like 1

Share this post


Link to post
Share on other sites

@hansv,

Welcome to PW and the forums. Apologies I have been a bit busy and was not able to respond quicker. Glad you found the answer and thanks for finding the typo in the Readme I'll correct it. By the way, note that you can also pass a menu $page or an array of menu items in addition to the ID 

Share this post


Link to post
Share on other sites

yeah, i've set it to 4 (just to make sure it's high enough), but the parent item is only marked current, when i include the children (include_children => 1).

but, with these settings the childpages are also included in the html of the menu, which i don't want.

here are my settings:

$menuOptions = array(
                    'current_class' => 'current',
                    'include_children' => 1,//show 'natural' MB non-native descendant items as part of navigation
                    'm_max_level' => 1,//how deep to fetch 'include_children'
                    'current_class_level' => 4,//how high up the ancestral tree to apply 'current_class'
             ); 

thanks!

@Torsten,

That's the current behaviour - only native menu builder child items & natural (tree) children associated via 'include_children' are affected by 'current_class_level'. I'll mull over extending the behaviour (via an API option) to include natural (tree) but non-associated children similar to the case you've described.

Share this post


Link to post
Share on other sites

Hi guys,

I have a  similar / the same problem as Torsten. But somehow, if I set "current_class_level" to 2, it doesn't seem to apply, for reasons I don't understand. My site structure looks something like this

Home

about

used stuff

products

Tv

Home Cinema

Speakers

Streaming solutions

etc.

 

If I navigate to products, the script automatically assigns the css-class "active" to the selected menu item, which changes the color of the menu item in the navbar. If I navigate to one of the children of "products" (TV,Home cinema etc.) though, my top menu item "products" loses its css class. 

I thought I could prevent "products" from losing its css- class when browsing children of "products" by increasing the value of 'current_class_level' to something greater than 1.

But if I do so, it doesn't change anything, my menu item "products" still loses its class when I navigate to one of its children.

I hope my description was understandable, and I hope even more that someone has a solution for my problem.

Best regards,

derelektrischemoench

Share this post


Link to post
Share on other sites

@derelektrischemoench,

Welcome to the forums. It works fine for me, both for 'included' (natural PW) children and native (MenuBuilder) children. Are you certain that your current class 'active' is not being applied as opposed to applied but overridden by another CSS class (e.g. 'last') via CSS Specificity/Cascade? Alternatively, can you confirm you are passing your $options properly to render() ?


@all....

I haven't forgotten pending requests/issues...I'm just currently swamped with other stuff. I hope to address concerns soon. Thanks for your patience.

Share this post


Link to post
Share on other sites

@derelektrischemoench,

Welcome to the forums. It works fine for me, both for 'included' (natural PW) children and native (MenuBuilder) children. Are you certain that your current class 'active' is not being applied as opposed to applied but overridden by another CSS class (e.g. 'last') via CSS Specificity/Cascade? Alternatively, can you confirm you are passing your $options properly to render() ?

@all....

I haven't forgotten pending requests/issues...I'm just currently swamped with other stuff. I hope to address concerns soon. Thanks for your patience.

Hi Kongondo,

so I reviewed my css (it's not that much so far), and  I didn't find the use of the class "active" or anything comparable that would mess this stuff up further down the cascade, but I guess that's not the problem here. If I inspect my code and select a child item from my menu, the script simply doesn't apply the class "active", meaning the output markup stays completely the same.

This is the code that generates my menu so far:

<?php 

         $options = array(

                'wrapper_list_type' => 'ul',//ul, ol, nav, div, etc.
                'list_type' => 'li',//li, a, span, etc.
                'menu_css_id' => 'nav',//a CSS ID for the menu
                'menu_css_class' => 'drop',//a CSS Class for the menu
                'submenu_css_class' => 'submenu',//CSS Class for sub-menus
                'has_children_class' => 'menu_child',//CSS Class for any menu item that has children
                'first_class'=>'menu_top',//CSS Class for the first item in 
                'last_class' => 'menu_bottom',
                'current_class' => 'active',
                'current_class_level' => 2,//how high up the ancestral tree to apply 'current_class'
                'default_title' => 0,//0=show saved titles;1=show actual/current titles
                'include_children' => 4,//show 'natural' MB non-native descendant items as part of navigation
                'm_max_level' => 2,//how deep to fetch 'include_children'
                
                );           

            $menu = $modules->get("MarkupMenuBuilder");
             //load the module
            echo $menu->render('nav', $options);

           

        ?>

so from my understanding the line 'current_class' => 'active' should assign the class "active" to the currently selected/active menu item, which would then enable me  to adress this class via css, correct?

Unfortunately this class assignment doesn't take place :(

Perhaps I got some of the code generating the menu wrong, I'm relatively new to programming and have yet to overcome sucking at it, so feel free to correct me   :-)

Thx so far

derelektrischemoench

//edit: Solved it myself. The problem was that I didn't set my "home" page as the parent of the menu tree, I assumed current_class_level somehow magically recognized the site tree and applied .active to parent items. Which, of course, it didn't.

Thx nevertheless, sry for wasting time by being stupid :D

Share this post


Link to post
Share on other sites

ProcessWire n00b here, be gentle!

Building my first ProcessWire site and one of the first problems I am running into is the menu system. Don't understand the logic in not having some kind of menu/nav builder in the Admin. Luckily I came across MenuBuilder!! So very simple to install and setup, thanks!

My site is based on BootStrap 3 and I am not finding enough "options" in the Menu Builder setup to get it working correctly. Hoping some one can point my in the right direction or a quick fix to the code could be done? Below is the correct code. I have hightlighted the pieces I can't figure out how to do with Menu Builder.

Edit: Apparently you can't highlight in the code block... Here's the bits in the top level menu item that has drop downs I need to add to the < a >:

  • class='dropdown-toggle'
  • data-toggle='dropdown'
  • <b class="caret"></b>

Any assistance is appreciated!

<ul class="nav navbar-nav navbar-right">
<li class='current'><a href='/'>Home</a></li>
<li class='dropdown'><a class='dropdown-toggle' href='/about/' data-toggle='dropdown' title='About'>About <b class="caret"></b></a>
<ul class='dropdown-menu'>
<li><a class='' href='/about/what/'  title='Child page example 1'>Child page example 1 </a></li>
<li><a class='' href='/about/background/'  title='Child page example 2'>Child page example 2 </a></li>
</ul>
</li>
<li><a class='' href='/site-map/'  title='Site Map'>Site Map </a></li>
</ul>

Share this post


Link to post
Share on other sites

Looks like I was able to figure out a slight code tweak. Not sure if this is something that should make it's way into the official code or not (or if it is too 'hacky' to be of use to everyone):

Replace (around line 349 in the MarkupMenuBuilder.module):

//if $iTag is empty, apply css id and classes to <a> instead
if(!$iTag) $out .= "\n\t<a{$itemCSSID} {$class}{$newtab} href='{$m->url}'>{$m->title}</a>";
else $out .= "\n\t<{$iTag}{$itemCSSID}{$class}>\n\t\t<a{$newtab} href='{$m->url}'>{$m->title}</a>";

With:

//Bootstrap A tag edits
if($m->isParent && $o->bootstrap) {
$itemHasChildrenLink = ' data-toggle="dropdown" class="dropdown-toggle"';
$itemHasChildCaret = ' <span class="caret"></span>';
}
else {
$itemHasChildrenLink = '';
$itemHasChildCaret = '';
}

//if $iTag is empty, apply css id and classes to <a> instead
if(!$iTag) $out .= "\n\t<a{$itemCSSID} {$class}{$newtab}{$itemHasChildrenLink} href='{$m->url}'>{$m->title}{$itemHasChildCaret}</a>";
else $out .= "\n\t<{$iTag}{$itemCSSID}{$class}>\n\t\t<a{$newtab}{$itemHasChildrenLink} href='{$m->url}'>{$m->title}{$itemHasChildCaret}</a>";

Then add @ line 977 to create a new option:

$this->set('bootstrap', isset($options['bootstrap_menu']) ? $options['bootstrap_menu'] : 0);
Where:
bootstrap  //Test for bootstrap style menus - 1 = Yes / 0 = No [default]

Share this post


Link to post
Share on other sites

Hi.

I get this error when saving menu items. The problem only arises when language support installed.

Error: Call to a member function getLanguageValue() on a non-object (line 1750 of /Users/vayu/Sites/processshop.dev/site/modules/ProcessMenuBuilder/ProcessMenuBuilder.module) 
This error message was shown because you are logged in as a Superuser. Error has been logged.

I have tested this on a clean install of Processwire version 2.6.1.

  • Like 1

Share this post


Link to post
Share on other sites

Hi.

I get this error when saving menu items. The problem only arises when language support installed.

Error: Call to a member function getLanguageValue() on a non-object (line 1750 of /Users/vayu/Sites/processshop.dev/site/modules/ProcessMenuBuilder/ProcessMenuBuilder.module) 
This error message was shown because you are logged in as a Superuser. Error has been logged.

I have tested this on a clean install of Processwire version 2.6.1.

I had already reported this issue on Github, where I posted a problem-solution that works. Hope it helps. https://github.com/kongondo/MenuBuilder/issues/22

David

  • Like 4

Share this post


Link to post
Share on other sites

If I was to put a static/hardcoded <li></li> into a Menu Builder menu, how would I best approach a solution? Is there a way to have no wrapper_list_type, or echo my additional <li></li> together with $out?

I guess my problem could be solved with Hanna Code, but the question still intrigue me.

Here's my current code, for reference. With two <ul>s that I am trying to merge into one.

<?php if($user->isSuperuser()) : ?>
<ul>
  <li><a href='<?php echo $page->editURL; ?>'><i class='fa fa-pencil'></i> <?php echo __('Rediger', '/site/templates/header.inc'); ?></a></li>
  <li><a href='<?php echo $config->urls->admin; ?>'><i class='fa fa-gears'></i> <?php echo __('Kontrollpanel', '/site/templates/header.inc'); ?></a></li>
</ul>
<?php 
$adminmenu = 'administrator-menu';
$options = array( 'wrapper_list_type' => 'ul', 'list_type' => 'li');
$menu = $modules->get('MarkupMenuBuilder');
$out = $menu->render($adminmenu, $options);
echo $out;
?>
<?php endif; ?>

Share this post


Link to post
Share on other sites

Hey @kongondo,

I love this module and I'm featuring it in a comparison to WordPress's menu builder in my screencast series, however I feel there could be some general UI/UX improvements that can really make it feel more "native" and simplify what I feel is option overload.  Please take this as constructive criticism.

Here are my thoughts:

  1. Perhaps remove the ability to create multiple menus.  It's a nice feature but it feels like overkill since sites typically don't have more than just a few menus.  (or disable this option by default and perhaps have it enabled in the module's settings for advanced used).  Perhaps add a standard "Add New" button instead that follows the typical Page creation process.
  2. For the same reasons above, remove batch actions to delete, unpublish, etc.  (or disable this option by default and perhaps have it enabled in the module's settings for advanced used).
  3. When going in to edit a menu, make the first tab be "Structure" which is selected by default.  This is typically the first action most people would want to take so it would feel more natural for it to be the first tab item. There should be 3 fieldsets/sections in this "Structure" tab:
    1. Add Page
    2. Add Custom Link
    3. Menu Items
  4. Perhaps simplify how you can add pages to your menu:
    1. Remove the existing 3 methods: Pages (both ASM and PageAutoComplete), Custom, Selector
      1. In regards to adding pages using Selectors, perhaps have this disabled by default, but an option that can be enabled in the modules settings.  It's an advanced feature but I'd imagine wouldn't be as commonly used and therefore feels a bit overwhelming.
    2. If possible, replace with a ProcessPageList (this is what goes inside the "Add Page" fieldset).  It feels like a more natural fieldtype since it uses the tree.
      1. since this would replace the ASM way of adding menu items, that means you can't change a CSS Class/ID until AFTER it's been added to the menu.  I think that's OK since right now you change CSS Classes/IDs both before and after adding the menu item, which I find a little confusing.
    3. If possible, upon clicking a page to add to your menu on the ProcessPageList, it should show an "add" action/button (native ProcessPageList action stuff), that when clicked, adds the page to the actual menu (some ajax/dom manipulation required here I think) instead of putting it in a "limbo" state like it is right now until a page is saved.
    4. As far as being able to add custom links, that should go under the "Add Custom Link" fieldset.  Perhaps also remove batch ability to add Custom Links and utilize general Inputfieldtext instead of a table structure.  Remove ability to set CSS Class and ID at this stage.
  5. Now for the "Menu Items" section:
    1. Right now, you're utilizing custom styling and javascript for the adding page items and creating the toggle boxes, however it should be possible to use make each added menu item act as an InputfieldFieldset.  When each item/fieldset is clicked, it should reveal the 5 editable fields (Title, URL, CSS ID, Class Class, New Window) and ability to delete.  Apply the nestedSortable JS to that list to make it have drag/drop capability with indenting.  A final result similar to this screenshot which I hacked together.
  6. "Main" tab should be renamed to "Settings".  Put as second tab.
  7. "Items Overview" tab: this could be removed (or disabled by default) since it's essentially just displaying the same menu in a table.  Feels repetitive.
  8. "Delete" tab should remain as is.

What do you think?

  • Like 2

Share this post


Link to post
Share on other sites

Hi,

thanks for the module, I think this is a great addition!

Is there a way to set default classes for the menu's li items and possible for the included a tags as well?

To keep nesting flat in the css, our stylesheet uses ".list-item" and ".list-item-link" classes.

And, would it be possible to set via the $options to not include the outermost "ul"? this would take care for instances like laban describes above (https://processwire.com/talk/topic/4451-menu-builder/page-6#entry97178) or my use case, where I'd like to add a "login / logout" nav item to the footer-menu - depending on the logged in state of the user this is either /login or /logout. I would add this in the template, not as an item via the menu builder, but it still needs to be enclosed in the "ul" wrap of the rendered menu.

Or would those two use cases be better taken care of if I used the JSON -> array() thing, just taking the infos provided by the menu builder and creating my own markup around it?

Anyways, great work, really looking forward to use this in a production site :-)

Share this post


Link to post
Share on other sites

WOW! Just to answer myself; all of the above can easily be covered. Just don't use the render(); method.

Step 1: fetch your menu data and store it in an array:

$footermenu_items_json =  $pages->get('name=footer-menu')->menu_items; // this is the menu page in menu builder, could also be fetched with the ID
$footermenu_items = json_decode($footermenu_items_json, true);

Step 2: use that array to build your custom markup:

if( count($footermenu_items) > 0 ){
  $out = '<ul class="nav-list">';
  foreach($footermenu_items as $item){
    $url = ($item['url']) ? $item['url'] : $pages->get($item['pages_id'])->url;
    $target = (1 == $item['newtab']) ? 'target="_blank"':'';
    $out .= '<li class="list-item"><a href="' . $url . '" class="list-item-link" ' . $target . '>' . $item['title'] . '</a></li>';
  }
  if( $user->isLoggedin() ){
    $out .= '<li class="list-item"><a href="' . $pages->get('name=login, template=login')->url . 'logout/' . '" class="list-item-link">Logout</a></li>';
  } else {
    $out .= '<li class="list-item"><a href="' . $pages->get('name=login, template=login')->url . '" class="list-item-link">Login</a></li>';
  }
  $out .= '</ul>';
  echo $out;
}

Just make sure to var_dump the array somewhere to get an idea of what info is stored in there for the nested levels, etc.

This is really neat. For me it's the best of both worlds - I can easily create and maintain menus in the backend, but can still fully control the output in the template. Thank you!!

cheers,
Tom

  • Like 4

Share this post


Link to post
Share on other sites

@all,

Again, this is just a quick holding post....I am still tied up and cannot presently address your issues. 

@jonathan...thanks for taking the time to review the UI of the module. I hope to respond to your thoughts/suggestions soon.

Thank you all for your patience... :)

Share this post


Link to post
Share on other sites

Hi! Thanks for the great module!

After deciding that its functionality was a bit too much for what I wanted to do right now, I tried to uninstall the module but it throws this error: 

Can't delete template 'menus' because it is used by 1 pages.

The Markup Module unisntalls just fine.

 I am using PW 2.6.1

Thanks for further assistance,

Share this post


Link to post
Share on other sites

Hi,

is there any progress with post 110?

I get the same error, when i using menubuiler with language support activated.  :( 

Share this post


Link to post
Share on other sites

Looks like I was able to figure out a slight code tweak. Not sure if this is something that should make it's way into the official code or not (or if it is too 'hacky' to be of use to everyone):

Replace (around line 349 in the MarkupMenuBuilder.module):

//if $iTag is empty, apply css id and classes to <a> instead
if(!$iTag) $out .= "\n\t<a{$itemCSSID} {$class}{$newtab} href='{$m->url}'>{$m->title}</a>";
else $out .= "\n\t<{$iTag}{$itemCSSID}{$class}>\n\t\t<a{$newtab} href='{$m->url}'>{$m->title}</a>";

With:

//Bootstrap A tag edits
if($m->isParent && $o->bootstrap) {
$itemHasChildrenLink = ' data-toggle="dropdown" class="dropdown-toggle"';
$itemHasChildCaret = ' <span class="caret"></span>';
}
else {
$itemHasChildrenLink = '';
$itemHasChildCaret = '';
}

//if $iTag is empty, apply css id and classes to <a> instead
if(!$iTag) $out .= "\n\t<a{$itemCSSID} {$class}{$newtab}{$itemHasChildrenLink} href='{$m->url}'>{$m->title}{$itemHasChildCaret}</a>";
else $out .= "\n\t<{$iTag}{$itemCSSID}{$class}>\n\t\t<a{$newtab}{$itemHasChildrenLink} href='{$m->url}'>{$m->title}{$itemHasChildCaret}</a>";

Then add @ line 977 to create a new option:

$this->set('bootstrap', isset($options['bootstrap_menu']) ? $options['bootstrap_menu'] : 0);
Where:
bootstrap  //Test for bootstrap style menus - 1 = Yes / 0 = No [default]

Great work! Hacky but great! I'm also new to PW but I'm loving it so far.

My solution for using MenuBuilder with Bootstrap 3 is kinda hacky as well. No need to change the module code here but it's definitely some sloppy coding, like don't-try-this-at-home-sloppy.

Configure the options like so:

$options = array(
           'wrapper_list_type'  => 'ul',
           'menu_css_class'     => 'nav navbar-nav',
           'submenu_css_class'  => 'dropdown-menu',
           'has_children_class' => 'dropdown',
);

And do the rest with jQuery: (the sloppy part)

$(document).ready(function () {
       $(".dropdown [href='#']:first-child").attr("data-toggle", "dropdown").addClass('dropdown-toggle');
});

I know the the dropdowns are selected with [href=#] (which is horrible). I did that because reasons. It works. And it took only 30 minutes to figure out. That proofs how awesome this module is!

Share this post


Link to post
Share on other sites

I had already reported this issue on Github, where I posted a problem-solution that works. Hope it helps. https://github.com/kongondo/MenuBuilder/issues/22

David

@David and other experiencing this issue. I have not been able to replicate the issue. Please see my comment on the issue at Github. Could someone please provide responses to the questions I have detailed there? Thanks.

Share this post


Link to post
Share on other sites

Hi all!

I am new to PW and I am using the module MenuBuilder just for creating the menu of my web site, but I have a problem when I swicth language from English to another; in fact when I switch to Italian language for example, the menu does not appear and sometimes an error appears ("Error: No menu items found"). I would like to ask if somebody knows how to create a multilanguage menu by means of Menu Builder and if yes, can show me how to do it.

Thanks in advance

Share this post


Link to post
Share on other sites

Hi @Mattia90,

Welcome to ProcessWire and the forums. Sorry about the problems you are encountering with MenuBuilder. I am the author of the module. To be honest, I know next to nothing about multilingual setups. I don't know how to add or remove a language or how to specify a default language nor about the various approaches to setting up a multilingual site :-). However, I have tested MenuBuilder with the default ProcessWire multilingual install and it works fine. Other guys have had issues with MenuBuilder after they'd removed a language. I have not been able to reproduce some of the issues. So, unless someone can give me a 'dummies' step-by-step instruction on how to reproduce their multilingual error/bug, I have no way of fixing the issues :(.

Share this post


Link to post
Share on other sites

Hi @kongondo!

Thank you for your reply. Now I explain in a detailed way what I did:

1) My idea was to create a web site both in English and in Italian and in order to do this, according to the official documentation of ProcessWire, I installed all the modules that you can find under the voice "Language" (Language Support) : in the admin page, Modules -> Core;

2) I have created a menu by means of admin page: Setup -> Menu Builder and here I created a menu with title "Menu_X" and then I built the menu by adding the pages that I wanted.

3) In order to have this web site in Italian and in English, in order to have the possibility to switch from one language to the other one, I added in each page this piece of code taken from the official documentation of ProcessWire:

$menu = $modules->get("MarkupMenuBuilder"); //load the module
 
$options = array(
         'wrapper_list_type' => 'ul',
         'list_type' => 'li',
         'menu_css_id' => '',
         'menu_css_class' => 'nav navbar-nav',
         'submenu_css_class' => 'hvr-bounce-to-bottom',
         'current_class' => 'active',
         'current_css_id' => '',
         'divider' => '»',// e.g. Home >> About Us >> Leadership
         //prepend home page at the as topmost item even if it isn't part of the breadcrumb
         'prepend_home' => 0,//=> 0=no;1=yes
         'default_title' => 0,//0=show saved titles;1=show actual/current titles
         'include_children' => 4,//show 'natural' MB non-native descendant items as part of navigation
         'b_max_level' => 1,//how deep to fetch 'include_children'
);
 
echo $menu->render('Menu_X', $options); //render the menu

This is a select that allows to switch from English to Italian and viceversa.

4) Now when I created the "Menu_X", there wasn't the possibility to specify the titles of the different menu items in both languages and also the different urls: in fact the menu works only in the default language (English); what it seems strange is that when I switch from English to Italian, this error appears: "Fatal error: Exception: No menu items found! Confirm that such a menu exists and that it has menu items."

In the worst case, what I expected is to have the same menu both in Italian and in English. I would like to have how to create a multilingual menu with the right urls by means of Menu Builder.

Thanks in advance.

Edited by kongondo
wrapped code in code block

Share this post


Link to post
Share on other sites

Hi @Mattia90

Apologies for the delay in getting back to you. I don't know about your setup there but MenuBuilder should work out of the box with a Multi-lingual site except for this one issue reported here include a possible fix which I am yet to implement. Does that fix help in your case? MenuBuilder will read and load the correct language of the user. No need to specify titles for each language when building the menu. 

What do you mean by: 

 This is a select that allows to switch from English to Italian and viceversa.

Is Menu_X the title of the menu you created?

Does your site work normally otherwise?, i.e. without MenuBuilder? Like I said, I have tested it with ProcessWire's site-languages and it works fine (with three languages). 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By tcnet
      PageViewStatistic for ProcessWire is a module to log page visits of the CMS. The records including some basic information like IP-address, browser, operating system, requested page and originate page. Please note that this module doesn't claim to be the best or most accurate.
      Advantages
      One of the biggest advantage is that this module doesn't require any external service like Google Analytics or similar. You don't have to modify your templates either. There is also no Javascript or image required.
      Disadvantages
      There is only one disadvantage. This module doesn't record visits if the browser loads the page from its browser cache. To prevent the browser from loading the page from its cache, add the following meta tags to the header of your page:
      <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="0" /> How to use
      The records can be accessed via the Setup-menu of the CMS backend. The first dropdown control changes the view mode.

      Detailed records
      View mode "Detailed records" shows all visits of the selected day individually with IP-address, browser, operating system, requested page and originate page. Click the update button to see new added records.

      Cached visitor records
      View modes other than "Detailed records" are cached visitor counts which will be collected on a daily basis from the detailed records. This procedure ensures a faster display even with a large number of data records. Another advantage is that the detailed records can be deleted while the cache remains. The cache can be updated manually or automatically in a specified time period. Multiple visits from the same IP address on the same day are counted as a single visitor.

      Upgrade from older versions
      Cached visitor counts is new in version 1.0.8. If you just upgraded from an older version you might expire a delay or even an error 500 if you display cached visitor counts. The reason for this is that the cache has to be created from the records. This can take longer if your database contains many records. Sometimes it might hit the maximally execution time. Don't worry about that and keep reloading the page until the cache is completely created.
      Special Feature
      PageViewStatistic for ProcessWire can record the time a visitor viewed the page. This feature is deactivated by default. To activate open the module configuration page and activate "Record view time". If activated you will find a new column "S." in the records which means the time of view in seconds. With every page request, a Javascript code is inserted directly after the <body> tag. Every time the visitor switches to another tab or closes the tab, this script reports the number of seconds the tab was visible. The initial page request is recorded only as a hyphen (-).

      Settings
      You can access the module settings by clicking the Configuration button at the bottom of the records page. The settings page is also available in the menu: Modules->Configure->ProcessPageViewStat.
      IP2Location
      This module uses the IP2Location database from: http://www.ip2location.com. This database is required to obtain the country from the IP address. IP2Location updates this database at the begin of every month. The settings of ProcessPageViewStat offers the ability to automatically download the database monthly. Please note, that automatically download will not work if your webspace doesn't allow allow_url_fopen.
      Dragscroll
      This module uses DragScroll. A JavaScript available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability in view mode "Day" to drag the records horizontally with the mouse pointer.
      parseUserAgentStringClass
      This module uses the PHP class parseUserAgentStringClass available from: http://www.toms-world.org/blog/parseuseragentstring/. This class is required to filter out the browser type and operating system from the server request.
    • By Mike Rockett
      TextformatterTypographer
      A ProcessWire wrapper for the awesome PHP Typography class, originally authored by KINGdesk LLC and enhanced by Peter Putzer in wp-Typography. Like Smartypants, it supercharges text fields with enhanced typography and typesetting, such as smart quotations, hyphenation in 59 languages, ellipses, copyright-, trade-, and service-marks, math symbols, and more.
      It's based on the PHP-Typography library found over at wp-Typography, which is more frequently updated and feature rich that its original by KINGdesk LLC.
      The module itself is fully configurable. I haven't done extensive testing, but there is nothing complex about this, and so I only envisage a typographical bug here and there, if any.
    • By robert
      I often had the need for an overview of all used fields and their contents for a specific page/template while developing new websites without switching to the backend, so I made a small module which lists all the needed information in a readable manner (at least for me):
      Debug Page Fields
      https://github.com/robertweiss/ProcessDebugPageFields
      It adds two new properties to all pages:
      $page->debugFieldValues – returns an object with all (sub-)fields, their labels, fieldtypes and values $page->debugFieldTypes – returns an object with all fieldtypes and their corresponding fields // List all values of a pages $page->debugFieldValues // List a specific field $page->debugFieldValues->fieldname // List all used fieldtypes of a page $page->debugFieldTypes I recommend using it in combination with Tracy Debugger, Ray, Xdebug etc. as it returns an object and is only meant for developing/debugging uses. 
      For now, the fieldtype support includes mostly fieldtypes I use in my projects, but can easily be extended by adding a new FieldtypeFIELDNAME method to the module. I use it with five different client installations (all PW 3.0.*), but of course there might be some (or more) field configurations which are not covered correctly yet.
      Supported fieldtypes
      Button Checkbox Color Combo Datetime Email FieldsetPage * File FontIconPicker Functional Image ImageReference MapMarker Multiplier Mystique Options Page PageIDs PageTitle Radio Repeater * RepeaterMatrix * RockAwesome SeoMaestro Table Text Textarea Textareas Toggle URL * The fields with complete subfield-support also list their corresponding subfields.
      Installation
      Download the zip file at Github or clone the repo into your site/modules directory. If you downloaded the zip file, extract it in your sites/modules directory. In your admin, go to Modules > Refresh, then Modules > New, then click on the Install button for this module. As this is my first ›public‹ module, I hope I did not miss any important things to mention here.
    • By horst
      Wire Mail SMTP

      An extension to the (new) WireMail base class that uses SMTP-transport

      This module integrates EmailMessage, SMTP and SASL php-libraries from Manuel Lemos into ProcessWire. I use this continously evolved libraries for about 10 years now and there was never a reason or occasion not to do so. I use it nearly every day in my office for automated composing and sending personalized messages with attachments, requests for Disposition Notifications, etc. Also I have used it for sending personalized Bulkmails many times.

      The WireMailSmtp module extends the new email-related WireMail base class introduced in ProcessWire 2.4.1 (while this writing, the dev-branch only).
       
      Here are Ryans announcement.



      Current Version 0.6.0
      Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md
      get it from the Modules Directory Install and Configure

      Download the module into your site/modules/ directory and install it.

      In the config page you fill in settings for the SMTP server and optionaly the (default) sender, like email address, name and signature.
      You can test the smtp settings directly there. If it says "SUCCESS! SMTP settings appear to work correctly." you are ready to start using it in templates, modules or bootstrap scripts.


      Usage Examples
      The simplest way to use it:
      $numSent = wireMail($to, $from, $subject, $textBody); $numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page This will send a plain text message to each recipient.
       
      You may also use the object oriented style:
      $mail = wireMail(); // calling an empty wireMail() returns a wireMail object $mail->to($toEmail, $toName); $mail->from = $yourEmailaddress; // if you don't have set a default sender in config // or if you want to override that $mail->subject($subject); $mail->body($textBody); $numSent = $mail->send(); Or chained, like everywhere in ProcessWire:
      $mail = wireMail(); $numSent = $mail->to($toEmail)->subject($subject)->body($textBody)->send(); Additionaly to the basics there are more options available with WireMailSmtp. The main difference compared to the WireMail BaseClass is the sendSingle option. With it you can set only one To-Recipient but additional CC-Recipients.
      $mail = wireMail(); $mail->sendSingle(true)->to($toEmail, $toName)->cc(array('person1@example.com', 'person2@example.com', 'person3@example.com')); $numSent = $mail->subject($subject)->body($textBody)->send(); The same as function call with options array:
      $options = array( 'sendSingle' => true, 'cc' => array('person1@example.com', 'person2@example.com', 'person3@example.com') ); $numSent = wireMail($to, '', $subject, $textBody, $options); There are methods to your disposal to check if you have the right WireMail-Class and if the SMTP-settings are working:
      $mail = wireMail(); if($mail->className != 'WireMailSmtp') { // Uups, wrong WireMail-Class: do something to inform the user and quit echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>"; return; } if(!$mail->testConnection()) { // Connection not working: echo "<p>Couldn't connect to the SMTP server. Please check the {$mail->className} modules config settings!</p>"; return; }  
      A MORE ADVANCED DEBUG METHOD!
      You can add some debug code into a template file and call a page with it:
      $to = array('me@example.com'); $subject = 'Wiremail-SMTP Test ' . date('H:i:s') . ' äöü ÄÖÜ ß'; $mail = wireMail(); if($mail->className != 'WireMailSmtp') { echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>"; } else { $mail->from = '--INSERT YOUR SENDER ADDRESS HERE --'; // <--- !!!! $mail->to($to); $mail->subject($subject); $mail->sendSingle(true); $mail->body("Titel\n\ntext text TEXT text text\n"); $mail->bodyHTML("<h1>Titel</h1><p>text text <strong>TEXT</strong> text text</p>"); $dump = $mail->debugSend(1); } So, in short, instead of using $mail->send(), use $mail->debugSend(1) to get output on a frontend testpage.
      The output is PRE formatted and contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection, like this one:
       
      Following are a ...


      List of all options and features


      testConnection () - returns true on success, false on failures


      sendSingle ( true | false ) - default is false

      sendBulk ( true | false ) - default is false, Set this to true if you have lots of recipients (50+)


      to ($recipients) - one emailaddress or array with multiple emailaddresses

      cc ($recipients) - only available with mode sendSingle, one emailaddress or array with multiple emailaddresses

      bcc ($recipients) - one emailaddress or array with multiple emailaddresses

       
      from = 'person@example.com' - emailaddress, can be set in module config (called Sender Emailaddress) but it can be overwritten here

      fromName = 'Name Surname' - optional, can be set in module config (called Sender Name) but it can be overwritten here


      priority (3) - 1 = Highest | 2 = High | 3 = Normal | 4 = Low | 5 = Lowest

      dispositionNotification () or notification () - request a Disposition Notification


      subject ($subject) - subject of the message

      body ($textBody) - use this one alone to create and send plainText emailmessages

      bodyHTML ($htmlBody) - use this to create a Multipart Alternative Emailmessage (containing a HTML-Part and a Plaintext-Part as fallback)

      addSignature ( true | false ) - the default-behave is selectable in config screen, this can be overridden here
      (only available if a signature is defined in the config screen)

      attachment ($filename, $alternativeBasename = "") - add attachment file, optionally alternative basename


      send () - send the message(s) and return number of successful sent messages


      debugSend(1) - returns and / or outputs a (pre formatted) dump that contains the areas: SETTINGS, RESULT, ERRORS and a complete debuglog of the server connection. (See above the example code under ADVANCED DEBUG METHOD for further instructions!)


      getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,


      logActivity ($logmessage) - you may log success if you want

      logError ($logmessage) - you may log warnings, too. - Errors are logged automaticaly
       
       
      useSentLog (true | false) - intended for usage with e.g. third party newsletter modules - tells the send() method to make usage of the sentLog-methods - the following three sentLog methods are hookable, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here

      sentLogReset ()  - starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter

      sentLogGet ()  - is called automaticly within the send() method - returns an array containing all previously used emailaddresses

      sentLogAdd ($emailaddress)  - is called automaticly within the send() method
      Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md
       
       
    • By Cybermano
      Food Allergens Module
      A simple List of Food Allergens
      My needs were to provide a simple list of food allergens for our clients with restaurant related activity.
      The idea was to simply output the list (to speed up the data entry) without leaving the food menu editing, eg. opening another page in new tab or window.
      This isn't a perfect solution, but it works fine for my needs and I decided to share the base idea.
      This could also be easily used to show little notes or short "vademecum", not only for the list of food allergens.
      ---
      Main features
      The basis
      All moves from a short editing of the module in this tutorial: How to create custom admin pages by @bernhard
      First of all it creates an empty admin page, with a dedicated permission to let safe-user to see it (this permission has to be created as a new ones, manually or by the module).
      Once the page is created, I have hooked its behaviour into the ready.php, to show the content (basically a list).
      A step further
      With the tips of  @bernhard, @Soma (and many others), see here , the magic happens. 
      The new page will be shown as a panel, so editors will not abandon their data entry to have a quick view to the list.
      A little further
      Why scroll to the top of the page to click a link?
      The next step was to create a sticky button only in the food menu pages.
      Again with a @bernhard tip I moved into the customization of this simple module and the related hook.
      ---
      How to use this module
      After installed, it creates the page /admin/page/allergens/ and the module is to be setted up. The first field is a CKEditor with multi-language. This is the place where to write the informations that will be shown into the page. The next field is a simply text-area where to place a bit of JS that will be appended to the markup of the text (omit the 'script' tags). I also putted a checkbox with a silly statement: this to think at least twice on the safety of the written JS. Now comes the first way to display the link to the page
      Field Note with Link. Enable and save it. The module will display a new row with 4 selects (1 standard and 3 ASM):
      View mode (to show the page as Panel or as Modal PopUp); Templates to select: select one or more and save before proceed, so the  asm-select of the pages will be populated showing all the pages of the selected templates. Pages to select: also here select at least one and save before proceed to populate the asm-select for fields only with the ones that belong to the selected pages. Select the fields where to place the note and save again. That's all: now you will find into the notes of the selected fields the link "See the List of Allergens".
      At the same way, the option for the sticky button, but with a plus
      The field select is obviously unnecessary, but you could play with the last row: the inline styles to fix your sticky button where you like. Here you could set the sticky position of the <div> and the absolute ones of the <a>.

      Video Explanation
      In these screencasts you could see a custom JS that show a "copy" button near a "hanna-code" call.
      This because I've set a specific one for each allergen to show up a tooltip in the front end.

      Registrazione #33.mp4  

      Registrazione #34.mp4 ---
      Last but not the least
      Actually it works fine for my needs, even if it's much improvable: I'm working on the permissions creation, the uninstall section, a separate configs and defaults and how to include the hook into the module leaving free the ready.php. According to a simpler uninstall. Also I would make the link text as a dynamic text field, so it will be more flexible.
      I always learn a lot here, so I would share my code for whom it could be interested.
      I removed the hanna code references, but I provide you the html list of the allergens, English and Italian too, so you can paste them into the "source" of the CKEditor field to have a ready to use module.
      Obviously you are free to modify the code as per your needs.
      Please, keep in mind that I'm not a pro coder and I beg your pardon for my verbosity (speaking and coding). 😉
      I hope be helpful or for inspiration.
      Bye
      ready.phpList-ITA.htmlList-ENG.htmlAllergens.module
      README.md
×
×
  • Create New...