Skip to content

Commit

Permalink
FIX #380 refacto plxMotor and plxFeed regex (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
haruka-7 authored Apr 17, 2020
1 parent 29dc35f commit c48bd2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
22 changes: 11 additions & 11 deletions core/lib/class.plx.feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ public function fprechauffage() {
# Hook plugins
if(eval($this->plxPlugins->callHook('plxFeedPreChauffageBegin'))) return;

if($this->get AND preg_match('#^(?:atom/|rss/)?categorie([0-9]+)/?#',$this->get,$capture)) {
if($this->get AND preg_match('#^(?:atom/|rss/)?categorie(\d+)/?#',$this->get,$capture)) {
$this->mode = 'article'; # Mode du flux
# On récupère la catégorie cible
$this->cible = str_pad($capture[1],3,'0',STR_PAD_LEFT); # On complète sur 3 caractères
# On modifie le motif de recherche
$this->motif = '/^[0-9]{4}.((?:[0-9]|home|,)*(?:'.$this->cible.')(?:[0-9]|home|,)*).[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
$this->motif = '#^\d{4}.((?:\d|home|,)*(?:'.$this->cible.')(?:\d|home|,)*).\d{3}.\d{12}.[\w-]+.xml$#';
}
elseif($this->get AND preg_match('#^(?:atom/|rss/)?commentaires/?$#',$this->get)) {
$this->mode = 'commentaire'; # Mode du flux
}
elseif($this->get AND preg_match('#^(?:atom/|rss/)?tag\/([a-z0-9-]+)/?$#',$this->get,$capture)) {
elseif($this->get AND preg_match('#^(?:atom/|rss/)?tag/([\w-]+)/?$#', $this->get, $capture)) {
$this->mode = 'tag';
$this->cible = $capture[1];
$ids = array();
Expand All @@ -106,19 +106,19 @@ public function fprechauffage() {
}
}
if(sizeof($ids)>0) {
$this->motif = '/('.implode('|', $ids).').(?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
$this->motif = '#('.implode('|', $ids).').(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.\d{12}.[\w-]+.xml$#';
} else
$this->motif = '';

}
elseif($this->get AND preg_match('#^(?:atom/|rss/)?commentaires/article([0-9]+)/?$#',$this->get,$capture)) {
elseif($this->get AND preg_match('#^(?:atom/|rss/)?commentaires/article(\d+)/?$#',$this->get,$capture)) {
$this->mode = 'commentaire'; # Mode du flux
# On récupère l'article cible
$this->cible = str_pad($capture[1],4,'0',STR_PAD_LEFT); # On complète sur 4 caractères
# On modifie le motif de recherche
$this->motif = '/^'.$this->cible.'.(?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
$this->motif = '#^'.$this->cible.'.(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.\d{12}.[\w-]+.xml$#';
}
elseif($this->get AND preg_match('#^admin([a-zA-Z0-9]+)/commentaires/(hors|en)-ligne/?$#',$this->get,$capture)) {
elseif($this->get AND preg_match('#^admin([\w-]+)/commentaires/(hors|en)-ligne/?$#',$this->get,$capture)) {
$this->mode = 'admin'; # Mode du flux
$this->cible = '-'; # /!\: il ne faut pas initialiser à blanc sinon ça prend par défaut les commentaires en ligne (faille sécurité)
if ($capture[1] == $this->clef) {
Expand All @@ -130,7 +130,7 @@ public function fprechauffage() {
} else {
$this->mode = 'article'; # Mode du flux
# On modifie le motif de recherche
$this->motif = '/^[0-9]{4}.(?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
$this->motif = '#^\d{4}.(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.\d{12}.[\w-]+.xml$#';
}
# Hook plugins
eval($this->plxPlugins->callHook('plxFeedPreChauffageEnd'));
Expand All @@ -155,13 +155,13 @@ public function fdemarrage() {
header('Location: '.$this->urlRewrite('?article'.$this->cible.'/'));
exit;
} else { # On récupère les commentaires
$regex = '/^'.$this->cible.'.[0-9]{10}-[0-9]+.xml$/';
$regex = '/^'.$this->cible.'.\d{10}-\d+.xml$/';
$this->getCommentaires($regex,'rsort',0,$this->bypage);
}
}
# Flux de commentaires global
elseif($this->mode == 'commentaire') {
$regex = '/^[0-9]{4}.[0-9]{10}-[0-9]+.xml$/';
$regex = '#^\d{4}.\d{10}-\d+.xml$#';
$this->getCommentaires($regex,'rsort',0,$this->bypage);
}
# Flux admin
Expand All @@ -172,7 +172,7 @@ public function fdemarrage() {
exit;
}
# On récupère les commentaires
$this->getCommentaires('/^'.$this->cible.'[0-9]{4}.[0-9]{10}-[0-9]+.xml$/','rsort',0,$this->bypage,'all');
$this->getCommentaires('#^'.$this->cible.'\d{4}.\d{10}-\d+.xml$#','rsort',0,$this->bypage,'all');
}
# Flux d'articles pour un tag
elseif($this->mode == 'tag') {
Expand Down
68 changes: 34 additions & 34 deletions core/lib/class.plx.motor.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,23 @@ public function prechauffage() {
$this->template = $this->aStats[ $this->cible ]['template'];
}
elseif(empty($this->get)
OR preg_match('@^(blog|blog\/page[0-9]*|\/?page[0-9]*)$@', $this->get)
AND !preg_match('@^(?:article|static|categorie|archives|tag|preview|telechargement|download)[\b\d/]+@', $this->get)) {
OR preg_match('#^(blog|blog\/page\d*|\/?page\d*)$#', $this->get)
AND !preg_match('#^(?:article|static|categorie|archives|tag|preview|telechargement|download)[\b\d/]+#', $this->get)) {
$this->mode = 'home';
$this->template = $this->aConf['hometemplate'];
$this->bypage = $this->aConf['bypage']; # Nombre d'article par page
# On regarde si on a des articles en mode "home"
if($this->plxGlob_arts->query('/^[0-9]{4}.(home[0-9,]*).[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/')) {
$this->motif = '/^[0-9]{4}.(home[0-9,]*).[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
if($this->plxGlob_arts->query('#^\d{4}\.(home[0-9,]*)\.\d{3}\.\d{12}\.[\w-]+\.xml$#')) {
$this->motif = '#^\d{4}.(home[0-9,]*).\d{3}.\d{12}.[\w-]+.xml$#';
} else { # Sinon on recupere tous les articles
$this->motif = '/^[0-9]{4}.(?:[0-9]|,)*(?:'.$this->homepageCats.')(?:[0-9]|,)*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
$this->motif = '#^\d{4}.(?:\d|,)*(?:'.$this->homepageCats.')(?:\d|,)*.\d{3}.\d{12}.[\w-]+.xml$#';
}
}
elseif($this->get AND preg_match('/^article([0-9]+)\/?([a-z0-9-]+)?/',$this->get,$capture)) {
elseif($this->get AND preg_match('#^article(\d+)\/?([\w-]+)?#',$this->get,$capture)) {
$this->mode = 'article'; # Mode article
$this->template = 'article.php';
$this->cible = str_pad($capture[1],4,'0',STR_PAD_LEFT); # On complete sur 4 caracteres
$this->motif = '/^'.$this->cible.'.((?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*).[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/'; # Motif de recherche
$this->motif = '#^'.$this->cible.'.(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.\d{12}.[\w-]+.xml$#'; # Motif de recherche
if($this->getArticles()) {
# Redirection 301
if(!isset($capture[2]) OR $this->plxRecord_arts->f('url')!=$capture[2]) {
Expand All @@ -163,7 +163,7 @@ public function prechauffage() {
$this->error404(L_UNKNOWN_ARTICLE);
}
}
elseif($this->get AND preg_match('/^static([0-9]+)\/?([a-z0-9-]+)?/',$this->get,$capture)) {
elseif($this->get AND preg_match('#^static(\d+)\/?([\w-]+)?#',$this->get,$capture)) {
$this->cible = str_pad($capture[1],3,'0',STR_PAD_LEFT); # On complète sur 3 caractères
if(!isset($this->aStats[$this->cible]) OR !$this->aStats[$this->cible]['active']) {
$this->error404(L_UNKNOWN_STATIC);
Expand All @@ -181,11 +181,11 @@ public function prechauffage() {
}
}
}
elseif($this->get AND preg_match('/^categorie([0-9]+)\/?([a-z0-9-]+)?/',$this->get,$capture)) {
elseif($this->get AND preg_match('#^categorie(\d+)\/?([\w-]+)?#',$this->get,$capture)) {
$this->cible = str_pad($capture[1],3,'0',STR_PAD_LEFT); # On complete sur 3 caracteres
if(!empty($this->aCats[$this->cible]) AND $this->aCats[$this->cible]['active'] AND $this->aCats[$this->cible]['url']==$capture[2]) {
$this->mode = 'categorie'; # Mode categorie
$this->motif = '/^[0-9]{4}.(?:[0-9]|home|,)*(?:'.$this->cible.')(?:[0-9]|home|,)*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/'; # Motif de recherche
$this->motif = '#^\d{4}.((?:\d|home|,)*(?:'.$this->cible.')(?:\d|home|,)*).\d{3}.\d{12}.[\w-]+.xml$#'; # Motif de recherche
$this->template = $this->aCats[$this->cible]['template'];
$this->tri = $this->aCats[$this->cible]['tri']; # Recuperation du tri des articles
$this->bypage = $this->aCats[$this->cible]['bypage'] > 0 ? $this->aCats[$this->cible]['bypage'] : $this->bypage;
Expand All @@ -198,18 +198,18 @@ public function prechauffage() {
$this->error404(L_UNKNOWN_CATEGORY);
}
}
elseif($this->get AND preg_match('/^archives\/([0-9]{4})[\/]?([0-9]{2})?[\/]?([0-9]{2})?/',$this->get,$capture)) {
elseif($this->get AND preg_match('#^archives\/(\d{4})[\/]?(\d{2})?[\/]?(\d{2})?#',$this->get,$capture)) {
$this->mode = 'archives';
$this->template = 'archives.php';
$this->bypage = $this->aConf['bypage_archives'];
$this->cible = $search = $capture[1];
if(!empty($capture[2])) $this->cible = ($search .= $capture[2]);
else $search .= '[0-9]{2}';
else $search .= '\d{2}';
if(!empty($capture[3])) $search .= $capture[3];
else $search .= '[0-9]{2}';
$this->motif = '/^[0-9]{4}.(?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*.[0-9]{3}.'.$search.'[0-9]{4}.[a-z0-9-]+.xml$/';
else $search .= '\d{2}';
$this->motif = '#^\d{4}.(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.'.$search.'\d{4}.[\w-]+.xml$#';
}
elseif($this->get AND preg_match('/^tag\/([a-z0-9-]+)/',$this->get,$capture)) {
elseif($this->get AND preg_match('#^tag\/([\w-]+)#',$this->get,$capture)) {
$this->cible = $capture[1];
$ids = array();
$datetime = date('YmdHi');
Expand All @@ -229,16 +229,16 @@ public function prechauffage() {
if(sizeof($ids)>0) {
$this->mode = 'tags'; # Affichage en mode home
$this->template = 'tags.php';
$this->motif = '/('.implode('|', $ids).').(?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/';
$this->motif = '#('.implode('|', $ids).').(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.\d{12}.[\w-]+.xml$#';
$this->bypage = $this->aConf['bypage_tags']; # Nombre d'article par page
} else {
$this->error404(L_ARTICLE_NO_TAG);
}
}
elseif($this->get AND preg_match('/^preview\/?/',$this->get) AND isset($_SESSION['preview'])) {
elseif($this->get AND preg_match('#^preview\/?#',$this->get) AND isset($_SESSION['preview'])) {
$this->mode = 'preview';
}
elseif($this->get AND preg_match('/^(telechargement|download)\/(.+)$/',$this->get,$capture)) {
elseif($this->get AND preg_match('#^(telechargement|download)\/(.+)$#',$this->get,$capture)) {
if($this->sendTelechargement($capture[2])) {
$this->mode = 'telechargement'; # Mode telechargement
$this->cible = $capture[2];
Expand Down Expand Up @@ -328,7 +328,7 @@ public function demarrage() {
exit;
}
# Récupération des commentaires
$this->getCommentaires('/^'.$this->cible.'.[0-9]{10}-[0-9]+.xml$/',$this->tri_coms);
$this->getCommentaires('#^'.$this->cible.'.\d{10}-\d+.xml$#',$this->tri_coms);
$this->template=$this->plxRecord_arts->f('template');
if($this->aConf['capcha']) $this->plxCapcha = new plxCapcha(); # Création objet captcha
}
Expand Down Expand Up @@ -463,7 +463,7 @@ public function getCategories($filename) {
$this->aCats[$number]['homepage'] = in_array($this->aCats[$number]['homepage'],array('0','1')) ? $this->aCats[$number]['homepage'] : 1;
if($this->aCats[$number]['active'] AND $this->aCats[$number]['homepage']) $homepageCats[]=$number;
# Recuperation du nombre d'article de la categorie
$motif = '/^[0-9]{4}.[home,|0-9,]*'.$number.'[0-9,]*.[0-9]{3}.[0-9]{12}.[A-Za-z0-9-]+.xml$/';
$motif = '#^\d{4}.[home,|0-9,]*'.$number.'\d*.\d{3}.\d{12}.[A-Za-z0-9-]+.xml$#';
$arts = $this->plxGlob_arts->query($motif,'art','',0,false,'before');
$this->aCats[$number]['articles'] = ($arts?sizeof($arts):0);
# Hook plugins
Expand Down Expand Up @@ -619,7 +619,7 @@ protected function mapTri($tri) { /* obsolete ! 2017-12-03 */
protected function getPage() {

# On check pour avoir le numero de page
if(preg_match('/page([0-9]*)/',$this->get,$capture))
if(preg_match('#page(\d*)#',$this->get,$capture))
$this->page = $capture[1];
else
$this->page = 1;
Expand Down Expand Up @@ -659,7 +659,7 @@ public function getArticles($publi='before') {
public function artInfoFromFilename($filename) {

# On effectue notre capture d'informations
if(preg_match('/(_?\d{4})\.([\d,|home|draft]*)\.(\d{3})\.(\d{12})\.([\w-]+)\.xml$/',$filename,$capture)) {
if(preg_match('#(_?\d{4})\.([\d,|home|draft]*)\.(\d{3})\.(\d{12})\.([\w-]+)\.xml$#',$filename,$capture)) {
return array(
'artId' => $capture[1],
'catId' => $capture[2],
Expand Down Expand Up @@ -709,7 +709,7 @@ public function parseArticle($filename) {
$art['categorie'] = $tmp['catId'];
$art['url'] = $tmp['artUrl'];
$art['date'] = $tmp['artDate'];
$art['nb_com'] = $this->getNbCommentaires('/^'.$art['numero'].'.[0-9]{10}.[0-9]+.xml$/');
$art['nb_com'] = $this->getNbCommentaires('#^'.$art['numero'].'.\d{10}.\d+.xml$#');
$art['date_creation'] = isset($iTags['date_creation']) ? plxUtils::getValue($values[$iTags['date_creation'][0]]['value']) : $art['date'];
$art['date_update'] = isset($iTags['date_update']) ? plxUtils::getValue($values[$iTags['date_update'][0]]['value']) : $art['date'];
# Hook plugins
Expand Down Expand Up @@ -744,7 +744,7 @@ public function getNbCommentaires($motif,$publi='before') {
**/
public function comInfoFromFilename($filename) {
# On effectue notre capture d'informations
if(preg_match('/([[:punct:]]?)([0-9]{4}).([0-9]{10})-([0-9]+).xml$/',$filename,$capture)) {
if(preg_match('#([[:punct:]]?)(\d{4}).(\d{10})-(\d+).xml$#',$filename,$capture)) {
return array(
'comStatus' => $capture[1],
'artId' => $capture[2],
Expand Down Expand Up @@ -841,7 +841,7 @@ public function getCommentaires($motif,$ordre='sort',$start=0,$limite=false,$pub
$array[$k] = $this->parseCommentaire(PLX_ROOT.$this->aConf['racine_commentaires'].$v);

# hiérarchisation et indentation des commentaires seulement sur les écrans requis
if( !(defined('plxAdmin::PLX_ADMIN') OR defined('plxFeed::PLX_FEED')) OR preg_match('/comment_new/',basename($_SERVER['SCRIPT_NAME']))) {
if( !(defined('plxAdmin::PLX_ADMIN') OR defined('plxFeed::PLX_FEED')) OR preg_match('#comment_new#',basename($_SERVER['SCRIPT_NAME']))) {
$array = $this->parentChildSort_r('index', 'parent', $array);
}

Expand All @@ -866,7 +866,7 @@ public function nextIdArtComment($idArt) {
if($dh = opendir(PLX_ROOT.$this->aConf['racine_commentaires'])) {
$Idxs = array();
while(false !== ($file = readdir($dh))) {
if(preg_match("/_?".$idArt.".[0-9]+-([0-9]+).xml/", $file, $capture)) {
if(preg_match("/_?".$idArt.".\d+-(\d+).xml/", $file, $capture)) {
if ($capture[1] > $ret)
$ret = $capture[1];
}
Expand Down Expand Up @@ -1034,7 +1034,7 @@ public function sendTelechargement($cible) {
# Hook plugins
if(eval($this->plxPlugins->callHook('plxMotorSendDownload'))) return;
# On lance le téléchargement et on check le répertoire medias
if(file_exists($file) AND preg_match('#^'.str_replace('\\', '/', realpath(PLX_ROOT.$this->aConf['medias']).'#'), str_replace('\\', '/', realpath($file)))) {
if(file_exists($file) AND preg_match('#^'.str_replace('\\', '#', realpath(PLX_ROOT.$this->aConf['medias']).'#'), str_replace('\\', '/', realpath($file)))) {
header('Content-Description: File Transfer');
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename='.basename($file));
Expand Down Expand Up @@ -1067,7 +1067,7 @@ public function urlRewrite($url='') {

if($url=='' OR $url=='?') return $this->racine;

preg_match('/^([0-9a-z\_\-\.\/]+)?[\?]?([0-9a-z\_\-\.\/,&=%]+)?[\#]?(.*)$/i', $url, $args);
preg_match('#^([0-9a-z\_\-\.\/]+)?[\?]?([0-9a-z\_\-\.\/,&=%]+)?[\#]?(.*)$#i', $url, $args);

if($this->aConf['urlrewriting']) {
$new_url = str_replace('index.php', '', $args[1]);
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public function urlRewrite($url='') {
* @scope global
* @author Stephane F
**/
public function nbArticles($select='all', $userId='[0-9]{3}', $mod='_?', $publi='all') {
public function nbArticles($select='all', $userId='\d{3}', $mod='_?', $publi='all') {

$nb = 0;
if($select == 'all')
Expand All @@ -1108,7 +1108,7 @@ public function nbArticles($select='all', $userId='[0-9]{3}', $mod='_?', $publi=
else
$motif = $select;

if($arts = $this->plxGlob_arts->query('/^'.$mod.'[0-9]{4}.('.$motif.').'.$userId.'.[0-9]{12}.[a-z0-9-]+.xml$/', 'art', '', 0, false, $publi))
if($arts = $this->plxGlob_arts->query('#^'.$mod.'\d{4}.('.$motif.').'.$userId.'.\d{12}.[\w-]+.xml$#', 'art', '', 0, false, $publi))
$nb = sizeof($arts);

return $nb;
Expand All @@ -1127,11 +1127,11 @@ public function nbComments($select='online', $publi='all') {

$nb = 0;
if($select == 'all')
$motif = '/[^[:punct:]?][0-9]{4}.(.*).xml$/';
$motif = '#[^[:punct:]?]\d{4}.(.*).xml$#';
elseif($select=='offline')
$motif = '/^_[0-9]{4}.(.*).xml$/';
$motif = '#^_\d{4}.(.*).xml$#';
elseif($select=='online')
$motif = '/^[0-9]{4}.(.*).xml$/';
$motif = '#^\d{4}.(.*).xml$#';
else
$motif = $select;

Expand All @@ -1152,7 +1152,7 @@ public function getActiveArts() {
if($this->plxGlob_arts->aFiles) {
$datetime=date('YmdHi');
foreach($this->plxGlob_arts->aFiles as $filename) {
if(preg_match('/^([0-9]{4}).(?:[0-9]|home|,)*(?:'.$this->activeCats.'|home)(?:[0-9]|home|,)*.[0-9]{3}.([0-9]{12}).[a-z0-9-]+.xml$/', $filename, $capture)) {
if(preg_match('#^(\d{4}).(?:\d|home|,)*(?:'.$this->activeCats.'|home)(?:\d|home|,)*.\d{3}.(\d{12}).[\w-]+.xml$#', $filename, $capture)) {
if($capture[2]<=$datetime) { # on ne prends que les articles publiés
$this->activeArts[$capture[1]]=1;
}
Expand Down

0 comments on commit c48bd2e

Please sign in to comment.