function syndicator_item_to_node($item_id = NULL) {
global $user;
if (is_null($item_id)) {
$iid = arg(2);
if (isset($iid)) {
$item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $iid));
}
}
else if (is_numeric($item_id)) {
$item = db_fetch_object(db_query(SYNDICATOR_PROMOTE_TO_NODE_QUERY, $item_id));
}
if (isset($item)) {
$node = new stdClass();
$node->is_new = true;
$item->description = check_markup($item->description, $node->filter);
$node->created = time();
$node->date = format_date($item->timestamp, 'custom', 'Y-m-d H:i:s O');
$node->type = variable_get('syndicator_publish_node_type', 'none');
$node->title = $item->title;
$node->filter = variable_get('filter_default_format', FILTER_FORMAT_DEFAULT);
$node->body = theme('syndicator_published_content', $item);
$node->teaser = node_teaser(theme('syndicator_published_content', $item),
variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)); // might be unnecessary
$node_options = variable_get('node_options_' . $node->type, array());
$node->comment = variable_get('comment_' . $node->type, 2);
unset($node->nid);
$node = node_submit($node);
$node->uid = $user->uid ? $user->uid : 1;
module_invoke('node', 'save', $node);
}
}
- and the real question: how does the following sequence of 4.6 translate into 4.7:$node->type = 'story';
$node->uid = 1;
$node->title = ''; // invalid empty title!
$node->body = ''; // invalid empty body!
$node = node_validate($node); // if life was only that
// that easy in 4.7...
if (form_get_errors()) {
// we detected the error... do something
unset($GLOBALS['form']);
// note: we unset $GLOBALS['form'] so the next time we
// try this trick, form_get_errors() return the errors
// of the last run and not of the previous.
// If something like this would be possible in 4.7 it
// would be great, but form_set_error() in 4.7 saves the
// errors in a static variable inside form_set_error()
// instead of in $GLOBALS['form']. I see no way to unset
// that...
$output .= node_view($node);
}
else {
// no errors? hmm, great, save it... quickly before
// "they" introduce something else that breaks
// "common sense". Really: why call something
// foobar_validate() if it doesn't validate anything
// at all... Am I alone in this? I guess so.
node_save($node);
}