forked from DBCDK/ting_search_carousel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathting_search_carousel.module
170 lines (144 loc) · 4.45 KB
/
ting_search_carousel.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
<?php
/**
* @file
* Ting search carousel module main file.
*/
/**
* Implements hook_menu().
*/
function ting_search_carousel_menu() {
$items = array();
$items['admin/config/ting/ting_search_carousel'] = array(
'title' => 'Ting search carousel',
'description' => 'Manage frontpage carousel',
'page callback' => 'ting_search_carousel_admin_page',
'page arguments' => array(),
'access arguments' => array('access administration pages'),
'file' => 'ting_search_carousel.admin.inc',
'weight' => 30,
'position' => 'left',
);
$items['ting_search_carousel/results/ajax'] = array(
'title' => 'Show search carousel results',
'page callback' => 'ting_search_carousel_result',
'access arguments' => array('access content'),
'file' => 'ting_search_carousel.pages.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_block_info().
*/
function ting_search_carousel_block_info() {
$blocks = array();
$blocks['ting_search_carousel'] = array(
'info' => 'Ting search carousel'
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function ting_search_carousel_block_view($delta) {
$block = array();
switch ($delta) {
case 'ting_search_carousel':
$searches = variable_get('ting_carousel_search_queries', array());
$block['content'] = theme('ting_search_carousel', array('searches' => $searches));
break;
}
return $block;
}
/**
* Implements hook_theme().
*/
function ting_search_carousel_theme($existing, $type, $theme, $path) {
$hooks = array();
$hooks['ting_search_carousel'] = array(
'variables' => array('searches' => NULL),
'template' => 'ting_search_carousel'
);
$hooks['ting_search_carousel_collection'] = array(
'variables' => array('collection' => NULL),
'template' => 'ting_search_carousel_collection'
);
$hooks['ting_search_carousel_admin_form'] = array(
'render element' => 'form',
);
return $hooks;
}
/**
* Implements hook_ctools_plugin_directory().
*/
function ting_search_carousel_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' || $module == 'panels') {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_cron().
*/
function ting_search_carousel_cron() {
ting_search_carousel_do_request(TRUE);
}
/**
* Perform a ting search, retrieve covers and store some of data in cache.
*/
function ting_search_carousel_do_request($full = FALSE) {
$search_queries = variable_get('ting_carousel_search_queries', array());
$sort = variable_get('ting_search_carousel_item_sorting', '');
$search_items = array();
// There are any queries set.
if (count($search_queries) > 0) {
module_load_include('with_images.inc', 'ting');
$j = 0;
// Search for each query up to 100 items.
foreach ($search_queries as $item) {
$results = ting_get_objects_with_images($item['query'], 100, $sort, array('ting_search_carousel'));
// For each found collection, find a related item with cover.
foreach ($results as $object) {
$item = new stdClass();
$item->id = $object->getLocalId();
$creator = $object->getCreators();
$item->creator = !empty($creator) ? $creator[0] : '';
$item->title = $object->getTitle();
$item->image = $object->getImage('ting_search_carousel');
$item->alt = !empty($creator) ? $creator[0] . ': ' . $item->title : $item->title;
$search_items[$j][] = $item;
}
$j++;
}
}
// Clear & set the cache.
cache_clear_all('ting_search_result', 'cache');
cache_set('ting_search_result', $search_items, 'cache');
}
/**
* Implements hook_image_default_styles().
*/
function ting_search_carousel_image_default_styles() {
$styles = array();
$styles['ting_search_carousel'] = array(
'name' => 'ting_search_carousel',
'effects' => array(
0 => array(
'label' => 'Scale',
'help' => 'Scaling will maintain the aspect-ratio of the original image. If only a single dimension is specified, the other dimension will be calculated.',
'effect callback' => 'image_scale_effect',
'dimensions callback' => 'image_scale_dimensions',
'form callback' => 'image_scale_form',
'summary theme' => 'image_scale_summary',
'module' => 'image',
'name' => 'image_scale',
'data' => array(
'width' => '',
'height' => '140',
'upscale' => 0,
),
'weight' => '1',
),
),
);
return $styles;
}