Skal lige siges det kommer fra en funktion dette:
Hele funktionen ser sådanne ud:
<?php
function visArtikel($idartikel,$template_dir, $image_dir, $filer_dir, $useDB) {
$mq_artikel = mysql_query("SELECT * FROM artikel WHERE idartikel = " . $idartikel);
$artikel = mysql_fetch_assoc($mq_artikel);
$fil = $template_dir . "/" . $artikel['template'];
$fp = fopen($fil,r);
$template = fread($fp,filesize($fil));
preg_match_all("|<BrugerFelt>(.*)</BrugerFelt>|U",$template,$out,PREG_PATTERN_ORDER);
for ($i=0;$i<sizeof($out[1]);$i++) {
$felt = split("\|",$out[1][$i]);
if ($useDB == true) {
$SQL = "SELECT felt_data FROM template_felt WHERE idartikel = " . $idartikel . " AND felt_id = '" . $felt[1]. "';";
$mq_felt = mysql_query($SQL) or die (mysql_error());
$arrfeltdata = mysql_fetch_assoc($mq_felt);
$feltdata = $arrfeltdata['felt_data'];
}
else {
$feltdata = $_REQUEST[$felt[1]];
$feltdata = str_replace("\\\"","\"",$feltdata);
$feltdata = str_replace("\\'","'",$feltdata);
}
if ($felt[0] == "linje") {
if ($feltdata != "") {
$vis = $felt[2] . $feltdata . $felt[3];
$template = str_replace($out[0][$i],$vis,$template);
}
else {
$template = str_replace($out[0][$i],"",$template);
}
}
if ($felt[0] == "tekst") {
if ($feltdata != "") {
#$vis = $felt[2] . nl2br($feltdata) . $felt[3];
$vis = $felt[2] . $feltdata . $felt[3];
$template = str_replace($out[0][$i],$vis,$template);
}
else {
$template = str_replace($out[0][$i],"",$template);
}
}
if ($felt[0] == "link") {
if ($feltdata != "") {
$feltArr = split("\|\|",$feltdata);
$vis = $felt[2] . "<a href='" . $feltArr[0] . "' target=_blank>" . $feltArr[1] . "</a>" . $felt[3];
$template = str_replace($out[0][$i],$vis,$template);
}
else {
$template = str_replace($out[0][$i],"",$template);
}
}
if ($felt[0] == "billede") {
$SQL = "SELECT * FROM artikel_images WHERE idartikel = '$idartikel'";
$mq = mysql_query($SQL) or die(mysql_error());
#$tael = mysql_num_rows($mq);
#echo $tael;
while($img = mysql_fetch_assoc($mq)){
#echo $SQL;
$input = "<img src='
http://www.ngo-traef.dk/admin/includes/show-image.php?image_id=".$img['image_id']."&idartikel=".$idartikel." style='border:1px solid #26405f; margin:1px;'>";
$template = str_replace($out[0][$i],$input,$template);
} // End while
#if (file_exists("$image_dir/artikler/$idartikel-" . $felt[1] . ".jpg")) {
# $input = $felt[2] . "<img style='page-break-inside: auto; margin: 5px' src='" . "$image_dir/resizer.php?imgtype=artikler&imgname=$idartikel-" . $felt[1] . ".jpg&maxWidth=" . $felt[5] . "&maxHeight=" . $felt[4] . "&time=" . time() . "' ";
# $input .= "class='" . $felt[7] . "' align='" . $felt[6] . "'>" . $felt[3];
#}
#else {
# $template = str_replace($out[0][$i],"",$template);
#}
}
if ($felt[0] == "fil") {
$SQL = "SELECT * FROM filer WHERE idartikel = " . $idartikel . ";";
$mq_filer = mysql_query($SQL) or die (mysql_error());
if (mysql_num_rows($mq_filer) > 0) {
$vis = $felt[2] . "<ul>";
while ($fil = mysql_fetch_assoc($mq_filer)) {
$vis .= "<li><a target='_blank' href='" . $filer_dir . "/" . $fil['idfiler'] . "/" . $fil['filnavn'] . "'>" . $fil['beskrivelse'] . "</a>";
}
$vis .= "</ul>" . $felt[3];
$template = str_replace($out[0][$i],$vis,$template);
}
else {
$template = str_replace($out[0][$i],"",$template);
}
}
}
#$datoArr = split("-",$artikel['dato']);
#$datoArr = array_reverse($datoArr);
#$template .= "<div align=right>/" . join(".",$datoArr) . "</div>";
return $template;
}
?>
----------------------------------------------
Og kalder den her:
<?
require("../admin/includes/config.inc.php");
require("../admin/lib/vis_artikel.php");
$idartikel = $_REQUEST['idartikel'];
echo visArtikel($idartikel,"../admin/artikel-templates", "../filer", true);
?>