17 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
41 parent::__construct();
42 $this->static_screens[
'details'][
'lock_type'] =
'attr_links';
43 unset($this->static_screens[
'lookupValues']);
60 $wa = $asset->writeAccess(
'attributes');
62 text_box($prefix.
'_filename', $asset->attr(
'name'), 25);
64 echo $asset->attr(
'name');
83 $wa = $asset->writeAccess(
'attributes');
84 $submitted = isset($_REQUEST[$prefix.
'_filename']) && !empty($_REQUEST[$prefix.
'_filename']);
85 $process = $wa && $submitted;
88 $info = get_file_upload_info($prefix);
91 if ($info !== FALSE && !empty($info)) {
95 if ($asset->name != $_REQUEST[$prefix.
'_filename']) {
97 $info[
'name'] = $_REQUEST[$prefix.
'_filename'];
98 $info[
'tmp_name'] = $asset->data_path.
'/'.$asset->name;
99 $info[
'non_uploaded_file'] = TRUE;
100 $info[
'setting_filename'] = TRUE;
128 if (!empty($_REQUEST[
'redirect_header'])) {
129 $url = strip_url($asset->getUrl()).
'/'.SQ_CONF_LIMBO_SUFFIX
130 .
'?SQ_BACKEND_PAGE=header'
131 .
'¤t_assetid='.$asset->id
132 .
'&sq_popups_blocked=0';
134 <script type=
"text/javascript">
135 if (parent.frames[
"sq_header"]) {
136 lock_type = parent.frames[
"sq_main"].get_form_element_value(
'sq_lock_type');
137 parent.frames[
"sq_header"].location =
"<?php echo $url ?>" +
"&sq_lock_type=" + lock_type;
143 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
145 echo
'<div id="'.$prefix.
'_file_pre_upload" style="display:none;">';
146 combo_box($prefix.
'_server_file', Array(
''=>
'')+$options, FALSE, Array());
148 normal_button($prefix.
'_simple_upload_button', translate(
'core_upload_new_file_button'),
'document.getElementById(\''.$prefix.
'_file_pre_upload\').style.display=\'none\';
149 document.getElementById(\''.$prefix.
'_choose_server_file_button\').parentNode.style.display=\'\'; document.getElementById(\''.$prefix.
'_server_file\').value = \'\'');
153 echo
'<div id="'.$prefix.
'_file_upload">';
154 file_upload($prefix);
157 normal_button($prefix.
'_choose_server_file_button', translate(
'core_upload_server_file_button'),
158 'document.getElementById(\''.$prefix.
'_file_upload\').style.display=\'none\';
159 document.getElementById(\''.$prefix.
'_simple_upload_button\').parentNode.style.display=\'\'');
165 $max_size = strtolower($GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_MAX_SIZE'));
167 if (substr($max_size, -1) ==
'k') {
168 $max_size = $max_size * 1024;
169 }
else if (substr($max_size, -1) ==
'm') {
170 $max_size = $max_size * 1024 * 1024;
174 $ini_size = strtolower(ini_get(
'upload_max_filesize'));
175 if (substr($ini_size, -1) ==
'k') {
176 $ini_size = $ini_size * 1024;
177 }
else if (substr($ini_size, -1) ==
'm') {
178 $ini_size = $ini_size * 1024 * 1024;
182 $post_size = strtolower(ini_get(
'post_max_size'));
183 if (substr($post_size, -1) ==
'k') {
184 $post_size = $post_size * 1024;
185 }
else if (substr($post_size, -1) ==
'm') {
186 $post_size = $post_size * 1024 * 1024;
189 $mem_limit_size = strtolower(ini_get(
'memory_limit'));
190 if (substr($mem_limit_size, -1) ==
'k') {
191 $mem_limit_size = $mem_limit_size * 1024;
192 }
else if (substr($mem_limit_size, -1) ==
'm') {
193 $mem_limit_size = $mem_limit_size * 1024 * 1024;
195 $max_size = min($ini_size, $post_size, $mem_limit_size);
197 ?><br/><span style=
"font-size: 10px;"><?php echo translate(
'core_cannot_upload_file_larger_than', strtoupper(easy_filesize($max_size))); ?></span><?php
198 if (!empty($asset->allowed_extensions)) {
199 $o->
note(translate(
'core_only_upload_files_of_type', make_readable_list($asset->allowed_extensions, strtolower(translate(
'and')))));
224 if (isset($_POST[$prefix.
'_server_file']) && empty($_POST[$prefix.
'_server_file'])){
259 public function processFileUpload(
File $asset, &$o, $prefix, Array $info=Array(), $redirect_in_limbo=TRUE, $asset_cloned=FALSE)
261 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
262 if (empty($info) && isset($_POST[$prefix.
'_server_file']) && !empty($_POST[$prefix.
'_server_file'])) {
267 if (!$asset->id)
return TRUE;
270 $info = get_file_upload_info($prefix);
272 if ($info === FALSE || empty($info)) {
278 if (!isset($info[
'path'])) {
279 $info[
'path'] = array_get_index($info,
'tmp_name',
'');
282 if (!isset($info[
'filename'])) {
283 $info[
'filename'] = array_get_index($info,
'name',
'');
286 $setting_filename = FALSE;
287 if (isset($info[
'setting_filename'])) {
288 $setting_filename = array_get_index($info,
'setting_filename', FALSE);
291 if (!$asset->
validFile($info))
return FALSE;
294 if (isset($info[
'path']) && !empty($info[
'path'])) {
295 $status = $asset->
scanFile($info[
'path']);
298 trigger_localised_error(
'CORE0300', E_USER_WARNING, $info[
'filename']);
303 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
304 $name = current(make_valid_web_paths(Array($info[
'name'])));
307 if (!defined(
'SQ_IN_IMPORT') && $asset->name != $name) {
308 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_SC_LINK_SIGNIFICANT,
'', NULL,
'minor');
309 for ($i = 0; $i < count($parents); $i++) {
310 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parents[$i][
'majorid'], $parents[$i][
'major_type_code']);
311 if (is_null($parent))
continue;
312 $bad_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($parent, Array($name), $asset->id);
313 if (!empty($bad_paths)) {
314 trigger_localised_error(
'CORE0055', E_USER_WARNING, $name);
321 create_directory($asset->data_path);
326 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
329 if ($setting_filename === TRUE) {
333 if ($asset->name != $name && !empty($existing)) {
341 if ($asset->name == $name && !empty($existing)) {
342 $file_status = $fv->upToDate($asset->data_path.
'/'.$name);
343 if (FUDGE_FV_MODIFIED & $file_status) {
344 if (!$fv->commit($asset->data_path.
'/'.$name,
'')) {
345 trigger_localised_error(
'CORE0034', E_USER_WARNING);
351 if (!$fv->add($asset->data_path_suffix, $asset->data_path.
'/'.$name,
'')) {
352 trigger_localised_error(
'CORE0026', E_USER_WARNING);
358 if (!$fv->checkOut($asset->data_path_suffix.
'/'.$name, $asset->data_path)) {
359 trigger_localised_error(
'CORE0032', E_USER_WARNING);
364 $asset->_tmp[
'uploading_file'] = TRUE;
367 trigger_localised_error(
'CORE0052', E_USER_WARNING);
370 $asset->_tmp[
'uploading_file'] = FALSE;
374 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'remap_manager');
375 $auto_add_remaps = $rm->attr(
'remap_upon_webpath_change');
376 if (!defined(
'SQ_IN_IMPORT') && !($asset_cloned) && !($asset->
saveWebPaths(Array($name),$auto_add_remaps))) {
377 trigger_localised_error(
'CORE0054', E_USER_WARNING);
381 if (SQ_IN_LIMBO && $name_changed && $redirect_in_limbo) {
384 if (!$asset->
attr(
'allow_unrestricted')) {
385 $o->setRedirect(strip_url($asset->getUrl()).
'/'.SQ_CONF_LIMBO_SUFFIX.
'?redirect_header=1');
389 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
390 $em->broadcastEvent($asset,
'ContentsUpdated');
414 if (!$create && (empty($asset->id) || array_get_index($asset->_tmp,
'__creating__'))) {
418 if ($asset->
writeAccess(
'attributes') && isset($_POST[$prefix.
'_server_file']) && (!empty($_POST[$prefix.
'_server_file']))) {
421 unlink($info[
'tmp_name']);
442 return !empty($preuploads);
464 foreach (list_files(SQ_TEMP_PATH) as $filename) {
465 if (substr($filename, 0, 1) ==
'.')
continue;
466 $options[$filename] = $filename;
489 $result = $fv->
remove($existing[
'path'],
'');
490 if ($result != FUDGE_FV_OK && $result != FUDGE_FV_NOT_CHECKED_OUT) {
491 trigger_localised_error(
'CORE0042', E_USER_WARNING);
497 $unrestricted = $asset->data_path_public.
'/'.$existing[
'filename'];
498 if (file_exists($unrestricted)) {
519 if (is_uploaded_file($info[
'tmp_name'])) {
521 if (!move_uploaded_file($info[
'tmp_name'], $asset->data_path.
'/'.$name)) {
522 trigger_localised_error(
'CORE0037', E_USER_WARNING, $info[
'tmp_name'], $asset->data_path.
'/'.$name);
525 }
else if (isset($info[
'non_uploaded_file']) && $info[
'non_uploaded_file'] === TRUE) {
527 if (!copy($info[
'tmp_name'], $asset->data_path.
'/'.$name)) {
528 trigger_localised_error(
'CORE0036', E_USER_WARNING, $info[
'tmp_name'], $asset->data_path.
'/'.$name);
531 }
else if (isset($info[
'created_file']) && $info[
'created_file'] === TRUE) {
533 if (!rename($info[
'tmp_name'].
'/'.$name, $asset->data_path.
'/'.$name)) {
534 trigger_localised_error(
'CORE0036', E_USER_WARNING, $info[
'tmp_name'], $asset->data_path.
'/'.$name);
539 trigger_localised_error(
'CORE0067', E_USER_ERROR);
557 if (isset($_POST[$prefix.
'_server_file']) && (!empty($_POST[$prefix.
'_server_file']))) {
558 $filename = trim($_POST[$prefix.
'_server_file'],
'./');
559 $info[
'name'] = $filename;
560 $info[
'tmp_name'] = SQ_TEMP_PATH.
'/'.$filename;
561 $info[
'non_uploaded_file'] = TRUE;
579 if (!empty($existing)) {
580 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
583 <b><a href=
"<?php echo current_url(TRUE, TRUE).'?a='.$asset->id?>&now=<?php echo time()?>" target=
"_blank"><?php echo translate(
'core_current_file'); ?></a></b><br/>
584 <b><?php echo translate(
'info'); ?>:</b> <?php echo get_asset_tag_line($asset->id); ?><br/>
585 <b><?php echo translate(
'size'); ?>:</b> <?php echo easy_filesize($existing[
'size'])?><br/>
586 <b><?php echo translate(
'updated'); ?>:</b> <?php echo readable_datetime($existing[
'modified'])?>