Page 1 of 1

Modified NAV_TABLE_COLUMN

Posted: Thu 3. Jul 2008, 16:59
by johan_further
The below customisation has been tested in PHPWCMS v1.3.3.

I have searched for a way to customise the simple navigation functions provided by PHPWCMS to no avail. Primarily I wanted to be able to use the nice NAV_TABLE_COLUMN tag to create a context sensitive navigation menu (compare with NAV_LIST_CURRENT).

After going through the code I realised that the replacement tag comes with all information needed to make the appropriate adjustments with a minimum of new code and hazzle.

I have added three parameters (in your template or content you add the parameters by adding ":PARAMETER", as per usual):
CURRENT - This parameter limits the scope of the menu to only children of the current page.
PARENT - This parameter limits the scope of the menu to only children of the current page's parent.
CAT_PARENT - This parameter (probably the most useful one...) looks up the page's top parent closest to the root node of the site and displays only children of this page. This is used to create "section navigation".

By editing the file content.func.inc.php and searching for NAV_TABLE_COLUMN and adding the below lines, you make the replacement tag accept these three additional parameters to extend it's functionality.

To gain this extended functionality, replace the NAV_TABLE_COLUMN replacement section in your code with the following:

Code: Select all

// Left table based rollover navigation
// Replacement tag altered by Johan Strömquist, 2008-07-03
// Added:
//	CURRENT - display only children of current page
//	PARENT - display only children of the current page's parent
//	CAT_PARENT - display only children of the top level parent of the active site section
if(strpos($content["all"],'{NAV_TABLE_COLUMN') !== false) {
	$parent = $content["cat_id"];
	while ($parent) {
		$catParent = $parent;
		$parent = $content["struct"][$parent]["acat_struct"];
	}

	$content["all"] = str_replace('{NAV_TABLE_COLUMN:CURRENT}', '{NAV_TABLE_COLUMN:' . $content["cat_id"] . '}', $content["all"]);
	$content["all"] = str_replace('{NAV_TABLE_COLUMN:PARENT}', '{NAV_TABLE_COLUMN:' . $content["struct"][$content["cat_id"]]["acat_struct"] . '}', $content["all"]);
	$content["all"] = str_replace('{NAV_TABLE_COLUMN:CAT_PARENT}', '{NAV_TABLE_COLUMN:' . $catParent . '}', $content["all"]);
	
	$content["all"] = str_replace('{NAV_TABLE_COLUMN}', '{NAV_TABLE_COLUMN:0}', $content["all"]);
	$replace = 'nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);';
	$content["all"] = preg_replace('/\{NAV_TABLE_COLUMN:(\d+)\}/e', $replace, $content["all"]);
}
Please use this code at your own discretion and if anyone has got a different way of accomplishing what this code does or have suggestions for improvement, please let me know.

Re: Modified NAV_TABLE_COLUMN

Posted: Thu 3. Jul 2008, 17:24
by flip-flop
Hi,

Mhh, why you don´t use the new standard - NAV_LIST_UL :?:

NAV_TABLE_COLUMN is a little bit unstable in new releases and it is an old table based navigation.

Knut

Re: Modified NAV_TABLE_COLUMN

Posted: Fri 4. Jul 2008, 09:11
by johan_further
Thanks Knut! The simple answer is "because I didn't know it existed".

I have now browsed the forum a bit to find more information about it but it seems mostly to be spread out in bits and pieces. Is there a page or post anywhere that I have missed that describes the tag and it's parameters more extensively? So far I'm not really sure how to use it.

In addition to this, is it possible to set the NAV_LIST_UL to display the children of the sections root no matter where in the section you are?

Example structure:
HOME
PageA1
PageA1:1
PageA1:2
PageA2:1
PageB1
PageB1:1
PageB1:2
PageB2:1

Is it possible here to let configure the tag to display the children of PageA1 or PageB1 respectively, no matter where in A or B you are at the moment? That was the purpose of the CAT_PARENT parameter I provided and it's the functionality that I am using in the particular project I am working on. I am very interested in replacing it if there is a current working "standard" alternative, such as the NAV_LIST_UL.

Re: Modified NAV_TABLE_COLUMN

Posted: Fri 4. Jul 2008, 09:37
by update
johan_further wrote:Is there a page or post anywhere
Yes there is:

Re: Modified NAV_TABLE_COLUMN

Posted: Fri 4. Jul 2008, 10:42
by flip-flop
Please: http://forum.phpwcms.org/viewtopic.php?t=12165
Is it possible here to let configure the tag to display the children of PageA1 or PageB1 respectively, no matter where in A or B you are at the moment?
Yes it is, have a look:

@string $parameter =
"menu_type, start_id, max_level, class_path, class_active, ul_id_name, wrap_ul_div(0 = off, 1 = <div>, 2 = <div id="">), wrap_link_text(<em>|</em>)"

E.g. standard, active path unfolded (F):
{NAV_LIST_UL:F, ID, max_level, act_path, active,,,}

