Project

General

Profile

1
<?php
2
  /**
3
  * QuickSkin Extension load_config
4
  * Reads an INI-Style configuration file into an array
5
  *
6
  * Usage Example:
7
  * Configuration File (parameter.ini):
8
  *
9
  *     PAGETITLE   =  Default Page Title
10
  *     [colors]
11
  *     BACKGROUND  =  #FFFFFF
12
  *     TEXT        =  #000000
13
  *
14
  * Template:
15
  *
16
  *     {load_config:"parameter.ini","config"}
17
  *     <title>{config.PAGETITLE}</title>
18
  *     <body bgcolor="{config.colors.BACKGROUND}" text="{config.colors.TEXT}">
19
  *
20
  * Result:
21
  *
22
  *     <title>Default Page Title</title>
23
  *     <body bgcolor="#FFFFFF" text="#000000">
24
  *
25
  * @author Andy Prevost andy@codeworxtech.com - original by Philipp v. Criegern philipp@criegern.de
26
  */
27
  function qx_load_config ( $filename,  $name = 'config' ) {
28
    global $_top;
29

    
30
    $section  =  null;
31
    if (is_file($filename)) {
32
      $cfgfile  =  file($filename);
33
      if (is_array($cfgfile)) {
34
        foreach ($cfgfile as $line) {
35
          if (substr($line, 0, 1) != '#') {
36
            if (substr($line, 0, 1) == '[') {
37
              if ($rbr = strpos($line, ']')) {
38
                $section  =  substr($line, 1, $rbr -1);
39
              }
40
            }
41
            if ($tr = strpos($line, '=')) {
42
              $k  =  trim(substr($line, 0, $tr));
43
              $v  =  trim(substr($line, $tr+1));
44
              if (isset($section)) {
45
                $_top[$name][$section][$k]  =  $v;
46
              } else {
47
                $_top[$name][$k]  =  $v;
48
              }
49
            }
50
          }
51
        }
52
      }
53
    }
54
  }
(25-25/43)