18 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
19 require_once SQ_FUDGE_PATH.
'/general/text.inc';
20 require_once SQ_FUDGE_PATH.
'/general/www.inc';
52 var $requires_form = FALSE;
57 var $performance_log_file_name =
'performance';
62 var $performance_threshold = 1000;
65 function __construct($assetid=0)
67 $this->_ser_attrs = TRUE;
68 parent::__construct($assetid);
85 if (!parent::_createAdditional($link))
return FALSE;
88 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
89 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
92 'type_formats' =>
'folder',
93 'position_formats' =>
'folder',
94 'group_formats' =>
'folder',
98 foreach ($sub_assets as $name => $type) {
100 $copy_link = Array(
'asset' => &$this,
'value' => $name ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
102 $asset->setAttrValue(
'name', ucwords(str_replace(
'_',
' ', $name)));
103 if (!$asset->create($copy_link))
return FALSE;
105 if ($name ==
'type_formats') $type_formats = $asset;
107 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
111 $copy_link = Array(
'asset' => &$type_formats,
'value' =>
'default_format' ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
112 $asset->setAttrValue(
'name', translate(
'default_format'));
114 if (!$asset->create($copy_link, $args))
return FALSE;
130 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
132 $copy_link = Array(
'asset' => &$this,
'value' =>
'page_contents' ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
133 $asset->setAttrValue(
'name',
'Page Contents');
135 if (!$asset->create($copy_link, $args))
return FALSE;
156 switch ($bodycopy_code) {
157 case 'page_contents':
158 return '%asset_listing%';
160 return '<p>'.translate(
'cms_listing_no_results').
'</p>';
161 case 'default_format':
162 return '%asset_name_linked%';
181 $lock_types = parent::lockTypes();
182 $lock_types[
'content'] = $lock_types[
'menu'];
208 function prepareLink(&$asset, $side_of_link, &$link_type, &$value, &$sort_order, &$dependant, &$exclusive)
211 if ($side_of_link ==
'major' && ($asset instanceof
Bodycopy) && $dependant !=
'1') {
231 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
232 switch (strtolower($link[
'value'])) {
234 return translate(
'cms_listing_root_node_link_desc');
237 return parent::describeLink($linkid);
254 $folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'type_formats');
255 if (!empty($folder_link)) {
256 if ($folder_link[
'linkid'] == $linkid && !$GLOBALS[
'SQ_PURGING_TRASH']) {
257 return translate(
'cms_listing_cannot_delete_type_formats_link', str_replace(
'_',
' ', $this->
type()));
261 $asset_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'position_formats');
262 if (!empty($asset_folder_link)) {
263 if ($asset_folder_link[
'linkid'] == $linkid && !$GLOBALS[
'SQ_PURGING_TRASH']) {
264 return translate(
'cms_listing_cannot_delete_position_formats_link', str_replace(
'_',
' ', $this->
type()));
268 $asset_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'group_formats');
269 if (!empty($asset_folder_link)) {
270 if ($asset_folder_link[
'linkid'] == $linkid && !$GLOBALS[
'SQ_PURGING_TRASH']) {
271 return translate(
'cms_listing_cannot_delete_group_formats_link', str_replace(
'_',
' ', $this->
type()));
275 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'page_contents');
276 if (!empty($bodycopy_link)) {
277 if ($bodycopy_link[
'linkid'] == $linkid && !$GLOBALS[
'SQ_PURGING_TRASH']) {
278 return translate(
'cms_cannot_delete_link', $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
282 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'no_results');
283 if (empty($bodycopy_link)) {
285 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_3,
'bodycopy', TRUE,
'no_results');
287 if (!empty($bodycopy_link) && $bodycopy_link[
'linkid'] == $linkid && !$GLOBALS[
'SQ_PURGING_TRASH']) {
288 return translate(
'cms_cannot_delete_link', $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
291 return parent::isDeletableLink($linkid);
321 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
322 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
324 if (in_array(
'attributes', $components) || in_array(
'all', $components)) {
328 $asset_grouping = $this->
attr(
'asset_grouping');
329 if (!empty($asset_grouping)) {
330 $am = $GLOBALS[
'SQ_SYSTEM']->am;
331 $new_asset_grouping = $asset_grouping;
332 foreach ($asset_grouping as $key => $group) {
333 if (isset($group[
'format_assetid']) && !empty($group[
'format_assetid'])) {
334 $bodycopy = $am->getAsset($group[
'format_assetid']);
335 $group_format_names[$key] = $bodycopy->name;
339 $folder = $clone->getFolder(
'group_formats');
340 if (is_null($folder)) {
342 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
343 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
344 trigger_localised_error(
'CMS0068', E_USER_WARNING);
347 $links_to_bodycopy = $am->getLinks($folder->id, SQ_LINK_TYPE_2,
'bodycopy');
348 if (!empty($links_to_bodycopy)) {
349 foreach ($links_to_bodycopy as $link) {
350 $bodycopy = $am->getAsset($link[
'minorid']);
351 if (($key = array_search($bodycopy->name, $group_format_names)) !== FALSE) {
352 $new_asset_grouping[$key][
'format_assetid'] = $bodycopy->id;
356 $clone->setAttrValue(
'asset_grouping', $new_asset_grouping);
357 $clone->saveAttributes();
363 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
364 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
379 $page_links = parent::_getAllowedLinks();
380 $page_links[SQ_LINK_TYPE_2][
'folder'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
381 $page_links[SQ_LINK_NOTICE][
'asset'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
382 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => 2,
'exclusive' => FALSE);
383 $page_links[SQ_LINK_TYPE_3][
'bodycopy'] = Array(
'card' => 1,
'exclusive' => FALSE);
400 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE, $type);
401 if (empty($link))
return $null;
403 $folder = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
404 if (is_null($folder))
return $null;
423 if (!isset($this->_tmp[
'formats'][$type])) {
425 $format_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE);
426 if (empty($format_links))
return Array();
429 foreach ($format_links as $link_data) {
430 $formats[$link_data[
'minorid']] = $link_data[
'value'];
432 $this->_tmp[
'formats'][$type] = $formats;
434 return $this->_tmp[
'formats'][$type];
450 $cached_contents = FALSE;
451 if (!empty($cache_key)) {
452 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
453 $cached_contents = $cm->loadFromCache($this->
id, $this->
type(), $cache_key);
456 $group_by = $this->
attr(
'group_by');
458 if ($cached_contents === FALSE) {
465 $contents = ob_get_clean();
470 $selections = $this->
attr(
'asset_selections');
472 if (!empty($used_fields) || !empty($selections) || $this->requires_form) {
475 $using_select_all = FALSE;
476 foreach ($selections as $selection_name => $selection_settings) {
477 if (array_get_index($selection_settings,
'type', NULL) ==
'radio' && !empty($selection_settings[
'options'][
'allow_multiple'])) {
479 <script
type=
"text/javascript" src=
"<?php echo sq_web_path('data') ?>/asset_types/listing_engine/js/select_all.js"></script>
481 $using_select_all = TRUE;
487 $contents = str_replace(
'%select_all_js_code%', $select_all_code, $contents);
489 if ($this->requires_form || !empty($used_fields)) {
493 $form_url = htmlspecialchars($form_url_components[
'url']);
496 <form
id=
"<?php echo $this->getPrefix() ?>" method=
"<?php echo $form_method ?>" action=
"<?php echo $form_url; ?>">
499 if ($form_method ==
'get') {
501 $vars_to_preserve = $_GET;
502 foreach ($used_fields as $used_field) {
503 if (substr($used_field, -1) ==
'%') {
505 foreach ($vars_to_preserve as $i => $v) {
506 if (0 === strpos($i, substr($used_field, 0, -1))) {
507 unset($vars_to_preserve[$i]);
511 if (isset($vars_to_preserve[$used_field])) {
512 unset($vars_to_preserve[$used_field]);
516 var_to_hidden_field($vars_to_preserve);
533 $contents = str_replace(
'%select_all_js_code%',
'', $contents);
538 if (!empty($cache_key) && (strcmp($group_by,
'random') != 0)) {
539 $cm->saveToCache($this->
id, $this->
type(), $cache_key, ob_get_contents());
545 echo $cached_contents;
560 $base_url = ($this->
attr(
'submit_to_page_url') ? $this->
getURL() : current_url());
563 if ($form_method ==
'get') {
568 $url = replace_query_string_vars(Array(), $base_url);
569 $vars_to_preserve = Array();
574 'url_base' => $base_url,
590 $no_results_bodycopy_printed = FALSE;
594 $replacements = Array();
595 $replacements[
'asset_count'] = 0;
596 $replacements[
'asset_listing'] =
'';
597 $replacements[
'page_list'] =
'';
598 $replacements[
'page_number'] = 0;
599 $replacements[
'page_asset_count'] = 0;
600 $replacements[
'total_pages'] = 0;
601 $replacements[
'first_asset_position'] = 0;
602 $replacements[
'last_asset_position'] = 0;
603 $replacements[
'previous_page'] =
'';
604 $replacements[
'previous_page_href'] =
'';
605 $replacements[
'next_page'] =
'';
606 $replacements[
'next_page_href'] =
'';
609 if (!is_null($no_results_bodycopy)) {
610 foreach ($keywords as $word) {
611 if (isset($replacements[$word]))
continue;
617 foreach ($replacements as $kw => $res) {
618 if ($res ==
'%'.$kw.
'%') {
619 $plain_keyword = parse_keyword($kw, $modifiers);
620 if (isset($replacements[$plain_keyword]) && $replacements[$plain_keyword] !==
'%'.$plain_keyword.
'%' && !empty($modifiers)) {
621 $replacements[$kw] = $replacements[$plain_keyword];
623 apply_keyword_modifiers($replacements[$kw], $modifiers, Array(
'assetid' => $this->
id,
'replacements' => $replacements));
628 $no_results_bodycopy->setKeywordReplacements($replacements);
629 $no_results_bodycopy->printBody();
630 $no_results_bodycopy_printed = TRUE;
633 return $no_results_bodycopy_printed;
646 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'page_contents');
647 $bodycopy_no_result_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'no_results');
648 if (empty($bodycopy_link))
return FALSE;
650 $format_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
652 if (is_null($format_bodycopy))
return FALSE;
654 require_once SQ_FUDGE_PATH.
'/general/text.inc';
655 $keywords = $format_bodycopy->getKeywords();
656 if ($bodycopy_no_result_link) {
657 $format_bodycopy_no_result = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_no_result_link[
'minorid'], $bodycopy_no_result_link[
'minor_type_code']);
658 $keywords = array_merge($format_bodycopy_no_result->getKeywords(),$keywords);
660 $replacements = Array();
662 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'getAssetList');
664 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'getAssetList');
672 $total_numbers = isset($children) ? count($children) : 0;
673 if ($total_numbers >= $this->performance_threshold) {
674 $log_contents =
'Listing page #'.$this->id.
' is trying to list '.$total_numbers.
' assets, which exceeds the performance monitor threshold of '.$this->performance_threshold;
675 log_write($log_contents, $this->performance_log_file_name, E_USER_WARNING);
678 $exclude_assets = $this->
attr(
'exclude_assets');
681 $exclude_root_nodes = $this->
attr(
'exclude_root_nodes');
682 $exlcude_rootids_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($exclude_root_nodes, Array(), TRUE,
'type_code');
683 foreach($exclude_root_nodes as $key =>$value) {
684 if (isset($exlcude_rootids_info[$value])) {
685 $exclude_children = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($value);
686 $exclude_assets = array_merge($exclude_assets, array_keys($exclude_children));
688 trigger_error(
'Cannot find the asset #'.$value.
' that has been set as an exclude root node on the listing asset #'.$this->id);
692 if (!empty($exclude_assets)) {
693 foreach ($exclude_assets as $index => $assetid) {
694 if (isset($children[$assetid])) {
695 unset($children[$assetid]);
700 if($this->
attr(
'exclude_current_asset')) {
701 foreach ($children as $assetid => $data) {
702 $url = strip_url($GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($assetid));
703 $requester = strip_url(current_url());
704 if ($requester === $url) {
705 unset($children[$assetid]);
713 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'filterAssetList');
715 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'filterAssetList');
717 $num_kids = count($children);
718 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'replaceFormatKeywords');
719 foreach ($keywords as $word) {
723 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'replaceFormatKeywords');
728 if (empty($children)) {
731 if (!$no_results_bodycopy_printed) {
732 $selections = $this->
attr(
'asset_selections');
733 foreach ($selections as $selection_name => $settings) {
734 $replacements[$selection_name.
'_check_all'] =
'';
735 $replacements[$selection_name.
'_check_all_in_group'] =
'';
738 $format_bodycopy->setKeywordReplacements($replacements);
739 $format_bodycopy->printBody();
744 if (!in_array(
'asset_listing', $keywords)) {
747 $format_bodycopy->printBody();
751 if ($this->
attr(
'group_by') ==
'grouped') {
753 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'getAssetsInfo');
756 if (!isset($this->_tmp[
'no_asset_info_url_cache'])) {
757 $this->_tmp[
'assets_info'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($children));
758 $this->_tmp[
'asset_urls'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_keys($children));
760 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'getAssetsInfo');
763 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'groupAssets');
766 $this->
sortGroups($this->
attr(
'asset_grouping'), $children, $children);
767 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'groupAssets');
771 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'chunkAssets');
774 $start_pos = $this->
attr(
'start_position') - 1;
775 if ($start_pos > 0) {
776 if ($this->
attr(
'group_by') !=
'grouped') {
777 $children = $start_pos < count($children) ? array_slice($children, $start_pos, count($children) - $start_pos , TRUE) : Array();
780 foreach($children as $group_id => $child_group) {
781 $children[$group_id] = $start_pos < count($child_group) ? array_slice($child_group, $start_pos, count($child_group) - $start_pos, TRUE) : Array();
788 $asset_result_page_var =
'result_'.$this->id.
'_result_page';
789 $generic_result_page_var =
'result_page';
794 $_REQUEST = array_merge($_GET, $_REQUEST);
799 if (isset($_REQUEST[$generic_result_page_var])) {
800 $result_page = (int)$_REQUEST[$generic_result_page_var];
802 if (isset($_REQUEST[$asset_result_page_var])) {
803 $result_page = (int)$_REQUEST[$asset_result_page_var];
806 if ($result_page <= 0) $result_page = 1;
809 $todo =& $this->
getChunk($children, $replacements, $keywords, $result_page, $num_per_page);
815 if ($this->
attr(
'group_by') ==
'random') {
817 while (count($todo) > max($num_per_page, 1)) {
822 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'chunkAssets');
825 if ($this->
attr(
'group_by') !=
'grouped') {
826 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'getAssetsInfo');
829 if (!isset($this->_tmp[
'no_asset_info_url_cache'])) {
830 $this->_tmp[
'assets_info'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($todo));
831 $this->_tmp[
'asset_urls'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL(array_keys($todo));
833 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'getAssetsInfo');
837 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this,
'printBody');
840 $num_assets_showing = count($todo);
841 if ($num_assets_showing > 0) {
844 $global_contents = ob_get_contents();
849 if (!$no_results_bodycopy_printed) {
850 $selections = $this->
attr(
'asset_selections');
851 foreach ($selections as $selection_name => $settings) {
852 $replacements[$selection_name.
'_check_all'] =
'';
853 $replacements[$selection_name.
'_check_all_in_group'] =
'';
856 $format_bodycopy->setKeywordReplacements($replacements);
857 $format_bodycopy->printBody();
863 $replacements[
'asset_listing'] = $global_contents;
864 if ($this->
attr(
'group_by') !=
'grouped') {
865 $replacements[
'asset_count'] = $num_kids;
868 $replacements[
'asset_count'] = $total_assets;
869 $replacements[
'unique_asset_count'] = $num_kids;
872 $result_page = $replacements[
'page_number'];
873 $replacements[
'page_asset_count'] = $num_assets_showing;
876 if ($replacements[
'asset_count'] == 0) {
877 $replacements[
'first_asset_position'] = 0;
878 }
else if ($num_per_page == 0) {
879 $replacements[
'first_asset_position'] = 1;
881 $replacements[
'first_asset_position'] = max(1, $num_per_page * ($result_page - 1) + 1);
884 if ($num_per_page == 0) {
885 $replacements[
'last_asset_position'] = $replacements[
'asset_count'];
887 $replacements[
'last_asset_position'] = min($replacements[
'asset_count'], $num_per_page * $result_page);
889 $replacements[
'select_all_js_code'] =
'%select_all_js_code%';
893 foreach ($replacements as $kw => $res) {
894 if ($res ==
'%'.$kw.
'%') {
895 $plain_keyword = parse_keyword($kw, $modifiers);
898 $keywords_is_replaced = isset($replacements[$plain_keyword]) && $replacements[$plain_keyword] !=
'%'.$plain_keyword.
'%' && $replacements[$plain_keyword] != $plain_keyword;
899 if (!empty($modifiers) && $keywords_is_replaced) {
900 $replacements[$kw] = $replacements[$plain_keyword];
902 apply_keyword_modifiers($replacements[$kw], $modifiers, Array(
'assetid' => $this->
id,
'replacements' => $replacements));
908 $format_bodycopy->setKeywordReplacements($replacements);
909 if (!in_array(
'select_all_js_code', $keywords)) {
912 echo
'%select_all_js_code%';
914 $format_bodycopy->printBody();
917 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($format_bodycopy);
920 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this,
'printBody');
932 $group_by = $this->
attr(
'group_by');
933 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
939 $asset_result_page_var =
'result_'.$this->id.
'_result_page';
940 $generic_result_page_var =
'result_page';
946 if (isset($_REQUEST[$generic_result_page_var])) {
947 $cache_key = (int)$_REQUEST[$generic_result_page_var];
949 if (isset($_REQUEST[$asset_result_page_var])) {
950 $cache_key = (int)$_REQUEST[$asset_result_page_var];
952 if ($cache_key <= 0) $cache_key = 1;
958 if (isset($_REQUEST[$generic_result_page_var])) {
959 $cache_key = $_REQUEST[$generic_result_page_var];
961 if (isset($_REQUEST[$asset_result_page_var])) {
962 $cache_key = $_REQUEST[$asset_result_page_var];
974 $pmap = unserialize($this->
attr(
'parameter_map'));
975 if (isset($pmap[
'root_node'])) {
977 $nodes = $parameter_map->getParameterValue(
'root_node');
978 if (is_array($nodes)) {
979 $root_nodes = $nodes;
981 $root_nodes[] = $nodes;
988 if ($this->
type() ==
'search_page') {
989 $pmap = unserialize($this->
attr(
'stored_query_session'));
992 $pmap_params = $pmap->getParameters();
993 if (is_array($pmap_params) && !empty($pmap_params)) {
994 foreach ($pmap_params as $params) {
995 $sq_index = $pmap->getParameterValue($params);
996 if (isset($sq_index)) $stored_queries[] = $sq_index;
1001 if (!empty($stored_queries)) {
1002 $cache_key .=
'-'.serialize($stored_queries);
1007 if ($this->
type() ==
'funnelback_search_page') {
1010 $pmap_params = $pmap->getParameters();
1011 foreach ($pmap_params as $params) {
1012 $dynamic_query = $pmap->getParameterValue($params);
1013 $cache_key .=
'-'.$params.
':'.$dynamic_query;
1018 if (!empty($root_nodes)) {
1019 $cache_key .=
'-'.implode(
'-', $root_nodes);
1026 $cache_key .=
'-ctx'.$contextid;
1042 $num_per_page = $this->
attr(
'num_per_page');
1045 require_once SQ_FUDGE_PATH.
'/general/text.inc';
1046 replace_global_keywords($num_per_page);
1047 $num_per_page_keywords = retrieve_keywords_replacements($num_per_page);
1048 $replacements = Array();
1049 foreach ($num_per_page_keywords as $keyword) {
1052 replace_keywords($num_per_page, $replacements);
1053 settype($num_per_page,
'integer');
1055 return $num_per_page;
1098 if (isset($sort_info[
'name']) && $sort_info[
'name'] ==
'No Sorting') {
1102 if (count($asset_list) == 1 || empty($sort_info)) {
1105 if ((!is_array($asset_list)) || (empty($asset_list))) {
1110 if ($sort_info[
'type'] ==
'' && $sort_info[
'name'] ==
'Random') {
1111 $keys = array_keys($asset_list);
1113 $rand_asset_list = Array();
1114 foreach ($keys as $key) {
1115 $rand_asset_list[$key] = $asset_list[$key];
1117 return ($rand_asset_list);
1120 $skipped_assets = Array();
1121 $sort_assets = Array();
1125 $sort_numeric = TRUE;
1128 $is_sort_by_attribute = ($sort_info[
'type'] ==
'asset_attrib');
1129 $is_sort_by_field = ($sort_info[
'type'] ==
'field');
1130 $is_sort_by_metadata = ($sort_info[
'type'] ==
'metadata');
1131 $is_sort_by_keyword = ($sort_info[
'type'] ==
'keyword');
1133 $sort_params =& $sort_info[
'params'];
1134 $assetids = array_keys($asset_list);
1136 if ($is_sort_by_attribute) {
1137 $sort_by_attr = $sort_params[
'attribute'];
1138 $sort_by_type_code = $sort_params[
'type_code'];
1140 foreach ($this->
attr(
'types') as $type_code => $inherit) {
1143 if ($type_code == $sort_by_type_code) {
1148 $type_anc = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($type_code);
1149 array_unshift($type_anc, $type_code);
1151 foreach ($type_anc as $this_type_code) {
1152 if ($this_type_code == $sort_by_type_code) {
1161 $rem_assetids = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($assetids, $type_code, !$inherit));
1167 if (isset($sort_params[
'attr_type']) && !in_array($sort_params[
'attr_type'], Array(
'int',
'float'))) {
1168 $sort_numeric = FALSE;
1171 $attr_info = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName($sort_by_attr, $sort_by_type_code, $rem_assetids);
1172 foreach ($rem_assetids as $assetid) {
1173 if (isset($attr_info[$assetid])) {
1174 $sort_assets[$assetid] = strtolower($attr_info[$assetid]);
1176 if (($pos = array_search($assetid, $skipped_assets)) !== FALSE) {
1177 unset($skipped_assets[$pos]);
1182 $skipped_assets = array_merge($skipped_assets, array_diff($rem_assetids,array_keys($attr_info)));
1186 $skipped_assets = array_merge($skipped_assets, $rem_assetids);
1189 }
else if ($is_sort_by_metadata) {
1191 $sort_numeric = FALSE;
1192 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
1193 $fieldid = $sort_info[
'field'];
1195 if (isset($sort_info[
'field'])) {
1196 $fieldid = $sort_info[
'field'];
1199 $field_default_val = $mm->getMetadataFieldDefaultValue($fieldid);
1201 $field_default_val =
'';
1204 $presentation_value = FALSE;
1205 if ($this->
attr(
'metadata_sort_type') ==
'presentation') {
1206 $presentation_value = TRUE;
1209 foreach ($asset_list as $assetid => $type) {
1210 $meta_field_val = $mm->getMetadataValueByAssetid($assetid,$fieldid,TRUE,$presentation_value);
1211 $field_value = $field_default_val;
1212 if (isset($meta_field_val)) {
1213 $field_value = $meta_field_val;
1216 if (preg_match(
'/^%(.*)%$/',$field_value,$matches)) {
1217 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1219 $field_value = $asset->getKeywordReplacement($matches[1]);
1221 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
1224 $sort_assets[$assetid] = strtolower($field_value);
1227 }
else if ($is_sort_by_keyword) {
1228 foreach ($asset_list as $assetid => $type) {
1229 $tmp_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1230 $replacement = $tmp_asset->getKeywordReplacement($sort_info[
'keyword']);
1231 if (!empty($replacement)) {
1232 $sort_assets[$assetid] = $replacement;
1235 $skipped_assets[] = $assetid;
1237 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($tmp_asset);
1239 $sort_numeric = FALSE;
1241 $sort_field = $sort_params[
'field'];
1243 if (isset($sortable_info[$sort_field])) {
1244 $sort_assets = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($assetids, NULL, TRUE, $sort_field);
1245 for (reset($sort_assets); NULL !== ($assetid = key($sort_assets)); next($sort_assets)) {
1246 $sort_assets[$assetid] = strtolower($sort_assets[$assetid]);
1249 if ($sort_field !=
'assetid') $sort_numeric = FALSE;
1252 if ($reverse_sort) {
1253 return array_reverse($asset_list, TRUE);
1262 if ($sort_numeric) {
1263 uasort($sort_assets, create_function(
'$a,$b',
'return '.($reverse_sort ?
'$b - $a' :
'$a - $b').
';'));
1265 if ($reverse_sort) {
1266 arsort($sort_assets);
1268 asort($sort_assets);
1272 $assets_to_list = Array();
1273 $sorted_assets = array_keys($sort_assets);
1274 foreach ($sorted_assets as $assetid) {
1275 $assets_to_list[$assetid] = $asset_list[$assetid];
1279 foreach ($skipped_assets as $assetid) {
1280 $assets_to_list[$assetid] = $asset_list[$assetid];
1282 return $assets_to_list;
1299 $group_by = $this->
attr(
'group_by');
1303 if (empty($todo))
return;
1306 switch ($group_by) {
1321 $filtered_todo = Array();
1322 for (reset($todo); NULL !== ($todo_id = key($todo)); next($todo)) {
1323 $filtered_todo[$todo_id] = Array( 0 => Array(
'type_code' => $todo[$todo_id][0][
'type_code']));
1327 foreach (array_keys($todo) as $todo_id) {
1328 if (!isset($filtered_todo[$todo_id])) {
1329 unset($todo[$todo_id]);
1332 unset($filtered_todo);
1356 if (empty($todo))
return;
1361 $real_assetids = Array();
1362 $bridge_assetids = Array();
1363 foreach ($todo as $assetid => $details) {
1364 if (FALSE !== strpos($assetid,
':')) {
1365 $bridge_assetids[] = strtok($assetid,
':');
1367 $real_assetids[] = $assetid;
1371 $wanted_statuses = $this->
attr(
'statuses');
1374 if (!empty($wanted_statuses) && (array_sum($wanted_statuses) != SQ_SC_STATUS_ALL)) {
1376 foreach (array_unique(array_merge($real_assetids, $bridge_assetids)) as $assetid) {
1379 $in_clauses = Array();
1380 foreach (array_chunk($query_assetids, 999) as $chunk) {
1381 $in_clauses[] =
' assetid IN ('.implode(
', ', $chunk).
')';
1388 ('.implode(
' OR ', $in_clauses).
')
1389 AND status IN ('.implode(
', ', $wanted_statuses).
')';
1391 $status_matches = Array();
1395 }
catch (Execption $e) {
1396 throw new Exception($e->getMessage());
1400 $status_matches = array_unique(array_merge($real_assetids, $bridge_assetids));
1403 if (!$GLOBALS[
'SQ_SYSTEM']->userRoot() && !$GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
1405 if (!empty($wanted_statuses)) {
1406 $may_have_sublives = FALSE;
1407 foreach ($wanted_statuses as $status) {
1408 if ($status < SQ_STATUS_LIVE) {
1409 $may_have_sublives = TRUE;
1414 $may_have_sublives = TRUE;
1417 if ($may_have_sublives) {
1418 $sub_live_assets = Array();
1419 foreach ($status_matches as $assetid) {
1422 $in_clauses = Array();
1423 foreach (array_chunk($query_assetids, 999) as $chunk) {
1424 $in_clauses[] =
' assetid IN ('.implode(
', ', $chunk).
')';
1431 ('.implode(
' OR ', $in_clauses).
')
1432 AND status < :status';
1433 $sub_live_assets = NULL;
1438 }
catch (Exception $e) {
1439 throw new Exception($e->getMessage());
1442 foreach ($status_matches as $i => $v) {
1443 if (isset($sub_live_assets[$v])) {
1444 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($v, $sub_live_assets[$v][0][
'type_code']);
1445 if (is_null($asset) || !$asset->readAccess()) {
1446 unset($status_matches[$i]);
1455 foreach (array_keys($todo) as $i) {
1456 if (FALSE !== strpos($i,
':')) {
1457 $bridgeid = strtok($i,
':');
1458 if (!in_array($bridgeid, $status_matches)) {
1462 if (!in_array($i, $status_matches)) unset($todo[$i]);
1486 if (empty($allowed_types)) {
1491 foreach ($todo as $assetid => $type_codes) {
1492 $type_code = $type_codes[0][
'type_code'];
1494 if (empty ($type_code)){
1495 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1496 $type_code = $asset->type();
1497 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
1499 if (!isset($allowed_types[$type_code])) {
1500 unset($todo[$assetid]);
1502 $todo[$assetid] = Array(
'0' => Array(
1503 'type_code' => $allowed_types[$type_code],
1529 if (isset($this->_tmp[
'allowed_asset_map'])) {
1530 return $this->_tmp[
'allowed_asset_map'];
1533 $wanted_types = $this->
attr(
'types');
1534 if (empty($wanted_types))
return Array();
1536 $allowed_asset_map = Array();
1537 foreach ($wanted_types as $allowed_parent_type => $inherit) {
1538 if (trim($allowed_parent_type) ==
'') {
1540 }
else if (!$inherit) {
1541 $allowed_asset_map[$allowed_parent_type] = $allowed_parent_type;
1543 $descendants = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($allowed_parent_type, TRUE);
1544 foreach ($descendants as $allowed_type) {
1545 if (!isset($allowed_asset_map[$allowed_type])) {
1546 $allowed_asset_map[$allowed_type] = $allowed_parent_type;
1552 $this->_tmp[
'allowed_asset_map'] = $allowed_asset_map;
1553 return $allowed_asset_map;
1570 $asset_positions = $this->
attr(
'asset_positions');
1571 if (empty($asset_positions))
return;
1574 $all_assets = $todo;
1575 $adjusted_positions = Array();
1582 $maximum_possible_position = count($all_assets);
1583 foreach ($asset_positions as $position => $asset_data) {
1584 $id = $asset_data[
'id'];
1588 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($id);
1589 if (is_null($asset)) {
1590 $read_access = FALSE;
1592 $read_access = $asset->readAccess();
1596 if (!$read_access) {
1601 if ($position > $maximum_possible_position) {
1606 if (!isset($all_assets[$id])) {
1608 $maximum_possible_position++;
1609 $type = $asset_data[
'type'];
1610 $all_assets[$id] = array_get_index($allowed_asset_map, $type, $type);
1616 $adjusted_positions[$position] = $id;
1620 if (empty($adjusted_positions))
return;
1622 $originally_ordered_ids = array_keys($todo);
1625 $current_position = 1;
1627 if (isset($adjusted_positions[$current_position])) {
1628 $current_id = $adjusted_positions[$current_position];
1629 unset($adjusted_positions[$current_position]);
1631 $current_id = array_shift($originally_ordered_ids);
1634 $todo[$current_id] = array_get_index($all_assets, $current_id);
1636 $current_position++;
1637 }
while (!empty($originally_ordered_ids) || isset($adjusted_positions[$current_position]));
1657 function &
getChunk(&$children, &$replacements, $keywords, $result_page, $num_per_page, $group_by=NULL)
1663 if (is_null($group_by)) {
1664 $group_by = $this->
attr(
'group_by');
1667 $page_list_keywords = Array();
1668 foreach ($keywords as $keyword) {
1669 if (preg_match(
'/page_list_([0-9]+)/', $keyword, $matches)) {
1670 $page_list_keywords[$matches[1]] = $keyword;
1674 $this->_tmp[
'result_page'] = 1;
1676 $asset_result_page_var =
'result_'.$this->id.
'_result_page';
1677 $generic_result_page_var =
'result_page';
1679 switch ($group_by) {
1682 if ($num_per_page > 0) {
1683 $chunks = array_chunk($children, $num_per_page, TRUE);
1685 $chunks = Array(
'0' => $children);
1688 if ($result_page > count($chunks)) {
1689 $result_page = count($chunks);
1691 $todo = $chunks[($result_page-1)];
1694 if ($result_page <= 1) {
1695 $replacements[
'previous_page'] = $this->
attr(
'hide_no_href_links') ?
'' : $this->
attr(
'prev_page_text');
1696 $replacements[
'previous_page_href'] =
'';
1699 $replacements[
'previous_page_href'] = htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $result_page-1), NULL, NULL, TRUE));
1700 $replacements[
'previous_page'] =
'<a href="'.$replacements[
'previous_page_href'].
'">'.$this->
attr(
'prev_page_text').
'</a>';
1705 if ($result_page >= count($chunks)) {
1706 $replacements[
'next_page'] = $this->
attr(
'hide_no_href_links') ?
'' : $this->
attr(
'next_page_text');
1707 $replacements[
'next_page_href'] =
'';
1709 $replacements[
'next_page_href'] = htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $result_page+1), NULL, NULL, TRUE));
1710 $replacements[
'next_page'] =
'<a href="'.$replacements[
'next_page_href'].
'">'.$this->
attr(
'next_page_text').
'</a>';
1713 $this->_tmp[
'result_page'] = (int)$result_page;
1714 $replacements[
'total_pages'] = count($chunks);
1716 $page_list = $this->
_getPageList(count($chunks), $result_page);
1717 $replacements[
'page_list'] = $page_list;
1718 $replacements[
'page_list_without_unused'] = $page_list;
1720 foreach ($page_list_keywords as $window_size => $keyword) {
1721 $replacements[$keyword] = $this->
_getPageList(count($chunks), $result_page, $window_size);
1730 $other_letter_value = $this->
attr(
'other_page_text');
1733 $other_letter =
'@';
1734 foreach (range(
'A',
'Z') as $one_letter) {
1735 $all_letters[$one_letter] = $one_letter;
1738 foreach ($children as $childid => $datas) {
1740 $letter = strtoupper($data[
'first_letter']);
1741 if (!isset($all_letters[$letter])) {
1742 $letter = $other_letter;
1744 $todo[$letter][$childid] = $data[
'type_code'];
1748 if (isset($todo[$other_letter])) {
1749 $all_letters[$other_letter] = $other_letter_value;
1752 if ($this->
attr(
'a_z_style') ==
'single') {
1754 $page_list_without_unused =
'';
1755 foreach ($all_letters as $one_letter => $text_value) {
1756 if (isset($todo[$one_letter])) {
1757 $letter_link =
' <a href="#letter_'.$one_letter.
'">'.$text_value.
'</a> ';
1758 $page_list .= $letter_link;
1759 $page_list_without_unused .= $letter_link;
1761 $page_list .=
' '.$text_value.
' ';
1765 $this->_tmp[
'result_page'] = (int)$result_page;
1766 $replacements[
'page_list'] = $page_list;
1767 $replacements[
'page_list_without_unused'] = $page_list_without_unused;
1773 foreach ($all_letters as $one_letter => $text) {
1774 if (isset($todo[$one_letter])) {
1775 $letters[] = $one_letter;
1779 $first_available_letter = $letters[0];
1782 $result_page = $first_available_letter;
1783 if (isset($_REQUEST[$generic_result_page_var])) {
1784 $result_page = $_REQUEST[
'result_page'];
1786 if (isset($_REQUEST[$asset_result_page_var])) {
1787 $result_page = $_REQUEST[$asset_result_page_var];
1791 if (!isset($todo[$result_page])) {
1792 $result_page = $first_available_letter;
1795 $this_letter_key = array_search($result_page, $letters);
1798 $prev_page_text = $this->
attr(
'prev_page_text');
1799 $prev_page_link =
'';
1800 if ($this_letter_key > 0) {
1801 $prev_page_link = htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $letters[$this_letter_key - 1]), NULL, NULL, TRUE));
1802 $prev_page_text =
'<a href="'.$prev_page_link.
'">'.$prev_page_text.
'</a>';
1804 $replacements[
'previous_page'] = $prev_page_text;
1805 $replacements[
'previous_page_href'] = $prev_page_link;
1808 $next_page_text = $this->
attr(
'next_page_text');
1809 $next_page_href =
'';
1810 if ($this_letter_key < (
sizeof($letters) - 1)) {
1811 $next_page_href = htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $letters[$this_letter_key + 1]), NULL, NULL, TRUE));
1812 $next_page_text =
'<a href="'.$next_page_href.
'">'.$next_page_text.
'</a>';
1814 $replacements[
'next_page'] = $next_page_text;
1815 $replacements[
'next_page_href'] = $next_page_href;
1817 $replacements[
'total_pages'] = count($letters);
1818 $this->_tmp[
'result_page'] = $this_letter_key + 1;
1822 $page_list_without_unused =
'';
1823 foreach ($all_letters as $one_letter => $text_value) {
1824 if (isset($todo[$one_letter])) {
1825 $page_link_format = $this->
attr(
'page_link_format');
1826 $letter_link = str_replace(Array(
'%page_number%',
'%page_link%'), Array($text_value, htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $one_letter)))), $page_link_format);
1828 $page_list .= $letter_link;
1829 $page_list_without_unused .= $letter_link;
1831 $current_page_format = $this->
attr(
'current_page_format');
1832 $page_list .= str_replace(
'%page_number%', $text_value, $current_page_format);
1837 $todo = $todo[$result_page];
1838 $replacements[
'page_list'] = $page_list;
1839 $replacements[
'page_list_without_unused'] = $page_list_without_unused;
1847 $count = count($children);
1853 }
else if ($num_per_page <= 1) {
1855 $random_asset = array_rand($children);
1856 $todo[$random_asset] = $children[$random_asset];
1860 $random_assets = array_rand($children, min($num_per_page, $count));
1861 foreach ($random_assets as $value) {
1862 $todo[$value] = $children[$value];
1871 $count = $num_per_page * $result_page;
1875 $num_per_page = $total_assets;
1876 $count = $total_assets;
1884 $this->
sortGroups($this->
attr(
'asset_grouping'), $children, $children);
1886 $this->
_groupChunk($children, $todo, $count, $num_per_page, count($this->
attr(
'asset_grouping')));
1888 if ($num_per_page == 0) {
1889 $num_per_page = count($todo);
1892 $chunks = array_chunk($todo, $num_per_page, TRUE);
1893 $num_pages = ceil($total_assets / $num_per_page);
1895 $todo = end($chunks);
1899 if ($num_per_page) {
1900 $result_page = min($result_page, ceil($total_assets / $num_per_page));
1904 if ($result_page <= 1) {
1905 $replacements[
'previous_page'] = $this->
attr(
'hide_no_href_links') ?
'' : $this->
attr(
'prev_page_text');
1906 $replacements[
'previous_page_href'] =
'';
1908 $replacements[
'previous_page_href'] = htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $result_page-1), NULL, NULL, TRUE));
1909 $replacements[
'previous_page'] =
'<a href="'.$replacements[
'previous_page_href'].
'">'.$this->
attr(
'prev_page_text').
'</a>';
1913 if ($result_page >= $num_pages) {
1914 $replacements[
'next_page'] = $this->
attr(
'hide_no_href_links') ?
'' : $this->
attr(
'next_page_text');
1915 $replacements[
'next_page_href'] =
'';
1917 $replacements[
'next_page_href'] = htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $result_page+1), NULL, NULL, TRUE));
1918 $replacements[
'next_page'] =
'<a href="'.$replacements[
'next_page_href'].
'">'.$this->
attr(
'next_page_text').
'</a>';
1921 $this->_tmp[
'result_page'] = (int)$result_page;
1922 $replacements[
'total_pages'] = $num_pages;
1925 $page_list = $this->
_getPageList($num_pages, $result_page);
1926 $replacements[
'page_list'] = $page_list;
1927 $replacements[
'page_list_without_unused'] = $page_list;
1928 foreach ($page_list_keywords as $window_size => $keyword) {
1929 $replacements[$keyword] = $this->
_getPageList($num_pages, $result_page, $window_size);
1936 $replacements[
'page_number'] = $this->_tmp[
'result_page'];
1940 $replacements[
'current_page'] = $replacements[
'page_number'];
1959 $current_page_format = $this->
attr(
'current_page_format');
1960 $page_link_format = $this->
attr(
'page_link_format');
1962 if (is_null($window_size)) {
1964 $end_page = $total_pages;
1966 $start_page = max(1, min(($current_page - floor($window_size / 2)), $total_pages - $window_size + 1));
1967 $end_page = min($total_pages, $start_page + $window_size - 1);
1969 $asset_result_page_var =
'result_'.$this->id.
'_result_page';
1971 for ($i = $start_page; $i <= $end_page; $i++) {
1972 if ($i == $current_page) {
1973 $page_list .= str_replace(
'%page_number%', $i, $current_page_format);
1975 $page_list .= str_replace(Array(
'%page_number%',
'%page_link%'), Array($i, htmlspecialchars(replace_query_string_vars(Array($asset_result_page_var => $i)))), $page_link_format);
1999 function _groupChunk(&$todo, &$chunk, &$remaining_count, $num_per_page, $group_limit=NULL)
2002 if (($group_limit > 0) || is_null($group_limit)) {
2003 foreach ($todo as $index => $child) {
2004 if ($remaining_count >= 0) {
2005 $this->
_groupChunk($todo[$index], $chunk[$index], $remaining_count, $num_per_page, ($group_limit == NULL ? NULL : $group_limit - 1));
2008 if (empty($chunk[$index])) unset($chunk[$index]);
2014 foreach ($todo as $index => $value) {
2015 if (($remaining_count > 0) && ($remaining_count <= $num_per_page)) {
2016 $chunk[$index] = $value;
2037 if (empty($todo))
return;
2039 $this->_tmp[
'formats'] = Array();
2040 $this->_tmp[
'default_format'] =
'';
2041 $this->_tmp[
'is_default'] = Array();
2042 if (empty($this->_tmp[
'assets_info'])) {
2043 include_once SQ_FUDGE_PATH.
'/general/general.inc';
2044 $flattened = array_keys(array_flatten($todo, FALSE, TRUE));
2045 $this->_tmp[
'assets_info'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($flattened);
2046 $this->_tmp[
'asset_urls'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($flattened);
2049 $type_folder = $this->
getFolder(
'type_formats');
2051 $this->_tmp[
'type_folder_id'] = $type_folder->id;
2053 $this->_tmp[
'position_formats'] = Array();
2054 $position_folder = $this->
getFolder(
'position_formats');
2055 $format_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($position_folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE);
2056 foreach ($format_links as $link_data) {
2057 $position = substr($link_data[
'value'], 9);
2058 $this->_tmp[
'position_formats'][$position] = $link_data[
'minorid'];
2065 $selections = $this->
attr(
'asset_selections');
2066 if (!empty($selections)) {
2068 <script
type=
"text/javascript">
2075 $this->_tmp[
'js_relation_code'] = ob_get_clean();
2077 if ($this->
attr(
'group_by') ==
'grouped') {
2101 $pointer = reset($todo);
2102 if (!empty($group_info)) {
2103 include_once SQ_FUDGE_PATH.
'/general/general.inc';
2105 $remaining_groups = array_shift($group_info);
2106 $format_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($remaining_groups[
'format_assetid']);
2107 $format_keywords = $format_bodycopy->getKeywords();
2108 foreach ($todo as $group_level => $value) {
2110 $replacements = Array();
2112 switch ($remaining_groups[
'group_type']) {
2114 case 'parent_asset':
2116 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($group_level);
2117 if (isset($asset->var[
'name'])) {
2118 $group_name = htmlspecialchars($asset->attr(
'name'));
2120 $group_name = htmlspecialchars($asset->name);
2122 foreach ($format_keywords as $format_keyword) {
2123 $pos = strpos($format_keyword,
'parent');
2125 $keyword = substr_replace($format_keyword,
'asset', 0, 6);
2126 $replacements[$format_keyword] = $asset->getKeywordReplacement($keyword);
2129 $replacements[
'group_name_linked'] =
'<a href="'.$asset->getUrl().
'">'.htmlspecialchars($asset->name).
'</a>';
2130 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
2135 $group_name = $group_level;
2138 case 'standard_asset':
2140 if (isset($remaining_groups[
'field']) && $remaining_groups[
'field'] ==
'type_code') {
2141 $group_name = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($group_level,
'name');
2144 $group_name = $group_level;
2149 $group_name = $group_level;
2161 if (isset($this->_tmp[
'group_info'])) {
2162 array_push($this->_tmp[
'group_info'], $group_level);
2164 $this->_tmp[
'group_info'] = Array($group_level);
2170 if (isset($this->_tmp[
'group_levels'])) {
2171 array_push($this->_tmp[
'group_levels'], $group_level);
2173 $this->_tmp[
'group_levels'] = Array($group_level);
2178 $group_contents = ob_get_contents();
2182 $replacements[
'group_listing'] = $group_contents;
2183 $replacements[
'group_name'] = $group_name;
2186 if ((preg_match(
'|%parent_contents%|is', $format_bodycopy->getRawBodycopyContent())) || (preg_match(
'|%parent_contents_raw%|is', $format_bodycopy->getRawBodycopyContent()))) {
2187 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($group_level);
2189 $parent_asset->printBodyWithPaintLayout();
2190 $replacements[
'parent_contents'] = ob_get_contents();
2193 $parent_asset->printBody();
2194 $replacements[
'parent_contents_raw'] = ob_get_contents();
2198 $replacements[
'group_immed_child_group_count'] = count($todo[$group_level]);
2199 $replacements[
'group_total_child_asset_count'] = count(array_flatten($todo[$group_level], TRUE, FALSE));
2202 $selections = $this->
attr(
'asset_selections');
2205 foreach ($selections as $selection_name => $settings) {
2206 if (!in_array($selection_name.
'_check_all_in_group', $format_keywords)) {
2212 $selection_options = array_get_index($settings,
'options', $selection_defaults[
'options']);
2213 $selection_allow_multiple = array_get_index($selection_options,
'allow_multiple', $selection_defaults[
'options'][
'allow_multiple']);
2215 if ((array_get_index($settings,
'type', $selection_defaults[
'type']) ==
'radio') && $selection_allow_multiple) {
2218 $group_cb_id =
'g_'.implode(
'_', $this->_tmp[
'group_info']);
2221 $replacements[$selection_name.'_check_all_in_group
'] = ob_get_clean();
2222 $replacements[$selection_name.'_selection_id
'] = $control_name;
2226 // Keywords not evaluated above might be the ones with the modifiers
2227 // see bug #5808 %globals_X% keywords do not work in group format bodycopies
2228 // and bug #4734 keyword modifiers not working on group_name keyword
2229 foreach($format_keywords as $format_keyword) {
2230 // if it is asset based or globals keyword don't empty
string the replacement
2232 if (!isset($replacements[$format_keyword]) &&
2233 (strpos($format_keyword,
'globals_') !== FALSE || strpos($format_keyword,
'asset_') !== FALSE)) {
2236 $replacements[$format_keyword] =
'%'.$format_keyword.
'%';
2237 }
else if (!isset($replacements[$format_keyword])) {
2240 $replacements[$format_keyword] =
'';
2245 foreach($replacements as $kw => $value) {
2246 $plain_keyword = parse_keyword($kw, $modifiers);
2249 if (!empty($modifiers) &&
'%'.$kw.
'%' != $value) {
2250 $replacements[$kw] = $replacements[$plain_keyword];
2253 $assetid = ($remaining_groups[
'group_type'] ==
'parent_asset') ? $group_level : 0;
2254 apply_keyword_modifiers($replacements[$kw], $modifiers, Array(
'assetid' => $assetid,
'replacements' => $replacements));
2258 array_pop($this->_tmp[
'group_info']);
2259 $format_bodycopy->setKeywordReplacements($replacements);
2260 $format_bodycopy->printBody();
2266 $extras = array_diff(array_keys($todo), array_keys($this->_tmp[
'assets_info']));
2267 if (!empty($extras)) {
2268 $group_assets = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($todo));
2269 for (reset($group_assets); NULL !== ($index = key($group_assets)); next($group_assets)) {
2270 $this->_tmp[
'assets_info'][$index] = $group_assets[$index];
2297 $column_layout = $this->
attr(
'column_layout');
2298 $column_layout_type = $this->
attr(
'column_layout_type');
2299 $using_groups = $this->
attr(
'group_by') ==
'grouped';
2300 $using_columns = (count($column_layout) > 1 || $column_layout[
'0'] > 1);
2301 $num_items = count($todo);
2304 $a_z_letter_format = $this->
attr(
'a_z_letter_format');
2305 if ($this->
attr(
'group_by') ==
'letter' && $this->
attr(
'a_z_style') ==
'single') {
2306 if ($using_columns && $column_layout_type ===
'table') {
2308 foreach ($todo as $letter => $assets) {
2309 $letter_text = $letter ===
'@' ? $this->
attr(
'other_page_text') : $letter;
2310 $anchor =
'<a name="letter_'.$letter.
'">'.$letter_text.
'</a>';
2311 $anchor = str_replace(
'%letter_group%', $anchor, $a_z_letter_format);
2313 echo
'<table width="100%">';
2314 $num_rows = max(array_keys($column_layout)) + 1;
2315 $num_columns = max(array_values($column_layout));
2317 for (reset($assets); NULL !== ($assetid = key($assets));) {
2319 $cols_in_row = array_get_index($column_layout, $current_row, $column_layout[
'0']);
2320 $each_colspan = (int)($num_columns / $cols_in_row);
2321 $first_colspan = $each_colspan + $num_columns - ($cols_in_row * $each_colspan);
2323 for ($c = 1; $c <= $cols_in_row; $c++) {
2324 $colspan = ($c == 1) ? $first_colspan : $each_colspan;
2326 <td <?php echo ($colspan > 1) ?
' colspan="'.$colspan.
'"' :
''; ?>>
2328 if ($assetid == NULL) {
2331 $this->
_printAsset($assetid, $list_position, $num_items);
2333 $assetid = key($assets);
2348 else if ($using_columns && $column_layout_type ===
'div') {
2349 foreach ($todo as $letter => $assets) {
2350 $letter_text = $letter ===
'@' ? $this->
attr(
'other_page_text') : $letter;
2351 $anchor =
'<a name="letter_'.$letter.
'">'.$letter_text.
'</a>';
2352 $anchor = str_replace(
'%letter_group%', $anchor, $a_z_letter_format);
2354 $num_rows = max(array_keys($column_layout)) + 1;
2355 $num_columns = max(array_values($column_layout));
2356 $row_class = $this->
attr(
'div_row_class');
2359 for (reset($assets); NULL !== ($assetid = key($assets));) {
2360 echo empty($row_class) ?
'<div>' :
'<div class="'.$row_class.
'">';
2361 $cols_in_row = array_get_index($column_layout, $current_row, $column_layout[
'0']);
2363 for ($c = 1; $c <= $cols_in_row; $c++) {
2364 if ($assetid != NULL) {
2365 $this->
_printAsset($assetid, $list_position, $num_items);
2367 $assetid = key($assets);
2378 foreach ($todo as $letter => $assets) {
2379 $letter_text = $letter ===
'@' ? $this->
attr(
'other_page_text') : $letter;
2380 $anchor =
'<a name="letter_'.$letter.
'">'.$letter_text.
'</a>';
2381 $anchor = str_replace(
'%letter_group%', $anchor, $a_z_letter_format);
2383 foreach ($assets as $assetid => $type_code) {
2384 $this->
_printAsset($assetid, $list_position, $num_items);
2392 if ($using_columns && $column_layout_type ===
'table') {
2393 $num_rows = max(array_keys($column_layout)) + 1;
2394 $num_columns = max(array_values($column_layout));
2398 echo
'<table width="100%">';
2400 for (reset($todo); NULL !== ($assetid = key($todo));) {
2403 $cols_in_row = array_get_index($column_layout, $current_row, $column_layout[
'0']);
2404 $each_colspan = (int)($num_columns / $cols_in_row);
2405 $first_colspan = $each_colspan + $num_columns - ($cols_in_row * $each_colspan);
2407 for ($c = 1; $c <= $cols_in_row; $c++) {
2408 $colspan = ($c == 1) ? $first_colspan : $each_colspan;
2410 <td<?php echo ($colspan > 1) ?
' colspan="'.$colspan.
'"' :
''; ?>>
2412 if ($assetid == NULL) {
2415 $this->
_printAsset($assetid, $list_position, $num_items);
2417 $assetid = key($todo);
2431 else if ($using_columns && $column_layout_type ===
'div') {
2432 $num_rows = max(array_keys($column_layout)) + 1;
2433 $num_columns = max(array_values($column_layout));
2434 $row_class = $this->
attr(
'div_row_class');
2437 for (reset($todo); NULL !== ($assetid = key($todo));) {
2438 echo empty($row_class) ?
'<div>' :
'<div class="'.$row_class.
'">';
2439 $cols_in_row = array_get_index($column_layout, $current_row, $column_layout[
'0']);
2441 for ($c = 1; $c <= $cols_in_row; $c++) {
2442 if ($assetid != NULL) {
2443 $this->
_printAsset($assetid, $list_position, $num_items);
2445 $assetid = key($todo);
2455 foreach ($todo as $assetid => $type_code) {
2457 $this->
_printAsset($assetid, $list_position, $num_items);
2478 $keywords = Array();
2479 $shadow_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2480 foreach ($bc_keywords as $key => $keyword) {
2481 $keywords[$keyword] = $shadow_asset->getKeywordReplacement($keyword);
2503 if (isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'list_current_asset_id'])) {
2504 $prev_list_current_asset_id = $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'list_current_asset_id'];
2506 $prev_list_current_asset_id = null;
2508 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'list_current_asset_id'] = $assetid;
2512 $keywords = Array();
2513 $customised = $this->
getFormats(
'type_formats');
2515 $asset_info_fields = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfoFields();
2519 $is_shadow = strpos($assetid,
':');
2525 $info = array_get_index($this->_tmp[
'assets_info'], $assetid, Array(
'type_code' =>
''));
2526 if (!empty($info[
'type_code'])) {
2527 $type_code = $info[
'type_code'];
2529 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2530 $type_code = $asset->type();
2533 if (isset($this->_tmp[
'position_formats'][$list_position])) {
2534 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_tmp[
'position_formats'][$list_position],
'bodycopy');
2535 }
else if ($num_items > 0) {
2544 $negative_offset = -1 + ($list_position - $num_items);
2545 if (isset($this->_tmp[
'position_formats'][$negative_offset])) {
2546 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_tmp[
'position_formats'][$negative_offset],
'bodycopy');
2552 if (is_null($bodycopy) && !in_array($type_code, $this->_tmp[
'is_default'])) {
2554 if (isset($this->_tmp[
'type_formats']) && array_key_exists($type_code, $this->_tmp[
'type_formats'])) {
2555 $type_key = array_search($this->_tmp[
'type_formats'][$type_code], $customised);
2556 $type_code = $this->_tmp[
'type_formats'][$type_code];
2559 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAncestors($type_code);
2561 if (($type_key = array_search($type_code, $customised)) === FALSE) {
2562 foreach ($parents as $parent) {
2564 if (array_search($parent, $customised) !== FALSE) {
2565 $this->_tmp[
'type_formats'][$type_code] = $parent;
2566 $type_key = array_search($this->_tmp[
'type_formats'][$type_code], $customised);
2567 $type_code = $parent;
2572 if (isset($type_key) && $type_key !== FALSE) {
2579 if (is_null($bodycopy)) {
2580 if (!isset($this->_tmp[
'default_format_bc'])) {
2581 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->_tmp[
'type_folder_id'], SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'default_format');
2583 $this->_tmp[
'default_format_bc'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'],
'bodycopy');
2586 trigger_error(
'Cannot Find the Default Bodycopy');
2590 $bodycopy = $this->_tmp[
'default_format_bc'];
2595 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
2596 if (isset($this->_tmp[
'bc_keywords'][$bodycopy->id][$contextid])) {
2597 $bc_keywords = $this->_tmp[
'bc_keywords'][$bodycopy->id][$contextid];
2599 $bc_keywords = $bodycopy->getKeywords();
2600 $this->_tmp[
'bc_keywords'][$bodycopy->id][$contextid] = $bc_keywords;
2602 $keywords = Array();
2607 $context_bc_keywords = Array();
2608 $paint_layouts_to_resolve = Array();
2609 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
2616 foreach ($bc_keywords as $kw) {
2617 if (substr($kw, 0, strlen(
'asset_contents')) ==
'asset_contents') {
2618 $kw = parse_keyword($kw, $modifiers);
2619 $contextid = extract_context_modifier($modifiers);
2621 if (!in_array($kw, $bc_keywords)) {
2622 array_push($bc_keywords, $kw);
2626 if (array_key_exists($kw, $context_bc_keywords) === FALSE) {
2627 $context_bc_keywords[$kw] = Array();
2630 if ($contextid === NULL) {
2631 $context_bc_keywords[$kw][
'current'] = NULL;
2633 $context_bc_keywords[$kw][$contextid] = $all_contexts[$contextid][
'name'];
2639 if (substr($kw, 0, strlen(
'asset_contents_paint_')) ==
'asset_contents_paint_') {
2640 $paint_layouts_to_resolve[] = substr($kw, strlen(
'asset_contents_paint_'));
2651 if (in_array(
'asset_contents', $bc_keywords)) {
2652 foreach ($context_bc_keywords[
'asset_contents'] as $contextid => $context_name) {
2653 $kw =
'asset_contents';
2654 if ($context_name !== NULL) {
2655 $kw .=
'^context:'.$context_name;
2657 if (empty($asset)) {
2658 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2667 if (in_array(
'asset_contents_raw', $bc_keywords)) {
2668 foreach ($context_bc_keywords[
'asset_contents_raw'] as $contextid => $context_name) {
2669 $kw =
'asset_contents_raw';
2670 if ($context_name !== NULL) {
2671 $kw .=
'^context:'.$context_name;
2673 if (empty($asset)) {
2674 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2682 $this_needs_asset = FALSE;
2683 foreach ($bc_keywords as $keyword) {
2684 if (in_array($keyword, Array(
'asset_url',
'asset_name_linked',
'asset_short_name_linked')) && !SQ_ROLLBACK_VIEW) {
2687 if (!isset($this->_tmp[
'assets_info'][$assetid][substr($keyword, 6)])) {
2688 $this_needs_asset = TRUE;
2693 if ($this_needs_asset) {
2694 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
2695 if (is_null($asset))
return;
2696 foreach ($bc_keywords as $keyword) {
2697 $keywords[$keyword] = $asset->getKeywordReplacement($keyword);
2702 if (array_key_exists(
'asset_contents', $keywords)) {
2703 foreach ($context_bc_keywords[
'asset_contents'] as $contextid => $context_name) {
2704 $kw =
'asset_contents';
2705 if ($context_name !== NULL) {
2706 $kw .=
'^context:'.$context_name;
2715 foreach ($paint_layouts_to_resolve as $paint_layout) {
2716 $base_kw =
'asset_contents_paint_'.$paint_layout;
2717 foreach ($context_bc_keywords[$base_kw] as $contextid => $context_name) {
2719 if ($context_name !== NULL) {
2720 $kw .=
'^context:'.$context_name;
2730 if (array_key_exists(
'asset_contents_raw', $keywords)) {
2731 foreach ($context_bc_keywords[
'asset_contents_raw'] as $contextid => $context_name) {
2732 $kw =
'asset_contents_raw';
2733 if ($context_name !== NULL) {
2734 $kw .=
'^context:'.$context_name;
2743 $keywords[
'asset_url'] = array_get_index($this->_tmp[
'asset_urls'], $assetid,
'./?a='.$assetid);
2744 $keywords[
'asset_name_linked'] =
'<a href="'.$keywords[
'asset_url'].
'">'.htmlspecialchars($asset->name).
'</a>';
2745 $keywords[
'asset_short_name_linked'] =
'<a href="'.$keywords[
'asset_url'].
'">'.htmlspecialchars($asset->short_name).
'</a>';
2747 if (in_array(
'asset_lineage', $bc_keywords) || in_array(
'asset_lineage_linked', $bc_keywords)) {
2748 preg_match(
'/(http[s]?:\/\/)(.*)/', $keywords[
'asset_url'], $matches);
2749 $lineage_array = Array();
2750 if (isset($matches[2])) {
2751 $lineage_array = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromUrl(NULL, $matches[2]);
2755 $linked_lineage =
'';
2757 if (!empty($lineage_array)) {
2758 $show_root = $this->
attr(
'root_in_lineage');
2759 $show_self = $this->
attr(
'self_in_lineage');
2762 $served_by_apache = strpos($matches[2],
'/__data/') !== FALSE || (SQ_CONF_STATIC_ROOT_URL && strpos($matches[2], SQ_CONF_STATIC_ROOT_URL.
'/') !== FALSE);
2763 if (!$show_self && !$served_by_apache) {
2764 array_pop($lineage_array);
2766 foreach ($lineage_array as $lineage_item) {
2767 if ($first && !$show_root) {
2772 if (!$first && $lineage !=
'') {
2773 $lineage .= $this->
attr(
'lineage_seperator');
2774 $linked_lineage .= $this->
attr(
'lineage_seperator');
2776 $lineage .= $lineage_item[
'short_name'];
2777 $linked_lineage .=
'<a href="'.$lineage_item[
'protocol'].
'://'.$lineage_item[
'url'].
'">'.htmlspecialchars($lineage_item[
'short_name']).
'</a>';
2781 $keywords[
'asset_lineage'] = htmlspecialchars($lineage);
2782 $keywords[
'asset_lineage_linked'] = $linked_lineage;
2787 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
2790 $keywords = Array();
2791 foreach ($this->_tmp[
'assets_info'][$assetid] as $field => $value) {
2792 $keywords[
'asset_'.$field] = htmlspecialchars($value);
2794 $keywords[
'asset_url'] = array_get_index($this->_tmp[
'asset_urls'], $assetid,
'./?a='.$assetid);
2795 $keywords[
'asset_name_linked'] =
'<a href="'.$keywords[
'asset_url'].
'">'.$keywords[
'asset_name'].
'</a>';
2796 $keywords[
'asset_short_name_linked'] =
'<a href="'.$keywords[
'asset_url'].
'">'.$keywords[
'asset_short_name'].
'</a>';
2801 $group_keywords = preg_grep(
'/group[0-9]+.*/', $bc_keywords);
2802 foreach ($group_keywords as $group_keyword) {
2803 preg_match(
'/group([0-9]+)_(.*)/', $group_keyword, $matches);
2804 if (isset($this->_tmp[
'group_levels'][$matches[1] - 1])) {
2805 $parent_id = $this->_tmp[
'group_levels'][$matches[1] - 1];
2806 if (assert_valid_assetid($parent_id,
'', TRUE, FALSE)) {
2808 switch ($matches[2]) {
2810 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($parent_id, $assetid);
2811 $keywords[$group_keyword] = array_get_index($link,
'value',
'');
2824 $keywords[
'page_href'] = $this->
getHref();
2826 if ($this->
attr(
'group_by') ==
'letter') {
2827 $keywords[
'asset_position'] = $list_position;
2829 $keywords[
'asset_position'] = (array_get_index($this->_tmp,
'result_page', 1) - 1) * $this->
_getNumPerPage() + $list_position;
2832 if (($list_position % 2) == 0) {
2833 $keywords[
'asset_odd_even'] = translate(
'cms_listing_asset_position_even');
2835 $keywords[
'asset_odd_even'] = translate(
'cms_listing_asset_position_odd');
2839 $selections = $this->
attr(
'asset_selections');
2842 if (is_array($selections) && !empty($selections)) {
2844 foreach ($selections as $selection_name => $settings) {
2846 $buffering = in_array($selection_name.
'_asset_selection', $bc_keywords);
2855 $selection_options = array_get_index($settings,
'options', $selection_defaults[
'options']);
2856 $selection_restrict = array_get_index($selection_options,
'restrict_range', $selection_defaults[
'options'][
'restrict_range']);
2857 $selection_restrict_enable = array_get_index($selection_restrict,
'enable', $selection_defaults[
'options'][
'restrict_range'][
'enable']);
2858 $selection_restrict_min = array_get_index($selection_restrict,
'min', $selection_defaults[
'options'][
'restrict_range'][
'min']);
2859 $selection_restrict_max = array_get_index($selection_restrict,
'max', $selection_defaults[
'options'][
'restrict_range'][
'max']);
2860 $selection_allow_negative = array_get_index($selection_options,
'allow_negative', $selection_defaults[
'options'][
'allow_negative']);
2861 $selection_allow_multiple = array_get_index($selection_options,
'allow_multiple', $selection_defaults[
'options'][
'allow_multiple']);
2866 if ($selection_restrict_enable) {
2867 $selection_value = ($selection_restrict_min > $selection_value ? $selection_restrict_min : $selection_value);
2870 switch (array_get_index($settings,
'type', $selection_defaults[
'type'])) {
2872 $selection_name_field = $selection_prefix.
'['.$assetid.
']';
2873 $selection_id = make_valid_html_id($selection_prefix.
'_'.$assetid,
'_');
2876 if ($selection_restrict_enable) {
2877 int_text_box($selection_name_field, $selection_value, $selection_allow_negative, 3, $selection_restrict_min, $selection_restrict_max,
'', FALSE, FALSE,
'id="'.$selection_id.
'"');
2879 int_text_box($selection_name_field, $selection_value, $selection_allow_negative, 3, NULL, NULL,
'', FALSE, FALSE,
'id="'.$selection_id.
'"');
2885 $selection_name_field = $selection_prefix.
'['.$assetid.
']';
2886 $selection_id = make_valid_html_id($selection_prefix.
'_'.$assetid,
'_');
2890 $selection_list = Array();
2891 if (!empty($settings[
'options'][
'restrict_range'][
'enable'])) {
2892 for ($ii = $selection_restrict_min; $ii <= $selection_restrict_max; $ii++) {
2893 $selection_list[$ii] = $ii;
2896 $selection_list = Array(
'0');
2900 if (!isset($selection_list[$selection_value])) {
2901 $selection_value = reset($selection_list);
2905 combo_box($selection_name_field, $selection_list, $selection_allow_multiple, $selection_value, 0,
'id="'.$selection_id.
'"');
2911 if ($selection_allow_multiple) {
2912 $selection_name_field = $selection_prefix.
'['.$assetid.
']';
2913 $selection_id = make_valid_html_id($selection_prefix.
'_'.$assetid,
'_');
2916 check_box($selection_name_field,
'1', ($selection_value > 0 ? TRUE : FALSE),
"sq_listing_check_state(this, '".$selection_prefix.
"')",
'id="'.$selection_id.
'"');
2922 if (empty($this->_tmp[
'asset_selection_checkbox_flag'][$selection_name])) {
2923 hidden_field(
'selection_flag_'.$selection_prefix,
'1');
2924 $this->_tmp[
'asset_selection_checkbox_flag'][$selection_name] = TRUE;
2928 $selection_name_field = $selection_prefix;
2929 $selection_id = make_valid_html_id($selection_prefix.
'_'.$assetid,
'_');
2932 radio_button($selection_name_field, $assetid, ($selection_value == $assetid ? TRUE : FALSE),
'',
'id="'.$selection_id.
'"');
2940 $keywords[$selection_name.
'_asset_selection'] = ob_get_clean();
2942 $keywords[$selection_name.
'_selection_name'] = $selection_name_field;
2943 $keywords[$selection_name.
'_selection_id'] = $selection_id;
2948 $keywords[
'asset_assetid'] = $assetid;
2951 $keywords[
'result_no'] =& $keywords[
'asset_position'];
2956 foreach ($keywords as $kw => $val) {
2957 if (substr($kw, 0, strlen(
'asset_contents')) ==
'asset_contents') {
2958 $plain_keyword = parse_keyword($kw, $modifiers);
2959 if (!empty($modifiers)) {
2963 $contextid = extract_context_modifier($modifiers);
2965 if ($contextid !== NULL) {
2966 $plain_keyword .=
'^context:'.$all_contexts[$contextid][
'name'];
2970 $keywords[$kw] = $keywords[$plain_keyword];
2973 apply_keyword_modifiers($keywords[$kw], $modifiers, Array(
'assetid' => $assetid,
'replacements' => $keywords));
2978 $bodycopy->setKeywordReplacements($keywords);
2979 $bodycopy->printBody();
2981 if ($prev_list_current_asset_id) {
2982 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'list_current_asset_id'] = $prev_list_current_asset_id;
2984 unset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'list_current_asset_id']);
3008 if ($asset->id !== $this->id) {
3010 if ($contextid !== NULL) {
3011 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
3012 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
3017 $replacement = ob_get_clean();
3020 if ($contextid !== NULL) {
3021 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
3023 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
3028 return $replacement;
3050 if ($asset->id !== $this->id) {
3052 if ($contextid !== NULL) {
3053 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
3054 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
3059 $replacement = ob_get_clean();
3062 if ($contextid !== NULL) {
3063 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
3065 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
3070 return $replacement;
3101 if ($asset->id !== $this->id) {
3103 if (($contextid !== NULL) && ($contextid !==
'current')) {
3104 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
3105 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->id);
3109 if (!assert_valid_assetid($paint_layout,
'Not valid assetid', TRUE, FALSE)) {
3110 $paint_layout = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL(preg_replace(
'/^[^:]*:\/\//',
'', $asset->getUrl()),
'paint_layout::user::'.$paint_layout);
3113 if (!empty($paint_layout) && $GLOBALS[
'SQ_SYSTEM']->am->assetExists($paint_layout)) {
3116 $replacement = ob_get_clean();
3120 if (($contextid !== NULL) && ($contextid !==
'current')) {
3121 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
3123 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
3128 return $replacement;
3143 if (!isset($this->_tmp[
'type_format_bcs'][$type_code])) {
3144 $this->_tmp[
'type_format_bcs'][$type_code] = NULL;
3145 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->_tmp[
'type_folder_id'], SQ_LINK_TYPE_2,
'bodycopy', TRUE, $type_code);
3147 $this->_tmp[
'type_format_bcs'][$type_code] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'],
'bodycopy');
3149 $this->_tmp[
'is_default'][] = $type_code;
3152 return $this->_tmp[
'type_format_bcs'][$type_code];
3167 return str_replace(
' ',
'_', $selection_name);
3180 return $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfoFields();
3198 $frontend_asset =& $GLOBALS[
'SQ_SYSTEM']->frontend_asset;
3199 $frontend_asset_id = (!is_null($frontend_asset)) ? $frontend_asset->id : NULL;
3200 if ($reload || (!empty($GLOBALS[
'SQ_SYSTEM']->frontend_asset) && !isset($this->_tmp[
'root_nodes_'.$frontend_asset_id]))) {
3201 $root_asset_ids = Array();
3202 $root_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'', FALSE,
'major',
'root');
3204 foreach ($root_links as $root_link) {
3205 if (strstr($root_link[
'minorid'],
':') !== FALSE) {
3206 $root_asset_ids[] = $root_link[
'minorid'];
3208 $root_asset_ids[] = (int)$root_link[
'minorid'];
3213 $raw_dynamic_root_nodes = $parameter_map->getParameterValue(
'root_node');
3214 $empty_dynamic_roots = TRUE;
3217 if (!empty($raw_dynamic_root_nodes)) {
3219 $dynamic_root_nodes = Array();
3222 if (!is_array($raw_dynamic_root_nodes)) {
3223 $raw_dynamic_root_nodes = explode(
',', $raw_dynamic_root_nodes);
3226 foreach ($raw_dynamic_root_nodes as $dynamic_root) {
3227 if (!strlen($dynamic_root))
continue;
3229 $dynamic_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($dynamic_root);
3233 if (in_array($dynamic_root, $root_asset_ids)) {
3234 $dynamic_root_nodes[] = $dynamic_root;
3238 $matching_root_ids = array_intersect(array_keys($dynamic_parents), $root_asset_ids);
3239 if (empty($matching_root_ids)) {
3240 trigger_localised_error(
'CMS0020', E_USER_WARNING, $dynamic_root, $this->
id);
3242 $dynamic_root_nodes[] = $dynamic_root;
3247 if (!empty($dynamic_root_nodes)) {
3248 $root_asset_ids = $dynamic_root_nodes;
3249 $empty_dynamic_roots = FALSE;
3253 $dynamic_parameters = $parameter_map->getParameters();
3254 if (in_array(
'root_node', $dynamic_parameters) && $empty_dynamic_roots && $this->
attr(
'dynamic_root_option') ==
'empty_result') {
3255 $root_asset_ids = Array();
3256 }
else if (empty($root_asset_ids)) {
3257 $root_asset_ids = Array($this->
id);
3259 $this->_tmp[
'root_nodes_'.$frontend_asset_id] = $root_asset_ids;
3263 return isset($this->_tmp[
'root_nodes_'.$frontend_asset_id]) ? $this->_tmp[
'root_nodes_'.$frontend_asset_id] : NULL;
3297 $field_name = $prefix.
'_sort_direction';
3299 $sort_order = array_get_index($_REQUEST, $field_name);
3300 switch ($sort_order) {
3309 $result = $this->
attr(
'reverse_sort');
3332 if (!empty($field_name)) {
3333 $this->_tmp[
'used_form_fields'][] = $field_name;
3350 return array_get_index($this->_tmp,
'used_form_fields', Array());
3391 $field_name = $prefix.
'_sort_by';
3393 $default_sort_by = $this->
attr(
'default_sort_by');
3395 $sort_by = array_get_index($_REQUEST, $field_name, $default_sort_by);
3396 $sort_by_list = $this->
attr(
'sort_by');
3397 if (!isset($sort_by_list[$sort_by])) {
3398 $sort_by = $default_sort_by;
3400 return array_get_index($sort_by_list, $sort_by, Array());
3425 $min_depth = $this->
attr(
'min_depth');
3426 if ($min_depth ==
'') $min_depth = NULL;
3427 $max_depth = $this->
attr(
'max_depth');
3428 if ($max_depth ==
'') $max_depth = NULL;
3433 if (empty($assetids) || empty($group_levels)) {
3438 $group_levels = array_reverse($group_levels);
3440 $asset_groups = Array();
3441 foreach ($assetids as $assetid => $group_datas) {
3442 $asset_groups[] = Array(
'assetid' => $assetid);
3446 $last_parent_asset = FALSE;
3447 $limit_array = Array();
3449 foreach ($group_levels as $group_key => $group_level) {
3450 array_unshift($limit_array, array_get_index($group_level,
'max_children', NULL));
3451 $new_asset_groups = Array();
3454 if (!is_null($min_depth)) {
3455 $min_depth -= 1 * ($this->
attr(
'direction') ==
'up' ? -1 : 1);
3457 if (!is_null($max_depth)) {
3458 $max_depth -= 1 * ($this->
attr(
'direction') ==
'up' ? -1 : 1);
3461 foreach ($asset_groups as $key => $group_data) {
3462 $assetid = $group_data[
'assetid'];
3464 if ($last_parent_asset === FALSE) {
3465 $current_parent = $assetid;
3467 $current_parent = $group_data[
'group'][$last_parent_asset];
3469 switch ($group_level[
'group_type']) {
3470 case 'parent_asset':
3471 $restrict_types = array_get_index($group_level,
'restrict_types', Array());
3472 $direct_parent_only = array_get_index($group_level,
'direct_parent_only', FALSE);
3478 if ($direct_parent_only && isset($this->_tmp[
'direct_parent_grouping'][$current_parent])) {
3479 $value = $this->_tmp[
'direct_parent_grouping'][$current_parent];
3487 if (!is_null($min_depth) || !is_null($max_depth)) {
3489 if (!isset($this->_tmp[
'grouping_treeids'])) {
3490 $this->_tmp[
'grouping_treeids'] = array();
3493 foreach ($value as $key => $parent_assetid) {
3501 if (!isset($this->_tmp[
'grouping_treeids'][$parent_assetid])) {
3502 if ($this->
attr(
'direction') ==
'down') {
3504 $this->_tmp[
'grouping_treeids'][$parent_assetid] = $GLOBALS[
'SQ_SYSTEM']->am->getParents($parent_assetid,
'', FALSE, NULL, NULL, TRUE, $min_depth, $max_depth);
3506 $this->_tmp[
'grouping_treeids'][$parent_assetid] = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($parent_assetid,
'', FALSE, NULL, NULL, NULL, TRUE, $min_depth, $max_depth);
3509 $parents = $this->_tmp[
'grouping_treeids'][$parent_assetid];
3510 $intersection = array_intersect(array_keys($parents), $root_nodes);
3511 if (empty($intersection) && !in_array($parent_assetid, $root_nodes)) unset($value[$key]);
3519 $metadata_field = NULL;
3520 $metadate_field_id = NULL;
3521 if (!empty($group_level[
'metadata_field'])) {
3522 $metadata_field_id = $group_level[
'metadata_field'];
3524 if (!empty($metadata_field_id)) {
3525 $metadata_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($metadata_field_id);
3528 $presentation_value = FALSE;
3529 if (!empty($group_level[
'metadata_sort_type'])) {
3530 if ($group_level[
'metadata_sort_type'] ===
'presentation') {
3531 $presentation_value = TRUE;
3536 if (!is_null($metadata_field)) {
3539 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3542 $parent_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_parent);
3543 if (!is_null($parent_asset)) {
3544 $value = $mm->getMetadataValueByAssetid($current_parent, $metadata_field_id, TRUE, $presentation_value);
3545 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($parent_asset);
3550 case 'standard_asset':
3551 if (!isset($this->_tmp[
'assets_info'][$current_parent])) {
3552 $this->_tmp[
'assets_info'][$current_parent] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($current_parent));
3554 if (!empty($this->_tmp[
'assets_info'][$current_parent])) {
3555 $asset_info = $this->_tmp[
'assets_info'][$current_parent];
3557 $standard_asset_field = $group_level[
'field'];
3558 switch ($standard_asset_field) {
3560 $value = $current_parent;
3564 $value = get_status_description($asset_info[
'status']);
3568 $value = $asset_info[$standard_asset_field];
3575 $keyword = $group_level[
'keyword'];
3576 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_parent);
3577 if(!is_null($asset)) {
3578 $value = $asset->getKeywordReplacement($keyword);
3590 if (!is_array($value)) {
3591 $group_data[
'group'][$group_key] = $value;
3592 $new_asset_groups[] = $group_data;
3594 foreach ($value as $sub_value) {
3595 $group_data[
'group'][$group_key] = $sub_value;
3596 $new_asset_groups[] = $group_data;
3602 $asset_groups = $new_asset_groups;
3604 if ($group_level[
'group_type'] ==
'parent_asset') {
3605 $last_parent_asset = $group_key;
3612 $group_keys = array_keys($group_levels);
3615 foreach ($asset_groups as $group_data) {
3617 foreach (array_reverse($group_keys) as $group_key) {
3618 $key = $group_data[
'group'][$group_key];
3621 $base =& $base[$key];
3623 $base[$group_data[
'assetid']] = $assetids[$group_data[
'assetid']];
3629 unset($this->_tmp[
'root_node_treeids']);
3653 $num = array_shift($limit_array);
3655 foreach ($results as $key => $val) {
3656 if (!is_null($num) && ($num >= 1)) {
3657 while (count($results[$key]) > $num) {
3658 array_pop($results[$key]);
3662 if (!empty($limit_array)) {
3688 $proxy_settings = $this->
attr(
'proxy_types');
3689 if (!empty($proxy_settings)) {
3690 if (!empty($this->_tmp[
'proxy_grouping'][$child_assetid])) {
3691 foreach ($this->_tmp[
'proxy_grouping'][$child_assetid] as $parent_type_code => $parent_assetids) {
3693 if (in_array($parent_type_code, $restrict_types[
'type_code'])) {
3694 return array_values(array_unique($parent_assetids));
3700 $parent_link_assetids = Array();
3703 if (empty($root_nodes) || (strpos($child_assetid,
':') !== FALSE) || ($this->
attr(
'direction') ==
'up')) {
3704 $parent_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($child_assetid, $this->
attr(
'link_types'),
'', TRUE,
'minor');
3705 $parent_link_assetids = Array();
3706 foreach ($parent_links as $parent_link) {
3707 $parent_link_assetids[] = $parent_link[
'majorid'];
3713 if (empty($parent_link_assetids) && strpos($child_assetid,
':') !== FALSE && $direct_parent_only) {
3714 $id_parts = explode(
':', $child_assetid);
3715 $parent_link_assetids[] = $id_parts[0];
3718 return $parent_link_assetids;
3736 if (empty($results))
return $results;
3738 $am = $GLOBALS[
'SQ_SYSTEM']->am;
3739 $proxy_settings = $this->
attr(
'proxy_types');
3740 if (empty($proxy_settings)) {
3744 $new_results = $results;
3745 return $new_results;
3748 $collated_types = Array();
3749 $result_types = $am->getAssetInfo(array_keys($results),
'asset', FALSE,
'type_code');
3750 foreach ($result_types as $result_assetid => $result_type) {
3751 $collated_types[$result_type][] = $result_assetid;
3754 $new_results = Array();
3755 $this->_tmp[
'proxy_grouping'] = Array();
3756 foreach ($collated_types as $result_type => $result_assetids) {
3757 if (isset($proxy_settings[$result_type])) {
3758 if (empty($proxy_settings[$result_type])) {
3762 $converted_types = Array();
3763 foreach ($proxy_settings[$result_type] as $type_code => $inherit) {
3765 $converted_types = array_merge($am->getTypeDescendants($type_code, TRUE), $converted_types);
3767 $converted_types[] = $type_code;
3771 $children = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($result_assetids, SQ_SC_LINK_SIGNIFICANT, $converted_types);
3773 foreach ($children as $orig_assetid => $links) {
3774 foreach ($links as $link) {
3776 $new_results[$link[
'minorid']] = $results[$orig_assetid];
3781 $this->_tmp[
'proxy_grouping'][$link[
'minorid']][$result_type][] = $orig_assetid;
3790 return $new_results;
3809 $groupable_parents = Array();
3810 if (!isset($this->_tmp[
'root_node_treeids'])) {
3811 foreach ($GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids($root_nodes) as $aid => $treeids) {
3812 $this->_tmp[
'root_node_treeids'][$aid] = reset($treeids);
3815 $lineages = $GLOBALS[
'SQ_SYSTEM']->am->getLinkLineages($child_assetid, 0, $this->_tmp[
'root_node_treeids'],
'type_code');
3817 foreach ($lineages as $lineage_info) {
3820 if ($direct_parent_only && !empty($lineage_info[
'lineage'])) {
3821 $all_assetids = array_keys($lineage_info[
'lineage']);
3822 $direct_parent_assetid = array_pop($all_assetids);
3823 $direct_parent_type = array_pop($lineage_info[
'lineage']);
3825 $lineage_info[
'lineage'] = Array($direct_parent_assetid => $direct_parent_type);
3829 if (!($lineage_info[
'link_type'] & $this->
attr(
'link_types'))) {
3834 if (!isset($restrict_types[
'type_code']) || empty($restrict_types[
'type_code'])) {
3835 $groupable_parents[] = array_shift(array_keys($lineage_info[
'lineage']));
3839 $lineage = array_reverse($lineage_info[
'lineage'], TRUE);
3842 foreach ($lineage as $parentid => $type_code) {
3843 if (in_array($type_code, $restrict_types[
'type_code'])) {
3846 $inherit_vals = $restrict_types[
'inherit'];
3847 foreach ($restrict_types[
'type_code'] as $type) {
3848 $inherit = array_shift($inherit_vals);
3849 if (!isset($this->_tmp[
'type_decendants'][$type])) {
3850 $this->_tmp[
'type_decendants'][$type] = $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($type, TRUE);
3852 if ($inherit && in_array($type_code, $this->_tmp[
'type_decendants'][$type])) {
3861 $groupable_parents[] = $parentid;
3867 return array_unique($groupable_parents);
3890 if (empty($assetids))
return;
3893 $group_type = array_shift($group_levels);
3896 switch ($group_type[
'group_type']) {
3897 case 'parent_asset':
3900 if (!empty($group_type[
'sorting_metadata_field'])) {
3901 $sorting_metadata_field_id = $group_type[
'sorting_metadata_field'];
3902 if (!empty($sorting_metadata_field_id)) {
3903 $sorting_metadata_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($sorting_metadata_field_id);
3905 if (!is_null($sorting_metadata_field)) {
3908 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3910 $group_order = Array();
3912 $presentation_value = FALSE;
3913 if (!empty($group_type[
'metadata_sort_type'])) {
3914 if ($group_type[
'metadata_sort_type'] ===
'presentation') {
3915 $presentation_value = TRUE;
3919 foreach ($results as $key => $arrayInfo) {
3920 $group_order[$key] = $mm->getMetadataValueByAssetid($key, $sorting_metadata_field_id, TRUE, $presentation_value);
3924 $group_order = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($results),
'asset', FALSE,array_get_index($group_type,
'sort_by',
'assetid'));
3928 if (array_get_index($group_type,
'sort_order',
'asc') ==
'asc') {
3929 asort($group_order);
3931 arsort($group_order);
3933 $group_results = Array();
3934 foreach (array_keys($group_order) as $assetid) {
3935 $group_results[$assetid] =& $results[$assetid];
3937 $results = $group_results;
3942 $group_order = Array();
3943 if (!empty($group_type[
'metadata_field'])) {
3944 $metadata_field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($group_type[
'metadata_field']);
3945 if(!is_null($metadata_field)) {
3947 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
3950 $presentation_value = FALSE;
3951 if (!empty($group_type[
'metadata_sort_type'])) {
3952 if ($group_type[
'metadata_sort_type'] ===
'presentation') {
3953 $presentation_value = TRUE;
3957 foreach ($results as $key => $arrayInfo) {
3960 if (method_exists($metadata_field,
'getKeyFromValue') && !$presentation_value && $metadata_field->attr(
'visible_part') ===
'key') {
3962 $raw_value = $metadata_field->getKeyFromValue($key);
3963 $group_order[$raw_value] = $arrayInfo;
3964 unset($results[$key]);
3969 $group_order = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($results),
'asset', FALSE,array_get_index($group_type,
'sort_by',
'assetid'));
3973 if (!empty($group_order) )$results = $group_order;
3975 case 'standard_asset':
3979 if (array_get_index($group_type,
'sort_order',
'asc') ==
'asc') {
3990 if (count($group_levels) > 0) {
3991 foreach ($results as $index => $group) {
3992 $this->
sortGroups($group_levels, $group, $results[$index]);
4009 $group_folder = $this->
getFolder(
'group_formats');
4010 $groups = $this->
attr(
'asset_grouping');
4011 if (empty($groups))
return TRUE;
4016 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
4017 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
4018 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
4021 foreach ($groups as $group) {
4023 $format_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($group[
'format_assetid']);
4024 if ($format_asset) {
4025 $format_asset->setAttrValue(
'name',
'Group Level '.$i.
' Format');
4026 $format_asset->saveAttributes();
4032 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
4033 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
4034 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
4082 'allow_multiple' => 0,
4083 'allow_negative' => 0,
4084 'restrict_range' => Array(
4106 'target_asset' => Array(
4130 for (reset($array); NULL !== ($k = key($array)); next($array)) {
4132 if (is_array($el) && (is_null($limit) || ($limit > 0))) {
4152 if (!isset($this->_tmp[
'position_formats'])) {
4153 $this->_tmp[
'position_formats'] = Array();
4155 $position_folder = $this->
getFolder(
'position_formats');
4156 $format_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($position_folder->id, SQ_LINK_TYPE_2,
'bodycopy', TRUE);
4157 foreach ($format_links as $link_data) {
4158 $position = substr($link_data[
'value'], 9);
4159 $this->_tmp[
'position_formats'][$position] = $link_data[
'minorid'];
4163 return $this->_tmp[
'position_formats'];
4183 $vars[
'keywords'] = isset($vars[
'keywords']) ? $vars[
'keywords'] : Array();
4185 $parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', TRUE);
4186 $parent_folders = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'folder', TRUE);
4191 $group_folder = $this->
getFolder(
'group_formats');
4192 $position_folder = $this->
getFolder(
'position_formats');
4193 $type_folder = $this->
getFolder(
'type_formats');
4195 $keywords = Array();
4196 if (!is_null($group_folder) && in_array($group_folder->id, array_keys($parent_folders))) {
4200 }
else if (!is_null($position_folder) && in_array($position_folder->id, array_keys($parent_folders))) {
4204 }
else if (!is_null($type_folder) && in_array($type_folder->id, array_keys($parent_folders))) {
4206 $type_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($type_folder->id, SQ_LINK_TYPE_2,
'bodycopy');
4207 $type_codes = Array();
4208 foreach ($type_links as $link_info) {
4209 if (isset($parents[$link_info[
'minorid']])) {
4210 $type_codes[] = $link_info[
'value'];
4215 if ((count($type_codes) == 1) && ($type_codes[0] !=
'default_format')) {
4216 $type_name = $type_codes[0];
4225 $vars[
'keywords'] = array_merge($vars[
'keywords'], $keywords);
4244 if (!empty($type)) {
4245 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type);
4246 $dummy_asset =
new $type();
4247 $keywords += $dummy_asset->getAvailableKeywords();
4248 unset($dummy_asset);
4269 $keywords[
'asset_lineage'] = translate(
'asset_lineage');
4270 $keywords[
'asset_lineage_linked'] = translate(
'asset_lineage_linked');
4271 $keywords[
'asset_contents'] = translate(
'cms_listing_asset_contents');
4272 $keywords[
'asset_contents_paint_'] = translate(
'cms_listing_asset_contents_paint');
4273 $keywords[
'asset_name_linked'] = translate(
'cms_listing_asset_name_linked');
4274 $keywords[
'asset_short_name_linked'] = translate(
'cms_listing_asset_short_name_linked');
4275 $keywords[
'asset_position'] = translate(
'cms_listing_asset_position');
4276 $keywords[
'asset_odd_even'] = translate(
'cms_listing_asset_position_odd_even');
4277 $keywords[
'root_nodes'] = translate(
'cms_listing_keyword_root_nodes');
4278 $keywords[
'asset_contents_raw'] = translate(
'cms_listing_asset_contents_raw');
4281 $selections = $this->
attr(
'asset_selections');
4282 if (is_array($selections) && !empty($selections)) {
4283 foreach ($selections as $name => $settings) {
4284 $keywords[$name.
'_asset_selection'] = translate(
'cms_listing_keyword_asset_selection', $name);
4308 $keywords = parent::getAvailableKeywords();
4329 $GLOBALS[
'SQ_SYSTEM']->lm->includeAssetStrings(
'page_asset_listing');
4331 $keywords[
'sort_by'] = translate(
'cms_listing_keyword_sort_by');
4332 $keywords[
'sort_order'] = translate(
'cms_listing_keyword_sort_order');
4333 $keywords[
'reset_button'] = translate(
'cms_listing_keyword_reset_button');
4334 $keywords[
'submit_button'] = translate(
'cms_listing_keyword_submit_button');
4335 $keywords[
'root_nodes'] = translate(
'cms_listing_keyword_root_nodes');
4337 $keywords[
'asset_listing'] = translate(
'cms_listing_asset_listing');
4338 $keywords[
'previous_page'] = translate(
'cms_listing_previous_page_link');
4339 $keywords[
'previous_page_href'] = translate(
'cms_listing_previous_page_link_href');
4340 $keywords[
'next_page'] = translate(
'cms_listing_next_page_link');
4341 $keywords[
'next_page_href'] = translate(
'cms_listing_next_page_link_href');
4343 $keywords[
'page_list'] = translate(
'cms_listing_page_list');
4344 if ($this->
attr(
'group_by') ==
'letter') {
4345 $keywords[
'page_list_without_unused'] = translate(
'cms_listing_page_list_without_unused');
4347 $keywords[
'page_list_X'] = translate(
'cms_listing_page_list_sliding');
4349 $keywords[
'page_number'] = translate(
'cms_listing_page_number');
4350 $keywords[
'asset_count'] = translate(
'cms_listing_asset_count');
4351 $keywords[
'page_asset_count'] = translate(
'cms_listing_page_asset_count');
4352 $keywords[
'total_pages'] = translate(
'cms_listing_total_pages');
4353 $keywords[
'first_asset_position'] = translate(
'cms_listing_first_asset_position');
4354 $keywords[
'last_asset_position'] = translate(
'cms_listing_last_asset_position');
4355 $keywords[
'unique_asset_count'] = translate(
'cms_listing_unique_asset_count');
4356 $keywords[
'structured_root_node'] = translate(
'cms_listing_structured_root_node');
4358 $keywords[
'select_all_js_code'] =
'Select All Script Code';
4360 $selections = $this->
attr(
'asset_selections');
4361 if (is_array($selections) && !empty($selections)) {
4362 foreach ($selections as $name => $settings) {
4363 if (array_get_index($settings,
'type',
'') ==
'radio' && !empty($settings[
'options'][
'allow_multiple'])) {
4364 $keywords[$name.
'_check_all'] = translate(
'cms_listing_asset_selection_check_all', $name);
4369 $targets = $this->
attr(
'asset_targets');
4370 if (is_array($targets) && !empty($targets)) {
4371 foreach ($targets as $name => $settings) {
4372 $keywords[$name.
'_asset_target'] = translate(
'cms_listing_asset_target_button', $name);
4392 $keywords[
'asset_lineage'] = translate(
'asset_lineage');
4393 $keywords[
'asset_lineage_linked'] = translate(
'asset_lineage_linked');
4394 $keywords[
'asset_contents'] = translate(
'cms_listing_asset_contents');
4395 $keywords[
'asset_name_linked'] = translate(
'cms_listing_asset_name_linked');
4396 $keywords[
'asset_short_name_linked'] = translate(
'cms_listing_asset_short_name_linked');
4397 $keywords[
'asset_position'] = translate(
'cms_listing_asset_position');
4398 $keywords[
'root_nodes'] = translate(
'cms_listing_keyword_root_nodes');
4402 $selections = $this->
attr(
'asset_selections');
4403 if (is_array($selections) && !empty($selections)) {
4404 foreach ($selections as $name => $settings) {
4405 $keywords[$name.
'_asset_selection'] = translate(
'cms_listing_keyword_asset_selection', $name);
4422 $fake_asset =
new Asset();
4423 $keywords = $fake_asset->getAvailableKeywords();
4424 foreach ($keywords as $key =>$keyword) {
4425 $key1 = substr_replace($key,
'parent', 0, 5);
4426 $keywords[$key1] = $keywords[$key];
4427 unset($keywords[$key]);
4429 $keywords[
'group_listing'] = translate(
'cms_listing_group_listing');
4430 $keywords[
'group_name'] = translate(
'cms_listing_group_name');
4431 $keywords[
'group_name_linked'] = translate(
'cms_listing_group_name_linked');
4432 $keywords[
'parent_contents'] = translate(
'cms_listing_parent_contents');
4433 $keywords[
'parent_contents_raw'] = translate(
'cms_listing_parent_contents_raw');
4434 $keywords[
'group_immed_child_group_count'] = translate(
'cms_listing_group_immed_child_group_count');
4435 $keywords[
'group_total_child_asset_count'] = translate(
'cms_listing_group_total_child_asset_count');
4437 $selections = $this->
attr(
'asset_selections');
4438 if (is_array($selections) && !empty($selections)) {
4439 foreach ($selections as $name => $settings) {
4440 if (array_get_index($settings,
'type',
'') ==
'radio' && !empty($settings[
'options'][
'allow_multiple'])) {
4441 $keywords[$name.
'_check_all_in_group'] = translate(
'cms_listing_asset_selection_check_all_in_group', $name);
4472 if (empty($original_keyword))
return '';
4473 $keyword = parse_keyword($original_keyword, $modifiers);
4477 if (preg_match(
'/^(.*)(_asset_target)$/', $keyword, $matches)) {
4478 if (isset($matches[1]) && isset($matches[2])) {
4479 $args = $matches[1];
4480 $keyword_stem = $matches[2];
4485 if (!empty($keyword_stem) && !empty($args)) {
4486 $func_name =
'get'.ucwords_no_space($keyword_stem).
'KeywordReplacement';
4487 if (method_exists($this, $func_name)) {
4488 $replacement = $this->$func_name($args);
4489 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
4490 return $replacement;
4494 $replacement = parent::getKeywordReplacement($keyword);
4496 if ($replacement ==
'%'.$keyword.
'%' && empty($modifiers)) {
4497 return $replacement;
4498 }
else if($replacement ==
'%'.$keyword.
'%' && !empty($modifiers)) {
4499 return '%'.$original_keyword.
'%';
4502 if (!is_null($replacement)) {
4503 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
4505 return $replacement;
4527 $replacements = Array();
4529 $selections = $this->
attr(
'asset_selections');
4532 foreach ($selections as $selection_name => $settings) {
4534 if (!in_array($selection_name.
'_check_all', $keywords)) {
4540 $selection_options = array_get_index($settings,
'options', $selection_defaults[
'options']);
4541 $selection_allow_multiple = array_get_index($selection_options,
'allow_multiple', $selection_defaults[
'options'][
'allow_multiple']);
4544 if ((array_get_index($settings,
'type', $selection_defaults[
'type']) ==
'radio') && $selection_allow_multiple) {
4547 $group_cb_id =
'all';
4551 $replacements[$selection_name.
'_check_all'] = ob_get_clean();
4552 $replacements[$selection_name.
'_selection_id'] = $control_name;
4554 $replacements[$selection_name.
'_check_all'] =
'';
4558 return $replacements;
4574 $field_name = $prefix.
'_sort_by';
4577 $default_sort_by = $this->
attr(
'default_sort_by');
4578 $sort_by = array_get_index($_REQUEST, $field_name, $default_sort_by);
4580 $sort_by_list = $this->
attr(
'sort_by');
4581 if (!isset($sort_by_list[$sort_by])) {
4582 $sort_by = $default_sort_by;
4586 foreach ($sort_by_list as $key => $value) {
4587 $options[$key] = $value[
'name'];
4591 combo_box($field_name, $options, FALSE, $sort_by);
4592 return ob_get_clean();
4606 $field_name = $prefix.
'_sort_direction';
4610 '0' => $this->
attr(
'sort_direction_asc_text'),
4611 '1' => $this->
attr(
'sort_direction_desc_text'),
4615 combo_box($field_name, $options, FALSE, (
int)$this->
isDescending());
4616 return ob_get_clean();
4630 $field_name = $prefix.
'_submit_button';
4633 $button_text = $this->
attr(
'submit_button_text');
4636 submit_button($field_name, $button_text);
4637 return ob_get_clean();
4651 $field_name = $prefix.
'_reset_button';
4654 $button_text = $this->
attr(
'reset_button_text');
4657 reset_button($field_name, $button_text);
4658 return ob_get_clean();
4671 if (SQ_IN_BACKEND || SQ_IN_LIMBO) {
4676 return implode(
',', $root_nodes);
4691 $targets = $this->
attr(
'asset_targets');
4693 $field_name = $prefix.
'_'.$name.
'_asset_target';
4696 if (isset($targets[$name])) {
4698 $button_text = array_get_index($targets[$name],
'label', $defaults[
'label']);
4702 $target_url = array_get_index($targets[$name],
'target_url', $defaults[
'target_url']);
4704 $target = $target_url;
4706 $target_asset = array_get_index($targets[$name],
'target_asset', $defaults[
'target_asset']);
4707 $target_assetid = array_get_index($target_asset,
'assetid', $defaults[
'target_asset'][
'assetid']);
4708 if ($GLOBALS[
'SQ_SYSTEM']->am->assetExists($target_assetid)) {
4709 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($target_assetid);
4710 $target = $asset->getURL();
4711 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($target_assetid);
4715 if (!is_null($target)) {
4717 submit_button($field_name, $button_text,
"document.getElementById('".$this->
getPrefix().
"').action = '".$target.
"';");
4718 return ob_get_clean();
4735 $options = $this->
attr(
'structured_dropdown_options');
4736 if (empty($options[
'root_node']))
return '';
4738 if (!empty($options[
'name'])) {
4743 $pass_codes = array_keys($options[
'asset_types']);
4744 foreach ($options[
'asset_types'] as $code => $inherit) {
4745 if ($inherit == 1) {
4746 $pass_codes += $GLOBALS[
'SQ_SYSTEM']->am->getTypeDescendants($code);
4749 $selected = (isset($_REQUEST[$options[
'name']])) ? Array($_REQUEST[$options[
'name']]) : Array();
4751 if (isset($selected[0]) && is_array($selected[0])) {
4752 $selected = $selected[0];
4756 structured_drop_down($options[
'name'], $options[
'root_node'], $pass_codes, $selected, $options[
'width'], $options[
'height'], $options[
'max_depth'], $this->
attr(
'check_boxes') == 2 ? TRUE : FALSE, $options[
'seperator'], TRUE, $options[
'all_text'], $this->
attr(
'check_boxes'));
4757 $replacement = ob_get_contents();
4759 return $replacement;
4772 return array_get_index($this->_tmp,
'js_relation_code',
'');
4793 for (reset($todo); NULL !== ($k = key($todo)); next($todo)) {
4795 if (is_array($el) && (is_null($limit) || ($limit > 0))) {
4797 $new_rel = Array(
'parent' => $prefix.$k,
'children' => Array());
4798 foreach (array_keys($el) as $el_key) {
4800 $new_rel[
'children'][] = $prefix.$k.
'_'.$el_key;
4802 $new_rel[
'children'][] =
'['.$el_key.
']';
4805 $relations[] = $new_rel;
4827 if (!isset($this->_tmp[
'check_all_relations'])) {
4830 if (($this->
attr(
'group_by') ==
'grouped') && (count($this->
attr(
'asset_grouping')) > 0)) {
4831 $new_rel = Array(
'parent' =>
'_all',
'children' => Array());
4832 foreach (array_keys($todo) as $group_id) {
4833 $new_rel[
'children'][] =
'g_'.$group_id;
4836 $new_rel = Array(
'parent' =>
'_all',
'children' => Array());
4837 foreach (array_keys($todo) as $child) {
4838 $new_rel[
'children'][] =
'['.$child.
']';
4842 $relations = Array($new_rel);
4845 $this->_tmp[
'check_all_relations'] =& $relations;
4848 return $this->_tmp[
'check_all_relations'];
4863 $rels = array_reverse($this->_tmp[
'check_all_relations']);
4864 $code =
'init_select_list_array(); select_list[\''.$this->getPrefix().
'\'] = [
';
4866 $select_lines = Array();
4867 foreach ($rels as $rel) {
4868 $parent_code = str_replace(' ', '_
', $rel['parent
']);
4869 for (reset($rel['children
']); NULL !== ($k = key($rel['children
'])); next($rel['children
'])) {
4870 if (preg_match('|\[(.*)\]|
', $rel['children
'][$k], $matches)) {
4871 $rel['children
'][$k] = $matches[1];
4877 if (is_numeric($rel['children
'][$k])) {
4878 $rel['children
'][$k] = str_replace(' ', '_
', $rel['children
'][$k]);
4880 $rel['children
'][$k] = make_valid_html_id(str_replace(' ', '_
', $rel['children
'][$k]));
4884 $rel['children
'][$k] = '[
'.$rel['children
'][$k].']
';
4887 $select_lines[] = "[['".make_valid_html_id($parent_code)."'], ['".implode("', '", $rel['children'])."']]";
4889 $code .= implode(',
', $select_lines);
4895 }//end _buildRelationsJS()
4904 function _getFormSubmitMethod()
4906 return $this->attr('form_submit_method
');
4908 }//end _getFormSubmitMethod()
4911 //-- NO RESULTS BODYCOPY --//
4924 function createNoResultsBodycopy($enable_on_create=TRUE)
4926 $bodycopy_links = $GLOBALS['SQ_SYSTEM
']->am->getLinks($this->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3, 'bodycopy
', FALSE, 'major
', 'no_results
');
4927 $bodycopy_link = reset($bodycopy_links);
4929 // we already have a bodycopy link?!
4930 if ($bodycopy_link) {
4933 $GLOBALS['SQ_SYSTEM
']->am->includeAsset('bodycopy
');
4935 $link_type = ($enable_on_create ? SQ_LINK_TYPE_2 : SQ_LINK_TYPE_3);
4937 $asset = new Bodycopy();
4940 'value
' => 'no_results
',
4941 'link_type
' => $link_type,
4942 'is_dependant
' => 1,
4943 'is_exclusive
' => 1,
4946 $asset->setAttrValue('name
', 'Page Contents (No Results)
');
4947 $args = Array('content
' => $this->_getDefaultBodycopyContent('no_results
'));
4948 if (!$asset->create($copy_link, $args)) return FALSE;
4950 $GLOBALS['SQ_SYSTEM
']->am->forgetAsset($asset);
4956 }//end createNoResultsBodycopy()
4969 function &getNoResultsBodycopy($only_if_enabled=TRUE)
4973 if ($only_if_enabled) {
4974 $link_types = SQ_LINK_TYPE_2;
4976 $link_types = SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3;
4979 $tmp_bodycopy_link = $GLOBALS['SQ_SYSTEM
']->am->getLinks($this->id, $link_types, 'bodycopy
', FALSE, 'major
', 'no_results
');
4980 $bodycopy_link = reset($tmp_bodycopy_link);
4982 if ($bodycopy_link) {
4983 $asset = $GLOBALS['SQ_SYSTEM
']->am->getAsset($bodycopy_link['minorid
'], 'bodycopy
');
4988 }//end getNoResultsBodycopy()
4997 function isNoResultsBodycopyEnabled()
4999 $link_types = SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3;
5001 $bodycopy_links = $GLOBALS['SQ_SYSTEM
']->am->getLinks($this->id, $link_types, 'bodycopy
', FALSE, 'major
', 'no_results
');
5002 $bodycopy_link = reset($bodycopy_links);
5004 if ($bodycopy_link) {
5005 return ($bodycopy_link['link_type
'] == SQ_LINK_TYPE_2);
5011 }//end isNoResultsBodycopyEnabled()
5023 function setUseNoResultsBodycopy($enabled)
5025 $tmp_body_link = $GLOBALS['SQ_SYSTEM
']->am->getLinks($this->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3, 'bodycopy
', FALSE, 'major
', 'no_results
');
5026 $bodycopy_link = reset($tmp_body_link);
5028 if (!$bodycopy_link) {
5029 // no bodycopy yet? If we're trying to
set to disabled, then we don
't
5030 // need to do anything - if not then we need to create it
5032 if (!$this->createNoResultsBodycopy()) return FALSE;
5035 // set link type to either TYPE_2 if enabled or TYPE_3 if disabled
5036 $new_link_type = ($enabled) ? SQ_LINK_TYPE_2 : SQ_LINK_TYPE_3;
5037 if ($bodycopy_link['link_type
'] != $new_link_type) {
5038 $GLOBALS['SQ_SYSTEM
']->am->updateLink($bodycopy_link['linkid
'], $new_link_type);
5044 }//end setUseNoResultsBodycopy()