[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * Horde Template Admin 4 * 5 * $Horde: horde/admin/templates.php,v 1.15.10.3 2006/01/01 21:28:05 jan Exp $ 6 * 7 * First stab at a template loader for horde, to be used by the horde 8 * admin to load alternate individual templates or entire themes for the 9 * Horde_Template system. 10 * - gives a list of active horde apps and their /templates directory 11 * contents to choose from 12 * - user can drill down to a specific file and load as many alternate 13 * templates as required 14 * - it allows saving of templates only on actual files (and not 15 * directories) and does not show hidden files. 16 * - the alternate templates are stored in the VFS under the directory 17 * path: 18 * .horde_templates/$app/sometemplatedir/templatefile 19 * so that directory would contain all the alternatives for that 20 * template. 21 * - TODO: don't show certain other files, like CVS directories; comments; 22 * theme selection and storing in the VFS under: 23 * .horde_templates/$app/_themes/$theme/sometemplatedir/templatefile 24 * to be able to call up an entire theme group of templates? better error 25 * checking; downloading of original templates; the application side of 26 * allowing a different template to be chosen/prefs/etc. 27 * 28 * Copyright 2003-2006 Marko Djukic <marko@oblo.com> 29 * 30 * See the enclosed file COPYING for license information (LGPL). If you 31 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 32 */ 33 34 @define('HORDE_BASE', dirname(__FILE__) . '/..'); 35 require_once HORDE_BASE . '/lib/base.php'; 36 require_once 'Horde/Menu.php'; 37 require_once 'Horde/Variables.php'; 38 39 if (!Auth::isAdmin()) { 40 Horde::fatal('Forbidden.', __FILE__, __LINE__); 41 } 42 $auth = &Auth::singleton($conf['auth']['driver']); 43 44 function _setValuesToKeys($in) { 45 $out = array(); 46 foreach ($in as $value) { 47 $out[$value] = $value; 48 } 49 asort($out); 50 return $out; 51 } 52 53 /* Set up VFS. */ 54 require_once 'VFS.php'; 55 $vfs_type = $conf['vfs']['type']; 56 $vfs_args = Horde::getDriverConfig('vfs', $vfs_type); 57 $vfs_args['user'] = Auth::getAuth(); 58 $vfs = &VFS::singleton($vfs_type, $vfs_args); 59 60 @define('TEMPLATES_VFS_PATH', '.horde_templates'); 61 62 /* Require Horde_Form libs. */ 63 require_once 'Horde/Form.php'; 64 require_once 'Horde/Form/Renderer.php'; 65 require_once 'Horde/Form/Action.php'; 66 67 /* Set up Horde_Form. */ 68 $vars = &Variables::getDefaultVariables(); 69 $form = &Horde_Form::singleton('TemplatesForm', $vars); 70 $action = &Horde_Form_Action::factory('submit'); 71 72 /* Set up form fields. */ 73 $apps = _setValuesToKeys($registry->listApps()); 74 $select_app = &$form->addVariable(_("Application"), 'app', 'enum', true, false, null, array($apps)); 75 $select_app->setAction($action); 76 $form->addHidden('', 'old_app', 'text', false, false); 77 78 /* Set up some variables. */ 79 $formname = $vars->get('formname'); 80 $app = $vars->get('app'); 81 $old_app = $vars->get('old_app'); 82 $template_path = $vars->get('template_path'); 83 $template_orig = $vars->get('template_orig'); 84 $old_template_orig = $vars->get('old_template_orig'); 85 $has_changed = false; 86 87 if ($app != $old_app) { 88 $has_changed = true; 89 $template_path = ''; 90 $template_orig = ''; 91 $old_template_orig = ''; 92 } 93 $vars->set('old_app', $app); 94 if ($template_orig != $old_template_orig) { 95 $has_changed = true; 96 } 97 $vars->set('old_template_orig', $template_orig); 98 99 if (!is_null($app)) { 100 if ($template_orig == '..') { 101 $path_parts = explode('/', $template_path); 102 array_pop($path_parts); 103 $template_path = implode('/', $path_parts); 104 $template_orig = ''; 105 } 106 107 /* Get the full template path on the file system. */ 108 $template_path_full = $registry->get('templates', $app) . '/' . $template_path; 109 110 /* If selected template is directory add to template path. */ 111 if (!empty($template_orig) && 112 is_dir($template_path_full . '/' . $template_orig)) { 113 $template_path .= '/' . $template_orig; 114 $template_path_full .= '/' . $template_orig; 115 } 116 117 $form->addVariable(sprintf(_("Original templates in %s:"), $template_path), 'orig_templates_header', 'header', false, false); 118 119 /* Add the path to the hidden var in the form. */ 120 $form->addHidden('', 'template_path', 'text', false, false); 121 $vars->set('template_path', $template_path); 122 123 /* Get directory list for chosen directory in templates. */ 124 if ($templates_dir = opendir($template_path_full)) { 125 while (false !== ($file = readdir($templates_dir))) { 126 /* Don't show current dir, hidden files and only show '..' 127 * if not in root dir of an app's templates. */ 128 if ($file != "." && !($file == '..' && empty($template_path)) && 129 !($file != '..' && substr($file, 0, 1) == '.')) { 130 $templates[] = $file; 131 } 132 } 133 closedir($templates_dir); 134 $templates = _setValuesToKeys($templates); 135 $v = &$form->addVariable(_("Original application template"), 'template_orig', 'enum', true, false, null, array($templates)); 136 $v->setAction($action); 137 $form->addHidden('', 'old_template_orig', 'text', false, false); 138 } 139 140 /* Only set up these vars if the chosen template is a file. */ 141 if (is_file($template_path_full . '/' . $template_orig)) { 142 $form->addVariable(_("Alternate templates"), 'alt_templates_header', 'header', false, false); 143 144 /* Get the already saved alternate templates. */ 145 $vfs_path = TEMPLATES_VFS_PATH . '/' . $app . $template_path . '/' . $template_orig; 146 $templates_alt = array_keys($vfs->listFolder($vfs_path, null, false)); 147 $templates_alt = array('' => '') + _setValuesToKeys($templates_alt); 148 $form->addVariable(_("Delete existing alternate template"), 'delete_template_alt', 'enum', false, false, null, array($templates_alt)); 149 150 $form->addVariable(_("Insert alternate template"), 'template_alt', 'file', false, false); 151 } 152 } 153 154 if ($formname && !$has_changed) { 155 /* Inserting a new alternate template. */ 156 $form->validate($vars); 157 158 if ($form->isValid()) { 159 $form->getInfo($vars, $info); 160 if (!empty($info['delete_template_alt'])) { 161 $vfs->deleteFile($vfs_path, $info['delete_template_alt']); 162 } 163 if (!empty($info['template_alt']['size'])) { 164 $vfs->write($vfs_path, $info['template_alt']['name'], $info['template_alt']['tmp_name'], true); 165 } 166 } 167 } 168 169 $title = _("Template Administration"); 170 require HORDE_TEMPLATES . '/common-header.inc'; 171 require HORDE_TEMPLATES . '/admin/common-header.inc'; 172 $notification->notify(array('listeners' => 'status')); 173 174 /* Render the form. */ 175 $renderer = &new Horde_Form_Renderer(); 176 $form->renderActive($renderer, $vars, 'templates.php', 'post'); 177 178 require HORDE_TEMPLATES . '/common-footer.inc';
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |