18 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
54 public static function execute($settings, &$state)
57 if (empty($settings[
'file_path']) || !file_exists($settings[
'file_path'])) {
63 if (empty($state[
'asset'])) {
65 if (empty($state[
'assetid'])) {
68 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
72 if (is_null($state[
'asset']))
return FALSE;
74 $asset = $state[
'asset'];
75 $edit_fns = $asset->getEditFns();
77 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
82 if (preg_match(
'/\\.tar\\.gz$/', $settings[
'file_path'])
83 || preg_match(
'/\\.tgz$/', $settings[
'file_path'])
84 || preg_match(
'/\\.tar$/', $settings[
'file_path']) ) {
86 require_once
'Archive/Tar.php';
87 $tar_ball =
new Archive_Tar($settings[
'file_path']);
88 if (($contents = $tar_ball->listContent()) != 0) {
92 $extract_list = Array();
93 foreach ($contents as $entry) {
94 if ($entry[
'typeflag'] !=
'0' && $entry[
'typeflag'] !=
'') {
98 $k = dirname($entry[
'filename']);
99 if (!isset($extract_list[$k])) {
100 $extract_list[$k] = Array();
102 $extract_list[$k][] = $entry[
'filename'];
106 foreach ($extract_list as $remove_path => $files) {
108 $files_dir = $asset->data_path.
'/.temp_files';
109 if (!create_directory($files_dir))
return FALSE;
110 if (!clear_directory($files_dir))
return FALSE;
112 $result = $tar_ball->extractList($files, $files_dir, $remove_path);
114 trigger_error(
'Failed to extract tar archive', E_USER_WARNING);
117 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
118 $design_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'',
'sort_order' => 1,
'is_dependant' => 1);
120 foreach ($files as $filename) {
121 $filename = preg_replace(
'|^'.$remove_path.
'/|',
'', $filename);
122 $temp_path = $files_dir.
'/'.$filename;
123 $temp_info = Array(
'name' => $filename,
'tmp_name' => $temp_path);
124 $temp_info[
'non_uploaded_file'] = TRUE;
125 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
126 if ($edit_fns->_processUploadedFile($asset, $temp_info)) {
129 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
132 delete_directory($files_dir);
140 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
141 if ($edit_fns->_processUploadedFile($asset, $info)) {
144 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
149 'assetid' => $state[
'asset']->
id,
165 public static function getInterface($settings, $prefix, $write_access=FALSE)
167 $file_path = array_get_index($settings,
'file_path',
'');
172 <td valign=
"top"><b><?php echo
'Path to the parse file'; ?></b></td>
173 <td valign=
"top" style=
"padding-bottom: 10px;"><?php
176 echo text_box($prefix.
'[file_path]', $file_path,
'50');
178 echo $file_path.
' ';
186 return ob_get_clean();
204 $file_path = array_get_index($request_data,
'file_path',
'');
205 $file_path = trim($file_path);
206 if ($file_path ==
'') {
207 return 'file path is not specified.';
209 $settings[
'file_path'] = $file_path;
225 public static function getLocks($settings, &$state)
228 $state[
'assetid'] => Array(