Skip to content

Site Map

<h1>Site Map</h1>
  <?php /* $Id: inc_sitemap.php 1697 2008-06-18 11:21:57Z dylan $ */
  echo '<p>&nbsp;</p>';
$templateConstants = DisplayBase::getTemplateConstants();
  $siteId = $templateConstants['siteId'];
$pageManager = getStaticClass('ObjectManager');
  $pages = $pageManager->getObjectsForSiteMap($siteId);
  //$splitPages = divideArray($pages,3);
  $splitPages = divideArray($pages,2);
echo '<table id="sitemap" width="100%" border="0">';
  echo '<tr>';
  foreach ($splitPages as $column){
  //echo '<td valign="top" width="33%">';
  echo '<td valign="top" width="50%">';
  echo drawLinks($column, $templateConstants, $pageManager);
  echo '</td>';
  }
  echo '</tr>';
  echo '</table>';

function drawLinks($pages, &$templateConstants, &$pageManager){
  $html = '';
  $count = count($pages);
  if ($count){
  $previousLevel = 2;
  for ($i=0; $i<$count; $i++){
  $page = $pages[$i];
 if ($page['level'] < $previousLevel) $html .= str_repeat("</ul>\n", ($previousLevel - $page['level']));
  if ($page['level'] > $previousLevel) {
  if (($page['level'] % 2) == 1)$class = 'level1';
  elseif (($page['level'] % 3) == 1)$class = 'level2';
  elseif (($page['level'] % 4) == 1)$class = 'level3';
  else $class = 'level4';
  $html .= "<ul class=\"$class\">\n";
  }
 $html .= buildTargetLink($page, $templateConstants, $pageManager);
 $previousLevel = $page['level'];
  if (isset($pages[($i + 1)]) && ($pages[($i + 1)]['level'] == 2)) $html .= "<br /><br />\n";
  }
  }
  return $html;
  }

function divideArray($pages, $pieces){
  $divArray = array();
  for ($i=$pieces; $i>1; $i--){
  $pageCount = count($pages);
  $splitStart = floor($pageCount / $i);
  $splitIndex = findNearestTopObject($pages, $splitStart);
  $divArray[] = array_splice($pages, 0, $splitIndex);
  }
  $divArray[] = $pages;
  return $divArray;
  }

function findNearestTopObject($pages, $splitStart, $splitDistance=1){
  if ($pages[$splitStart]['level'] != 2){;
  $splitStart = $splitStart + $splitDistance;
  $splitDistance = (((abs($splitDistance) / $splitDistance) * -1) * (abs($splitDistance) + 1));
  $splitStart = findNearestTopObject($pages, $splitStart, $splitDistance);
  }
  return $splitStart;
  }

function buildTargetLink($page, &$templateConstants, &$pageManager) {
  $targetLink = $templateConstants['webRoot'];
  if (isPublishing()) {
  // external link has diff path, currently we have to pattern match to decipher between external/internal links
  if ($page['type'] == 'link' && preg_match('#http://#', $page['linkTarget']) && strlen($page['name'])) $targetLink .= $page['linkTarget'];
  else $targetLink .= $page['path'];
  }
  else {
  if ($page['type'] == 'link') {
  if (strlen($page['name'])) $targetLink .= $page['linkTarget'];
  else $targetLink .= '/template' . PHP_EXT . substr($page['linkTarget'], 1);
  }
  else $targetLink .= '/template' . PHP_EXT . '?cid=' . $page['cid'];
  }
 $html = '';
  if ($page['level'] > 2) $html .= "<li>";
  else if ($page['level'] == 2) $html .= "<b>";
 if (!strlen($page['name']) && $page['type'] == 'link') {
  $pageData = $pageManager->getIdsByPath($page['linkTarget']);
  //abort($templateConstants);
  $pageData = $pageManager->getObjectByCid($pageData['cid'], $templateConstants['siteId']);
  $page['name'] = $pageData['name'];
  }
 $html .= "<a href=\"$targetLink\">" . $page['name'] . "</a>";
  if ($page['level'] > 2) $html .= "</li>";
  else if ($page['level'] == 2) $html .= "</b>";
  $html .= "\n";
  return $html;
  }

?>
Author
J. Weir
Date Written:
Unknown
Version:
1697
Time:
.5 hours
Department(s):
Production

Sites using this template:

Comments: