/**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (empty(URLParser::$text)) {
         return;
     }
     // search pattern for finding all urls without title
     $urlPattern = "~\\[url\\](.*?)\\[/url\\]~i";
     URLParser::$text = preg_replace_callback($urlPattern, array($this, 'makeURLTitle'), URLParser::$text);
 }
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (empty(URLParser::$text)) {
         return;
     }
     // reset data
     $this->postIDToThreadID = $this->threads = array();
     $threadIDs = $postIDs = array();
     // get page urls
     $pageURLs = URLBBCode::getPageURLs();
     $pageURLs = '(?:' . implode('|', array_map(create_function('$a', 'return preg_quote($a, \'~\');'), $pageURLs)) . ')';
     // build search pattern
     $threadIDPattern = "~\\[url\\](" . $pageURLs . "/?" . $this->threadURLPattern . ".*?)\\[/url\\]~i";
     $postIDPattern = "~\\[url\\](" . $pageURLs . "/?" . $this->postURLPattern . ".*?)\\[/url\\]~i";
     // find thread ids
     if (preg_match_all($threadIDPattern, URLParser::$text, $matches)) {
         $threadIDs = $matches[2];
     }
     // find post ids
     if (preg_match_all($postIDPattern, URLParser::$text, $matches)) {
         $postIDs = $matches[2];
     }
     if (count($threadIDs) > 0 || count($postIDs) > 0) {
         // get thread ids
         if (count($postIDs)) {
             $sql = "SELECT\tpostID, threadID\n\t\t\t\t\tFROM \twbb" . WBB_N . "_post\n\t\t\t\t\tWHERE \tpostID IN (" . implode(",", $postIDs) . ")";
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 $this->postIDToThreadID[$row['postID']] = $row['threadID'];
                 $threadIDs[] = $row['threadID'];
             }
         }
         // get accessible boards
         require_once WBB_DIR . 'lib/data/board/Board.class.php';
         $boardIDs = Board::getAccessibleBoards();
         if (empty($boardIDs)) {
             return;
         }
         // get topics and prefixes :)
         if (count($threadIDs)) {
             // remove duplicates
             $threadIDs = array_unique($threadIDs);
             $sql = "SELECT\tthreadID, prefix, topic\n\t\t\t\t\tFROM \twbb" . WBB_N . "_thread\n\t\t\t\t\tWHERE \tthreadID IN (" . implode(",", $threadIDs) . ")\n\t\t\t\t \t\tAND boardid IN (0" . $boardIDs . ")";
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 $this->threads[$row['threadID']] = $row;
             }
         }
         if (count($this->threads) > 0) {
             // insert topics
             URLParser::$text = preg_replace_callback($threadIDPattern, array($this, 'buildThreadURLCallback'), URLParser::$text);
             URLParser::$text = preg_replace_callback($postIDPattern, array($this, 'buildPostURLCallback'), URLParser::$text);
         }
     }
 }
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (!MODULE_CONTEST || empty(URLParser::$text)) {
         return;
     }
     // reset data
     $this->classes = $this->entries = array();
     $classIDArray = $contestIDArray = array();
     // get page urls
     $pageURLs = URLBBCode::getPageURLs();
     $pageURLs = '(?:' . implode('|', array_map('preg_quote', $pageURLs)) . ')';
     // build search pattern
     $classIDPattern = "!\\[url\\](" . $pageURLs . "/?" . $this->classURLPattern . ".*?)\\[/url\\]!i";
     $contestIDPattern = "!\\[url\\](" . $pageURLs . "/?" . $this->entryURLPattern . ".*?)\\[/url\\]!i";
     // find class ids
     if (preg_match_all($classIDPattern, URLParser::$text, $matches)) {
         $classIDArray = $matches[2];
     }
     // find entry ids
     if (preg_match_all($contestIDPattern, URLParser::$text, $matches)) {
         $contestIDArray = $matches[2];
     }
     // get classes
     if (count($classIDArray) > 0) {
         // remove duplicates
         $classIDArray = array_unique($classIDArray);
         $sql = "SELECT\tclassID, title\n\t\t\t\tFROM \twcf" . WCF_N . "_contest_class\n\t\t\t\tWHERE \tclassID IN (" . implode(",", $classIDArray) . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $this->classes[$row['classID']] = $row['title'];
         }
         if (count($this->classes) > 0) {
             // insert classes
             URLParser::$text = preg_replace_callback($classIDPattern, array($this, 'buildClassURLTagCallback'), URLParser::$text);
         }
     }
     // get entries
     if (count($contestIDArray) > 0) {
         // remove duplicates
         $contestIDArray = array_unique($contestIDArray);
         $sql = "SELECT\tcontestID, subject\n\t\t\t\tFROM \twcf" . WCF_N . "_contest\n\t\t\t\tWHERE \tcontestID IN (" . implode(",", $contestIDArray) . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $this->entries[$row['contestID']] = $row['subject'];
         }
         if (count($this->entries) > 0) {
             // insert classes
             URLParser::$text = preg_replace_callback($contestIDPattern, array($this, 'buildEntryURLTagCallback'), URLParser::$text);
         }
     }
 }
    /**
     * Adds the url and email bbcode tags in a text automatically.
     */
    public static function parse($text)
    {
        self::$text = $text;
        // cache codes
        self::$text = self::cacheCodes(self::$text);
        // call event
        EventHandler::fireAction('URLParser', 'shouldParse');
        // define pattern
        $urlPattern = '~(?<!\\B|"|\'|=|/|\\]|,|\\?)
			(?:						# hostname
				(?:ftp|https?)://' . self::$illegalChars . '(?:\\.' . self::$illegalChars . ')*
				|
				www\\.(?:' . self::$illegalChars . '\\.)+
				(?:[a-z]{2,4}(?=\\b))
			)

			(?::\\d+)?					# port

			(?:
				/
				[^!.,?;"\'<>()\\[\\]{}\\s]*
				(?:
					[!.,?;(){}]+ [^!.,?;"\'<>()\\[\\]{}\\s]+
				)*
			)?
			~ix';
        $emailPattern = '~(?<!\\B|"|\'|=|/|\\]|,|:)
			(?:)
			\\w+(?:[\\.\\-]\\w+)*
			@
			(?:' . self::$illegalChars . '\\.)+		# hostname
			(?:[a-z]{2,4}(?=\\b))
			(?!"|\'|\\[|\\-|\\.[a-z])
			~ix';
        // add url tags
        self::$text = preg_replace($urlPattern, '[url]\\0[/url]', self::$text);
        if (StringUtil::indexOf(self::$text, '@') !== false) {
            self::$text = preg_replace($emailPattern, '[email]\\0[/email]', self::$text);
        }
        // call event
        EventHandler::fireAction('URLParser', 'didParse');
        if (count(self::$cachedCodes) > 0) {
            // insert cached codes
            self::$text = self::insertCachedCodes(self::$text);
        }
        return self::$text;
    }