Files
le-matelot/client/plugins/rewriting/Rewriting.class.php
2020-01-27 08:56:08 +01:00

156 lines
3.5 KiB
PHP

<?php
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Reecriture.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Lang.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Variable.class.php");
class Rewriting extends PluginsClassiques {
var $rewrites = array();
var $langs = array();
const NOM_VARIABLE_CONFIG = 'rewriting_afficher_urls_base';
function __construct(){
parent::__construct("rewriting");
}
function init() {
$v = new Variable();
if (! $v->charger(self::NOM_VARIABLE_CONFIG)) {
$v->nom = self::NOM_VARIABLE_CONFIG;
$v->cache = 1;
$v->protege = 1;
$v->valeur = 1;
$v->add();
}
}
function destroy() {
$v = new Variable(self::NOM_VARIABLE_CONFIG);
$v->delete();
}
function get_langs()
{
$l = new Lang();
$q = "select * from $l->table";
$r = $this->query($q);
while($r && $row = $this->fetch_object($r)){
$l->charger($row->id);
$this->langs[$l->id] = $l->description;
}
return $this->langs;
}
function get_rewrites()
{
$re = new Reecriture();
$q = "select * from $re->table";
if (Variable::lire(Rewriting::NOM_VARIABLE_CONFIG) == 0) $q .= " where fond not in ('produit', 'contenu', 'rubrique', 'dossier')";
$r = $this->query($q, $re->link);
while($r && $row = $this->fetch_object($r)){
$this->rewrites[$row->id] = array('url' => $row->url, 'fond' => $row->fond, 'param' => $row->param, 'lang' => $row->lang, 'actif' => $row->actif);
}
return $this->rewrites;
}
function add($url, $fond, $param, $lang, $actif)
{
$r = new Reecriture();
$r->url = $url;
$r->fond = $fond;
$r->param = $param;
$r->lang = $lang;
$r->actif = $actif;
$r->add();
}
function update($id, $url, $fond, $param, $lang, $actif)
{
$r = new Reecriture();
if($r->charger_id($id)):
$r->url = $url;
$r->fond = $fond;
$r->param = $param;
$r->lang = $lang;
$r->actif = $actif;
$r->maj();
return TRUE;
else:
return FALSE;
endif;
}
function delete($id)
{
$r = new Reecriture();
if($r->charger_id($id)):
$r->delete();
return TRUE;
else:
return FALSE;
endif;
}
function boucle($texte, $args)
{
$id = lireTag($args, 'id');
$url = lireTag($args, 'url');
$fond = lireTag($args, 'fond');
$param = lireTag($args, 'param');
$lang = lireTag($args, 'lang');
$ligne = lireTag($args,"ligne");
if ($lang == '') $lang = 1;
if ($ligne == '') $ligne = 1;
$res="";
$r = new Reecriture();
if ($id):
$result = $r->charger_id($id);
elseif ($url):
$result = $r->charger($url);
else:
$result = $r->charger_param($fond, $param, $lang, $ligne);
endif;
if ($result):
$var = new Variable();
$var->charger('urlsite');
$temp = str_replace("#ID", $r->id, $texte);
$temp = str_replace("#URI", $r->url, $temp);
$temp = str_replace("#URL", $var->valeur.'/'.$r->url, $temp);
$temp = str_replace("#COMPLETEURL", $var->valeur.'?fond='.$r->fond.$r->param.'&'.$r->lang, $temp);
$temp = str_replace("#FOND", $r->fond, $temp);
$temp = str_replace("#PARAM", $r->param, $temp);
$temp = str_replace("#RLANG", $r->lang, $temp);
$temp = str_replace("#LIGNE", $r->actif, $temp);
$res .= $temp;
endif;
return $res;
}
function lireVarUrl($reecriture)
{
global $vars;
foreach ($vars as $nomvar => $typevar) {
global $$nomvar;
if (lireVarUrl($nomvar, $reecriture->param)) $$nomvar = lireVarUrl($nomvar, $reecriture->param);
}
}
}
?>