function Parse($iniFile, $parseSections = false) { if (file_exists($iniFile)) { $parsedArray = parse_ini_file($iniFile, $parseSections); return IniFile::ProcessArrays($parsedArray); } else { // Return false if the file doesn't exist return false; } }
public static function LoadFromString($string, $separator = '=') { $object = new IniFile($separator); $object->__Load($string, null, $separator); return $object; }
files, you should see the following : $ diff example.ini example.out.ini 14c14,15 < LastUpdate = 2015/01/01 17:40:00 --- > LastUpdate = 2015/10/01 14:16:07 > Status = 0 The LastUpdate parameter was updated with the current date/time, and the Status parameter was added. ***/ require 'IniFile.class.php'; // Instanciate an IniFile object for file example.ini $inifile = IniFile::LoadFromFile('example.ini'); // Get the value of the Listen and Port parameters in the [Network] section // Note that you can specify a default value if the parameter is not defined $listen = $inifile->GetKey('Network', 'Listen', '127.0.0.0'); $port = $inifile->GetKey('Network', 'Port'); // ... do some processing // Processing done : update the LastUpdate parameter of the [Results] section then // add the Status parameter $inifile->SetKey('Results', 'LastUpdate', date('Y/m/d H:i:s')); $inifile->SetKey('Results', 'Status', 0); // Write the results back ; the "example.out.ini" file is specified just to give you // the possibility to compare the example.ini file contents before and after processing // You can simply write back "example.ini" by calling : // $inifile -> Save ( ) ; // Note that in our case, you can specify either "true" or "false" for the $forced parameter // of the Save() method ; since we have called the SetKey() method to modify parameters, the
public function __construct($file_path = null) { // get the exception handler if (!self::$except) { self::$except = new Except(); } $this->exceptions =& self::$except; // see if we have a file path if (is_string($file_path)) { $this->file_path = $file_path; } // check if we can parse the file if ($this->is_valid_file()) { $this->contents = $this->read_file(); $this->storage = $this->parse(); } }
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <?php require 'class/nette.min.php'; require 'class/IniFile.class.php'; //$IniFile = new IniFile('/home/pi/b7/setting.ini');//cesta a nazev k ini souboru $IniFile = new IniFile('setting.ini'); //cesta a nazev k ini souboru $ini_array = $IniFile->iniFileArray; use Nette\Forms\Form; ?> <html> <head> <title>B7 setting</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/b7.css"> <script src="js/jquery.js"></script> <script src="js/netteForms.js"></script> <script src="js/main.js"></script> </head> <body> <div style="width: 800px;"> <?php
function ItemViewController() { global $_JAM; // Get list of contexts $contexts = IniFile::Parse('engine/config/imageContexts.ini', true); if ($appContexts = IniFile::Parse('app/config/imageContexts.ini', true)) { $contexts += $appContexts; } // Get path to file $file = $_JAM->filesDirectory . $this->itemID; if ($context = $contexts[$_GET['context']]) { $image = new Image($file); // Set dimensions according to context $width = $context['width']; $height = $context['height']; if ($context['allowScaleUp'] === '') { // Scale up is forbidden; check whether we're scaling up if ($context['width'] > $image->width || $context['height'] > $image->height) { // We're indeed scaling up; override context dimensions with actual file dimensions $width = $image->width; $height = $image->height; } } $image->OutputResizedImage($width, $height); } else { // Set MIME type, if available if ($this->items[$this->itemID]['type']) { header('Content-type: ' . $this->items[$this->itemID]['type']); } // Determine file size if ($fileSize = filesize($file)) { header('Content-length: ' . $fileSize); } // Read file directly from 'files' directory readfile($file); } // Don't display anything else; this also bypasses caching, which is good exit; }
function FirstRun() { // Load table structure for required tables $tables = IniFile::Parse('engine/database/tables.ini', true); // Create tables foreach ($tables as $name => $schema) { if (!Database::CreateTable($name, $schema)) { trigger_error("Couldn't create table " . $name, E_USER_ERROR); } } // Manually add admin module to _modules table if (Query::TableIsEmpty('_modules')) { $adminModule = array('name' => 'admin'); if (!Database::Insert('_modules', $adminModule)) { trigger_error("Couldn't install core modules", E_USER_ERROR); } } // Install required modules $requiredModules = array('users', 'files'); foreach ($requiredModules as $moduleName) { $module = Module::GetNewModule($moduleName); $module->Install(); } // Add default admin user if (Query::TableIsEmpty('users')) { $adminUserParams = array('created' => $this->databaseTime, 'login' => 'admin', 'name' => 'Admin', 'password' => 'admin', 'status' => 3); if (!Database::Insert('users', $adminUserParams)) { trigger_error("Couldn't create admin user", E_USER_ERROR); } } // Add admin path $adminModuleId = Query::SingleValue('_modules', 'id', "name = 'admin'"); if (!Path::Insert('admin', $adminModuleId, false)) { trigger_error("Couldn't add admin path", E_USER_ERROR); } // Redirect to admin interface HTTP::RedirectLocal('admin'); }
function Initialize() { // Set PHP configuration options $options = array('mbstring.language' => 'Neutral', 'mbstring.internal_encoding' => 'UTF-8', 'mbstring.encoding_translation' => 'On', 'mbstring.http_input' => 'auto', 'mbstring.detect_order' => 'ASCII,UTF-8,JIS,SJIS,EUC-JP', 'upload_max_filesize' => '21M', 'post_max_size' => '24M', 'display_errors' => true); foreach ($options as $key => $value) { ini_set($key, $value); } // Required for UTF-8 support mb_language('uni'); // Error display //error_reporting(E_ALL^E_NOTICE); error_reporting(0); // Add app/ and engine/ to include path set_include_path(get_include_path() . PATH_SEPARATOR . './app' . PATH_SEPARATOR . './engine'); // Load classes $classesDir = 'engine/classes'; $dirHandle = opendir($classesDir); while ($filename = readdir($dirHandle)) { // Make sure files end in .php if ($filename != basename($filename, '.php')) { $classPath = $classesDir . '/' . $filename; if (!is_dir($classPath)) { require_once $classPath; } } } // Start caching engine; this also initializes output buffering $this->cache = new Cache(); // Start output buffering ob_start('mb_output_handler'); // Define files directory $this->filesDirectory = 'files/'; // Load configuration files $this->projectConfig = IniFile::Parse('app/config/project.ini', true); $this->serverConfig = IniFile::Parse('app/config/server.ini', true); // Define constants define('ROOT', $this->serverConfig['root']); define('ERROR_FOREIGN_KEY_CONSTRAINT', 2); // Used in engine/classes/Module.php // Load database field types $this->fieldTypes = IniFile::Parse('engine/database/types.ini'); // Load module fields $this->moduleFields = IniFile::Parse('engine/database/moduleFields.ini', true); $this->versionsSupportFields = IniFile::Parse('engine/database/versionsSupportFields.ini', true); // Load GetID3 require_once 'engine/libraries/getid3/getid3.php'; // Determine default language $this->defaultLanguage = $this->projectConfig['languages'][0]; // Determine requested language $requestedLanguage = $_GET['language']; if ($requestedLanguage && in_array($requestedLanguage, $this->projectConfig['languages'])) { // User has manually switched language Cookie::Create('language', $requestedLanguage); $this->language = $requestedLanguage; } elseif ($_COOKIE['language']) { // User has previously selected a language $this->language = $_COOKIE['language']; } else { // User has never selected a language; use default $this->language = $this->defaultLanguage; } // Load strings in the requested language $this->strings = IniFile::Parse('engine/strings/' . $this->language . '.ini', true); // Load shorthands (useful function aliases; must load after strings) require 'engine/helpers/shorthands.php'; // Connect to database $db = $this->serverConfig['database']; if (!($this->databaseLink = Database::Connect($db['server'], $db['username'], $db['password'], $db['database']))) { trigger_error("Couldn't connect to database " . $db['database'], E_USER_ERROR); } // Get available modules list $engineModules = Filesystem::GetDirNames('engine/modules'); $this->appModules = Filesystem::GetDirNames('app/modules'); $this->availableModules = $engineModules + $this->appModules; // Strip root directory and trailing slashes from full path request $pathString = $_SERVER['REQUEST_URI']; $barePath = substr($pathString, 0, strrpos($pathString, '?')); $pathString = $barePath ? $barePath : $pathString; $fullRequest = rtrim($pathString, '/'); preg_match('|^' . ROOT . '(.*)$|', $fullRequest, $requestArray); // Use requested URL, or use root path if none was requested $this->request = $requestArray[1] ? $requestArray[1] : $this->projectConfig['rootPath']; // We sync using database time (might differ from PHP time) $databaseTimeQuery = new Query(array('fields' => 'NOW()')); $databaseTime = $databaseTimeQuery->GetSingleValue(); $this->databaseTime = $databaseTime; // Make sure everything is properly initialized $tables = Database::GetTables(); if (!$tables['users'] || !$tables['_paths']) { require 'engine/helpers/firstrun.php'; } // Get installed modules list $this->installedModules = Query::SimpleResults('_modules'); // Create User object $this->user = new User(); // Create layout object $this->template = new Template(); // Determine mode $requestedMode = $_GET['mode']; $availableModes = IniFile::Parse('engine/config/modes.ini'); if ($availableModes[$requestedMode]) { // If requested mode exists, use it $this->mode = $requestedMode; } else { // HTML is the default mode $this->mode = 'html'; } // Load paths $paths = Query::FullResults('_paths'); foreach ($paths as $path) { // Use path as key in $_JAM->paths array $this->paths[$path['path']] = $path; } // Look for request in paths if ($path = $this->paths[$this->request]) { // Path does exist if ($path['current']) { // This is a valid path; proceed to module if ($this->rootModule = Module::GetNewModule($this->installedModules[$path['module']], $path['item'])) { // Check whether we have sufficient privileges to display the module if ($this->rootModule->CanView()) { // Display module $this->rootModule->Display(); // Determine path to admin pane for this item $adminPath = 'admin/' . $moduleName; if ($this->paths[$adminPath]) { if ($path['item']) { $adminPath .= '?a=edit&id=' . $path['item']; } $this->adminPath = ROOT . $adminPath; } else { $this->adminPath = ROOT . 'admin'; } } else { // Display login if we can't display $this->user->Connect(); } } else { trigger_error("Couldn't load root module", E_USER_ERROR); } } else { // This is an obsolete URL; find its current (up to date) equivalent $whereArray = array('module = ' . $path['module'], 'item = ' . $path['item'], "language = '" . $path['language'] . "'", 'current = TRUE'); $currentPath = Query::SingleValue('_paths', 'path', $whereArray); HTTP::NewLocation($currentPath); } } else { // Path does not exist; throw 404 header("HTTP/1.0 404 Not Found"); $this->rootModule = Module::GetNewModule('errors'); $this->rootModule->Display(); } // Store and flush the contents of the output buffer $buffer = ob_get_clean(); // Load and display template if ($this->mode == 'html' && $this->rootModuleName == 'admin') { // Special case for admin pages requested in HTML $templateName = 'html_admin'; } else { $templateName = $this->mode; } $this->template->SetTemplate($templateName); $this->template->Display($buffer); // Set MIME type $contentType = $this->contentType ? $this->contentType : $availableModes[$this->mode]; if ($contentType) { header('Content-Type: ' . $contentType); } // Write to cache; this also cleans output buffering $this->cache->Write(); }
<?php ini_set("display_errors", 'Off'); include_once "functions.php"; include_once "class.IniFile.php"; include_once "class.RequestVars.php"; require_once "class.SciELOInstances.php"; $iniObj = new IniFile("ini/stat.ini"); $iniArr = $iniObj->parse(); $xml_node_ini = $iniObj->getXML(); $requestVars = new RequestVars(); $xml_node_request_vars = $requestVars->getVarsXml(); $array_request_vars = $requestVars->getVarsArray(); /* * eliminar a passagem de parametros * server_action e xml * por motivo de seguranca * */ $pair_state_action = array("02" => "", "16" => "", "17" => "7", "03" => "", "15" => "1", "04" => "", "05" => "1_2", "18" => "", "19" => "1_3", "08" => "3", "07" => "", "09" => "", "10" => "6", "11" => "", "13" => "5out", "12" => "5"); if ($array_request_vars["state"] != "" && array_key_exists($state, $pair_state_action)) { $state = $array_request_vars["state"]; } else { //echo("Warning: no state was defined, so default 02 is runing the business..."); $state = "02"; } /* tratamento de idioma */ if ($array_request_vars['lang'] != 'en' && $array_request_vars['lang'] != 'es' && $array_request_vars['lang'] != 'pt') { $array_request_vars['lang'] = 'en'; } /* obtencao da data de processamento */
function GetRelatedArray($field) { if ($relatedModule = $this->schema[$field]['relatedModule']) { $relatedModuleConfig = Module::ParseConfigFile($relatedModule, 'config/config.ini', true); // Look for keyQuery.ini if ($relatedQueryParams = Module::ParseConfigFile($relatedModule, 'config/keyQuery.ini', true)) { // Fetch array using specified query $relatedQuery = new Query($relatedQueryParams); } else { if (!($keyField = $relatedModuleConfig['keyField'])) { // If no key field was specified in config file, use first field $relatedModuleSchema = Module::ParseConfigFile($relatedModule, 'config/schema.ini', true); reset($relatedModuleSchema); $keyField = key($relatedModuleSchema); } // If we do find a key field, build query according to that if ($keyField) { $params = array(); if ($relatedModuleConfig['keepVersions']) { $params['fields']['id'] = 'IF(master IS NULL, id, master)'; } else { $params['fields']['id'] = 'id'; } $params['fields'][] = $keyField; $relatedQuery = new Query($params); } } // If we successfuly built a query, fetch data if ($relatedQuery) { $relatedQuery->AddFrom($relatedModule); // Manage versions if ($relatedModuleConfig['keepVersions']) { $relatedQuery->AddWhere($relatedModule . '.current = TRUE'); } return $relatedQuery->GetSimpleArray(); } } elseif ($relatedArray = $this->schema[$field]['relatedArray']) { // Array is specified in a config file $relatedArrays = IniFile::Parse($this->modulePath . 'config/relatedArrays.ini', true); $relatedData = $relatedArrays[$relatedArray]; // Look for localized strings foreach ($relatedData as $key => $label) { if ($string = $this->strings[$relatedArray][$label]) { $relatedData[$key] = $string; } } return $relatedData; } else { return false; } }
--- scripts/php/webstats.php Sun Jul 15 21:50:15 2001 +++ scripts/php/webstats.php Sun Feb 16 18:10:25 2003 @@ -4,7 +4,7 @@ <?php include "class.inifile.php"; //we read the serverwide config file -($serverwideini = new IniFile("/etc/webstats/webstats.ini")); +($serverwideini = new IniFile("%%PREFIX%%/etc/webstats/webstats.ini")); $servername = $serverwideini->value("misc", "SERVERNAME", "not defined/config file not found?"); $vhost_directory = $serverwideini->value("rmagic", "VHOSTDIR", "VHOSTDIR not defined/config file not found?"); $logs_directory = $serverwideini->value("rmagic", "LOGSDIR", "LOGSDIR not defined/config file not found?");
<?php // Load table structure for required tables $tables = IniFile::Parse('engine/database/tables.ini', true); // Create tables foreach ($tables as $name => $schema) { if (!Database::CreateTable($name, $schema)) { trigger_error("Couldn't create table " . $name, E_USER_ERROR); } } // Manually add admin module to _modules table if (Query::TableIsEmpty('_modules')) { $adminModule = array('name' => 'admin'); if (!Database::Insert('_modules', $adminModule)) { trigger_error("Couldn't install core modules", E_USER_ERROR); } } // Install required modules $requiredModules = array('users', 'files'); foreach ($requiredModules as $moduleName) { $module = Module::GetNewModule($moduleName); $module->Install(); } // Add default admin user if (Query::TableIsEmpty('users')) { $adminUserParams = array('created' => $_JAM->databaseTime, 'login' => 'admin', 'name' => 'Admin', 'password' => 'admin', 'status' => 3); if (!Database::Insert('users', $adminUserParams)) { trigger_error("Couldn't create admin user", E_USER_ERROR); } } // Add admin path