function tk_populate_initial_theme_settings_data() { require get_template_directory() . '/config/admin-config.php'; $i = 0; $last_val = ''; $tab_name = ''; foreach ($tabs as $tab) { foreach ($tab as $tab1) { if (!is_array($tab1)) { if (ctype_lower($tab1)) { $tab_name = $tab1; } // if } // check if tab1 is array foreach ((array) $tab1 as $tab2) { if (isset($tab2['name']) && isset($tab2['value']) && isset($tab2['type'])) { if (!empty($tab2['value']) && $tab2['type'] != 'select') { if (get_option(wp_get_theme()->name . '_' . $tab2['name']) == false) { update_option(wp_get_theme()->name . '_' . $tab_name . '_' . $tab2['name'], $tab2['value']); } // if have name } // if have value, type } // if have name, valua and type } // foreach tab1 } // foreach tab } // foreach tabs }
/** * Returns Expression function implementation as closure * * @return \Closure */ public function expressionFunction() { return function ($arguments) { $string = $arguments[0]; return ctype_lower($string); }; }
/** * Create and position pieces of the game for the forsyth string * * @param Game $game * @param string $forsyth * @return Game $game */ public static function import(Game $game, $forsyth) { static $classes = array('p' => 'Pawn', 'r' => 'Rook', 'n' => 'Knight', 'b' => 'Bishop', 'q' => 'Queen', 'k' => 'King'); $x = 1; $y = 8; $board = $game->getBoard(); $forsyth = str_replace('/', '', preg_replace('#\\s*([\\w\\d/]+)\\s.+#i', '$1', $forsyth)); $pieces = array('white' => array(), 'black' => array()); for ($itForsyth = 0, $forsythLen = strlen($forsyth); $itForsyth < $forsythLen; $itForsyth++) { $letter = $forsyth[$itForsyth]; if (is_numeric($letter)) { $x += intval($letter); } else { $color = ctype_lower($letter) ? 'black' : 'white'; $pieces[$color][] = new Piece($x, $y, $classes[strtolower($letter)]); ++$x; } if ($x > 8) { $x = 1; --$y; } } foreach ($game->getPlayers() as $player) { $player->setPieces($pieces[$player->getColor()]); } $game->ensureDependencies(); }
function validate($css, $config, &$context) { $css = $this->parseCDATA($css); $definition = $config->getCSSDefinition(); // we're going to break the spec and explode by semicolons. // This is because semicolon rarely appears in escaped form // Doing this is generally flaky but fast // IT MIGHT APPEAR IN URIs, see HTMLPurifier_AttrDef_CSSURI // for details $declarations = explode(';', $css); $propvalues = array(); foreach ($declarations as $declaration) { if (!$declaration) { continue; } if (!strpos($declaration, ':')) { continue; } list($property, $value) = explode(':', $declaration, 2); $property = trim($property); $value = trim($value); $ok = false; do { if (isset($definition->info[$property])) { $ok = true; break; } if (ctype_lower($property)) { break; } $property = strtolower($property); if (isset($definition->info[$property])) { $ok = true; break; } } while (0); if (!$ok) { continue; } // inefficient call, since the validator will do this again if (strtolower(trim($value)) !== 'inherit') { // inherit works for everything (but only on the base property) $result = $definition->info[$property]->validate($value, $config, $context); } else { $result = 'inherit'; } if ($result === false) { continue; } $propvalues[$property] = $result; } // procedure does not write the new CSS simultaneously, so it's // slightly inefficient, but it's the only way of getting rid of // duplicates. Perhaps config to optimize it, but not now. $new_declarations = ''; foreach ($propvalues as $prop => $value) { $new_declarations .= "{$prop}:{$value};"; } return $new_declarations ? $new_declarations : false; }
public static function asSnakeCase($value) { if (!is_string($value)) { return $value; } return ctype_lower($value) ? $value : mb_strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $value)); }
/** * Initializes the object depending of the name in Api specifications * * @param string $name object name * @return ApiEntity|DetailsResponse|ListResponse|ObjectEntity|Property */ public static function init($name) { if (preg_match('#^.*(List|Details)(Response)$#', $name, $match)) { return $match[1] == 'List' ? new ListResponse($name) : new DetailsResponse($name); } return ctype_lower($name[0]) ? new Property($name) : (preg_match('#^Api#', $name) ? new ApiEntity($name) : new ObjectEntity($name)); }
public function validate($length, $config, $context) { $length = $this->parseCDATA($length); if ($length === '') { return false; } if ($length === '0') { return '0'; } $strlen = strlen($length); if ($strlen === 1) { return false; } // impossible! // we assume all units are two characters $unit = substr($length, $strlen - 2); if (!ctype_lower($unit)) { $unit = strtolower($unit); } $number = substr($length, 0, $strlen - 2); if (!isset($this->units[$unit])) { return false; } $number = $this->number_def->validate($number, $config, $context); if ($number === false) { return false; } return $number . $unit; }
/** * Validates the number and unit. */ function validate() { // Special case: static $allowedUnits = array('em' => true, 'ex' => true, 'px' => true, 'in' => true, 'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true); if ($this->n === '+0' || $this->n === '-0') { $this->n = '0'; } if ($this->n === '0' && $this->unit === false) { return true; } if (!ctype_lower($this->unit)) { $this->unit = strtolower($this->unit); } if (!isset($allowedUnits[$this->unit])) { return false; } // Hack: $def = new HTMLPurifier_AttrDef_CSS_Number(); $a = false; // hack hack $result = $def->validate($this->n, $a, $a); if ($result === false) { return false; } $this->n = $result; return true; }
function crypto($n, $string, $k) { $low = range('a', 'z'); $high = range('A', 'Z'); $newLetters = []; for ($i = 0; $i < $n; $i++) { $letter = $string[$i]; switch (true) { case ctype_upper($letter): $off = offsetK(array_search($letter, $high) + $k); $new = array_slice($high, $off, 1)[0]; break; case ctype_lower($letter): $off = offsetK(array_search($letter, $low) + $k); $new = array_slice($low, $off, 1)[0]; break; case ctype_digit($letter): $new = $letter; break; default: $new = $letter; break; } $newLetters[] = $new; } return implode('', $newLetters); }
/** * Get composite properties * * @param $class_name string|object The composite class name or object * @param $property_name string The composite property name * @return Reflection_Property[] key is the name of the property */ public static function getCompositeProperties($class_name = null, $property_name = null) { // flexible parameters : first parameter can be a property name alone if (!isset($property_name) && is_string($class_name) && !empty($class_name)) { if (ctype_lower($class_name[0])) { $property_name = $class_name; $class_name = null; } } elseif (is_object($class_name)) { $class_name = get_class($class_name); } $self = get_called_class(); $path = $self . DOT . $class_name . DOT . $property_name; if (!isset(self::$composite_property_name[$path])) { self::$composite_property_name[$path] = []; $properties = empty($property_name) ? (new Reflection_Class($self))->getAnnotedProperties('composite') : [new Reflection_Property($self, $property_name)]; // take the right composite property foreach ($properties as $property) { if (!isset($class_name) || is_a($class_name, $property->getType()->asString(), true)) { self::$composite_property_name[$path][$property->name] = $property; } } if (!self::$composite_property_name[$path]) { // automatic composite property : filter all properties by class name as type foreach ((new Reflection_Class($self))->getProperties([T_EXTENDS, T_USE]) as $property) { if (!isset($class_name) || is_a($class_name, $property->getType()->asString(), true)) { self::$composite_property_name[$path][$property->name] = $property; } } } } return self::$composite_property_name[$path]; }
/** * Implementation of filterSet() to call set on Translation relationship to allow * access to I18n properties from the main object. * * @param Doctrine_Record $record * @param string $name Name of the property * @param string $value Value of the property * @return void */ public function filterSet(Doctrine_Record $record, $fieldName, $value) { $translation = $record->get('Translation'); $culture = myDoctrineRecord::getDefaultCulture(); if ($translation->contains($culture)) { $i18n = $record->get('Translation')->get($culture); } else { $i18n = $record->get('Translation')->get($culture); /* * If translation is new * populate it with i18n fallback */ if ($i18n->state() == Doctrine_Record::STATE_TDIRTY) { if ($fallback = $record->getI18nFallBack()) { $fallBackData = $fallback->toArray(); unset($fallBackData['id'], $fallBackData['lang']); $i18n->fromArray($fallBackData); } } } if (!ctype_lower($fieldName) && !$i18n->contains($fieldName)) { $underscoredFieldName = dmString::underscore($fieldName); if (strpos($underscoredFieldName, '_') !== false && $i18n->contains($underscoredFieldName)) { $fieldName = $underscoredFieldName; } } $i18n->set($fieldName, $value); return $value; }
function __construct() { // Check username if (!SECOND_PARAMETER || !Validate::username(SECOND_PARAMETER)) { Base::redirect('/oops'); } $this->user = User::where('username', SECOND_PARAMETER)->findOne(); if (!$this->user) { Base::redirect('/oops'); } // Set some variables for template View::set('page_title', $this->user->username); View::set('user', $this->user->asArray()); $this->sidebar(); if (!THIRD_PARAMETER) { $this->user(); } else { if (ctype_lower(THIRD_PARAMETER) && method_exists($this, THIRD_PARAMETER)) { $func = THIRD_PARAMETER; $this->{$func}(); } else { Base::redirect('/oops'); } } }
public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); // custom fields $builder->add('super', 'checkbox', array('label' => 'Looking for Super Admin account:', 'required' => false)); $builder->add('dbNameUq', 'text', array('label' => 'Database name (only lower case letters):', 'required' => false)); $builder->add('defaultlanguage', 'language', array('label' => 'Default language:', 'required' => false)); // custom validation $extraValidator = function (FormEvent $event) { $form = $event->getForm(); $dbNameUq = $form->get('dbNameUq'); $defaultlanguage = $form->get('defaultlanguage'); $super = $form->get('super')->getData(); if (!$super) { if (!is_null($dbNameUq->getData())) { if (!ctype_lower($dbNameUq->getData())) { $dbNameUq->addError(new FormError("This field is not valid (only lower case letters)")); } if (strlen($dbNameUq->getData()) < 3 || strlen($dbNameUq->getData()) > 50) { $dbNameUq->addError(new FormError("This field must contain 3 to 50 lower case letters")); } } else { $dbNameUq->addError(new FormError("This field must not be empty")); } if (is_null($defaultlanguage->getData())) { $defaultlanguage->addError(new FormError("This field must not be empty")); } } }; $builder->addEventListener(FormEvents::POST_BIND, $extraValidator); }
function _genderise($old_pre, $old, $old_post, $new) { // Determine case $case = NULL; // work it out here... if (ctype_upper($old)) { $case = 'upper'; } if (ctype_lower($old)) { $case = 'lower'; } if (preg_match('/[A-Z][a-z]+/', $old)) { $case = 'title'; } // Transform string switch ($case) { case 'lower': return $old_pre . strtolower($new) . $old_post; break; case 'upper': return $old_pre . strtoupper($new) . $old_post; break; case 'title': return $old_pre . title_case($new) . $old_post; break; } return $old_pre . $new . $old_post; }
/** * Convert a string to snake case. * * @param string $str * @param string $delimiter * @return string */ public static function convertSnake($str, $delimiter = '_') { if (ctype_lower($str)) { return $str; } return strtolower(preg_replace('/(.)(?=[A-Z])/', '$1' . $delimiter, $str)); }
public static function camelToUnderscore($string) { $out = ""; for ($c = 0; $c < strlen($string); $c++) { $out .= (ctype_lower($string[$c]) ? "" : "_") . strtolower($string[$c]); } return $out; }
/** * @dataProvider randomStringProvider * * @covers ::randomString * * @param int $length */ public function test_randomString($length) { // When $str = Str::randomString($length); // Then $this->assertSame($length, strlen($str)); $this->assertSame(true, ctype_lower($str)); }
protected function snake($value) { if (!ctype_lower($value)) { $replace = '$1_$2'; $value = strtolower(preg_replace('/(.)([A-Z])/', $replace, $value)); } return $value; }
/** * Convert a string to snake case. * * @param string $value * @param string $delimiter * @return string */ public static function snake($value, $delimiter = '_') { if (!ctype_lower($value)) { $value = preg_replace('/\\s+/', '', $value); $value = strtolower(preg_replace('/(.)(?=[A-Z])/', '$1' . $delimiter, $value)); } return $value; }
public static function snake($var) { if (!ctype_lower($var)) { $var = preg_replace('/\\s+/', '', $var); $var = strtolower(preg_replace('/(.)(?=[A-Z])/', '$1' . '_', $var)); } return $var; }
/** * Convert a string to snake case. * * @param string $value * @param string $delimiter * * @return string */ function snake_case($value, $delimiter = '_') { $key = $value . $delimiter; if (!ctype_lower($value)) { $value = preg_replace('/\\s+/u', '', $value); $value = mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); } return $value; }
/** * @param $function * @param $value * * @return \Gileson\RussianPostCalc\Letterhead */ function _($function, $value) { $key = mb_substr($function, 3); if (!ctype_lower($key)) { $key = strtolower(preg_replace('/(.)(?=[A-Z])/', '$1_', $key)); } $this->info[$key] = $value; return $this; }
/** * @param InputValue $input * @throws ValidationException */ public function process(InputValue $input) { if ($this->getOption('convert') === false && !ctype_lower($input->getValue())) { throw new ValidationException('value must be lowercase'); } $input->replace(function ($value) { return strtolower($value); }); }
/** * @param array $arguments * @return bool */ protected static function evaluateCondition($arguments = null) { if (true === $arguments['fullString']) { $result = ctype_lower($arguments['string']); } else { $result = ctype_lower(substr($arguments['string'], 0, 1)); } return true === $result; }
/** * @note Automatically normalizes scheme and port */ function HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment) { $this->scheme = is_null($scheme) || ctype_lower($scheme) ? $scheme : strtolower($scheme); $this->userinfo = $userinfo; $this->host = $host; $this->port = is_null($port) ? $port : (int) $port; $this->path = $path; $this->query = $query; $this->fragment = $fragment; }
/** * Tests listing functions. * * @covers empire\framework\template\constructs\FunctionFactory::listFunctions */ public function testListFunctions() { $functions = FunctionFactory::listFunctions(); $this->assertContainsOnly('string', $functions); $this->assertContains('date', $functions); $this->assertContains('safeHTMLComment', $functions); foreach ($functions as $function) { $this->assertTrue(ctype_lower($function[0])); } }
/** * @param string $string * @param HTMLPurifier_Config $config * @param HTMLPurifier_Context $context * @return bool|string */ public function validate($string, $config, $context) { $string = trim($string); if (!$this->case_sensitive) { // we may want to do full case-insensitive libraries $string = ctype_lower($string) ? $string : strtolower($string); } $result = isset($this->valid_values[$string]); return $result ? $string : false; }
public function toSingleRegister($base, $needle) { for ($i = 0; $i < strlen($base); $i++) { if (ctype_lower($base[$i])) { $needle[$i] = strtolower($needle[$i]); } else { $needle[$i] = strtoupper($needle[$i]); } } return $needle; }
function __construct() { // Everything done directly from user // user/login, user/logout, user/settings if (ctype_lower(SECOND_PARAMETER) && method_exists($this, SECOND_PARAMETER)) { $func = SECOND_PARAMETER; $this->{$func}(); } else { Base::redirect('/oops'); } }
/** * Converts a string to a suitable html ID attribute. * * http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a * valid ID attribute in HTML. This function: * * - Ensure an ID starts with an alpha character by optionally adding an 'n'. * - Replaces any character except A-Z, numbers, and underscores with dashes. * - Converts entire string to lowercase. * * @param $string * The string * @return * The converted string */ function meedjum_id_safe($string) { // Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores. $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string)); // If the first character is not a-z, add 'n' in front. if (!ctype_lower($string[0])) { // Don't use ctype_alpha since its locale aware. $string = 'id' . $string; } return $string; }