/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _handler_view($handler_id, array $args, array &$data) { $data['name'] = $args[0]; if (!midcom::get('componentloader')->is_installed($data['name'])) { throw new midcom_error_notfound("Component {$data['name']} is not installed."); } $componentpath = midcom::get('componentloader')->path_to_snippetpath($data['name']); // Load and parse the global config $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc"); if (!$cfg) { // hmmm... that should never happen $cfg = array(); } $config = new midcom_helper_configuration($cfg); // Go for the sitewide default $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$data['name']}/config.inc"); if ($cfg !== false) { $config->store($cfg, false); } // Finally, check the sitegroup config $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$data['name']}/config"); if ($cfg !== false) { $config->store($cfg, false); } $data['config'] =& $config; $this->_update_breadcrumb($data['name']); $this->_prepare_toolbar($data); midcom::get('head')->set_pagetitle($data['view_title']); }
public function load_schemadb() { // Load SchemaDb $schemadb_config_path = midcom::get('componentloader')->path_to_snippetpath($this->_request_data['name']) . '/config/config_schemadb.inc'; $schemadb = null; $schema = 'default'; if (file_exists($schemadb_config_path)) { // Check that the schema is valid DM2 schema $schema_array = midcom_baseclasses_components_configuration::read_array_from_file($schemadb_config_path); if (isset($schema_array['config'])) { $schema = 'config'; } if (!isset($schema_array[$schema]['name'])) { // This looks like DM2 schema $schemadb = midcom_helper_datamanager2_schema::load_database("file:/{$schemadb_config_path}"); } // TODO: Log error on deprecated config schema? } if (!$schemadb) { // Create dummy schema. Naughty component would not provide config schema. $schemadb = midcom_helper_datamanager2_schema::load_database("file:/midgard/admin/asgard/config/schemadb_libconfig.inc"); } $schemadb[$schema]->l10n_schema = $this->_request_data['name']; foreach ($this->_request_data['config']->_global as $key => $value) { // try to sniff what fields are missing in schema if (!array_key_exists($key, $schemadb[$schema]->fields)) { $schemadb[$schema]->append_field($key, $this->_detect_schema($key, $value)); $schemadb[$schema]->fields[$key]['title'] = midcom::get('i18n')->get_string($schemadb[$schema]->fields[$key]['title'], $schemadb[$schema]->l10n_schema); } if (!isset($this->_request_data['config']->_local[$key]) || $this->_request_data['config']->_local[$key] == $this->_request_data['config']->_global[$key]) { // No local configuration setting, note to user that this is the global value $schemadb[$schema]->fields[$key]['title'] = midcom::get('i18n')->get_string($schemadb[$schema]->fields[$key]['title'], $schemadb[$schema]->l10n_schema); $schemadb[$schema]->fields[$key]['title'] .= " <span class=\"global\">(" . midcom::get('i18n')->get_string('global value', 'midgard.admin.asgard') . ")</span>"; } } // Prepare defaults foreach ($this->_request_data['config']->get_all() as $key => $value) { if (!isset($schemadb[$schema]->fields[$key])) { // Skip continue; } if (is_array($value)) { $schemadb[$schema]->fields[$key]['default'] = "array(\n" . $this->_draw_array($value, ' ') . ")"; } else { $schemadb[$schema]->fields[$key]['default'] = $value; } } return $schemadb; }
public function get_libraries() { $libs = array(); foreach (midcom::get('componentloader')->manifests as $name => $manifest) { if (!array_key_exists('package.xml', $manifest->_raw_data)) { // This component is not yet packaged, skip continue; } if ($manifest->purecode) { midcom::get('componentloader')->load_graceful($name); $configpath = midcom::get('componentloader')->path_to_snippetpath($name) . "/config/config.inc"; $lib = midcom_baseclasses_components_configuration::read_array_from_file("{$configpath}"); if (!$lib) { continue; } $libs[$name] = $manifest; } } return $libs; }
/** * @param mixed $handler_id The ID of the handler. * @param Array $args The argument list. * @param Array &$data The local request data. * @return boolean Indicating success. */ public function _handler_edit($handler_id, array $args, array &$data) { $this->_component_name = $args[0]; if (!midcom::get('componentloader')->is_installed($this->_component_name)) { throw new midcom_error_notfound("Component {$this->_component_name} is not installed."); } $componentpath = midcom::get('componentloader')->path_to_snippetpath($this->_component_name); // Load and parse the global config $cfg = midcom_baseclasses_components_configuration::read_array_from_file("{$componentpath}/config/config.inc"); if (!$cfg) { // hmmm... that should never happen $cfg = array(); } $this->_libconfig = new midcom_helper_configuration($cfg); // Go for the sitewide default $cfg = midcom_baseclasses_components_configuration::read_array_from_file("/etc/midgard/midcom/{$this->_component_name}}/config.inc"); if ($cfg !== false) { $this->_libconfig->store($cfg, false); } // Finally, check the sitegroup config $cfg = midcom_baseclasses_components_configuration::read_array_from_snippet("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$this->_component_name}/config"); if ($cfg !== false) { $this->_libconfig->store($cfg, false); } $this->_controller = $this->get_controller('nullstorage'); switch ($this->_controller->process_form()) { case 'save': if ($this->_save_configuration()) { mgd_cache_invalidate(); midcom::get('uimessages')->add($this->_l10n->get('host configuration'), $this->_l10n->get('settings saved successfully') . $this->_codeinit->id, 'ok'); } else { midcom::get('uimessages')->add($this->_l10n->get('host configuration'), sprintf($this->_l10n->get('failed to save settings, reason %s')), 'error'); } // *** FALL-THROUGH *** // *** FALL-THROUGH *** case 'cancel': return new midcom_response_relocate('__mfa/asgard_midcom.admin.libconfig/edit/' . $this->_component_name); } $data['controller'] =& $this->_controller; $this->_update_breadcrumb(); midcom::get('head')->set_pagetitle($data['view_title']); }
/** * The constructor loads the manifest indicated by the filename passed to it. * * If it is a relative path, it is evaluated against MIDCOM_ROOT. Otherwise, * the file is accessed directly. * * @param string $filename The name of the manifest file to load. */ public function __construct($filename) { $this->filename = $filename; $this->_raw_data = midcom_baseclasses_components_configuration::read_array_from_file($filename); $this->_load_manifest(); }