Textpattern | PHP Cross Reference | Content Management Systems |
Description: Styles panel.
1 <?php 2 3 /* 4 * Textpattern Content Management System 5 * http://textpattern.com 6 * 7 * Copyright (C) 2005 Dean Allen 8 * Copyright (C) 2016 The Textpattern Development Team 9 * 10 * This file is part of Textpattern. 11 * 12 * Textpattern is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation, version 2. 15 * 16 * Textpattern is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with Textpattern. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 /** 26 * Styles panel. 27 * 28 * @package Admin\CSS 29 */ 30 31 if (!defined('txpinterface')) { 32 die('txpinterface is undefined.'); 33 } 34 35 if ($event == 'css') { 36 require_privs('css'); 37 38 bouncer($step, array( 39 'pour' => false, 40 'css_save' => true, 41 'css_delete' => true, 42 'css_edit' => false, 43 )); 44 45 switch (strtolower($step)) { 46 case '': 47 css_edit(); 48 break; 49 case 'pour': 50 css_edit(); 51 break; 52 case 'css_save': 53 css_save(); 54 break; 55 case 'css_delete': 56 css_delete(); 57 break; 58 case 'css_edit': 59 css_edit(); 60 break; 61 } 62 } 63 64 /** 65 * Renders a list of stylesheets. 66 * 67 * @param string $current The active stylesheet 68 * @param string $default Not used 69 * @return string HTML 70 */ 71 72 function css_list($current, $default) 73 { 74 $out = array(); 75 $protected = safe_column("DISTINCT css", 'txp_section', "1 = 1"); 76 77 $criteria = 1; 78 $criteria .= callback_event('admin_criteria', 'css_list', 0, $criteria); 79 80 $rs = safe_rows_start("name", 'txp_css', $criteria); 81 82 if ($rs) { 83 while ($a = nextRow($rs)) { 84 extract($a); 85 $active = ($current === $name); 86 87 $edit = eLink('css', '', 'name', $name, $name); 88 89 if (!array_key_exists($name, $protected)) { 90 $edit .= dLink('css', 'css_delete', 'name', $name); 91 } 92 93 $out[] = tag(n.$edit.n, 'li', array( 94 'class' => $active ? 'active' : '', 95 )); 96 } 97 98 $out = tag(join(n, $out), 'ul', array( 99 'class' => 'switcher-list', 100 )); 101 102 return wrapGroup('all_styles', $out, 'all_stylesheets'); 103 } 104 } 105 106 /** 107 * The main stylesheet editor panel. 108 * 109 * @param string|array $message The activity message 110 */ 111 112 function css_edit($message = '') 113 { 114 global $event, $step; 115 116 pagetop(gTxt('edit_css'), $message); 117 118 $default_name = safe_field("css", 'txp_section', "name = 'default'"); 119 120 extract(array_map('assert_string', gpsa(array( 121 'copy', 122 'save_error', 123 'savenew', 124 )))); 125 126 $name = sanitizeForPage(assert_string(gps('name'))); 127 $newname = sanitizeForPage(assert_string(gps('newname'))); 128 129 if ($step == 'css_delete' || empty($name) && $step != 'pour' && !$savenew) { 130 $name = $default_name; 131 } elseif (((($copy || $savenew) && $newname) || ($newname && ($newname != $name))) && !$save_error) { 132 $name = $newname; 133 } 134 135 $titleblock = inputLabel( 136 'new_style', 137 fInput('text', 'newname', $name, 'input-medium', '', '', INPUT_MEDIUM, '', 'new_style', false, true), 138 'css_name', 139 array('', 'instructions_style_name'), 140 array('class' => 'txp-form-field name') 141 ); 142 143 if ($name === '') { 144 $titleblock .= hInput('savenew', 'savenew'); 145 } else { 146 $titleblock .= hInput('name', $name); 147 } 148 149 $titleblock .= eInput('css').sInput('css_save'); 150 151 $thecss = gps('css'); 152 153 if (!$save_error) { 154 $thecss = fetch('css', 'txp_css', 'name', $name); 155 } 156 157 $actionsExtras = ''; 158 159 if ($name) { 160 $actionsExtras .= href('<span class="ui-icon ui-icon-copy"></span> '.gTxt('duplicate'), '#', array( 161 'class' => 'txp-clone', 162 'data-form' => 'style_form', 163 )); 164 } 165 166 $actions = graf( 167 sLink('css', 'pour', '<span class="ui-icon ui-extra-icon-new-document"></span> '.gTxt('create_new_css'), 'txp-new'). 168 $actionsExtras, 169 array('class' => 'txp-actions txp-actions-inline') 170 ); 171 172 $buttons = graf( 173 tag_void('input', array( 174 'class' => 'publish', 175 'type' => 'submit', 176 'method' => 'post', 177 'value' => gTxt('save'), 178 )), ' class="txp-save"' 179 ); 180 181 echo n.'<div class="txp-layout">'. 182 n.tag( 183 hed(gTxt('tab_style'), 1, array('class' => 'txp-heading')), 184 'div', array('class' => 'txp-layout-1col') 185 ); 186 187 // Styles create/switcher column. 188 189 echo n.tag( 190 css_list($name, $default_name).n, 191 'div', array( 192 'class' => 'txp-layout-4col-alt', 193 'id' => 'content_switcher', 194 'role' => 'region', 195 ) 196 ); 197 198 // Styles code columm. 199 200 echo n.tag( 201 form( 202 $actions. 203 $titleblock. 204 inputLabel( 205 'css', 206 '<textarea class="code" id="css" name="css" cols="'.INPUT_LARGE.'" rows="'.TEXTAREA_HEIGHT_LARGE.'" dir="ltr">'.txpspecialchars($thecss).'</textarea>', 207 'css_code', 208 array('', 'instructions_style_code'), 209 array('class' => 'txp-form-field') 210 ). 211 $buttons 212 , '', '', 'post', '', '', 'style_form'), 213 'div', array( 214 'class' => 'txp-layout-4col-3span', 215 'id' => 'main_content', 216 'role' => 'region', 217 ) 218 ); 219 220 echo n.'</div>'; // End of .txp-layout. 221 } 222 223 /** 224 * Saves or clones a stylesheet. 225 */ 226 227 function css_save() 228 { 229 extract(doSlash(array_map('assert_string', psa(array( 230 'savenew', 231 'copy', 232 'css', 233 ))))); 234 235 $name = sanitizeForPage(assert_string(ps('name'))); 236 $newname = sanitizeForPage(assert_string(ps('newname'))); 237 238 $save_error = false; 239 $message = ''; 240 241 if (!$newname) { 242 $message = array(gTxt('css_name_required'), E_ERROR); 243 $save_error = true; 244 } else { 245 if ($copy && ($name === $newname)) { 246 $newname .= '_copy'; 247 $_POST['newname'] = $newname; 248 } 249 250 $exists = safe_field("name", 'txp_css', "name = '".doSlash($newname)."'"); 251 252 if (($newname !== $name) && $exists) { 253 $message = array(gTxt('css_already_exists', array('{name}' => $newname)), E_ERROR); 254 if ($savenew) { 255 $_POST['newname'] = ''; 256 } 257 258 $save_error = true; 259 } else { 260 if ($savenew or $copy) { 261 if ($newname) { 262 if (safe_insert('txp_css', "name = '".doSlash($newname)."', css = '$css'")) { 263 update_lastmod('css_created', compact('newname', 'name', 'css')); 264 $message = gTxt('css_created', array('{name}' => $newname)); 265 } else { 266 $message = array(gTxt('css_save_failed'), E_ERROR); 267 $save_error = true; 268 } 269 } else { 270 $message = array(gTxt('css_name_required'), E_ERROR); 271 $save_error = true; 272 } 273 } else { 274 if (safe_update('txp_css', "css = '$css', name = '".doSlash($newname)."'", "name = '".doSlash($name)."'")) { 275 safe_update('txp_section', "css = '".doSlash($newname)."'", "css='".doSlash($name)."'"); 276 update_lastmod('css_saved', compact('newname', 'name', 'css')); 277 $message = gTxt('css_updated', array('{name}' => $name)); 278 } else { 279 $message = array(gTxt('css_save_failed'), E_ERROR); 280 $save_error = true; 281 } 282 } 283 } 284 } 285 286 if ($save_error === true) { 287 $_POST['save_error'] = '1'; 288 } else { 289 callback_event('css_saved', '', 0, $name, $newname); 290 } 291 292 css_edit($message); 293 } 294 295 /** 296 * Deletes a stylesheet. 297 */ 298 299 function css_delete() 300 { 301 $name = ps('name'); 302 $count = safe_count('txp_section', "css = '".doSlash($name)."'"); 303 $message = ''; 304 305 if ($count) { 306 $message = array(gTxt('css_used_by_section', array('{name}' => $name, '{count}' => $count)), E_ERROR); 307 } else { 308 if (safe_delete('txp_css', "name = '".doSlash($name)."'")) { 309 callback_event('css_deleted', '', 0, $name); 310 $message = gTxt('css_deleted', array('{name}' => $name)); 311 } 312 } 313 css_edit($message); 314 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title