Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
xml_file_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/files/file/file_edit_fns.inc';
19 
29 {
30 
31 
36  function __construct()
37  {
38  parent::__construct();
39 
40  }//end constructor
41 
42 
53  function paintEditFile($asset, Backend_Outputter $o, $prefix)
54  {
55  if (SQ_ROLLBACK_VIEW) {
56  // get an older version of the parse file
57  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
58  $rep_file = $asset->data_path_suffix.'/'.$asset->name;
59  $then = iso8601_ts($_SESSION['sq_rollback_view']['rollback_time']);
60  $info = @$fv->_checkOutCheck($rep_file, NULL, $then);
61  $parse_file = $info['source_file'];
62  ob_start();
63  $success = $fv->output($rep_file, NULL, $then);
64  $str = ob_get_clean();
65  if (!$success) return FALSE;
66  } else {
67  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
68  $parse_file = $asset->data_path.'/'.$asset->name;
69  $str = file_to_string($parse_file);
70  }
71 
72  if ($asset->writeAccess('attributes')) {
73  text_area($prefix.'_new_file', $str, 0, 0, 0, 'style="font-family: \'Courier New\', Courier, monospace; white-space: pre-wrap; width: 99%; height: 480px"');
74  return TRUE;
75  } else {
76  echo '<pre>', htmlspecialchars($str), '</pre>';
77  }
78  return FALSE;
79 
80  }//end paintEditFile()
81 
82 
93  function processEditFile($asset, Backend_Outputter $o, $prefix)
94  {
95  if (!$asset->writeAccess('attributes')) return FALSE;
96  if (isset($_POST[$prefix.'_new_file'])) {
97 
98  // make them unix format ;)
99  $str = str_replace("\r\n", "\n", $_POST[$prefix.'_new_file']);
100 
101  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
102 
103  // it's easier if we just use the processFileUpload() (future proof's this a little bit)
104  // so create a temporary file that will be moved to the proper file
105  $file_info = Array(
106  'name' => $asset->name,
107  'tmp_name' => $asset->data_path.'/'.$asset->name.'.new',
108  'non_uploaded_file' => TRUE,
109  );
110 
111  if (!string_to_file($str, $file_info['tmp_name'])) {
112  return FALSE;
113  }
114 
115  $ret_val = $this->processFileUpload($asset, $o, $prefix, $file_info);
116  unlink($file_info['tmp_name']);
117  return $ret_val;
118 
119  }//end if
120 
121  return FALSE;
122 
123  }//end processEditFile()
124 
125 
136  function paintTransformations($asset, Backend_Outputter $o, $prefix)
137  {
138  $xsl = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'xsl_file', TRUE, 'transform');
139  $assetid = array_get_index($xsl, 'minorid', 0);
140  if (!class_exists('XSLTProcessor')) {
141  trigger_localised_error('XSL0001', E_USER_WARNING);
142  } else {
143  if ($asset->writeAccess('links')) {
144  echo asset_finder($prefix.'_transform_xsl', $assetid, Array('xsl_file'=>'I'));
145  } else {
146  if (empty($assetid)) {
147  echo 'No XSL file selected';
148  } else {
149  $xsl_file = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
150  if (!is_null($xsl_file)) {
151  echo $this->printExistingFileInfo($xsl_file);
152  } else {
153  echo 'No XSL File selected';
154  }//end if
155  }//end if
156  }//end if
157  }//end if
158  return TRUE;
159 
160  }//end paintTransformations()
161 
162 
173  function processTransformations($asset, Backend_Outputter $o, $prefix)
174  {
175  $status = FALSE;
176  $minor = NULL;
177  if (!$asset->writeAccess('links')) return $status;
178 
179  $current = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'xsl_file', TRUE, 'transform');
180  $selected = array_get_index($_POST, $prefix.'_transform_xsl', Array());
181  $xsl_assetid = array_get_index($selected, 'assetid', 0);
182 
183  // Load the asset up
184  if (!empty($xsl_assetid)) {
185  $minor = $GLOBALS['SQ_SYSTEM']->am->getAsset($xsl_assetid);
186  if (is_null($minor) || $minor->type() != 'xsl_file') {
187  // Invalid asset type, return
188  return $status;
189  }//end if
190  }//end if
191 
192  if (!empty($current)) {
193  $current_id = array_get_index($current, 'minorid', 0);
194  $current_linkid = array_get_index($current, 'linkid', 0);
195  if ($current_id != $xsl_assetid) {
196  // Different from already created one, so delete and recreate
197  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_linkid);
198  if (!is_null($minor)) {
199  $status = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $minor, SQ_LINK_NOTICE, 'transform');
200  }//end if
201  }//end if
202  } else {
203  // None created so just create
204  if (!is_null($minor)) {
205  $status = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $minor, SQ_LINK_NOTICE, 'transform');
206  }//end if
207  }//end if
208 
209  return $status;
210 
211  }//end processTransformations()
212 
213 
214 }//end class
215 ?>