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;
|
break;
|
||||||
}
|
}
|
||||||
$asResult = $this->oMySql->selectRows(array('select'=>array('id_message', 'nickname', 'message', 'led'), 'from'=>'messages', 'constraint'=>array('message'=>$sRegEx), 'constOpe'=>array('message'=>' REGEXP ')));
|
$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)
|
foreach($asResult as $iLinkId=>$asRow)
|
||||||
{
|
{
|
||||||
@@ -825,7 +825,7 @@ class Databap extends PhpObject
|
|||||||
$sDescription = isset($asPost['description'])?$asPost['description']:'';
|
$sDescription = isset($asPost['description'])?$asPost['description']:'';
|
||||||
|
|
||||||
//Get docs
|
//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)
|
foreach($asPost as $sFormId=>$sValue)
|
||||||
{
|
{
|
||||||
preg_match($sImagePattern, $sFormId, $asMatches);
|
preg_match($sImagePattern, $sFormId, $asMatches);
|
||||||
@@ -1227,7 +1227,7 @@ class Databap extends PhpObject
|
|||||||
{
|
{
|
||||||
$asResult = array('is_pm'=>false, 'chan_name'=>$sChanSafeName);
|
$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))
|
if(!empty($asMatch))
|
||||||
{
|
{
|
||||||
$asResult['is_pm'] = true;
|
$asResult['is_pm'] = true;
|
||||||
@@ -1247,9 +1247,9 @@ class Databap extends PhpObject
|
|||||||
$iCompChan = array_search($sChanSafeName, array_map(array('self', 'getChanSafeName'), $asCompanies));
|
$iCompChan = array_search($sChanSafeName, array_map(array('self', 'getChanSafeName'), $asCompanies));
|
||||||
$asPm = $this->isPmChan($sChanSafeName);
|
$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
|
($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())
|
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)
|
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);
|
preg_match($sImagePattern, $sMessage, $asMatches);
|
||||||
|
|
||||||
//Looking for user Id
|
//Looking for user Id
|
||||||
@@ -1744,13 +1744,15 @@ class Databap extends PhpObject
|
|||||||
}
|
}
|
||||||
else //Normal message
|
else //Normal message
|
||||||
{
|
{
|
||||||
|
//TODO Internal links
|
||||||
|
|
||||||
//Dynamic web link
|
//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>');
|
$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']);
|
$asMessages['messages'][$iMessageId]['message'] = preg_replace($asPatterns, $asLinks, $asMessages['messages'][$iMessageId]['message']);
|
||||||
|
|
||||||
//Dynamic chan link
|
//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>';
|
$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']);
|
$asMessages['messages'][$iMessageId]['message'] = preg_replace($asPatterns, $asLinks, $asMessages['messages'][$iMessageId]['message']);
|
||||||
}
|
}
|
||||||
@@ -2215,9 +2217,23 @@ class Databap extends PhpObject
|
|||||||
return md5($sPass);
|
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)
|
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
|
//Sort PM chans
|
||||||
$asPm = self::isPmChan($sChanSafeName);
|
$asPm = self::isPmChan($sChanSafeName);
|
||||||
@@ -2418,8 +2434,8 @@ class Procedure extends PhpObject
|
|||||||
$this->sDescription = isset($asPost['description'])?$asPost['description']:'';
|
$this->sDescription = isset($asPost['description'])?$asPost['description']:'';
|
||||||
|
|
||||||
//Steps
|
//Steps
|
||||||
$sStepPattern = '/c(?P<step_id>\d+)_step_text/';
|
$sStepPattern = '/c(?P<step_id>\d+)_step_text/u';
|
||||||
$sImagePattern = '/c(?P<step_id>\d+)_(?P<image_id>\d+)_image_(?P<image_info>\w+)/';
|
$sImagePattern = '/c(?P<step_id>\d+)_(?P<image_id>\d+)_image_(?P<image_info>\w+)/u';
|
||||||
foreach($asPost as $sFormId=>$sValue)
|
foreach($asPost as $sFormId=>$sValue)
|
||||||
{
|
{
|
||||||
//Step Text
|
//Step Text
|
||||||
@@ -2706,7 +2722,6 @@ class SearchEngine extends PhpObject
|
|||||||
}
|
}
|
||||||
$sWords = implode(self::KEYWORDS_SEPARATOR, $asWords);
|
$sWords = implode(self::KEYWORDS_SEPARATOR, $asWords);
|
||||||
$sWords = mb_strtolower(str_replace("\n", self::KEYWORDS_SEPARATOR, $sWords));
|
$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
|
$sWords = preg_replace('/(\W+)/u', self::KEYWORDS_SEPARATOR, $sWords); //remove all non-word characters
|
||||||
|
|
||||||
//Add / Modify search database
|
//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)
|
private function getParsedWords($sSearchWords)
|
||||||
{
|
{
|
||||||
return array_unique(array_filter(explode(' ', $sSearchWords), array($this, 'checkSearchedWords')));
|
return array_unique(array_filter(explode(' ', $sSearchWords), array($this, 'checkSearchedWords')));
|
||||||
@@ -3084,28 +3085,28 @@ class Reader
|
|||||||
//Strings
|
//Strings
|
||||||
foreach($this->getWords('cString') as $sStringWord)
|
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);
|
$sCode = preg_replace($sPattern, '>$1<span class="string">'.$sStringWord.'$2'.$sStringWord.'</span>', $sCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Part comment
|
//Part comment
|
||||||
$sPattern = '/>([^<]*)\"\;([^<]*)\<\/span\>\<\/li\>/';
|
$sPattern = '/>([^<]*)\"\;([^<]*)\<\/span\>\<\/li\>/u';
|
||||||
$sCode = preg_replace($sPattern, '>$1<span class="comment">"$2</span>', $sCode);
|
$sCode = preg_replace($sPattern, '>$1<span class="comment">"$2</span>', $sCode);
|
||||||
|
|
||||||
//Internal Url
|
//Internal Url
|
||||||
//$sPattern = '/>([^<]*)'.preg_quote($_GET['serv_name'], '/').'\/r\-([^<]*)/';
|
//$sPattern = '/>([^<]*)'.preg_quote($_GET['serv_name'], '/').'\/r\-([^<]*)/u';
|
||||||
$sPattern = '/>([^<\/]*)(http:\/\/'.$sSafeRexExServName.'|'.$sSafeRexExServName.')(c|code|p|proc|procedure)\-([^<]*)/';
|
$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);
|
$sCode = preg_replace($sPattern, '>$1<a class="share internal_link" href="'.$sServName.'$3-$4" target="_blank">$3 $4</a>', $sCode);
|
||||||
|
|
||||||
//Global / Main
|
//Global / Main
|
||||||
$sPattern = '/>\*\ \[('.implode('|', $this->getWords('wCodePart')).')\]/';
|
$sPattern = '/>\*\ \[('.implode('|', $this->getWords('wCodePart')).')\]/u';
|
||||||
$sCode = preg_replace($sPattern, '><span class="code_part">> $1</span>', $sCode);
|
$sCode = preg_replace($sPattern, '><span class="code_part">> $1</span>', $sCode);
|
||||||
|
|
||||||
//Core Words
|
//Core Words
|
||||||
foreach($this->getWords('wCore') as $sCoreWord)
|
foreach($this->getWords('wCore') as $sCoreWord)
|
||||||
{
|
{
|
||||||
$sCoreWord = mb_strtolower($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);
|
$sCode = preg_replace($sPattern, '>$1<span class="core">$4</span>$5', $sCode);
|
||||||
}
|
}
|
||||||
//$sCoreWords = str_replace(' ', '\ ', implode('|', array_map('mb_strtolower', $this->getWords('wCore'))));
|
//$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')));
|
$asOperators = array_unique(array_merge($this->getWords('cOperator'), $this->getWords('cCalculation')));
|
||||||
foreach($asOperators as $sOpWord)
|
foreach($asOperators as $sOpWord)
|
||||||
{
|
{
|
||||||
$sPattern = '/>([^<]*)\\'.$sOpWord.'/';
|
$sPattern = '/>([^<]*)\\'.$sOpWord.'/u';
|
||||||
$sCode = preg_replace($sPattern, '>$1<span class="operator">'.$sOpWord.'</span>', $sCode);
|
$sCode = preg_replace($sPattern, '>$1<span class="operator">'.$sOpWord.'</span>', $sCode);
|
||||||
}
|
}
|
||||||
//$sPattern = '/>([^<]*)['.implode(array_map('mb_strtolower', ($this->getWords('cOperator')))).']/';
|
//$sPattern = '/>([^<]*)['.implode(array_map('mb_strtolower', ($this->getWords('cOperator')))).']/';
|
||||||
@@ -3126,7 +3127,7 @@ class Reader
|
|||||||
|
|
||||||
//Numbers
|
//Numbers
|
||||||
$sPreChar = '\\'.implode('\\', $this->getWords('cCalculation')).'\s';
|
$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);
|
$sCode = preg_replace($sPattern, '>$1<span class="number">$4</span>$5', $sCode);
|
||||||
|
|
||||||
return $sCode;
|
return $sCode;
|
||||||
@@ -3230,7 +3231,7 @@ class Mask extends PhpObject
|
|||||||
|
|
||||||
private function setParts()
|
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'];
|
$sPartName = $asMatch['part'];
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ if($bUserOk && $sAction!=Databap::EXT_ACCESS)
|
|||||||
{
|
{
|
||||||
case 'add_user':
|
case 'add_user':
|
||||||
$asInfo = explode('-', strtolower($oUser));
|
$asInfo = explode('-', strtolower($oUser));
|
||||||
$oDatabap->addUser($asInfo[0], $asInfo[1], $asInfo[2]);
|
$sResult = 'User added. Id='.$oDatabap->addUser($asInfo[0], $asInfo[1], $asInfo[2]);
|
||||||
break;
|
break;
|
||||||
case 'reset_token':
|
case 'reset_token':
|
||||||
$sResult = print_r($oDatabap->resetToken(), true);
|
$sResult = print_r($oDatabap->resetToken(), true);
|
||||||
@@ -164,10 +164,13 @@ if($bUserOk && $sAction!=Databap::EXT_ACCESS)
|
|||||||
$oDatabap->buildCompleteIndex();
|
$oDatabap->buildCompleteIndex();
|
||||||
$sResult = 'Index ok';
|
$sResult = 'Index ok';
|
||||||
break;
|
break;
|
||||||
case 'install':
|
case 'install_queries':
|
||||||
$oMySqlInstall = new MySqlManager();
|
$oMySqlInstall = new MySqlManager();
|
||||||
$sResult = $oMySqlInstall->getFullInstallQuery();
|
$sResult = $oMySqlInstall->getFullInstallQuery();
|
||||||
break;
|
break;
|
||||||
|
case 'reset_chan_safe_names':
|
||||||
|
$sResult = $oDatabap->resetChanSafeNames();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user