[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Installation 5 * 6 * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Installation\Form\Field\Installation; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\Form\FormField; 14 15 // phpcs:disable PSR1.Files.SideEffects 16 \defined('_JEXEC') or die; 17 // phpcs:enable PSR1.Files.SideEffects 18 19 /** 20 * Database Prefix field. 21 * 22 * @since 1.6 23 */ 24 class PrefixField extends FormField 25 { 26 /** 27 * The form field type. 28 * 29 * @var string 30 * @since 1.6 31 */ 32 protected $type = 'Prefix'; 33 34 /** 35 * Method to get the field input markup. 36 * 37 * @return string The field input markup. 38 * 39 * @since 1.6 40 */ 41 protected function getInput() 42 { 43 // Initialize some field attributes. 44 $size = $this->element['size'] ? abs((int) $this->element['size']) : 5; 45 $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; 46 $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; 47 $readonly = (string) $this->element['readonly'] === 'true' ? ' readonly="readonly"' : ''; 48 $disabled = (string) $this->element['disabled'] === 'true' ? ' disabled="disabled"' : ''; 49 50 // Make sure somebody doesn't put in a too large prefix size value. 51 if ($size > 10) { 52 $size = 10; 53 } 54 55 // If a prefix is already set, use it instead. 56 $session = Factory::getSession()->get('setup.options', array()); 57 58 if (empty($session['db_prefix'])) { 59 // Create the random prefix. 60 $prefix = ''; 61 $chars = range('a', 'z'); 62 $numbers = range(0, 9); 63 64 // We want the fist character to be a random letter. 65 shuffle($chars); 66 $prefix .= $chars[0]; 67 68 // Next we combine the numbers and characters to get the other characters. 69 $symbols = array_merge($numbers, $chars); 70 shuffle($symbols); 71 72 for ($i = 0, $j = $size - 1; $i < $j; ++$i) { 73 $prefix .= $symbols[$i]; 74 } 75 76 // Add in the underscore. 77 $prefix .= '_'; 78 } else { 79 $prefix = $session['db_prefix']; 80 } 81 82 // Initialize JavaScript field attributes. 83 $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; 84 85 return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . 86 ' value="' . htmlspecialchars($prefix, ENT_COMPAT, 'UTF-8') . '"' . 87 $class . $disabled . $readonly . $onchange . $maxLength . '>'; 88 } 89 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |