Input file '$infile' not found. Nothing done\n\n"; exit; } foreach ($lines as $l) { if (! preg_match('/file=(\S+)\s*;/', $l, $m)) { // This is a file to read print "\n========> No file=name found in file '$infile': $l\n\n"; continue; } $f = $indir . trim($m[1]); if (! preg_match('/title=([^;]+);/', $l, $m)) { // This is title print "\n========> No title=name found in file '$infile': $l\n\n"; continue; } $t = trim($m[1]); $ts=''; if (preg_match('/taxonomy=(\S+)\s*;/', $l, $m)) { // This is taxonomy $ts = trim($m[1]); } $b = file_get_contents($f); if (! $b) { print "\n========> Unable to read file '$f'\n\n"; continue; } //$t = "Terry's Test node 3"; //$b = "
here is a paragraph<\p>\n"; //$ts = 'aaron,Books,1995'; // Load data from this file, title, body and taxonomy string loaddata($t, $b, $ts); //print "\n++++> Create node title='$t' (" . strlen($b) . " chars) tax='$ts' file=$f\n"; } exit; function loaddata($title, $body, $tax) { global $taxonomies, $rarray; $mynode = array(); $mynode['title'] = $title; // all content types have names which are given at the time of the content type creation. // visible at content types page when you drag your mouse over the list of content types $mynode['type'] = 'page'; //$mynode['name'] = "thenameoftheusersubmittingthepage"; // not necessary $mynode['body'] = $body; // published=1 or unpublished=0 content $mynode['status'] = 1; // uid is user id, the user id 1 being the id of the one who makes first id after // a drupal installation, uid 1 has all prvilleged, make sure your user id comes // with all privileges,preferably use userid 1 to save yourself from the hassle. $mynode['uid'] = 1; // promote =0 doesn't promote the content to the front page // whereas promote=1 promotes the content to the front page $mynode['promote'] = 0; // comment 0=off , comment 1=readonly, comment 2=allowed $mynode['comment'] = '0'; // inputformat, format=0 means Filtered HTML,format=1 means PHP code , format=2 means Full HTML $mynode['format'] = '2'; // Set taxonomy settings, if they exist // See http://drupal.org/node/67887 $o = (object)$mynode; if ($tax) { gettaxonomy($tax); $o->taxonomy[] = &$taxonomies; } // Create the node and save it $newnode = node_submit($o); node_save($newnode); // Hack to get values from object to prove it really worked $r = print_r($newnode, 1); //print "++> $r <++\n"; $rarray = explode("\n",$r); $t = getvalue('title'); $n = getvalue('nid'); $v = getvalue('vid'); if ($n == '') { print "WARNING - no object created\n"; } else { print "\n========> Created Page '$n' ($t)\n\n"; } } // gettaxonomy('aaron,Books,1995'); // // Set $taxonomies based on comma delimited string of taxonomies // I chose to hard code all the taxonomy details here. // A better choice would be to read the table term_data // and extract the keys and values which are hardcoded below. function gettaxonomy($taxstr) { global $taxonomies; // $taxonomies is based on values from term_data $tgroup = array (1 => 'aaron', 2 => 'board'); $ttopic = array (3=> 'SIC', 4 => 'Wed',5 => 'Books',6 => 'Dharma',7 => 'Retreats', 8 => 'Other'); $tyear = array ( 9 => '1992', 10 => '1993', 11 => '1994', 12 => '1995', 13 => '1996', 14 => '1997', 15 => '1998', 16 => '1999', 17 => '2000', 18 => '2001', 19 => '2002', 20 => '2003', 21 => '2004', 22 => '2005', 23 => '2006', 24 => '2007', 25 => '2008', 26 => '1990', 27 => '1991', 28 => '1989' ); // Split taxonomies into three parts $a = explode(',', $taxstr); $taxonomies = array(); $taxonomies[0] = array_search($a[0], $tgroup); $taxonomies[1] = array_search($a[1], $ttopic); $taxonomies[2] = array_search($a[2], $tyear); return $arr; } // getvalue('title'); // // Get part of string from $rarray function getvalue($k) { global $rarray; reset($rarray); foreach ($rarray as $l) { if (preg_match("/\[$k\] => (.+)/", $l, $m)) { return $m[1]; } } return ''; } ?>