$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" : ""); ?>
" method="post" name="xfieldsform">

Enter the name of the field.
Enter the description of the field.
The category ids where the XFields should appear, empty for all categories.
The type of the XField.
> Enter the default value for a column. (optional) > Enter the default value for a column. (optional)
style="width: 150px;" /> Check if this field is optional.

" method="post" name="xfieldsform"> $value) { $rowstyle = ($name & 1) ? $rowstyleodd : $rowstyleeven; ?>
Name Description Categories Type Default Value Optional  
0) { ?>Action:    
$value) { if (!$xfieldsadd) $value[4] = $xfieldsdata[$xfieldsid][$value[0]]; $showfield = ((int)$value[2] == 0 or (int)$value[2] == $xfieldscat); ?> > >
"; break; case "textarea": echo ""; break; default: echo "XFields Error: Invalid field type, your \"./data/xfieldsdata.txt\" file could be damaged!"; } ?>
$value) { if ($value[2] and !in_array($category, explode(",", $value[2]))) { continue; } $postedxfields[$value[0]] = trim($postedxfields[$value[0]]); if ($value[5] == 0 and !strlen($postedxfields[$value[0]]) > 0) msg("error", "XFields Error", "You should fill in all required fields.
go back"); $newpostedxfields[$value[0]] = $postedxfields[$value[0]]; } $postedxfields = $newpostedxfields; break; case "save": // Make sure it is first initialized if (!empty($postedxfields)) { $xfieldsdata = xfieldsdataload(); $xfieldsdata[$xfieldsid] = $postedxfields; @xfieldsdatasave($xfieldsdata); } break; case "delete": $xfieldsdata = xfieldsdataload(); unset($xfieldsdata[$xfieldsid]); @xfieldsdatasave($xfieldsdata); break; case "templatereplace": $xfieldsdata = xfieldsdataload(); $xfieldsoutput = $xfieldsinput; foreach ($xfields as $value) { $preg_safe_name = preg_quote($value[0]); if ($value[5] != 0) if (empty($xfieldsdata[$xfieldsid][$value[0]])) $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\].*?\\[/xfgiven_{$preg_safe_name}\\]'i", "", $xfieldsoutput); else $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'i", "\\1", $xfieldsoutput); $xfieldsoutput = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", $xfieldsdata[$xfieldsid][$value[0]], $xfieldsoutput); } break; case "templatereplacepreview": $xfieldsoutput = $xfieldsinput; foreach ($xfields as $value) { $preg_safe_name = preg_quote($value[0]); if ($value[5] != 0) if (empty($xfieldsdata[$value[0]])) $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\].*?\\[/xfgiven_{$preg_safe_name}\\]'i", "", $xfieldsoutput); else $xfieldsoutput = preg_replace("'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'i", "\\1", $xfieldsoutput); $xfieldsoutput = preg_replace("'\\[xfvalue_{$preg_safe_name}\\]'i", $xfieldsdata[$value[0]], $xfieldsoutput); } break; case "categoryfilter": echo << function ShowOrHideEx(id, show) { var item = null; if (document.getElementById) { item = document.getElementById(id); } else if (document.all) { item = document.all[id]; } else if (document.layers){ item = document.layers[id]; } if (item && item.style) { item.style.display = (show)?"":"none"; } else { item.visibility = "show"; } } function onCategoryChange(value) { HTML; foreach ($xfields as $value) { $categories = str_replace(",", "||value==", $value[2]); if ($categories) { echo "ShowOrHideEx(\"xfield_holder_{$value[0]}\", (value=={$categories})?true:false);"; } } echo "}"; break; default: msg("error", "XFields Error", "Invalid Request, maybe you found a bug in XFields."); } ?>
Historical archive. This is a preserved copy of 36 Degrees Design (2005–2008), the early web-design weblog of Stuart Frisby. It is maintained independently as a piece of web history and is not operated by, affiliated with, or endorsed by Stuart Frisby. If you are the original owner and would like this domain returned, get in touch — it’s yours, no fuss.