[pmwiki-users] FOX-question: reading / writing plain text files ?

Hans design5 at softflow.co.uk
Sat Feb 6 07:39:45 CST 2010


Saturday, February 6, 2010, 11:33:29 AM, Hans wrote:

> PS: another approach might be to manipulate the $EditFunctions array.
> Write a function which will save to text file (using the php functions
> fopen, fwrite, fclose), add it to $EditFunctions array, and remove
> 'PostPage' from it. This could be done without hacking fox.php.

Just played with this idea. Here is a simple working example.
The pub/textfiles/ directory needs to be created first.
The idea is to use group 'Text' as target group, so when Fox gets
target with 'Text' as group name, it will post the Name as text file.
Make sure the Fox form has a 'group' field, to be set to 'Text'.

$group = PageVar($pagename, '$Group');
if ($action=='foxpost' && $_POST['group']=='Text') {
  $FoxExcludeEditFunctions[] ='PostPage';
  array_unshift($EditFunctions, 'PostTextFile');
}
function PostTextFile ($pagename, $page, $new) {
  global $IsPagePosted;
  $name = PageVar($pagename, '$Name');
  $TextFilesDir = "pub/textfiles/";
  $TextFilesExt = ".txt";
  $filename = FmtPageName($TextFilesDir.$name.$TextFilesExt, $pagename);
  $file = fopen($filename, "a+");
  $text = $new['text'];
  fwrite($file, $text);
  fclose($file);
  $GLOBALS['IsPagePosted'] = true;
}



  ~Hans




More information about the pmwiki-users mailing list