Example #1
0
 public function RegisterFeatures()
 {
     $highlights = OnePanelConfig::GetHighlights();
     if (is_array($highlights)) {
         foreach ($highlights as $key => &$highlight) {
             // If the highlight does not already exist in this modules features
             if (!isset($this->features[self::GetHighlightKey($highlight->GetName())])) {
                 $new_highlight = new HighlightFeature();
                 $new_highlight_key = self::GetHighlightKey($highlight->GetName());
                 $new_highlight->SetTitle($highlight->GetName());
                 $new_highlight->SetSourceType($highlight->GetDefaultSourceType());
                 $new_highlight->SetContentLimit($highlight->GetContentLimit());
                 $new_highlight->SetTitleLimit($highlight->GetTitleLimit());
                 $new_highlight->SetAlternateKey(self::GetHighlightKey($highlight->GetName()));
                 $new_highlight->SetConfigModule($highlight);
                 $new_highlight->Enable();
                 /*
                  * We don't use a refrence here as the source object will be replaced 
                  * after this iteration.
                  */
                 $this->features[$new_highlight_key] = $new_highlight;
                 // We now refrence the permanent object.
                 $this->enabled_features[] =& $this->features[$new_highlight_key];
                 $this->registered_features[] = $new_highlight;
             } else {
                 // If it does exist in the features
                 $stored_highlight_key = self::GetHighlightKey($highlight->GetName());
                 $stored_highlight =& $this->features[$stored_highlight_key];
                 // Make sure its enabled
                 $stored_highlight->Enable();
                 // Set the config module
                 $stored_highlight->SetConfigModule($highlight);
                 /*
                  * This may change if we allow the users to set the content limit at a later date
                  * for now, any changes to the limit in the config fail need to take immediate effect 
                  */
                 $stored_highlight->SetContentLimit($highlight->GetContentLimit());
                 $stored_highlight->SetTitleLimit($highlight->GetTitleLimit());
                 // Garbage collection and enabled state
                 $this->registered_features[] =& $stored_highlight;
                 $this->enabled_features[] = $stored_highlight_key;
             }
             // Set up ajax for it
             add_action('wp_ajax_opcp_' . self::GetHighlightKey($highlight->GetName()) . 'Activate', array($this->features[self::GetHighlightKey($highlight->GetName())], 'Activate'));
             add_action('wp_ajax_opcp_' . self::GetHighlightKey($highlight->GetName()) . 'Deactivate', array($this->features[self::GetHighlightKey($highlight->GetName())], 'Deactivate'));
         }
     }
 }