E.g. with parent output (P) and active path unfolded (F):
{NAV_LIST_UL:FP, ID, max_level, act_path, active,,,}

E.g. without active path unfolded (all opened):
{NAV_LIST_UL:, ID, max_level, act_path, active,,,}

E.g. parent output (P) without active path unfolded:
{NAV_LIST_UL:P, ID, max_level, act_path, active,,,}

Where ID is the start ID of your category e.g. Home = 0
and max_level is the desired depth of your structure.
act_path, active are class names.

Knut

Re: Modified NAV_TABLE_COLUMN

Posted: Fri 4. Jul 2008, 13:45
by johan_further
Thanks for these simple examples! They really made it easier to understand the NAV_LIST_UL.

Does this mean that I would have to set the ID of the start node statically in my configuration of the tag?

This would mean that I need:
1. a template for each category and set the ID to the category parent, or
2. to add the tag in a content block for each article where I want the menu to appear and there set the ID to the category parent.

If this is indeed as I understand it, the NAV_LIST_UL is a perfect replacement to the first two arguments I created ("CURRENT" and "PARENT"), but it does not provide a simple way to dynamically render the menu using one template and provide the list of category children only.

I fully understand that what I am describing is nothing but a curious exception to what people normally want to accomplish. I am not saying it as a critique to the NAV_LIST_UL tag but am merely interested in knowing whether this new tag is capable of providing this tailored functionality without any additional tweaking.

MY_NAV_LIST_UL special

Posted: Fri 4. Jul 2008, 17:44
by flip-flop
I am not saying it as a critique to the NAV_LIST_UL tag but am merely interested in knowing whether this new tag is capable of providing this tailored functionality without any additional tweaking
I have discussed this extra featuring with O.G. long time ago. We arrived at the conclusion, that this tag has more than enough capabilities to generate a navigation. (With one eye ever looking to the behavior in relation to the runtime).
Special wishes like yours can easily solved with a little php snippet in the /frontend_render/ folder.

Pleaser have a look to this fast programmed solution without any hack (every update is killing your script):

Put this snippet into a new file /template/inc_script/frontend_render/rt_MY_NAV_LIST_UL.php
Set in conf.inc.php
$phpwcms['allow_ext_render'] = 1; //allow including of custom external scripts at frontend rendering

Code: Select all

<?php
/* ======================================================================
 <UL> <LI> based rollover navigation
 Replacement tag altered by Johan Strömquist, 2008-07-03
 Added:
  CURRENT - display only children of current page
  PARENT - display only children of the current page's parent
  CAT_PARENT - display only children of the top level parent of 
	             the active site section

  Enhanced 08/07/04: For NAV_LIST_UL by flip-flop (KH)
  http://forum.phpwcms.org/viewtopic.php?p=105841#p105841
  ======================================================================= */
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------

if(strpos($content["all"],'{MY_NAV_LIST_UL') !== false) { // TAG in use ?

	$x_current    = $content["cat_id"];  // current ID
	$x_parent     = $content["struct"][$x_current]["acat_struct"]; // parent ID
	$x_specParent = $x_current;          // special parent ID to find catParent
	$x_catParent  = '';                  // cat_parent ID
	
	$x_class_01   = '<div class="nlu_navi1">';  // Formating the output 
	$x_class_02   = '</div>';

   while ($x_specParent) {  // searching for the right catParent ID?
      $x_catParent = $x_specParent;
      $x_specParent = $content["struct"][$x_specParent]["acat_struct"];
   }
// Test: 
// echo 'current: '.$x_current .'  /  parent: '.$x_parent.'  /  catParent: '.$x_catParent.'  /  specParent: '.$x_specParent.'<br>';

   // new nav string as a function of current/parent/cat_parent
   $x_str_nav = array("current"=>trim(buildCascadingMenu( 'F,'. $x_current   . ',1,act_path,active' )),
                       "parent"=>trim(buildCascadingMenu( 'F,'. $x_parent    . ',2,act_path,active' )),
                    "catParent"=>trim(buildCascadingMenu( 'F,'. $x_catParent . ',2,act_path,active' ))
                        );

   $content["all"] = str_replace('{MY_NAV_LIST_UL:CURRENT}',    $x_class_01 .$x_str_nav["current"]  .$x_class_02, $content["all"]);
   $content["all"] = str_replace('{MY_NAV_LIST_UL:PARENT}',     $x_class_01 .$x_str_nav["parent"]   .$x_class_02, $content["all"]);
   $content["all"] = str_replace('{MY_NAV_LIST_UL:CAT_PARENT}', $x_class_01 .$x_str_nav["catParent"].$x_class_02, $content["all"]);

}
?>
buildCascadingMenu( 'F, start_level_id, depth, act_path, active' )
is exactly the same as {NAV_LIST_UL: F,start_level_id, depth, act_path, active}
but build with php function behind.
---------------

Call in your template e.g.:

{MY_NAV_LIST_UL:CURRENT} or/and
{MY_NAV_LIST_UL:PARENT} or/and
{MY_NAV_LIST_UL:CAT_PARENT}

