Use GT-Mod for navigation with frontend-render

If you have created additional (non official) documentation or tutorials or something like that please post this here
Post Reply
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Use GT-Mod for navigation with frontend-render

Post by metti »

Hello guys,

Do you want to have a image based navigation like here http://www.netzelf.de or here: http://www.hoerspiel-leipzig.de

(it's a category-based navigation)

So you can do this in your phpwcms-installation:
  • Create a empty php-file in template/inc_script/frontend_render and name it how you want.
    Write this code to the new file:

Code: Select all

<?php

// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------

$rp_tag = "{MY_LEVEL_NAV}";

if( ! ( strpos($content["all"],$rp_tag)===false ) ) {
	
	$gt_link_style   = "navi";
	$gt_hover_style  = "navi_hover"; //Leave it empty if no Hover-Style is needed
	$gt_active_style = "navi_active";
	$use_title       = 0;
  $cat_before      = "";
	$cat_after       = "";
	$cat_between     = '<img src="img/leer.gif" border="0" width="18" height="1" alt="" />';
	$cat_transform   = 2; // 0=none 1=lowercase 2=uppercase
  $link_attributes = ""; //additional attributes for the link-tag eg. ' target="_blank" class="link_nav"'
  $img_attributes  = ""; //additional attributes for the image-tag eg. ' border="0" class="img_nav"'
  
  $struct = getStructureChildData(0);
  foreach($struct as $value) {
      if ($cat_transform == 2)
      {
        $name = strtoupper($value["acat_name"]);
      }elseif ($cat_transform == 2)
      {
        $name = strtolower($value["acat_name"]);
      }else
      {
        $name = $value["acat_name"];
      }
      $string .= ($value["acat_id"] == $GLOBALS["content"]["cat_id"]) ? "{im:".$value["acat_alias"]."}{GT:".$gt_active_style."}".$name."{/GT}{/im}" : "{im:".$value["acat_alias"]."}{GT:".$gt_link_style."}".$name."{/GT}{/im}";
      if (!empty($gt_hover_style))
      {
        $string .= "{imh:".$value["acat_alias"]."}{GT:".$gt_hover_style."}".$name."{/GT}{/imh}";
      }
	}
	$content["all"] .= $string;
  require_once ('include/inc_module/mod_graphical_text/inc_front/gt.func.inc.php');
  $phpwcms["gt_mod"] = false;
  $content["all"] = preg_replace_callback('/\{im:(.+?)\}<img src="(.*?)" alt="(.*?)" title="(.*?)" width="(.*?)" height="(.*?)" border="0" \/>\{\/im\}/is', 'get_link_img', $content["all"]);
	if (!empty($gt_hover_style))
	{
    $content["all"] = preg_replace_callback('/\{imh:(.+?)\}<img src="(.*?)" alt="(.*?)" title="(.*?)" width="(.*?)" height="(.*?)" border="0" \/>\{\/imh\}/is', 'get_hover_img', $content["all"]);
  }
  $idi = 0;
  foreach ($GLOBALS["img_nav"] as $img)
  {
    if (!empty($gt_hover_style))
    {
      $js .= "      image_url[$idi] = '".$img["hsrc"]."';\n";
      $cat_behaviour = " onmouseover=\"switch_img($idi);\" onmouseout=\"switch_img($idi);\"";
    }
    $cat = $cat_before.'<a href="index.php?'.$id.'"'.$cat_behaviour.$link_attributes.'><img src="'.$img["src"].'" alt="'.$img["name"];
    $cat .= ($use_title) ? '" title="'.$img["name"] : "";
    $img_link[] = $cat.'" width="'.$img["width"].'" height="'.$img["height"].'"'.$img_attributes." id=\"img_nav_$idi\" /></a>$cat_after";
    $idi++;
  }
  $idi--;
  $img_link = implode($cat_between, $img_link);
	$content["all"] = str_replace($rp_tag, $img_link, $content["all"]);
	if (!empty($gt_hover_style)) {
  $block["htmlhead"] .= '<script type="text/javascript">
  <!--

    if (document.images)
    {
      preload_image_object = new Image();
      image_url = new Array();
'.$js.'
       var i = 0;
       for(i=0; i<='.$idi.'; i++) 
         preload_image_object.src = image_url[i];
    }
    exc_img = new Array(); exc_img[0] = -1;
    function switch_img(id) {
      if (exc_img[0] == id) {
        document.getElementById("img_nav_" + id).src = exc_img[1];
        exc_img[0] = -1;
      }else{
        exc_img[0] = id;
        exc_img[1] = document.getElementById("img_nav_" + id).src;
        document.getElementById("img_nav_" + id).src = image_url[id];
      }
    }

    //-->
</script>';
  }
}
function get_link_img($matches) {
  $GLOBALS["img_nav"][$matches[1]]["name"] = $matches[3];
  $GLOBALS["img_nav"][$matches[1]]["src"] = $matches[2];
  $GLOBALS["img_nav"][$matches[1]]["width"] = $matches[5];
  $GLOBALS["img_nav"][$matches[1]]["height"] = $matches[6];
  return "";
}
function get_hover_img($matches) {
  $GLOBALS["img_nav"][$matches[1]]["hsrc"] = $matches[2];
  return "";
}
?>
  • -Create GT-Styles for link, hover and active and change the names for the Styles in the script.
    -Use {MY_LEVEL_NAV} or the tag you specified whereever you want in your template.
    -READY
Hope this will help you ;)

Changed because of a useless function: foreach ($GLOBALS["img_nav"] as $id => $img) is now foreach ($GLOBALS["img_nav"] as $img)
Last edited by metti on Thu 24. Jan 2008, 15:09, edited 1 time in total.
#GeorgeWBush { position:absolute; bottom:-6ft; }
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

WOWA
Methinks
Metti will become
phpWcms superstar
http://www.hoerspiel-leipzig.de
nice -- very nice
plenty of discussion to result.....
:D
User avatar
heliotrope
Posts: 33
Joined: Fri 14. Sep 2007, 15:21

Re: Use GT-Mod for navigation with frontend-render

Post by heliotrope »

very cool mod , Metti !!!
Works fine but each link point to "index.php?" , not the the category ...
Is that because I have sub-categories ??
Is there something special to add in the .php file ?????
User avatar
heliotrope
Posts: 33
Joined: Fri 14. Sep 2007, 15:21

Re: Use GT-Mod for navigation with frontend-render

Post by heliotrope »

metti wrote:
Changed because of a useless function: foreach ($GLOBALS["img_nav"] as $id => $img) is now foreach ($GLOBALS["img_nav"] as $img)
Well, I left the "useless function" instead of your update:

Code: Select all

foreach ($GLOBALS["img_nav"] as $id => $img)
and it seems to be ok ...I get to good link for each cat .
User avatar
metti
Posts: 81
Joined: Tue 28. Nov 2006, 07:34
Location: Merseburg
Contact:

Re: Use GT-Mod for navigation with frontend-render

Post by metti »

Yes. It should work without problems, but someone wrote me a pm, that the script did not work for him, because of an error caused by this "useless function". So there you are ;)

Edit: There's nothing to change in any .php. You should simply give alias to the category-items you want to be seen and to work in nav-listing (thatswhy you only see |index.php?| because if there was an alias for this, it would be index.php?alias). Hope this helps
#GeorgeWBush { position:absolute; bottom:-6ft; }
Post Reply