Explicit Relative Paths for Includes

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Explicit Relative Paths for Includes

Post by cmb » Mon Oct 01, 2012 2:47 pm

Hello Community,

today a problem related to file inclusion without an explicit path was reported: http://cmsimpleforum.com/viewtopic.php?f=10&t=5160. I have no clue for which reason the inclusion failed, but it might be better anyhow to use explicit relative paths:
http://de.php.net/manual/en/ini.core.php#ini.include-path wrote:However, it is more efficient to explicitly use include './file' than having PHP always check the current directory for every include.
So I suggest we should do so. I've reviewed all include(_once) and require(_once) directives and the following changes should suffice:

Code: Select all

Index: cmsimple/login.php
===================================================================
--- cmsimple/login.php    (revision 295)
+++ cmsimple/login.php    (working copy)
@@ -27,7 +27,7 @@
 if (preg_match('/login.php/i', sv('PHP_SELF')))
     die('Access Denied');
 
-require 'PasswordHash.php';
+require $pth['folder']['cmsimple'] . 'PasswordHash.php';
 $xh_hasher = new PasswordHash(8, true);
 
 // for subsite solution - GE 20011-02
Index: plugins/filebrowser/classes/required_classes.php
===================================================================
--- plugins/filebrowser/classes/required_classes.php    (revision 295)
+++ plugins/filebrowser/classes/required_classes.php    (working copy)
@@ -5,6 +5,6 @@
  */
 
 /* utf-8 marker: äöü */
-require_once "filebrowser_view.php";
-require_once "filebrowser.php";
+require_once $pth['folder']['plugin_classes'] . 'filebrowser_view.php';
+require_once $pth['folder']['plugin_classes'] . 'filebrowser.php';
 ?>
\ No newline at end of file
Index: plugins/filebrowser/editorbrowser.php
===================================================================
--- plugins/filebrowser/editorbrowser.php    (revision 295)
+++ plugins/filebrowser/editorbrowser.php    (working copy)
@@ -5,8 +5,8 @@
  */
 
 /* utf-8 marker: äöü */
-require_once 'classes/filebrowser_view.php';
-require_once 'classes/filebrowser.php';
+require_once './classes/filebrowser_view.php';
+require_once './classes/filebrowser.php';
 
 if (!isset($_SESSION)) {     session_start(); }
 
@@ -114,7 +114,7 @@
 
 
 
-    $jsFile = 'editorhooks/' . basename($_GET['editor']) . '/script.php';
+    $jsFile = './editorhooks/' . basename($_GET['editor']) . '/script.php';
 
     $script = '';
     if (file_exists($jsFile)) {
Index: plugins/meta_tags/index.php
===================================================================
--- plugins/meta_tags/index.php    (revision 295)
+++ plugins/meta_tags/index.php    (working copy)
@@ -21,10 +21,6 @@
 if(!defined('PLUGINLOADER')) {
     die('Plugin '. basename(dirname(__FILE__)) . ' requires a newer version of the Pluginloader. No direct access.');
 }
-/**
- * Include language package
- */
-include_once "languages/".$sl.'.php';
 
 /**
  * Add used interests to router
Index: plugins/page_params/index.php
===================================================================
--- plugins/page_params/index.php    (revision 295)
+++ plugins/page_params/index.php    (working copy)
@@ -20,10 +20,6 @@
  * Check if PLUGINLOADER is calling and die if not
  */
 if(!defined('PLUGINLOADER_VERSION')){die('Plugin '. basename(dirname(__FILE__)) . ' requires a newer version of the Pluginloader. No direct access.');}
-/**
- * Include language package
- */
-include_once "languages/".$sl.'.php';
 
 /**
  * Add used interests to router
Please note that instead of changing the paths to be relative in page_params and meta_tags this patch will remove the explicit inclusion of the language file alltogether, as this is already done by the plugin loader.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply