Esempio n. 1
0
 /**
  * Handles a [url] tag. Creates a link to another web page.
  *
  * @param	string	If tag has option, the displayable name. Else, the URL.
  * @param	string	If tag has option, the URL.
  *
  * @return	string	HTML representation of the tag.
  */
 function handle_bbcode_url($text, $link)
 {
     $rightlink = trim($link);
     if (empty($rightlink)) {
         // no option -- use param
         $rightlink = trim($text);
     }
     $rightlink = str_replace(array('`', '"', "'", '['), array('`', '"', ''', '['), $this->stripSmilies($rightlink));
     // remove double spaces -- fixes issues with wordwrap
     $rightlink = str_replace('  ', '', $rightlink);
     if (!preg_match('#^[a-z0-9]+(?<!about|javascript|vbscript|data):#si', $rightlink)) {
         $rightlink = "http://{$rightlink}";
     }
     if (!trim($link) or str_replace('  ', '', $text) == $rightlink) {
         $tmp = vB_String::unHtmlSpecialChars($rightlink);
         if (vB_String::vbStrlen($tmp) > 55 and $this->isWysiwyg() == false) {
             $text = vB_String::htmlSpecialCharsUni(vB_String::vbChop($tmp, 36) . '...' . substr($tmp, -14));
         } else {
             // under the 55 chars length, don't wordwrap this
             $text = str_replace('  ', '', $text);
         }
     }
     static $current_url, $current_host, $allowed, $friendlyurls = array();
     if (!isset($current_url)) {
         $current_url = @vB_String::parseUrl(self::$bbUrl);
     }
     $is_external = self::$urlNoFollow;
     if (self::$urlNoFollow) {
         if (!isset($current_host)) {
             $current_host = preg_replace('#:(\\d)+$#', '', self::$vBHttpHost);
             $allowed = preg_split('#\\s+#', self::$urlNoFollowWhiteList, -1, PREG_SPLIT_NO_EMPTY);
             $allowed[] = preg_replace('#^www\\.#i', '', $current_host);
             $allowed[] = preg_replace('#^www\\.#i', '', $current_url['host']);
         }
         $target_url = preg_replace('#^([a-z0-9]+:(//)?)#', '', $rightlink);
         foreach ($allowed as $host) {
             if (vB_String::stripos($target_url, $host) !== false) {
                 $is_external = false;
             }
         }
     }
     // standard URL hyperlink
     return "<a href=\"{$rightlink}\" target=\"_blank\"" . ($is_external ? ' rel="nofollow"' : '') . ">{$text}</a>";
 }
 /**
  * Create a url XML text block for one URL
  *
  * @param	string		The URL (not encoded) to add to the sitemap
  * @param 	int			The unix timestamp of the last modifictaion time of the data in UTC
  * @param 	double		The priority of the data from 0.1 to 1.0
  * @param 	boolean		Enable formatting of the output
  *
  * @return	string		Formatted escaped <url> wrapped text
  */
 protected function url_block($url, $lastmod, $pri = false, $formatting = false)
 {
     $l = "\n" . ($formatting ? "\t\t" : '');
     // Start block
     $data .= "\n" . ($formatting ? "\t" : '') . '<url>';
     $url = $url;
     $data .= $l . '<loc>' . htmlspecialchars_uni(vB_String::vbChop($url, 2048)) . '</loc>';
     //if we have a null or 0 lastmod let's not publish a bogus date.
     //also skip the change frequency.  These are optional and the default behavior of
     //the search engine is preferable to bad data
     if ($lastmod) {
         $data .= $l . '<lastmod>' . htmlspecialchars_uni(gmdate(DATE_W3C, $lastmod)) . '</lastmod>';
         $changefreq = '';
         if ($lastmod + 600 >= vB::getRequest()->getTimeNow()) {
             $changefreq = 'always';
         } else {
             if ($lastmod + 3600 >= vB::getRequest()->getTimeNow()) {
                 $changefreq = 'hourly';
             } else {
                 if ($lastmod + 86400 >= vB::getRequest()->getTimeNow()) {
                     $changefreq = 'daily';
                 } else {
                     if ($lastmod + 604800 >= vB::getRequest()->getTimeNow()) {
                         $changefreq = 'weekly';
                     } else {
                         if ($lastmod + 2629743 >= vB::getRequest()->getTimeNow()) {
                             $changefreq = 'monthly';
                         } else {
                             $changefreq = 'yearly';
                         }
                     }
                 }
             }
         }
         $data .= $l . '<changefreq>' . $changefreq . '</changefreq>';
     }
     if ($pri !== false) {
         $data .= $l . '<priority>' . floatval($pri) . '</priority>';
     }
     $data .= "\n" . ($formatting ? "\t" : '') . '</url>';
     return $data;
 }