1: <?php
2:
3: use FieldtypePDF\PagePDF;
4:
5: /*
6: * The MIT License
7: *
8: * Copyright 2015 Richard Jedlička <jedlicka.r@gmail.com> (http://uiii.cz)
9: *
10: * Permission is hereby granted, free of charge, to any person obtaining a copy
11: * of this software and associated documentation files (the "Software"), to deal
12: * in the Software without restriction, including without limitation the rights
13: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14: * copies of the Software, and to permit persons to whom the Software is
15: * furnished to do so, subject to the following conditions:
16: *
17: * The above copyright notice and this permission notice shall be included in
18: * all copies or substantial portions of the Software.
19: *
20: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26: * THE SOFTWARE.
27: */
28:
29: class InputfieldPDF extends InputfieldImage implements InputfieldItemList
30: {
31: public static function getModuleInfo()
32: {
33: return array(
34: 'version' => 110,
35: 'title' => __('PDF files with thumbnails', __FILE__), // Module Title
36: 'summary' => __('One or more pdf files upload with thumbnails', __FILE__), // Module Summary
37: 'href' => 'http://modules.processwire.com/modules/fieldtype-pdf',
38: 'author' => "Richard Jedlička",
39: 'requires' => array("FieldtypePDF")
40: );
41: }
42:
43: public function init()
44: {
45: parent::init();
46: $this->set('extensions', 'PDF');
47: }
48:
49: protected function ___fileAdded(Pagefile $pagefile)
50: {
51: // skip image resizing from InputfieldImage
52: return InputfieldFile::___fileAdded($pagefile);
53: }
54:
55: protected function ___renderItem($pagefile, $id, $n)
56: {
57: if ($pagefile instanceof PagePDF) {
58: $pagefile = $pagefile->toImage();
59: }
60:
61: return parent::___renderItem($pagefile, $id, $n);
62: }
63:
64: public function ___getConfigInputfields()
65: {
66: $inputfields = parent::___getConfigInputfields();
67:
68: $inputfields->get('maxWidth')->parent->collapsed = InputfieldPDF::collapsedHidden;
69:
70: if ($inputfields->has('minWidth')) { // PW 2.5
71: $inputfields->get('minWidth')->parent->collapsed = InputfieldPDF::collapsedHidden;
72: }
73:
74: return $inputfields;
75: }
76: }
77: