/** * Verifies that the provided username is valid, and attempts to correct it if it is not valid * * @param string Username * * @return boolean Returns true if the username is valid, or has been corrected to be valid */ function verify_username(&$username) { // fix extra whitespace and invisible ascii stuff $username = trim(preg_replace('#[ \\r\\n\\t]+#si', ' ', strip_blank_ascii($username, ' '))); $username_raw = $username; if (strtolower(vB_String::getCharset()) !== 'utf-8') { // Following lines don't work for UTF-8. See VBV-3225. $username = vB_String::cleanUserName($username); } $username = str_replace(chr(0), '', $username); $username = trim($username); if (empty($this->existing['userid'])) { $this->existing['userid'] = false; } if (empty($this->existing['username'])) { if ($this->existing['userid']) { $userInfo = $this->assertor->getRow('user', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'userid' => $this->existing['userid'])); $this->existing['username'] = $userInfo['username']; } else { $this->existing['username'] = false; } } // check length only if it's a new user or if the username changed if ($this->existing['username'] === false or $username != $this->existing['username']) { $length = iconv_strlen($username, vB_String::getCharset()); // We shouldn't use vB_String::vbStrlen() as it will count &xxx; as one character. if ($length == 0) { // check for empty string $this->error('fieldmissing_username'); return false; } else { if ($length < $this->options['minuserlength'] and !$this->adminoverride) { // name too short $this->error('usernametooshort', $this->options['minuserlength']); return false; } else { if ($length > $this->options['maxuserlength'] and !$this->adminoverride) { // name too long $this->error('usernametoolong', $this->options['maxuserlength']); return false; } else { if (preg_match('/(?<!&#[0-9]{3}|&#[0-9]{4}|&#[0-9]{5});/', $username)) { // name contains semicolons $this->error('username_contains_semi_colons'); return false; } else { if ($username != fetch_censored_text($username) and !$this->adminoverride) { // name contains censored words $this->error('censorfield'); return false; } } } } } /*else if (vB_String::htmlSpecialCharsUni($username_raw) != $this->existing['username'] AND $user = $this->dbobject->query_first(" SELECT userid, username FROM " . TABLE_PREFIX . "user WHERE userid != " . intval($this->existing['userid']) . " AND ( username = '******' OR username = '******' ) "))*/ } if ((empty($this->existing['username']) or vB_String::htmlSpecialCharsUni($username_raw) != $this->existing['username']) and $user = $this->assertor->getRow('getUsernameAndId', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'userid' => intval($this->existing['userid']), 'username' => vB_String::htmlSpecialCharsUni($username), 'username_raw' => vB_String::htmlSpecialCharsUni($username_raw)))) { // name is already in use if ($this->error_handler == vB_DataManager_Constants::ERRTYPE_CP) { $this->error('usernametaken_edit_here', vB_String::htmlSpecialCharsUni($username), $this->session->get('sessionurl'), $user['userid']); } else { $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), $this->session->get('sessionurl')); } return false; } if (!empty($this->options['usernameregex']) and !$this->adminoverride) { // check for regex compliance if (!preg_match('#' . str_replace('#', '\\#', $this->options['usernameregex']) . '#siU', $username)) { $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), vB::getCurrentSession()->get('sessionurl')); return false; } } if (!empty($this->existing['username']) and (vB_String::htmlSpecialCharsUni($username_raw) != $this->existing['username'] and !$this->adminoverride and $this->options['usernamereusedelay'] > 0)) { require_once DIR . '/includes/class_userchangelog.php'; $userchangelog = new vB_UserChangeLog($this->registry); $userchangelog->set_execute(true); $userchangelog->set_just_count(true); if ($userchangelog->sql_select_by_username(vB_String::htmlSpecialCharsUni($username), vB::getRequest()->getTimeNow() - $this->options['usernamereusedelay'] * 86400)) { $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), vB::getCurrentSession()->get('sessionurl')); return false; } } if ((empty($this->existing['username']) or vB_String::htmlSpecialCharsUni($username_raw) != $this->existing['username']) and !empty($this->options['illegalusernames']) and !$this->adminoverride) { // check for illegal username $usernames = preg_split('/[ \\r\\n\\t]+/', $this->options['illegalusernames'], -1, PREG_SPLIT_NO_EMPTY); foreach ($usernames as $val) { if (strpos(strtolower($username), strtolower($val)) !== false) { // wierd error to show, but hey... $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), vB::getCurrentSession()->get('sessionurl')); return false; } } } $unregisteredphrases = $this->assertor->getRows('phrase', array('varname' => 'unregistered', 'fieldname' => 'global')); //while ($unregisteredphrase = $this->registry->db->fetch_array($unregisteredphrases)) foreach ($unregisteredphrases as $unregisteredphrase) { if (strtolower($unregisteredphrase['text']) == strtolower($username) or strtolower($unregisteredphrase['text']) == strtolower($username_raw)) { //$this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), vB::getCurrentSession()->get('sessionurl')); $this->error('usernametaken', vB_String::htmlSpecialCharsUni($username), $this->session->get('sessionurl')); return false; } } // if we got here, everything is okay $username = vB_String::htmlSpecialCharsUni($username); // remove any trailing HTML entities that will be cut off when we stick them in the DB. // if we don't do this, the affected person won't be able to login, be banned, etc... $column_info = $this->assertor->getRow('getColumnUsername', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'field' => 'username')); if (preg_match('#char\\((\\d+)\\)#i', $column_info['Type'], $match) and $match[1] > 0) { $username = preg_replace('/&([a-z0-9#]*)$/i', '', substr($username, 0, $match[1])); } $username = trim($username); return true; }
public function getUrl() { $bburl = vB::getDatastore()->getOption('bburl'); $url = $bburl . '/' . $this->prefix . '/' . $this->arguments['file'] . '.php'; if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl() { // the regex contains the url $url = '/' . $this->prefix . '/' . $this->arguments['tab']; if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl() { //bburl isn't correct as it will create a link to core rather than admincp. This happens to work //for admincp for the time being, but is the wrong url. // $bburl = vB::getDatastore()->getOption('bburl'); // return $bburl . '/' . $this->prefix . '/' . $this->arguments['file'] . '.php'; //user the header hack instead. $url = vB::getDatastore()->getOption('frontendurl') . '/' . $this->prefix . '/' . $this->arguments['file'] . '.php'; if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl() { if (empty($this->arguments['username'])) { $userInfo = vB_Api::instanceInternal('user')->fetchProfileInfo($this->arguments['userid']); $this->arguments['username'] = $userInfo['username']; } // the regex contains the url $url = '/' . $this->prefix . '/' . $this->arguments['userid'] . '-' . vB_String::getUrlIdent($this->arguments['username']) . '/' . $this->arguments['tab']; if (isset($this->arguments['pagenum']) and is_numeric($this->arguments['pagenum']) and $this->arguments['pagenum'] > 1) { $url .= '/page' . intval($this->arguments['pagenum']); } if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl() { $cache = vB_Cache::instance(vB_Cache::CACHE_FAST); $hashKey = 'vbRouteURLIndent_' . $this->arguments['nodeid']; $urlident = $cache->read($hashKey); if (empty($urlident)) { $node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']); $urlident = $node['urlident']; $cache->write($hashKey, $urlident); } elseif (is_array($urlident) and !empty($urlident['urlident'])) { $urlident = $urlident['urlident']; } $url = '/album/' . $this->arguments['nodeid'] . '-' . $urlident; if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
function print_apioutput($data) { global $VB_API_REQUESTS; // We need to convert $data charset if we're not using UTF-8 if (vB_String::getCharset() != 'UTF-8') { $data = vB_String::toCharset($data, vB_String::getCharset(), 'UTF-8'); } //If this is IE9 we need to send type "text/html". //Yes, we know that's not the standard. if (!headers_sent() and isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) { header('Content-type: text/plain; charset=UTF-8'); } else { header('Content-type: application/json; charset=UTF-8'); } // IE will cache ajax requests, and we need to prevent this - VBV-148 header('Cache-Control: max-age=0,no-cache,no-store,post-check=0,pre-check=0'); header('Expires: Sat, 1 Jan 2000 01:00:00 GMT'); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Pragma: no-cache"); $output = json_encode($data); //we can get here because we failed to create the session so let's make sure its //a proper API session (hack alert). $currentSession = vB::getCurrentSession(); $apiclient = array(); if ($currentSession instanceof vB_Session_Api) { $apiclient = $currentSession->getApiClient(); } $vboptions = vB::getDatastore()->getValue('options'); if ($apiclient and !in_array($VB_API_REQUESTS['api_m'], array('user.login', 'user.logout'))) { $sign = md5($output . $apiclient['apiaccesstoken'] . $apiclient['apiclientid'] . $apiclient['secret'] . $vboptions['apikey']); @header('Authorization: ' . $sign); } echo $output; exit; }
public function getUrl() { $url = "/{$this->prefix}/" . $this->actionInternal . $this->actionClass->getUrlParameters(); if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl() { if (empty($this->arguments['title'])) { $node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']); if (empty($node) or !empty($node['errors'])) { return FALSE; } if ($node['urlident']) { $this->arguments['title'] = $node['urlident']; } else { $this->arguments['title'] = vB_String::getUrlIdent($node['title']); } } if (empty($this->arguments['userid'])) { if (!isset($node['nodeid'])) { $node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']); } if ($node['setfor']) { $user = vB_User::fetchUserinfo($node['setfor']); $this->arguments['userid'] = $user['userid']; $this->arguments['username'] = $user['username']; } } $url = '/member/' . $this->arguments['userid'] . '-' . vB_String::getUrlIdent($this->arguments['username']) . '/visitormessage/' . $this->arguments['nodeid'] . '-' . vB_String::vBStrToLower(vB_String::htmlSpecialCharsUni(str_replace(' ', '-', $this->arguments['title']))); if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl($node = false) { if (isset($this->arguments['customUrl']) and $this->arguments['customUrl']) { $result = '/' . $this->prefix; } else { $cache = vB_Cache::instance(vB_Cache::CACHE_FAST); // looking up cache for the node $hashKey = 'vbRouteURLIndent_' . $this->arguments['nodeid']; $urlident = $cache->read($hashKey); if (empty($urlident) or !is_array($urlident)) { $urlident = array(); if (!empty($this->matches['starter']) && isset($node['urlident'])) { $node['starter'] = $this->matches['starter']; $node['urlident'] = $this->matches['urlident']; } else { $node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']); } $mainConversationId = $node['starter']; if ($mainConversationId and $mainConversationId != $this->arguments['nodeid']) { $mainConversation = vB_Library::instance('node')->getNodeBare($mainConversationId); $urlident['urlident'] = $mainConversation['urlident']; $urlident['nodeid'] = $mainConversationId; } else { $urlident['urlident'] = $node['urlident']; $urlident['nodeid'] = $this->arguments['nodeid']; } $cache->write($hashKey, $urlident, 1440, array('routeChg_' . $this->arguments['nodeid'], 'nodeChg_' . $this->arguments['nodeid'])); } $channelUrl = $this->getChannelURL($this->arguments['channelid'], $this->matches); // remove trailing / (special case, non-default home page with a conversation route) $channelUrl = rtrim($channelUrl, '/'); $result = $channelUrl . '/' . $urlident['nodeid'] . '-' . $urlident['urlident']; } // putting /contentpageX before /pageX if (isset($this->arguments['contentpagenum']) and is_numeric($this->arguments['contentpagenum']) and $this->arguments['contentpagenum'] > 1) { $result .= '/contentpage' . intval($this->arguments['contentpagenum']); } if (isset($this->arguments['pagenum']) and is_numeric($this->arguments['pagenum']) and $this->arguments['pagenum'] > 1) { $result .= '/page' . intval($this->arguments['pagenum']); } if (strtolower(vB_String::getCharset()) != 'utf-8') { $result = vB_String::encodeUtf8Url($result); } return $result; }
public function getUrl() { // do not append '/' if prefix is empty string (happens for home page) $url = $this->prefix === '' ? '' : '/' . $this->prefix; if (isset($this->arguments['pagenum']) and is_numeric($this->arguments['pagenum']) and $this->arguments['pagenum'] > 1) { $url .= '/page' . intval($this->arguments['pagenum']); } if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
/** * Adds the URLs to $this->content * * @param int forumdid to start at * @param int perpage limit defaults to 30000 */ public function generate_sitemap($startat = 0, $perpage = 30000) { $tempFilename = $this->sitemap_path . '/' . $this->tempfile; $fp = @fopen($tempFilename, 'a'); if ($fp === false) { $this->errors[] = 'Error opening temporary file : ' . $tempFilename; return false; } $startersQry = vB::getDbAssertor()->assertQuery('vBAdminCP:getGuestVisibleNodes', array('startat' => $startat, 'perpage' => $perpage + 1)); // todo: why did we need the below loop? Do we have duplicate rows in the query or something? $starters = array(); foreach ($startersQry as $node) { $args = unserialize($node['arguments']); $starters[$node['nodeid']] = array('routeid' => $node['routeid'], 'nodeid' => $node['nodeid'], 'lastpost' => $node['lastcontent'], 'urlident' => $node['urlident'], 'prefix' => $node['prefix'], 'customUrl' => !empty($args['customUrl'])); } $this->has_more = false; foreach ($starters as $node) { // is this one part of the next batch? if ($this->pagecount + 1 > $perpage) { $this->has_more = true; break; } $this->pagecount++; $this->lastid = $node['nodeid']; /* * vB5_Route::buildUrl was having some memory issues, probably due to hundreds of route instances being * created etc. So below is a cheap way to generate the full URL. This has no concept of query strings * or anchor tags, but that's okay since we're only dealing with topic STARTERS here (so no page# needed.) * In short this is an extremely simplified version of vB5_Route_Conversation's buildUrl() */ if ($node['customUrl']) { $url = vB::getDatastore()->getOption('frontendurl') . '/' . trim($node['prefix'], '/'); } else { $url = vB::getDatastore()->getOption('frontendurl') . '/' . trim($node['prefix'], '/') . '/' . $node['nodeid'] . '-' . $node['urlident']; } if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } $content = $this->url_block($url, $node['lastpost'], $this->get_effective_priority('node', $node['nodeid'])); fwrite($fp, $content); } fclose($fp); // Return the amout done return $this->pagecount; }
public function getUrl() { if (!empty($this->arguments['userid']) and !empty($this->arguments['username'])) { $result = '/' . $this->prefix . '/' . $this->arguments['userid'] . '-' . vB_String::getUrlIdent($this->arguments['username']); } else { return false; } // append the tab to URL only if it's a valid tab. if (isset($this->arguments['tab'])) { if (isset(self::$availableTabs[$this->arguments['tab']])) { $result .= '/' . $this->arguments['tab']; if (isset(self::$doNotIndexTabs[$this->arguments['tab']])) { $this->arguments['noindex'] = true; } // append the page number if pagenum argument is set & if a tab with pagination is set if (isset($this->arguments['pagenum']) and is_numeric($this->arguments['pagenum']) and $this->arguments['pagenum'] > 1 and isset(self::$tabsWithPagination[$this->arguments['tab']])) { $result .= '/page' . intval($this->arguments['pagenum']); } } else { // invalid tab, unset it unset($this->arguments['tab']); } } if (strtolower(vB_String::getCharset()) != 'utf-8') { $result = vB_String::encodeUtf8Url($result); } return $result; }
/** Returns the canonical url * * **/ public function getCanonicalUrl() { $url = '/' . self::DEFAULT_PREFIX; if (!empty($this->arguments['nodeid'])) { if (empty($this->title)) { $node = vB_Library::instance('node')->getNodeBare($this->arguments['nodeid']); $this->title = self::prepareTitle($node['title']); } $url .= '/' . $this->arguments['nodeid'] . '-' . $this->title; } $url .= '/' . $this->arguments[self::$actionKey] . '/' . $this->arguments['action2']; if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
/** * This checks whether the a username is available and valid * * @param username $ * @return bool */ public function checkUsername($candidate) { $cleaner = vB::get_cleaner(); $candidate = $cleaner->clean($candidate, vB_Cleaner::TYPE_STR); $options = vB::getDatastore()->getValue('options'); if (empty($candidate)) { throw new vB_Exception_Api('invalid_username_specified'); } $usernameLen = iconv_strlen($candidate, vB_String::getCharset()); // We shouldn't use vB_String::vbStrlen() as it will count &xxx; as one character. if ($usernameLen < $options['minuserlength']) { throw new vB_Exception_Api('invalid_username_specified_minlength_x', array($options['minuserlength'])); } if ($usernameLen > $options['maxuserlength']) { throw new vB_Exception_Api('invalid_username_specified_maxlength_x', array($options['maxuserlength'])); } if (!empty($options['usernameregex'])) { // check for regex compliance if (!preg_match('#' . str_replace('#', '\\#', $options['usernameregex']) . '#siU', $candidate)) { throw new vB_Exception_Api('usernametaken', array(vB_String::htmlSpecialCharsUni($candidate), vB::getCurrentSession()->get('sessionurl'))); } } if (!empty($options['illegalusernames'])) { // check for illegal username $usernames = preg_split('/[ \\r\\n\\t]+/', $options['illegalusernames'], -1, PREG_SPLIT_NO_EMPTY); foreach ($usernames as $val) { if (strpos(strtolower($candidate), strtolower($val)) !== false) { // wierd error to show, but hey... throw new vB_Exception_Api('usernametaken', array(vB_String::htmlSpecialCharsUni($candidate), vB::getCurrentSession()->get('sessionurl'))); } } } $candidate = trim(preg_replace('#[ \\r\\n\\t]+#si', ' ', strip_blank_ascii($candidate, ' '))); $check = vB::getDbAssertor()->getRow('user', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'username' => $candidate)); if (isset($check['errors'])) { throw new vB_Exception_Api($check['errors'][0][0]); } else { if (!empty($check)) { throw new vB_Exception_Api('user_name_x_already_in_use_choose_different_name', array($candidate)); } } return true; }
/** * Used by parsePage() to extract the data to return * * @param array|string The return value of the vB_Url call * @param array The URL parts * * @return array Array containing: * 'title' => $title, * 'meta' => $meta, * 'images' => (array) $imgurls, */ protected function extractData($data, $urlparts) { if (!is_array($data)) { $data = array('body' => $data); } if (!$data['body']) { // Don't throw exception here. Just return empty results return array('title' => '', 'meta' => '', 'images' => null); } $charset = false; // Check if we have content-type header and try to get charset from it if (!empty($data['headers']['content-type'])) { $charset = substr($data['headers']['content-type'], strrpos($data['headers']['content-type'], '=') + 1); if ($charset) { $data['body'] = '<?xml encoding="' . $charset . '">' . $data['body']; } } $dom = new DOMDocument(); libxml_use_internal_errors(true); if (!$dom->loadHTML($data['body'])) { // Invalid HTML. return empty results. return array('title' => '', 'meta' => '', 'images' => null); } // Get title $title = ''; if ($titlenode = $dom->getElementsByTagName("title")->item(0)) { $title = $titlenode->nodeValue; } if (!$title) { // If no title, try to get meta open graph title try { foreach ($dom->getElementsByTagName("meta") as $metanode) { if ($metanode->hasAttributes()) { $metaItem = $metanode->attributes->getNamedItem('property'); if (!empty($metaItem)) { if ($metaItem->nodeValue == 'og:title') { $title = $metanode->attributes->getNamedItem('content')->nodeValue; break; } } } } } catch (exception $e) { } //nothing we can do- just continue; } // Get Meta $meta = ''; foreach ($dom->getElementsByTagName("meta") as $metanode) { if ($metanode->hasAttributes()) { try { $metaItem = $metanode->attributes->getNamedItem('name'); if (!empty($metaItem)) { if ($metaItem->nodeValue == 'description') { $meta = $metanode->attributes->getNamedItem('content')->nodeValue; break; } } } catch (exception $e) { } //nothing we can do- just continue; } } if (!$meta) { // If no meta description, try to get meta open graph og:description try { foreach ($dom->getElementsByTagName("meta") as $metanode) { if ($metanode->hasAttributes()) { $metaItem = $metanode->attributes->getNamedItem('property'); if (!empty($metaItem)) { if ($metaItem->nodeValue == 'og:description') { $meta = $metanode->attributes->getNamedItem('content')->nodeValue; break; } } } } } catch (exception $e) { } //nothing we can do- just continue; } if (!$meta) { // If no meta og:description, try to get meta keywords try { foreach ($dom->getElementsByTagName("meta") as $metanode) { if ($metanode->hasAttributes()) { $metaItem = $metanode->attributes->getNamedItem('name'); if (!empty($metaItem)) { if ($metaItem->nodeValue == 'keywords') { $meta = $metanode->attributes->getNamedItem('content')->nodeValue; break; } } } } } catch (exception $e) { } //nothing we can do- just continue; } // Get baseurl $baseurl = ''; if ($basenode = $dom->getElementsByTagName("base")->item(0)) { if ($basenode->hasAttributes()) { $item = $basenode->attributes->getNamedItem('href'); if (!empty($item)) { $baseurl = $item->nodeValue; } } } if (!$baseurl) { // We assume that the baseurl is domain+path of $url $baseurl = $urlparts['scheme'] . '://'; if (!empty($urlparts['user'])) { $baseurl .= $urlparts['user'] . ':' . $urlparts['pass'] . '@'; } $baseurl .= $urlparts['host']; if (!empty($urlparts['port'])) { $baseurl .= ':' . $urlparts['port']; } if (!empty($urlparts['path'])) { $path = $urlparts['path']; // Remove filename from path $pos = strrpos($path, '/'); if ($pos !== false and $pos !== 0) { $path = substr($path, 0, $pos); } $baseurl .= $path; } } $baseurl = rtrim($baseurl, '/'); // Get images $imgurls = array(); // We need to add og:image if exists try { foreach ($dom->getElementsByTagName("meta") as $metanode) { if ($metanode->hasAttributes()) { $metaItem = $metanode->attributes->getNamedItem('property'); if (!empty($metaItem)) { if ($metaItem->nodeValue == 'og:image') { $imgurls[] = $metanode->attributes->getNamedItem('content')->nodeValue; // Don't break here. Because Open Graph allows multiple og:image tags } } } } } catch (exception $e) { } //nothing we can do- just continue; foreach ($dom->getElementsByTagName("img") as $imgnode) { if ($imgnode->hasAttributes() && $imgnode->attributes->getNamedItem('src')) { if ($imgurl = $imgnode->attributes->getNamedItem('src')->nodeValue) { $imgurls[] = $imgurl; } } } foreach ($imgurls as &$imgurl) { if (!$imgurl) { unset($imgurl); } // protocol-relative URL (//domain.com/logo.png) if (preg_match('|^//[a-z0-9-]+(\\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $imgurl)) { // We add url scheme to the url $imgurl = $urlparts['scheme'] . ':' . $imgurl; } // relative url? make it absolute $imgurl = $this->rel2abs($imgurl, $baseurl); } $imgurls = array_unique($imgurls); // sendAsJSON will convert it to UTF-8, so if the board is in ISO-8859-1, it'll double-encode & break multibyte UTF-8 characters. // So we encode it from detected charset to the board's charset, & convert it if necessary. // If charset is not detected, then do not convert (TODO: automatically detect charset if not set in header) $boardCharset = vB_String::getCharset(); if ($charset and strtolower($charset) !== strtolower($boardCharset)) { $title = vB_String::toCharset($title, $charset, $boardCharset); $meta = vB_String::toCharset($meta, $charset, $boardCharset); $imgurls = vB_String::toCharset($imgurls, $charset, $boardCharset); } return array('title' => $title, 'meta' => $meta, 'images' => $imgurls); }
/** * Converts a string to the desired character set if possible. Wrapper for the callback * @param string * @param string Character to convert to * * @return string Character in desired character set or as an HTML entity */ public static function convertStringToCurrentCharset($string) { return preg_replace_callback('/&#([0-9]+);/i', function ($matches) { return vB_String::convertUnicodeCharToCharset($matches[1], vB_String::getCharset()); }, $string); }
public function getUrl() { $url = '/' . $this->prefix; if (isset($this->arguments['pagenum']) and is_numeric($this->arguments['pagenum']) and $this->arguments['pagenum'] > 1) { $url .= '/page' . intval($this->arguments['pagenum']); } if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }
public function getUrl() { $url = $this->getCanonicalUrl(); if (strtolower(vB_String::getCharset()) != 'utf-8') { $url = vB_String::encodeUtf8Url($url); } return $url; }