function build($argv) { global $_plugin; global $success; global $error; global $errors; prompt('WARNING: Building fixtures clear all data from your table; are you sure you want to do this?') or $error = $errors['aborted']; if (!$error) { require_once $_plugin['dir']['fixtures'] . $argv[3] . '.php'; # Let's get connected! db_connect(); use_db(); # Truncate table. echo 'Truncating ' . $argv[3] . ' table...' . "\n\n"; $query = mysql_query('TRUNCATE ' . $argv[3]); foreach ($_fixtures as $_fixture) { $query = ' INSERT INTO ' . $argv[3] . ' (' . implode(',', array_keys($_fixture)) . ') VALUES (' . implode(',', array_values(enquote($_fixture))) . ') '; //add option to display this? echo 'Running the following query:'; echo "\n" . $query . "\n\n"; if (mysql_query($query)) { $success = 'fixtures for the table: ' . $argv[3] . ' have been succesfully built!'; } else { $error = mysql_error(); } } } }
//header('Content-Type: text/plain'); // Dump column names $fc = $rs->FieldCount(); for ($i = 0; $i < $fc; $i++) { $f = $rs->FetchField($i); $fn = $f->name; if ($i != 0) { print ","; } print csv_encoded($fn); } print "\n"; // Dump data $rc = $rs->RecordCount(); while (!$rs->EOF) { for ($i = 0; $i < $fc; $i++) { $v = $rs->Fields($i); if ($i != 0) { print ","; } print csv_encoded($v); } print "\n"; $rs->MoveNext(); } print "{$rc},records\n"; $msg = enquote($sql); log_event("Records exported: {$msg}"); } else { print "Error,{$sql}\n"; }
header("Expires: 0"); } else { header("Content-type: text/plain; charset=utf-8"); } function enquote($string) { $string = str_replace("\"", "\"\"", $string); $string = html_entity_decode($string); return "\"{$string}\""; } echo "#,Title,Summary,School,Description,Keywords,Link\n"; $i = 1; foreach ($combined as $f) { $f = (object) $f; $iswse = (bool) stristr($f->school, "Whiting"); $isksas = (bool) stristr($f->school, "Krieger"); $line = array(); $line[] = $i++; $line[] = enquote($f->post_title_import); $line[] = enquote($f->summary_import); $line[] = $iswse ? "WSE" : "KSAS"; $line[] = enquote($f->summary_import); $line[] = empty($f->keywords_import) ? "none" : enquote($f->keywords_import); $line[] = ($iswse ? "http://engineering.jhu.edu/?post_type=department&p=" : "http://flagship.dev/?post_type=studyfields&p=") . $f->_id_import; echo implode(",", $line) . "\n"; } } else { header("Content-type: application/json"); echo json_encode($combined); die; }