Пример #1
0
    $judul_content = isset($_POST['judul_content']) ? $_POST['judul_content'] : NULL;
    $kode_kategori = isset($_POST['kode_kategori']) ? $_POST['kode_kategori'] : NULL;
    $penulis = isset($_POST['penulis']) ? $_POST['penulis'] : NULL;
    $content = isset($_POST['content']) ? $_POST['content'] : NULL;
    $keyword = isset($_POST['keyword']) ? $_POST['keyword'] : NULL;
    $deskripsi = isset($_POST['deskripsi']) ? $_POST['deskripsi'] : NULL;
    $status = isset($_POST['status']) ? $_POST['status'] : NULL;
    if ($status == "lama") {
        $response = update_content($kode_content, $judul_content, $kode_kategori, $penulis, $content, $keyword, $deskripsi);
        if ($response == 1) {
            header('location:index.php?page=content&message=2');
        } else {
            header('location:index.php?page=content&message=0');
        }
    } else {
        $response = insert_content($judul_content, $kode_kategori, $penulis, $content, $keyword, $deskripsi);
        if ($response == 1) {
            header('location:index.php?page=content&message=1');
        } else {
            header('location:index.php?page=content&message=0');
        }
    }
} else {
    if (isset($_GET['action'])) {
        if ($_GET['action'] == "delete") {
            $response = delete_content($_GET['kode']);
            if ($response == 1) {
                header('location:index.php?page=content&message=3');
            } else {
                header('location:index.php?page=content&message=0');
            }
// Bootstrap Drupal
include_once "includes/bootstrap.inc";
include_once "includes/common.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// CSV file containing the data to import.
// For simplicity I place this in the root of the Drupal
// site and remove it when done.
$data_archive = 'mn1.csv';
// Content information... This is the CCK type data you wish to import to.
// It needs to match exactly your created content type information.
$content_type = 'eis_meeting_notes';
$content_name = 'EIS Meeting Notes';
// Check for the script being enabled, and for appropriate permissions.
if ($active) {
    if (user_access("administer content types")) {
        insert_content($content_type, $data_archive);
    } else {
        print "You don't have permission to administer content types.";
    }
} else {
    print "Variable active is set to false.";
}
function insert_content($content_type, $data_archive)
{
    // Open the CSV file read only.
    $handle = fopen($data_archive, "r");
    // Read the headers from the first line.
    $theHeaders = fgetcsv($handle);
    // Keep count of how many lines we have processed.
    $lineno = 0;
    while ($line = fgetcsv($handle)) {
Пример #3
0
$active = FALSE;
//This modified script inputs data based upon the first row in your CSV file, the header row. Your headers must match the fields of the node object in order for any data to be saved. For example, you should have columns for title, body, and type (type is the node type).
//Look at the translate_value function to see field types I've already accounted for. You will need to match the key values for special things like organic groups and CCK.
//If you're using CCK, make sure to include YOUR custom field machine-readable field names in the list of cases. For most fields, you can just include them in the big list of cases. If the field needs to be submitted with something other than the [0] => [value] => "value" format, you need to add a special case.
// CODE
include_once "includes/bootstrap.inc";
include_once "includes/common.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$archive_data = 'files/data_file.csv';
// must point to your data file, which must have proper header row
print "Script working<br />";
if ($active) {
    if (user_access("administer content types")) {
        print "Processing begins \n";
        print '<pre>';
        $nodes_array = insert_content($archive_data);
        print_r($nodes_array);
        // prints the array of nodes the script gathered from your file, for debugging purposes only
        print '</pre>';
    } else {
        print "You don't have permission to administer this content type";
    }
} else {
    print "Import script is not active. Change the active variable to TRUE to activate";
}
// this function translates a cell in your CSV file and inserts it into the $node array
// the postpone variable is for fields that should be added to the node object AFTER _validate and _submit for whatever reason; I use it here for organic groups
function translate_value($key, $value, $headers, &$node, &$postpone)
{
    switch ($headers[$key]) {
        // this first batch is generic node stuff