3 * Copyright (c) STMicroelectronics, 2004-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once 'common/plugin/PluginInfo.class.php';
22 require_once 'ForumMLPluginDescriptor.class.php';
23 require_once 'common/include/PropertyDescriptor.class.php';
25 class ForumMLPluginInfo extends PluginInfo {
27 function __construct($plugin) {
28 parent::__construct($plugin);
29 $this->setPluginDescriptor(new ForumMLPluginDescriptor());
30 $this->_conf_path = $plugin->getPluginEtcRoot() .'/forumml.inc';
31 $this->loadProperties();
35 function loadProperties() {
36 if (is_file($this->_conf_path)) {
37 $this->checkConfigurationFiles($this->_conf_path);
38 $variables = $this->_getVariablesFromConfigurationFile($this->_conf_path);
39 foreach($variables as $variable) {
40 $key =& $variable['name'];
41 if (preg_match('`^"(.*)"$`', $variable['value'], $match) ||
42 preg_match('`^\'(.*)\'$`', $variable['value'], $match))
48 $value = $variable['value'];
50 $descriptor = new PropertyDescriptor($key, $value);
51 $this->_addPropertyDescriptor($descriptor);
56 function saveProperties() {
57 copy($this->_conf_path, $this->_conf_path .'.'. date('YmdHis'));
58 $content = file_get_contents($this->_conf_path);
59 $descs =& $this->getPropertyDescriptors();
60 $keys =& $descs->getKeys();
61 $iter =& $keys->iterator();
62 while($iter->valid()) {
63 $key =& $iter->current();
64 $desc =& $descs->get($key);
65 $desc_name =& $desc->getName();
66 if (is_bool($desc->getValue())) {
67 $replace = '$1'. ($desc->getValue() ? 'true' : 'false') .';';
69 $replace = '$1"'.addslashes($desc->getValue()).'";';
71 $content = preg_replace(
72 '`((?:^|\n)\$'. preg_quote($desc_name) .'\s*=\s*)(.*)\s*;`',
78 $f = fopen($this->_conf_path, 'w');
85 function getPropertyValueForName($name) {
86 $desc = $this->getPropertyDescriptorForName($name);
87 return $desc ? $desc->getValue() : $desc;
90 function _getVariablesFromConfigurationFile($file) {
91 $tokens = token_get_all(file_get_contents($file));
95 foreach($tokens as $token) {
98 $variables[$current] = array('name' => substr($token[1], 1), 'value' => '');
101 case T_CONSTANT_ENCAPSED_STRING:
105 if (T_STRING == $token[0] && (!strcasecmp($token[1], "false") || !strcasecmp($token[1], "true"))) {
106 $val = (bool)strcasecmp($token[1], "false");
107 if (isset($variables[$current])) {
108 $variables[$current]['value'] = $val;
111 if (isset($variables[$current])) {
112 $variables[$current]['value'] .= $token[1];
117 if (isset($variables[$current])) {
118 $variables[$current]['value'] .= $token[0];
131 function checkConfigurationFiles() {
132 require($this->_conf_path);