dlike.inc in Drupal like (Flag counter) 7.2
Same filename and directory in other branches
This files contains all the include functions.
File
dlike.incView source
<?php
// $Id$
/**
* @file
* This files contains all the include functions.
*/
/**
* Get data of all the users who flagged a content.
*/
function dlike_get_users($flag_type, $content_id, $flag_name) {
$user_data = flag_get_content_flags($flag_type, $content_id, $flag_name);
return array_keys($user_data);
}
/**
* Get list of names of all the users who flagged particular content.
*/
function dlike_user_list($flag_type, $content_id, $flag_name) {
$output = '';
$i = 0;
$flaggers = array();
$flaggers = dlike_get_users($flag_type, $content_id, $flag_name);
$output .= "<div class='dlike'>";
$output .= '<h2>' . variable_get('dlike-modal-window-title-' . $flag_name, NULL) . '</h2>';
// count($flaggers)
$alignment = variable_get('dlike-modal-flagged-user-alignment-' . $flag_name, NULL);
$col = variable_get('dlike-modal-flagged-user-horizontal-columns-' . $flag_name, NULL);
if ($alignment == 'horizontal') {
$iterate = 0;
while ($flaggers[$i]) {
if ($iterate / $col === 0) {
if ($iterate !== 0) {
$output .= '</div><div class="dlike-user-row-col-' . $iterate . '">';
$output .= '<div class="dlike-user-col-' . $col . '">' . views_embed_view('dlike_user_view', 'default', array(
$flaggers[$i],
)) . '</div>';
}
else {
$output .= '<div class="dlike-user-row-col-' . $iterate . '">';
$output .= '<div class="dlike-user-col-' . $col . '">' . views_embed_view('dlike_user_view', 'default', array(
$flaggers[$i],
)) . '</div>';
}
}
else {
$output .= '<div class="dlike-user-col-' . $col . '">' . views_embed_view('dlike_user_view', 'default', array(
$flaggers[$i],
)) . '</div>';
}
$i++;
$iterate++;
}
}
else {
while ($flaggers[$i]) {
$output .= '<div class="dlike-user-row">' . views_embed_view('dlike_user_view', 'default', array(
$flaggers[$i],
)) . '</div>';
$i++;
}
}
$output .= "</div>";
print $output;
}
function dlike_append($flag_type, $content_id, $flag_name) {
// Variables added for appending facebook like like string
// Check if facebook like likes is enabled for a flag
$dlike_status_value = variable_get('dlike-' . $flag_name . '_option', 0);
$dlike_append_link = '';
//add a condition for disabled flags
if ($dlike_status_value == 1) {
// Get the list of all the users those flagged current content
// $dlike_append_names = dlike_user_list($type, $flag->get_content_id($object), $flag->name);
// Get the flag counts for a piece of content
$active_user_flagged_count = variable_get('dlike-modal-active-user-flagged-count-' . $flag_name, 0);
if ($active_user_flagged_count == 1) {
$dlike_append_count = dlike_flag_get_active_users_counts($flag_name, $content_id);
}
else {
$dlike_append_count = flag_get_counts($flag_type, $content_id);
}
// dprint_r($dlike_append_count); exit;
if ($dlike_append_count && isset($dlike_append_count[$flag_name]) && $dlike_append_count[$flag_name] > 0) {
// Get the text string set by the user
$dlike_text_value = variable_get('dlike-' . $flag_name . '_text_value', NULL);
// Pass the string through t().
$dlike_sanitize_string = t('@text', array(
'@text' => $dlike_text_value,
));
// If set, replace the token for count by actual count.
$dlike_append_string = str_replace('@count', $dlike_append_count[$flag_name], $dlike_sanitize_string);
// Check if user has the right permissions
if (user_access('dlike access list')) {
// format link address.
$dlike_link_address = 'dlike/' . $flag_type . '/' . $content_id . '/' . $flag_name;
// format the attributed for l() function.
$dlike_link_arrtibutes = array();
$alignment = variable_get('dlike-modal-flagged-user-alignment-' . $flag_name, NULL);
$col = variable_get('dlike-modal-flagged-user-horizontal-columns-' . $flag_name, NULL);
if ($alignment == 'horizontal') {
switch ($col) {
case 2:
$width = 600;
break;
case 3:
$width = 800;
break;
case 4:
$width = 1000;
break;
}
$dlike_link_arrtibutes = array(
'html' => TRUE,
'attributes' => array(
'rel' => 'lightmodal[|width: ' . $width . 'px; height:600px; scrolling: auto;]',
),
);
}
else {
$dlike_link_arrtibutes = array(
'html' => TRUE,
'attributes' => array(
'rel' => 'lightmodal[|width:400px; height:300px; scrolling: auto;]',
),
);
}
// format the link to the list of users who flagged the content.
$dlike_append_link = '<span class="dlike-' . $flag_type . '-append-' . $content_id . '-' . $flag_name . '">' . l($dlike_append_string, $dlike_link_address, $dlike_link_arrtibutes) . '</span>';
}
else {
// $dlike_append_link = $dlike_append_string;
}
}
else {
$dlike_append_link = '<span class="dlike-' . $flag_type . '-append-' . $content_id . '-' . $flag_name . '"></span>';
}
}
if (isset($_POST['method']) && $_POST['method'] == 'ajax') {
print $dlike_append_link;
die;
}
return $dlike_append_link;
}
/**
* get only active users flagged count
*/
function dlike_flag_get_active_users_counts($flag_name, $content_id) {
$query = db_select('flags', 'f');
$query
->leftJoin('flag_content', 'fc', 'f.fid = fc.fid');
$query
->leftJoin('users', 'u', 'fc.uid = u.uid');
$result = $query
->fields('f', array(
'name',
))
->fields('fc', array(
'fid',
))
->condition('f.name', $flag_name)
->condition('fc.content_id', $content_id)
->condition('u.status', '1')
->countQuery()
->execute()
->fetchField();
$count = array();
$count[$flag_name] = $result;
return $count;
}
Functions
Name![]() |
Description |
---|---|
dlike_append | |
dlike_flag_get_active_users_counts | get only active users flagged count |
dlike_get_users | Get data of all the users who flagged a content. |
dlike_user_list | Get list of names of all the users who flagged particular content. |