1: <?php
2: 3: 4: 5: 6: 7:
8: class Ansel_Form_Upload extends Horde_Form
9: {
10: protected $_useFormToken = false;
11:
12: public function __construct(&$vars, $title)
13: {
14: global $gallery, $conf;
15:
16: parent::Horde_Form($vars, $title);
17:
18: $filesize = ini_get('upload_max_filesize');
19: if (substr($filesize, -1) == 'M') {
20: $filesize = $filesize * 1048576;
21: }
22: $filesize = $this->_get_size($filesize);
23:
24: $postsize = ini_get('post_max_size');
25: if (substr($postsize, -1) == 'M') {
26: $postsize = $postsize * 1048576;
27: }
28: $postsize = $this->_get_size($postsize);
29:
30: $this->setButtons(array(_("Upload"), _("Cancel")));
31: $this->addHidden('', 'gallery', 'text', false);
32: $this->addHidden('', 'page', 'text', false);
33:
34: $this->setSection('single_file', _("Single Photo"));
35: $this->addHidden('', 'image0', 'text', false);
36: if (!strlen($vars->get('image0'))) {
37: $upload = &$this->addVariable(
38: _("File to upload"), 'file0', 'file', false, false,
39: _("Maximum photo size:") . ' ' . $filesize, array(false));
40: $upload->setHelp('upload');
41: }
42: $this->addVariable(_("Make this the default photo for this gallery?"), 'image0_default', 'boolean', false);
43: $this->addVariable(_("Caption"), 'image0_desc', 'longtext', false, false, null, array('4', '40'));
44: $this->addVariable(_("Tags"), 'image0_tags', 'text', false, false, _("Separate tags with commas."));
45:
46: $this->setSection('multi_file', _("Multiple Photos"));
47:
48: if (!strlen($vars->get('image0'))) {
49: $msg = sprintf(_("Maximum photo size: %s; with a total of: %s"),
50: $filesize, $postsize);
51: $this->addVariable($msg, 'description', 'description', false);
52: }
53:
54:
55: for ($i = 1; $i <= $conf['image']['num_uploads']; $i++) {
56: $this->addHidden('', 'image' . $i, 'text', false);
57: if (!strlen($vars->get('image' . $i))) {
58: $upload = &$this->addVariable(sprintf(_("File %s"), $i), 'file' . $i, 'file', false, false, null, array(false));
59: $upload->setHelp('upload');
60: }
61: }
62:
63: $this->setSection('zip_file', _("Zip File Upload"));
64: $this->addHidden('', 'image' . ($conf['image']['num_uploads'] + 1), 'text', false);
65: if (!strlen($vars->get('zip'))) {
66: $upload = &$this->addVariable(
67: _("File to upload"),
68: 'file' . ($conf['image']['num_uploads'] + 1),
69: 'file', false, false,
70: _("Maximum file size:") . ' ' . $filesize);
71: $upload->setHelp('upload');
72: }
73: }
74:
75: 76: 77:
78: protected function _get_size($size)
79: {
80: $bytes = array('B', 'KB', 'MB', 'GB', 'TB');
81:
82: foreach ($bytes as $val) {
83: if ($size > 1024) {
84: $size = $size / 1024;
85: } else {
86: break;
87: }
88: }
89:
90: return round($size, 2) . ' ' . $val;
91: }
92:
93: }
94: