";
echo "
";
// SET THESE VALUES...
// ----------------------
$namespace = 'csvtest'; // THIS IS THE ONLY VALUE YOU REALLY NEED TO CHANGE
// (except the next one if your filename is not in first column)
$pagename_column = array(8,9); // which column in the csv file contains
// the wiki page name to be created (starting from 0)
// IMPORTANT - MAKE SURE THIS IS CORRECT!
// Note: two columns can be combined to make unique filenames
// by using an array such as: $pagename_column = array(8,9);
// where data from columns 8 and 9 are combined
$OVERWRITE_FILES = FALSE; // you can set this to TRUE if you want to allow existing pages
// to be overwritten
// ---------------------------------------------------
$indexpage = 'start'; // the default dokuwiki page is 'start' but you can (if you wish)
// change this value so that a different index page is created
$csvfile = 'csvdata'; // the dokuwiki page in which you pasted the csv data
$templatefile = 'csvtemplate';// the dokuwiki page you created holding the template
// ----------------------
// DO NOT EDIT BELOW HERE
$outputfilepath = '../data/pages/'.$namespace.'/'; // where the page files are going to be created
$indexpagecontent = "=====REMINDER: DELETE THE CSVTODW FOLDER OFF YOUR SERVER!!!=====\r\n\r\n" .
"==== INDEX ====\r\n\r\n Pages created from csv data:\r\n\r\n----\r\n\r\n";
$dr = rtrim( $_SERVER['DOCUMENT_ROOT'], "/" ) .'/';
// get the template file contents
$template = file_get_contents($outputfilepath.$templatefile.'.txt');
// open the csv data file
$file = fopen($outputfilepath.$csvfile.'.txt', 'r');
// get field names from first row
$fieldnames = fgetcsv($file);
// if we have some fieldnames lets rock'n'roll
if ($fieldnames !== FALSE) {
if (array_count_values($fieldnames) >= 1) {
while (( $line = fgetcsv($file) ) !== FALSE) {
if ( !empty(array_filter($line)) ) {
// get clean copy of the template
$thispage = $template;
// set the output filename
if ( ! is_array($pagename_column) ) {
$outputfile = trim($line[$pagename_column]).'.txt';
} else {
$outputfile = '';
// combine column data into filename
foreach ($pagename_column as $col) {
$outputfile .= trim($line[$col]).'_';
}
$outputfile = rtrim($outputfile, "_").'.txt';
}
// clean output filename to dokuwiki standards
$ofclean = strtolower(preg_replace('/\s+/', '', $outputfile));
$indexpagecontent .= ' * [['.substr($ofclean, 0, -4)."|".substr($outputfile, 0, -4)."]]\r\n";
// replace the template [placeholder] names with content
foreach ($fieldnames as $key => $field) {
$thispage = str_replace('['.strtolower($field).']', $line[$key], $thispage);
}
echo "