View source
<?php
include_once 'commons_like.features.inc';
function commons_like_strongarm_alter(&$items) {
if (!empty($items['rate_widgets']->value)) {
foreach ($items['rate_widgets']->value as $key => $widget) {
if ($widget->name == 'commons_like') {
$commons_entity_integrations = commons_entity_integration_info();
if (!empty($commons_entity_integrations['node'])) {
foreach ($commons_entity_integrations['node'] as $bundle => $options) {
if (!isset($options['exclude_rate']) || $options['exclude_rate'] != TRUE) {
$items['rate_widgets']->value[$key]->node_types[] = $bundle;
}
if (!isset($options['exclude_rate_comments']) || $options['exclude_rate_comments'] != TRUE) {
$items['rate_widgets']->value[$key]->comment_types[] = $bundle;
}
}
}
}
}
}
}
function commons_like_votingapi_insert($votes) {
foreach ($votes as $vote) {
if ($vote['tag'] == 'commons_like' && $vote['entity_type'] == 'node') {
$node = node_load($vote['entity_id']);
$message = message_create('commons_like_user_likes_node', array(
'uid' => $vote['uid'],
'timestamp' => $vote['timestamp'],
));
$wrapper = entity_metadata_wrapper('message', $message);
$wrapper->field_target_nodes[] = $node;
$wrapper
->save();
}
}
}
function commons_like_votingapi_delete($votes) {
foreach ($votes as $vote) {
if (isset($vote['tag']) && $vote['tag'] == 'commons_like' && $vote['entity_type'] == 'node') {
if (module_exists('commons_activity_streams') && ($mids = commons_like_existing_node_like_messages($vote['uid'], array(
$vote['entity_id'],
)))) {
message_delete_multiple($mids);
}
}
}
}
function commons_like_existing_node_like_messages($acting_uid, $target_nids) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'message', '=')
->propertyCondition('uid', $acting_uid)
->propertyCondition('type', 'commons_like_user_likes_node', '=')
->fieldCondition('field_target_nodes', 'target_id', $target_nids, 'IN')
->execute();
if (!empty($query->ordered_results)) {
$mids = array();
foreach ($query->ordered_results as $result) {
$mids[] = $result->entity_id;
}
return $mids;
}
return FALSE;
}
function commons_like_theme() {
return array(
'rate_template_commons_like' => array(
'variables' => array(
'links' => NULL,
'results' => NULL,
'mode' => NULL,
'just_voted' => FALSE,
'entity_type' => NULL,
'entity_id' => NULL,
'display_options' => NULL,
),
'template' => 'commons-like',
),
);
}
function commons_like_rate_templates() {
$templates = array();
$templates['commons_like'] = new stdClass();
$templates['commons_like']->value_type = 'points';
$templates['commons_like']->options = array(
array(
1,
'like',
),
);
$templates['commons_like']->theme = 'rate_template_commons_like';
$templates['commons_like']->css = drupal_get_path('module', 'commons_like') . '/commons-like.css';
$templates['commons_like']->customizable = FALSE;
$templates['commons_like']->translate = TRUE;
$templates['commons_like']->use_source_translation = TRUE;
$templates['commons_like']->template_title = t('Commons like');
return $templates;
}
function commons_like_preprocess_rate_template_commons_like(&$variables) {
$variables['like_button'] = theme('rate_button', array(
'text' => $variables['links'][0]['text'],
'href' => $variables['links'][0]['href'],
'class' => 'rate-commons-like-btn',
));
}