17 require_once SQ_FUDGE_PATH.
'/wysiwyg/wysiwyg.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/designs/design_area/design_area_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
42 parent::__construct();
43 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
61 file_upload($prefix.
'_parse_file');
83 $upload_info = get_file_upload_info($prefix.
'_parse_file');
84 if (empty($upload_info))
return FALSE;
86 $parse_file = $asset->data_path.
'/parse.txt';
90 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
92 $info = get_file_upload_info($prefix.
'_parse_file');
93 if(!isset($info[
'tmp_name'])) {
94 trigger_error(
'Design parse file is not found', E_USER_WARNING);
97 $parse_file_content = file_get_contents($info[
'tmp_name']);
98 if(empty($parse_file_content)) {
99 trigger_error(
'Empty design parse file is not allowed', E_USER_WARNING);
104 if (is_file($parse_file)) {
106 if (!unlink($parse_file)) {
107 trigger_localised_error(
'CORE0164', E_USER_WARNING);
113 if (commit_file_upload($prefix.
'_parse_file', $parse_file, TRUE)) {
115 $asset->_tmp[
'update_customisations'] = TRUE;
116 $asset->_tmp[
'generate_design'] = TRUE;
121 $file_status = $fv->upToDate($parse_file);
122 if (FUDGE_FV_MODIFIED & $file_status) {
123 if (!$fv->commit($parse_file,
'')) {
124 trigger_localised_error(
'CORE0160', E_USER_WARNING);
129 if (!$fv->add($asset->data_path_suffix, $parse_file,
'')) {
130 trigger_localised_error(
'CORE1057', E_USER_WARNING);
136 if (!$fv->checkOut($asset->data_path_suffix.
'/parse.txt', $asset->data_path)) {
137 trigger_localised_error(
'CORE0158', E_USER_WARNING);
159 $parse_file = $asset->data_path.
'/parse.txt';
160 if (!is_file($parse_file)) {
161 echo translate(
'core_no_existing_parsefile');
163 check_box($prefix.
'_reparse');
164 label(translate(
'core_manually_reparse'), $prefix.
'_reparse');
185 if (isset($_POST[$prefix.
'_reparse'])) {
187 $asset->_tmp[
'update_customisations'] = TRUE;
188 $asset->_tmp[
'generate_design'] = TRUE;
209 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
211 if (SQ_ROLLBACK_VIEW) {
213 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
214 $rep_file = $asset->data_path_suffix.
'/parse.txt';
215 $then = iso8601_ts($_SESSION[
'sq_rollback_view'][
'rollback_time']);
216 $info = @$fv->_checkOutCheck($rep_file, NULL, $then);
217 $parse_file = $info[
'source_file'];
219 $parse_file = $asset->data_path.
'/parse.txt';
221 if (!is_file($parse_file)) {
222 echo translate(
'core_require_upload_parsefile');
226 $str = file_to_string($parse_file);
229 text_area($prefix.
'_new_parse_file', str_replace(
"\t",
' ', $str), 0, 0, 0,
'style="font-family: \'Courier New\', Courier, monospace; white-space: pre-wrap; width: 99%; height: 480px"');
233 $str = htmlspecialchars($str);
237 $my_style =
'style="color:#FF0517;font-weight:bold;"';
238 $mysrc_search = Array(
239 '/<MySource_(.*?(>))/ims',
240 '/<\/MySource_(.*?(>))/ims',
242 $mysrc_replace = Array(
243 '<span '.$my_style.
'><MySource_${1}</span>',
244 '<span '.$my_style.
'></MySource_${1}</span>',
246 $str = preg_replace($mysrc_search, $mysrc_replace, $str);
249 function wrap_css($matches)
251 $css_style =
'style="color:#6A287E;font-style:italic;"';
253 $return_string .=
'<span '.$css_style.
'><style'.$matches[1];
254 $white_space = Array(
"\r\n",
"\n",
"\r");
255 $return_string .= str_replace($white_space,
"</span>\n<span ".$css_style.
'>', $matches[3]);
256 $return_string .=
'</span>';
257 return $return_string;
260 '/<style(.*?(>))(.*?(<\/style>))/ims',
262 $str = preg_replace_callback($css_search,
"wrap_css", $str);
265 $html_style =
'style="color:#0000A0;"';
266 $html_keywords =
'!DOCTYPE|a|html|head|title|meta|link|body|script|div|span|h1|h2|h3|h4|h5|h6|ul|li|ol|table|tr|td|th|p|br|strong|pre';
267 $html_search = Array(
268 '/<('.$html_keywords.
')>/i',
269 '/<('.$html_keywords.
')(.*?(\/>))/ims',
270 '/<('.$html_keywords.
')(.*?(>))/ims',
271 '/<\/('.$html_keywords.
')>/ims',
273 $html_replace = Array(
274 '<span '.$html_style.
'><${1}></span>',
275 '<span '.$html_style.
'><${1}${2}</span>',
276 '<span '.$html_style.
'><${1}${2}</span>',
277 '<span '.$html_style.
'></${1}></span>',
279 $str = preg_replace($html_search, $html_replace, $str);
282 function wrap_comment($matches)
284 $cmmt_style =
'style="color:#347C17;"';
286 $return_string .=
'<span '.$cmmt_style.
'><!-- ';
287 $white_space = Array(
"\r\n",
"\n",
"\r");
288 $return_string .= str_replace($white_space,
"</span>\n<span ".$cmmt_style.
'>', $matches[1]);
289 $return_string .=
'</span>';
290 return $return_string;
292 $cmmt_search = Array(
293 '/<!--(.*?(-->))/ims',
295 $str = preg_replace_callback($cmmt_search,
"wrap_comment", $str);
298 $pre_style =
'style="size:10px;font-family:helvetica,verdana,sans-serif;"';
299 $line_style =
'style="color:black;list-style-type:decimal;border-left: thin solid #000000;"';
300 $lines = explode(
"\n", $str);
301 $number_of_lines = count($lines);
302 $padding = strlen($number_of_lines);
303 foreach ($lines as $line_number => $line) {
305 $lines[$line_number] =
'<li '.$line_style.
' value="'.($line_number+1).
'"> '.$line.
'</li>';
307 $formatted = implode(
'', $lines);
308 echo
'<pre ', $pre_style,
'><ol>', $formatted,
'</ol></pre>';
327 if (isset($_POST[$prefix.
'_new_parse_file'])) {
329 $parse_file = $asset->data_path.
'/parse.txt';
330 $new_file = $_POST[$prefix.
'_new_parse_file'];
332 if (!is_file($parse_file))
return FALSE;
334 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
336 if(empty($new_file)) {
337 trigger_error(
'Empty design parse file is not allowed', E_USER_WARNING);
342 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
343 if (string_to_file($new_file, $parse_file)) {
345 $asset->_tmp[
'update_customisations'] = TRUE;
346 $asset->_tmp[
'generate_design'] = TRUE;
350 $file_status = $fv->upToDate($parse_file);
351 if (FUDGE_FV_MODIFIED & $file_status) {
352 if (!$fv->commit($parse_file,
'')) {
353 trigger_localised_error(
'CORE0160', E_USER_WARNING);
360 trigger_localised_error(
'CORE0167', E_USER_WARNING);
364 if (!$fv->checkOut($asset->data_path_suffix.
'/parse.txt', $asset->data_path)) {
365 trigger_localised_error(
'CORE0158', E_USER_WARNING);
392 for ($i = 0; $i < 2; $i++) {
393 file_upload($prefix.
'_assoc_file_'.$i);
412 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
416 for ($i = 0; $i < 2; $i++) {
417 $info = get_file_upload_info($prefix.
'_assoc_file_'.$i);
418 if (empty($info))
continue;
421 if (preg_match(
'/\\.tar\\.gz$/', $info[
'name'])
422 || preg_match(
'/\\.tgz$/', $info[
'name'])
423 || preg_match(
'/\\.tar$/', $info[
'name']) ) {
425 require_once
'Archive/Tar.php';
426 $tar_ball =
new Archive_Tar($info[
'tmp_name']);
427 if (($contents = $tar_ball->listContent()) != 0) {
431 $extract_list = Array();
432 foreach ($contents as $entry) {
433 if ($entry[
'typeflag'] !=
'0' && $entry[
'typeflag'] !=
'') {
437 $k = dirname($entry[
'filename']);
438 if (!isset($extract_list[$k])) {
439 $extract_list[$k] = Array();
441 $extract_list[$k][] = $entry[
'filename'];
445 foreach ($extract_list as $remove_path => $files) {
447 $files_dir = $asset->data_path.
'/.temp_files';
448 if (!create_directory($files_dir))
return FALSE;
449 if (!clear_directory($files_dir))
return FALSE;
451 $result = $tar_ball->extractList($files, $files_dir, $remove_path);
453 trigger_error(
'Failed to extract tar archive', E_USER_WARNING);
456 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
457 $design_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'',
'sort_order' => 1,
'is_dependant' => 1);
459 foreach ($files as $filename) {
460 $filename = preg_replace(
'|^'.$remove_path.
'/|',
'', $filename);
461 $temp_path = $files_dir.
'/'.$filename;
462 $temp_info = Array(
'name' => $filename,
'tmp_name' => $temp_path);
463 $temp_info[
'non_uploaded_file'] = TRUE;
470 delete_directory($files_dir);
503 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
505 $existing_ids = Array();
506 $existing = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'file', FALSE);
508 foreach ($existing as $link) {
509 $existing_ids[$link[
'minorid']] = $link[
'linkid'];
512 $existing_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($existing_ids));
516 $new_file_name = make_valid_web_paths(Array($info[
'name']));
517 $new_file_name = array_shift($new_file_name);
519 $existing_fileid = 0;
520 foreach ($existing_info as $asset_id => $asset_info) {
522 if ($asset_info[
'name'] == $new_file_name) {
523 $existing_fileid = $asset_id;
528 if (!$existing_fileid) {
531 switch (get_file_type($info[
'name'])) {
533 $new_asset_type =
'text_file';
539 $new_asset_type =
'image';
542 $new_asset_type =
'file';
546 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($new_asset_type);
547 $new_file =
new $new_asset_type();
548 $new_file->_tmp[
'uploading_file'] = TRUE;
549 $new_file->setAttrValue(
'name', $info[
'name']);
550 $design_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'',
'sort_order' => 1,
'is_dependant' => 1);
552 return $new_file->create($design_link, $info);
557 $new_file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($existing_fileid);
559 $lock_status = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($new_file->id,
'attributes');
560 $edit_fns = $new_file->getEditFns();
562 $success = $edit_fns->processFileUpload($new_file, $o, $new_file->getPrefix(), $info);
564 if ($lock_status === 1) {
565 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($new_file->id,
'attributes');
587 $type_name = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($asset->
type(),
'name');
588 echo translate(
'core_design_must_acquire_locks_new_customisation', strtolower($type_name));
592 check_box($prefix.
'_new_customisation');
593 text_box($prefix.
'_new_customisation_name', $asset->name.
' - Customisation', 40);
611 if (empty($_POST[$prefix.
'_new_customisation']) || !($new_name = trim($_POST[$prefix.
'_new_customisation_name']))) {
615 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
616 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
621 $create_link = Array();
624 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->getRunLevel() & SQ_RUN_LEVEL_FORCED);
626 $asset->_tmp[
'custom'] = TRUE;
627 $clone = $GLOBALS[
'SQ_SYSTEM']->am->cloneAsset($asset, $create_link, $map, Array(
'attributes',
'permissions',
'roles'), FALSE);
628 unset ($asset->_tmp[
'custom']);
629 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
632 if (is_null($clone)) {
633 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
634 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
639 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($clone->id,
'all')) {
640 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
641 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
646 if (!$cloned = $clone->morph(
'design_customisation')) {
647 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
648 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
653 if (!$asset->
createLink($cloned, SQ_LINK_TYPE_2,
'customisation', NULL,
'1',
'1')) {
654 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
655 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
658 if (!($cloned->setAttrValue(
'id_name', $new_name) && $cloned->saveAttributes())) {
659 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
660 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
664 $am = $GLOBALS[
'SQ_SYSTEM']->am;
668 foreach ($da_links as $link) {
669 $da = $am->getAsset($link[
'minorid'], $link[
'minor_type_code'], TRUE);
670 if (is_null($da))
continue;
671 if (!$cloned->createLink($da, SQ_LINK_TYPE_3, $link[
'value'], NULL,
'1')) {
672 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
673 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
679 $initial_path = strtolower($new_name);
680 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
681 $valid_paths = make_valid_web_paths(Array($initial_path));
682 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($asset, $valid_paths, $cloned->id, TRUE);
683 if (!$cloned->saveWebPaths($good_paths)) {
684 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
685 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
690 $file_link_ids = Array();
691 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'file', FALSE);
692 foreach ($file_links as $link) {
693 $minor = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
694 if (!$cloned->createLink($minor, SQ_LINK_TYPE_3,
'', NULL, 1)) {
695 trigger_localised_error(
'CORE0162', E_USER_WARNING);
696 $am->forgetAsset($minor);
697 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
698 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
702 $am->forgetAsset($minor);
705 $css_link_ids = Array();
706 $css_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'design_css', FALSE);
707 foreach ($css_links as $link) {
708 $minor = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
709 if (!$cloned->createLink($minor, SQ_LINK_TYPE_3,
'', NULL, 1)) {
710 trigger_localised_error(
'CORE0161', E_USER_WARNING);
711 $am->forgetAsset($minor);
712 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
713 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
717 $am->forgetAsset($minor);
720 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($cloned->id,
'all')) {
721 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
722 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
726 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
727 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
746 $customisation_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'design_customisation', TRUE,
'major',
'customisation');
747 if ($customisation_links) {
748 $am = $GLOBALS[
'SQ_SYSTEM']->am;
749 foreach ($customisation_links as $link) {
750 echo get_asset_tag_line($link[
'minorid'],
'details').
'<br/>';
754 echo translate(
'core_design_no_customisations_created');
770 $parse_file = $asset->data_path.
'/parse.txt';
771 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
772 $str = file_to_string($parse_file);
792 $file_contents = preg_replace( Array(
'/<head/i',
'/<\\/head/i',
'/<body/i',
'/<\\/body/i'),
793 Array(
'<head',
'</head',
'<body',
'</body'),
800 if(strpos($file_contents,
'</head>') !== FALSE) {
801 $file_contents = str_replace(
'</head>',
"\n<".$this->tag_name.
"_PRINT id_name='__global__' var='html_header' />\n</head>", $file_contents);
807 if(strpos($file_contents,
'</body>') !== FALSE) {
808 $file_contents = str_replace(
'</body>',
"\n<".$this->tag_name.
"_PRINT id_name='__global__' var='html_footer' />\n</body>", $file_contents);
812 return parent::_parseString($file_contents);
830 foreach ($contents as $index => $element) {
831 if ($element[
'_type'] !=
'TAG' || $element[
'operation'] !=
'area') {
836 if (empty($element[
'attributes'][
'id_name']) || empty($element[
'attributes'][
'design_area'])) {
837 trigger_localised_error(
'CORE0143', E_USER_WARNING);
842 if (!preg_match(
'/^[a-z][a-z0-9_]*$/i', $element[
'attributes'][
'id_name']) || $element[
'attributes'][
'id_name'] != preg_replace(
'/__+/',
'', $element[
'attributes'][
'id_name'])) {
843 trigger_localised_error(
'CORE0181', E_USER_WARNING, $element[
'attributes'][
'id_name']);
847 $element[
'attributes'][
'design_area'] =
'design_area_'.strtolower($element[
'attributes'][
'design_area']);
850 if (isset($id_names[$element[
'attributes'][
'id_name']])) {
851 trigger_localised_error(
'CORE0142', E_USER_WARNING, $element[
'attributes'][
'id_name']);
855 $id_names[$element[
'attributes'][
'id_name']] = $element[
'attributes'][
'design_area'];
859 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
860 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
862 if (isset($GLOBALS[
'SQ_PROCESSED_DESIGN_AREAS'])) {
865 $existing_id_names = Array();
866 foreach ($existing_da_links as $link) {
867 $existing_id_names[$link[
'value']] = $link[
'linkid'];
870 $removed_id_names = array_diff(array_keys($existing_id_names), array_keys($GLOBALS[
'SQ_PROCESSED_DESIGN_AREAS']));
873 foreach ($removed_id_names as $id_name) {
874 if (!$asset->
deleteLink($existing_id_names[$id_name])) {
875 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
876 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
881 $GLOBALS[
'SQ_PROCESSED_DESIGN_AREAS'] = Array();
886 $design_areas = Array();
890 foreach ($id_names as $id_name => $design_area) {
895 if (!is_null($da) && $da->type() !== $design_area) {
898 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
899 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
908 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($design_area);
909 $da =
new $design_area();
910 $da_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_3,
'value' => $id_name,
'is_dependant' =>
'1');
911 $da->setAttrValue(
'id_name', $id_name);
912 if (!$da->create($da_link)) {
913 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
914 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
917 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($da->id,
'parsing')) {
918 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
919 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
924 $design_areas[$id_name] = $da;
930 foreach ($contents as $index => $element) {
931 if ($element[
'_type'] !=
'TAG' || $element[
'operation'] !=
'area') {
935 $edit_fns = $design_areas[$element[
'attributes'][
'id_name']]->getEditFns();
936 if (!$edit_fns->_processContents($design_areas[$element[
'attributes'][
'id_name']], $element[
'contents'])) {
937 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
938 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
942 $print = !in_array(array_get_index($element[
'attributes'],
'print',
'yes'), Array(
'no',
'false',
'0'));
943 $design_areas[$element[
'attributes'][
'id_name']]->setAttrValue(
'print', $print);
944 $cache = in_array(array_get_index($element[
'attributes'],
'cache', FALSE), Array(
'yes',
'true',
'1'));
945 $design_areas[$element[
'attributes'][
'id_name']]->setAttrValue(
'cache', $cache);
947 if (!$design_areas[$element[
'attributes'][
'id_name']]->saveAttributes()) {
948 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
949 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
957 $lockInfo = $GLOBALS[
'SQ_SYSTEM']->am->getLockInfo($design_areas[$element[
'attributes'][
'id_name']]->
id,
'parsing');
958 if (!empty($lockInfo[
'links']) && $lockInfo[
'links'][
'userid'] ==
'0') {
959 @$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($design_areas[$element[
'attributes'][
'id_name']]->
id,
'parsing');
967 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
968 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
971 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
972 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
992 $o->
openField(translate(
'core_design_import_file'));
994 file_upload($prefix.
'_import_file');
996 $o->
note(translate(
'core_design_import_note'));
998 $o->
openField(translate(
'core_design_existing_asset'));
1000 asset_finder($prefix.
'_import_asset', 0, Array(
'file' =>
'I'));
1002 $o->
note(translate(
'core_design_existing_asset_note'));
1022 $tar_upload = get_file_upload_info($prefix.
'_import_file');
1023 if ($tar_upload === FALSE) {
1024 trigger_error(translate(
'core_design_import_upload_error'), E_USER_WARNING);
1026 if (!empty($tar_upload)) {
1027 $import_dir = $asset->data_path.
'/temp/';
1028 if (!is_dir($import_dir)) {
1029 create_directory($import_dir);
1031 commit_file_upload($prefix.
'_import_file', $import_dir, TRUE, 0, TRUE, Array(
'gz',
'tar',
'tgz'));
1033 $filename = $tar_upload[
'name'];
1034 $import_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'export_file');
1035 $temp_info = Array(
'name' => $filename,
'tmp_name' => $import_dir.
'/'.$filename,
'non_uploaded_file' => TRUE);
1037 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
1038 $new_file =
new File();
1039 $new_file->_tmp[
'uploading_file'] = TRUE;
1040 $new_file->setAttrValue(
'name', $filename);
1042 if (!$new_file->create($import_link, $temp_info)) {
1043 trigger_error(
'Failed to import File '.$filename, E_USER_WARNING);
1045 delete_directory($import_dir);
1049 $selected_asset = $_POST[$prefix.
'_import_asset'][
'assetid'];
1050 if ($selected_asset !=
'0') {
1051 $file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($selected_asset);
1052 $asset->
createLink($file, SQ_LINK_TYPE_1,
'export_file');
1072 $o->
sectionNote(translate(
'core_design_export_warning'));
1074 $o->
openField(translate(
'core_design_export_filename'));
1075 if ($write_access) {
1076 text_box($prefix.
'_export_filename',
'');
1078 $o->
note(translate(
'core_design_export_note'));
1100 if ($write_access) {
1101 if ($_POST[$prefix.
'_export_filename'] !=
'') {
1102 $new_file_name = $_POST[$prefix.
'_export_filename'];
1103 if (strpos($new_file_name,
'.tar.gz') === FALSE) {
1104 $new_file_name .=
'.tar.gz';
1107 $files_dir = $asset->data_path.
'/.temp_files';
1108 if (!create_directory($files_dir))
return FALSE;
1109 if (!clear_directory($files_dir))
return FALSE;
1112 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'file', FALSE);
1114 $files_to_copy = Array();
1115 foreach ($links as $link_data) {
1116 if ($link_data[
'value'] ==
'export_file')
continue;
1117 $child_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_data[
'minorid']);
1118 $current_file_info = $child_asset->getExistingFile();
1119 $files_to_copy[$current_file_info[
'filename']] = $current_file_info[
'path'];
1121 $archive_files = Array();
1122 foreach ($files_to_copy as $filename => $path) {
1123 copy($path, $files_dir.
'/'.$filename);
1124 $archive_files[] = $files_dir.
'/'.$filename;
1127 require_once
'Archive/Tar.php';
1129 $tar_object =
new Archive_Tar($files_dir.
'/associated_files.tar.gz', TRUE);
1130 $tar_object->createModify($archive_files,
'', $files_dir);
1132 foreach ($archive_files as $remove) {
1136 $archive_files = Array();
1139 if (!file_exists($asset->data_path.
'/parse.txt')) {
1140 trigger_error(
'No Parse File to Export', E_USER_WARNING);
1144 copy($asset->data_path.
'/parse.txt', $files_dir.
'/parse.html');
1146 $archive_files[] = $files_dir.
'/parse.html';
1147 $archive_files[] = $files_dir.
'/associated_files.tar.gz';
1149 $tar_object =
new Archive_Tar($files_dir.
'/'.$new_file_name, TRUE);
1150 $tar_object->createModify($archive_files,
'', $files_dir);
1152 $temp_path = $files_dir.
'/'.$new_file_name;
1153 $temp_info = Array(
'name' => $new_file_name,
'tmp_name' => $temp_path);
1154 $temp_info[
'non_uploaded_file'] = TRUE;
1156 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'file');
1158 $new_file =
new File();
1159 $new_file->_tmp[
'uploading_file'] = TRUE;
1160 $new_file->setAttrValue(
'name', $new_file_name);
1161 $design_link = Array(
'asset' => &$asset,
'link_type' => SQ_LINK_TYPE_2,
'value' =>
'export_file',
'sort_order' => 1,
'is_dependant' => 1);
1163 $new_file->create($design_link, $temp_info);
1165 delete_directory($files_dir);
1169 return $write_access;
1186 $o->
sectionNote(translate(
'core_design_apply_warning'));
1189 <table
class=
"sq-backend-table" style=
"width: 350px;">
1191 <td
class=
"sq-backend-table-header" style=
"width: 200px;"><?php echo translate(
'core_design_export_file_name'); ?></td>
1193 if ($write_access) {
1195 <td
class=
"sq-backend-table-header" style=
"width: 75px;"><?php echo translate(
'download'); ?></td>
1196 <td
class=
"sq-backend-table-header" style=
"width: 75px;"><?php echo translate(
'apply'); ?></td>
1202 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'file', TRUE,
'major',
'export_file');
1203 $file_ids = Array();
1204 foreach ($file_links as $data) {
1205 $file_ids[] = $data[
'minorid'];
1207 $file_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($file_ids);
1208 foreach ($file_info as $id => $data) {
1209 $file_name = $data[
'name'];
1212 <td><?php echo $file_name; ?></td>
1214 if ($write_access) {
1216 <td><a href=
"./?a=<?php echo $id; ?>"><?php echo translate(
'download'); ?></a></td>
1218 <?php radio_button($prefix.
'_apply', $id);?>
1228 if ($write_access) {
1230 <tr><td colspan=
"2"><?php echo translate(
'core_design_export_no_change'); ?></td><td><?php radio_button($prefix.
'_apply',
'', TRUE);?></td></tr>
1254 if (!$write_access)
return FALSE;
1256 $file_to_apply = $_POST[$prefix.
'_apply'];
1257 if ($file_to_apply ==
'')
return TRUE;
1258 $file = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($file_to_apply);
1259 $file_info = $file->getExistingFile();
1261 require_once
'Archive/Tar.php';
1262 $tar_ball =
new Archive_Tar($file_info[
'path']);
1264 if (($contents = $tar_ball->listContent()) != 0) {
1266 $extract_list = Array();
1267 foreach ($contents as $data) {
1268 $extract_list[] = $data[
'filename'];
1271 $valid_parse_names = Array(
1279 $parse_file_found = FALSE;
1281 foreach ($valid_parse_names as $name) {
1282 if (in_array($name, $extract_list)) {
1283 $parse_file = $name;
1284 $parse_file_found = TRUE;
1289 if (!$parse_file_found) {
1290 trigger_error(translate(
'core_design_export_no_parsefile'), E_USER_WARNING);
1294 $files_dir = $asset->data_path.
'/.temp_files';
1295 if (!create_directory($files_dir))
return FALSE;
1296 if (!clear_directory($files_dir))
return FALSE;
1298 $result = $tar_ball->extractList($extract_list, $files_dir);
1301 $current_parse_file = $asset->data_path.
'/parse.txt';
1303 $new_version = FALSE;
1305 $fv = $GLOBALS[
'SQ_SYSTEM']->getFileVersioning();
1308 if (is_file($current_parse_file)) {
1309 $new_version = TRUE;
1310 if (!unlink($current_parse_file)) {
1311 trigger_localised_error(
'CORE0164', E_USER_WARNING);
1316 if (copy($files_dir.
'/'.$parse_file, $current_parse_file)) {
1318 $asset->_tmp[
'update_customisations'] = TRUE;
1319 $asset->_tmp[
'generate_design'] = TRUE;
1324 $file_status = $fv->upToDate($parse_file);
1325 if (FUDGE_FV_MODIFIED & $file_status) {
1326 if (!$fv->commit($current_parse_file,
'')) {
1327 trigger_localised_error(
'CORE0160', E_USER_WARNING);
1332 if (!$fv->add($asset->data_path_suffix, $current_parse_file,
'')) {
1333 trigger_localised_error(
'CORE1057', E_USER_WARNING);
1338 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'');
1339 $trash_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'trash_folder');
1340 foreach ($links as $data) {
1341 if ($data[
'value'] !=
'export_file') {
1343 $trashed = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($data[
'minorid']);
1344 $trashed->saveWebPaths(Array());
1345 $GLOBALS[
'SQ_SYSTEM']->am->trashAsset($trashed->id);
1350 if (in_array(
'associated_files.tar.gz', $extract_list)) {
1351 $assoc_tar =
'associated_files.tar.gz';
1353 if (in_array(
'associated-files.tar.gz', $extract_list)) {
1354 $assoc_tar =
'associated-files.tar.gz';
1356 if ($assoc_tar !=
'') {
1358 create_directory($files_dir.
'/extracted/');
1359 require_once
'Archive/Tar.php';
1360 $nested_tar_ball =
new Archive_Tar($files_dir.
'/associated_files.tar.gz');
1362 $nested_tar_ball->extract($files_dir.
'/extracted/');
1363 $assoc_files = list_files($files_dir.
'/extracted/', TRUE);
1365 foreach ($assoc_files as $full_path) {
1366 $info = Array(
'name' => basename($full_path),
'tmp_name' => $full_path);
1367 $info[
'non_uploaded_file'] = TRUE;
1369 trigger_error(translate(
'core_design_export_associated_file_problem', basename($full_path)), E_USER_WARNING);
1374 delete_directory($files_dir);
1377 trigger_error(translate(
'core_design_export_opening_problem', $file_info[
'name']), E_USER_WARNING);
1379 return $write_access;
1400 $tree_tops = $GLOBALS[
'SQ_SYSTEM']->am->getAssetidsByLookupValue(
'design::%', $asset->id, TRUE);
1402 if (count($tree_tops) > 0) {
1405 $num_pages = ceil(count($tree_tops) / $page_size);
1406 $page_num = array_get_index($_POST, $prefix.
'_usage_page', 1);
1407 $page_num = max($page_num, 1);
1408 $page_num = min($page_num, $num_pages);
1410 if ($num_pages == 1) {
1411 $page_tag = translate(
'page_number', $page_num, $num_pages);
1413 $page_tag = translate(
'page_number_with_pager', $page_num, $num_pages, $prefix.
'_usage_page');
1415 $asset_count_tag = translate(
'item_range', ($page_num - 1) * $page_size + 1, min(count($tree_tops), $page_num * $page_size), count($tree_tops), strtolower(translate(
'assets')));
1417 $tree_tops = array_slice($tree_tops, ($page_num - 1) * $page_size, $page_size);
1420 'first' =>
'<<',
1421 'previous' =>
'<',
1422 'page' => $page_tag,
1424 'last' =>
'>>',
1427 if ($page_num > 1) {
1428 $links[
'first'] =
'<a title="'.translate(
'pagination_go_to_first').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_usage_page\', 1)">'.$links[
'first'].
'</a>';
1429 $links[
'previous'] =
'<a title="'.translate(
'pagination_go_to_previous').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_usage_page\', '.($page_num - 1).
')">'.$links[
'previous'].
'</a>';
1431 $links[
'first'] =
'<span title="'.translate(
'pagination_cannot_go_further_back').
'." style="color: #333">'.$links[
'first'].
'</span>';
1432 $links[
'previous'] =
'<span title="'.translate(
'pagination_cannot_go_further_back').
'." style="color: #333">'.$links[
'previous'].
'</span>';
1435 if ($page_num < $num_pages) {
1436 $links[
'last'] =
'<a title="'.translate(
'pagination_go_to_last').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_usage_page\', '.$num_pages.
')">'.$links[
'last'].
'</a>';
1437 $links[
'next'] =
'<a title="'.translate(
'pagination_go_to_next').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_usage_page\', '.($page_num + 1).
')">'.$links[
'next'].
'</a>';
1439 $links[
'last'] =
'<span title="'.translate(
'pagination_cannot_go_further_forward').
'." style="color: #333">'.$links[
'last'].
'</span>';
1440 $links[
'next'] =
'<span title="'.translate(
'pagination_cannot_go_further_forward').
'." style="color: #333">'.$links[
'next'].
'</span>';
1443 hidden_field($prefix.
'_usage_page', $page_num); ?>
1444 <table
class=
"sq-backend-table">
1446 <tr
class=
"sq-backend-table-row">
1447 <td
class=
"sq-backend-table-header-header"><?php echo implode(
' ', $links) ?></td>
1448 <td
class=
"sq-backend-table-header-header" style=
"text-align: right; font-weight: normal"><?php echo $asset_count_tag; ?></span></td>
1450 <tr
class=
"sq-backend-table-row">
1451 <th
class=
"sq-backend-table-cell" colspan=
"2"><?php echo translate(
'asset'); ?></th>
1457 foreach ($tree_tops as &$tree_info) {
1458 ?><tr
class=
"sq-backend-table-row">
1459 <td
class=
"sq-backend-table-cell" colspan=
"2">
1462 $tag_line = get_asset_tag_line($tree_info[
'assetid'],
'details');
1464 $child_count_mult = $tree_info[
'child_count'];
1465 if ($child_count_mult > 1) $child_count_mult =
'm';
1466 echo translate(
'asset_and_child_count_'.$child_count_mult, $tag_line, $tree_info[
'child_count']);
1477 $o->
note(translate(
'design_usage_explanation'));
1480 $o->
note(translate(
'core_design_usage_no_assets'));
1506 $all_treeids = Array();
1507 foreach ($treeids as $assetid => $asset_treeids) {
1508 foreach ($asset_treeids[0] as $asset_treeid) {
1509 if (($asset_treeid ===
'override') || ($asset_treeid ===
'not_override')) {
1512 $all_treeids[$asset_treeid] = $assetid;
1515 uksort($all_treeids, Array($this,
'_strlenCmp'));
1517 foreach ($all_treeids as $treeid => $assetid) {
1518 $treeid_copy = $treeid;
1519 while (!empty($treeid_copy)) {
1520 if (isset($res[$treeid_copy])) {
1521 $res[$treeid_copy][
'child_count']++;
1524 $treeid_copy = substr($treeid_copy, 0, -SQ_CONF_ASSET_TREE_SIZE);
1526 $res[$treeid][
'assetid'] = $assetid;
1527 $res[$treeid][
'child_count'] = 0;
1546 return strlen($a) > strlen($b);
1564 $write_access = $asset->
writeAccess(
'attributes');
1565 $select_options = $asset->
attr($attribute);
1567 if (!empty($select_options)) {
1569 <table
class=
"sq-backend-table">
1571 <td
class=
"sq-backend-table-header"><?php echo translate(
'core_design_class_name'); ?></td>
1572 <td
class=
"sq-backend-table-header"><?php echo translate(
'core_design_class_short_name'); ?></td>
1574 if ($write_access) {
1575 ?><td
class=
"sq-backend-table-header"><?php echo translate(
'delete_question'); ?></td><?php
1581 foreach ($select_options as $option_key => $option_value) {
1584 <td
class=
"sq-backend-table-cell">
1586 if ($write_access) {
1587 text_box($prefix.
'_options[key]['.$i.
']', $option_key, 20);
1593 <td
class=
"sq-backend-table-cell" align=
"left">
1595 if ($write_access) {
1596 text_box($prefix.
'_options[val]['.$i.
']', $option_value, 20);
1603 if ($write_access) {
1605 <td
class=
"sq-backend-table-cell">
1606 <?php check_box($prefix.
'_options[del]['.$i.
']', $option_key); ?>
1620 echo translate(
'no_select_box_options');
1624 if ($write_access) {
1626 echo
'<b>'.translate(
'key').
'</b> ';
1627 text_box($prefix.
'_new_key',
'');
1628 echo
' <b>'.translate(
'value').
'</b> ';
1629 text_box($prefix.
'_new_val',
'');
1652 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
1654 $select_options = Array();
1655 if (isset($_POST[$prefix.
'_options'])) {
1656 $option_changes = $_POST[$prefix.
'_options'];
1657 foreach ($option_changes[
'key'] as $i => $key) {
1658 if (isset($option_changes[
'del'][$i]))
continue;
1659 $select_options[trim($key)] = trim($option_changes[
'val'][$i]);
1664 if (strlen(trim($_POST[$prefix.
'_new_key']))>0 && strlen(trim($_POST[$prefix.
'_new_val']))>0) {
1665 $new_select_key = trim($_POST[$prefix.
'_new_key']);
1666 $new_select_val = trim($_POST[$prefix.
'_new_val']);
1667 $select_options[$new_select_key] = $new_select_val;
1688 $this->
_paintSelection($asset, $o, $prefix.
'_wysiwyg',
'wysiwyg_classes');
1690 $o->
note(translate(
'core_design_class_wysiwyg_note'));
1727 $o->
note(translate(
'core_design_class_div_note'));