public function __construct($data, $boxname = "")
 {
     $this->TopData['templatename'] = "topthanksgivinguser";
     $this->getBoxStatus($data);
     $this->TopData['boxID'] = $data['boxID'];
     if (!defined('TOPTHANKSGIVINGUSER_COUNT_ACP')) {
         define('TOPTHANKSGIVINGUSER_COUNT_ACP', 10);
     }
     if (!defined('TOPTHANKSGIVINGUSER_TITLELENGTH_ACP')) {
         define('TOPTHANKSGIVINGUSER_TITLELENGTH_ACP', 28);
     }
     if (!defined('TOPTHANKSGIVINGUSER_SBCOLOR_ACP')) {
         define('TOPTHANKSGIVINGUSER_SBCOLOR_ACP', 2);
     }
     if (!defined('TOPTHANKSGIVINGUSER_HITS_ACP')) {
         define('TOPTHANKSGIVINGUSER_HITS_ACP', true);
     }
     $sql = "SELECT wcf.userID, wcf.username, wbb.thanks_got" . "\n  FROM wcf" . WCF_N . "_user wcf" . "\n  LEFT JOIN wbb" . WBB_N . "_user wbb ON (wbb.userid = wcf.userid)" . "\n WHERE wbb.thanks_got > 0" . "\n ORDER BY wbb.thanks_got DESC, wcf.username" . "\n LIMIT 0, " . TOPTHANKSGIVINGUSER_COUNT_ACP;
     $result = WBBCore::getDB()->sendQuery($sql);
     while ($row = WBBCore::getDB()->fetchArray($result)) {
         $plainUser = $row['username'];
         $row['thanks_got'] = StringUtil::formatInteger($row['thanks_got']);
         if (TOPTHANKSGIVINGUSER_TITLELENGTH_ACP != 0 && strlen($plainUser) > TOPTHANKSGIVINGUSER_TITLELENGTH_ACP) {
             $row['username'] = StringUtil::substring($plainUser, 0, TOPTHANKSGIVINGUSER_TITLELENGTH_ACP - 3) . '...';
         }
         $row['username'] = StringUtil::encodeHTML($row['username']);
         $this->TopData['thanksgivinguser'][] = $row;
     }
     WCF::getTPL()->assign('TOPTHANKSGIVINGUSER_SBCOLOR_ACP', intval(TOPTHANKSGIVINGUSER_SBCOLOR_ACP));
     WCF::getTPL()->assign('TOPTHANKSGIVINGUSER_HITS_ACP', TOPTHANKSGIVINGUSER_HITS_ACP);
 }
 /**
  * Checks the condition.
  *
  * @param	PMRuleCondition		$condition
  * @param	string			$string
  * @return	boolean
  */
 protected function checkCondition(PMRuleCondition $condition, $string)
 {
     $value = StringUtil::toLowerCase($condition->ruleConditionValue);
     $string = StringUtil::toLowerCase($string);
     switch ($condition->ruleCondition) {
         case 'contains':
             if (StringUtil::indexOf($string, $value) !== false) {
                 return true;
             }
             break;
         case 'dontContains':
             if (StringUtil::indexOf($string, $value) === false) {
                 return true;
             }
             break;
         case 'beginsWith':
             if (StringUtil::indexOf($string, $value) === 0) {
                 return true;
             }
             break;
         case 'endsWith':
             if (StringUtil::substring($string, -1 * StringUtil::length($value)) == $value) {
                 return true;
             }
             break;
         case 'isEqualTo':
             if ($value == $string) {
                 return true;
             }
             break;
     }
     return false;
 }
 /**
  * Parses search keywords.
  * 
  * @param	string		$keywordString
  */
 protected static function parseKeywords($keywordString)
 {
     // convert encoding if necessary
     if (CHARSET == 'UTF-8' && !StringUtil::isASCII($keywordString) && !StringUtil::isUTF8($keywordString)) {
         $keywordString = StringUtil::convertEncoding('ISO-8859-1', 'UTF-8', $keywordString);
     }
     // remove bad wildcards
     $keywordString = preg_replace('/(?<!\\w)\\*/', '', $keywordString);
     // remove search operators
     $keywordString = preg_replace('/[\\+\\-><()~]+/', '', $keywordString);
     if (StringUtil::substring($keywordString, 0, 1) == '"' && StringUtil::substring($keywordString, -1) == '"') {
         // phrases search
         $keywordString = StringUtil::trim(StringUtil::substring($keywordString, 1, -1));
         if (!empty($keywordString)) {
             self::$keywords = array_merge(self::$keywords, array(StringUtil::encodeHTML($keywordString)));
         }
     } else {
         // replace word delimiters by space
         $keywordString = preg_replace('/[.,]/', ' ', $keywordString);
         $keywords = ArrayUtil::encodeHTML(ArrayUtil::trim(explode(' ', $keywordString)));
         if (count($keywords) > 0) {
             self::$keywords = array_merge(self::$keywords, $keywords);
         }
     }
 }
