PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_sef2/sef.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 152 lines | 121 code | 12 blank | 19 comment | 19 complexity | 693b9834ca6f2d2a4672a1b75590df68 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * SEF module for Joomla!
  4. *
  5. * @author $Author: michal $
  6. * @copyright ARTIO s.r.o., http://www.artio.cz
  7. * @package JoomSEF
  8. * @version $Name$, ($Revision: 4994 $, $Date: 2005-11-03 20:50:05 +0100 (??t, 03 XI 2005) $)
  9. */
  10. // Security check to ensure this file is being included by a parent file.
  11. if (!defined('_VALID_MOS')) die('Direct Access to this location is not allowed.');
  12. $debug = 0;
  13. // IIS patch.
  14. if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
  15. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
  16. }
  17. // OpenSEF patch.
  18. define('_OPENSEF', 1);
  19. if ($mosConfig_sef) {
  20. // VirtueMart redirection hack
  21. if( file_exists($GLOBALS['mosConfig_absolute_path'].'/components/com_virtuemart/virtuemart.php') ) {
  22. @session_start();
  23. $_SESSION['vmhack'] = 1;
  24. }
  25. $sefDirAdmin = $GLOBALS['mosConfig_absolute_path'].'/administrator/components/com_sef/';
  26. // Load language file.
  27. if (file_exists($sefDirAdmin.'language/'.$mosConfig_lang.'.php')){
  28. include($sefDirAdmin.'language/'.$mosConfig_lang.'.php');
  29. }
  30. else {
  31. include($sefDirAdmin.'language/english.php');
  32. }
  33. // load config data
  34. $sef_config_class = $sefDirAdmin.'sef.class.php';
  35. $sef_config_file = $sefDirAdmin.'config.sef.php';
  36. if (!is_readable($sef_config_file)) die(_COM_SEF_NOREAD."($sef_config_file)<br />"._COM_SEF_CHK_PERMS);
  37. if (is_readable($sef_config_class)) require_once($sef_config_class);
  38. else die(_COM_SEF_NOREAD."( $sef_config_class )<br />"._COM_SEF_CHK_PERMS);
  39. $sefConfig = new SEFConfig();
  40. // load checksums
  41. $license = trim(@file_get_contents($sefDirAdmin.'signature.b64'));
  42. $checksum = trim(@file_get_contents($sefDirAdmin.'checksum.md5'));
  43. $checkstr = '';
  44. $checkA = array_fill(0, 4, '');
  45. $checkA = explode('-', $license);
  46. foreach ($checkA as $id => $checkpart) {
  47. $checkA[$id] = base64_decode($checkpart);
  48. $checkstr .= $checkA[$id];
  49. }
  50. $sefConfig->enabled &= ($checksum == md5($checkstr));
  51. // check for kind of SEF or no SEF at all
  52. // test if this is Joomla! style URL
  53. if (strstr($_SERVER['REQUEST_URI'], 'index.php/content/')
  54. || strstr($_SERVER['REQUEST_URI'], '/content/')
  55. || strstr($_SERVER['REQUEST_URI'], 'index.php/component/option,')
  56. || strstr($_SERVER['REQUEST_URI'], '/component/option,')) {
  57. require_once('functions.php');
  58. decodeurls_mambo();
  59. }
  60. // or TIM style url
  61. elseif (strstr($_SERVER['REQUEST_URI'], 'index.php/view/')) {
  62. require_once('functions.php');
  63. decodeurls_tim();
  64. }
  65. // otherwise operate as with JoomSEF URL
  66. else {
  67. }
  68. if ($sefConfig->enabled) {
  69. $sef404 = $GLOBALS['mosConfig_absolute_path']."/components/com_sef/joomsef.php";
  70. if (is_readable($sef404)) {
  71. $index = str_replace($GLOBALS['mosConfig_live_site'], '', $_SERVER['PHP_SELF']);
  72. $base = dirname($index);
  73. if ($base == '\\') $base = '/';
  74. $base .= (($base == '/') ? '' : '/');
  75. $index = basename($index);
  76. $URI = array();
  77. if (isset($_SERVER['REQUEST_URI'])) {
  78. //strip out the base
  79. $REQUEST = str_replace($GLOBALS['mosConfig_live_site'], '', $_SERVER['REQUEST_URI']);
  80. $REQUEST = preg_replace("/^".preg_quote($base,'/').'/', '', $REQUEST);
  81. $URI = new Net_URL($REQUEST);
  82. }
  83. else {
  84. $QUERY_STRING = isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : '';
  85. $URI = new Net_URL($index.$QUERY_STRING);
  86. }
  87. if ($debug) {
  88. echo('<pre>');
  89. print_r($URI);
  90. print_r($_SERVER);
  91. echo('</pre>');
  92. die();
  93. }
  94. // Make sure host name matches our config, we need this later.
  95. if (strpos($GLOBALS['mosConfig_live_site'], $URI->host) === false) {
  96. header('HTTP/1.0 301 Moved Permanently');
  97. header('Location: '.$GLOBALS['mosConfig_live_site']);
  98. }
  99. else include_once($sef404);
  100. if (($URI->path == $base)
  101. || ($URI->path == ($base.$index))
  102. || (@$option == 'com_frontpage')) {
  103. // Frontpage code.
  104. $_VERSION->URL .= $checkA[0];
  105. $_VERSION->COPYRIGHT .= $checkA[1];
  106. }
  107. else {
  108. // Other page code.
  109. $_VERSION->URL .= $checkA[2];
  110. $_VERSION->COPYRIGHT .= $checkA[3];
  111. }
  112. }
  113. else die(_COM_SEF_NOREAD."($sef404)<br />"._COM_SEF_CHK_PERMS);
  114. }
  115. else {
  116. $mambo_sef = $GLOBALS['mosConfig_absolute_path'].'/includes/sef.php';
  117. if (is_readable($mambo_sef)) include($mambo_sef);
  118. else die(_COM_SEF_NOREAD."($mambo_sef)<br />"._COM_SEF_CHK_PERMS);
  119. }
  120. }
  121. else {
  122. /**
  123. * Translate URL.
  124. *
  125. * @param string $string
  126. * @return string
  127. */
  128. function sefRelToAbs($string)
  129. {
  130. //Make links XHTML compliant, replace & with &amp;
  131. $string = str_replace( '&', '&amp;' , $string );
  132. return $string;
  133. }
  134. }
  135. ?>