---------------
Do you see the great potentialities of the /frontend_render/ folder?
Every file ...../frontend_render/*.php is parsed by the system during the rendering process of the page. ........
You can manipulate the output before the site is delivered to the browser by own tags or little/big php snippets.
Thats one of the most powerfull features in this system. - Manipulation of the output without any core hack.

Have a short look and test:

Code: Select all

echo 'Var Dump ===================';
echo '<pre>LEVEL ID</pre>';
dumpVar($GLOBALS['LEVEL_ID']);
echo '<pre>LEVEL KEY</pre>';
dumpVar($GLOBALS['LEVEL_KEY']);
echo '<pre>LEVEL STRUCT</pre>';
dumpVar($GLOBALS['LEVEL_STRUCT']);
echo 'END Dump =================== <br /> ';


echo 'Articles Dump =================== <br /> ';
dumpVar($GLOBALS['content']["articles"]); // article-structure

echo 'Structure Dump =================== <br /> ';
dumpVar($GLOBALS['content']["struct"]);   // category-structure
// and many more .......

echo '====================== <br /> ';
(New cms version available at: http://code.google.com/p/phpwcms/downloads/list
-> and the newest dev revisions http://code.google.com/p/phpwcms/source/list)

Knut :D

Re: Modified NAV_TABLE_COLUMN

Posted: Mon 7. Jul 2008, 08:12
by johan_further
Beautiful! Love at first sight.

I'll implement this right away and get back with any additional thoughts as soon as I've tried this approach out properly.

Re: Modified NAV_TABLE_COLUMN

Posted: Tue 8. Jul 2008, 10:56
by johan_further
Wonderful!

I've now implemented and properly tested the NAV_LIST_UL with a couple of modifications to your suggested stylesheet, and it looks great!

What I'm even more impressed with however, is the power of the frontend_render folder. It is a brilliant way to make it possible to include tailored functionality and to keep the core nicely black boxed. Cudos Oliver!

I will probably produce a couple of replacement tags of my own, now that I know how simple it is. And the best thing is that I will be able to neatly package them and reuse them through version upgrades. :D

Thanks a lot for the help Knut!

Re: Modified NAV_TABLE_COLUMN

Posted: Tue 8. Jul 2008, 11:02
by jscholtysik
Hi,

the community is always searching for new and useful Replacement Tags... ;-), so please feel free to share them with us...


Joachim

Re: Modified NAV_TABLE_COLUMN

Posted: Tue 8. Jul 2008, 11:27
by flip-flop
Have a look into the folder .../frontend_render/disabled/*
There you will find some example snippets.

Most basic functions you will find in /include/inc_front/front.func.inc.php (content.func.inc.php, .....).
This is a little framework for phpwcms.

Another example with a call of a basic function {SHOW_CONTENT:.....} and a little bit sql: http://forum.phpwcms.org/viewtopic.php?p=102798#p102798

In most CP (ContentPart) templates there is a option too for implementing your own php or JS snippets.
Example: /template/inc_cntpart/imagespecial/slider.php.

I hope I don´t overrun your mind with this lot of informations. :wink:

Knut :D

Re: Modified NAV_TABLE_COLUMN

Posted: Tue 8. Jul 2008, 15:12
by johan_further
No worries - I am not easily drowned. :)

One question arises; What's the easiest way to get access to the replacement tag parameters? Do I parse the replacement tag expression with a regexp or is there some easier way to get access to them?

Ex.

{ARTICLE_LIST_BY_DATE:5:NOW} - How do I access the 5 and the 'NOW'? Would I simply use an explode on ':' and grab them from the resulting array, or is there a better way?

My next tag will be an article list that will only display article summaries for articles with a date in a header or other > than the date supplied in the parameter. The purpose is to create an event calendar list with only relevant events / articles (events occuring in the future), completely based on articles.

If I'm reinventing the wheel here I'd be very happy to know. :)

Re: Modified NAV_TABLE_COLUMN

Posted: Tue 8. Jul 2008, 15:29
by juergen
like this:

Code: Select all

$content["all"] = preg_replace('/\{BLABLABLA:(.*?):(.*?)\}/ie', 'bla("$1","$2")', $content["all"]);
where Replacement is:

Code: Select all

{BLABLABLA:1:phpwcms}

and we come in PHP with that:

Code: Select all

function bla($one,$two) {.......}
Regular Expressions for the decode of the Substitution.....

as you can see, this construct needs a returned value ... something like:

$a='Hello';
$a.=' World';
return $a;


and this value is the replaced text or whatelese...

Re: Modified NAV_TABLE_COLUMN

Posted: Tue 8. Jul 2008, 17:38
by johan_further
That worked wonders, thanks! :D

I've made another post explaining my event calendar a bit more in detail and posted my code there as well, including my implementation of your regexp:
http://forum.phpwcms.org/viewtopic.php?f=8&t=17466

Thanks for all your help guys! It has so far made all the difference!