Example #1
0
 /**
  * @type function
  * @name load_configurations
  *
  * Info:
  * @desc Loads this module's configuration file, and merges the values with the defaults provided.
  */
 public function load_configurations()
 {
     if (!file_exists($this->get_directory())) {
         mkdir($this->get_directory());
     }
     $location = $this->get_directory() . "config.ini";
     $configuration_file = new ModuleConfiguration($location, $this->configurations);
     $this->configurations = $configuration_file->read_file();
 }
 /**
  * Save the configuration file corresponding to module object
  *
  * @param string $p_destDirectory
  *
  * @return 0 or string in case of error
  */
 public function save($p_destDirectory = "")
 {
     // check if the object was initialized correctly
     if (!ModuleConfiguration::validModuleName($this->m_moduleName)) {
         return "Invalid module name";
     }
     if (!is_array($this->m_variablesList) || !is_array($this->m_variables)) {
         return "Variables not initialized";
     }
     $moduleName = $this->m_moduleName;
     $directory = $p_destDirectory != "" ? $p_destDirectory : $this->m_directory;
     // compute the configuration file path and create the file
     $variablesList = $this->m_variablesList;
     array_walk($variablesList, 'addslashes_walk');
     $file_path = ModuleConfiguration::configurationFilePath($moduleName, $directory);
     if (!($file = @fopen($file_path, "w+"))) {
         return "Unable to create configuration file \"{$file_path}\"";
     }
     fputs($file, "<?php\n\n");
     foreach ($this->m_variables as $var_name => $value) {
         fputs($file, "\$Campsite['" . addslashes($var_name) . "'] = '" . addslashes($value) . "';\n");
     }
     fputs($file, "\n\$CampsiteVars['" . addslashes($moduleName) . "'] = array('" . implode("', '", $variablesList) . "');\n\n?>");
     fclose($file);
     return 0;
 }