lib.mod.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. # Recherche d'un mode, des id, tout ça
  23. # Fix a bug in PHP 4.1 with queries like ?arg (and no value)
  24. function rebuildQuery()
  25. {
  26. if (!empty($_SERVER['QUERY_STRING']))
  27. {
  28. $q = explode('&',$_SERVER['QUERY_STRING']);
  29. $T = array();
  30. foreach ($q as $v)
  31. {
  32. $t = explode('=',$v);
  33. if (empty($t[1])) {
  34. $t[1] = '0';
  35. }
  36. $T[] = $t[0].'='.$t[1];
  37. }
  38. return implode('&',$T);
  39. }
  40. return '';
  41. }
  42. function dcGetMod()
  43. {
  44. $args = '';
  45. if (!empty($_GET['q'])) {
  46. return 'search';
  47. }
  48. # Méthode de scan des URL
  49. if (dc_url_scan == 'path_info') {
  50. if (preg_match('/^'.preg_quote(dc_blog_url,'/').'(.*)$/',$_SERVER['REQUEST_URI'],$match)) {
  51. $args = preg_replace('/^[\/]?(.*?)[\/]?$/','$1',$match[1]);
  52. }
  53. } elseif (dc_url_scan == 'query_string' && !empty($_SERVER['QUERY_STRING'])) {
  54. parse_str(rebuildQuery(),$qs);
  55. $qs = array_keys($qs);
  56. if ($_GET[$qs[0]] == '') {
  57. $args = $qs[0];
  58. unset($_GET[$qs[0]]);
  59. unset($_REQUEST[$qs[0]]);
  60. }
  61. } else {
  62. $args = '';
  63. }
  64. if ($args != '' && preg_match('!^([a-z]{2}(-[a-z]{2})?)(/(.*)|\z)$!',$args,$match)) {
  65. $_GET['l'] = $match[1];
  66. $args = (!empty($match[4])) ? $match[4] : '';
  67. }
  68. if($args != '')
  69. {
  70. if(preg_match('!^([0-9]{4}/[0-9]{2})(/|\z)!',$args,$match))
  71. {
  72. $_GET['d'] = $match[1];
  73. if(preg_match('!^([0-9]{4}/[0-9]{2}/[0-9]{2})(/|\z)!',$args,$match))
  74. {
  75. $_GET['d'] = $match[1];
  76. if(preg_match('!^[0-9]{4}/[0-9]{2}/[0-9]{2}/([0-9]+)!',$args,$match))
  77. {
  78. $_GET['p'] = $match[1];
  79. }
  80. }
  81. }
  82. elseif(preg_match('!^([A-Z][A-Za-z0-9_-]*)([^/]*)?(/|\z)!',$args,$match))
  83. {
  84. $_GET['cat'] = $match[1];
  85. if(preg_match('!^[A-Z][A-Za-z0-9_-]*([^/]*?)/([0-9]{4}/[0-9]{2})!',$args,$match))
  86. {
  87. $_GET['d'] = $match[2];
  88. if(preg_match('!^[A-Z][A-Za-z0-9_-]*([^/]*)?/([0-9]{4}/[0-9]{2}/[0-9]{2})!',$args,$match))
  89. {
  90. $_GET['d'] = $match[2];
  91. }
  92. }
  93. }
  94. }
  95. $GLOBALS['dc_args'] = $args;
  96. if (!empty($_GET['p'])) {
  97. return 'post';
  98. } elseif (!empty($_GET['d']) && strlen($_GET['d']) == 10) {
  99. return 'day';
  100. } elseif (!empty($_GET['d']) && strlen($_GET['d']) == 7) {
  101. return 'month';
  102. } elseif (!empty($_GET['cat'])) {
  103. return 'cat';
  104. } else {
  105. return 'home';
  106. }
  107. }
  108. ?>