function _vkxp_process_node in VK CrossPoster 7
Same name and namespace in other branches
- 6.3 vkxp.module \_vkxp_process_node()
- 7.2 vkxp.module \_vkxp_process_node()
Process node and send it to vk.com if needed.
Parameters
$node: Node object during insert/update.
$op: Current node operation (insert or update).
2 calls to _vkxp_process_node()
- vkxp_node_insert in ./
vkxp.module - Implements hook_node_insert().
- vkxp_node_update in ./
vkxp.module - Implements hook_node_update().
File
- ./
vkxp.module, line 185
Code
function _vkxp_process_node($node, $op) {
// Get node types that could be crossposted.
$enabled_node_types = variable_get('vkxp_node_types', array());
$selected_types = array_filter($enabled_node_types);
// If current node is in selected types list - crosspost it.
if (in_array($node->type, $selected_types)) {
// Collect data and check access to crosspost nodes.
$access_token = variable_get('vkxp_access_token', '');
$user_access = user_access('post to vkontakte');
$post_node = FALSE;
if (isset($node->vkxp_post_this_node)) {
$post_node = $node->vkxp_post_this_node;
}
// Check requiered data to post.
if ($access_token && $user_access && $post_node) {
// Clear cached data if user wants to add link to this page.
// If do not flush page cache, vkontakte may not post this node due to unaccessable node url.
$add_link_to_node = variable_get('vkxp_add_link', 0);
$cache_disabled = variable_get('cache', 0) ? FALSE : TRUE;
if ($add_link_to_node && !$cache_disabled && $op == 'insert') {
cache_clear_all(NULL, 'cache_page');
}
// Get absolute node link.
$url = url('node/' . $node->nid, array(
'absolute' => TRUE,
));
// Get message from node.
$post_object = variable_get('vkxp_post_object', 'body');
if ($post_object == 'body') {
$body = array_shift($node->body);
$message = trim(strip_tags($body[0]['value']));
}
elseif ($post_object == 'title') {
$message = trim(check_plain($node->title));
}
else {
$body = array_shift($node->body);
$message = trim(check_plain($node->title)) . "\n\n" . trim(strip_tags($body[0]['value']));
}
// Trim message if needed.
$cut_message = variable_get('vkxp_cut_message', 1);
if ($cut_message) {
$length = variable_get('vkxp_cut_message_length', 255);
if (drupal_strlen($message) > $length) {
$message = drupal_substr($message, 0, $length - 3) . '...';
}
}
// Decode special symbols.
$message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
$message = htmlspecialchars_decode($message);
// Post node to vk.com.
$images = _vkxp_get_node_images($node);
$image_ids = '';
if ($images) {
$upload_url = _vkxp_get_upload_server();
$image_ids = _vkxp_upload_images($upload_url, $images);
}
_vkxp_post_to_wall($message, $url, $image_ids);
}
}
}