function index() { $this->template->content = new View('admin/addons/themes'); $this->template->content->title = 'Addons'; // setup and initialize form field names $form = array('site_style' => ''); // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; // check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST // fields with our own things $post = new Validation($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('site_style', 'length[1,50]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid Settings_Model::save_setting('site_style', $post->site_style); // Everything is A-Okay! $form_saved = TRUE; // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('settings')); $form_error = TRUE; } } else { $site_style = Settings_Model::get_setting('site_style'); // Retrieve Current Settings $form = array('site_style' => !empty($site_style) ? $site_style : 'default'); } $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $themes = addon::get_addons('theme'); foreach ($themes as $key => $theme) { // We want to hide checkin themes if checkins is not enabled if (!Kohana::config('settings.checkins') and $theme['Checkins'] == 1) { unset($themes[$key]); } } $this->template->content->themes = $themes; }
/** * Tests addon::get_addons() * * @test */ public function test_get_addons() { $themes = addon::get_addons('theme'); $plugins = addon::get_addons('plugin'); // Check for bundled plugins $this->assertArrayHasKey('smssync', $plugins); $this->assertArrayHasKey('sharing', $plugins); // Check for bundled themes $this->assertArrayHasKey('default', $themes); $this->assertArrayHasKey('unicorn', $themes); // Check for themes not in plugins and vice versa $this->assertArrayNotHasKey('default', $plugins, 'Theme "default" returned in get_addons(\'plugin\') array'); $this->assertArrayNotHasKey('smssync', $themes, 'Plugin "smssync" returned in get_addons(\'theme\') array'); // @todo test includeMeta $themes_nometa = addon::get_addons('theme', FALSE); $themes_meta = addon::get_addons('theme', TRUE); $this->assertNotEmpty($themes_meta['default'], 'get_addons(\'theme\', TRUE) not returning meta array'); $this->assertEmpty($themes_nometa['default'], 'get_addons(\'theme\', FALSE) not returning empty meta array'); }
/** * Loads ushahidi themes */ public static function register_theme() { self::$themes = addon::get_addons('theme', TRUE); $theme = Kohana::config("settings.site_style"); $theme = empty($theme) ? 'default' : $theme; self::load_theme($theme); }
/** * Resync plugins in codebase with database */ public static function resync_plugins() { $plugins = addon::get_addons('plugin', FALSE); // Get all plugins from the db $plugins_db = ORM::factory('plugin')->select_list('id', 'plugin_name'); // Sync the folder with the database foreach ($plugins as $dir => $plugin) { if (!in_array($dir, $plugins_db)) { $plugin = ORM::factory('plugin'); $plugin->plugin_name = $dir; $plugin->save(); } } // Remove any plugins not found in the plugins folder and not previously installed from the database foreach (ORM::factory('plugin')->where('plugin_installed', 0)->find_all() as $plugin) { if (!array_key_exists($plugin->plugin_name, $plugins)) { $plugin->delete(); } } }