1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Picture Section |
4
|
|
|
* |
5
|
|
|
* @package Intraface_CMS |
6
|
|
|
* @author Lars Olesen <[email protected]> |
7
|
|
|
* @since 0.1.0 |
8
|
|
|
* @version @package-version@ |
9
|
|
|
*/ |
10
|
|
|
class Intraface_modules_cms_section_Picture extends CMS_Section |
11
|
|
|
{ |
12
|
|
|
function __construct($cmspage, $id = 0) |
13
|
|
|
{ |
14
|
|
|
$this->value['type'] = 'picture'; |
15
|
|
|
parent::__construct($cmspage, $id); |
16
|
|
|
$this->cmspage->kernel->useModule('filemanager'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function load_section() |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
$this->value['pic_id'] = $this->parameter->get('pic_id'); |
23
|
|
|
$size = $this->template_section->get('pic_size'); |
24
|
|
|
$this->cmspage->kernel->useModule('filemanager'); |
25
|
|
|
$this->value['picture'] = array(); |
26
|
|
|
|
27
|
|
|
if ($this->value['pic_id'] == 0) { |
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
$filemanager = new FileHandler($this->cmspage->kernel, $this->value['pic_id']); |
33
|
|
|
|
34
|
|
View Code Duplication |
if ($filemanager->get('id') > 0) { |
35
|
|
|
if ($size == 'original') { |
36
|
|
|
$this->value['picture'] = $filemanager->get(); |
37
|
|
|
} else { |
38
|
|
|
$filemanager->createInstance($size); |
39
|
|
|
$this->value['picture'] = $filemanager->instance->get(); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
function validate_section(& $var) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$validator = new Intraface_Validator($this->error); |
47
|
|
|
if (!empty($var['pic_id'])) { |
48
|
|
|
$validator->isNumeric($var['pic_id'], 'error in pic_id', 'allow_empty'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($this->error->isError()) { |
52
|
|
|
return 0; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
return 1; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function save_section($var) |
58
|
|
|
{ |
59
|
|
|
|
60
|
|
|
/* |
|
|
|
|
61
|
|
|
Det g�res nu i page.php |
62
|
|
|
if (!empty($_FILES['new_picture_'.$key])) { |
63
|
|
|
$filehandler = new FileHandler($kernel); |
64
|
|
|
$filehandler->loadUpload(); |
65
|
|
|
$filehandler->upload->setSetting('file_accessibility', 'public'); |
66
|
|
|
$id = $filehandler->upload->upload('new_picture_'.$key); |
67
|
|
|
|
68
|
|
|
if ($id != 0) { |
69
|
|
|
$var['pic_id'] = $id; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
*/ |
73
|
|
|
|
74
|
|
|
/* |
|
|
|
|
75
|
|
|
if (!empty($var['delete_picture'])) { |
76
|
|
|
$var['pic_id'] = 0; |
77
|
|
|
} |
78
|
|
|
elseif (!empty($_FILES) AND !empty($_FILES['userfile']['name'][$this->get('id')])) { |
79
|
|
|
$filehandler = new FileHandler($this->cmspage->kernel); |
80
|
|
|
$filehandler->loadUpload(); |
81
|
|
|
if (!$id = $filehandler->upload->upload('userfile['.$this->get('id').']')) { |
82
|
|
|
throw new Exception('Kunne ikke uploade filen'); |
83
|
|
|
} |
84
|
|
|
$var['pic_id'] = $id; |
85
|
|
|
if ($this->cmspage->kernel->user->hasModuleAccess('filemanager')) { |
86
|
|
|
$this->cmspage->kernel->useModule('filemanager'); |
87
|
|
|
$filemanager = new FileManager($this->cmspage->kernel, $var['pic_id']); |
88
|
|
|
if (!$filemanager->update(array('description' => $var['pic_text']))) { |
89
|
|
|
throw new Exception('Filemanager kunne ikke gemme teksten.'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
else { |
95
|
|
|
$var['pic_id'] = $this->parameter->get('pic_id'); |
96
|
|
|
} |
97
|
|
|
*/ |
98
|
|
|
if (!empty($var['pic_id'])) { |
99
|
|
|
$this->addParameter('pic_id', $var['pic_id']); |
100
|
|
|
} |
101
|
|
|
return 1; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.