Skip to content

Instantly share code, notes, and snippets.

@bazooka07
Last active October 19, 2018 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bazooka07/e3bf47ec9e4268937ea95e20c8c40ce5 to your computer and use it in GitHub Desktop.
Save bazooka07/e3bf47ec9e4268937ea95e20c8c40ce5 to your computer and use it in GitHub Desktop.
plxShow::staticlist(...)
/*
Ajouter les cosntantes de class comme ceci :
class plxShow {
const STATICLIST_FORMAT = <<< FMT1
<li class="#static_class #static_status" id="#static_id"><a href="#static_url">#static_name</a></li>\n
FMT1;
const STATICLIST_GROUP_FORMAT = <<< FMT2
<span class="#group_class #group_status">#group_name</span>
FMT2;
const STATICLIST_CAT_FORMAT = <<< FMT3
<li class="#cat_class #cat_status" id="#cat_id"><a href="#cat_url" title="#cat_title">#cat_name (#cat_nb)</a></li>\n
FMT3;
public $plxMotor = false; # Objet plxMotor
private $lang; # fichier de traduction du theme
*/
/**
* Méthode qui affiche la liste des pages statiques.
*
* @param extra si renseigné: nom du lien vers la page d'accueil affiché en première position
* @param format format du texte pour chaque page (variable : #static_id, #static_status, #static_url, #static_name, #group_id, #group_class, #group_name)
* @param format_group format du texte pour chaque groupe (variable : #group_class, #group_name, #group_status)
* @param menublog position du menu Blog (si non renseigné le menu n'est pas affiché)
* @param format_cat format du texte pour chaque catégorie (variable : #cat_id, #cat_status, #cat_url, #cat_name, #group_id, #cat_class)
* @param menucat position du menu catégories (si non renseigné, se place après l'entrée accueil)
* @return stdout
* @scope global
* @author Stephane F
**/
public function staticList(
$extra='',
$format=self::STATICLIST_FORMAT,
$format_group=self::STATICLIST_GROUP_FORMAT,
$menublog=-1,
$format_cat=self::STATICLIST_CAT_FORMAT,
$pos_cat=false
) {
$menus = array();
$group_active = false;
# Hook Plugins
if(eval($this->plxMotor->plxPlugins->callHook('plxShowStaticListBegin'))) return;
$home = $this->plxMotor->mode == 'home';
# Si on a la variable extra, on affiche un lien vers la page d'accueil (avec $extra comme nom)
if(!empty(trim($extra))) {
$replaces = array(
'#static_id' => 'static-home',
'#static_class' => 'static menu',
'#static_url' => $this->plxMotor->urlRewrite(),
'#static_name' => plxUtils::strCheck(trim($extra)),
'#static_status' => ($home == true) ? 'active' : 'noactive'
);
$menus[] = str_replace(array_keys($replaces), array_values($replaces), $format);
}
# Affiche les pages statiques, avec un sous-menu si groupe
if($this->plxMotor->aStats) {
foreach($this->plxMotor->aStats as $k=>$v) {
$numPage = intval($k);
if($v['active'] == 1 AND $v['menu'] == 'oui') {
# La page est bien active et dispo dans le menu
if($v['url'][0]=='?') # url interne commençant par ?
$url = $this->plxMotor->urlRewrite($v['url']);
elseif(plxUtils::checkSite($v['url'],false)) # url externe en http ou autre
$url = $v['url'];
else # url page statique
$url = $this->plxMotor->urlRewrite("?static${numPage}/${v['url']}");
$active = ($this->staticId() == $numPage);
$replaces = array(
'#static_id' => "static-${numPage}",
'#static_class' => 'static menu',
'#static_url' => $url,
'#static_name' => plxUtils::strCheck($v['name']),
'#static_status' => ($active) ? 'active' : 'noactive'
);
$group = trim($v['group']);
if(empty($group))
$menus[] = str_replace(array_keys($replaces), array_values($replaces), $format);
else {
if(!array_key_exists($group, $menus)) { $menus[$group] = array(); }
$menus[$group][] = str_replace(array_keys($replaces), array_values($replaces), "\t\t${format}");
if(
empty($group_active) AND
empty($home) AND
$active // static-page
) {
$group_active = $group;
}
}
}
}
}
# affiche entrée blog
if(
!empty($this->plxMotor->aConf['homestatic']) and
is_numeric($menublog) and
isset($this->plxMotor->aStats[$this->plxMotor->aConf['homestatic']])
) {
if($this->plxMotor->aStats[$this->plxMotor->aConf['homestatic']]['active']) {
$status = (
$this->plxMotor->get and
preg_match('/(blog|categorie|archives|tag|article)/', $_SERVER['QUERY_STRING'].$this->plxMotor->mode)
) ? 'active' : 'noactive';
$replaces = array(
'#static_id' => 'static-blog',
'#static_class' => 'static menu',
'#static_url' => $this->plxMotor->urlRewrite('?blog'),
'#static_name' => ucfirst(L_PAGEBLOG_TITLE),
'#static_status' => $status
);
if($menublog > 0) {
array_splice(
$menus,
$menublog-1,
0,
array(
str_replace(array_keys($replaces), array_values($replaces), $format)
)
);
} else {
$menus[] = str_replace(array_keys($replaces), array_values($replaces), $format);
}
}
}
# Affiche les catégories
if(
!empty($format_cat) and
!empty($this->plxMotor->aCats)
) {
$activeCatId = $this->catId();
$catsMenu = array();
foreach($this->plxMotor->aCats as $catId=>$catInfos) {
$idNum = intval($catId);
$status = ($activeCatId == $idNum);
if($status and $this->plxMotor->mode === 'categorie') {
$group_active = ucfirst(L_CATEGORIES);
}
$replaces = array(
'#cat_id' => "static-cat-${idNum}",
'#cat_class' => 'static menu',
'#cat_url' => $this->plxMotor->urlRewrite("?categorie${idNum}/${catInfos['url']}"),
'#cat_name' => plxUtils::strCheck($catInfos['name']),
'#cat_nb' => $catInfos['articles'],
'#cat_title' => plxUtils::strCheck($catInfos['description']),
'#cat_status' => ($status) ? 'active' : 'noactive'
);
$catsMenu[] = str_replace(array_keys($replaces), array_values($replaces), $format_cat);
}
if(!is_numeric($pos_cat)) {
$pos_cat = (!empty(trim($extra))) ? 1 : 0;
}
switch($pos_cat) {
case -1:
# catégories à la fin du menu
$menus[ucfirst(L_CATEGORIES)] = $catsMenu;
break;
case 0:
# catégories au debut du menu
$menus = array_merge(array(ucfirst(L_CATEGORIES) => $catsMenu), $menus);
break;
default:
$head = array_splice($menus, 0, $pos_cat, true);
$tail = array_splice($menus, $pos_cat, 255, true);
$menus = array_merge($head, array(ucfirst(L_CATEGORIES) => $catsMenu), $tail);
}
}
# Hook Plugins
if(eval($this->plxMotor->plxPlugins->callHook('plxShowStaticListEnd'))) return;
# Affichage des pages statiques + menu Accueil et Blog
if(!empty($menus)) {
foreach($menus as $k=>$v) {
if(is_string($v)) {
echo $v;
}
elseif(is_array($v)) {
$replaces = array(
'#group_id' => 'static-group-'.plxUtils::title2url($k),
'#group_class' => 'static group',
'#group_name' => plxUtils::strCheck($k),
'#group_status' => ($group_active === $k) ? 'active' : 'noactive'
);
$caption = str_replace(array_keys($replaces), array_values($replaces), $format_group);
$options_menu = implode('', array_values($v));
$id = plxUtils::title2url($k);
echo <<< SOUS_MENU
<li>
$caption
<ul id="static-$id">
$options_menu </ul>
</li>\n
SOUS_MENU;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment