/**
  * @param string $active_theme_path
  * @param string $default_theme_path
  * @param string $default_theme_path
  * @return Ai1ec_Lessphp_Controller
  */
 public static function create_lessphp_controller()
 {
     $lessc = self::create_lessc_instance();
     $lessphp_controller = new Ai1ec_Lessphp_Controller($lessc, self::$default_theme_url, Ai1ec_Adapters_Factory::create_db_adapter_instance());
     foreach (self::$files as $file) {
         $file = self::create_less_file_instance($file, self::$active_theme_path, self::$default_theme_path);
         $lessphp_controller->add_file($file);
     }
     // Set the variable.less file
     $variable_file = self::create_less_file_instance('variables', self::$active_theme_path, self::$default_theme_path);
     $lessphp_controller->set_variable_file($variable_file);
     return $lessphp_controller;
 }
 /**
  * Try to get the CSS from cache.
  * If it's not there re-generate it and save it to cache
  * If we are in preview mode, recompile the css using the theme present in the url.
  *
  */
 private function get_compiled_css()
 {
     try {
         // If we want to force a recompile, we throw an exception.
         if ($this->preview_mode === true || self::PARSE_LESS_FILES_AT_EVERY_REQUEST === true) {
             throw new Ai1ec_Cache_Not_Set_Exception();
         } else {
             // This throws an exception if the key is not set
             $css = $this->persistance_context->get_data_from_persistence();
             return $css;
         }
     } catch (Ai1ec_Cache_Not_Set_Exception $e) {
         // If we are in preview mode we force a recompile and we pass the variables.
         if ($this->preview_mode) {
             return $this->lessphp_controller->parse_less_files($this->lessphp_controller->get_less_variable_data_from_config_file(Ai1ec_Less_Factory::create_less_file_instance(Ai1ec_Less_File::USER_VARIABLES_FILE)));
         } else {
             $css = $this->lessphp_controller->parse_less_files();
         }
         try {
             $this->update_persistence_layer($css);
             return $css;
         } catch (Ai1ec_Cache_Write_Exception $e) {
             // If something is really broken, still return the css.
             // This means we parse it every time. This should never happen.
             return $css;
         }
     }
 }
 /**
  * Adds al the elements to the page.
  * I took this out of the factory so that it's done only if the page is clicked
  */
 private function add_renderables_to_page()
 {
     // These are the tabs
     $tabs_ids_description = array('general' => __('General', AI1EC_PLUGIN_NAME), 'table' => __('Tables', AI1EC_PLUGIN_NAME), 'buttons' => __('Buttons', AI1EC_PLUGIN_NAME), 'forms' => __('Forms', AI1EC_PLUGIN_NAME), 'calendar' => __('Calendar general', AI1EC_PLUGIN_NAME), 'posterboard' => __('Posterboard view', AI1EC_PLUGIN_NAME), 'stream' => __('Stream view', AI1EC_PLUGIN_NAME), 'month' => __('Month/week/day view', AI1EC_PLUGIN_NAME), 'agenda' => __('Agenda view', AI1EC_PLUGIN_NAME));
     // Create the tab layout
     $bootstrap_tabs_layout = Ai1ec_Helper_Factory::create_bootstrap_tabs_layout_instance();
     $bootstrap_tabs_layout->set_layout('left');
     $less_variables = Ai1ec_Lessphp_Controller::get_saved_variables(Ai1ec_Adapters_Factory::create_db_adapter_instance());
     // Inizialize the array of tabs that will be added to the layout
     $bootstrap_tabs_to_add = array();
     // initialize the array of tab bodyes that will be added to the tabs
     $tabs_bodies = array();
     foreach ($tabs_ids_description as $id => $description) {
         $bootstrap_tabs_to_add["ai1ec-{$id}"] = Ai1ec_Helper_Factory::create_bootstrap_tab_instance($id, $description);
         $bootstrap_tabs_to_add["ai1ec-{$id}"]->add_class('form-horizontal');
         // create the main div that will hold all the variables
         $div = Ai1ec_Helper_Factory::create_generic_html_tag('div');
         $tabs_bodies["ai1ec-{$id}"] = $div;
     }
     foreach ($less_variables as $variable_id => $variable_attributes) {
         $variable_attributes['id'] = $variable_id;
         $less_variable = Ai1ec_Less_Factory::create_less_variable($variable_attributes['type'], $variable_attributes);
         $tabs_bodies["ai1ec-{$variable_attributes['tab']}"]->add_renderable_children($less_variable);
     }
     foreach ($tabs_bodies as $tab => $div) {
         $bootstrap_tabs_to_add[$tab]->add_renderable_children($div);
     }
     foreach ($bootstrap_tabs_to_add as $tab) {
         $bootstrap_tabs_layout->add_renderable_children($tab);
     }
     $this->add_renderable_children($bootstrap_tabs_layout);
     $input = Ai1ec_Helper_Factory::create_input_instance();
     $input->set_type('submit');
     $input->set_value(__('Save Options', AI1EC_PLUGIN_NAME));
     $input->set_name(Ai1ec_Less_Variables_Editing_Page::FORM_SUBMIT_NAME);
     $input->add_class("button-primary");
     $reset_theme = Ai1ec_Helper_Factory::create_input_instance();
     $reset_theme->set_type('submit');
     $reset_theme->set_value(__('Reset to defaults', AI1EC_PLUGIN_NAME));
     $reset_theme->set_name(Ai1ec_Less_Variables_Editing_Page::FORM_SUBMIT_RESET_THEME);
     $reset_theme->add_class("button");
     $reset_theme->set_id('ai1ec-reset-variables');
     $this->add_renderable_children($input);
     $this->add_renderable_children($reset_theme);
 }