BullGuard Antivirus Sale - 60% Off with openElement !
Forum openElement Homepage
Forum Home Forum Home >

openElement

> Dynamic OE - Databases, etc
  New Posts New Posts RSS Feed - how to change the path dynamically according to?
  FAQ FAQ  Forum Search   Register Register  Login Login

how to change the path dynamically according to?

 Post Reply Post Reply Page  123>
Author
Message Reverse Sort Order
Dmit OE View Drop Down
Admin Group
Admin Group
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5276
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Topic: how to change the path dynamically according to?
    Posted: 07 Feb 2017 at 16:03
Ok thanks for the details
Back to Top
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 Août 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Posted: 07 Feb 2017 at 15:37
DmitOE, I found an error in my code.

As OE at PC local server, dirname($_SERVER['PHP_SELF']); is "\". Therefore,
explode("/", dirname($_SERVER['PHP_SELF']));  is array(1) { [0]=> string(1) "\" }

BUT, AS webserver at RPi, dirname($_SERVER['PHP_SELF']); is "/". Therefore, 
explode("/", dirname($_SERVER['PHP_SELF']));  is array(2) { [0]=> string(0) "" [1]=> string(0) "" }

Consequently, my source never point to home root where PHP_SELF is home.

Finally, I debug my code as following;

function changeCurrentPath2RelativeDot(){
$current_path = dirname($_SERVER['PHP_SELF']);
if ($current_path == "/") {
$testpath = "";
return $testpath;
} else {
$testpath = explode("/", $current_path);
$no_double_dot = count($testpath) - 1;
$testpath = str_repeat('../', $no_double_dot);
return $testpath;
}
}
$relative_dot = changeCurrentPath2RelativeDot();

include_once "{$relative_dot}Templates/includes/nmudb.php";
require_once "{$relative_dot}Templates/includes/php_serial.class.php";

Sorry for making your confusion.


Edited by djju1029 - 07 Feb 2017 at 17:09
Back to Top
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 Août 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 23:06
Many many thanks to DmitOE. Finally, I did it like ths,

<include, by PHP at start of document of BaseLayer.php>

function changeCurrentPath2RelativeDot(){
$testpath = explode("/", dirname($_SERVER['PHP_SELF']));
$no_double_dot = count($testpath) - 1;
$testpath = str_repeat('../', $no_double_dot);
return $testpath;
}
$relative_dot = changeCurrentPath2RelativeDot();

include_once($relative_dot."Templates/includes/nmudb.php");
require_once($relative_dot."Templates/includes/php_serial.class.php");

<jquery_ui, by HTML at head of BaseLayer.php>

<?php echo "<link href='{$relative_dot}WEFiles/Other/jquery-ui.css' rel='stylesheet'>"; ?>
<br>
<?php echo "<script type='text/javascript' src='{$relative_dot}WEFiles/Other/jquery-ui.js'></script>"; ?>

every page woks! Thank you, my mentor!



Edited by djju1029 - 03 Feb 2017 at 23:39
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5276
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 21:57
This is calculated inside OE, who knows where each page is exactly. There's a way to get it in PHP version if you use Packs on the page, but it is not necessary I think. Your code allows to get the same value (is it?), ex. "../../../", so you just do something like:

echo "<link href='{$relative_dot}Files/Other/jquery-ui.css' rel='stylesheet'>";

Why woud this not work? Just not WEFiles/Other but Files/Other (and place the file jquery-ui.css accordingly).

I have a n impression that you are missing something rather obvious. If nothing works, send me your project via a private message with the code that does not work, I will look why when I have time.
Back to Top
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 Août 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 21:47
Cry Where I am blocked is prepend my result of "$relative_dot" to link in the header.

This question comes from when I look your source.

When I look into original source view of page, I found the link of header is relative dot to back as following:

It is original source view of page and link of css file in header:
<link id="openElement" rel="stylesheet" type="text/css" href="../../../WEFiles/Css/v02/openElement.css?v=50491101600" />

I just want to copy your way in my source, so I found how to change current absolute dirpath to relative ../ to get back to root.
But I have no idea how to prepend it to link path commonly.

If I put $relative_dot into the link, but it don't work....

When I look at source view of page, I found:
var WEInfoPage = {"PHPVersion":"phpOK","OEVersion":"1-56-0","PagePath":"test/examples/test_folder/Copy-BlankLayer","Culture":"DEFAULT","LanguageCode":"EN-US","RelativePath":"../../../","RenderMode":"Export","PageAssociatePath":"test/examples/test_folder/Copy-BlankLayer","EditorTexts":null};

See, there is "RelativePath":"../../../" 
Eureka! I think it has some secret on your source that change path relatively to the root.
I just want to figure out how you realize this way and to copy it on my source.....Cry
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5276
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 21:08
I don't understand where you are blocked; you seem to have found an effcient function to get the path "back" to the root. By the way it is relative to the page location, not an included script. Why not simply prepend it to "/WEFiles/Other/jquery-ui.css"?
Back to Top
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 Août 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 19:34
DmitOE,

I found that $_SERVER["PHP_SELF"] returns same result from PC or my Raspberry Pi such as /test/manual_scripting (not \ from pc)

Therefore, I wrote simple function that this path to relative dotted path as following:

function changeCurrentPath2RelativeDot(){
$testpath = explode("/", dirname($_SERVER['PHP_SELF']));
$no_double_dot = count($testpath) - 1;
$testpath = str_repeat('../', $no_double_dot);
return $testpath;
}
$relative_dot = changeCurrentPath2RelativeDot();

// Test:
echo "<br><br>RelativePath to the Files/Other folder: ",$relative_dot,"Files/Other"; //result is ../../Files/Other

I checked the $relative_dot gives corrent number of dot path such as ../../../ where page is.
I put this function into Start of Document of BaseLayer.
But I got another problem.
I need to use $relative_dot on CSS link in the header like this:

<Absolute>
<link href="C:/Users/djoo/Desktop/PortableGit/project/NMU_mockup/WEFiles/Other/jquery-ui.css" rel="stylesheet">

<Relative>
<link href="../../WEFiles/Other/jquery-ui.css" rel="stylesheet">

when $relative_dot is ../../

How can I change this absolute to relative path in HTML using the result of my function?


Edited by djju1029 - 03 Feb 2017 at 19:35
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5276
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 17:14
Check my latest pos, it should suit you
Back to Top
djju1029 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 Août 2016
Location: the US
Status: Offline
Points: 126
Post Options Post Options   Thanks (0) Thanks(0)   Quote djju1029 Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 15:44
I need your help, a solution using certain Packs auxiliary functionality. I couldn't do a beacon method to find the physical root path of the website....Cry

Many many thanks,

DJ
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5276
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: 03 Feb 2017 at 10:42
Or, to not bother about all this, here is a universal solution, given that you do not have any index.php or index.htm in subfolders of your project somewhere. Insert this into a Code Block Source type PHP in your baselayer or anywhere else:

function findSiteRootPath()    {
   
    $path = __DIR__; // page or script's absolute path, somewhere in the project
   
    // find the folder where index.php or index.htm is, starting from the current folder:
    while ((strpos($path, '/') || strpos($path, '\\')) && !file_exists("$path/index.php") && !file_exists("$path/index.htm")) {
        $path = dirname($path);
    }
   
    return $path; //
}

$root = findSiteRootPath();
// Test:
echo "<br><br>Path to the Files/Other folder: $root/Files/Other";
Back to Top
 Post Reply Post Reply Page  123>
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 10.11
Copyright ©2001-2012 Web Wiz Ltd.

This page was generated in 0,031 seconds.