午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    批量導(dǎo)入XML數(shù)據(jù)到drupal系統(tǒng)的方法
    來源:易賢網(wǎng) 閱讀:1013 次 日期:2015-04-13 14:59:14
    溫馨提示:易賢網(wǎng)小編為您整理了“批量導(dǎo)入XML數(shù)據(jù)到drupal系統(tǒng)的方法”,方便廣大網(wǎng)友查閱!

    本文實例講述了批量導(dǎo)入XML數(shù)據(jù)到drupal系統(tǒng)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

    如果你想把其它網(wǎng)站的數(shù)據(jù)批量導(dǎo)入到drupal系統(tǒng)中,可以采用本文所述代碼。前提條件是,你要把原來網(wǎng)站的數(shù)據(jù)生成XML格式!

    生成XML的工具有很多,有個叫 xml.class.php的類,可以試用一下,你也可以自己寫PHP代碼來實現(xiàn)。

    生成XML文件后,通過這個模塊,直接上傳,就可以把它導(dǎo)入到drupal系統(tǒng)了。

    該模塊還可以對你導(dǎo)入的數(shù)據(jù)進(jìn)行自動分類(Taxonomy整合)。

    以下為該模塊的部分精華源代碼,感興趣的朋友可以測試運(yùn)行一下本實例。主要功能代碼如下:

    復(fù)制代碼代碼如下:<?php

    function import_form_submit($form, &$form_state) {

    $validators = array('file_validate_extensions' => array('upload_file'),);

    if ($file = file_save_upload('upload_file', $validators)) {

    $fd = fopen($file->filepath, "rb");

    if (!$fd) {

    form_set_error('upload_file', t('Import failed: file %filename cannot be read.', array('%filename' => $file->filename)));

    }

    else {

    $info = fstat($fd);

    $len = $info["size"];

    $text = fread($fd, $len);

    fclose($fd);

    drupal_set_message(t('Loaded file %filename. Now processing it.', array('%filename' => $file->filename)));

    $form_state['values']['file'] = $file;

    import_xml_invoke_import($text, $form_state['values']);

    }

    }

    else {

    form_set_error('upload_file', t('Import failed: file was not uploaded.'));

    }

    }

    function parseMol($mvalues) {

    for ($i=0; $i < count($mvalues); $i++)

    $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];

    return new ImportXml($mol);

    }

    class ImportXml {

    var $tushushangpin;

    var $shangpindaima;

    var $shuming;

    var $congshuming;

    var $fushucongshuming;

    var $zhuzuozhe;

    var $chubanzhe;

    var $benbanbanci;

    var $yinci;

    var $dingjia;

    function ImportXml ($aa) {

    foreach ($aa as $k=>$v)

    $this->$k = $aa[$k];

    }

    }

    /**

    * Do the actual importing from the given string, pased on the parameters passed

    * from the form.

    *

    * @param $text

    */

    function import_xml_invoke_import(&$text) {

    // parse the data:

    $xml_parser = drupal_xml_parser_create($text);

    xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);

    xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1);

    xml_parse_into_struct($xml_parser,$text,$values,$tags);

    xml_parser_free($xml_parser);

    // now begin fetch the value

    foreach ($tags as $key=>$val) {

    if ($key == "tushushangpin") {

    $molranges = $val;

    for ($i=0; $i < count($molranges); $i+=2) {

    $offset = $molranges[$i] + 1;

    $len = $molranges[$i + 1] - $offset;

    $tdb[] = parseMol(array_slice($values, $offset, $len));

    }

    } else {

    continue;

    }

    }

    foreach($tdb as $value){

    $node = array();

    $node = new stdClass;

    $node->type = "product";

    $node->status = 1;

    $node->uid = 1;

    $node->title = $value->shuming;

    // $node->body = $value->neirongtiyao;

    $node->field_product_shangpindaima[0]['value'] = $value->shangpindaima;

    $node->field_product_shuming[0]['value'] = $value->shuming; // use ubercart

    $node->field_product_congshuming[0]['value'] = $value->congshuming;

    $node->field_product_fushucongshuming[0]['value'] = $value->fushucongshuming;

    $node->field_product_zhuzuozhe[0]['value'] = $value->zhuzuozhe;

    $node->field_product_chubanzhe[0]['value'] = $value->chubanzhe;

    $node->field_product_benbanbanci[0]['value'] = $value->benbanbanci;

    $node->field_product_yinci[0]['value'] = $value->yinci;

    $node->field_product_dingjia[0]['value'] = $value->dingjia;

    // if $value->tongjifenlei is not null then :

    if($value->tongjifenlei){

    $tj_vid = 1;

    if($tid = (int) db_result(db_query('SELECT tid FROM {term_data} WHERE name = "%s" AND vid = %d', $value->tongjifenlei,$tj_vid))){

    $tj_tid = $tid;

    }else{

    // vocabulary ID is hard coded for this example

    $autoterm = array(

    'name' => $value->tongjifenlei, // or whatever you want the auto-term to be named

    'parent' => 0,

    'vid' => $tj_vid,

    );

    taxonomy_save_term($autoterm);

    $tj_tid = (int) db_result(db_query('SELECT MAX(tid) FROM {term_data} WHERE vid = %d', $vid));

    }

    $node->taxonomy[$tj_vid][$tj_tid] = $tj_tid;

    }

    node_save($node);

    }

    drupal_set_message("Import Successful!");

    }

    ?>

    希望本文所述對大家的drupal建站有所幫助。

    更多信息請查看IT技術(shù)專欄

    更多信息請查看CMS教程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:批量導(dǎo)入XML數(shù)據(jù)到drupal系統(tǒng)的方法
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
    相關(guān)閱讀CMS教程

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機(jī)號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)