Skip to content

Commit

Permalink
FIX punctuation in articles and pages titles #505 (bazooka07)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrocadete committed Nov 18, 2020
1 parent 0dcd810 commit 2417a5e
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 70 deletions.
155 changes: 86 additions & 69 deletions core/lib/class.plx.motor.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,28 +626,35 @@ protected function getPage() {
$this->page = 1;
}

/**
* Méthode qui récupere la liste des articles
*
* @param publi before, after ou all => on récupère tous les fichiers (date) ?
* @return boolean vrai si articles trouvés, sinon faux
* @author Stéphane F
**/
public function getArticles($publi='before') {

# On calcule la valeur start
$start = $this->bypage*($this->page-1);
# On recupere nos fichiers (tries) selon le motif, la pagination, la date de publication
if($aFiles = $this->plxGlob_arts->query($this->motif,'art',$this->tri,$start,$this->bypage,$publi)) {
# on mémorise le nombre total d'articles trouvés
foreach($aFiles as $k=>$v) # On parcourt tous les fichiers
$array[$k] = $this->parseArticle(PLX_ROOT.$this->aConf['racine_articles'].$v);
# On stocke les enregistrements dans un objet plxRecord
$this->plxRecord_arts = new plxRecord($array);
return true;
}
else return false;
}
/**
* Méthode qui récupere la liste des articles
*
* @param publi before, after ou all => on récupère tous les fichiers (date) ?
* @return boolean vrai si articles trouvés, sinon faux
* @author Stéphane F, J.P. Pourrez (bazooka07)
**/
public function getArticles($publi='before') {

# On calcule la valeur start
$start = $this->bypage*($this->page-1);
# On recupere nos fichiers (tries) selon le motif, la pagination, la date de publication
if($aFiles = $this->plxGlob_arts->query($this->motif,'art',$this->tri,$start,$this->bypage,$publi)) {
# On analyse tous les fichiers
$artsList = array();
foreach($aFiles as $v) {
$art = $this->parseArticle(PLX_ROOT . $this->aConf['racine_articles'] . $v);
if(!empty($art)) {
$artsList[] = $art;
}
}
# On stocke les enregistrements dans un objet plxRecord
$this->plxRecord_arts = new plxRecord($artsList);
return true;
}

$this->plxRecord_arts = false;
return false;
}

