setDBO(VoxelCareDB::getDatabase()); } function getFilePath() { return JPATH_BASE. '/components/com_vxc/settings_'.SiteOptionsHelper::getFranchiseName().'.json'; // return $_SERVER['DOCUMENT_ROOT'].'/settings.json'; } function getVar($key, $defaultValue=null) { $settings =& $this->getSettings(); $keyParts = explode('.',$key); $returnValue = $settings; for ($i=0;$i{$keyParts[$i]}; if (($i != count($keyParts) -1) && $returnValue=== NULL) return $defaultValue; } if ($returnValue===NULL) return $defaultValue; else return $returnValue; } function getSettings() { if (!$this->_settings) { $session =& JFactory::getSession(); $settings = $session->get('jsonsettings',null,'vxc'); $fileIniPath = $this->getFilePath(); if ($settings!==null) { $timeIniChange = @filemtime($fileIniPath); if ($timeIniChange===FALSE) return $settings; $settingsStoreDate = $session->get('jsonsettingsstoredate',null,'vxc'); if ($settingsStoreDate ===null ) $iniChanged = true; else $iniChanged = $timeIniChange > $settingsStoreDate; } else $iniChanged = true; if ($iniChanged) { $json = new Services_JSON(); $dataJSON = @file_get_contents($fileIniPath); $settings = new stdClass(); if ($dataJSON!==FALSE) { $settings = $json->decode($dataJSON); if (!$settings) $settings = new stdClass(); } $session->set('jsonsettingsstoredate',time(),'vxc'); $session->set('jsonsettings',$settings,'vxc'); } $this->_settings = $settings; } return $this->deepCopy($this->_settings); } function deepCopy($object){ return unserialize(serialize($object)); } function recoverBackup() { $filePath = $this->getFilePath(); $backupFilePath = $filePath.".old"; @copy($backupFilePath,$filePath); @chmod($filePath,0666); } function mergeSettings(&$dst,$src) { if (!is_object($dst) || !is_object($src)) return; foreach(get_object_vars($src) as $key => $srcChild) { if (is_object($srcChild)) { if (!is_object($dst->{$key})) $dst->{$key} = new stdClass(); $this->mergeSettings($dst->{$key},$srcChild); } else { $dst->{$key} = $srcChild; } } } function storeAsText(&$settings) { $filePath = $this->getFilePath(); // Backup storage $backupFilePath = $filePath.".".strtotime ("now"); @copy($filePath,$backupFilePath); @chmod($backupFilePath,0666); $fic=@fopen($filePath,"wb"); if ($fic) { @fputs($fic,$settings); @fclose($fic); @chmod($filePath,0666); } } function getSettingsAsText() { $filePath = $this->getFilePath(); $contents = @file_get_contents($filePath); if ($contents===FALSE) return ""; else return $contents; } }// class