-
Posts
7,479 -
Joined
-
Last visited
-
Days Won
146
Everything posted by kongondo
-
Maybe not related but I've noticed my last submitted module (Image Marker) was approved but I didn't get an email notification like usually happens. Thing is I don't know whether that was pre- or post- the switch
-
@LostKobrakai..could Iftrunner be used as a 'worker' in this case?
- 75 replies
-
OK...sigh...because you asked nicely... @note: Using this method, it makes no sense to create a menu with more than 1 level in Menu Builder. The levels will be built using natural child-parent relationship in MSN The CSS attritubes that can be set in MB have no meaning. I see no way of passing those to MSN This was a one-time exercise. Currently, I am not able to support more features for this technique Step 1: Create a 1-level menu in MB Step 2: Grab menu items from the menu created in MB in Step #1 $itemIDs = ''; $mb = $modules->get("MarkupMenuBuilder"); // options 1: get menu items as array $menuItemsArray = $mb->getMenuItems('Ivan Gretsky', 1); foreach($menuItemsArray as $m) $itemIDs .= $m['pages_id'] . '|'; $itemIDs = rtrim($itemIDs, '|'); #### OR #### //option 2: get menu items as object (WireArray) $menuItemsObj = $mb->getMenuItems('Ivan Gretsky'); // implode the WireArray the cool way (PW 2.4+) $itemIDs = $menuItemsObj->implode('|', 'pagesID'); // get a PageArray using menu item IDs $itemsPageArray = $pages->find('id=' . $itemIDs); Step 3: Output the menu using MSN // pass the PageArray to MSN (optionally passing it MSN $options) to output your menu $menu = $modules->get("MarkupSimpleNavigation"); echo $menu->render($options, null, $itemsPageArray);
-
De nada
-
Thanks Ben, very nice. I am getting a slight horizontal shift when navigating through different pages...Intentional? Checked on Chrome..
-
I don't know if MSN can use a WireArray to build menus. It certainly can take a PageArray and build a menu out of that. The key here is that MSN relies on true/natural PW child-parent relationships (unless something has changed that I don't know about) to create menus. So, $page->children will make sense to it. You won't get $page->children in MB...at least not in that original sense.
-
I'm not sure what the point of that would be (or whether it's even possible)? ..MSN is brilliant if you want a menu that matches your page tree...MB mainly caters for the opposite need....
-
Looks fine here..on Chrome..
-
Update: version 0.1.5 Changelog Added new method getMenuItems() to MarkupMenuBuilder that greatly simplifies creation of custom complex menus. Read more about it in previous (long) post.
-
I have now added a method to MarkupMenuBuilder that makes this quite easy, thanks to your challenge . @Beluga, I have used your example to make a demo using Menu Builder, thanks. @Peter, you will find full examples in Menu Builder's support forum here.
-
Been getting questions on how to build complex/custom menus. Even with the ability to pass it custom options, some menus are a bit more complex than what Menu Builder offers out of the box. My answer to such questions has, to date, been get the JSON and use that to build your menu. Not very easy for some....but no more...thanks to @Beluga, @Peter and @Webrocker + others for the inspiration/challenges. I've now added a method in MarkupMenuBuilder to make building custom complex menus a breeze. Don't get me wrong, you still have to know your foreach loops or even better grab one of the many recursive list/menu functions in the forums (or StackOverflow) and adapt it to your needs. Don't worry though, below, I provide a couple of complete code examples using recursive functions. For a 2-level deep menu, even a nested foreach would do. Going forward, this new method is what I recommend for building complex menus if using Menu Builder. The new method is called getMenuItems($menu, $type = 2, $options = null) takes 3 arguments. Before I show you the cool things you can do with this method, let's get familiar with the arguments. $menu: This is identical to the first argument in MarkupMenuBuilder's method render(): Use this argument to tell getMenuItems() the menu whose items you want returned. The argument takes a Page, id, title, name or array of menu items $type: Whether to return a normal array or a Menu object (WireArray) of menu items $options: Similar to render() method options but please note that only 3 options (from the list of those applicable to render()) apply to getMenuItems(). These are default_title, default_class and current_class_level. default_class is applied to the item's property $m['ccss_itemclass']. Probably not many know that MarkupMenuBuilder ships with a tiny but useful internal class called Menu. MenuBuilder uses it internally to build Menu objects that are finally used to build menus. Menu objects are WireArrays. If $type == 2, this is what is returned. Array vs WireArray So, which type of output should you return using getMenuItems()? Well, it depends on your needs. Personally, I'd go for the Menu object. Here's why: Although you can still easily build menus by using getMenuItems() to return a normal PHP Array, it's not nearly as powerful as returning and using a WireArray Menu object instead. Whichever type of items you return using getMenuItems(), it means you can manipulate or apply logic before or within a recursive function (or foreach loop) to each of your menu items. For instance, show some parts of the menu only to users who are logged in, or get extra details from a field of the page represented by the menu item, add images to your menu items, etc. Grabbing the Menu object means you can easily add some runtime properties to each Menu object (i.e. each menu item). If you went with a normal array, of course, you can also manipulate it, but not as easily as working with an object. A Menu object also means you have access to the powerful WireArray methods (don't touch sort though!). For instance, $menuItems->find("parentID=$m->id"). With a Menu object, you also get to avoid annoying isset(var) that come with arrays . Here are the properties that come with each Menu object. Use these to control your logic and output menu items values. In that block of code, to the left are the indices you'd get with a normal array. The values (to the right) are the Menu object properties. Below are examples of building the W3Bits 'CSS-only responsive multi-level menu' as illustrated in the tutorial by @Beluga. We use 3 different recursive functions to build the menu using items returned by getMenuItems(). I will eventually expound on and add the examples to my Menu Builder site. Meanwhile, here's a (very colourful) demo. Examples @note: The CSS is the one by @Beluga in the tutorial linked to above. @note: Clearer examples can be found in these gists. First, we grab menu items and feed those to our recursive functions. $mb = $modules->get('MarkupMenuBuilder');// get Menu Builder // get menu raw menu items. $menu can be a Page, an ID, a name, a title or an array #$menu = $pages->get(1299);// pass a Page #$menu = 1299;// pass an ID #$menu = 'main';// pass a name $jsonStr = $pages->get(1299)->menu_items; $arrayFromJSON = json_decode($jsonStr, true); #$menu = $arrayFromJSON;// pass an array $menu = 'Main';// pass a title /** grab menu items as WireArray with Menu objects **/ // for examples 1a, 2 and 3 $menuItems = $mb->getMenuItems($menu, 2, $options);// called with options and 2nd argument = 2 {return Menu (WireArray object)} #$menuItems = $mb->getMenuItems($menu);// called without options; 2nd argument defaults to 2 /** grab menu items as Normal Array with Menu items **/ // only for example 1b below menuItems2 = $mb->getMenuItems($menu, 1);// called without options; 2nd argument is 1 so return array Example 1a: Using some recursive function and a Menu object /** * Builds a nested list (menu items) of a single menu. * * A recursive function to display nested list of menu items. * * @access private * @param Int $parent ID of menu item. * @param Array $menu Object of menu items to display. * @param Int $first Helper variable to designate first menu item. * @return string $out. * */ function buildMenuFromObject($parent = 0, $menu, $first = 0) { $out = ''; $has_child = false; foreach ($menu as $m) { $newtab = $m->newtab ? " target='_blank'" : ''; // if this menu item is a parent; create the sub-items/child-menu-items if ($m->parentID == $parent) {// if this menu item is a parent; create the inner-items/child-menu-items // if this is the first child if ($has_child === false) { $has_child = true;// This is a parent if ($first == 0){ $out .= "<ul class='main-menu cf'>\n"; $first = 1; } else $out .= "\n<ul class='sub-menu'>\n"; } $class = $m->isCurrent ? ' class="current"' : ''; // a menu item $out .= '<li' . $class . '><a href="' . $m->url . '"' . $newtab . '>' . $m->title; // if menu item has children if ($m->isParent) { $out .= '<span class="drop-icon">▼</span>' . '<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($m->title) . '" onclick>▼</label>' . '</a>' . '<input type="checkbox" id="' . wire('sanitizer')->pageName($m->title) . '">'; } else $out .= '</a>'; // call function again to generate nested list for sub-menu items belonging to this menu item. $out .= buildMenuFromObject($m->id, $menu, $first); $out .= "</li>\n"; }// end if parent }// end foreach if ($has_child === true) $out .= "</ul>\n"; return $out; } Example 1b: Using some recursive function and a Menu array /** * Builds a nested list (menu items) of a single menu from an Array of menu items. * * A recursive function to display nested list of menu items. * * @access private * @param Int $parent ID of menu item. * @param Array $menu Array of menu items to display. * @param Int $first Helper variable to designate first menu item. * @return string $out. * */ function buildMenuFromArray($parent = 0, $menu, $first = 0) { $out = ''; $has_child = false; foreach ($menu as $id => $m) { $parentID = isset($m['parent_id']) ? $m['parent_id'] : 0; $newtab = isset($m['newtab']) && $m['newtab'] ? " target='_blank'" : ''; // if this menu item is a parent; create the sub-items/child-menu-items if ($parentID == $parent) {// if this menu item is a parent; create the inner-items/child-menu-items // if this is the first child if ($has_child === false) { $has_child = true;// This is a parent if ($first == 0){ $out .= "<ul class='main-menu cf'>\n"; $first = 1; } else $out .= "\n<ul class='sub-menu'>\n"; } $class = isset($m['is_current']) && $m['is_current'] ? ' class="current"' : ''; // a menu item $out .= '<li' . $class . '><a href="' . $m['url'] . '"' . $newtab . '>' . $m['title']; // if menu item has children if (isset($m['is_parent']) && $m['is_parent']) { $out .= '<span class="drop-icon">▼</span>' . '<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($m['title']) . '" onclick>▼</label>' . '</a>' . '<input type="checkbox" id="' . wire('sanitizer')->pageName($m['title']) . '">'; } else $out .= '</a>'; // call function again to generate nested list for sub-menu items belonging to this menu item. $out .= buildMenuFromArray($id, $menu, $first); $out .= "</li>\n"; }// end if parent }// end foreach if ($has_child === true) $out .= "</ul>\n"; return $out; } For example 1a and 1b we call the respective functions to output the menu <div id="content"> <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <?php // build menu from Menu object (example 1a) echo buildMenuFromObject(0, $menuItems); // OR build menu from array (example 1b) #echo buildMenuFromArray(0, $menuItems2); ?> </nav> </div> Example 2: Using a modified version of @mindplay.dk's recursive function /** * Recursively traverse and visit every child item in an array|object of Menu items. * * @param Menu item parent ID $parent to start traversal from. * @param callable $enter function to call upon visiting a child menu item. * @param callable|null $exit function to call after visiting a child menu item (and all of its children). * @param Menu Object|Array $menuItems to traverse. * * @see Modified From mindplay.dk https://processwire.com/talk/topic/110-recursive-navigation/#entry28241 */ function visit($parent, $enter, $exit=null, $menuItems) { foreach ($menuItems as $m) { if ($m->parentID == $parent) { call_user_func($enter, $m); if ($m->isParent) visit($m->id, $enter, $exit, $menuItems); if ($exit) call_user_func($exit, $m); } } } For example 2, we call the function (@note: a bit different from example 1 and 3) this way to output the menu <div id="content"> <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <?php echo "<ul class='main-menu cf'>"; visit( 0// start from the top items , // function $enter: <li> for a single menu item function($menuItem) { echo '<li><a href="' . $menuItem->url . '">' . $menuItem->title; if ($menuItem->isParent) { echo '<span class="drop-icon">▼</span>' . #'<label title="Toggle Drop-down" class="drop-icon" for="' . wire('sanitizer')->pageName($menuItem->title) . '" onclick>▼</label>' . '<label title="Toggle Drop-down" class="drop-icon" for="sm' . $menuItem->id . '" onclick>▼</label>' . '</a>' . #'<input type="checkbox" id="' . wire('sanitizer')->pageName($menuItem->title) . '"><ul class="sub-menu">' . '<input type="checkbox" id="sm' . $menuItem->id . '"><ul class="sub-menu">'; } else echo '</a>'; }// end function 1 ($enter) , #function $exit: close menu item <li> and sub-menu <ul> tags function($menuItem) { if ($menuItem->isParent) echo '</ul>'; echo '</li>'; }, $menuItems// the menu items (Menu objects in this example) ); ?> </nav> </div> Example 3: Using a modified version of @slkwrm's recursive function /** * Recursively traverse and visit every child item in an array|object of Menu items. * * @param Menu Object|Array $menuItems to traverse. * @param Int $parent ID to start traversal from. * @param Int $depth Depth of sub-menus. * @param Int $first Helper variable to designate first menu item. * @see Modified From @slkwrm * @return string $out. */ function treeMenu($menuItems, $parent, $depth = 1, $first = 0) { $depth -= 1; if ($first == 0){ $out = "\n<ul class='main-menu cf'>"; $first = 1; } else $out = "\n<ul class='sub-menu'>"; foreach($menuItems as $m) { if ($m->parentID == $parent) { $sub = ''; $out .= "\n\t<li>\n\t\t<a href='" . $m->url . "'>" . $m->title; if($m->isParent && $depth > 0 ) { $sub = str_replace("\n", "\n\t\t", treeMenu($menuItems, $m->id, $depth, $first)); $out .= '<span class="drop-icon">▼</span>' . '<label title="Toggle Drop-down" class="drop-icon" for="sm' . $m->id . '" onclick>▼</label>' . '</a>' . '<input type="checkbox" id="sm' . $m->id . '">' . $sub . "\n\t"; } else $out .= "</a>\n\t"; $out .="\n\t</li>"; } }// end foreach $out .= "\n</ul>"; return $out; } For example 3, we call the function to output the menu <div id="content"> <nav id="mainMenu"> <label for='tm' id='toggle-menu' onclick>Navigation <span class='drop-icon'>▼</span></label> <input id='tm' type='checkbox'> <?php //parameters: menuItems, menu item parent ID, depth, first (helper variable) echo treeMenu($menuItems, 0, 4); ?> </nav> </div>
-
MenuBuilder menu's are created from a JSON string that has info about each menu item: title, page_id, parent_id, etc...Easiest way to achieve this is to grab that JSON string, convert it into an array and use whatever recursive method tickles your fancy . Now that I think about it, I'll create a method in MB that just returns the JSON string or its array depending on the arguments you supply. That way you can have your cake and eat it too...like this guy did...
-
Accessing filesize property of $file in admin template
kongondo replied to ZGD's topic in API & Templates
No errors? You have debug on? Some code we could have a look at? -
Accessing filesize property of $file in admin template
kongondo replied to ZGD's topic in API & Templates
filesizeStr...does that work? Just fishing here since I don't know why filesize shouldn't work but other properties do... -
Welcome to ProcessWire and the forums... Here's a start: https://processwire.com/talk/topic/3579-tutorial-approaches-to-categorising-site-content/
-
api created occasionally broken thumbnail images
kongondo replied to dlen's topic in API & Templates
Seen such 'blank' images before. Happened when PHP run out of memory to process a big image. It always annoyed me that ImageSizer insisted on creating the blank image rather than giving up . About not being able to delete them...it means they were still in memory being processed, basically, in a crazy loop I suppose. So, check your memory, or your image size, or use $pages->uncacheAll() after each resizing or increase your set_time_limit(60)/ or 30 maybe, inside your loop to avoid timing out or a combination of all these tricks...With the latest ImageSizer though I think (?) such issues have been resolved...don't quote me though...haven't tested it yet -
@Bron, Apologies, my bad. I assumed too much . Hope you get an answer soon.
-
A couple of questions about the ProcessWire Form Builder
kongondo replied to Neo's topic in General Support
No idea but just throwing this out there...there's a free PaymentPaypal module...by Antti... Also there this thread: https://processwire.com/talk/topic/7373-paypal-integration-to-form-builder/ -
Welcome to the forums and ProcessWire @Bron... Home <= parent page of About About <= parent page of child 1 and child 2 Child 1 <= parent page of grandchild Grandchild Child 2 You might want to start with the docs
-
Page tree: Link titles should show template too (not just name)
kongondo replied to ottogal's topic in Wishlist & Roadmap
Don't know. You could ask at its support forum: https://processwire.com/talk/topic/2607-module-custom-page-list/ -
Page tree: Link titles should show template too (not just name)
kongondo replied to ottogal's topic in Wishlist & Roadmap
Not on hover, but I suppose you know you can view them always by specifying your settings in template -> advance -> List of fields to display.... -
Having trouble saving data from a post form?
kongondo replied to ZionBludd's topic in Getting Started
$message('your message');// or $error('error message'); $session->redirect('./') You may want to consider handling situations where the page was not successfully saved or other form errors occurred... -
Having trouble saving data from a post form?
kongondo replied to ZionBludd's topic in Getting Started
What is $u? The eror says $u is not an object...I am guessing you is for user? You also need to sanitize inputs before saving them, e.g. the 'lp_item' -
http://bfy.tw/5mfF : migrate site Please have a look at the results and let us know if you still have a specific need...
- 1 reply
-
- 1
-
Module Module: RuntimeMarkup Fieldtype & Inputfield
kongondo replied to kongondo's topic in Modules/Plugins
Thanks Macrura...had let this slip under the radar. I'll add it as an option so users get to choose (and why wouldn't they?) if they want the textarea formatted with ace or not...