private function getVariableValue($type, $content) { $value = 0; foreach ($this->dbResult as $row) { $textUtils = new TextUtils($row, $this->parameters, $this->variables); $valueTemp = $textUtils->changeFieldValue($content); //TODO FAzer os outros //TODO Juntar com PdfUtils::getReturnValues if ($type == 'Sum') { $value += $valueTemp; } } return $value; }
public function testEndsWith() { $this->assertFalse(TextUtils::endsWith('Morrelinko', 'M')); $this->assertTrue(TextUtils::endsWith('Morrelinko', 'o')); $this->assertTrue(TextUtils::endsWith('Morrelinko', 'linko')); $this->assertFalse(TextUtils::endsWith('Morrelinko', 'relink')); }
/** * @see http://csrc.nist.gov/ipsec/papers/rfc2202-testcases.txt **/ public function testHmacsha1() { $this->assertEquals(TextUtils::hex2Binary('b617318655057264e28bc0b6fb378c8ef146be00'), CryptoFunctions::hmacsha1(TextUtils::hex2Binary('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'), "Hi There")); $this->assertEquals(CryptoFunctions::hmacsha1("Jefe", "what do ya want for nothing?"), TextUtils::hex2Binary('effcdf6ae5eb2fa2d27416d5f184df9c259a7c79')); $this->assertEquals(CryptoFunctions::hmacsha1(TextUtils::hex2Binary('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), TextUtils::hex2Binary('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd')), TextUtils::hex2Binary('125d7342b9ac11cd91a39af48aa17b4f63f175d3')); $this->assertEquals(CryptoFunctions::hmacsha1(TextUtils::hex2Binary('0102030405060708090a0b0c0d0e0f10111213141516171819'), TextUtils::hex2Binary('cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd')), TextUtils::hex2Binary('4c9007f4026250c6bc8414f9bf50c86c2d7235da')); $this->assertEquals(CryptoFunctions::hmacsha1(TextUtils::hex2Binary('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c'), "Test With Truncation"), TextUtils::hex2Binary('4c1a03424b55e07fe7f27be1d58bb9324a9a5a04')); $this->assertEquals(CryptoFunctions::hmacsha1(TextUtils::hex2Binary('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), "Test Using Larger Than Block-Size Key - Hash Key First"), TextUtils::hex2Binary('aa4ae5e15272d00e95705637ce8a3b55ed402112')); $this->assertEquals(CryptoFunctions::hmacsha1(TextUtils::hex2Binary('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data"), TextUtils::hex2Binary('e8e99d0f45237d786d6bbaa7965c7808bbff1a91')); }
/** * Many PHP installations will have magic quotes turned on. * * Normalize the parameters of interest and return a new * array with only those entries. If no specific parameters * of interest are given, all will be handled. */ public static function undoMagicQuotes($src, $params = false) { $needed = get_magic_quotes_gpc(); if (!$params) { $params = array_keys($src); } $ret = array(); foreach ($params as $key) { $ret[$key] = $needed ? TextUtils::stripSlashesHandleArrays($src[$key]) : $src[$key]; } return $ret; }
/** * @return ModelAndView **/ public function handleRequest(HttpRequest $request) { Assert::isNotEmptyArray($this->innerControllers, 'Add atleast one innerController first'); $activeController = $this->getActiveController($request); $model = $this->mav->getModel(); if ($activeController) { $controllerName = $activeController->getName(); $activeMav = $activeController->handleRequest($request); $model->set(TextUtils::downFirst($controllerName), $activeMav->getModel()); unset($this->innerControllers[$controllerName]); } foreach ($this->innerControllers as $controller) { $passedRequest = clone $request; $passedRequest->{'set' . $controller->getRequestGetter() . 'Var'}('action', null); $subMav = $controller->handleRequest($passedRequest); $model->set(TextUtils::downFirst($controller->getName()), $subMav->getModel()); } return isset($activeMav) && $activeMav->viewIsRedirect() ? $activeMav : $this->mav; }
/** * Further instructions (Step 2) of installing * CMAT-o-Matic */ function step2Body($confData = false) { // TODO: Give proper instructions on what to do next on this page if ($confData) { ?> <h1>Action Required: CMATic Configuration Not Saved</h1> <p> The CMATic installer was unable to write to the settings file. Copy the following configuration into <kbd><CMATic root>/server/.cmatic_conf.php</kbd> before continuing. Remember to replace the password placeholder text with the real password. </p> <pre><code><?php echo TextUtils::htmlize($confData); ?> </code></pre> <?php } ?> <h1>CMATic Installed</h1> <p> The database has been setup and is ready for CMATic. </p> <h1>Now What?</h1> <p> Congratulations! You are now ready to create events for your tournament and add competitors. </p> <?php }
foreach ($record as $fieldApiName => $value) { if ($fieldApiName == 'id') { $recordId = strval($value); continue; } $tmpField = CmaticSchema::getFieldDbColumn($typeApiName, $fieldApiName); if (is_null($tmpField)) { throw new CmaticApiException(sprintf('Record %d: Unrecognized field on type: %s.%s', $index, $typeApiName, $fieldApiName)); } if (is_null($value)) { $tmpValue = 'NULL'; } else { if (is_int($value) || is_float($value)) { $tmpValue = $value; } else { $tmpValue = '\'' . TextUtils::cleanTextForSql($value) . '\''; } } if (is_null($tmpValue)) { throw new CmaticApiException(sprintf('Record %d: Invalid value for %s.%s: $s', $index, $typeApiName, $fieldApiName, $value)); } $setClause[] = sprintf('%s = %s', $tmpField, $tmpValue); } // TODO: Move last_mod into triggers? $conn->query(sprintf('update %s set last_mod = now(), %s where %s=%s', $typeDbTable, implode(',', $setClause), CmaticSchema::getFieldDbColumn($typeApiName, 'id'), $recordId)); } } else { if ($op == 'delete') { // Disable deletes it's too scary to allow // TODO: There needs to be some checks to make sure not just anything can be deleted. // Specifically, we should NEVER be able to delete scoring rows if they have scores.
public function testHex2Binary() { $this->assertEquals(' ', TextUtils::hex2Binary('2020202020')); }
function UploadRecord($table, $fields, $guidfield, $idfield, $syncfield, $delimiter = ',', $enclosure = '"') { LogUtils::log_str('UploadRecord Begin'); LogUtils::log_obj(func_get_args()); $server =& $GLOBALS['as_server']; $sys =& $GLOBALS['system']; $db = $sys->database(); $syncitems = array(); $atts = $server->getAttachments(); LogUtils::log_obj($atts); if (count($atts) > 0) { $att = null; foreach ($atts as $attitem) { $att = $attitem; break; } $csvfile = ServerUtils::formalPath(ServerUtils::buildPath(AS_TMP_DIR, 'tmpcsv' . time() . '.txt')); file_put_contents($csvfile, $att['data']); LogUtils::log_str($csvfile); $list = TextUtils::csv2array($csvfile, $fields, $delimiter, $enclosure); unlink($csvfile); $validators = BaseValidator::loadValidators(AS_VALIDATOR_DIR, $table, $sys); $idcolarr = split(',', $idfield); foreach ($list as $row) { LogUtils::log_obj($row); $sync_item = array(); $sync_item['guid'] = ''; $sync_item['id'] = ''; $sync_item['succ'] = false; $sync_item['errmsg'] = ''; $sync_item['syncstate'] = AS_SYNC_ADDED; if (array_key_exists($guidfield, $row)) { $sync_item['guid'] = $row[$guidfield]; } if (array_key_exists($syncfield, $row)) { $sync_item['syncstate'] = $row[$syncfield]; } $idcnd = array(); $idcndstr = ''; foreach ($idcolarr as $idcol) { if (array_key_exists($idcol, $row)) { $idcnd[$idcol] = $row[$idcol]; if (!empty($idcndstr)) { $idcndstr .= ' and '; } $idcndstr .= $idcol . "=" . $db->quote($row[$idcol]); } } $sync_item['id'] = implode(',', $idcnd); LogUtils::log_obj($idcnd); switch ($sync_item['syncstate']) { case AS_SYNC_DELETED: if (count($idcnd) > 0) { if (BaseValidator::runValidateBefore($validators, 'delete', $row)) { $sql = "delete from sdb_{$table} where {$idcndstr}"; LogUtils::log_str($sql); if ($db->exec($sql)) { $sync_item['succ'] = true; BaseValidator::runValidateAfter($validators, 'delete', $row); } } } break; case AS_SYNC_UNCHANGED: case AS_SYNC_MODIFIED: if (count($idcnd) > 0) { $sql = "select * from sdb_{$table} where {$idcndstr}"; LogUtils::log_str($sql); $count = $db->_count($sql); if ($count > 0) { if (BaseValidator::runValidateBefore($validators, 'update', $row)) { $rs = $db->query($sql); $sql = $db->getUpdateSql($rs, $row, true); LogUtils::log_str($sql); if ($sql && $db->exec($sql)) { $sync_item['succ'] = true; BaseValidator::runValidateAfter($validators, 'update', $row); } } } else { if (BaseValidator::runValidateBefore($validators, 'insert', $row)) { $rs = $db->query($sql); $sql = $db->getInsertSQL($rs, $row); LogUtils::log_str($sql); if ($sql && $db->exec($sql)) { if (count($idcnd) == 1) { $sync_item['id'] = $db->lastInsertId(); } $sync_item['succ'] = true; BaseValidator::runValidateAfter($validators, 'insert', $row); } } } } break; case AS_SYNC_ADDED: $count = 0; if (count($idcnd) > 0) { $sql = "select * from sdb_{$table} where {$idcndstr}"; LogUtils::log_str($sql); $count = $db->_count($sql); } if ($count > 0) { if (BaseValidator::runValidateBefore($validators, 'update', $row)) { $rs = $db->query($sql); $sql = $db->getUpdateSql($rs, $row, true); LogUtils::log_str($sql); if ($sql && $db->exec($sql)) { $sync_item['succ'] = true; BaseValidator::runValidateAfter($validators, 'update', $row); } } } else { if (BaseValidator::runValidateBefore($validators, 'insert', $row)) { $sql = "select * from sdb_{$table} where 0=1"; LogUtils::log_str($sql); $rs = $db->query($sql); $sql = $db->getInsertSQL($rs, $row); LogUtils::log_str($sql); if ($sql && $db->exec($sql)) { if (count($idcnd) == 1) { $sync_item['id'] = $db->lastInsertId(); } $sync_item['succ'] = true; BaseValidator::runValidateAfter($validators, 'insert', $row); } } } break; } LogUtils::log_obj($sync_item); $syncitems[] = $sync_item; } } $pack = array('items' => $syncitems); LogUtils::log_str('UploadRecord Return'); return $pack; }
require_once '../util/Ex.php'; require_once '../util/TextUtils.php'; /** * Hash the event row to a unique string. * Use a concatenation of the division, sex, age, and * form ids joined by a '-'. This will be unique as a * '-' can never appear as part of and id. * * @param {assoc. array} $r Represents the event row from the database */ function hashEvent($d, $s, $a, $f) { return $d . '-' . $s . '-' . $a . '-' . $f; } $isSuccessful = false; $requestParams = TextUtils::undoMagicQuotes($_REQUEST); $divisions = $requestParams['divisions']; $sexes = $requestParams['sexes']; $ageGroups = $requestParams['ageGroups']; $forms = $requestParams['forms']; try { if (empty($divisions)) { throw new CmaticApiException('Input "divisions[]" cannot be empty.'); } if (empty($sexes)) { throw new CmaticApiException('Input "sexes[]" cannot be empty.'); } if (empty($ageGroups)) { throw new CmaticApiException('Input "ageGroups[]" cannot be empty.'); } if (empty($forms)) {
/** * @dataProvider provideTruncate */ public function testTruncate($text, $length, $suffix, $expected) { $res = TextUtils::truncate($text, $length, $suffix); $this->assertEquals($expected, $res); }
private static function parametersToSend($subreportParameter, $row, $parameters, $variables) { $return = array(); $textUtils = new TextUtils($row, $parameters, $variables); //sendding necessary parameters if (is_array($subreportParameter)) { foreach ($subreportParameter as $param) { $return[$param->name] = $textUtils->changeFieldValue($param->subreportParameterExpression->content); } } else { $return[$subreportParameter->name] = $textUtils->changeFieldValue($subreportParameter->subreportParameterExpression->content); } //sendding the master parameters foreach ($parameters as $parameterName => $parameterValue) { if (!array_key_exists($parameterName, $return)) { $return[$parameterName] = $parameterValue; } } return $return; }
private function _formatValue($v) { if (is_int($v)) { return $v; } else { if (is_float($v)) { return $v; } else { return sprintf("'%s'", TextUtils::cleanTextForSql($v)); } } }
public static function friendlyFileSize($size, $precision = 2) { if ($size < 1024) { return $size . ' ' . self::selectCaseForNumber($size, array('байт', 'байта', 'байт')); } else { return TextUtils::friendlyFileSize($size, $precision, self::$bytePrefixes, true) . 'Б'; } }