wayfinder.snippet.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Wayfinder Snippet to build site navigation menus
  4. *
  5. * Totally refactored from original DropMenu nav builder to make it easier to
  6. * create custom navigation by using chunks as output templates. By using
  7. * templates, many of the paramaters are no longer needed for flexible output
  8. * including tables, unordered- or ordered-lists (ULs or OLs), definition lists
  9. * (DLs) or in any other format you desire.
  10. *
  11. * @version 2.1.1-beta5
  12. * @author Garry Nutting (collabpad.com)
  13. * @author Kyle Jaebker (muddydogpaws.com)
  14. * @author Ryan Thrash (modx.com)
  15. * @author Shaun McCormick (modx.com)
  16. * @author Jason Coward (modx.com)
  17. *
  18. * @example [[Wayfinder? &startId=`0`]]
  19. *
  20. * @var modX $modx
  21. * @var array $scriptProperties
  22. *
  23. * @package wayfinder
  24. */
  25. $wayfinder_base = $modx->getOption('wayfinder.core_path',$scriptProperties,$modx->getOption('core_path').'components/wayfinder/');
  26. /* include a custom config file if specified */
  27. if (isset($scriptProperties['config'])) {
  28. $scriptProperties['config'] = str_replace('../','',$scriptProperties['config']);
  29. $scriptProperties['config'] = $wayfinder_base.'configs/'.$scriptProperties['config'].'.config.php';
  30. } else {
  31. $scriptProperties['config'] = $wayfinder_base.'configs/default.config.php';
  32. }
  33. if (file_exists($scriptProperties['config'])) {
  34. include $scriptProperties['config'];
  35. }
  36. /* include wayfinder class */
  37. include_once $wayfinder_base.'wayfinder.class.php';
  38. if (!$modx->loadClass('Wayfinder',$wayfinder_base,true,true)) {
  39. return 'error: Wayfinder class not found';
  40. }
  41. $wf = new Wayfinder($modx,$scriptProperties);
  42. /* get user class definitions
  43. * TODO: eventually move these into config parameters */
  44. $wf->_css = array(
  45. 'first' => isset($firstClass) ? $firstClass : '',
  46. 'last' => isset($lastClass) ? $lastClass : 'last',
  47. 'here' => isset($hereClass) ? $hereClass : 'active',
  48. 'parent' => isset($parentClass) ? $parentClass : '',
  49. 'row' => isset($rowClass) ? $rowClass : '',
  50. 'outer' => isset($outerClass) ? $outerClass : '',
  51. 'inner' => isset($innerClass) ? $innerClass : '',
  52. 'level' => isset($levelClass) ? $levelClass: '',
  53. 'self' => isset($selfClass) ? $selfClass : '',
  54. 'weblink' => isset($webLinkClass) ? $webLinkClass : ''
  55. );
  56. /* get user templates
  57. * TODO: eventually move these into config parameters */
  58. $wf->_templates = array(
  59. 'outerTpl' => isset($outerTpl) ? $outerTpl : '',
  60. 'rowTpl' => isset($rowTpl) ? $rowTpl : '',
  61. 'parentRowTpl' => isset($parentRowTpl) ? $parentRowTpl : '',
  62. 'parentRowHereTpl' => isset($parentRowHereTpl) ? $parentRowHereTpl : '',
  63. 'hereTpl' => isset($hereTpl) ? $hereTpl : '',
  64. 'innerTpl' => isset($innerTpl) ? $innerTpl : '',
  65. 'innerRowTpl' => isset($innerRowTpl) ? $innerRowTpl : '',
  66. 'innerHereTpl' => isset($innerHereTpl) ? $innerHereTpl : '',
  67. 'activeParentRowTpl' => isset($activeParentRowTpl) ? $activeParentRowTpl : '',
  68. 'categoryFoldersTpl' => isset($categoryFoldersTpl) ? $categoryFoldersTpl : '',
  69. 'startItemTpl' => isset($startItemTpl) ? $startItemTpl : ''
  70. );
  71. /* process Wayfinder */
  72. $output = $wf->run();
  73. if ($wf->_config['debug']) {
  74. $output .= $wf->renderDebugOutput();
  75. }
  76. /* output results */
  77. if ($wf->_config['ph']) {
  78. $modx->setPlaceholder($wf->_config['ph'],$output);
  79. } else {
  80. return $output;
  81. }