function arbreBoucle_dos($depart, $profondeur = 0, $i = 0)
{
    $rec = "";
    $i++;
    if ($i == $profondeur && $profondeur != 0) {
        return;
    }
    $tdossier = new Dossier();
    $query = "select * from {$tdossier->table} where parent=\"{$depart}\"";
    $resul = CacheBase::getCache()->query($query);
    if ($resul == "" || count($resul) == 0) {
        return "";
    }
    foreach ($resul as $row) {
        $rec .= $row->id . ",";
        $rec .= arbreBoucle_dos($row->id, $profondeur, $i);
    }
    return $rec;
}
Beispiel #2
0
function boucleContenu($texte, $args, $type = 0)
{
    global $page, $totbloc, $id_contenu;
    // récupération des arguments
    $dossier = lireTag($args, "dossier", "int");
    $ligne = lireTag($args, "ligne", "int");
    $deb = lireTag($args, "deb", "int");
    $num = lireTag($args, "num", "int");
    $bloc = lireTag($args, "bloc", "int");
    $id = lireTag($args, "id", "int_list");
    $motcle = lireTag($args, "motcle", "string+\\s\\'");
    $classement = lireTag($args, "classement", "string");
    $aleatoire = lireTag($args, "aleatoire", "int");
    $produit = lireTag($args, "produit", "int");
    $rubrique = lireTag($args, "rubrique", "int");
    $profondeur = lireTag($args, "profondeur", "int");
    $courant = lireTag($args, "courant", "int");
    $exclusion = lireTag($args, "exclusion", "int_list");
    $forcepage = lireTag($args, "forcepage", "int");
    if ($bloc) {
        $totbloc = $bloc;
    }
    if (!$deb) {
        $deb = 0;
    }
    if ($page) {
        $_SESSION['navig']->page = $page;
    }
    if (!$page || $page == 1) {
        $page = 0;
    }
    if (!$totbloc) {
        $totbloc = 1;
    }
    if ($page) {
        $deb = ($page - 1) * $totbloc * $num + $deb;
    }
    if ($forcepage != "") {
        if ($forcepage == 1) {
            $forcepage = 0;
            $deb = 0;
        }
        if ($forcepage) {
            $deb = ($forcepage - 1) * $totbloc * $num + $deb;
        }
    }
    // initialisation de variables
    $search = "";
    $order = "";
    $comptbloc = 0;
    $virg = "";
    $limit = "";
    $res = "";
    // preparation de la requete
    if ($dossier != "") {
        if ($profondeur == "") {
            $profondeur = 0;
        }
        $rec = arbreBoucle_dos($dossier, $profondeur);
        $rec = rtrim($rec, ",");
        if ($rec) {
            $virg = ",";
        }
        $search .= " and dossier in('{$dossier}'{$virg}{$rec})";
    }
    if ($ligne == "") {
        $ligne = "1";
    }
    $search .= " and ligne=\"{$ligne}\"";
    if ($id != "") {
        $search .= " and id in({$id})";
    }
    if ($courant == "1") {
        $search .= " and id='{$id_contenu}'";
    } else {
        if ($courant == "0") {
            $search .= " and id!='{$id_contenu}'";
        }
    }
    if ($exclusion != "") {
        $search .= " and id not in({$exclusion})";
    }
    if ($bloc == "-1") {
        $bloc = "999999999";
    }
    if ($bloc != "" && $num != "") {
        $limit .= " limit {$deb},{$bloc}";
    } else {
        if ($num != "") {
            $limit .= " limit {$deb},{$num}";
        }
    }
    $liste = "";
    if ($rubrique != "" || $produit != "") {
        if ($rubrique) {
            $type_obj = 0;
            $objet = $rubrique;
        } else {
            $type_obj = 1;
            $objet = $produit;
        }
        $contenuassoc = new Contenuassoc();
        $query = "select * from {$contenuassoc->table} where objet=\"" . $objet . "\" and type=\"" . $type_obj . "\"";
        $resul = CacheBase::getCache()->query($query);
        if (empty($resul)) {
            return "";
        }
        foreach ($resul as $row) {
            $liste .= "'" . $row->contenu . "',";
        }
        $liste = rtrim($liste, ",");
        if ($liste != "") {
            $search .= " and id in ({$liste})";
        } else {
            $search .= " and id in ('')";
        }
        $type_obj = "";
    }
    if ($aleatoire) {
        $order = "order by " . " RAND()";
    } else {
        if ($classement == "manuel") {
            $order = "order by classement";
        } else {
            if ($classement == "inverse") {
                $order = "order by classement desc";
            } else {
                if ($classement == "date") {
                    $order = "order by datemodif desc";
                }
            }
        }
    }
    $contenu = new Contenu();
    $contenudesc = new Contenudesc();
    if ($motcle) {
        $motcle = $contenu->escape_string(strip_tags(trim($motcle)));
        $liste = "";
        $query = "\n\t\t\t\tSELECT cd.contenu FROM\n\t\t\t\t\t{$contenudesc->table} cd\n\t\t\t\tWHERE\n                    cd.lang = " . ActionsLang::instance()->get_id_langue_courante() . "\n                AND (\n\t\t\t\t\tmatch(cd.titre, cd.chapo, cd.description, cd.postscriptum) AGAINST ('{$motcle}' IN BOOLEAN MODE)\n\t\t\t\tOR\n\t\t\t\t\tcd.titre REGEXP '[[:<:]]{$motcle}[[:>:]]'\n\t\t\t\tOR\n\t\t\t\t  \tcd.chapo REGEXP '[[:<:]]{$motcle}[[:>:]]'\n\t\t\t\tOR\n\t\t\t\t \tcd.description REGEXP '[[:<:]]{$motcle}[[:>:]]'\n\t\t\t\tOR\n\t\t\t\t \tcd.postscriptum REGEXP '[[:<:]]{$motcle}[[:>:]]'\n    \t\t\t)\n\t\t\t";
        $resul = CacheBase::getCache()->query($query);
        if (empty($resul)) {
            return "";
        }
        foreach ($resul as $row) {
            $liste .= "'{$row->contenu}',";
        }
        $liste = rtrim($liste, ',');
        $query = "select * from {$contenu->table} where id in ({$liste}) and ligne=\"{$ligne}\" {$limit}";
        $saveReq = "select * from {$contenu->table} where id in ({$liste}) and ligne=\"{$ligne}\"";
    } else {
        $query = "select * from {$contenu->table} where 1 {$search} {$order} {$limit}";
    }
    $saveReq = "select * from {$contenu->table} where 1 {$search}";
    $resul = CacheBase::getCache()->query($query);
    if (empty($resul)) {
        return "";
    }
    // substitutions
    if ($type) {
        return $query;
    }
    $saveReq = str_replace("*", "count(*) as totcount", $saveReq);
    $saveRes = CacheBase::getCache()->query($saveReq);
    $countRes = $saveRes[0]->totcount;
    $compt = 1;
    foreach ($resul as $row) {
        if ($num > 0) {
            if ($comptbloc >= ceil($countRes / $num) && $bloc != "") {
                continue;
            }
        }
        if ($comptbloc == 0) {
            $debcourant = 0;
        } else {
            $debcourant = $num * $comptbloc;
        }
        $comptbloc++;
        $dossierdesc = new Dossierdesc();
        $dossierdesc->charger($row->dossier);
        $contenudesc = new Contenudesc();
        $contenudesc->charger($row->id);
        $temp = $texte;
        $temp = str_replace("#DATE", substr($row->datemodif, 0, 10), $temp);
        $temp = str_replace("#HEURE", substr($row->datemodif, 11), $temp);
        $temp = str_replace("#DEBCOURANT", "{$debcourant}", $temp);
        $temp = str_replace("#ID", "{$row->id}", $temp);
        $temp = str_replace("#DOSSIER", "{$row->dossier}", $temp);
        $temp = str_replace("#TITRE", "{$contenudesc->titre}", $temp);
        $temp = str_replace("#STRIPTITRE", strip_tags($contenudesc->titre), $temp);
        $temp = str_replace("#CHAPO", "{$contenudesc->chapo}", $temp);
        $temp = str_replace("#STRIPCHAPO", strip_tags($contenudesc->chapo), $temp);
        $temp = str_replace("#DESCRIPTION", str_replace("../", "", $contenudesc->description), $temp);
        $temp = str_replace("#POSTSCRIPTUM", "{$contenudesc->postscriptum}", $temp);
        $temp = str_replace("#STRIPDESCRIPTION", strip_tags($contenudesc->description), $temp);
        $temp = str_replace("#URL", $contenudesc->getUrl(), $temp);
        $temp = str_replace("#REWRITEURL", $contenudesc->getUrl(), $temp);
        $temp = str_replace("#DOSTITRE", "{$dossierdesc->titre}", $temp);
        $temp = str_replace("#PRODUIT", "{$produit}", $temp);
        $temp = str_replace("#RUBRIQUE", "{$rubrique}", $temp);
        $temp = str_replace("#COMPT", "{$compt}", $temp);
        $res .= $temp;
        $compt++;
    }
    return $res;
}