/**
* Méthode qui retourne les informations $output en analysant
Expand All @@ -671,53 +678,63 @@ public function artInfoFromFilename($filename) {
}
}

/**
* Méthode qui parse l'article du fichier $filename
*
* @param filename fichier de l'article à parser
* @return array
* @author Anthony GUÉRIN, Florent MONTHEL, Stéphane F
**/
public function parseArticle($filename) {

# Mise en place du parseur XML
$data = implode('',file($filename));
$parser = xml_parser_create(PLX_CHARSET);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_parse_into_struct($parser,$data,$values,$iTags);
xml_parser_free($parser);
# Recuperation des valeurs de nos champs XML
$art['title'] = plxUtils::getValue($values[$iTags['title'][0]]['value']);
$art['allow_com'] = plxUtils::getValue($values[$iTags['allow_com'][0]]['value']);
$art['template'] = plxUtils::getValue($values[$iTags['template'][0]]['value'],'article.php');
$art['chapo'] = plxUtils::getValue($values[$iTags['chapo'][0]]['value']);
$art['content'] = plxUtils::getValue($values[$iTags['content'][0]]['value']);
$art['tags'] = plxUtils::getValue($values[ $iTags['tags'][0] ]['value']);
$meta_description = plxUtils::getValue($iTags['meta_description'][0]);
$art['meta_description'] = plxUtils::getValue($values[$meta_description]['value']);
$meta_keywords = plxUtils::getValue($iTags['meta_keywords'][0]);
$art['meta_keywords'] = plxUtils::getValue($values[$meta_keywords]['value']);
$art['title_htmltag'] = isset($iTags['title_htmltag']) ? plxUtils::getValue($values[$iTags['title_htmltag'][0]]['value']) : '';
$art['thumbnail'] = isset($iTags['thumbnail']) ? plxUtils::getValue($values[$iTags['thumbnail'][0]]['value']) : '';
$art['thumbnail_title'] = isset($iTags['thumbnail_title']) ? plxUtils::getValue($values[$iTags['thumbnail_title'][0]]['value']) : '';
$art['thumbnail_alt'] = isset($iTags['thumbnail_alt']) ? plxUtils::getValue($values[$iTags['thumbnail_alt'][0]]['value']) : '';
# Informations obtenues en analysant le nom du fichier
$art['filename'] = $filename;
$tmp = $this->artInfoFromFilename($filename);
$art['numero'] = $tmp['artId'];
$art['author'] = $tmp['usrId'];
$art['categorie'] = $tmp['catId'];
$art['url'] = $tmp['artUrl'];
$art['date'] = $tmp['artDate'];
$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
eval($this->plxPlugins->callHook('plxMotorParseArticle'));
# On retourne le tableau
return $art;
}
/**
* Méthode qui parse l'article du fichier $filename
*
* @param filename fichier de l'article à parser
* @return array
* @author Anthony GUÉRIN, Florent MONTHEL, Stéphane F, J.P. Pourrez (bazooka07)
**/
public function parseArticle($filename) {

# Informations obtenues en analysant le nom du fichier
$tmp = $this->artInfoFromFilename($filename);
if(!empty($tmp)) {
# Mise en place du parseur XML
$data = implode('',file($filename));
$parser = xml_parser_create(PLX_CHARSET);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_parse_into_struct($parser,$data,$values,$iTags);
xml_parser_free($parser);

$meta_description = plxUtils::getValue($iTags['meta_description'][0]);
$meta_keywords = plxUtils::getValue($iTags['meta_keywords'][0]);
$art = array(
'filename' => $filename,
# Recuperation des valeurs de nos champs XML
'title' => plxUtils::getValue($values[$iTags['title'][0]]['value']),
'allow_com' => plxUtils::getValue($values[$iTags['allow_com'][0]]['value']),
'template' => plxUtils::getValue($values[$iTags['template'][0]]['value'], 'article.php'),
'chapo' => plxUtils::getValue($values[$iTags['chapo'][0]]['value']),
'content' => plxUtils::getValue($values[$iTags['content'][0]]['value']),
'tags' => plxUtils::getValue($values[ $iTags['tags'][0] ]['value']),
'meta_description' => plxUtils::getValue($values[$meta_description]['value']),
'meta_keywords' => plxUtils::getValue($values[$meta_keywords]['value']),
'title_htmltag' => plxUtils::getValue($values[$iTags['title_htmltag'][0]]['value']),
'thumbnail' => plxUtils::getValue($values[$iTags['thumbnail'][0]]['value']),
'thumbnail_title' => plxUtils::getValue($values[$iTags['thumbnail_title'][0]]['value']),
'thumbnail_alt' => plxUtils::getValue($values[$iTags['thumbnail_alt'][0]]['value']),
'numero' => $tmp['artId'],
'author' => $tmp['usrId'],
'categorie' => $tmp['catId'],
'url' => $tmp['artUrl'],
'date' => $tmp['artDate'],
'nb_com' => $this->getNbCommentaires('#^' . $tmp['artId'] . '.\d{10}.\d+.xml$#'),
'date_creation' => plxUtils::getValue($values[$iTags['date_creation'][0]]['value'], $tmp['artDate']),
'date_update' => plxUtils::getValue($values[$iTags['date_update'][0]]['value'], $tmp['artDate']),
);

# Hook plugins
eval($this->plxPlugins->callHook('plxMotorParseArticle'));

# On retourne le tableau
return $art;
} else {
# le nom du fichier article est incorrect !!
return false;
}
}

/**
* Méthode qui retourne le nombre de commentaires respectants le motif $motif et le paramètre $publi
Expand Down
2 changes: 1 addition & 1 deletion core/lib/class.plx.utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public static function urlify($url, $remove=false, $replace='-', $lower=true) {
$clean_url = preg_replace('@[\s' . $replace . ']+@', $replace, $clean_url);

// remove non-alphanumeric character
$clean_url = trim(preg_replace('@[^\w\.-]+@', '', $clean_url), '-');
$clean_url = trim(preg_replace('@[^\w-]+@', '', $clean_url), '-');

if($lower) {
$clean_url = strtolower($clean_url);
Expand Down
1 change: 1 addition & 0 deletions readme/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## PLUXML 5.8.x (YYYY/MM/DD) ##
FIX allow punctuation in articles and pages titles #505 (bazooka07)
FIX plxShow::catList() and plxShow::catId multiples article with same category #495 (bazooka07)

## PLUXML 5.8.4 (2020/09/07) ##
Expand Down

0 comments on commit 2417a5e

Please sign in to comment.