This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shrinktheweb_field.module
174 lines (165 loc) · 5.01 KB
/
shrinktheweb_field.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// $Id$
/**
* @file
* shrinktheweb Field allows links to web pages to be displayed as thumbnails
*
*/
/**
* Implements hook_menu()
*
*/
function shrinktheweb_field_menu() {
$items['admin/settings/shrinktheweb'] = array(
'title' => 'ShrinkTheWeb Account',
'description' => 'Details of your shrinktheweb Account.',
'page callback' => 'drupal_get_form',
'page arguments' => array('shrinktheweb_field_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Our admin form
*
*/
function shrinktheweb_field_admin_settings() {
$form['shrinktheweb_account_code'] = array(
'#type' => 'textfield',
'#title' => t('Your public access key'),
'#description' => t('The access key given to you by <a href="http://shrinktheweb.com">shrinktheweb.com</a> for access to web thumbnails.'),
'#default_value' => variable_get('shrinktheweb_account_code', ''),
);
$form['shrinktheweb_account_secret_code'] = array(
'#type' => 'textfield',
'#title' => t('Your secret access key'),
'#description' => t('The secret key given to you by <a href="http://shrinktheweb.com">shrinktheweb.com</a> for access to web thumbnails.'),
'#default_value' => variable_get('shrinktheweb_account_secret_code', ''),
);
return system_settings_form($form);
}
/**
* Declare our theme functions
*
*/
function shrinktheweb_field_theme() {
$theme = array(
'shrinktheweb_field_formatter_micro' => array(
'arguments' => array('element' => NULL),
'function' => 'theme_shrinktheweb_field_formatter',
),
'shrinktheweb_field_formatter_tiny' => array(
'arguments' => array('element' => NULL),
'function' => 'theme_shrinktheweb_field_formatter',
),
'shrinktheweb_field_formatter_verysmall' => array(
'arguments' => array('element' => NULL),
'function' => 'theme_shrinktheweb_field_formatter',
),
'shrinktheweb_field_formatter_small' => array(
'arguments' => array('element' => NULL),
'function' => 'theme_shrinktheweb_field_formatter',
),
'shrinktheweb_field_formatter_large' => array(
'arguments' => array('element' => NULL),
'function' => 'theme_shrinktheweb_field_formatter',
),
'shrinktheweb_field_formatter_xtralarge' => array(
'arguments' => array('element' => NULL),
'function' => 'theme_shrinktheweb_field_formatter',
),
);
return $theme;
}
/**
* Declare our formatters
*
*/
function shrinktheweb_field_field_formatter_info() {
$formatters = array();
$formatters['micro'] = array(
'label' => t('shrinktheweb micro image'),
'field types' => array('link'),
);
$formatters['tiny'] = array(
'label' => t('shrinktheweb tiny image'),
'field types' => array('link'),
);
$formatters['verysmall'] = array(
'label' => t('shrinktheweb very small image'),
'field types' => array('link'),
);
$formatters['small'] = array(
'label' => t('shrinktheweb small image'),
'field types' => array('link'),
);
$formatters['large'] = array(
'label' => t('shrinktheweb large image'),
'field types' => array('link'),
);
$formatters['xtralarge'] = array(
'label' => t('shrinktheweb xtralarge image'),
'field types' => array('link'),
);
return $formatters;
}
/**
* Themeable function for field output
*
*/
function theme_shrinktheweb_field_formatter($element) {
if ($element['#item']['url']) {
return shrinktheweb_field_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], $element['#item']['url'], $element['#node']->title);
}
}
/**
* Implementation of hook_field_formatter().
*/
function shrinktheweb_field_field_formatter($field, $item, $formatter, $url, $title) {
switch ($formatter) {
default:
case 'micro':
$size = 'mcr';
$width = 75;
$height = 56;
break;
case 'tiny':
$size = 'tiny';
$width = 200;
$height = 150;
break;
case 'verysmall':
$size = 'vsm';
$width = 100;
$height = 75;
break;
case 'small':
$size = 'sm';
$width = 120;
$height = 90;
break;
case 'large':
$size = 'lg';
$width = 200;
$height = 150;
break;
case 'xtralarge':
$size = 'xlg';
$width = 320;
$height = 240;
break;
}
if (variable_get('shrinktheweb_account_code', '')) {
$shrinktheweb_url = 'http://images.shrinktheweb.com/xino.php?embed=1' .
// '&stwu=' variable_get('shrinktheweb_account_secret_code', '') .
'&stwaccesskeyid='. variable_get('shrinktheweb_account_code', '') .
'&stwsize='. $size .'&stwurl='. _shrinktheweb_format_url($url);
$image = theme('image', $shrinktheweb_url, $title, $title, array('height' => $height, 'width' => $width), FALSE);
return l($image, $url, array('html' => TRUE, 'attributes' => $item['attributes']));
}
}
function _shrinktheweb_format_url($url) {
$parsed = parse_url($url);
return $parsed['host'];
}