18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
40 public $allowed_extensions = Array();
47 public $ignore_update = FALSE;
58 parent::__construct($assetid);
75 if (!parent::_preCreateCheck($link))
return FALSE;
77 $name = trim($this->
attr(
'name'));
79 trigger_localised_error(
'CORE0083', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
98 public function create(Array &$link, $info=Array())
100 $this->_tmp[
'file_create_data'] =& $info;
104 $info = get_file_upload_info($this->
getPrefix(), isset($info[
'non_uploaded_file']) && $info[
'non_uploaded_file']);
107 if ($info === FALSE || empty($info)) {
110 $info = $edit->getChosenFileInfo($this->
getPrefix());
113 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
114 if ($info === FALSE || empty($info)) {
115 trigger_localised_error(
'CORE0056', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
121 if (!isset($info[
'path'])) {
122 $info[
'path'] = array_get_index($info,
'tmp_name',
'');
124 if (!isset($info[
'filename'])) {
125 $info[
'filename'] = array_get_index($info,
'name',
'');
128 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
129 if (!$this->
validFile($info))
return FALSE;
132 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_DATA_VALIDATION)) {
134 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
135 $valid_names = make_valid_web_paths(Array($info[
'name']));
136 $name = array_shift($valid_names);
139 if (!defined(
'SQ_IN_IMPORT')) {
140 $bad_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($link[
'asset'], Array($name));
141 if (!empty($bad_paths)) {
142 trigger_localised_error(
'CORE0086', E_USER_WARNING, $name);
149 if (!isset($this->_tmp[
'vars_set'][
'allow_unrestricted'])) $this->
setAttrValue(
'allow_unrestricted', TRUE);
153 return parent::create($link);
173 if (!$lock_held = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($this->id,
'attributes')) {
181 $this->_tmp[
'uploading_file'] = 1;
182 $prefix = $this->
type().
'_0';
184 if ((!is_null($GLOBALS[
'SQ_SYSTEM']->backend)) && (!is_null($GLOBALS[
'SQ_SYSTEM']->backend->out))) {
185 $o = $GLOBALS[
'SQ_SYSTEM']->backend->out;
187 $info = $this->_tmp[
'file_create_data'];
189 $ret_val = $edit->processFileChooser($this, $o, $prefix, TRUE) || $edit->processFileUpload($this, $o, $prefix, $info, FALSE);
193 if ($lock_held == 1) {
194 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($this->
id,
'attributes');
245 $temp_info = Array(
'name' => $this->name,
'tmp_name' => $this->data_path.
'/'.$this->name,
'non_uploaded_file' => TRUE);
250 if (!$edit_fns->processFileUpload($clone, $GLOBALS[
'SQ_SYSTEM']->backend->out, $clone->
getPrefix(), $temp_info,TRUE, TRUE)) {
251 trigger_localised_error(
'CORE0010', E_USER_WARNING, $this->name, $this->
id);
255 return parent::cloneComponents($clone, $components, $override);
268 $lock_types = parent::lockTypes();
269 $lock_types[
'attr_links'] = ($lock_types[
'attributes'] | $lock_types[
'links']);
284 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
287 if (!create_directory($this->data_path)) {
288 trigger_localised_error(
'CORE0049', E_USER_WARNING, $this->name);
293 if (!create_directory($this->data_path.
'/.sq_system')) {
294 trigger_localised_error(
'CORE0050', E_USER_WARNING, $this->name);
299 if (!clear_directory($this->data_path.
'/.sq_system')) {
300 trigger_localised_error(
'CORE0046', E_USER_WARNING, $this->name);
305 if (!string_to_file(serialize($this), $this->data_path.
'/.sq_system/.object_data')) {
306 trigger_localised_error(
'CORE0051', E_USER_WARNING, $this->name);
310 $contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
311 foreach ($contexts as $contextid => $context_data) {
312 if ($contextid === 0) {
313 $files_to_copy = Array(
'metadata.php',
'metadata_field_values.php');
315 $files_to_copy = Array(
'metadata.'.$contextid.
'.php',
'metadata_field_values.'.$contextid.
'.php');
317 foreach ($files_to_copy as $filename) {
318 if (file_exists($this->data_path.
'/'.$filename) === TRUE) {
319 if (!copy_file($this->data_path.
'/'.$filename, $this->data_path.
'/.sq_system/'.$filename)){
320 trigger_localised_error(
'SYS0166', E_USER_WARNING, $this->name, $filename);
328 if (!parent::updateLookups()) {
329 trigger_localised_error(
'CORE0053', E_USER_WARNING, $this->name);
330 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
331 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
337 trigger_localised_error(
'CORE0053', E_USER_WARNING, $this->name);
338 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
339 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
345 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
346 $file_info = $fv->_checkOutCheck($this->data_path_suffix.
'/'.$this->name);
347 $latest_version = $file_info[
'version'];
348 if (!string_to_file($latest_version, $this->data_path.
'/.sq_system/sq_system_version_no')) {
349 trigger_localised_error(
'CORE0051', E_USER_WARNING, $this->name);
367 $se_name = $this->
attr(
'name');
371 $this->_tmp[
'uploading_file'] = TRUE;
372 if (!parent::revertToSystemVersion()) {
373 $this->_tmp[
'uploading_file'] = FALSE;
376 $this->_tmp[
'uploading_file'] = FALSE;
378 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
380 $file_version = NULL;
381 if (is_file($this->data_path.
'/sq_system_version_no')) {
382 $file_version = file_to_string($this->data_path.
'/sq_system_version_no');
387 if (!clear_directory($this->data_path, Array(
'metadata.php',
'metadata_field_values.php'))){
388 trigger_localised_error(
'CORE0045', E_USER_WARNING, $this->name);
392 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
396 if ($this->
attr(
'name') != $se_name) {
397 $se_rep_path = $this->data_path_suffix.
'/'.$se_name;
398 $result = $fv->remove($se_rep_path,
'');
399 if ($result != FUDGE_FV_OK && $result != FUDGE_FV_NOT_CHECKED_OUT) {
400 trigger_localised_error(
'CORE0042', E_USER_WARNING);
403 $removed_file_info = $fv->_checkOutCheck($se_rep_path);
404 $fv->_updateFile($removed_file_info[
'fileid'], $this->data_path_suffix, $this->data_path.
'/'.$se_name);
408 $rep_path = $this->data_path_suffix.
'/'.$this->name;
409 if (!$fv->checkOut($rep_path, $this->data_path, $file_version)) {
410 trigger_localised_error(
'CORE0044', E_USER_WARNING, $this->name);
415 $file_info = $fv->_checkOutCheck($rep_path, $file_version);
416 $fv->_updateFile($file_info[
'fileid'], $this->data_path_suffix, $this->data_path.
'/'.$this->name);
419 if (!$fv->checkOut($rep_path, $this->data_path)) {
420 trigger_localised_error(
'CORE0044', E_USER_WARNING, $this->name);
437 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
442 if (!create_directory($this->data_path_public)) {
443 trigger_localised_error(
'CORE0049', E_USER_WARNING, $this->name);
447 if (!clear_directory($this->data_path_public)) {
448 trigger_localised_error(
'CORE0305', E_USER_WARNING, $this->name);
452 return parent::clearSystemVersion();
466 public function morph($new_type_code)
468 $am = $GLOBALS[
'SQ_SYSTEM']->am;
470 $file_types = array_merge($am->getTypeAncestors($this->type(), FALSE), $am->getTypeDescendants($this->type()));
472 if (in_array($new_type_code, $file_types)) {
475 $am->includeAsset($new_type_code);
476 $tmp =
new $new_type_code();
478 if (!empty($existing)) {
479 if (!$tmp->validFile($existing)) {
480 trigger_localised_error(
'CORE0008', E_USER_WARNING, $this->name, $new_type_code, $existing[
'filename'], $new_type_code);
484 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
485 $fv->changeFvTypeCode($existing[
'path'], $new_type_code);
490 return parent::morph($new_type_code);
508 $this->ignore_update = TRUE;
511 $old_status = $this->status;
512 $this->_tmp[
'old_status'] = $old_status;
513 $this->_tmp[
'old_urls'] = $this->
getURLs();
514 $this->_tmp[
'allow_unrestricted'] = $this->
attr(
'allow_unrestricted');
516 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
517 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
519 if (!parent::processStatusChange($new_status, $update_parents, $run_updated)) {
520 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
521 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
528 $this->ignore_update = FALSE;
530 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
531 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
535 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
536 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
552 SQ_LINK_TYPE_1 => Array(),
553 SQ_LINK_TYPE_2 => Array(),
554 SQ_LINK_TYPE_3 => Array(),
555 SQ_LINK_NOTICE => Array(
558 'exclusive' => FALSE,
582 if (!parent::_updated($update_parents))
return FALSE;
584 if ($this->ignore_update == TRUE) {
588 if($this->status & SQ_SC_STATUS_SAFE_EDITING) {
607 if ($this->status & SQ_SC_STATUS_SAFE_EDITING) {
625 if ($this->status & SQ_SC_STATUS_SAFE_EDITING)
return TRUE;
627 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
630 if (empty($existing))
return TRUE;
632 $unrestricted = $this->data_path_public.
'/'.$existing[
'filename'];
639 if (!create_directory($this->data_path_public)) {
640 trigger_localised_error(
'CORE0049', E_USER_WARNING, $this->name);
644 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
646 if ($fv->upToDate($unrestricted) & (FUDGE_FV_NOT_CHECKED_OUT | FUDGE_FV_OLD_VERSION)) {
647 if (file_exists($unrestricted)) {
648 unlink($this->data_path_public.
'/'.$existing[
'filename']);
651 if ($fv->checkOut($this->data_path_suffix.
'/'.$existing[
'filename'], $this->data_path_public)) {
654 trigger_localised_error(
'CORE0032', E_USER_WARNING);
663 if (is_file($unrestricted)) {
664 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
665 if ($fv->clearOut($unrestricted) & FUDGE_FV_OK) {
668 trigger_localised_error(
'CORE0104', E_USER_WARNING);
692 if (empty($existing))
return TRUE;
694 $unrestricted = $this->data_path_public.
'/'.$existing[
'filename'];
695 if (is_file($unrestricted)) {
696 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
697 if ($fv->clearOut($unrestricted) & FUDGE_FV_OK) {
700 trigger_localised_error(
'CORE0104', E_USER_WARNING);
719 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
722 if (empty($existing))
return TRUE;
724 $unrestricted = $this->data_path_public.
'/'.$existing[
'filename'];
727 if (!create_directory($this->data_path_public)) {
728 trigger_localised_error(
'CORE0049', E_USER_WARNING, $this->name);
732 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
734 if ($fv->upToDate($unrestricted) & (FUDGE_FV_NOT_CHECKED_OUT | FUDGE_FV_OLD_VERSION)) {
735 if (file_exists($unrestricted)) {
736 unlink($this->data_path_public.
'/'.$existing[
'filename']);
739 if ($fv->checkOut($this->data_path_suffix.
'/'.$existing[
'filename'], $this->data_path_public)) {
742 trigger_localised_error(
'CORE0032', E_USER_WARNING);
761 return ($this->
attr(
'allow_unrestricted') && $this->
effectiveUnrestricted() && !($this->status & SQ_SC_STATUS_SAFE_EDITING));
777 if (!isset($this->_tmp[
'deleting_file'])) {
778 $this->_tmp[
'deleting_file'] = FALSE;
781 if (!$this->
usePublicPath() && !$this->_tmp[
'deleting_file']) {
784 $result = parent::updateLookups($auto_add_remaps);
792 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
794 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
796 unset($this->_tmp[
'lookups']);
797 unset($this->_tmp[
'url']);
798 unset($this->_tmp[
'href']);
801 $bind_vars = Array(
'assetid' => $this->
id);
803 }
catch (Exception $e) {
804 throw new Exception(
'Unable to delete lookup information for asset: '.$this->
id.
' due to database error: '.$e->getMessage());
807 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
808 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
822 $parameter = Array();
823 if (isset($this->_tmp[
'old_status'])) {
824 $parameter[
'old_status'] = $this->_tmp[
'old_status'];
826 if (!empty($old_urls)) {
827 $parameter[
'old_urls'] = $old_urls;
829 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
830 $em->broadcastEvent($this,
'LookupsUpdated', Array(
'asset_name' => $this->name));
831 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_lookups_updated', $this, $parameter);
847 if (!isset($existing[
'filename'])) {
855 $save_urls = Array();
856 $root_urls = explode(
"\n", trim(SQ_CONF_SYSTEM_ROOT_URLS));
858 if (!SQ_CONF_STATIC_ROOT_URL ==
'') {
859 if (!$GLOBALS[
'SQ_SYSTEM']->am->assetInTrash($this->id, TRUE)){
861 $web_path = str_replace(sq_web_path(
'data').
'/',
'', $this->
getWebDataPath()).
'/'.$existing[
'filename'];
862 $save_urls[SQ_CONF_STATIC_ROOT_URL] = Array(
'http' => SQ_CONF_STATIC_ROOT_HTTP,
'https' => SQ_CONF_STATIC_ROOT_HTTPS);
866 $web_path = str_replace(sq_web_path(
'root_url').
'/',
'', $this->
getWebDataPath()).
'/'.$existing[
'filename'];
867 $site_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($this->
id,
'site', FALSE);
868 foreach ($site_parents as $assetid => $type_code) {
869 $site = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
870 if (is_null($site))
continue;
871 $urls = $site->getSiteURLS();
873 foreach ($urls as $urlid => $data) {
875 $matching_roots = Array();
877 foreach ($root_urls as $tmp_url) {
878 if (substr($data[
'url'].
'/', 0, strlen($tmp_url) + 1) == $tmp_url.
'/') {
879 $matching_roots[] = $tmp_url;
883 if (empty($matching_roots))
continue;
885 foreach ($matching_roots as $root_url) {
886 if (isset($save_urls[$root_url])) {
887 if (empty($save_urls[$root_url][
'http'])) {
888 $save_urls[$root_url][
'http'] = $data[
'http'];
890 if (empty($save_urls[$root_url][
'https'])) {
891 $save_urls[$root_url][
'https'] = $data[
'https'];
894 $save_urls[$root_url] = Array(
'http' => $data[
'http'],
'https' => $data[
'https']);
904 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
906 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
909 foreach ($save_urls as $url => $url_data) {
912 'url' => $url.
'/'.$web_path,
913 'assetid' => $this->id,
914 'http' => ($this->force_secure ===
'1') ?
'0' : $url_data[
'http'],
915 'https' => ($this->force_secure ===
'-') ?
'0' : $url_data[
'https'],
919 }
catch (Exception $e) {
920 throw new Exception(
'Unable to insert lookups for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
930 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
931 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
948 if (in_array($_POST[
'asset_action'], Array(
'create',
'create_custom'))) {
949 $this->_tmp[
'uploading_file'] = 1;
951 switch ($_POST[
'asset_action']) {
953 $ei = $this->
getEI();
954 if (!$ei->process($this, $o, TRUE))
return FALSE;
956 return $this->
create($link);
960 return parent::processBackend($o, $link);
978 if (!$this->
id)
return TRUE;
981 if (trim($this->
attr(
'title')) ==
'') {
985 if (isset($this->_tmp[
'vars_set'][
'name'])) {
987 $uploading_file = !empty($this->_tmp[
'uploading_file']);
989 if (!$uploading_file) {
991 $old_filename = $this->_tmp[
'vars_set'][
'name'][
'old_value'];
992 $new_filename = $this->
attr(
'name');
995 if (!parent::saveAttributes($dont_run_updated)) {
999 if (is_file($this->data_path.
'/'.$old_filename)) {
1000 if (!$this->
_renameFile($this->data_path, $old_filename, $new_filename)) {
1001 parent::setAttrValue(
'name', $old_filename);
1002 parent::saveAttributes($dont_run_updated);
1008 if (is_file($this->data_path_public.
'/'.$old_filename)) {
1010 $this->_tmp[
'old_status'] = $this->status;
1011 unlink($this->data_path_public.
'/'.$old_filename);
1012 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
1013 $fv->checkOut($this->data_path_suffix.
'/'.$new_filename, $this->data_path_public);
1026 return parent::saveAttributes($dont_run_updated);
1041 protected function _renameFile($data_path, $old_filename, $new_filename)
1044 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
1048 if (!copy($data_path.
'/'.$old_filename, $data_path.
'/'.$new_filename)) {
1049 trigger_localised_error(
'CORE0026', E_USER_WARNING);
1055 $result = $fv->remove($data_path.
'/'.$old_filename,
'');
1056 if ($result != FUDGE_FV_OK && $result != FUDGE_FV_NOT_CHECKED_OUT) {
1057 trigger_localised_error(
'CORE0042', E_USER_WARNING);
1062 if (!$fv->add($this->data_path_suffix, $data_path.
'/'.$new_filename,
'')) {
1063 trigger_localised_error(
'CORE0026', E_USER_WARNING);
1068 if (!$fv->checkOut($this->data_path_suffix.
'/'.$new_filename, $data_path)) {
1069 trigger_localised_error(
'CORE0032', E_USER_WARNING);
1091 $uploading_file = (!empty($this->_tmp[
'uploading_file'])) ? TRUE : FALSE;
1092 $created_file = isset($this->_tmp[
'file_create_data'][
'created_file']) ? $this->_tmp[
'file_create_data'][
'created_file'] : FALSE;
1094 if ($name ==
'name' && !$uploading_file) {
1096 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
1097 $valid_names = make_valid_web_paths(Array($value));
1098 $value = array_shift($valid_names);
1100 if (is_file($this->data_path.
'/'.$this->attr(
'name'))) {
1101 $data_path = $this->data_path;
1103 $data_path = $this->data_path_public;
1106 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1108 $old_filename = $this->
attr(
'name');
1109 $old_ext = get_file_type($old_filename);
1110 $new_ext = get_file_type($value);
1111 if (trim($old_ext) !=
'' && $old_ext != $new_ext) {
1112 trigger_localised_error(
'CORE0115', E_USER_WARNING);
1113 $value = $old_filename;
1117 if (!is_file($data_path.
'/'.$old_filename) && !$created_file) {
1118 trigger_localised_error(
'CORE0023', E_USER_WARNING);
1119 $value = $old_filename;
1124 return parent::setAttrValue($name, $value);
1139 $pre_uploaded = FALSE;
1140 if (isset($info[
'non_uploaded_file']) && $info[
'non_uploaded_file']) {
1141 $pre_uploaded = TRUE;
1144 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1145 $ext = get_file_type($info[
'filename']);
1146 if (!empty($this->allowed_extensions) && !in_array($ext, $this->allowed_extensions)) {
1147 trigger_localised_error(
'CORE0106', E_USER_WARNING, make_readable_list($this->allowed_extensions, strtolower(translate(
'or'))), strtoupper($ext));
1149 unlink($info[
'path']);
1158 unlink($info[
'path']);
1177 $size = filesize($info[
'path']);
1179 $pre_uploaded = FALSE;
1180 if (isset($info[
'non_uploaded_file']) && $info[
'non_uploaded_file']) {
1181 $pre_uploaded = TRUE;
1184 if ($pre_uploaded) {
1185 $file_max_size = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_PREUPLOADED_MAX_SIZE');
1186 $error_code =
'CORE0262';
1188 $file_max_size = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_MAX_SIZE');
1189 $error_code =
'CORE0057';
1192 if (empty($file_max_size))
return TRUE;
1194 $max_size = strtolower($file_max_size);
1195 if (!$max_size)
return TRUE;
1197 if (substr($max_size, -1) ==
'k') {
1198 $max_size = $max_size * 1024;
1199 }
else if (substr($max_size, -1) ==
'm') {
1200 $max_size = $max_size * 1024 * 1024;
1202 if ($size > $max_size) {
1203 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1204 trigger_localised_error($error_code, E_USER_WARNING, strtoupper(easy_filesize($max_size)), strtoupper(easy_filesize($size)));
1225 $filename = $info[
'filename'];
1227 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1228 $extension = get_file_type($filename);
1232 if (php_sapi_name() ==
'cli')
return TRUE;
1235 $is_root = $GLOBALS[
'SQ_SYSTEM']->userRoot();
1236 $is_admin = ($is_root || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin());
1237 if ($is_root || $is_admin) {
1242 $extension = trim($extension);
1243 if (empty($extension)) {
1244 $allowed_no_extension = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_ALLOW_NO_EXTENSION');
1245 if ($allowed_no_extension)
return TRUE;
1246 trigger_localised_error(
'CORE0267', E_USER_WARNING);
1250 if ($pre_uploaded) {
1251 $allowed_extensions = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_ALLOWED_PREUPLOADED_TYPES');
1253 $allowed_extensions = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_ALLOWED_TYPES');
1256 if (!empty($allowed_extensions)) {
1257 $allowed_extensions_list = explode(
',', $allowed_extensions);
1258 if (!in_array($extension, $allowed_extensions_list)) {
1259 trigger_localised_error(
'CORE0266', E_USER_WARNING, $filename);
1264 if (isset($this->allowed_extensions) && !empty($this->allowed_extensions)) {
1265 if (!in_array($extension, $this->allowed_extensions)) {
1266 trigger_localised_error(
'CORE0266', E_USER_WARNING, $filename);
1291 if (SQ_IN_LIMBO && !(isset($_REQUEST[
'a']) && $_REQUEST[
'a'] == $this->
id)) {
1292 return parent::printFrontend();
1296 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
1302 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', FALSE);
1305 if (!empty($existing)) {
1306 require_once SQ_FUDGE_PATH.
'/standards_lists/mime_types.inc';
1307 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
1309 $ext = get_file_type($existing[
'filename']);
1310 if (($this->status & SQ_SC_STATUS_SAFE_EDITING) && ($GLOBALS[
'SQ_SYSTEM']->user instanceof
Public_User)) {
1312 $ext = preg_replace(
'/,ffv\d+$/',
'', $ext);
1313 $existing[
'filename'] = preg_replace(
'/,ffv\d+$/',
'', $existing[
'filename']);
1315 $type = (empty($standards_lists_mime_types[$ext])) ?
'text/plain' : $standards_lists_mime_types[$ext];
1318 $ssl_connection = FALSE;
1319 $url_info = parse_url(current_url());
1320 $protocol = (isset($url_info[
'scheme'])) ? $url_info[
'scheme'] : NULL;
1321 if (!is_null($protocol) && $protocol ==
'https') {
1322 $ssl_connection = TRUE;
1324 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
1325 $using_ie6_8 = isset ($_SERVER[
'HTTP_USER_AGENT']) ? preg_match(
'/(MSIE\s[0-8]+\.)/', $_SERVER[
'HTTP_USER_AGENT']) : FALSE;
1328 if (basename($_SERVER[
'PHP_SELF']) != SQ_CONF_NOCACHE_SUFFIX && SQ_CONF_SEND_CACHEABLE_HEADER && ($GLOBALS[
'SQ_SYSTEM']->user instanceof Public_User) && empty($_POST) && $cm->cacheableHeadersEnabledForCurrentProtocol() && $this->status >= SQ_STATUS_LIVE && $this->
readAccess()) {
1330 $browser_cache_expiry = $cm->getBrowserCacheExpiry($this->
type(), $this->
id);
1331 if (empty($browser_cache_expiry)) {
1332 $browser_cache_expiry = $cm->getExpiry($this->
type(), $this->
id);
1336 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + $browser_cache_expiry).
' GMT');
1337 header(
'Cache-Control: max-age='.$browser_cache_expiry.
', '.$cm->cacheControlLevel());
1338 header(
'Pragma: cache');
1339 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s',$existing[
'modified']).
' GMT');
1340 }
else if (!$using_ie6_8 || !$ssl_connection) {
1343 if (SQ_CONF_SEND_NO_CACHE_HEADER) {
1344 header(
'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
1346 header(
'Cache-Control: must-revalidate, post-check=0, pre-check=0');
1349 header(
'Pragma: no-cache');
1350 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time()-3600).
' GMT');
1356 header(
'Cache-Control: private, max-age=0, must-revalidate');
1357 header(
'Pragma: private');
1358 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time()-3600).
' GMT');
1361 header(
'Content-Type: '.$type);
1362 header(
'Content-Disposition: inline; filename="'.$existing[
'filename'].
'";');
1363 header(
'Content-Length: '.$existing[
'size']);
1366 readfile($existing[
'path']);
1383 public function getURL($base_url=NULL, $ignore_rollback=FALSE)
1385 if (SQ_ROLLBACK_VIEW) {
1386 if (is_null($base_url)) $base_url = current_url();
1387 $base_url = strip_url($base_url, FALSE);
1388 return $base_url.
'/?a='.$this->id;
1390 return parent::getURL($base_url, $ignore_rollback);
1406 public function getHref($base_url=NULL, $ignore_rollback=FALSE)
1408 if (SQ_ROLLBACK_VIEW) {
1409 return './?a='.$this->id;
1411 return parent::getHref($base_url, $ignore_rollback);
1425 $existing = Array();
1428 if (SQ_ROLLBACK_VIEW) {
1430 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
1431 $rep_file = $this->data_path_suffix.
'/'.$this->name;
1432 $then = iso8601_ts($_SESSION[
'sq_rollback_view'][
'rollback_time']);
1433 $info = $fv->_checkOutCheck($rep_file, NULL, $then);
1434 $path = $info[
'source_file'];
1435 $existing[
'filename'] = $info[
'filename'];
1436 }
else if (($this->status & SQ_SC_STATUS_SAFE_EDITING) && ($GLOBALS[
'SQ_SYSTEM']->user instanceof
Public_User)) {
1438 if (is_file($this->data_path.
'/sq_system_version_no')) {
1439 $file_version = file_to_string($this->data_path.
'/sq_system_version_no');
1440 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
1441 $rep_file = $this->data_path_suffix.
'/'.$this->name;
1442 $info = $fv->_checkOutCheck($rep_file, $file_version);
1443 $path = $info[
'source_file'];
1447 $path = $this->data_path.
'/'.$this->
attr(
'name');
1450 if (is_file($path)) {
1451 $existing[
'path'] = $path;
1452 $existing[
'modified'] = filemtime($existing[
'path']);
1453 $existing[
'size'] = filesize($existing[
'path']);
1455 if (isset($existing[
'filename']) ===
false) {
1456 $existing[
'filename'] = basename($existing[
'path']);
1475 public function _getName($short_name=FALSE, $contextid=NULL)
1478 if ($contextid === NULL) {
1479 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
1484 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'title', $this->
type(), Array($this->
id), $contextid);
1485 if (empty($values) === TRUE) {
1486 return $this->
attr(
'title');
1488 return $values[$this->id];
1492 return $this->
attr(
'name');
1513 $keywords = parent::getAvailableKeywords();
1515 $keywords[
'asset_file_size_in_bytes'] = translate(
'core_file_keyword_size_in_bytes');
1516 $keywords[
'asset_file_size_readable'] = translate(
'core_file_keyword_size_readable');
1517 $keywords[
'asset_file_contents'] = translate(
'core_file_keyword_file_contents');
1534 $size = (isset($existing[
'size'])) ? $existing[
'size'] : 0;
1549 $size = (isset($existing[
'size'])) ? $existing[
'size'] : 0;
1550 return easy_filesize($size);
1563 $file_contents = isset($existing[
'path']) ? file_get_contents($existing[
'path']) :
'';
1564 return $file_contents;
1578 public function delete($release_lock=TRUE)
1580 $this->_tmp[
'deleting_file'] = TRUE;
1581 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1582 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1584 if (!parent::delete($release_lock)) {
1585 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1586 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1590 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1591 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1592 $this->_tmp[
'deleting_file'] = FALSE;
1612 require_once SQ_FUDGE_PATH.
'/antivirus/antivirus.inc';
1615 $file_to_scan = $this->data_path.
'/'.$this->
attr(
'name');
1617 $file_to_scan = $path;
1639 if(isset($file_info[
'filename'])) {
1640 $ext = substr($file_info[
'filename'], strrpos($file_info[
'filename'],
'.') + 1);
1656 $summary = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'file',
'SQ_FILE_ASSET_SUMMARY');
1657 $keywords = retrieve_keywords_replacements($summary);
1659 $keyword_replacement = Array();
1660 foreach($keywords as $full_keyword) {
1662 $part_keyword = parse_keyword($full_keyword, $modifiers);
1664 if ($part_keyword != $full_keyword) {
1665 apply_keyword_modifiers($keyword_value, $modifiers, Array(
'assetid' => $this->
id));
1668 $keyword_replacement[$full_keyword] = $keyword_value;
1671 replace_keywords($summary, $keyword_replacement);
1690 $original_url = Array();
1694 if(strpos($data_url,
'__data') === FALSE)
return $data_url;
1697 if(empty($site_url))
return $data_url;
1699 $site_parts = explode(
'://', $site_url);
1700 $site = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL($site_parts[0], $site_parts[1]);
1702 $site_treeid = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids($site->id);
1705 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($this->
id,
'', TRUE, NULL, NULL, TRUE, 1, 1);
1707 $url_found = Array();
1708 foreach($parents as $parentid => $type_code) {
1709 if($site->id != $parentid){
1710 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parentid);
1712 $parent_asset = $site;
1714 $parent_urls = $parent_asset->getURLs();
1715 foreach ($parent_urls as $index => $parent_url) {
1716 if(strpos($parent_url[
'url'], $site_parts[1]) !== FALSE || $parent_url[
'url'] == $site_url) {
1717 $url_found = $parent_url;
1723 if(!empty($url_found)) {
1724 $construct_url = ($url_found[
'https'] ==
'1') ?
'https://' :
'http://';
1725 foreach ($web_paths as $webpath) {
1726 $original_url[] = $construct_url.$url_found[
'url'].
'/'.$webpath;
1730 return $original_url;