PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/cms/breadcrumbs.lib.php

https://github.com/jithinkr/pragyan
PHP | 91 lines | 53 code | 12 blank | 26 comment | 9 complexity | 4d520ee1fadb2aaab4df3cafe44c3d88 MD5 | raw file
  1. <?php
  2. if(!defined('__PRAGYAN_CMS'))
  3. {
  4. header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
  5. echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
  6. echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
  7. exit(1);
  8. }
  9. /**
  10. * @package pragyan
  11. * @author Ankit Srivastava
  12. * @copyright (c) 2010 Pragyan Team
  13. * @license http://www.gnu.org/licenses/ GNU Public License
  14. * For more details, see README
  15. */
  16. /**
  17. * breadcrumbs.lib.php
  18. * To generate the bread crumbs required to show the location of the page with links to each level.
  19. * Generate breadcrumbs for a given page
  20. *
  21. * @param $pageIdArray Array of integers holding the page ids of the pages constituting the path to the current page
  22. * @param $separator The string with which Items in the generated breadcrumbs should be separated
  23. * @return HTML string representing the breadcrumbs to be displayed for the given page
  24. */
  25. function breadcrumbs($pageIdArray) {
  26. $sqlOutputArray = array();
  27. $pageIdList = join($pageIdArray, ",");
  28. $query = 'SELECT `page_id`, `page_name`, `page_title` FROM `' . MYSQL_DATABASE_PREFIX . 'pages` WHERE `page_id` IN (' . $pageIdList . ')';
  29. $resultId = mysql_query($query);
  30. while ($row = mysql_fetch_assoc($resultId))
  31. $sqlOutputArray[$row['page_id']] = array($row['page_name'], $row['page_title']);
  32. global $urlRequestRoot;
  33. $str = '<div id="cms-breadcrumb"><ul>';
  34. $hrefString = $urlRequestRoot . '/home/';
  35. $parentPath = '/';
  36. $pageCount = count($pageIdArray);
  37. global $userId;
  38. $children = getChildren($pageIdArray[$pageCount - 1], $userId);
  39. $selectedId = $pageCount - 1;
  40. if ($pageCount == 1) {
  41. $selectedId = 0;
  42. $children = getChildren(0, $userId);
  43. }
  44. $showSubmenu = showBreadcrumbSubmenu();
  45. for ($i = 0; $i < $pageCount; ++$i) {
  46. if ($i) {
  47. $hrefString .= $sqlOutputArray[$pageIdArray[$i]][0] . '/';
  48. $parentPath .= $sqlOutputArray[$pageIdArray[$i]][0] . '/';
  49. }
  50. $str .= '<li class="cms-breadcrumbItem';
  51. if ($i == $selectedId)
  52. $str .= ' selected';
  53. $str .= '" rel="' . $parentPath . '"><span><a href="' . $hrefString . '"><div>' . $sqlOutputArray[$pageIdArray[$i]][1] . '</div></a></span>';
  54. if($showSubmenu)
  55. $str .= generateSubmenu($pageIdArray[$i],$hrefString);
  56. $str .= '</li>';
  57. }
  58. $str .= '</ul></div>';
  59. /* if()
  60. {
  61. $childCount = count($children);
  62. $childHtml = "";
  63. for ($i = 0; $i < $childCount; ++$i)
  64. $childHtml .= '<li><a href="' . ($selectedId == 0 ? $urlRequestRoot . '/home/' : './') . $children[$i][1] . '">' . $children[$i][2] . '</a></li>';
  65. $childHtml = "<ul>$childHtml</ul>";
  66. $str .= '<div id="cms-breadcrumbsubmenu">' . $childHtml . '<div class="clearer"></div></div>';
  67. }*/
  68. return $str;
  69. }
  70. function generateSubmenu($pageId, $parentPath) {
  71. $ret = '<div class="cms-breadcrumbsubmenu"><ul>';
  72. global $userId;
  73. $children = getChildren($pageId,$userId);
  74. foreach($children as $child)
  75. $ret .= "<li><span><a href='{$parentPath}{$child[1]}'>{$child[2]}</a></span></li><br>";
  76. $ret .= '</ul></div>';
  77. return $ret;
  78. }