protected function RegisterFeatures() { // Simple ones $this->RegisterFeature('SkinFeatureSwitcher'); $this->RegisterFeature('DefaultSkinFeature'); // Less simple ones $config_skins =& OnePanelConfig::GetSkins(); $config_default_skin =& OnePanelConfig::GetDefaultSkin(); // Other required modules $default_selector_feature =& $this->features['DefaultSkinFeature']; if (is_array($config_skins)) { foreach ($config_skins as $key => &$config_skin) { // The config may have changed so run garbage collection routines $skin_key = self::GetSkinKey($config_skin->GetName()); $stored_skin =& $this->features[$skin_key]; $config_images = $config_skin->GetManagableImages(); $config_styles = $config_skin->GetStyles(); if (is_null($stored_skin)) { // There is no feature in the save map so set everything up from the config $new_skin = new SkinFeature(); $new_skin->SetTitle($config_skin->GetName()); $new_skin->Enable(); $new_skin->SetAsActive(); $new_skin->SetAlternateKey($skin_key); // Add all those lovely images from the config file foreach ($config_images as $key => $image) { $new_skin->AddImage($key, $image); } // Same for the styles foreach ($config_styles as $key => $style_sheet) { $new_skin->AddStyle($key, $style_sheet); } /* * Register the feature * * We don't use a refrence here as the source object will be replaced * after this iteration. */ $this->features[$skin_key] = $new_skin; // We now refrence the permanent object previously created. $this->registered_features[] =& $this->features[$skin_key]; // Make sure we can decipher the enabled state. $this->enabled_features[] = $skin_key; // Is this the default? If so, notify the DefaultSkinFeature. if ($config_default_skin->GetName() == $config_skin->GetName()) { $default_selector_feature->SetDefaultSkin($new_skin); } } else { // Make sure its enabled $stored_skin->Enable(); // Garbage collection and enabled state $this->registered_features[] =& $stored_skin; $this->enabled_features[] = $skin_key; // Check all the images for garbage - will will have to check on the key and not the value! // Need this incase of changes to the config $feature_images = $stored_skin->GetImages(); $config_keys = array_keys($config_images); foreach ($feature_images as $feature_key => &$value) { if (!in_array($feature_key, $config_keys)) { // Remove any images that are in the data but not in the config $stored_skin->RemoveImage($feature_key); } } // Add new images foreach ($config_images as $key => &$image) { if (!$stored_skin->ImageExists($key)) { $stored_skin->AddImage($key, $image); } } // Now the same again for the stylesheets $feature_styles = $stored_skin->GetStyles(); $config_style_keys = array_keys($config_styles); foreach ($feature_styles as $feature_key => &$value) { if (!in_array($feature_key, $config_style_keys)) { // Remove any images that are in the data but not in the config $stored_skin->RemoveStyle($feature_key); } else { // Check to see if the location of the file has changed and revert to config if necessary if ($value != $config_styles[$feature_key]) { $stored_skin->RemoveStyle($feature_key); $stored_skin->AddStyle($feature_key, $config_styles[$feature_key]); } } } // Add new styles foreach ($config_styles as $key => &$style) { if (!$stored_skin->StyleExists($key)) { $stored_skin->AddStyle($key, $style); } } } // Set up ajax for it add_action('wp_ajax_opcp_' . self::GetSkinKey($config_skin->GetName()) . 'Activate', array($this->features[self::GetSkinKey($config_skin->GetName())], 'Activate')); add_action('wp_ajax_opcp_' . self::GetSkinKey($config_skin->GetName()) . 'Deactivate', array($this->features[self::GetSkinKey($config_skin->GetName())], 'Deactivate')); } } /* * Make sure the Default Selector feature has access to the skins * * We need to do this after we have registered the features, otherwise * we may just be populating the selector with an empty array. */ $default_selector_feature->SetSkins($this->GetSkinFeatures()); }