You are here

function joomla_myblog_process_node in Joomla to Drupal 6

1 call to joomla_myblog_process_node()
joomla_myblog_joomla in ./joomla_myblog.module

File

./joomla_myblog.module, line 143

Code

function joomla_myblog_process_node($node = NULL, $contentid = NULL) {
  if ($node === NULL) {
    return;
  }
  db_set_active('joomla');

  // Check to see if there is a myblog tag for this content item
  $myblogcategory = db_fetch_object(db_query('SELECT mcc.category,mc.name FROM %smyblog_content_categories mcc JOIN %smyblog_categories mc on mc.id = mcc.category WHERE mcc.contentid = %d', variable_get('joomla_prefix', JOOMLA_PREFIX), variable_get('joomla_prefix', JOOMLA_PREFIX), $contentid));
  db_set_active();

  // If this is not a myblog content item, there's nothing left to do
  if (!$myblogcategory->category) {
    return;
  }

  // Get the taxonomy term id for this myblog category
  $myblog_map = db_fetch_object(db_query('SELECT * FROM {joomla_myblog_categories} WHERE myblogcategoryid = %d', $myblogcategory->category));
  $vid = joomla_myblog_get_vocabulary_id();
  if (!$myblog_map) {

    // Create a new taxonomy term
    $term = new stdClass();
    $term->name = $myblogcategory->name;
    $term->description = $myblogcategory->name;
    $term->vid = $vid;
    drupal_write_record('term_data', $term);
    $term_hierarchy = new stdClass();
    $term_hierarchy->tid = $term->tid;
    $term_hierarchy->parent = 0;
    drupal_write_record('term_hierarchy', $term_hierarchy);
    $myblog_map = new stdClass();
    $myblog_map->myblogcategoryid = $myblogcategory->category;
    $myblog_map->tid = $term->tid;
    drupal_write_record('joomla_myblog_categories', $myblog_map);
  }

  // Create a node <-> taxonomy link
  $term_node = new stdClass();
  $term_node->tid = $myblog_map->tid;
  $term_node->vid = $node->vid;
  $term_node->nid = $node->nid;
  drupal_write_record('term_node', $term_node);
}