View source
<?php
function shrinktheweb_help($path, $arg) {
switch ($path) {
case 'admin/help#shrinktheweb':
return '<p>' . t('You can find the latest help information for the ShrinkTheWeb module at !url .', array(
'!url' => '<a href="http://drupal.org/node/1067900" target="_blank">http://drupal.org/node/1067900</a>',
)) . '</p>';
}
}
function shrinktheweb_permission() {
return array(
'administer ShrinkTheWeb settings' => array(
'title' => t('Administer ShrinkTheWeb settings'),
'description' => t('Set API keys and other configuration options for the ShrinkTheWeb module.'),
),
);
}
function shrinktheweb_menu() {
$items = array();
$items['admin/config/media/shrinktheweb'] = array(
'title' => 'ShrinkTheWeb',
'description' => 'Configure API settings such as public, private keys, thumbnails cache and other',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'shrinktheweb_admin_settings',
),
'access arguments' => array(
'administer ShrinkTheWeb settings',
),
'file' => 'shrinktheweb.admin.inc',
);
$items['admin/config/media/shrinktheweb/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/media/shrinktheweb/log'] = array(
'title' => 'Log',
'description' => 'Browse the request records',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'shrinktheweb_admin_log',
),
'access arguments' => array(
'administer ShrinkTheWeb settings',
),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
'file' => 'shrinktheweb.admin.inc',
);
return $items;
}
function shrinktheweb_get_thumbnail($url, $options = array()) {
module_load_include('inc', 'shrinktheweb', 'shrinktheweb.api');
$sImageURL = shrinktheweb_getThumbnailURL($url, $options);
return $sImageURL;
}
function shrinktheweb_theme($existing, $type, $theme, $path) {
return array(
'shrinktheweb_image' => array(
'variables' => array(
'url' => NULL,
'options' => array(),
),
),
'shrinktheweb_image_link' => array(
'variables' => array(
'url' => NULL,
'options' => array(),
),
),
'shrinktheweb_formatter_shrinktheweb_link_no_text' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_default' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_plain' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_url' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_short' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_label' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_separate' => array(
'variables' => array(
'element' => NULL,
),
),
'shrinktheweb_formatter_shrinktheweb_link_image' => array(
'variables' => array(
'element' => NULL,
),
),
);
}
function theme_shrinktheweb_image($variables) {
$url = $variables['url'];
$options = $variables['options'];
if ($src = shrinktheweb_get_thumbnail($url)) {
$options['path'] = $src;
$options['attributes'] = !empty($options['attributes']) ? $options['attributes'] : array();
return theme_image($options);
}
return FALSE;
}
function theme_shrinktheweb_image_link($variables) {
$url = $variables['url'];
$options = $variables['options'];
if ($img = theme('shrinktheweb_image', $variables)) {
$options['html'] = TRUE;
$options['attributes'] = !empty($options['attributes']) ? $options['attributes'] : array();
return l($img, $url, $options);
}
return FALSE;
}
function shrinktheweb_field_formatter_info() {
return array(
'shrinktheweb_link_no_text' => array(
'label' => t('[ShrinkTheWeb] No link text'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_default' => array(
'label' => t('[ShrinkTheWeb] Title, as link'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_url' => array(
'label' => t('[ShrinkTheWeb] URL, as link'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_plain' => array(
'label' => t('[ShrinkTheWeb] URL, as plain text'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_short' => array(
'label' => t('[ShrinkTheWeb] Short, as link with title "Link"'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_label' => array(
'label' => t('[ShrinkTheWeb] Label, as link with label as title'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_separate' => array(
'label' => t('[ShrinkTheWeb] Separate title and URL'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
'shrinktheweb_link_image' => array(
'label' => t('[ShrinkTheWeb] Image, as link'),
'field types' => array(
'link_field',
),
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
),
);
}
function shrinktheweb_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$elements = array();
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#markup' => theme('shrinktheweb_formatter_' . $display['type'], array(
'element' => $item,
'field' => $instance,
)),
);
}
return $elements;
}
function theme_shrinktheweb_formatter_shrinktheweb_link_no_text($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
return $preview;
}
function theme_shrinktheweb_formatter_shrinktheweb_link_default($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
if (!empty($vars['element']['title']) && !empty($vars['element']['url'])) {
return $preview . l($vars['element']['title'], $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
));
}
elseif (!empty($vars['element']['title'])) {
return check_plain($vars['element']['title']);
}
elseif (!empty($vars['element']['url'])) {
return $preview . l($vars['element']['title'], $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
));
}
}
function theme_shrinktheweb_formatter_shrinktheweb_link_plain($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
return empty($vars['element']['url']) ? check_plain($vars['element']['title']) : $preview . url($vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
));
}
function theme_shrinktheweb_formatter_shrinktheweb_link_url($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
return $vars['element']['url'] ? $preview . l($vars['element']['display_url'], $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
)) : '';
}
function theme_shrinktheweb_formatter_shrinktheweb_link_short($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
return $vars['element']['url'] ? $preview . l(t('Link'), $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
)) : '';
}
function theme_shrinktheweb_formatter_shrinktheweb_link_label($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
return $vars['element']['url'] ? $preview . l($vars['field']['label'], $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
)) : '';
}
function theme_shrinktheweb_formatter_shrinktheweb_link_separate($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
$class = empty($vars['element']['attributes']['class']) ? '' : ' ' . $vars['element']['attributes']['class'];
unset($vars['element']['attributes']['class']);
$title = empty($vars['element']['title']) ? '' : check_plain($vars['element']['title']);
$output = '';
$output .= '<div class="link-item ' . $class . '">';
if (!empty($title)) {
$output .= '<div class="link-title">' . $title . '</div>';
}
if (!empty($preview)) {
$output .= '<div class="link-preview">' . $preview . '</div>';
}
$output .= '<div class="link-url">' . l($vars['element']['url'], $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
)) . '</div>';
$output .= '</div>';
return $output;
}
function theme_shrinktheweb_formatter_shrinktheweb_link_image($vars) {
$preview = theme('shrinktheweb_image', array(
'url' => $vars['element']['url'],
'options' => array(
'attributes' => array(
'class' => array(
'shrinktheweb',
),
),
),
));
return $vars['element']['url'] ? l($preview, $vars['element']['url'], array(
'attributes' => $vars['element']['attributes'],
'html' => TRUE,
)) : '';
}
function shrinktheweb_file_download($uri) {
if (preg_match('/^' . file_default_scheme() . ':\\/\\/' . variable_get('shrinktheweb_thumbs_folder', '') . '(.*?)\\.jpg$/si', $uri)) {
$info = image_get_info($uri);
return array(
'Content-Type' => $info['mime_type'],
);
}
}