11<?php
22
33// We need this for error reporting
4+ use phpweb \ProjectGlobals ;
5+
46include_once __DIR__ . '/errors.inc ' ;
57
68// Try to find some variations of keyword with $prefix in the $lang manual
@@ -14,35 +16,35 @@ function tryprefix($lang, $keyword, $prefix)
1416
1517 // Try the keyword with the prefix
1618 $ try = "/manual/ {$ lang }/ {$ prefix }{$ keyword }.php " ;
17- if (@file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . $ try )) { return $ try ; }
19+ if (@file_exists (ProjectGlobals:: getPublicRoot () . $ try )) { return $ try ; }
1820
1921 // Drop out spaces, and try that keyword (if different)
2022 $ nosp = str_replace (" " , "" , $ keyword );
2123 if ($ nosp != $ keyword ) {
2224 $ try = "/manual/ {$ lang }/ {$ prefix }{$ nosp }.php " ;
23- if (@file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . $ try )) { return $ try ; }
25+ if (@file_exists (ProjectGlobals:: getPublicRoot () . $ try )) { return $ try ; }
2426 }
2527
2628 // Replace spaces with hyphens, and try that (if different)
2729 $ dasp = str_replace (" " , "- " , $ keyword );
2830 if ($ dasp != $ keyword ) {
2931 $ try = "/manual/ {$ lang }/ {$ prefix }{$ dasp }.php " ;
30- if (@file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . $ try )) { return $ try ; }
32+ if (@file_exists (ProjectGlobals:: getPublicRoot () . $ try )) { return $ try ; }
3133 }
3234
3335 // Remove hyphens (and underscores), and try that (if different)
3436 $ noul = str_replace ("- " , "" , $ keyword );
3537 if ($ noul != $ keyword ) {
3638 $ try = "/manual/ {$ lang }/ {$ prefix }{$ noul }.php " ;
37- if (@file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . $ try )) { return $ try ; }
39+ if (@file_exists (ProjectGlobals:: getPublicRoot () . $ try )) { return $ try ; }
3840 }
3941
4042 // urldecode() (%5C == \) Replace namespace sperators, and try that (if different)
4143 $ keyword = urldecode ($ keyword );
4244 $ noul = str_replace ("\\" , "- " , $ keyword );
4345 if ($ noul != $ keyword ) {
4446 $ try = "/manual/ {$ lang }/ {$ prefix }{$ noul }.php " ;
45- if (@file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . $ try )) { return $ try ; }
47+ if (@file_exists (ProjectGlobals:: getPublicRoot () . $ try )) { return $ try ; }
4648 }
4749
4850 // Replace first - with a dot and try that (for mysqli_ type entries)
@@ -53,7 +55,7 @@ function tryprefix($lang, $keyword, $prefix)
5355 $ keyword [$ pos ] = '. ' ;
5456
5557 $ try = "/manual/ {$ lang }/ {$ prefix }{$ keyword }.php " ;
56- if (@file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . $ try )) { return $ try ; }
58+ if (@file_exists (ProjectGlobals:: getPublicRoot () . $ try )) { return $ try ; }
5759 }
5860 }
5961
@@ -108,9 +110,9 @@ function find_manual_page($lang, $keyword)
108110 $ dbh = false ;
109111 if (class_exists ('PDO ' )) {
110112 if (in_array ('sqlite ' , PDO ::getAvailableDrivers (), true )) {
111- if (file_exists ($ _SERVER [ ' DOCUMENT_ROOT ' ] . '/backend/manual-lookup.sqlite ' )) {
113+ if (file_exists (ProjectGlobals:: getPublicRoot () . '/backend/manual-lookup.sqlite ' )) {
112114 try {
113- $ dbh = new PDO ( 'sqlite: ' . $ _SERVER [ ' DOCUMENT_ROOT ' ] . '/backend/manual-lookup.sqlite ' , '' , '' , [PDO ::ATTR_PERSISTENT => true , PDO ::ATTR_EMULATE_PREPARES => true ] );
115+ $ dbh = new PDO ( 'sqlite: ' . ProjectGlobals:: getPublicRoot () . '/backend/manual-lookup.sqlite ' , '' , '' , [PDO ::ATTR_PERSISTENT => true , PDO ::ATTR_EMULATE_PREPARES => true ] );
114116 } catch (PDOException $ e ) {
115117 return find_manual_page_slow ($ lang , $ keyword );
116118 }
@@ -204,7 +206,7 @@ function find_manual_page($lang, $keyword)
204206 // But does the file really exist?
205207 // @todo consider redirecting here, instead of including content within the 404
206208 // @todo considering the file path is generated from the manual build, we can probably remove this file_exists() check
207- if (file_exists ($ _SERVER [ " DOCUMENT_ROOT " ] . $ r [0 ])) {
209+ if (file_exists (ProjectGlobals:: getPublicRoot () . $ r [0 ])) {
208210 return $ r [0 ];
209211 }
210212 }
0 commit comments