VCL
[ class tree: VCL ] [ index: VCL ] [ all elements ]

Source for file vcl.inc.php

Documentation is available at vcl.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2007 qadram software <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  8. *
  9. *  This library is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU Lesser General Public
  11. *  License as published by the Free Software Foundation; either
  12. *  version 2.1 of the License, or (at your option) any later version.
  13. *
  14. *  This library is distributed in the hope that it will be useful,
  15. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. *  Lesser General Public License for more details.
  18. *
  19. *  You should have received a copy of the GNU Lesser General Public
  20. *  License along with this library; if not, write to the Free Software
  21. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22. *  USA
  23. *
  24. */
  25.  
  26. /**
  27. * Major version of the VCL
  28. */
  29. define('VCL_VERSION_MAJOR',1);
  30. /**
  31. * Minor version of the VCL
  32. */
  33. define('VCL_VERSION_MINOR',0);
  34.  
  35. /**
  36. * Version of the VCL, use this define to make work your components between VCL versions
  37. */
  38. define('VCL_VERSION',VCL_VERSION_MAJOR.'.'.VCL_VERSION_MINOR);
  39.  
  40.  
  41.         $scriptfilename='';
  42.  
  43.         if (isset($_SERVER['SCRIPT_FILENAME'])) $scriptfilename$_SERVER['SCRIPT_FILENAME'];
  44.         else
  45.         {
  46.                         global $HTTP_SERVER_VARS;
  47.  
  48.                         $scriptfilename=$HTTP_SERVER_VARS["SCRIPT_NAME"];
  49.         }
  50.  
  51.         //Defines the PATH where the VCL resides
  52.         $fs_path=relativePath(realpath(dirname(__FILE__)),dirname(realpath($scriptfilename)));
  53.         $http_path=$fs_path;
  54.  
  55.         //If the vcl folder is not a subfolder of the VCL, then it uses vcl-bin as an alias to find the assets
  56.         if (substr($fs_path,0,2)=='..')
  57.         {
  58.             if (!array_key_exists('FOR_PREVIEW',$_SERVER)) $http_path='vcl-bin';
  59.         }
  60.  
  61.         /**
  62.          * Filesystem path to the VCL
  63.          *
  64.          */
  65.         define('VCL_FS_PATH',$fs_path);
  66.  
  67.         /**
  68.          * Webserver path to the VCL
  69.          *
  70.          */
  71.         define('VCL_HTTP_PATH',$http_path);
  72.  
  73.         /**
  74.          * Returns a relative path
  75.          *
  76.          * @param string $path 
  77.          * @param string $root 
  78.          * @param string $separator 
  79.          * @return string 
  80.          */
  81.         function relativePath($path$root$separator '/')
  82.         {
  83.                 $path=strtolower(str_replace('\\','/',$path));
  84.                 $root=strtolower(str_replace('\\','/',$root));
  85.  
  86.                 $dirs explode($separator$path);
  87.                 $comp explode($separator$root);
  88.  
  89.                 foreach ($comp as $i => $part)
  90.                 {
  91.                         if (isset($dirs[$i]&& $part == $dirs[$i])
  92.                         {
  93.                                 unset($dirs[$i]$comp[$i]);
  94.                         }
  95.                         else
  96.                         {
  97.                                 //TODO: Check this with UNC
  98.                                 //TODO: If the .php file to be executed resides on a UNC, the webserver it doesn't start,
  99.                                 //fix or warn users about the correct usage of the library and the location
  100.                                 if ((strpos($part,':')) && (strpos($dirs[$i],':')))
  101.                                 {
  102.                                         //This fixes the problem with having the code to be run
  103.                                         //and the library in different drives, but it only works with IE
  104.                                         //FF throws a security warning
  105.                                         //TODO: Must fix another way
  106.                                         $result='file:///'.$path;
  107.                                         return($result);
  108.                                 }
  109.                                 break;
  110.                         }
  111.                 }
  112.  
  113.                                 $result=str_repeat('..' $separatorcount($comp)) implode($separator$dirs);
  114.  
  115.                 return($result);
  116.         }
  117.  
  118.         /**
  119.          * Includes an VCL unit
  120.          *
  121.          * @param string $path Relative to VCL root path
  122.          */
  123.         function use_unit($path)
  124.         {
  125.                 $apath=VCL_FS_PATH;
  126.                 if ($apath!=""$apath.="/";
  127.                 require_once($apath.$path);
  128.         }
  129. ?>

Documentation generated on Tue, 27 Mar 2007 13:36:01 +0200 by phpDocumentor 1.3.1