This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_slideshow.module
282 lines (221 loc) · 8.07 KB
/
pdf_slideshow.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
require_once('file.inc');
/**
* Implementation of hook_perm()
*/
function pdf_slideshow_perm() {
return array('administer pdf slideshow');
}
/**
* Implementation of hook_menu()
*/
function pdf_slideshow_menu($may_cache) {
drupal_add_css(drupal_get_path('module', 'pdf_slideshow').'/css/pdf_slideshow.css');
drupal_add_js(drupal_get_path('module', 'pdf_slideshow').'/js/jquery.fancybox/jquery.fancybox-1.2.1.pack.js');
drupal_add_js(drupal_get_path('module', 'pdf_slideshow').'/js/jquery.fancybox/jquery.easing.1.3.js');
drupal_add_css(drupal_get_path('module', 'pdf_slideshow').'/js/jquery.fancybox/jquery.fancybox.css');
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/pdfslideshow',
'title' => t('PDF Slideshow'),
'description' => t('Configure PDF Slideshow settings.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('pdf_slideshow_admin_settings'),
'access' => user_access('administer pdf slideshow'),
'type' => MENU_NORMAL_ITEM,
);
}
else {
$nid = arg(1);
$fid = arg(3);
if (is_numeric($nid) && is_numeric($fid) && $node = node_load($nid)) {
if ($file = $node->files[$fid]) {
$items[] = array(
'path' => 'node/'. $node->nid.'/file/'.$fid.'/show',
'title' => t('View'),
'callback' => 'node_pdf_slideshow',
'callback arguments' => array(arg(1), arg(3)),
'access' => node_access('view', $node),
'type' => MENU_CALLBACK
);
}
}
if (is_numeric($nid) && is_numeric($fid) && $node = node_load($nid)) {
if ($file = $node->files[$fid]) {
$items[] = array(
'path' => 'node/'. $node->nid.'/file/'.$fid.'/gallery',
'title' => t('Gallery view'),
'callback' => 'node_pdf_gallery',
'callback arguments' => array(arg(1), arg(3)),
'access' => node_access('view', $node),
'type' => MENU_CALLBACK
);
}
}
}
return $items;
}
function _handle_position($images) {
$max = count($images);
//$max--;
if (!is_numeric($_GET['position']) || $_GET['position'] < 0 || !$_GET['position']) {
return 1;
}
if ($_GET['position'] > $max) {
return $max;
}
return $_GET['position'];
}
function theme_pdf_slideshow_navigator($position, $fragment = 'pdf_preview_box', $counter = 1) {
if ($counter > 1) {
$output .= '<div class="pdf_navigation">';
$output .= '<div style="float: left;">';
if ($position > 1) $output .= l(t('< Previous'), $_GET['q'], array(), 'position='.($position ? $prev = $position - 1 : 1), $fragment);
$output .= '</div>';
$output .= '<div style="float: right;">';
if ($position != $counter) $output .= l(t('Next >'), $_GET['q'], array(), 'position='.($position ? $next = $position + 1 : 1), $fragment);
$output .= '</div>';
$output .= '</div>';
return $output;
}
}
function theme_pdf_slideshow($node, $file, $ret) {
drupal_set_title(l($node->title, 'node/'.$node->nid));
if (module_exists('euwi_breadcrumb')) {
$breadcrumb = init_breadcrumb();
foreach (module_implements('breadcrumb_alter') AS $module) {
$function = $module .'_breadcrumb_alter';
$function($breadcrumb, $node, 'node');
}
array_pop($breadcrumb);
array_push($breadcrumb, l($node->title, 'node/'.$node->nid));
array_push($breadcrumb, t('Document preview'));
drupal_set_breadcrumb($breadcrumb);
}
$target_dir = $ret['path'];
$images = convert_api_file_list($target_dir);
$target_rel_dir = $ret['rel_path'];
$position = _handle_position($images);
$pos_align = ($position - 1);
$output .= '<div id="pdf_preview_box">';
/* Navigator */
$output .= theme('pdf_slideshow_navigator', $position, 'pdf_preview_box', count($images));
$output .= theme('image', $target_rel_dir.'/'.$images[$pos_align], array(), array(), array('width' => '600'));
//var_dump($output); die;
/* Navigator */
$output .= theme('pdf_slideshow_navigator', $position, 'pdf_preview_box', count($images));
$output .= '</div>';
$output .= '<div style="text-align: center;">';
$output .= l(t('View as PDF'), file_create_url($file->filepath), array('class' => 'pdf')). ' | ';
$output .= l(t('View as Gallery'), str_replace('show', 'gallery', $_GET['q']));
$output .= '</div>';
return $output;
}
function theme_pdf_gallery($node, $file, $ret) {
drupal_set_title(l($node->title, 'node/'.$node->nid));
if (module_exists('euwi_breadcrumb')) {
$breadcrumb = init_breadcrumb();
foreach (module_implements('breadcrumb_alter') AS $module) {
$function = $module .'_breadcrumb_alter';
$function($breadcrumb, $node, 'node');
}
array_pop($breadcrumb);
array_push($breadcrumb, l($node->title, 'node/'.$node->nid));
array_push($breadcrumb, t('Document preview'));
drupal_set_breadcrumb($breadcrumb);
}
$target_dir = $ret['path'];
$images = convert_api_file_list($target_dir);
$target_rel_dir = $ret['rel_path'];
$position = _handle_position($images);
$pos_align = ($position - 1);
$output .= '<div id="pdf_preview_gallery" style="height: 600px; overflow: auto;">';
foreach($images as $image) {
$output .= l(theme('imagecache', 'pdf_gallery_thumb', $target_rel_dir.'/'.$image, array(), array(), array('style' => 'margin-right: 15px;')),
file_create_url($target_rel_dir.'/'.$image), array('class' => 'gallery', 'rel' => 'pdf_gallery'), NULL, NULL, FALSE, TRUE);
}
drupal_add_js('
$(document).ready(function() {
/* This is basic - uses default settings */
$("a.gallery").fancybox({ "zoomSpeedIn": 300, "zoomSpeedOut": 300, "overlayShow": false });
});
','inline');
$output .= '</div>';
$output .= '<div style="text-align: center;">';
$output .= l(t('View as PDF'), file_create_url($file->filepath), array('class' => 'pdf')). ' | ';
$output .= l(t('View as Book'), str_replace('gallery', 'show', $_GET['q']));
$output .= '</div>';
return $output;
}
function node_pdf_slideshow($nid, $fid) {
if (is_numeric($nid) && $node = node_load($nid)) {
if ($file = $node->files[$fid]) {
if ($res = conversion_api($file, $nid)) {
return theme('pdf_slideshow', $node, $file, $res);
}
else {
drupal_set_message(t('Error on conversion, please try again.'));
drupal_goto('node/' . $node->nid);
}
}
else {
drupal_goto('node/' . $node->nid);
}
}
}
function node_pdf_gallery($nid, $fid) {
if (is_numeric($nid) && $node = node_load($nid)) {
if ($file = $node->files[$fid]) {
if ($res = conversion_api($file, $nid)) {
return theme('pdf_gallery', $node, $file, $res);
}
else {
drupal_set_message(t('Error on conversion, please try again.'));
drupal_goto('node/' . $node->nid);
}
}
else {
drupal_goto('node/' . $node->nid);
}
}
}
function pdf_slideshow_admin_settings() {
$form['general'] = array(
'#type' => 'fieldset',
'#title' => t('General settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['general']['imagemagick_path'] = array(
'#type' => 'textfield',
'#title' => t('Imagemagick path'),
'#size' => 50,
'#default_value' => variable_get('imagemagick_path', exec('/usr/bin/which convert')),
'#description' => t('Path to imagemagick.'),
);
return system_settings_form($form);
}
function phptemplate_upload_attachments($files) {
$node = node_load(arg(1));
$header = array(t('Attachment'), t('Size'), t('Preview'));
$rows = array();
foreach ($files as $file) {
$file = (object)$file;
if ($file->list && !$file->remove) {
// Generate valid URL for both existing attachments and preview of new attachments (these have 'upload' in fid)
$href = file_create_url((strpos($file->fid, 'upload') === FALSE ? $file->filepath : file_create_filename($file->filename, file_create_path())));
$text = $file->description ? $file->description : $file->filename;
$preview_link = l(t('Preview'), 'node/'.$node->nid.'/file/'.$file->fid.'/show');
$rows[] = array(
l($text, $href),
format_size($file->filesize),
$preview_link,
);
}
}
if (count($rows)) {
return theme('table', $header, $rows, array('id' => 'attachments'));
}
}
?>