*/
public function isVisible() {
// proceed if option is visible for all
- if ($this->visible & UserOption::VISIBILITY_GUEST) {
+ if ($this->visible & self::VISIBILITY_GUEST) {
return true;
}
// proceed if option is visible for registered users and current user is logged in
- if (($this->visible & UserOption::VISIBILITY_REGISTERED) && WCF::getUser()->userID) {
+ if (($this->visible & self::VISIBILITY_REGISTERED) && WCF::getUser()->userID) {
return true;
}
// check admin permissions
- if ($this->visible & UserOption::VISIBILITY_ADMINISTRATOR) {
+ if ($this->visible & self::VISIBILITY_ADMINISTRATOR) {
if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
return true;
}
}
// check owner state
- if ($this->visible & UserOption::VISIBILITY_OWNER) {
+ if ($this->visible & self::VISIBILITY_OWNER) {
if ($this->user !== null && $this->user->userID == WCF::getUser()->userID) {
return true;
}
}
-
+
return false;
}
*/
public function isEditable() {
// check admin permissions
- if ($this->editable & UserOption::EDITABILITY_ADMINISTRATOR) {
+ if ($this->editable & self::EDITABILITY_ADMINISTRATOR) {
if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
return true;
}
}
-
+
// check owner state
- if ($this->editable & UserOption::VISIBILITY_OWNER) {
+ // TODO: Shouldn't this be: EDITABILITY_OWNER?
+ if ($this->editable & self::VISIBILITY_OWNER) {
if ($this->user === null || $this->user->userID == WCF::getUser()->userID) {
return true;
}
*/
protected function initStyle() {
if (isset($_REQUEST['styleID'])) {
- WCF::getSession()->setStyleID(intval($_REQUEST['styleID']));
+ self::getSession()->setStyleID(intval($_REQUEST['styleID']));
}
- StyleHandler::getInstance()->changeStyle(WCF::getSession()->getStyleID());
+ StyleHandler::getInstance()->changeStyle(self::getSession()->getStyleID());
}
/**
*/
protected function initBlacklist() {
if (defined('BLACKLIST_IP_ADDRESSES') && BLACKLIST_IP_ADDRESSES != '') {
- if (!StringUtil::executeWordFilter(WCF::getSession()->ipAddress, BLACKLIST_IP_ADDRESSES)) {
+ if (!StringUtil::executeWordFilter(self::getSession()->ipAddress, BLACKLIST_IP_ADDRESSES)) {
throw new PermissionDeniedException();
}
}
if (defined('BLACKLIST_USER_AGENTS') && BLACKLIST_USER_AGENTS != '') {
- if (!StringUtil::executeWordFilter(WCF::getSession()->userAgent, BLACKLIST_USER_AGENTS)) {
+ if (!StringUtil::executeWordFilter(self::getSession()->userAgent, BLACKLIST_USER_AGENTS)) {
throw new PermissionDeniedException();
}
}
if (defined('BLACKLIST_HOSTNAMES') && BLACKLIST_HOSTNAMES != '') {
- if (!StringUtil::executeWordFilter(@gethostbyaddr(WCF::getSession()->ipAddress), BLACKLIST_HOSTNAMES)) {
+ if (!StringUtil::executeWordFilter(@gethostbyaddr(self::getSession()->ipAddress), BLACKLIST_HOSTNAMES)) {
throw new PermissionDeniedException();
}
}
*/
protected $body = '';
+ // TODO: Should this be a constant?
public static $crlf = "\n";
/**
*/
public static function buildAddress($name, $email, $encodeName = true) {
if (!empty($name) && MAIL_USE_FORMATTED_ADDRESS) {
- if ($encodeName) $name = Mail::encodeMIMEHeader($name);
+ if ($encodeName) $name = self::encodeMIMEHeader($name);
if (!preg_match('/^[a-z0-9 ]*$/i', $name)) return '"'.str_replace('"', '\"', $name).'" <'.$email.'>';
else return $name . ' <'.$email.'>';
}
*/
public static function encodeMIMEHeader($string) {
if (function_exists('mb_encode_mimeheader')) {
- $string = mb_encode_mimeheader($string, 'UTF-8', 'Q', Mail::$crlf);
+ $string = mb_encode_mimeheader($string, 'UTF-8', 'Q', self::$crlf);
}
else {
$string = '=?UTF-8?Q?'.preg_replace('/[^\r\n]{73}[^=\r\n]{2}/', "$0=\r\n", str_replace("%", "=", str_replace("%0D%0A", "\r\n", str_replace("%20", " ", rawurlencode($string))))).'?=';
if (is_object($string)) $string = $string->__toString();
// escape backslash
- $string = StringUtil::replace("\\", "\\\\", $string);
+ $string = self::replace("\\", "\\\\", $string);
// escape singe quote
- $string = StringUtil::replace("'", "\'", $string);
+ $string = self::replace("'", "\'", $string);
// escape new lines
- $string = StringUtil::replace("\n", '\n', $string);
+ $string = self::replace("\n", '\n', $string);
// escape slashes
- $string = StringUtil::replace("/", '\/', $string);
+ $string = self::replace("/", '\/', $string);
return $string;
}
*/
public static function encodeAllChars($string) {
$result = '';
- for ($i = 0, $j = StringUtil::length($string); $i < $j; $i++) {
- $char = StringUtil::substring($string, $i, 1);
- $result .= '&#'.StringUtil::getCharValue($char).';';
+ for ($i = 0, $j = self::length($string); $i < $j; $i++) {
+ $char = self::substring($string, $i, 1);
+ $result .= '&#'.self::getCharValue($char).';';
}
return $result;
* @param boolean $breakWords should words be broken in the middle
* @return string
*/
- public static function truncate($string, $length = 80, $etc = StringUtil::HELLIP, $breakWords = false) {
+ public static function truncate($string, $length = 80, $etc = self::HELLIP, $breakWords = false) {
if ($length == 0) {
return '';
}
* @param string $etc ending string which will be appended after truncating
* @return string truncated string
*/
- public static function truncateHTML($string, $length = 500, $wordWrap = true, $etc = StringUtil::HELLIP) {
- if (StringUtil::length(StringUtil::stripHTML($string)) <= $length) {
+ public static function truncateHTML($string, $length = 500, $wordWrap = true, $etc = self::HELLIP) {
+ if (self::length(self::stripHTML($string)) <= $length) {
return $string;
}
$openTags = array();
$truncatedString = '';
// initalize length counter with the ending length
- $totalLength = StringUtil::length($etc);
+ $totalLength = self::length($etc);
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $string, $tags, PREG_SET_ORDER);
$truncatedString .= $tag[1];
// get length of the content without entities. If the content is too long, keep entities intact
- $contentLength = StringUtil::length(StringUtil::decodeHTML($tag[3]));
+ $contentLength = self::length(self::decodeHTML($tag[3]));
if ($contentLength + $totalLength > $length) {
$left = $length - $totalLength;
$entitiesLength = 0;
foreach ($entities[0] as $entity) {
if ($entity[1] + 1 - $entitiesLength <= $left) {
$left--;
- $entitiesLength += StringUtil::length($entity[0]);
+ $entitiesLength += self::length($entity[0]);
}
else {
break;
}
}
}
- $truncatedString .= StringUtil::substring($tag[3], 0, $left + $entitiesLength);
+ $truncatedString .= self::substring($tag[3], 0, $left + $entitiesLength);
break;
}
else {
// if word wrap is active search for the last word change
if ($wordWrap) {
- $lastWhitespace = StringUtil::lastIndexOf($truncatedString, ' ');
+ $lastWhitespace = self::lastIndexOf($truncatedString, ' ');
// check if inside a tag
- $lastOpeningTag = StringUtil::lastIndexOf($truncatedString, '<');
+ $lastOpeningTag = self::lastIndexOf($truncatedString, '<');
if ($lastOpeningTag < $lastWhitespace) {
- $lastClosingTag = StringUtil::lastIndexOf($truncatedString, '>');
+ $lastClosingTag = self::lastIndexOf($truncatedString, '>');
if (($lastClosingTag === false || $lastClosingTag > $lastWhitespace) && $lastClosingTag > $lastOpeningTag) {
$lastWhitespace = $lastOpeningTag;
array_shift($openTags);
if ($truncatedString[$lastWhitespace] != ' ') {
- $firstPart = StringUtil::substring($truncatedString, 0, $lastWhitespace);
- $secondPart = StringUtil::substring($truncatedString, $lastWhitespace + 1);
+ $firstPart = self::substring($truncatedString, 0, $lastWhitespace);
+ $secondPart = self::substring($truncatedString, $lastWhitespace + 1);
$truncatedString = $firstPart.' '.$secondPart;
}
}
}
if ($lastWhitespace !== false) {
- $endString = StringUtil::substring($truncatedString, $lastWhitespace);
+ $endString = self::substring($truncatedString, $lastWhitespace);
preg_match_all('/<\/([a-z]+)>/', $endString, $tagOverhead, PREG_SET_ORDER);
if (count($tagOverhead)) {
foreach ($tagOverhead as $tag) {
}
}
}
- $truncatedString = StringUtil::substring($truncatedString, 0, $lastWhitespace);
+ $truncatedString = self::substring($truncatedString, 0, $lastWhitespace);
}
}