View source
<?php
require_once drupal_get_path('module', 'flickr') . '/flickr.inc';
function flickr_tags_menu($may_cache) {
global $user;
$items = array();
if ($may_cache) {
}
else {
if (arg(0) == 'flickr' && is_numeric(arg(1)) && arg(1) > 0) {
$account = user_load(array(
'uid' => arg(1),
));
if ($account !== FALSE && isset($account->flickr['nsid'])) {
$nsid = $account->flickr['nsid'];
$admin_access = user_access('administer flickr');
$view_access |= user_access('view own flickr photos') && $user->uid == arg(1) || user_access('view all flickr photos');
$view_access &= $account->status || $admin_access;
$items[] = array(
'path' => 'flickr/' . arg(1) . '/tags',
'title' => t("Tags"),
'type' => MENU_LOCAL_TASK,
'callback' => 'flickr_tags_cloud',
'callback arguments' => array(
arg(1),
$nsid,
),
'access' => $view_access,
);
$items[] = array(
'path' => 'flickr/' . arg(1) . '/tags/cloud',
'title' => t("Cloud"),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access' => $view_access,
);
$items[] = array(
'path' => 'flickr/' . arg(1) . '/tags/list',
'title' => t("List"),
'type' => MENU_LOCAL_TASK,
'callback' => 'flickr_tags_list',
'callback arguments' => array(
arg(1),
$nsid,
),
'access' => $view_access,
);
if (arg(3) !== NULL && arg(3) != 'cloud' && arg(3) != 'list') {
$items[] = array(
'path' => 'flickr/' . arg(1) . '/tags/' . arg(3),
'title' => t('Tags: @tags', array(
'@tags' => str_replace(',', ', ', arg(3)),
)),
'type' => MENU_LOCAL_TASK,
'callback' => 'flickr_tags_photos',
'callback arguments' => array(
arg(1),
$nsid,
arg(3),
),
'access' => $view_access,
);
}
}
}
}
return $items;
}
function flickr_tags_cloud($uid, $nsid) {
drupal_add_css(drupal_get_path('module', 'flickr_tags') . '/flickr_tags.css');
$account = user_load(array(
'uid' => $uid,
));
$poptag_response = flickr_tags_get_list_user_popular($nsid, variable_get('flickr_tags_in_cloud', 150));
if ($poptag_response === FALSE) {
drupal_set_message(t('Error retrieving %user\'s tags from Flickr'), array(
'%user' => $account->name,
));
return '';
}
elseif (empty($poptag_response)) {
drupal_set_message(t('%user has no tags'), array(
'%user' => $account->name,
));
return '';
}
$tag_arr = array();
$tags = $poptag_response;
foreach ($tags as $tag) {
$tag_arr[$tag['_content']] = $tag['count'];
}
return theme('flickr_tags_cloud', $uid, $nsid, $tag_arr);
}
function flickr_tags_list($uid, $nsid) {
drupal_add_css(drupal_get_path('module', 'flickr_tags') . '/flickr_tags.css');
$account = user_load(array(
'uid' => $uid,
));
$taglist_response = flickr_tags_get_list_user($nsid);
if ($taglist_response === FALSE) {
drupal_set_message(t('Error retrieving %user\'s tags from Flickr'), array(
'%user' => $account->name,
));
return '';
}
elseif (empty($taglist_response)) {
drupal_set_message('%user has no tags', array(
'%user' => $account->name,
));
return '';
}
$tags = $taglist_response;
$tag_arr = array();
foreach ($tags as $tag) {
$tag_arr[] = $tag['_content'];
}
return theme('flickr_tags_list', $uid, $nsid, $tag_arr);
}
function flickr_tags_photos($uid, $nsid, $tagstring) {
global $pager_page_array, $pager_total, $pager_total_items;
drupal_add_css(drupal_get_path('module', 'flickr') . '/flickr.css');
$tag_arr = explode(',', $tagstring);
$account = user_load(array(
'uid' => $uid,
));
$element = 0;
$pager_page_array[$element] = empty($_GET['page']) ? 0 : (int) $_GET['page'];
$photo_arr = flickr_photos_search($nsid, $pager_page_array[$element] + 1, flickr_tag_request_args($tag_arr));
if ($photo_arr === FALSE) {
drupal_set_message(t('Error retrieving %user\'s photos from Flickr'), array(
'%user' => $account->name,
));
return '';
}
else {
if (empty($photo_arr)) {
drupal_set_message(t('No photos tagged with %tags found in %user\'s Flickr account'), array(
'%user' => $account->name,
'%tags' => str_replace(',', ', ', $tagstring),
));
return '';
}
}
$pager_total[$element] = $photo_arr['pages'];
$pager_total_items[$element] = $photo_arr['total'];
return theme('flickr_photos', $uid, $photo_arr);
}
function theme_flickr_tags_list($uid, $nsid, $tag_arr) {
$output = "<ul id='flickr_taglist'>\n";
$first_char = '';
foreach ($tag_arr as $tag) {
if ($first_char != substr($tag, 0, 1)) {
$new_item = TRUE;
}
else {
$new_item = FALSE;
}
if ($first_char != '' && $new_item) {
$output .= "</ul></li>\n";
}
if ($new_item) {
$first_char = substr($tag, 0, 1);
$output .= "<li><ul>\n";
}
$output .= "<li>\n";
$output .= l($tag, "flickr/{$uid}/tags/{$tag}") . "\n";
$output .= "</li>\n";
}
if ($first_char != '') {
$output .= "</ul></li>\n";
}
$output .= "</ul>\n";
return $output;
'';
}
function theme_flickr_tags_cloud($uid, $nsid, $tag_arr) {
$max_occur = max($tag_arr);
$min_occur = max($tag_arr);
$max_font = 3.5;
$min_font = 0.7;
$output = "<ul id='flickr_tagcloud'>\n";
foreach ($tag_arr as $tagname => $occurences) {
$font_size = round(($max_font - $min_font) * sqrt($occurences / $max_occur) + $min_font, 1);
$output .= "<li style='font-size: {$font_size}em'>\n";
$output .= l($tagname, "flickr/{$uid}/tags/{$tagname}") . "\n";
$output .= "</li>\n";
}
$output .= "</ul>\n";
return $output;
}