本文整理汇总了PHP中StringUtil::getHash方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::getHash方法的具体用法?PHP StringUtil::getHash怎么用?PHP StringUtil::getHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtil
的用法示例。
在下文中一共展示了StringUtil::getHash方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadCache
/**
* Loads the tag cloud cache.
*/
public function loadCache()
{
if ($this->tags !== null) {
return;
}
// get cache
WCF::getCache()->addResource($this->cacheName, WCF_DIR . 'cache/cache.tagCloud-' . PACKAGE_ID . '-' . StringUtil::getHash(implode(',', $this->languageIDArray)) . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderTagCloud.class.php', 0, 86400);
$this->tags = WCF::getCache()->get($this->cacheName);
}
示例2: pushToStringStack
/**
* Replaces a string with an unique hash value.
*
* @param string $string
* @param string $type
* @return string $hash
*/
public static function pushToStringStack($string, $type = 'default')
{
$hash = '@@' . StringUtil::getHash(uniqid(microtime()) . $string) . '@@';
if (!isset(self::$stringStack[$type])) {
self::$stringStack[$type] = array();
}
self::$stringStack[$type][$hash] = $string;
return $hash;
}
示例3: pushToStringStack
/**
* Replaces a string with an unique hash value.
*
* @param string $string
* @param string $type
* @return string $hash
*/
public static function pushToStringStack($string, $type = 'default', $delimiter = '@@')
{
self::$i++;
$hash = $delimiter . StringUtil::getHash(self::$i . uniqid(microtime()) . $string) . $delimiter;
if (!isset(self::$stringStack[$type])) {
self::$stringStack[$type] = array();
}
self::$stringStack[$type][$hash] = $string;
return $hash;
}
示例4: getGroupData
/**
* @see UserSession::getGroupData()
*/
protected function getGroupData()
{
parent::getGroupData();
// get group permissions from cache (board_to_group)
$groups = implode(",", $this->groupIDs);
$groupsFileName = StringUtil::getHash(implode("-", $this->groupIDs));
// register cache resource
WCF::getCache()->addResource('boardPermissions-' . $groups, WBB_DIR . 'cache/cache.boardPermissions-' . $groupsFileName . '.php', WBB_DIR . 'lib/system/cache/CacheBuilderBoardPermissions.class.php');
// get group data from cache
$this->boardPermissions = WCF::getCache()->get('boardPermissions-' . $groups);
if (isset($this->boardPermissions['groupIDs']) && $this->boardPermissions['groupIDs'] != $groups) {
$this->boardPermissions = array();
}
// get board moderator permissions
$sql = "SELECT\t\t*\n\t\t\tFROM\t\twbb" . WBB_N . "_board_moderator\n\t\t\tWHERE\t\tgroupID IN (" . implode(',', $this->groupIDs) . ")\n\t\t\t\t\t" . ($this->userID ? " OR userID = " . $this->userID : '') . "\n\t\t\tORDER BY \tuserID DESC";
$result = WCF::getDB()->sendQuery($sql);
while ($row = WCF::getDB()->fetchArray($result)) {
$boardID = $row['boardID'];
unset($row['boardID'], $row['userID'], $row['groupID']);
if (!isset($this->boardModeratorPermissions[$boardID])) {
$this->boardModeratorPermissions[$boardID] = array();
}
foreach ($row as $permission => $value) {
if ($value == -1) {
continue;
}
if (!isset($this->boardModeratorPermissions[$boardID][$permission])) {
$this->boardModeratorPermissions[$boardID][$permission] = $value;
} else {
$this->boardModeratorPermissions[$boardID][$permission] = $value || $this->boardModeratorPermissions[$boardID][$permission];
}
}
}
if (count($this->boardModeratorPermissions)) {
require_once WBB_DIR . 'lib/data/board/Board.class.php';
Board::inheritPermissions(0, $this->boardModeratorPermissions);
}
}
示例5: getRandomFieldName
/**
* Generates a random field name.
*
* @param string $fieldName
* @return string
*/
public static function getRandomFieldName($fieldName)
{
$hash = StringUtil::getHash($fieldName . StringUtil::getRandomID());
return substr($hash, 0, mt_rand(8, 16));
}
示例6: cacheCode
/**
* Caches a code bbcode.
*
* @param string $content
* @return string $hash
*/
private static function cacheCode($content)
{
// strip slashes
$content = str_replace("\\\"", "\"", $content);
// create hash
$hash = '@@' . StringUtil::getHash(uniqid(microtime()) . $content) . '@@';
// save tag
self::$cachedCodes[$hash] = $content;
return $hash;
}
示例7: validate
/**
* @see Form::validate()
*/
public function validate()
{
parent::validate();
// get search conditions
$conditions = $this->getConditions();
// check query and author
if (empty($this->query) && empty($this->username) && !$this->userID) {
throw new UserInputException('q');
}
// build search hash
$this->searchHash = StringUtil::getHash(serialize(array($this->query, $this->types, !$this->subjectOnly, $conditions, $this->sortField . ' ' . $this->sortOrder, PACKAGE_ID)));
// check search hash
if (!empty($this->query)) {
$sql = "SELECT\tsearchID\n\t\t\t\tFROM\twcf" . WCF_N . "_search\n\t\t\t\tWHERE\tsearchHash = '" . $this->searchHash . "'\n\t\t\t\t\tAND userID = " . WCF::getUser()->userID . "\n\t\t\t\t\tAND searchType = 'messages'\n\t\t\t\t\tAND searchDate > " . (TIME_NOW - 1800);
$row = WCF::getDB()->getFirstRow($sql);
if (isset($row['searchID'])) {
HeaderUtil::redirect('index.php?form=Search&searchID=' . $row['searchID'] . '&highlight=' . urlencode($this->query) . SID_ARG_2ND_NOT_ENCODED);
exit;
}
}
// do search
$this->result = $this->engine->search($this->query, $this->types, $conditions, $this->sortField . ' ' . $this->sortOrder);
// result is empty
if (count($this->result) == 0) {
$this->throwNoMatchesException();
}
}
示例8: getHash
/**
* Calculates hash for a given package
*
* @param integer $sourceID
* @param string $packageName
* @param string $directory
* @return string
*/
public static function getHash($sourceID, $packageName, $directory)
{
return StringUtil::getHash($sourceID . ':' . $packageName . ':' . $directory);
}
示例9: test
/**
* Checks whether a post with the given data already exists in the database.
*
* @param string $subject
* @param string $message
* @param integer $authorID
* @param string $author
* @param integer $threadID
*
* @return boolean true, if a post with the given data already exists in the database
*/
public static function test($subject, $message, $authorID, $author, $threadID = 0)
{
$hash = StringUtil::getHash(($threadID ? $threadID : '') . $subject . $message . $authorID . $author);
$sql = "SELECT\t\tpostID\n\t\t\tFROM \t\twbb" . WBB_N . "_post_hash\n\t\t\tWHERE \t\tmessageHash = '" . $hash . "'";
$row = WCF::getDB()->getFirstRow($sql);
if (!empty($row['postID'])) {
return $row['postID'];
}
return false;
}
示例10: cacheCode
/**
* Caches a code bbcode.
*
* @param string $codeTag
* @param string $content
* @return string $hash
*/
protected function cacheCode($codeTag, $content)
{
// strip slashes
$codeTag = str_replace("\\\"", "\"", $codeTag);
$content = str_replace("\\\"", "\"", $content);
// create hash
$hash = '@@' . StringUtil::getHash(uniqid(microtime()) . $content) . '@@';
// build tag
$tag = $this->buildTag($codeTag);
$tag['content'] = $content;
// save tag
$this->cachedCodes[$hash] = $tag;
return $hash;
}
示例11: loadCache
/**
* loads the group option cache
*/
protected static function loadCache()
{
// cache already loaded
if (count(self::$availablePermissions)) {
return;
}
// build cache
$groupIDs = array(Group::EVERYONE, Group::GUESTS, Group::OTHER, Group::USERS);
$groupsFileName = StringUtil::getHash(implode("-", $groupIDs));
WCF::getCache()->addResource('groups-' . PACKAGE_ID . '-' . implode(',', $groupIDs), WCF_DIR . 'cache/cache.groups-' . PACKAGE_ID . '-' . $groupsFileName . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderGroupPermissions.class.php');
// get cached options
$groupOptions = WCF::getCache()->get('groups-' . PACKAGE_ID . '-' . implode(',', $groupIDs));
// filter options
$options = array();
foreach ($groupOptions as $key => $value) {
list($category, ) = explode('.', $key);
// only boolean options are allowed
if (!is_bool($value) || $key == 'mod.board.isSuperMod') {
continue;
} else {
$categoryName = WCF::getLanguage()->get('wcf.acp.group.option.category.' . $category);
$options[$categoryName][$key] = WCF::getLanguage()->get('wcf.acp.group.option.' . $key);
}
}
self::$availablePermissions = $options;
}
开发者ID:Fighter456,项目名称:de.fighter456.wcf.pageMenuPermission,代码行数:29,代码来源:PageMenuItemAddFormPermissionListener.class.php
示例12: create
/**
* Creates a new private message with the given parameters.
*/
public static function create($draft, $recipients, $blindCopies, $subject, $text, $userID, $username, $options = array(), $attachments = null, $parentPmID = 0)
{
$hash = StringUtil::getHash(serialize($recipients) . serialize($blindCopies) . $subject . $text . $userID . $username);
// get number of attachments
$attachmentsAmount = $attachments != null ? count($attachments->getAttachments()) : 0;
// save message
$pmID = self::insert($subject, $text, array('parentPmID' => $parentPmID, 'userID' => $userID, 'username' => $username, 'time' => TIME_NOW, 'enableSmilies' => isset($options['enableSmilies']) ? $options['enableSmilies'] : 1, 'enableHtml' => isset($options['enableHtml']) ? $options['enableHtml'] : 0, 'enableBBCodes' => isset($options['enableBBCodes']) ? $options['enableBBCodes'] : 1, 'showSignature' => isset($options['showSignature']) ? $options['showSignature'] : 1, 'saveInOutbox' => $draft ? 0 : 1, 'isDraft' => $draft ? 1 : 0, 'attachments' => $attachmentsAmount));
// save hash
$sql = "REPLACE INTO\twcf" . WCF_N . "_pm_hash\n\t\t\t\t\t(pmID, messageHash, time)\n\t\t\tVALUES\t\t(" . $pmID . ", '" . $hash . "', " . TIME_NOW . ")";
WCF::getDB()->registerShutdownUpdate($sql);
// update parent pm id
if ($parentPmID == 0) {
$sql = "UPDATE\twcf" . WCF_N . "_pm\n\t\t\t\tSET\tparentPmID = pmID\n\t\t\t\tWHERE\tpmID = " . $pmID;
WCF::getDB()->sendQuery($sql);
}
// save recipients
$recipientIDs = '';
$inserts = '';
foreach ($recipients as $recipient) {
if (!empty($inserts)) {
$inserts .= ',';
}
$inserts .= "(" . $pmID . ", " . $recipient['userID'] . ", '" . escapeString($recipient['username']) . "'" . ($draft ? ', 2' : ', 0') . ", 0)";
if (!empty($recipientIDs)) {
$recipientIDs .= ',';
}
$recipientIDs .= $recipient['userID'];
}
// save blind copy recipients
foreach ($blindCopies as $recipient) {
if (!empty($inserts)) {
$inserts .= ',';
}
$inserts .= "(" . $pmID . ", " . $recipient['userID'] . ", '" . escapeString($recipient['username']) . "'" . ($draft ? ', 2' : ', 0') . ", 1)";
if (!empty($recipientIDs)) {
$recipientIDs .= ',';
}
$recipientIDs .= $recipient['userID'];
}
if (!empty($inserts)) {
$sql = "INSERT IGNORE INTO \twcf" . WCF_N . "_pm_to_user\n\t\t\t\t\t\t\t(pmID, recipientID, recipient, isDeleted, isBlindCopy)\n\t\t\t\tVALUES\t\t\t" . $inserts;
WCF::getDB()->sendQuery($sql);
}
// update attachments
if ($attachments != null) {
$attachments->updateContainerID($pmID);
$attachments->findEmbeddedAttachments($text);
}
// update message count
if (!empty($recipientIDs)) {
self::updateUnreadMessageCount($recipientIDs);
}
self::updateTotalMessageCount((!empty($recipientIDs) ? $recipientIDs . ',' : '') . $userID);
// reset session data
$userIDArray = !empty($recipientIDs) ? explode(',', $recipientIDs) : array();
$userIDArray[] = $userID;
Session::resetSessions($userIDArray, true, false);
return new PMEditor($pmID);
}
示例13: execute
/**
* @see EventListener::execute()
*/
public function execute($eventObj, $className, $eventName)
{
if ($eventName == 'readParameters') {
// handle special search options here
$action = '';
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
}
if (empty($action)) {
return;
}
// get accessible board ids
require_once WBB_DIR . 'lib/data/board/Board.class.php';
$boardIDArray = Board::getAccessibleBoardIDArray(array('canViewBoard', 'canEnterBoard', 'canReadThread'));
foreach ($boardIDArray as $key => $boardID) {
if (WCF::getUser()->isIgnoredBoard($boardID)) {
unset($boardIDArray[$key]);
} else {
if (!Board::getBoard($boardID)->searchable) {
unset($boardIDArray[$key]);
}
}
}
if (!count($boardIDArray)) {
return;
}
switch ($action) {
case 'unread':
$sql = "SELECT\t\tthread.threadID\n\t\t\t\t\t\tFROM\t\twbb" . WBB_N . "_thread thread\n\t\t\t\t\t\tWHERE\t\tthread.boardID IN (" . implode(',', $boardIDArray) . ")\n\t\t\t\t\t\t\t\tAND thread.lastPostTime > " . WCF::getUser()->getLastMarkAllAsReadTime() . "\n\t\t\t\t\t\t\t\t" . (WCF::getUser()->userID ? "\n\t\t\t\t\t\t\t\tAND thread.lastPostTime > IFNULL((\n\t\t\t\t\t\t\t\t\tSELECT\tlastVisitTime\n\t\t\t\t\t\t\t\t\tFROM \twbb" . WBB_N . "_thread_visit\n\t\t\t\t\t\t\t\t\tWHERE \tthreadID = thread.threadID\n\t\t\t\t\t\t\t\t\t\tAND userID = " . WCF::getUser()->userID . "\n\t\t\t\t\t\t\t\t), 0)\n\t\t\t\t\t\t\t\tAND thread.lastPostTime > IFNULL((\n\t\t\t\t\t\t\t\t\tSELECT\tlastVisitTime\n\t\t\t\t\t\t\t\t\tFROM \twbb" . WBB_N . "_board_visit\n\t\t\t\t\t\t\t\t\tWHERE \tboardID = thread.boardID\n\t\t\t\t\t\t\t\t\t\tAND userID = " . WCF::getUser()->userID . "\n\t\t\t\t\t\t\t\t), 0)\n\t\t\t\t\t\t\t\t" : '') . "\n\t\t\t\t\t\t\t\tAND thread.isDeleted = 0\n\t\t\t\t\t\t\t\tAND thread.isDisabled = 0\n\t\t\t\t\t\t\t\t" . (count(WCF::getSession()->getVisibleLanguageIDArray()) ? " AND languageID IN (" . implode(',', WCF::getSession()->getVisibleLanguageIDArray()) . ")" : "") . "\n\t\t\t\t\t\t\t\tAND thread.movedThreadID = 0\n\t\t\t\t\t\tORDER BY\tthread.lastPostTime DESC";
break;
case 'newPostsSince':
$since = TIME_NOW;
if (isset($_REQUEST['since'])) {
$since = intval($_REQUEST['since']);
}
$sql = "SELECT\t\tthread.threadID\n\t\t\t\t\t\tFROM\t\twbb" . WBB_N . "_thread thread\n\t\t\t\t\t\tWHERE\t\tthread.boardID IN (" . implode(',', $boardIDArray) . ")\n\t\t\t\t\t\t\t\tAND thread.lastPostTime > " . $since . "\n\t\t\t\t\t\t\t\tAND thread.isDeleted = 0\n\t\t\t\t\t\t\t\tAND thread.isDisabled = 0\n\t\t\t\t\t\t\t\t" . (count(WCF::getSession()->getVisibleLanguageIDArray()) ? " AND languageID IN (" . implode(',', WCF::getSession()->getVisibleLanguageIDArray()) . ")" : "") . "\n\t\t\t\t\t\t\t\tAND thread.movedThreadID = 0\n\t\t\t\t\t\tORDER BY\tthread.lastPostTime DESC";
break;
case 'unreplied':
$sql = "SELECT\t\tthreadID\n\t\t\t\t\t\tFROM\t\twbb" . WBB_N . "_thread\n\t\t\t\t\t\tWHERE\t\tboardID IN (" . implode(',', $boardIDArray) . ")\n\t\t\t\t\t\t\t\tAND isDeleted = 0\n\t\t\t\t\t\t\t\tAND isDisabled = 0\n\t\t\t\t\t\t\t\tAND movedThreadID = 0\n\t\t\t\t\t\t\t\t" . (count(WCF::getSession()->getVisibleLanguageIDArray()) ? " AND languageID IN (" . implode(',', WCF::getSession()->getVisibleLanguageIDArray()) . ")" : "") . "\n\t\t\t\t\t\t\t\tAND replies = 0\n\t\t\t\t\t\tORDER BY\tlastPostTime DESC";
break;
case '24h':
$sql = "SELECT\t\tthreadID\n\t\t\t\t\t\tFROM\t\twbb" . WBB_N . "_thread\n\t\t\t\t\t\tWHERE\t\tboardID IN (" . implode(',', $boardIDArray) . ")\n\t\t\t\t\t\t\t\tAND lastPostTime > " . (TIME_NOW - 86400) . "\n\t\t\t\t\t\t\t\tAND isDeleted = 0\n\t\t\t\t\t\t\t\tAND isDisabled = 0\n\t\t\t\t\t\t\t\t" . (count(WCF::getSession()->getVisibleLanguageIDArray()) ? " AND languageID IN (" . implode(',', WCF::getSession()->getVisibleLanguageIDArray()) . ")" : "") . "\n\t\t\t\t\t\t\t\tAND movedThreadID = 0\n\t\t\t\t\t\tORDER BY\tlastPostTime DESC";
break;
default:
return;
}
// build search hash
$searchHash = StringUtil::getHash($sql);
// execute query
$matches = array();
$result = WCF::getDB()->sendQuery($sql, 1000);
while ($row = WCF::getDB()->fetchArray($result)) {
$matches[] = array('messageID' => $row['threadID'], 'messageType' => 'post');
}
// result is empty
if (count($matches) == 0) {
throw new NamedUserException(WCF::getLanguage()->get('wbb.search.error.noMatches'));
}
// save result in database
$searchData = array('packageID' => PACKAGE_ID, 'query' => '', 'result' => $matches, 'additionalData' => array('post' => array('findThreads' => 1)), 'sortOrder' => 'DESC', 'sortField' => 'time', 'types' => array('post'));
$searchData = serialize($searchData);
$sql = "INSERT INTO\twcf" . WCF_N . "_search\n\t\t\t\t\t\t(userID, searchData, searchDate, searchType, searchHash)\n\t\t\t\tVALUES\t\t(" . WCF::getUser()->userID . ",\n\t\t\t\t\t\t'" . escapeString($searchData) . "',\n\t\t\t\t\t\t" . TIME_NOW . ",\n\t\t\t\t\t\t'messages',\n\t\t\t\t\t\t'" . $searchHash . "')";
WCF::getDB()->sendQuery($sql);
$searchID = WCF::getDB()->getInsertID();
// forward to result page
HeaderUtil::redirect('index.php?form=Search&searchID=' . $searchID . SID_ARG_2ND_NOT_ENCODED);
exit;
} else {
if ($eventName == 'readFormParameters') {
if (isset($_POST['findThreads'])) {
$this->findThreads = intval($_POST['findThreads']);
}
if (isset($_REQUEST['findUserThreads'])) {
$this->findUserThreads = intval($_REQUEST['findUserThreads']);
}
if ($this->findUserThreads == 1) {
$this->findThreads = 1;
}
// handle findThreads option
if ($this->findThreads == 1 && (!count($eventObj->types) || in_array('post', $eventObj->types))) {
// remove all other searchable message types
// findThreads only supports post search
$eventObj->types = array('post');
} else {
$this->findThreads = 0;
}
} else {
if ($eventName == 'assignVariables') {
if ($eventObj instanceof SearchResultPage) {
$html = '<div class="floatedElement">
<label for="findThreads">' . WCF::getLanguage()->get('wbb.search.results.display') . '</label>
<select name="findThreads" id="findThreads">
<option value="0">' . WCF::getLanguage()->get('wbb.search.results.display.post') . '</option>
<option value="1"' . ($eventObj->additionalData['post']['findThreads'] == 1 ? ' selected="selected"' : '') . '>' . WCF::getLanguage()->get('wbb.search.results.display.thread') . '</option>
</select>
</div>';
WCF::getTPL()->append('additionalDisplayOptions', $html);
//.........这里部分代码省略.........