added informations for tematic advance and parse_info_file function for parsing .info - partial CT#570

skala
Cristian Fasanando 16 years ago
parent e551283b49
commit 809a960190
  1. 20
      main/inc/lib/course_description.lib.php
  2. 123
      main/inc/lib/main_api.lib.php

@ -72,22 +72,30 @@ class CourseDescription
}
/**
* Get all data by description and session id,
* Get all data by description and session id,
* first you must set session_id property with the object CourseDescription
* @param int description type
* @param string course code (optional)
* @return array
*/
public function get_data_by_description_type($description_type) {
public function get_data_by_description_type($description_type, $course_code = '') {
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
if (!empty($course_code)) {
$course_info = api_get_course_info($course_code);
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION, $course_info['dbName']);
}
$sql = "SELECT * FROM $tbl_course_description WHERE description_type='$description_type' AND session_id='".$this->session_id."'";
$rs = Database::query($sql);
$data = array();
$rs = Database::query($sql, __FILE__, __LINE__);
$data = array();
if ($description = Database::fetch_array($rs)) {
$data['description_title'] = $description['title'];
$data['description_content'] = $description['content'];
$data['progress'] = $description['progress'];
}
return $data;
}
return $data;
}
/**

@ -145,6 +145,7 @@ define('SECTION_PLATFORM_ADMIN', 'platform_admin');
define('SECTION_MYGRADEBOOK', 'mygradebook');
define('SECTION_TRACKING','session_my_space');
define('SECTION_SOCIAL', 'social');
define('SECTION_DASHBOARD', 'dashboard');
// CONSTANT name for local authentication source
define('PLATFORM_AUTH_SOURCE', 'platform');
@ -3073,6 +3074,128 @@ function api_chmod_R($path, $filemode) {
return chmod($path, $filemode);
}
/**
* Parse info file format. (e.g: file.info)
*
* Files should use an ini-like format to specify values.
* White-space generally doesn't matter, except inside values.
* e.g.
*
* @verbatim
* key = value
* key = "value"
* key = 'value'
* key = "multi-line
*
* value"
* key = 'multi-line
*
* value'
* key
* =
* 'value'
* @endverbatim
*
* Arrays are created using a GET-like syntax:
*
* @verbatim
* key[] = "numeric array"
* key[index] = "associative array"
* key[index][] = "nested numeric array"
* key[index][index] = "nested associative array"
* @endverbatim
*
* PHP constants are substituted in, but only when used as the entire value:
*
* Comments should start with a semi-colon at the beginning of a line.
*
* This function is NOT for placing arbitrary module-specific settings. Use
* variable_get() and variable_set() for that.
*
* Information stored in the module.info file:
* - name: The real name of the module for display purposes.
* - description: A brief description of the module.
* - dependencies: An array of shortnames of other modules this module depends on.
* - package: The name of the package of modules this module belongs to.
*
* Example of .info file:
* @verbatim
* name = Forum
* description = Enables threaded discussions about general topics.
* dependencies[] = taxonomy
* dependencies[] = comment
* package = Core - optional
* version = VERSION
* @endverbatim
*
* @param $filename
* The file we are parsing. Accepts file with relative or absolute path.
* @return
* The info array.
*/
function parse_info_file($filename) {
$info = array();
if (!file_exists($filename)) {
return $info;
}
$data = file_get_contents($filename);
if (preg_match_all('
@^\s* # Start at the beginning of a line, ignoring leading whitespace
((?:
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
\[[^\[\]]*\] # unless they are balanced and not nested
)+?)
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
(?:
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
([^\r\n]*?) # Non-quoted string
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace
@msx', $data, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
// Fetch the key and value string
$i = 0;
foreach (array('key', 'value1', 'value2', 'value3') as $var) {
$$var = isset($match[++$i]) ? $match[$i] : '';
}
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
// Parse array syntax
$keys = preg_split('/\]?\[/', rtrim($key, ']'));
$last = array_pop($keys);
$parent = &$info;
// Create nested arrays
foreach ($keys as $key) {
if ($key == '') {
$key = count($parent);
}
if (!isset($parent[$key]) || !is_array($parent[$key])) {
$parent[$key] = array();
}
$parent = &$parent[$key];
}
// Handle PHP constants
if (defined($value)) {
$value = constant($value);
}
// Insert actual value
if ($last == '') {
$last = count($parent);
}
$parent[$last] = $value;
}
}
return $info;
}
/**
* Get Dokeos version from the configuration files
* @return string A string of type "1.8.4", or an empty string if the version could not be found

Loading…
Cancel
Save