protected function getUniqueName(\TYPO3\CMS\Core\Resource\Folder $folder, $theFile, $dontCheckForUnique = FALSE) { static $maxNumber = 99, $uniqueNamePrefix = ''; // Fetches info about path, name, extention of $theFile $origFileInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($theFile); // Adds prefix if ($uniqueNamePrefix) { $origFileInfo['file'] = $uniqueNamePrefix . $origFileInfo['file']; $origFileInfo['filebody'] = $uniqueNamePrefix . $origFileInfo['filebody']; } // Check if the file exists and if not - return the fileName... $fileInfo = $origFileInfo; // The destinations file $theDestFile = $fileInfo['file']; // If the file does NOT exist we return this fileName if (!$this->driver->fileExistsInFolder($theDestFile, $folder) || $dontCheckForUnique) { return $theDestFile; } // Well the fileName in its pure form existed. Now we try to append // numbers / unique-strings and see if we can find an available fileName // This removes _xx if appended to the file $theTempFileBody = preg_replace('/_[0-9][0-9]$/', '', $origFileInfo['filebody']); $theOrigExt = $origFileInfo['realFileext'] ? '.' . $origFileInfo['realFileext'] : ''; for ($a = 1; $a <= $maxNumber + 1; $a++) { // First we try to append numbers if ($a <= $maxNumber) { $insert = '_' . sprintf('%02d', $a); } else { // TODO remove constant 6 $insert = '_' . substr(md5(uniqId('')), 0, 6); } $theTestFile = $theTempFileBody . $insert . $theOrigExt; // The destinations file $theDestFile = $theTestFile; // If the file does NOT exist we return this fileName if (!$this->driver->fileExistsInFolder($theDestFile, $folder)) { return $theDestFile; } } throw new \RuntimeException('Last possible name "' . $theDestFile . '" is already taken.', 1325194291); }
/** * @expectedException GFG\Hek\Exceptions\RetryMessage */ public function testExecuteWithRequestException() { $exportedData = ['order_nr' => 'order number']; $fullUrl = 'http://site.com/final-url'; $statusCode = 400; $body = '{"order_nr":"order number"}'; $uniqueId = uniqId(); $options = ['body' => $body, 'headers' => ['access-token' => 'my access token', 'user-key' => 'user key'], 'exceptions' => false]; $baseUriMock = $this->getMockBuilder('\\GuzzleHttp\\Psr7\\Uri')->disableOriginalConstructor()->getMock(); $baseUriMock->expects($this->once())->method('__toString')->willReturn('baseUri'); $url = $this->getMockBuilder('Url\\Url')->disableOriginalConstructor()->setMethods(['getHttpMethod', 'getFullUrl'])->getMock(); $url->expects($this->once())->method('getFullUrl')->willReturn($fullUrl); $context = $this->getMock('GFG\\Hek\\Interfaces\\Context'); $context->expects($this->once())->method('getUrl')->willReturn($url); $context->expects($this->exactly(3))->method('getHttpMethod')->willReturn('put'); $context->method('exportContextData')->willReturn($exportedData); $response = $this->getMock('Psr\\Http\\Message\\ResponseInterface'); $response->method('getStatusCode')->willReturn($statusCode); $response->method('getBody')->willReturn($body); $exception = $this->getMockBuilder('GuzzleHttp\\Exception\\RequestException')->disableOriginalConstructor()->getMock(); $exception->method('getResponse')->willReturn($response); $client = $this->getMockBuilder('GuzzleHttp\\Client')->disableOriginalConstructor()->setMethods(['put', 'getConfig'])->getMock(); $client->expects($this->once())->method('put')->with($fullUrl, $options)->will($this->throwException($exception)); $client->expects($this->once())->method('getConfig')->with('base_uri')->willReturn($baseUriMock); $messageRequest = sprintf('%s REQUEST TO: %s -- OPTIONS %s', $uniqueId, $fullUrl, json_encode($options)); $messageResponse = sprintf('%s RESPONSE: %s -- HTTP CODE %s -- BODY %s', $uniqueId, $fullUrl, $statusCode, $body); $this->client->setUniqueId($uniqueId); $this->client->setClient($client); $this->assertSame($response, $this->client->execute($context)); }
/** * 创建待提交post表单 * @method createPostForm * @since 0.0.1 * @param {array} $params 参数 * @return {string} */ private function createPostForm($params) { $id = $this->name_pre . uniqId(); $form = ['<form action="' . $this->api . '" method="post" name="' . $id . '">']; foreach ($params as $name => $value) { $form[] = '<input type="hidden" name="' . $name . '" value="' . $value . '" />'; } $form[] = '</form><script type="text/javascript">document.' . $id . '.submit();</script>'; return implode('', $form); }
public static function cache__save($reload = false) { if ($reload) { $data = DatabaseData::reloadDb(); } else { $data = DatabaseData::getInstance()->queries; } $uniq = uniqId(); $output = array("uniq" => $uniq, "queries" => $data); $filePath = CACHE_FOLDER . CACHE_FILE . "." . CACHE_FILE_EXT; file_put_contents($filePath, Zend_Json_Encoder::encode($output)); if ($reload) { echo "Cache updated. New id is " . $uniq . " (Time is = " . date("Y-m-d") . ")"; } }
/** * Helper method for flushByTag() and flushByTags() * Gets list of identifiers and tags and removes all relations of those tags * * Scales O(1) with number of cache entries * Scales O(n^2) with number of tags * * @param array $identifiers List of identifiers to remove * @param array $tags List of tags to be handled * @return void */ protected function removeIdentifierEntriesAndRelations(array $identifiers, array $tags) { // Set an temporary entry which holds all identifiers that need to be removed from // the tag to identifiers sets $uniqueTempKey = 'temp:' . uniqId(); $prefixedKeysToDelete = array($uniqueTempKey); $prefixedIdentifierToTagsKeysToDelete = array(); foreach ($identifiers as $identifier) { $prefixedKeysToDelete[] = self::IDENTIFIER_DATA_PREFIX . $identifier; $prefixedIdentifierToTagsKeysToDelete[] = self::IDENTIFIER_TAGS_PREFIX . $identifier; } foreach ($tags as $tag) { $prefixedKeysToDelete[] = self::TAG_IDENTIFIERS_PREFIX . $tag; } $tagToIdentifiersSetsToRemoveIdentifiersFrom = $this->redis->sUnion($prefixedIdentifierToTagsKeysToDelete); // Remove the tag to identifier set of the given tags, they will be removed anyway $tagToIdentifiersSetsToRemoveIdentifiersFrom = array_diff($tagToIdentifiersSetsToRemoveIdentifiersFrom, $tags); // Diff all identifiers that must be removed from tag to identifiers sets off from a // tag to identifiers set and store result in same tag to identifiers set again $queue = $this->redis->multi(\Redis::PIPELINE); foreach ($identifiers as $identifier) { $queue->sAdd($uniqueTempKey, $identifier); } foreach ($tagToIdentifiersSetsToRemoveIdentifiersFrom as $tagToIdentifiersSet) { $queue->sDiffStore(self::TAG_IDENTIFIERS_PREFIX . $tagToIdentifiersSet, self::TAG_IDENTIFIERS_PREFIX . $tagToIdentifiersSet, $uniqueTempKey); } $queue->delete(array_merge($prefixedKeysToDelete, $prefixedIdentifierToTagsKeysToDelete)); $queue->exec(); }
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 $access->check_feature('feature_live_support'); // This is a generic chat window used by users, operators and observers // should receive the following parameters // reqId: the requestId // role: the role of the user can be (operator,user,other) // We should receive the reqId here $senderId = md5(uniqId('.')); $smarty->assign('senderId', $senderId); if ($_REQUEST['role'] == 'operator') { $lslib->operator_accept($_REQUEST['reqId'], $user, $senderId); $lslib->set_operator_id($_REQUEST['reqId'], $senderId); } if ($_REQUEST['role'] == 'user') { $lslib->set_user_id($_REQUEST['reqId'], $senderId); $lslib->set_request_status($_REQUEST['reqId'], 'op_accepted'); } $smarty->assign('role', $_REQUEST['role']); $smarty->assign('req_info', $lslib->get_request($_REQUEST['reqId'])); $smarty->assign('reqId', $_REQUEST['reqId']); $smarty->assign('IP', $tikilib->get_ip_address()); if (!isset($user)) { $smarty->assign('username', 'anonymous');
/** * @brief Autogenerate a password * @returns string * * generates a password */ public static function generatePassword() { return uniqId(); }
/** * Returns the destination path/filename of a unique filename/foldername in that path. * If $theFile exists in $theDest (directory) the file have numbers appended up to $this->maxNumber. Hereafter a unique string will be appended. * This function is used by fx. TCEmain when files are attached to records and needs to be uniquely named in the uploads/* folders * * @param string The input filename to check * @param string The directory for which to return a unique filename for $theFile. $theDest MUST be a valid directory. Should be absolute. * @param boolean If set the filename is returned with the path prepended without checking whether it already existed! * @return string The destination absolute filepath (not just the name!) of a unique filename/foldername in that path. * @see t3lib_TCEmain::checkValue() * @todo Define visibility */ public function getUniqueName($theFile, $theDest, $dontCheckForUnique = 0) { // @todo: should go into the LocalDriver in a protected way (not important to the outside world) $theDest = $this->is_directory($theDest); // $theDest is cleaned up $origFileInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($theFile); // Fetches info about path, name, extension of $theFile if ($theDest) { if ($this->getUniqueNamePrefix) { // Adds prefix $origFileInfo['file'] = $this->getUniqueNamePrefix . $origFileInfo['file']; $origFileInfo['filebody'] = $this->getUniqueNamePrefix . $origFileInfo['filebody']; } // Check if the file exists and if not - return the filename... $fileInfo = $origFileInfo; $theDestFile = $theDest . '/' . $fileInfo['file']; // The destinations file if (!file_exists($theDestFile) || $dontCheckForUnique) { // If the file does NOT exist we return this filename return $theDestFile; } // Well the filename in its pure form existed. Now we try to append numbers / unique-strings and see if we can find an available filename... $theTempFileBody = preg_replace('/_[0-9][0-9]$/', '', $origFileInfo['filebody']); // This removes _xx if appended to the file $theOrigExt = $origFileInfo['realFileext'] ? '.' . $origFileInfo['realFileext'] : ''; for ($a = 1; $a <= $this->maxNumber + 1; $a++) { if ($a <= $this->maxNumber) { // First we try to append numbers $insert = '_' . sprintf('%02d', $a); } else { // .. then we try unique-strings... $insert = '_' . substr(md5(uniqId('')), 0, $this->uniquePrecision); } $theTestFile = $theTempFileBody . $insert . $theOrigExt; $theDestFile = $theDest . '/' . $theTestFile; // The destinations file if (!file_exists($theDestFile)) { // If the file does NOT exist we return this filename return $theDestFile; } } } }
<?php /** * Copyright (c) 2010 Frank Karlitschek karlitschek@kde.org * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ $RUNTIME_NOAPPS = TRUE; //no apps require_once '../../lib/base.php'; // Someone lost their password: if (isset($_POST['user'])) { if (OC_User::userExists($_POST['user'])) { $token = sha1($_POST['user'] + uniqId()); OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token); $email = OC_Preferences::getValue($_POST['user'], 'lostpassword', 'email', ''); if (!empty($email)) { $link = OC_Helper::linkTo('core/lostpassword', 'resetpassword.php', null, true) . '?user='******'user'] . '&token=' . $token; $tmpl = new OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link); $msg = $tmpl->fetchPage(); $l = new OC_L10N('core'); mail($email, $l->t('Owncloud password reset'), $msg); } OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true)); } else { OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => true, 'requested' => false)); } } else { OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => false));
$params = array_merge($_SESSION["user_params"], array("option" => "numTeeth")); } //----------- ------------------------PNG or STL is being generated------------------------------------------ if (isset($_GET["output_type"])) { // adds in the output type (png or stl) from the $_GET array $thing_params = array_merge((array) $_SESSION["options"][0], array("output_type" => $_GET["output_type"])); $fileNames = generateThing($thing_params); if ($fileNames != false) { switch ($_GET["output_type"]) { case "png": echo "<div style=\"margin:auto;width:50%;text-align:center\">"; echo "<img src=\"{$fileNames['0']}\" style=\"margin:auto\">"; echo "</div>"; break; case "stl": $filename = "/var/www-chapresearch/SprocketR_Output/" . uniqId() . ".zip"; zipSprockets($filename, $fileNames); $filename = substr($filename, strlen("/var/www-chapresearch/SprocketR_Output/")); echo "<h1 style=\"text-align:center\">"; echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>'; echo "<script type=\"text/javascript\">\n \$.get('download.php?fileName={$filename}', function(response, success){\n window.location = 'download.php?fileName={$filename}';\n });\n </script>"; break; } } else { echo "<h1 style=\"text-align:center\">"; echo "<strong>Unable to generate file!</strong></h1>"; } } else { // -----------------------------------options are being created-------------------------------------- $options = generateOptions($params); if ($options !== false) {
public static function getToken() { $token = uniqId(); self::dbQuery("insert into sc_captcha set code = {token}, created_date = now(), remote_ip = {remote-ip}", array("token" => $token, "remote-ip" => $_SERVER["REMOTE_ADDR"])); return array("token" => $token); }
/** * @test */ public function getVersionMatrixReturnsMatrixFromRegistry() { /** @var $instance \TYPO3\CMS\Install\Service\CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('fetchVersionMatrixFromRemote'), array(), '', FALSE); $registry = $this->getMock('TYPO3\\CMS\\Core\\Registry'); $versionArray = array(uniqId()); $registry->expects($this->once())->method('get')->will($this->returnValue($versionArray)); $instance->_set('registry', $registry); $this->assertSame($versionArray, $instance->_call('getVersionMatrix')); }
function addTemplate($type = "innerHtml") { // $type=innerHtml/outerHtml $tplid = uniqId(); $this->attr("data-template", $tplid); $that = $this->clone(); $that->removeClass("loaded"); if ($type == "innerHtml") { $tpl = urlencode($that->innerHtml()); } else { $tpl = urlencode($that->outerHtml()); } $this->after("<textarea data-role='template' id='{$tplid}' style='display:none;'>{$tpl}</textarea>"); }
function generateThing($params) { $fileName = uniqId() . "." . $params["output_type"]; $cmd = 'blender -b /usr/lib/blender/scripts/addons/'; if ($params["output_type"] == "png") { $cmd .= 'pic.blend'; // needs a camera object in the blend file to generate a picture } else { $cmd .= 'blend.blend'; } if ($_GET["page_id"] == PAGE_2) { $cmd .= ' -P /usr/lib/blender/scripts/addons/' . SCRIPT . ' -- '; } else { if ($_GET["page_id"] == PAGE_2_ALT) { $cmd .= ' -P /usr/lib/blender/scripts/addons/' . SCRIPT_ALT . ' -- '; } } $cmd .= $fileName . formatParams($params); $output = array(); exec($cmd, $output); cleanUp(); return returnFileNames($output, $params["output_type"]); }