Пример #4
0
 public function __construct($data, $boxname = "")
 {
     $this->TopData['templatename'] = "topthreads";
     $this->getBoxStatus($data);
     $this->TopData['boxID'] = $data['boxID'];
     if (!defined('TOPTHREADS_COUNT')) {
         define('TOPTHREADS_COUNT', 10);
     }
     if (!defined('TOPTHREADS_TITLELENGTH')) {
         define('TOPTHREADS_TITLELENGTH', 25);
     }
     if (!defined('TOPTHREADS_SBCOLOR_ACP')) {
         define('TOPTHREADS_SBCOLOR_ACP', 2);
     }
     require_once WBB_DIR . 'lib/data/board/Board.class.php';
     $boardIDs = Board::getAccessibleBoards();
     if (!empty($boardIDs)) {
         $sql = "SELECT thread.*" . "\n  FROM wbb" . WBB_N . "_thread thread" . "\n WHERE thread.boardID IN (0" . $boardIDs . ")" . "\n ORDER BY thread.replies DESC" . "\n LIMIT 0, " . TOPTHREADS_COUNT;
         $result = WBBCore::getDB()->sendQuery($sql);
         while ($row = WBBCore::getDB()->fetchArray($result)) {
             $row['replies'] = StringUtil::formatInteger($row['replies']);
             $row['title'] = StringUtil::encodeHTML($row['topic']) . ' - ' . $row['replies'];
             if (TOPTHREADS_TITLELENGTH != 0 && strlen($row['topic']) > TOPTHREADS_TITLELENGTH) {
                 $row['topic'] = StringUtil::substring($row['topic'], 0, TOPTHREADS_TITLELENGTH - 3) . '...';
             }
             $row['topic'] = StringUtil::encodeHTML($row['topic']);
             $this->TopData['threads'][] = $row;
         }
     }
 }
 /**
  * @see TemplatePluginModifier::execute()
  */
 public function execute($tagArgs, Template $tplObj)
 {
     // default values
     $length = 80;
     $etc = '...';
     $breakWords = false;
     // get values
     $string = $tagArgs[0];
     if (isset($tagArgs[1])) {
         $length = intval($tagArgs[1]);
     }
     if (isset($tagArgs[2])) {
         $etc = $tagArgs[2];
     }
     if (isset($tagArgs[3])) {
         $breakWords = $tagArgs[3];
     }
     // execute plugin
     if ($length == 0) {
         return '';
     }
     if (StringUtil::length($string) > $length) {
         $length -= StringUtil::length($etc);
         if (!$breakWords) {
             $string = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($string, 0, $length + 1));
         }
         return StringUtil::substring($string, 0, $length) . $etc;
     } else {
         return $string;
     }
 }
 /**
  * Inserts the page number into the link.
  * 
  * @param 	string		$link
  * @param 	integer		$pageNo
  * @return	string		final link
  */
 protected static function insertPageNumber($link, $pageNo)
 {
     $startPos = StringUtil::indexOf($link, '%d');
     if ($startPos !== null) {
         $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2);
     }
     return $link;
 }
 /**
  * Returns an excerpt of this private message.
  * 
  * @return	string
  */
 public function getMessagePreview()
 {
     AttachmentBBCode::setMessageID($this->pmID);
     $parser = MessageParser::getInstance();
     $parser->setOutputType('text/plain');
     $message = $parser->parse($this->message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes, false);
     if (StringUtil::length($message) > 500) {
         $message = StringUtil::substring($message, 0, 497) . '...';
     }
     return $message;
 }
 /**
  * @see DatabaseObject::handleData()
  */
 protected function handleData($data)
 {
     parent::handleData($data);
     // calculate page logo path
     if (!empty($this->data['variables']['page.logo.image']) && !FileUtil::isURL($this->data['variables']['page.logo.image']) && StringUtil::substring($this->data['variables']['page.logo.image'], 0, 1) !== '/') {
         $this->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->data['variables']['page.logo.image'];
     }
     // load icon cache
     WCF::getCache()->addResource('icon-' . PACKAGE_ID . '-' . $this->styleID, WCF_DIR . 'cache/cache.icon-' . PACKAGE_ID . '-' . $this->styleID . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderIcon.class.php');
     $this->iconCache = WCF::getCache()->get('icon-' . PACKAGE_ID . '-' . $this->styleID);
 }
 /**
  * Returns an excerpt of the message.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     $enableSmilies = 1;
     $enableHtml = 0;
     $enableBBCodes = 1;
     MessageParser::getInstance()->setOutputType('text/plain');
     $message = MessageParser::getInstance()->parse($this->comment, $enableSmilies, $enableHtml, $enableBBCodes);
     // get abstract
     if (StringUtil::length($message) > 50) {
         $message = StringUtil::substring($message, 0, 47) . '...';
     }
     return $message;
 }
 /**
  * @see NotificationObject::getTitle()
  */
 public function getTitle()
 {
     $message = $this->getFormattedMessage('text/plain');
     $message = StringUtil::stripHTML($message);
     $message = StringUtil::trim($message);
     if (StringUtil::length($message) > 100) {
         $message = StringUtil::substring($message, 0, 97) . '...';
     }
     if (empty($message)) {
         $message = '#' . $this->entryID;
     }
     return $message;
 }
 public static function getTitle($name, $html = false)
 {
     $item = 'wcf.sketchbook.sketchTitles.' . self::nameToLangVar($name);
     $value = WCF::getLanguage()->getDynamicVariable($item);
     $new = false;
     if ($value == $title) {
         $value = StringUtil::substring($title, StringUtil::lastIndexOf($title, '.'));
         $new = true;
     }
     if ($html) {
         return '<span class="sketch' . ($new ? ' sketchNew' : '') . '">' . StringUtil::encodeHTML($title) . '</span>';
     }
     return $title;
 }
Пример #12
0
 /**
  * Returns an excerpt of the help item.
  * 
  * @return	string
  */
 public function getExcerpt()
 {
     // get text
     $description = WCF::getLanguage()->getDynamicVariable('wcf.help.item.' . $this->helpItem . '.description');
     // remove headlines
     $description = preg_replace('~<h4>.*?</h4>~', '', $description);
     // remove help images
     $description = preg_replace('~<p class="helpImage.*?</p>~s', '', $description);
     // strip html tags
     $description = strip_tags($description);
     // truncate text
     if (StringUtil::length($description) > 250) {
         $description = preg_replace('/\\s+?(\\S+)?$/', '', StringUtil::substring($description, 0, 251));
         $description = StringUtil::substring($description, 0, 250) . '...';
     }
     return $description;
 }
 /**
  * @see TemplatePluginCompiler::executeStart()
  */
 public function executeStart($tagArgs, TemplateScriptingCompiler $compiler)
 {
     $compiler->pushTag('implode');
     if (!isset($tagArgs['from'])) {
         throw new SystemException($compiler->formatSyntaxError("missing 'from' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo()), 12001);
     }
     if (!isset($tagArgs['item'])) {
         throw new SystemException($compiler->formatSyntaxError("missing 'item' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo()), 12001);
     }
     $hash = StringUtil::getRandomID();
     $glue = isset($tagArgs['glue']) ? $tagArgs['glue'] : "', '";
     $this->tagStack[] = array('hash' => $hash, 'glue' => $glue);
     $phpCode = "<?php\n";
     $phpCode .= "\$_length" . $hash . " = count(" . $tagArgs['from'] . ");\n";
     $phpCode .= "\$_i" . $hash . " = 0;\n";
     $phpCode .= "foreach (" . $tagArgs['from'] . " as " . (isset($tagArgs['key']) ? (StringUtil::substring($tagArgs['key'], 0, 1) != '$' ? "\$this->v[" . $tagArgs['key'] . "]" : $tagArgs['key']) . " => " : '') . (StringUtil::substring($tagArgs['item'], 0, 1) != '$' ? "\$this->v[" . $tagArgs['item'] . "]" : $tagArgs['item']) . ") { ?>";
     return $phpCode;
 }
 /**
  * autoload method for classname
  *
  * @param 	string		$className
  */
 public function autoload($className)
 {
     if (!isset($className)) {
         throw new SystemException('missing className');
     }
     $className = StringUtil::getClassName($className);
     $dir = StringUtil::toLowercase(StringUtil::substring($className, StringUtil::length('ViewableContest')));
     if (empty($dir)) {
         throw new SystemException('wrong dir: ' . $dir);
     }
     $file = WCF_DIR . 'lib/data/contest/' . $dir . '/' . $className . '.class.php';
     if (!is_file($file)) {
         throw new SystemException('wrong file: ' . $file);
     }
     require_once $file;
     if (!class_exists($className)) {
         throw new SystemException('class does not exist: ' . $className);
     }
 }
 public function __construct($data, $boxname = "")
 {
     $this->threadLastPostsBoxData['templatename'] = "threadlastpostsbox";
     $this->getBoxStatus($data);
     $this->threadLastPostsBoxData['boxID'] = $data['boxID'];
     $cntPosts = 0;
     if (!defined('THREADLASTPOSTSBOX_THREADID')) {
         define('THREADLASTPOSTSBOX_THREADID', 0);
     }
     if (!defined('THREADLASTPOSTSBOX_LIMIT')) {
         define('THREADLASTPOSTSBOX_LIMIT', 10);
     }
     if (!defined('THREADLASTPOSTSBOX_TITLELENGTH')) {
         define('THREADLASTPOSTSBOX_TITLELENGTH', 28);
     }
     if (!defined('THREADLASTPOSTSBOX_SBCOLOR')) {
         define('THREADLASTPOSTSBOX_SBCOLOR', 2);
     }
     require_once WBB_DIR . 'lib/data/board/Board.class.php';
     $boardIDs = Board::getAccessibleBoards();
     if (!empty($boardIDs) && THREADLASTPOSTSBOX_THREADID) {
         $sql = "SELECT wp.postID, wp.threadID, wp.userID, wp.subject, wp.message, wp.time" . "\n  FROM wbb1_1_post wp" . "\n  JOIN wbb1_1_thread wt ON (wt.threadID = wp.threadID)" . "\n WHERE wp.threadID = " . THREADLASTPOSTSBOX_THREADID . "\n   AND wp.isDeleted = 0" . "\n   AND wp.isDisabled = 0" . "\n   AND wt.isDeleted = 0" . "\n   AND wt.isDisabled = 0" . "\n   AND wt.boardID IN (" . $boardIDs . ")" . "\n ORDER BY wp.postID DESC" . "\n  LIMIT 0, " . THREADLASTPOSTSBOX_LIMIT;
         $result = WBBCore::getDB()->sendQuery($sql);
         while ($row = WBBCore::getDB()->fetchArray($result)) {
             if (!empty($row['subject'])) {
                 $title = $row['subject'];
             } else {
                 $title = preg_replace('/\\[/', '<', $row['message']);
                 $title = preg_replace('/\\]/', '>', $title);
                 $title = strip_tags($title);
                 //StringUtil::stripHTML($title);
             }
             if (THREADLASTPOSTSBOX_TITLELENGTH != 0 && StringUtil::length($title) > THREADLASTPOSTSBOX_TITLELENGTH) {
                 $title = StringUtil::substring($title, 0, THREADLASTPOSTSBOX_TITLELENGTH - 3) . '...';
             }
             $row['title'] = StringUtil::encodeHTML($title);
             $this->threadLastPostsBoxData['box'][] = $row;
             $cntPosts++;
         }
     }
     WCF::getTPL()->assign(array('THREADLASTPOSTSBOX_SBCOLOR' => intval(THREADLASTPOSTSBOX_SBCOLOR), 'threadLastPostBoxCnt' => $cntPosts));
 }
Пример #16
0
 /**
  * @see BBCode::getParsedTag()
  */
 public function getParsedTag($openingTag, $content, $closingTag, BBCodeParser $parser)
 {
     $url = '';
     if (isset($openingTag['attributes'][0])) {
         $url = $openingTag['attributes'][0];
     }
     $noTitle = $content == $url;
     // add protocol if necessary
     if (!preg_match("/[a-z]:\\/\\//si", $url)) {
         $url = 'http://' . $url;
     }
     if ($parser->getOutputType() == 'text/html') {
         $external = true;
         if (($newURL = $this->isInternalURL($url)) !== false) {
             $url = $newURL;
             $external = false;
         }
         // cut visible url
         if ($noTitle) {
             $decodedContent = StringUtil::decodeHTML($content);
             if (StringUtil::length($decodedContent) > 60) {
                 $content = StringUtil::encodeHTML(StringUtil::substring($decodedContent, 0, 40)) . '&hellip;' . StringUtil::encodeHTML(StringUtil::substring($decodedContent, -15));
             }
         } else {
             $content = StringUtil::trim($content);
         }
         return '<a href="' . $url . '"' . ($external ? ' class="externalURL"' : '') . '>' . $content . '</a>';
     } else {
         if ($parser->getOutputType() == 'text/plain') {
             if ($noTitle) {
                 return $url;
             }
             return $content . ': ' . $url;
         }
     }
 }
 public function __construct($data, $boxname = "")
 {
     $this->TopData['templatename'] = "topthanksgivingposts";
     $this->getBoxStatus($data);
     $this->TopData['boxID'] = $data['boxID'];
     if (!defined('TOPTHANKSGIVING_COUNT_ACP')) {
         define('TOPTHANKSGIVING_COUNT_ACP', 10);
     }
     if (!defined('TOPTHANKSGIVING_TITLELENGTH_ACP')) {
         define('TOPTHANKSGIVING_TITLELENGTH_ACP', 28);
     }
     if (!defined('TOPTHANKSGIVING_SBCOLOR_ACP')) {
         define('TOPTHANKSGIVING_SBCOLOR_ACP', 2);
     }
     if (!defined('TOPTHANKSGIVING_HITS_ACP')) {
         define('TOPTHANKSGIVING_HITS_ACP', true);
     }
     require_once WBB_DIR . 'lib/data/board/Board.class.php';
     $boardIDs = Board::getAccessibleBoards();
     if (!empty($boardIDs)) {
         $sql = "SELECT thread.topic AS subject, MIN(post.postID) AS postID, COUNT(*) AS cnt" . "\n  FROM wbb" . WBB_N . "_thread thread" . "\n  LEFT JOIN (wbb" . WBB_N . "_post post, wbb" . WBB_N . "_thank_guests tg, wbb" . WBB_N . "_thank_user tu)" . "\n  ON (post.threadID = thread.threadID AND (post.postID = tu.postID OR post.postID = tg.postID))" . "\n  WHERE thread.isDisabled = 0" . "\n  AND thread.isDeleted = 0" . "\n  AND thread.boardID IN (" . $boardIDs . ")" . "\n  AND post.isDeleted = 0" . "\n  AND post.isDisabled = 0" . "\n  GROUP BY thread.threadID" . "\n  ORDER BY cnt DESC" . "\n  LIMIT 0, " . TOPTHANKSGIVING_COUNT_ACP;
         $result = WBBCore::getDB()->sendQuery($sql);
         while ($row = WBBCore::getDB()->fetchArray($result)) {
             $plainSubject = $row['subject'];
             $row['thanks'] = StringUtil::formatInteger($row['cnt']);
             $row['title'] = StringUtil::encodeHTML($plainSubject) . ' - ' . $row['thanks'];
             if (TOPTHANKSGIVING_TITLELENGTH_ACP != 0 && strlen($plainSubject) > TOPTHANKSGIVING_TITLELENGTH_ACP) {
                 $row['subject'] = StringUtil::substring($plainSubject, 0, TOPTHANKSGIVING_TITLELENGTH_ACP - 3) . '...';
             }
             $row['subject'] = StringUtil::encodeHTML($row['subject']);
             $this->TopData['thanksgiving'][] = $row;
         }
     }
     WCF::getTPL()->assign('TOPTHANKSGIVING_SBCOLOR_ACP', intval(TOPTHANKSGIVING_SBCOLOR_ACP));
     WCF::getTPL()->assign('TOPTHANKSGIVING_HITS_ACP', TOPTHANKSGIVING_HITS_ACP);
 }
 /**
  * Gets the list of available letters.
  */
 protected function loadLetters()
 {
     for ($i = 0, $j = StringUtil::length(self::$defaultLetters); $i < $j; $i++) {
         $this->letters[] = StringUtil::substring(self::$defaultLetters, $i, 1);
     }
 }
 /**
  * Returns html entities of all characters in the given string.
  * 
  * @param	string		$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 .= '&#' . (USE_MBSTRING ? StringUtil::getCharValue($char) : ord($char)) . ';';
     }
     return $result;
 }
 /**
  * Returns the right file type icon for the given attachment.
  * 
  * @return	string
  */
 public function getFileTypeIcon()
 {
     if ($this->fileTypeIcon === null) {
         $this->fileTypeIcon = '';
         // get file extension
         $extension = StringUtil::firstCharToUpperCase(StringUtil::toLowerCase(StringUtil::substring($this->attachmentName, StringUtil::lastIndexOf($this->attachmentName, '.') + 1)));
         // get file type icon
         if (file_exists(WCF_DIR . 'icon/fileTypeIcon' . $extension . 'M.png')) {
             $this->fileTypeIcon = 'fileTypeIcon' . $extension . 'M.png';
         } else {
             foreach (self::$fileTypeGroups as $key => $group) {
                 if (in_array($extension, $group)) {
                     $this->fileTypeIcon = 'fileTypeIcon' . $key . 'M.png';
                     break;
                 }
             }
             if (empty($this->fileTypeIcon)) {
                 $this->fileTypeIcon = 'fileTypeIconDefaultM.png';
             }
         }
     }
     if (!class_exists('StyleManager')) {
         return RELATIVE_WCF_DIR . 'icon/' . $this->fileTypeIcon;
     } else {
         return StyleManager::getStyle()->getIconPath($this->fileTypeIcon);
     }
 }
 /**
  * Builds the attributes of a bbcode tag.
  * 
  * @param	string		$string
  * @return	array		bbcode attributes
  */
 protected function buildTagAttributes($string)
 {
     preg_match_all("~(?:^|,)('[^'\\\\]*(?:\\\\.[^'\\\\]*)*'|[^,]*)~", $string, $matches);
     // remove quotes
     for ($i = 0, $j = count($matches[1]); $i < $j; $i++) {
         if (StringUtil::substring($matches[1][$i], 0, 1) == "'" && StringUtil::substring($matches[1][$i], -1) == "'") {
             $matches[1][$i] = StringUtil::replace("\\'", "'", $matches[1][$i]);
             $matches[1][$i] = StringUtil::replace("\\\\", "\\", $matches[1][$i]);
             $matches[1][$i] = StringUtil::substring($matches[1][$i], 1, -1);
         }
     }
     return $matches[1];
 }
 /**
  * Compiles an output tag.
  * 
  * @param	string		$tag
  * @return	string			php code of this tag
  */
 protected function compileOutputTag($tag)
 {
     $encodeHTML = false;
     $formatNumeric = false;
     if ($tag[0] == '@') {
         $tag = StringUtil::substring($tag, 1);
     } else {
         if ($tag[0] == '#') {
             $tag = StringUtil::substring($tag, 1);
             $formatNumeric = true;
         } else {
             $encodeHTML = true;
         }
     }
     $parsedTag = $this->compileVariableTag($tag);
     // the @ operator at the beginning of an output avoids
     // the default call of StringUtil::encodeHTML()
     if ($encodeHTML) {
         $parsedTag = 'StringUtil::encodeHTML(' . $parsedTag . ')';
     } else {
         if ($formatNumeric) {
             $parsedTag = 'StringUtil::formatNumeric(' . $parsedTag . ')';
         }
     }
     return '<?php echo ' . $parsedTag . '; ?>';
 }
 /**
  * @see NotificationObject::getTitle()
  */
 public function getTitle()
 {
     $substring = StringUtil::substring($this->className, StringUtil::length('Contest'));
     return $substring;
 }
 /**
  * Imports a style.
  * 
  * @param	string		$filename
  * @param	integer		$packageID
  * @param	StyleEditor	$style
  * @return	StyleEditor
  */
 public static function import($filename, $packageID = PACKAGE_ID, $style = null)
 {
     // open file
     require_once WCF_DIR . 'lib/system/io/Tar.class.php';
     $tar = new Tar($filename);
     // get style data
     $data = self::readStyleData($tar);
     // fix safe_mode problem
     $iconsLocation = FileUtil::addTrailingSlash($data['variables']['global.icons.location']);
     $imagesLocation = $data['variables']['global.images.location'];
     if (FileUtil::getSafeMode() && !empty($data['images']) && !file_exists(WCF_DIR . $imagesLocation)) {
         $oldImagesLocation = $imagesLocation;
         $imagesLocation = 'images/' . str_replace('/', '-', preg_replace('!^images/!', '', $imagesLocation));
         foreach ($data['variables'] as $name => $value) {
             $data['variables'][$name] = str_replace($oldImagesLocation, $imagesLocation, $value);
         }
         $data['variables']['global.images.location'] = 'images/';
         if (strpos($data['variables']['page.logo.image'], '../') !== false) {
             $data['variables']['page.logo.image'] = 'images/' . basename($data['variables']['page.logo.image']);
         }
     }
     // create template pack
     $templatePackID = 0;
     if (!empty($data['templates'])) {
         // create template pack
         $originalTemplatePackName = $templatePackName = $data['name'];
         $templatePackFolderName = preg_replace('/[^a-z0-9_-]/i', '', $templatePackName);
         if (empty($templatePackFolderName)) {
             $templatePackFolderName = 'generic' . StringUtil::substring(StringUtil::getRandomID(), 0, 8);
         }
         $originalTemplatePackFolderName = $templatePackFolderName;
         // get unique template pack name
         $i = 1;
         do {
             $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_pack\n\t\t\t\t\tWHERE\ttemplatePackName = '" . escapeString($templatePackName) . "'";
             $row = WCF::getDB()->getFirstRow($sql);
             if (!$row['count']) {
                 break;
             }
             $templatePackName = $originalTemplatePackName . '_' . $i;
             $i++;
         } while (true);
         // get unique folder name
         $i = 1;
         do {
             $sql = "SELECT\tCOUNT(*) AS count\n\t\t\t\t\tFROM\twcf" . WCF_N . "_template_pack\n\t\t\t\t\tWHERE\ttemplatePackFolderName = '" . escapeString(FileUtil::addTrailingSlash($templatePackFolderName)) . "'\n\t\t\t\t\t\tAND parentTemplatePackID = 0";
             $row = WCF::getDB()->getFirstRow($sql);
             if (!$row['count']) {
                 break;
             }
             $templatePackFolderName = $originalTemplatePackFolderName . '_' . $i;
             $i++;
         } while (true);
         $sql = "INSERT INTO\twcf" . WCF_N . "_template_pack\n\t\t\t\t\t\t(templatePackName, templatePackFolderName)\n\t\t\t\tVALUES\t\t('" . escapeString($templatePackName) . "', '" . FileUtil::addTrailingSlash(escapeString($templatePackFolderName)) . "')";
         WCF::getDB()->sendQuery($sql);
         $templatePackID = WCF::getDB()->getInsertID("wcf" . WCF_N . "_template_pack", 'templatePackID');
     }
     // save style
     if ($style !== null) {
         $style->update($data['name'], $data['variables'], $templatePackID, $data['description'], $data['version'], $data['date'], ($data['image'] ? 'images/' : '') . $data['image'], $data['copyright'], $data['license'], $data['authorName'], $data['authorURL']);
     } else {
         $style = self::create($data['name'], $data['variables'], $templatePackID, $data['description'], $data['version'], $data['date'], ($data['image'] ? 'images/' : '') . $data['image'], $data['copyright'], $data['license'], $data['authorName'], $data['authorURL'], 0, $packageID);
     }
     // import preview image
     if (!empty($data['image'])) {
         $i = $tar->getIndexByFilename($data['image']);
         if ($i !== false) {
             $tar->extract($i, WCF_DIR . 'images/' . $data['image']);
             @chmod(WCF_DIR . 'images/' . $data['image'], 0777);
         }
     }
     // import images
     if (!empty($data['images'])) {
         // create images folder if necessary
         if (!file_exists(WCF_DIR . $imagesLocation) && !FileUtil::getSafeMode()) {
             @mkdir(WCF_DIR . $data['variables']['global.images.location'], 0777);
             @chmod(WCF_DIR . $data['variables']['global.images.location'], 0777);
         }
         $i = $tar->getIndexByFilename($data['images']);
         if ($i !== false) {
             // extract images tar
             $destination = FileUtil::getTemporaryFilename('images_');
             $tar->extract($i, $destination);
             // open images tar
             $imagesTar = new Tar($destination);
             $contentList = $imagesTar->getContentList();
             foreach ($contentList as $key => $val) {
                 if ($val['type'] == 'file') {
                     $imagesTar->extract($key, WCF_DIR . $imagesLocation . basename($val['filename']));
                     @chmod(WCF_DIR . $imagesLocation . basename($val['filename']), 0666);
                 }
             }
             // delete tmp file
             $imagesTar->close();
             @unlink($destination);
         }
     }
     // import icons
     if (!empty($data['icons']) && $iconsLocation != 'icon/') {
         $i = $tar->getIndexByFilename($data['icons']);
         if ($i !== false) {
             // extract icons tar
             $destination = FileUtil::getTemporaryFilename('icons_');
             $tar->extract($i, $destination);
             // open icons tar and group icons by package
             $iconsTar = new Tar($destination);
             $contentList = $iconsTar->getContentList();
             $packageToIcons = array();
             foreach ($contentList as $key => $val) {
                 if ($val['type'] == 'file') {
                     $folders = explode('/', $val['filename']);
                     $packageName = array_shift($folders);
                     if (!isset($packageToIcons[$packageName])) {
                         $packageToIcons[$packageName] = array();
                     }
                     $packageToIcons[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders));
                 }
             }
             // copy icons
             foreach ($packageToIcons as $package => $icons) {
                 // try to find package
                 $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = '" . escapeString($package) . "'\n\t\t\t\t\t\t\tAND standalone = 1";
                 $result = WCF::getDB()->sendQuery($sql);
                 while ($row = WCF::getDB()->fetchArray($result)) {
                     // get icon path
                     $iconDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . $iconsLocation;
                     // create icon path
                     if (!file_exists($iconDir)) {
                         @mkdir($iconDir, 0777);
                         @chmod($iconDir, 0777);
                     }
                     // copy icons
                     foreach ($icons as $icon) {
                         $iconsTar->extract($icon['index'], $iconDir . $icon['filename']);
                     }
                 }
             }
             // delete tmp file
             $iconsTar->close();
             @unlink($destination);
         }
     }
     // import templates
     if (!empty($data['templates'])) {
         $i = $tar->getIndexByFilename($data['templates']);
         if ($i !== false) {
             // extract templates tar
             $destination = FileUtil::getTemporaryFilename('templates_');
             $tar->extract($i, $destination);
             // open templates tar and group templates by package
             $templatesTar = new Tar($destination);
             $contentList = $templatesTar->getContentList();
             $packageToTemplates = array();
             foreach ($contentList as $key => $val) {
                 if ($val['type'] == 'file') {
                     $folders = explode('/', $val['filename']);
                     $packageName = array_shift($folders);
                     if (!isset($packageToTemplates[$packageName])) {
                         $packageToTemplates[$packageName] = array();
                     }
                     $packageToTemplates[$packageName][] = array('index' => $val['index'], 'filename' => implode('/', $folders));
                 }
             }
             // copy templates
             foreach ($packageToTemplates as $package => $templates) {
                 // try to find package
                 $sql = "SELECT\t*\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t\t\t\tWHERE\tpackage = '" . escapeString($package) . "'\n\t\t\t\t\t\t\tAND standalone = 1";
                 $result = WCF::getDB()->sendQuery($sql);
                 while ($row = WCF::getDB()->fetchArray($result)) {
                     // get icon path
                     $templatesDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $row['packageDir']) . 'templates/' . $templatePackFolderName);
                     // create template path
                     if (!file_exists($templatesDir)) {
                         @mkdir($templatesDir, 0777);
                         @chmod($templatesDir, 0777);
                     }
                     // copy templates
                     foreach ($templates as $template) {
                         $templatesTar->extract($template['index'], $templatesDir . $template['filename']);
                         $sql = "INSERT INTO\twcf" . WCF_N . "_template\n\t\t\t\t\t\t\t\t\t\t(packageID, templateName, templatePackID)\n\t\t\t\t\t\t\t\tVALUES\t\t(" . $row['packageID'] . ", '" . escapeString(str_replace('.tpl', '', $template['filename'])) . "', " . $templatePackID . ")";
                         WCF::getDB()->sendQuery($sql);
                     }
                 }
             }
             // delete tmp file
             $templatesTar->close();
             @unlink($destination);
         }
     }
     $tar->close();
     return $style;
 }
 private static function parseURLsCallback($matches)
 {
     $url = $title = $matches[0];
     $decodedTitle = StringUtil::decodeHTML($title);
     if (StringUtil::length($decodedTitle) > 60) {
         $title = StringUtil::encodeHTML(StringUtil::substring($decodedTitle, 0, 40)) . '&hellip;' . StringUtil::encodeHTML(StringUtil::substring($decodedTitle, -15));
     }
     // add protocol if necessary
     if (!preg_match("/[a-z]:\\/\\//si", $url)) {
         $url = 'http://' . $url;
     }
     $external = true;
     if (($newURL = self::isInternalURL($url)) !== false) {
         $url = $newURL;
         $external = false;
     }
     return '<a href="' . $url . '"' . ($external ? ' class="externalURL"' : '') . '>' . $title . '</a>';
 }
 /**
  * Sends the email notification.
  */
 public function sendNotification($post = null, $attachmentList = null)
 {
     $sql = "SELECT\t\tuser.*\n\t\t\tFROM\t\twbb" . WBB_N . "_board_subscription subscription\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user\n\t\t\tON\t\t(user.userID = subscription.userID)\n\t\t\tWHERE\t\tsubscription.boardID = " . $this->boardID . "\n\t\t\t\t\tAND subscription.enableNotification = 1\n\t\t\t\t\tAND subscription.emails = 0\n\t\t\t\t\tAND subscription.userID <> " . $this->userID . "\n\t\t\t\t\tAND user.userID IS NOT NULL";
     $result = WCF::getDB()->sendQuery($sql);
     if (WCF::getDB()->countRows($result)) {
         // get first post
         if ($post === null) {
             require_once WBB_DIR . 'lib/data/post/Post.class.php';
             $post = new Post($this->firstPostID);
         }
         // get attachments
         if ($attachmentList === null) {
             require_once WCF_DIR . 'lib/data/attachment/MessageAttachmentList.class.php';
             $attachmentList = new MessageAttachmentList($this->firstPostID);
             $attachmentList->readObjects();
         }
         // set attachments
         require_once WCF_DIR . 'lib/data/message/bbcode/AttachmentBBCode.class.php';
         AttachmentBBCode::setAttachments($attachmentList->getSortedAttachments());
         // parse text
         require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php';
         $parser = MessageParser::getInstance();
         $parser->setOutputType('text/plain');
         $parsedText = $parser->parse($post->message, $post->enableSmilies, $post->enableHtml, $post->enableBBCodes, false);
         // truncate message
         if (!POST_NOTIFICATION_SEND_FULL_MESSAGE && StringUtil::length($parsedText) > 500) {
             $parsedText = StringUtil::substring($parsedText, 0, 500) . '...';
         }
         // send notifications
         $languages = array();
         $languages[WCF::getLanguage()->getLanguageID()] = WCF::getLanguage();
         $languages[0] = WCF::getLanguage();
         require_once WCF_DIR . 'lib/data/mail/Mail.class.php';
         require_once WCF_DIR . 'lib/data/user/User.class.php';
         require_once WBB_DIR . 'lib/data/board/Board.class.php';
         $board = Board::getBoard($this->boardID);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $recipient = new User(null, $row);
             // get language
             if (!isset($languages[$recipient->languageID])) {
                 $languages[$recipient->languageID] = new Language($recipient->languageID);
             }
             // enable language
             $languages[$recipient->languageID]->setLocale();
             // send mail
             $data = array('PAGE_TITLE' => $languages[$recipient->languageID]->get(PAGE_TITLE), 'PAGE_URL' => PAGE_URL, '$recipient' => $recipient->username, '$author' => $this->username, '$boardTitle' => $languages[$recipient->languageID]->get($board->title), '$topic' => $this->topic, '$threadID' => $this->threadID, '$text' => $parsedText);
             $mail = new Mail(array($recipient->username => $recipient->email), $languages[$recipient->languageID]->get('wbb.threadAdd.notification.subject', array('$title' => $languages[$recipient->languageID]->get($board->title))), $languages[$recipient->languageID]->get('wbb.threadAdd.notification.mail', $data));
             $mail->send();
         }
         // enable user language
         WCF::getLanguage()->setLocale();
         // update notification count
         $sql = "UPDATE\twbb" . WBB_N . "_board_subscription\n\t\t\t\tSET \temails = emails + 1\n\t\t\t\tWHERE\tboardID = " . $this->boardID . "\n\t\t\t\t\tAND enableNotification = 1\n\t\t\t\t\tAND emails = 0";
         WCF::getDB()->registerShutdownUpdate($sql);
     }
 }
Пример #27
0
 /**
  * Adds tags to a tagged object.
  * 
  * @param 	array 		$tags 		array holding tag names
  * @param 	Tagged 		$object 	object that should be tagged
  */
 public function addTags($tags, Tagged $object, $languageID = 0)
 {
     $tagIDs = array();
     foreach ($tags as $tag) {
         if (empty($tag)) {
             continue;
         }
         $tagID = Tag::test($tag, $languageID);
         if (!$tagID) {
             $tagID = Tag::insert($tag, $languageID);
         }
         $tagIDs[] = $tagID;
     }
     $tagIDs = array_unique($tagIDs);
     $sql = "INSERT INTO\twcf" . WCF_N . "_tag_to_object\n\t\t\t\t\t(objectID, tagID, taggableID, time, languageID)\n\t\t\tVALUES ";
     foreach ($tagIDs as $tagID) {
         $sql .= "(" . $object->getObjectID() . ", " . $tagID . ", " . $object->getTaggable()->getTaggableID() . ", " . TIME_NOW . ", " . $languageID . "),";
     }
     $sql = StringUtil::substring($sql, 0, StringUtil::length($sql) - 1);
     $result = WCF::getDB()->sendQuery($sql);
 }
 /**
  * Handles a request on the attachment edit form.
  * Deletes old or uploads new attachments.
  */
 public function handleRequest()
 {
     // delete uploaded attachments
     if (isset($_POST['delete']) && is_array($_POST['delete']) && count($_POST['delete'])) {
         // delete selected attachments
         $keys = array_keys($_POST['delete']);
         $this->delete(intval(array_shift($keys)));
     }
     // move uploaded attachments
     if (isset($_POST['attachmentListPositions']) && is_array($_POST['attachmentListPositions'])) {
         $positionChanged = false;
         $positions = ArrayUtil::toIntegerArray($_POST['attachmentListPositions']);
         foreach ($positions as $attachmentID => $position) {
             $attachmentID = intval($attachmentID);
             if (isset($this->attachments[$this->messageID][$attachmentID]) && $this->attachments[$this->messageID][$attachmentID]['showOrder'] != $position) {
                 $this->attachments[$this->messageID][$attachmentID]['showOrder'] = $position;
                 $sql = "UPDATE\twcf" . WCF_N . "_attachment\n\t\t\t\t\t\tSET\tshowOrder = " . $position . "\n\t\t\t\t\t\tWHERE\tattachmentID = " . $attachmentID;
                 WCF::getDB()->registerShutdownUpdate($sql);
                 $positionChanged = true;
             }
         }
         if ($positionChanged) {
             uasort($this->attachments[$this->messageID], array('self', 'compareAttachments'));
         }
     }
     // upload new attachments
     if (isset($_FILES) && count($_FILES) && isset($_FILES['upload'])) {
         // upload new attachments
         for ($x = 0, $y = count($_FILES['upload']['name']); $x < $y; $x++) {
             $attachment = array();
             $attachment['attachmentName'] = $_FILES['upload']['name'][$x];
             if ($attachment['attachmentName']) {
                 $attachment['attachment'] = $_FILES['upload']['tmp_name'][$x];
                 $attachment['attachmentSize'] = $_FILES['upload']['size'][$x];
                 $attachment['sha1Hash'] = sha1_file($attachment['attachment']);
                 $attachment['attachmentExtension'] = StringUtil::toLowerCase(StringUtil::substring($attachment['attachmentName'], StringUtil::lastIndexOf($attachment['attachmentName'], '.') + 1));
                 $attachment['fileType'] = $_FILES['upload']['type'][$x];
                 $attachment['isImage'] = 0;
                 if (strchr($attachment['fileType'], 'image')) {
                     // check mime
                     $attachment['fileType'] = 'application/octet-stream';
                     if (($imageData = @getImageSize($attachment['attachment'])) !== false) {
                         if (strchr($imageData['mime'], 'image')) {
                             $attachment['fileType'] = $imageData['mime'];
                             if ($attachment['fileType'] == 'image/bmp') {
                                 $attachment['fileType'] = 'image/x-ms-bmp';
                             }
                             $attachment['isImage'] = 1;
                         }
                     }
                 }
                 $attachment['showOrder'] = (isset($this->attachments[$this->messageID]) ? count($this->attachments[$this->messageID]) : 0) + 1;
                 if ($this->checkAttachment($attachment['attachment'], $attachment['attachmentName'] . ':' . $attachment['sha1Hash'], $attachment['attachmentName'], $attachment['attachmentSize'], $attachment['attachmentExtension'], $attachment['isImage'])) {
                     $attachment['messageID'] = $this->messageID;
                     $attachment['idHash'] = $this->idHash;
                     $attachment['userID'] = WCF::getUser()->userID;
                     $attachment['uploadTime'] = TIME_NOW;
                     $attachment['thumbnailType'] = '';
                     if ($this->setAttachment($attachment)) {
                         $this->attachmentHashes[count($this->attachmentHashes)] = $attachment['attachmentName'] . ':' . $attachment['sha1Hash'];
                         $attachment['fileTypeIcon'] = $this->getFileTypeIcon($attachment);
                         $this->attachments[$this->messageID][$attachment['attachmentID']] = $attachment;
                     }
                 }
             }
         }
     }
     $this->assign();
     if (count($this->errors)) {
         // throw user exception
         throw new UserInputException('attachments', $this->errors);
     }
 }
Пример #29
0
 /**
  * Returns a blowfish salt, e.g. $2a$07$usesomesillystringforsalt$
  * 
  * @param	string		$salt
  * @return	string
  */
 protected static function getSalt($salt)
 {
     $salt = StringUtil::substring($salt, 0, 22);
     return '$' . self::BCRYPT_TYPE . '$' . self::BCRYPT_COST . '$' . $salt;
 }
 /**
  * Returns the right file type icon for the given attachment.
  * 
  * @param	array		$data
  * @return	string
  */
 protected static function getFileTypeIcon($data)
 {
     // get file extension
     $extension = StringUtil::firstCharToUpperCase(StringUtil::toLowerCase(StringUtil::substring($data['attachmentName'], StringUtil::lastIndexOf($data['attachmentName'], '.') + 1)));
     // get file type icon
     if (file_exists(WCF_DIR . 'icon/fileTypeIcon' . $extension . 'M.png')) {
         return StyleManager::getStyle()->getIconPath('fileTypeIcon' . $extension . 'M.png');
     } else {
         foreach (self::$fileTypeGroups as $key => $group) {
             if (in_array($extension, $group)) {
                 return StyleManager::getStyle()->getIconPath('fileTypeIcon' . $key . 'M.png');
             }
         }
         return StyleManager::getStyle()->getIconPath('fileTypeIconDefaultM.png');
     }
 }