$value) {
foreach ($value as $name2 => $value2) {
$value2 = stripslashes($value2);
$value2 = str_replace("|", "|", $value2);
$value2 = str_replace("\r\n", "__NEWL__", $value2);
$filecontents .= $value2 . ($name2 < count($value) - 1 ? "|" : "");
}
$filecontents .= ($name < count($data) - 1 ? "\r\n" : "");
}
$filehandle = fopen("./data/xfields.txt", "w");
if (!$filehandle)
msg("error", "XFields Error", "Could not save data to file \"./data/xfields.txt\", check if the file exists and is properly chmoded.");
fwrite($filehandle, $filecontents);
fclose($filehandle);
header("Location: http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"] .
"?mod=xfields&xfieldsaction=configure");
exit;
}
////////////
// Load XFields from a file, used when you do anything in the Options section.
function xfieldsload() {
$filecontents = file("{$GLOBALS["cutepath"]}/data/xfields.txt");
if (!is_array($filecontents))
msg("error", "XFields Error", "Could not load data from file \"{$GLOBALS["cutepath"]}/data/xfields.txt\", check if the file exists and is properly chmoded.");
foreach ($filecontents as $name => $value) {
$filecontents[$name] = explode("|", trim($value));
foreach ($filecontents[$name] as $name2 => $value2) {
$value2 = str_replace("|", "|", $value2);
$value2 = str_replace("__NEWL__", "\r\n", $value2);
$filecontents[$name][$name2] = $value2;
}
}
return $filecontents;
}
////////////
// Save XFields Data to a file, used when a news item is added/edited
function xfieldsdatasave($data) {
foreach ($data as $id => $xfieldsdata) {
foreach ($xfieldsdata as $xfielddataname => $xfielddatavalue) {
if ($xfielddatavalue == "") { unset($xfieldsdata[$xfielddataname]); continue;}
$xfielddataname = stripslashes($xfielddataname);
$xfielddatavalue = stripslashes($xfielddatavalue);
$xfielddataname = str_replace("|", "|", $xfielddataname);
$xfielddataname = str_replace("\r\n", "__NEWL__", $xfielddataname);
$xfielddatavalue = str_replace("|", "|", $xfielddatavalue);
$xfielddatavalue = str_replace("\r\n", "__NEWL__", $xfielddatavalue);
$filecontents[$id][] = "$xfielddataname|$xfielddatavalue";
}
$filecontents[$id] = "$id|>|" . implode("||", $filecontents[$id]);
}
$filecontents = @implode("\r\n", $filecontents);
$filehandle = fopen("./data/xfieldsdata.txt", "w");
if (!$filehandle)
msg("error", "XFields Error", "Could not save data to file \"./data/xfieldsdata.txt\", check if the file exists and is properly chmoded.");
fwrite($filehandle, $filecontents);
fclose($filehandle);
}
////////////
// Load XFields Data from a file, used when a your news is displayed or when you edit a news item.
function xfieldsdataload() {
$filecontents = file("{$GLOBALS["cutepath"]}/data/xfieldsdata.txt");
if (!is_array($filecontents))
msg("error", "XFields Error", "Could not load data from file \"{$GLOBALS["cutepath"]}/data/xfieldsdata.txt\", check if the file exists and is properly chmoded.");
foreach ($filecontents as $name => $value) {
list($id, $xfieldsdata) = explode("|>|", trim($value), 2);
$xfieldsdata = explode("||", $xfieldsdata);
foreach ($xfieldsdata as $xfielddata) {
list($xfielddataname, $xfielddatavalue) = explode("|", $xfielddata);
$xfielddataname = str_replace("|", "|", $xfielddataname);
$xfielddataname = str_replace("__NEWL__", "\r\n", $xfielddataname);
$xfielddatavalue = str_replace("|", "|", $xfielddatavalue);
$xfielddatavalue = str_replace("__NEWL__", "\r\n", $xfielddatavalue);
$data[$id][$xfielddataname] = $xfielddatavalue;
}
}
return $data;
}
}
$xfieldfunctionsdeclared = true;
// XField Structure: Name, Description, Category, Defaultvalue, Optional
$xfields = xfieldsload();
switch ($xfieldsaction) {
case "configure":
switch ($xfieldssubaction) {
case "delete":
unset($xfields[$xfieldsindex]);
@xfieldssave($xfields);
break;
case "add":
$xfieldsindex = count($xfields);
// Fall trough to edit
case "edit":
if (!isset($xfieldsindex))
msg("error", "XFields Error", "You should select an item to edit.
go back");
if (!$editedxfield) {
$editedxfield = $xfields[$xfieldsindex];
} elseif (strlen(trim($editedxfield[0])) > 0 and
strlen(trim($editedxfield[1])) > 0) {
foreach ($xfields as $name => $value) {
if ($name != $xfieldsindex and
$value[0] == $editedxfield[0]) {
msg("error", "XFields Error", "The name must be unique.
go back");
}
}
$editedxfield[0] = strtolower(trim($editedxfield[0]));
$editedxfield[4] = $editedxfield["4_{$editedxfield[3]}"];
unset($editedxfield["4_text"], $editedxfield["4_textarea"]);
$editedxfield[5] = ($editedxfield[5] == "on" ? 1 : 0);
ksort($editedxfield);
$xfields[$xfieldsindex] = $editedxfield;
ksort($xfields);
@xfieldssave($xfields);
break;
} else {
msg("error", "XFields Error", "You should fill in the name and description.
go back");
}
echoheader("options", (($xfieldssubaction == "add") ? "Add" : "Edit") . " XField");
$checked = ($editedxfield[5] ? " checked" : "");
?>