/** * Themes admin page * * @param App $a * @return string */ function admin_page_themes(&$a) { $allowed_themes_str = get_config('system', 'allowed_themes'); $allowed_themes_raw = explode(',', $allowed_themes_str); $allowed_themes = array(); if (count($allowed_themes_raw)) { foreach ($allowed_themes_raw as $x) { if (strlen(trim($x))) { $allowed_themes[] = trim($x); } } } $themes = array(); $files = glob('view/theme/*'); /* */ if ($files) { foreach ($files as $file) { $f = basename($file); $is_experimental = intval(file_exists($file . '/experimental')); $is_supported = 1 - intval(file_exists($file . '/unsupported')); $is_allowed = intval(in_array($f, $allowed_themes)); if ($is_allowed or $is_supported or get_config("system", "show_unsupported_themes")) { $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed); } } } if (!count($themes)) { notice(t('No themes found.')); return ''; } /** * Single theme */ if ($a->argc == 3) { $theme = $a->argv[2]; if (!is_dir("view/theme/{$theme}")) { notice(t("Item not found.")); return ''; } if (x($_GET, "a") && $_GET['a'] == "t") { check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't'); // Toggle theme status toggle_theme($themes, $theme, $result); $s = rebuild_theme_table($themes); if ($result) { install_theme($theme); info(sprintf('Theme %s enabled.', $theme)); } else { uninstall_theme($theme); info(sprintf('Theme %s disabled.', $theme)); } set_config('system', 'allowed_themes', $s); goaway($a->get_baseurl(true) . '/admin/themes'); return ''; // NOTREACHED } // display theme details require_once 'library/markdown.php'; if (theme_status($themes, $theme)) { $status = "on"; $action = t("Disable"); } else { $status = "off"; $action = t("Enable"); } $readme = Null; if (is_file("view/theme/{$theme}/README.md")) { $readme = file_get_contents("view/theme/{$theme}/README.md"); $readme = Markdown($readme); } else { if (is_file("view/theme/{$theme}/README")) { $readme = "<pre>" . file_get_contents("view/theme/{$theme}/README") . "</pre>"; } } $admin_form = ""; if (is_file("view/theme/{$theme}/config.php")) { require_once "view/theme/{$theme}/config.php"; if (function_exists("theme_admin")) { $admin_form = theme_admin($a); } } $screenshot = array(get_theme_screenshot($theme), t('Screenshot')); if (!stristr($screenshot[0], $theme)) { $screenshot = null; } $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Themes'), '$toggle' => t('Toggle'), '$settings' => t('Settings'), '$baseurl' => $a->get_baseurl(true), '$plugin' => $theme, '$status' => $status, '$action' => $action, '$info' => get_theme_info($theme), '$function' => 'themes', '$admin_form' => $admin_form, '$str_author' => t('Author: '), '$str_maintainer' => t('Maintainer: '), '$screenshot' => $screenshot, '$readme' => $readme, '$form_security_token' => get_form_security_token("admin_themes"))); } /** * List themes */ $xthemes = array(); if ($themes) { foreach ($themes as $th) { $xthemes[] = array($th['name'], $th['allowed'] ? "on" : "off", get_theme_info($th['name'])); } } $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Themes'), '$submit' => t('Save Settings'), '$baseurl' => $a->get_baseurl(true), '$function' => 'themes', '$plugins' => $xthemes, '$experimental' => t('[Experimental]'), '$unsupported' => t('[Unsupported]'), '$form_security_token' => get_form_security_token("admin_themes"))); }
public function themes($e = 'main', $a = 1) { current_user()->cannot('system@manage_themes') ? $this->url->redirect(array('admin', 'index?notice=accessDenied')) : false; redirect_if_webapp_is_enabled(); if ($e == 'main') { js_push_if_not_exists('jtransit/jquery.transit.min'); set_page('title', translate('Manage themes - Tendoo')); set_core_vars('ttThemes', $ttThemes = count(get_themes()), 'read_only'); set_core_vars('paginate', $paginate = $this->tendoo->paginate(10, $ttThemes, 1, "bg-color-blue fg-color-white", "bg-color-white fg-color-blue", $a, $this->url->site_url(array('admin', 'modules', 'main')) . '/'), 'read_only'); // Pagination set_core_vars('themes_list', get_themes('list_all', $paginate[1], $paginate[2]), 'read_only'); $this->load->the_view('admin/themes/main'); } else { if ($e == 'manage') { $this->load->library('form_validation'); $this->form_validation->set_rules('action', translate('Set as active theme')); $this->form_validation->set_rules('theme_namespace', translate('theme id'), 'required'); if ($this->form_validation->run()) { if ($this->input->post('action') == 'ADMITSETDEFAULT') { if (active_theme($this->input->post('theme_namespace'))) { echo json_encode(array('status' => 'success', 'alertType' => 'notice', 'message' => translate('The theme has been set as active'), 'response' => 'theme_set')); return; } echo json_encode(array('status' => 'warning', 'alertType' => 'modal', 'message' => translate('Error occured, this theme can\'t been set as active'), 'response' => 'theme_set_failure')); return; } } $this->form_validation->set_rules('action', translate('Delete theme')); $this->form_validation->set_rules('theme_namespace', translate('Theme id'), 'required'); if ($this->form_validation->run()) { if ($this->input->post('action') == 'ADMITDELETETHEME') { $status = uninstall_theme($this->input->post('theme_namespace')); if ($status) { echo json_encode(array('status' => 'success', 'alertType' => 'notice', 'message' => translate('The theme has been deleted'), 'response' => 'theme_deleted')); return; } echo json_encode(array('status' => 'warning', 'alertType' => 'modal', 'message' => translate('Error occured, this theme can\'t be deleted'), 'response' => 'theme_deletion_failure')); return; } } } else { $this->url->redrect(array('error', 'code', 'page-404')); } } }