fixing preg_replace / preg_match (UTF-8)
This commit is contained in:
71
config.php
71
config.php
@@ -479,7 +479,7 @@ class Databap extends PhpObject
|
||||
break;
|
||||
}
|
||||
$asResult = $this->oMySql->selectRows(array('select'=>array('id_message', 'nickname', 'message', 'led'), 'from'=>'messages', 'constraint'=>array('message'=>$sRegEx), 'constOpe'=>array('message'=>' REGEXP ')));
|
||||
$sPattern = '/(https?\:\/\/|www\.)[\S]+\.[a-zA-Z]{2,4}([\S]*)/i';
|
||||
$sPattern = '/(https?\:\/\/|www\.)[\S]+\.[a-zA-Z]{2,4}([\S]*)/ui';
|
||||
|
||||
foreach($asResult as $iLinkId=>$asRow)
|
||||
{
|
||||
@@ -825,7 +825,7 @@ class Databap extends PhpObject
|
||||
$sDescription = isset($asPost['description'])?$asPost['description']:'';
|
||||
|
||||
//Get docs
|
||||
$sImagePattern = '/c1_(?P<doc_id>\d+)_image_(?P<doc_info>\w+)/';
|
||||
$sImagePattern = '/c1_(?P<doc_id>\d+)_image_(?P<doc_info>\w+)/u';
|
||||
foreach($asPost as $sFormId=>$sValue)
|
||||
{
|
||||
preg_match($sImagePattern, $sFormId, $asMatches);
|
||||
@@ -1227,7 +1227,7 @@ class Databap extends PhpObject
|
||||
{
|
||||
$asResult = array('is_pm'=>false, 'chan_name'=>$sChanSafeName);
|
||||
|
||||
preg_match('/(?P<from>\d+)'.self::PM_SEP.'(?P<to>\d+)/', $sChanSafeName, $asMatch);
|
||||
preg_match('/(?P<from>\d+)'.self::PM_SEP.'(?P<to>\d+)/u', $sChanSafeName, $asMatch);
|
||||
if(!empty($asMatch))
|
||||
{
|
||||
$asResult['is_pm'] = true;
|
||||
@@ -1247,9 +1247,9 @@ class Databap extends PhpObject
|
||||
$iCompChan = array_search($sChanSafeName, array_map(array('self', 'getChanSafeName'), $asCompanies));
|
||||
$asPm = $this->isPmChan($sChanSafeName);
|
||||
|
||||
return $sChanSafeName!='' && //Empty channel name
|
||||
return $sChanSafeName!='' && //Empty channel name
|
||||
($iCompChan===false || $asUserInfo['company']==self::getCompanyFormat($asCompanies[$iCompChan])) && //Test Company Channel
|
||||
(!$asPm['is_pm'] || $iUserId==$asPm['from'] || $iUserId==$asPm['to']); //Test PM
|
||||
(!$asPm['is_pm'] || $iUserId==$asPm['from'] || $iUserId==$asPm['to']); //Test PM
|
||||
}
|
||||
|
||||
public function joinChan($sChanName, $bFirstConn=false, $asAttendees=array())
|
||||
@@ -1507,7 +1507,7 @@ class Databap extends PhpObject
|
||||
}
|
||||
elseif(mb_substr($sMessage, 0, 6) == '/mail ' && mb_strlen($sMessage)>6)
|
||||
{
|
||||
$sImagePattern = '/\/mail (?P<nickname>\w+) (?P<message>.*)/';
|
||||
$sImagePattern = '/\/mail (?P<nickname>\w+) (?P<message>.*)/u';
|
||||
preg_match($sImagePattern, $sMessage, $asMatches);
|
||||
|
||||
//Looking for user Id
|
||||
@@ -1744,13 +1744,15 @@ class Databap extends PhpObject
|
||||
}
|
||||
else //Normal message
|
||||
{
|
||||
//TODO Internal links
|
||||
|
||||
//Dynamic web link
|
||||
$asPatterns = array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si', '`((?<!//)(www\.\S+[[:alnum:]]/?))`si');
|
||||
$asPatterns = array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`sui', '`((?<!//)(www\.\S+[[:alnum:]]/?))`sui');
|
||||
$asLinks = array('<a href="$1" target="_blank">$1</a> ', '<a href="http://$1" target="_blank">$1</a>');
|
||||
$asMessages['messages'][$iMessageId]['message'] = preg_replace($asPatterns, $asLinks, $asMessages['messages'][$iMessageId]['message']);
|
||||
|
||||
//Dynamic chan link
|
||||
$asPatterns = '/(^|\s)#(\w*[^\s]+\w*)/';
|
||||
$asPatterns = '/(^|\s)#(\w*[^\s]+\w*)/u';
|
||||
$asLinks = '\1<span class="chan_link clickable">#<span class="chan_text">\2</span></span>';
|
||||
$asMessages['messages'][$iMessageId]['message'] = preg_replace($asPatterns, $asLinks, $asMessages['messages'][$iMessageId]['message']);
|
||||
}
|
||||
@@ -2215,9 +2217,23 @@ class Databap extends PhpObject
|
||||
return md5($sPass);
|
||||
}
|
||||
|
||||
public function resetChanSafeNames()
|
||||
{
|
||||
$iChanIdCol = MySqlManager::getId(MySqlManager::CHAN_TABLE);
|
||||
$asChans = $this->oMySql->selectRows(array('select'=>array($iChanIdCol, MySqlManager::getText(MySqlManager::CHAN_TABLE)), 'from'=>MySqlManager::CHAN_TABLE), true, $iChanIdCol);
|
||||
|
||||
$asResult = array();
|
||||
foreach($asChans as $iChanId=>$sChanName)
|
||||
{
|
||||
$asResult[$iChanId] = ($this->oMySql->updateRow(MySqlManager::CHAN_TABLE, $iChanId, array('safe_name'=>self::getChanSafeName($sChanName))) > 0)?'Fixed':'Not Fixed';
|
||||
}
|
||||
return MySqlManager::implodeAll($asResult, ' : ', "\n", 'Result reset ID channel ', '.');
|
||||
}
|
||||
|
||||
public static function getChanSafeName($sChanName)
|
||||
{
|
||||
$sChanSafeName = preg_replace('/[^a-z0-9]/', '_', mb_strtolower($sChanName));
|
||||
//TODO replace unsafe chars with unique id
|
||||
$sChanSafeName = preg_replace('/[^a-z0-9]/u', '_', mb_strtolower($sChanName));
|
||||
|
||||
//Sort PM chans
|
||||
$asPm = self::isPmChan($sChanSafeName);
|
||||
@@ -2418,8 +2434,8 @@ class Procedure extends PhpObject
|
||||
$this->sDescription = isset($asPost['description'])?$asPost['description']:'';
|
||||
|
||||
//Steps
|
||||
$sStepPattern = '/c(?P<step_id>\d+)_step_text/';
|
||||
$sImagePattern = '/c(?P<step_id>\d+)_(?P<image_id>\d+)_image_(?P<image_info>\w+)/';
|
||||
$sStepPattern = '/c(?P<step_id>\d+)_step_text/u';
|
||||
$sImagePattern = '/c(?P<step_id>\d+)_(?P<image_id>\d+)_image_(?P<image_info>\w+)/u';
|
||||
foreach($asPost as $sFormId=>$sValue)
|
||||
{
|
||||
//Step Text
|
||||
@@ -2706,7 +2722,6 @@ class SearchEngine extends PhpObject
|
||||
}
|
||||
$sWords = implode(self::KEYWORDS_SEPARATOR, $asWords);
|
||||
$sWords = mb_strtolower(str_replace("\n", self::KEYWORDS_SEPARATOR, $sWords));
|
||||
//TODO Fix char encoding
|
||||
$sWords = preg_replace('/(\W+)/u', self::KEYWORDS_SEPARATOR, $sWords); //remove all non-word characters
|
||||
|
||||
//Add / Modify search database
|
||||
@@ -2869,20 +2884,6 @@ class SearchEngine extends PhpObject
|
||||
}
|
||||
}
|
||||
|
||||
private function formatCode($sCode, $sPattern)
|
||||
{
|
||||
preg_match_all('/\n(.*)\n(.*)'.$sPattern.'(.*)\n(.*)\n/i', $sCode, $asMatches);
|
||||
if(!array_key_exists(0, $asMatches) || !is_array($asMatches[0]) || count($asMatches[0])==0)
|
||||
{
|
||||
$asResult = array(implode("\n", array_slice(explode("\n", $sCode), 0, 3))."\n[...]");
|
||||
}
|
||||
else
|
||||
{
|
||||
$asResult = $asMatches[0];
|
||||
}
|
||||
return $asResult;
|
||||
}
|
||||
|
||||
private function getParsedWords($sSearchWords)
|
||||
{
|
||||
return array_unique(array_filter(explode(' ', $sSearchWords), array($this, 'checkSearchedWords')));
|
||||
@@ -3084,28 +3085,28 @@ class Reader
|
||||
//Strings
|
||||
foreach($this->getWords('cString') as $sStringWord)
|
||||
{
|
||||
$sPattern = '/>([^<]*?)'.$sStringWord.'([^<]*?)'.$sStringWord.'/';
|
||||
$sPattern = '/>([^<]*?)'.$sStringWord.'([^<]*?)'.$sStringWord.'/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<span class="string">'.$sStringWord.'$2'.$sStringWord.'</span>', $sCode);
|
||||
}
|
||||
|
||||
//Part comment
|
||||
$sPattern = '/>([^<]*)\"\;([^<]*)\<\/span\>\<\/li\>/';
|
||||
$sPattern = '/>([^<]*)\"\;([^<]*)\<\/span\>\<\/li\>/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<span class="comment">"$2</span>', $sCode);
|
||||
|
||||
//Internal Url
|
||||
//$sPattern = '/>([^<]*)'.preg_quote($_GET['serv_name'], '/').'\/r\-([^<]*)/';
|
||||
$sPattern = '/>([^<\/]*)(http:\/\/'.$sSafeRexExServName.'|'.$sSafeRexExServName.')(c|code|p|proc|procedure)\-([^<]*)/';
|
||||
//$sPattern = '/>([^<]*)'.preg_quote($_GET['serv_name'], '/').'\/r\-([^<]*)/u';
|
||||
$sPattern = '/>([^<\/]*)(http:\/\/'.$sSafeRexExServName.'|'.$sSafeRexExServName.')(c|code|p|proc|procedure)\-([^<]*)/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<a class="share internal_link" href="'.$sServName.'$3-$4" target="_blank">$3 $4</a>', $sCode);
|
||||
|
||||
//Global / Main
|
||||
$sPattern = '/>\*\ \[('.implode('|', $this->getWords('wCodePart')).')\]/';
|
||||
$sPattern = '/>\*\ \[('.implode('|', $this->getWords('wCodePart')).')\]/u';
|
||||
$sCode = preg_replace($sPattern, '><span class="code_part">> $1</span>', $sCode);
|
||||
|
||||
//Core Words
|
||||
foreach($this->getWords('wCore') as $sCoreWord)
|
||||
{
|
||||
$sCoreWord = mb_strtolower($sCoreWord);
|
||||
$sPattern = '/>(([^<]*)([^\w&<]{1})|.{0})('.$sCoreWord.')([\W])/';
|
||||
$sPattern = '/>(([^<]*)([^\w&<]{1})|.{0})('.$sCoreWord.')([\W])/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<span class="core">$4</span>$5', $sCode);
|
||||
}
|
||||
//$sCoreWords = str_replace(' ', '\ ', implode('|', array_map('mb_strtolower', $this->getWords('wCore'))));
|
||||
@@ -3117,7 +3118,7 @@ class Reader
|
||||
$asOperators = array_unique(array_merge($this->getWords('cOperator'), $this->getWords('cCalculation')));
|
||||
foreach($asOperators as $sOpWord)
|
||||
{
|
||||
$sPattern = '/>([^<]*)\\'.$sOpWord.'/';
|
||||
$sPattern = '/>([^<]*)\\'.$sOpWord.'/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<span class="operator">'.$sOpWord.'</span>', $sCode);
|
||||
}
|
||||
//$sPattern = '/>([^<]*)['.implode(array_map('mb_strtolower', ($this->getWords('cOperator')))).']/';
|
||||
@@ -3126,7 +3127,7 @@ class Reader
|
||||
|
||||
//Numbers
|
||||
$sPreChar = '\\'.implode('\\', $this->getWords('cCalculation')).'\s';
|
||||
$sPattern = '/>((([^<]*)['.$sPreChar.']{1})|.{0})([0-9]+)([\W])/';
|
||||
$sPattern = '/>((([^<]*)['.$sPreChar.']{1})|.{0})([0-9]+)([\W])/u';
|
||||
$sCode = preg_replace($sPattern, '>$1<span class="number">$4</span>$5', $sCode);
|
||||
|
||||
return $sCode;
|
||||
@@ -3230,7 +3231,7 @@ class Mask extends PhpObject
|
||||
|
||||
private function setParts()
|
||||
{
|
||||
while(preg_match('/\<\!-- \[PART\] (?P<part>\S+) \[START\] --\>/', $this->sMask, $asMatch))
|
||||
while(preg_match('/\<\!-- \[PART\] (?P<part>\S+) \[START\] --\>/u', $this->sMask, $asMatch))
|
||||
{
|
||||
$sPartName = $asMatch['part'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user