| 1 |
<?php |
<?php |
| 2 |
// $Id: core.inc,v 1.1.2.12 2009/07/01 02:40:56 dman Exp $ |
// $Id: core.inc,v 1.1.2.13 2009/09/09 06:47:22 dman Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Basic per-module functionality used by import_html. |
* Basic per-module functionality used by import_html. |
| 6 |
* |
* |
| 7 |
* Each available module MAY implement a hook_import_html() function to add or |
* Each available module MAY implement a hook_import_html() function to add or |
| 8 |
* manipulate its own data as the node gets saved. |
* manipulate its own data as the node gets saved. |
| 9 |
* |
* |
| 10 |
* This set defines the known core module attributes that can be added to a node |
* This set defines the known core module attributes that can be added to a node |
| 11 |
* when importing. It sets the node (content & title) values, the menu and path |
* when importing. It sets the node (content & title) values, the menu and path |
| 12 |
* values, and possibly some taxonomy tags. |
* values, and possibly some taxonomy tags. |
| 13 |
* |
* |
| 14 |
* Each of these (pretty integral) attributes is set in a modular way as an |
* Each of these (pretty integral) attributes is set in a modular way as an |
| 15 |
* example for extensions, and to keep the central import_html codebase lighter. |
* example for extensions, and to keep the central import_html codebase lighter. |
| 16 |
* |
* |
| 17 |
* |
* |
| 18 |
* @ingroup import_html Import HTML |
* @ingroup import_html Import HTML |
| 19 |
* @author Dan Morrison http://coders.co.nz/ |
* @author Dan Morrison http://coders.co.nz/ |
| 20 |
*/ |
*/ |
| 21 |
|
|
| 22 |
|
|
| 23 |
/************************************************** |
/************************************************** |
| 24 |
* NODE |
* NODE |
| 25 |
**************************************************/ |
**************************************************/ |
| 26 |
|
|
| 27 |
/** |
/** |
| 28 |
* Implementation of hook_import_html |
* Implementation of hook_import_html |
| 29 |
* |
* |
| 30 |
* Add appropriate normal node attributes - title, body and teaser |
* Add appropriate normal node attributes - title, body and teaser |
| 31 |
* - to the node |
* - to the node |
| 32 |
*/ |
*/ |
| 33 |
function node_import_html($profile, &$node, $datadoc = NULL) { |
function node_import_html($profile, &$node, $datadoc = NULL) { |
| 34 |
// Setting a few basics will just avoid 'undefined' complaints when previewing |
// Setting a few basics will just avoid 'undefined' complaints when previewing |
| 35 |
$node->nid = isset($node->nid) ? $node->nid : 0; |
$node->nid = isset($node->nid) ? $node->nid : 0; |
| 36 |
$node->sticky = isset($node->sticky) ? $node->sticky : FALSE; |
$node->sticky = isset($node->sticky) ? $node->sticky : FALSE; |
| 37 |
|
|
| 38 |
|
|
| 39 |
// |
// |
| 40 |
// Title |
// Title |
| 41 |
// Note, internally the title should always be plaintext, encoded characters and no newlines |
// Note, internally the title should always be plaintext, encoded characters and no newlines |
| 42 |
// A meta 'title' may have been set, |
// A meta 'title' may have been set, |
| 43 |
// but I'll use the real visible one by preference. |
// but I'll use the real visible one by preference. |
| 44 |
$h1 = xml_get_element_content($datadoc, 'h1'); |
$h1 = xml_get_element_content($datadoc, 'h1'); |
| 45 |
if ($h1) { |
if ($h1) { |
| 46 |
$node->title = $h1; |
$node->title = $h1; |
| 47 |
} |
} |
| 48 |
else { |
else { |
| 49 |
$title_elem = xml_get_element_content($datadoc, 'title'); |
$title_elem = xml_get_element_content($datadoc, 'title'); |
| 50 |
if ($title_elem) { |
if ($title_elem) { |
| 54 |
|
|
| 55 |
// |
// |
| 56 |
// BODY is the thing with id=content or whatever is set in the prefs |
// BODY is the thing with id=content or whatever is set in the prefs |
| 57 |
// |
// |
| 58 |
import_html_debug_code('XML DOM being scanned for XPATH data extraction to find the body content', xml_tostring($datadoc)); |
import_html_debug_code('XML DOM being scanned for XPATH data extraction to find the body content', xml_tostring($datadoc)); |
| 59 |
$content_element = xml_getelementbyid($datadoc, 'content'); |
$content_element = xml_getelementbyid($datadoc, 'content'); |
| 60 |
|
|
| 61 |
if (!$content_element) { |
if (!$content_element) { |
| 62 |
import_html_debug("Failed to find a body, anything with id='content' in this page", array(), WATCHDOG_NOTICE); |
import_html_debug("Failed to find a body, anything with id='content' in this page", array(), WATCHDOG_NOTICE); |
| 71 |
$node->import_html_precision = $precision; |
$node->import_html_precision = $precision; |
| 72 |
$explanation = xml_getattribute($content_element, 'title'); |
$explanation = xml_getattribute($content_element, 'title'); |
| 73 |
import_html_debug( |
import_html_debug( |
| 74 |
"I'm %precision % confident that we found the right body element. !explanation", |
"I'm %precision % confident that we found the right body element. !explanation", |
| 75 |
array('%precision' => 100*$precision, '!explanation' => $explanation), |
array('%precision' => 100*$precision, '!explanation' => $explanation), |
| 76 |
WATCHDOG_INFO |
WATCHDOG_INFO |
| 77 |
); |
); |
| 87 |
// |
// |
| 88 |
// Teaser |
// Teaser |
| 89 |
// |
// |
| 90 |
$teaser = xml_textcontent( xml_getelementbyid($datadoc, 'teaser') ); |
$teaser = xml_textcontent( xml_getelementbyid($datadoc, 'teaser') ); |
| 91 |
$description = xml_textcontent( xml_getelementbyid($datadoc, 'description') ); |
$description = xml_textcontent( xml_getelementbyid($datadoc, 'description') ); |
| 92 |
if (!$teaser) $teaser = $description ; |
if (!$teaser) $teaser = $description ; |
| 93 |
if ($teaser) { |
if ($teaser) { |
| 102 |
/* |
/* |
| 103 |
// No custom teaser found, but |
// No custom teaser found, but |
| 104 |
// Imported HTML is highly likely to contain formatting that |
// Imported HTML is highly likely to contain formatting that |
| 105 |
// will ruin teasers. Do our own cut-down version that assumes |
// will ruin teasers. Do our own cut-down version that assumes |
| 106 |
// FILTERED HTML |
// FILTERED HTML |
| 107 |
if (!$teaser) { |
if (!$teaser) { |
| 108 |
$teaser = filter_filter('process', 0, 1, node_teaser($node->body)); |
$teaser = filter_filter('process', 0, 1, node_teaser($node->body)); |
| 120 |
/************************************************** |
/************************************************** |
| 121 |
* USER |
* USER |
| 122 |
**************************************************/ |
**************************************************/ |
| 123 |
|
|
| 124 |
/** |
/** |
| 125 |
* Implementation of hook_import_html |
* Implementation of hook_import_html |
| 126 |
* |
* |
| 127 |
* Add appropriate user identification to the new node. |
* Add appropriate user identification to the new node. |
| 128 |
*/ |
*/ |
| 129 |
function user_import_html($profile, &$node, $datadoc = NULL) { |
function user_import_html($profile, &$node, $datadoc = NULL) { |
| 130 |
global $user; |
global $user; |
| 131 |
$node->uid = $user->uid; |
$node->uid = $user->uid; |
| 145 |
* its namespace. Miscellaneous class HTML import may create an attribute called |
* its namespace. Miscellaneous class HTML import may create an attribute called |
| 146 |
* 'menu'. That would be bad. |
* 'menu'. That would be bad. |
| 147 |
*/ |
*/ |
| 148 |
function menu_import_html($profile, &$node, $datadoc = NULL) { |
function menu_import_html($profile, &$node, $datadoc = NULL) { |
| 149 |
unset($node->menu); |
unset($node->menu); |
| 150 |
} |
} |
| 151 |
|
|
| 152 |
// |
// |
| 153 |
// This is currently a freaking mess. I don't know what the menu router is trying to do these days. |
// This is currently a freaking mess. I don't know what the menu router is trying to do these days. |
| 154 |
// |
// |
| 155 |
|
|
| 156 |
/** |
/** |
| 157 |
* Set alias and navigation for the given node |
* Set alias and navigation for the given node |
| 158 |
* Helper for import_html_import_files() |
* Helper for import_html_import_files() |
| 170 |
import_html_debug("We will re-use the existing menu item, and keep its place in the sitemap"); |
import_html_debug("We will re-use the existing menu item, and keep its place in the sitemap"); |
| 171 |
} |
} |
| 172 |
else { |
else { |
| 173 |
// Check if a placeholder menu for the alias exists. |
// Check if a placeholder menu for the alias exists. |
| 174 |
// This can happen if the child items were created earlier and required a placeholder |
// This can happen if the child items were created earlier and required a placeholder |
| 175 |
// Try both canonic and aliased paths |
// Try both canonic and aliased paths |
| 176 |
if ( ! $menu = menu_get_item_by_path($normal_path) ) { |
if ( ! $menu = menu_get_item_by_path($normal_path) ) { |
| 178 |
} |
} |
| 179 |
} |
} |
| 180 |
// $menu is a menu_link array |
// $menu is a menu_link array |
| 181 |
|
|
| 182 |
if (! empty($menu)) { |
if (! empty($menu)) { |
| 183 |
// Found a pre-existing menu, update it |
// Found a pre-existing menu, update it |
| 184 |
import_html_debug("Discovered that a placeholder menu item for %path already exists. Filling that one out with the full details now", array('%path' => $node->path)); |
import_html_debug("Discovered that a placeholder menu item for %path already exists. Filling that one out with the full details now", array('%path' => $node->path)); |
| 189 |
$parent_menu = import_html_create_menu_path(dirname($node->path), $profile); |
$parent_menu = import_html_create_menu_path(dirname($node->path), $profile); |
| 190 |
#dpm(array('After creating the menu path, the parent menu is' => $parent_menu)); |
#dpm(array('After creating the menu path, the parent menu is' => $parent_menu)); |
| 191 |
|
|
| 192 |
if (empty($parent_menu)) { |
if (empty($parent_menu)) { |
| 193 |
trigger_error("Code should not get here - failed to build menu - no parent menu returned to hang this node off.", E_USER_ERROR); |
trigger_error("Code should not get here - failed to build menu - no parent menu returned to hang this node off.", E_USER_ERROR); |
| 194 |
return; |
return; |
| 195 |
} |
} |
| 204 |
} |
} |
| 205 |
|
|
| 206 |
$node->menu = $menu; |
$node->menu = $menu; |
| 207 |
# dpm(array("about to save menu link " => $menu)); |
# dpm(array("about to save menu link " => $menu)); |
| 208 |
menu_link_save($node->menu); |
menu_link_save($node->menu); |
| 209 |
} |
} |
| 210 |
} |
} |
| 214 |
* Given a traditional URL path, return the parent menu item |
* Given a traditional URL path, return the parent menu item |
| 215 |
* |
* |
| 216 |
* A helper function to menu_import_html_after_save() |
* A helper function to menu_import_html_after_save() |
| 217 |
* |
* |
| 218 |
* This is a recursive function that slices the given |
* This is a recursive function that slices the given |
| 219 |
* (alias) path up until it finds a menu item it recognises. |
* (alias) path up until it finds a menu item it recognises. |
| 220 |
* Once found, it comes back down again building a path |
* Once found, it comes back down again building a path |
| 225 |
* I'd like to have it fall back to system_admin_menu_block_page by default, but |
* I'd like to have it fall back to system_admin_menu_block_page by default, but |
| 226 |
* can't see how to make that happen on the fly. |
* can't see how to make that happen on the fly. |
| 227 |
* |
* |
| 228 |
* @param $path |
* @param $path |
| 229 |
* the path (aliased URL) we intend to construct |
* the path (aliased URL) we intend to construct |
| 230 |
* @param $title |
* @param $title |
| 231 |
* optional Display title of the menu item at that path point, otherwist |
* optional Display title of the menu item at that path point, otherwist |
| 232 |
* it'll use the last fragment of the path as a display title |
* it'll use the last fragment of the path as a display title |
| 233 |
* @return a menu object, the bottom-most, the one we asked for. |
* @return a menu object, the bottom-most, the one we asked for. |
| 234 |
* FALSE if it hit |
* FALSE if it hit |
| 235 |
* the top unexpectedly |
* the top unexpectedly |
| 236 |
* |
* |
| 237 |
* @return a menu_link definition ARRAY |
* @return a menu_link definition ARRAY |
| 238 |
* |
* |
| 239 |
**/ |
**/ |
| 240 |
function import_html_create_menu_path($path, $profile = array()) { |
function import_html_create_menu_path($path, $profile = array()) { |
| 241 |
|
|
| 261 |
|
|
| 262 |
if ($p_path == dirname($p_path)) { |
if ($p_path == dirname($p_path)) { |
| 263 |
import_html_debug(" |
import_html_debug(" |
| 264 |
Hit topmost menu path '$p_path', this is either caused by creating a new menu tree |
Hit topmost menu path '$p_path', this is either caused by creating a new menu tree |
| 265 |
from the bottom up and we just reached the top, |
from the bottom up and we just reached the top, |
| 266 |
or a recursion error (illegal paths). |
or a recursion error (illegal paths). |
| 267 |
", array(), WATCHDOG_INFO); |
", array(), WATCHDOG_INFO); |
| 270 |
} |
} |
| 271 |
else { |
else { |
| 272 |
if (! $parent = menu_get_item_by_path($p_path)) { |
if (! $parent = menu_get_item_by_path($p_path)) { |
| 273 |
// Parent not found. Need to make it up. |
// Parent not found. Need to make it up. |
| 274 |
// Recurse... |
// Recurse... |
| 275 |
$parent = import_html_create_menu_path($p_path, $profile); |
$parent = import_html_create_menu_path($p_path, $profile); |
| 276 |
// ... and welcome back again! |
// ... and welcome back again! |
| 291 |
|
|
| 292 |
import_html_debug("Creating a placeholder menu item for $path. Parent was found to be item {$parent['mlid']}", array(), WATCHDOG_INFO); |
import_html_debug("Creating a placeholder menu item for $path. Parent was found to be item {$parent['mlid']}", array(), WATCHDOG_INFO); |
| 293 |
$menu_link_item = import_html_create_placeholder_menu_item($path, $profile, $parent); |
$menu_link_item = import_html_create_placeholder_menu_item($path, $profile, $parent); |
| 294 |
|
|
| 295 |
if (empty($menu_link_item)) { |
if (empty($menu_link_item)) { |
| 296 |
trigger_error("Failed to create placeholder menu item ($path, $parent) ", E_USER_ERROR); |
trigger_error("Failed to create placeholder menu item ($path, $parent) ", E_USER_ERROR); |
| 297 |
return NULL; |
return NULL; |
| 302 |
} |
} |
| 303 |
|
|
| 304 |
/** |
/** |
| 305 |
* Create a dummy node to represent a menu container. |
* Create a dummy node to represent a menu container. |
| 306 |
* |
* |
| 307 |
* This appears to be the only sane way to build a site from the bottom up. |
* This appears to be the only sane way to build a site from the bottom up. |
| 308 |
* I can, If I try, create menu trees that do not link to nodes ... but most |
* I can, If I try, create menu trees that do not link to nodes ... but most |
| 309 |
* users will not be able to remove, over-write or edit them using the tools |
* users will not be able to remove, over-write or edit them using the tools |
| 310 |
* they are used to. |
* they are used to. |
| 311 |
* |
* |
| 312 |
* Instead, just make empty shells on-the-fly. You can kill them via content |
* Instead, just make empty shells on-the-fly. You can kill them via content |
| 313 |
* management and things will bubble up and Drupal will not have a hernia. |
* management and things will bubble up and Drupal will not have a hernia. |
| 314 |
* |
* |
| 315 |
* @param $parent is a parent link item array, containing (at least) a mlid and |
* @param $parent is a parent link item array, containing (at least) a mlid and |
| 316 |
* menu_name |
* menu_name |
| 317 |
*/ |
*/ |
| 323 |
'status' => $profile['import_status'], |
'status' => $profile['import_status'], |
| 324 |
'promote' => FALSE, |
'promote' => FALSE, |
| 325 |
'body' => t(" |
'body' => t(" |
| 326 |
Placeholder page. |
Placeholder page. |
| 327 |
Created by import_html. |
Created by import_html. |
| 328 |
This is required to keep the menu in place during imports. |
This is required to keep the menu in place during imports. |
| 329 |
Feel free to delete it! |
Feel free to delete it! |
| 330 |
"), |
"), |
| 331 |
); |
); |
| 337 |
trigger_error("Failed to create placeholder node to hold the menus together. Not fatal, but some sections under $path will be unstructured", E_USER_WARNING); |
trigger_error("Failed to create placeholder node to hold the menus together. Not fatal, but some sections under $path will be unstructured", E_USER_WARNING); |
| 338 |
return NULL; |
return NULL; |
| 339 |
} |
} |
| 340 |
|
|
| 341 |
// Now make the menu for this dummy node |
// Now make the menu for this dummy node |
| 342 |
$menu = array( |
$menu = array( |
| 343 |
'parent' => $parent_menu['menu_name'] .':'. $parent_menu['mlid'], |
'parent' => $parent_menu['menu_name'] .':'. $parent_menu['mlid'], |
| 346 |
'link_title' => import_html_guess_label('', $path), |
'link_title' => import_html_guess_label('', $path), |
| 347 |
'link_path' => 'node/'. $node->nid, |
'link_path' => 'node/'. $node->nid, |
| 348 |
); |
); |
| 349 |
|
|
| 350 |
$mlid = menu_link_save($menu); |
$mlid = menu_link_save($menu); |
| 351 |
|
|
| 352 |
if (! $mlid) { |
if (! $mlid) { |
| 363 |
/** |
/** |
| 364 |
* Return a menu item matching a given path or alias. |
* Return a menu item matching a given path or alias. |
| 365 |
* The alias for the requested path will be tried automatically. |
* The alias for the requested path will be tried automatically. |
| 366 |
* |
* |
| 367 |
* @return a menu link ARRAY. NULL if no valid menu item was found. |
* @return a menu link ARRAY. NULL if no valid menu item was found. |
| 368 |
*/ |
*/ |
| 369 |
function menu_get_item_by_path($path) { |
function menu_get_item_by_path($path) { |
| 370 |
// Caching works against me when adding lots of aliases in one go. |
// Caching works against me when adding lots of aliases in one go. |
| 371 |
// Cannot trust get_alias etc |
// Cannot trust get_alias etc |
| 372 |
// Wipe it :( |
// Wipe it :( |
| 373 |
drupal_lookup_path('wipe'); // This is not working? |
drupal_lookup_path('wipe'); // This is not working? |
| 374 |
|
|
| 375 |
// Use DB to fetch all aliases |
// Use DB to fetch all aliases |
| 376 |
$aliases = array($path); |
$aliases = array($path); |
| 377 |
$placeholders = array(' link_path = "%s" '); |
$placeholders = array(' link_path = "%s" '); |
| 410 |
function path_import_html($profile, &$node, $datadoc = NULL) { |
function path_import_html($profile, &$node, $datadoc = NULL) { |
| 411 |
drupal_lookup_path('wipe'); |
drupal_lookup_path('wipe'); |
| 412 |
|
|
| 413 |
// Path requires the nodes language to be set. Don't know why it's a PATH job, but |
// Path requires the nodes language to be set. Don't know why it's a PATH job, but |
| 414 |
// that's the module that complains about undefined property if it isn't |
// that's the module that complains about undefined property if it isn't |
| 415 |
$node->language = isset($node->language) ? $node->language : ''; |
$node->language = isset($node->language) ? $node->language : ''; |
| 416 |
|
|
| 417 |
|
|
| 418 |
} |
} |
| 419 |
|
|
| 420 |
|
|
| 421 |
/** |
/** |
| 422 |
* Add path alias support to the import_html process |
* Add path alias support to the import_html process |
| 423 |
* |
* |
| 424 |
* Needed to be run after save as we need to know the nid |
* Needed to be run after save as we need to know the nid |
| 425 |
* |
* |
| 426 |
* Adds an old-style (legacy) alias to the node path if required. |
* Adds an old-style (legacy) alias to the node path if required. |
| 427 |
*/ |
*/ |
| 428 |
function path_import_html_after_save($profile, &$node, $datadoc = NULL) { |
function path_import_html_after_save($profile, &$node, $datadoc = NULL) { |
| 429 |
#dpm(array('INVOKED path_import_html_after_save for '. $node->path)); |
#dpm(array('INVOKED path_import_html_after_save for '. $node->path)); |
| 430 |
if ($profile['legacy_aliases'] && ($node->old_path != $node->path)) { |
if ($profile['legacy_aliases'] && ($node->old_path != $node->path)) { |
| 431 |
import_html_debug("Setting up URL ALIASES for this item now. Directing {$node->old_path} to go to the system path ". drupal_get_normal_path($node->path), array(), WATCHDOG_DEBUG); |
import_html_debug("Setting up URL ALIASES for this item now. Directing {$node->old_path} to go to the system path ". drupal_get_normal_path($node->path), array(), WATCHDOG_DEBUG); |
| 432 |
|
|
| 433 |
$normal_path = "node/{$node->nid}"; |
$normal_path = "node/{$node->nid}"; |
| 434 |
|
|
| 435 |
if ($normal_path == $node->path) { |
if ($normal_path == $node->path) { |
| 436 |
import_html_debug( |
import_html_debug( |
| 437 |
"Failed to resolve %node_path into a system path. Cannot create alias at this time.", |
"Failed to resolve %node_path into a system path. Cannot create alias at this time.", |
| 438 |
array('%node_path' => $node->path), |
array('%node_path' => $node->path), |
| 439 |
WATCHDOG_NOTICE |
WATCHDOG_NOTICE |
| 440 |
); |
); |
| 441 |
} |
} |
| 442 |
else { |
else { |
| 443 |
// path_set_alias is WRONG when it looks for existing items |
// path_set_alias is WRONG when it looks for existing items |
| 444 |
// drupal_lookup_path('wipe'); // DOES NOT WORK - to it ourselves. |
// drupal_lookup_path('wipe'); // DOES NOT WORK - to it ourselves. |
| 446 |
path_set_alias($normal_path, $node->old_path); |
path_set_alias($normal_path, $node->old_path); |
| 447 |
} |
} |
| 448 |
import_html_debug( |
import_html_debug( |
| 449 |
"This document (known internally as '%normal_path' ) |
"This document (known internally as '%normal_path' ) |
| 450 |
should now be accessible via aliases as both |
should now be accessible via aliases as both |
| 451 |
'!main_alias' and '!legacy_alias' ", |
'!main_alias' and '!legacy_alias' ", |
| 452 |
array( |
array( |
| 453 |
'%normal_path' => $normal_path, |
'%normal_path' => $normal_path, |
| 458 |
); |
); |
| 459 |
} |
} |
| 460 |
} |
} |
| 461 |
|
|
| 462 |
} |
} |
| 463 |
|
|
| 464 |
/************************************************** |
/************************************************** |
| 468 |
/** |
/** |
| 469 |
* Absorbs elements in the import document we recognise as being (probably) |
* Absorbs elements in the import document we recognise as being (probably) |
| 470 |
* taxonomy terms. |
* taxonomy terms. |
| 471 |
* |
* |
| 472 |
* |
* |
| 473 |
* Any link rel="tag" is a start. The plaintext content of such a tag is |
* Any link rel="tag" is a start. The plaintext content of such a tag is |
| 474 |
* searched for as a term. |
* searched for as a term. |
| 475 |
* |
* |
| 476 |
* both <a href rel='tag' > and <link rel="tag"> are good for me. |
* both <a href rel='tag' > and <link rel="tag"> are good for me. |
| 477 |
* |
* |
| 478 |
* @TODO this still needs to be expanded with real-world cases |
* @TODO this still needs to be expanded with real-world cases |
| 479 |
*/ |
*/ |
| 480 |
function taxonomy_import_html($profile, &$node, $datadoc = NULL) { |
function taxonomy_import_html($profile, &$node, $datadoc = NULL) { |
| 482 |
|
|
| 483 |
$active_vocabs = taxonomy_get_vocabularies($node->type); |
$active_vocabs = taxonomy_get_vocabularies($node->type); |
| 484 |
if (!$active_vocabs) return; |
if (!$active_vocabs) return; |
| 485 |
|
|
| 486 |
$freetag_vocab = $profile['freetag_vocab']; |
$freetag_vocab = $profile['freetag_vocab']; |
| 487 |
|
|
| 488 |
if ($freetag_vocab && !empty($node->keywords)) { |
if ($freetag_vocab && !empty($node->keywords)) { |
| 511 |
$reltypes = explode(' ', xml_getAttribute($link, 'rel')); |
$reltypes = explode(' ', xml_getAttribute($link, 'rel')); |
| 512 |
$rellink = xml_getattribute($link, 'href'); |
$rellink = xml_getattribute($link, 'href'); |
| 513 |
$label = trim(xml_textcontent($link)); |
$label = trim(xml_textcontent($link)); |
| 514 |
// Microformats may put their value into a 'title' attribute instead |
// Microformats may put their value into a 'title' attribute instead |
| 515 |
if (empty($label)) { |
if (empty($label)) { |
| 516 |
$label = xml_getAttribute($link, 'title'); |
$label = xml_getAttribute($link, 'title'); |
| 517 |
} |
} |
| 518 |
|
|
| 519 |
if (!empty($label)) { |
if (!empty($label)) { |
| 521 |
if ($reltype == 'tag') { |
if ($reltype == 'tag') { |
| 522 |
// Some of this magic should probably shift into absorb_metas() |
// Some of this magic should probably shift into absorb_metas() |
| 523 |
// Still thinking of the best way to encode tags into the raw HTML |
// Still thinking of the best way to encode tags into the raw HTML |
| 524 |
|
|
| 525 |
if (strstr($label, ":")) { |
if (strstr($label, ":")) { |
| 526 |
// allow an extended format for this value |
// allow an extended format for this value |
| 527 |
// to support freetext vocab additions |
// to support freetext vocab additions |
| 535 |
$node->taxonomy['tags'][$vocabulary->vid] .= ",". $label; |
$node->taxonomy['tags'][$vocabulary->vid] .= ",". $label; |
| 536 |
} |
} |
| 537 |
} |
} |
| 538 |
|
|
| 539 |
// Match against existing terms |
// Match against existing terms |
| 540 |
$terms = taxonomy_get_term_by_name($label); |
$terms = taxonomy_get_term_by_name($label); |
| 541 |
// Allow an optional 'S' on the end of terms when looking for a match. Just to be flexible. |
// Allow an optional 'S' on the end of terms when looking for a match. Just to be flexible. |
| 542 |
$terms = array_merge($terms, taxonomy_get_term_by_name($label ."s")); |
$terms = array_merge($terms, taxonomy_get_term_by_name($label ."s")); |
| 543 |
|
|
| 544 |
if (!is_array($node->taxonomy)) { |
if (!is_array($node->taxonomy)) { |
| 545 |
$node->taxonomy = array(); |
$node->taxonomy = array(); |
| 546 |
} |
} |
| 547 |
if ($terms) { |
if ($terms) { |
| 548 |
foreach ($terms as $term) { |
foreach ($terms as $term) { |
| 549 |
// If we did successfully identify the vocab earlier, filter on that. Otherwise let anything go |
// If we did successfully identify the vocab earlier, filter on that. Otherwise let anything go |
| 550 |
if ($vocabulary && ($term->vid != $vocabulary->vid)) continue; |
if ($vocabulary && ($term->vid != $vocabulary->vid)) continue; |
| 551 |
$node->taxonomy[$term->tid] = $term; |
$node->taxonomy[$term->tid] = $term; |
| 552 |
} |
} |
| 553 |
} |
} |
| 562 |
} // has value |
} // has value |
| 563 |
} // each rel |
} // each rel |
| 564 |
|
|
| 565 |
// Tag this new content if the profile has a global tag set |
// Tag this new content if the profile has a global tag set |
| 566 |
// May have been set during the form process. |
// May have been set during the form process. |
| 567 |
// |
// |
| 568 |
// Note that if the global tag is from a freetaging vocab, we insert it as a string |
// Note that if the global tag is from a freetaging vocab, we insert it as a string |
| 569 |
// but if it was from a select category, we insert it by ID. |
// but if it was from a select category, we insert it by ID. |
| 570 |
|
|
| 571 |
$cats = $profile['import_category']; |
$cats = $profile['import_category']; |
| 572 |
if (is_array($cats)) { |
if (is_array($cats)) { |
| 573 |
foreach ($cats as $term_id) { |
foreach ($cats as $term_id) { |
| 574 |
if ($term = taxonomy_get_term($term_id)) { |
if ($term = taxonomy_get_term($term_id)) { |
| 575 |
// Be careful not to add terms that are invalid or recently deleted |
// Be careful not to add terms that are invalid or recently deleted |
| 576 |
|
|
| 577 |
// $node->taxonomy contains either strings or IDs. |
// $node->taxonomy contains either strings or IDs. |
| 578 |
// Figure it out and insert into the object accordingly |
// Figure it out and insert into the object accordingly |
| 579 |
// Mixing ids and strings confuses taxonomy submit otherwise |
// Mixing ids and strings confuses taxonomy submit otherwise |
| 580 |
$term_vocab = taxonomy_vocabulary_load($term->vid); |
$term_vocab = taxonomy_vocabulary_load($term->vid); |
| 594 |
} |
} |
| 595 |
|
|
| 596 |
/** |
/** |
| 597 |
* implimentation of hook_import_html_node_merge. |
* Implimentation of hook_import_html_node_merge() |
| 598 |
* |
* |
| 599 |
* HOOK_import_html_node_merge gets called after a new node has been created, |
* HOOK_import_html_node_merge gets called after a new node has been created, |
| 600 |
* and is being used to update a pre-existing one. |
* and is being used to update a pre-existing one. |
| 601 |
* |
* |
| 602 |
* A per-module way of blending new values over old ones - conflict resolution |
* A per-module way of blending new values over old ones - conflict resolution |
| 603 |
* and checking for duplicates. |
* and checking for duplicates. |
| 604 |
* |
* |
| 605 |
* If the values are done with, unset them from the $old node so they don't get |
* If the values are done with, unset them from the $old node so they don't get |
| 606 |
* inadvertantly copied by the bulk operation that follows. |
* inadvertantly copied by the bulk operation that follows. |
| 607 |
* |
* |
| 608 |
* Taxonomy needs this because: If I am MERGING with a pre-existing node that |
* Taxonomy needs this because: If I am MERGING with a pre-existing node that |
| 609 |
* already has terms (such as when doing a re-import) then the node taxonomy |
* already has terms (such as when doing a re-import) then the node taxonomy |
| 610 |
* already has a bunch of identified terms that are likely to be duplicates. I |
* already has a bunch of identified terms that are likely to be duplicates. I |
| 612 |
* leaving the node with them set, and ALSO adding the freetagging list will |
* leaving the node with them set, and ALSO adding the freetagging list will |
| 613 |
* cause duplicate complaints. I need to investigate the existing terms and |
* cause duplicate complaints. I need to investigate the existing terms and |
| 614 |
* remove them individually. Easiest way is to convert them into a flat list so |
* remove them individually. Easiest way is to convert them into a flat list so |
| 615 |
* they get re-saved. |
* they get re-saved. |
| 616 |
* |
* |
| 617 |
* taxonomy_preview_terms() didn't look like it will help. |
* taxonomy_preview_terms() didn't look like it will help. |
| 618 |
* |
* |
| 619 |
* taxonomy_form_alter() seems to have the same problem. And solves it sorta. |
* taxonomy_form_alter() seems to have the same problem. And solves it sorta. |
| 620 |
* |
* |
| 621 |
* But not good enough for us without rewriting $node->taxonomy totally |
* But not good enough for us without rewriting $node->taxonomy totally |
| 622 |
* |
* |
| 623 |
* Taxonomy doesn't mind duplicates in the freetag string, so we will pull the |
* Taxonomy doesn't mind duplicates in the freetag string, so we will pull the |
| 624 |
* known terms out, just add them to the freetag string, and discard the oldies. |
* known terms out, just add them to the freetag string, and discard the oldies. |
| 625 |
* |
* |
| 626 |
* It operates on both old and new by reference. |
* It operates on both old and new by reference. |
| 627 |
*/ |
*/ |
| 628 |
function taxonomy_import_html_node_merge(&$old_node, &$new_node, $profile = array()) { |
function taxonomy_import_html_node_merge(&$old_node, &$new_node, $profile = array()) { |
| 638 |
$new_node->taxonomy['tags'][$term->vid] = ''; |
$new_node->taxonomy['tags'][$term->vid] = ''; |
| 639 |
} |
} |
| 640 |
$new_node->taxonomy['tags'][$term->vid] .= ', '. $term->name; |
$new_node->taxonomy['tags'][$term->vid] .= ', '. $term->name; |
| 641 |
} |
} |
| 642 |
} |
} |
| 643 |
} |
} |
| 644 |
} |
} |