18 require_once SQ_CORE_PACKAGE_PATH.
'/content_type/content_type_edit_fns.inc';
43 parent::__construct();
59 function paint(&$asset, $editing=FALSE, $generating=FALSE)
61 $snippet_asset = $asset->getCurrentSnippet();
65 if (!is_null($snippet_asset)) {
66 $snippet_asset->printBody();
88 if (!is_null($snippet_asset)) {
90 $snippet_assetid =
'<?php echo $snippet_asset->id; ?>';
91 $snippet_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($snippet_assetid);
92 $snippet_asset->printBody();
111 if ($asset->writeAccess(
'attributes')) {
114 $snippets = $asset->getSnippets();
115 if (empty($snippets)) {
116 echo translate(
'cms_ct_snippet_no_access');
121 $source_safe = FALSE;
122 $current_view = $asset->attr(
'view_style');
123 $current_snippet = $asset->getCurrentSnippet();
124 $current_id = (is_null($current_snippet)) ? 0 : $current_snippet->id;
125 $current_content = translate(
'cms_ct_snippet_select_one');
127 if (!isset($snippets[$current_id])) {
129 $current_content = translate(
'cms_ct_snippet_warning', get_asset_tag_line($current_id));
131 $current_content = $snippets[$current_id][
'content'];
138 'source' =>
'View source',
139 'html' =>
'View HTML',
141 $dropdown = Array(0 =>
'--');
142 foreach ($snippets as $id => $info) {
143 $dropdown[$id] = $id.
': '.$info[
'name'];
145 hidden_field($prefix.
'_hidden_source_'.$id, $info[
'type'] ==
'content_type_nest_content' ? $info[
'content'] : nl2br(htmlspecialchars($info[
'content'])));
146 hidden_field($prefix.
'_hidden_html_'.$id, $info[
'content']);
151 $switchSnippet =
'onChange="switchSnippet(this.value)"';
152 $switchView =
'onChange="switchView(this.value)"';
154 <table
class=
"sq-backend-table">
156 <td
class=
"sq-backend-table-cell-alt">
157 <?php echo combo_box($prefix.
'_dropdown', $dropdown, FALSE, $current_id, 0, $switchSnippet); ?>
158 <?php echo combo_box($prefix.
'_viewstyle', $viewstyle, FALSE, $current_view, 0, $switchView); ?>
163 <span
id=
"<?php echo $prefix.'_displayarea'; ?>" name=
"<?php echo $prefix.'_displayarea'; ?>">
165 if ($current_view ==
'source' && $source_safe) {
166 echo $snippets[$current_id][
'type'] ==
'content_type_nest_content' ? $current_content : nl2br(htmlspecialchars($current_content));
168 echo $current_content;
175 <script type=
"text/javascript">
176 function switchSnippet(
id) {
177 var span = document.getElementById(
'<?php echo $prefix.'_displayarea
'; ?>');
178 var style = document.getElementById(
'<?php echo $prefix.'_viewstyle
'; ?>');
180 span.innerHTML =
'<?php echo translate('cms_ct_snippet_select_one
'); ?>';
183 var snippet = document.getElementById((
'<?php echo $prefix; ?>_hidden_' + style.value +
'_' +
id));
184 span.innerHTML = snippet.value;
186 function switchView(style) {
187 var span = document.getElementById(
'<?php echo $prefix.'_displayarea
'; ?>');
188 var dropdown = document.getElementById(
'<?php echo $prefix.'_dropdown
'; ?>');
189 if (dropdown.value == 0) {
192 var snippet = document.getElementById((
'<?php echo $prefix; ?>_hidden_' + style +
'_' + dropdown.value));
193 span.innerHTML = snippet.value;
216 if ($asset->writeAccess(
'attributes')) {
219 if (isset($_POST[$prefix.
'_viewstyle'])) {
220 $asset->setAttrValue(
'view_style', $_POST[$prefix.
'_viewstyle']);
221 $asset->saveAttributes();
223 $current_snippet = $asset->getCurrentSnippet();
224 $current_id = (is_null($current_snippet)) ? 0 : $current_snippet->id;
225 $new_id = (isset($_POST[$prefix.
'_dropdown'])) ? $_POST[$prefix.
'_dropdown'] : 0;
227 if (!$new_id && (!$current_id || !$current_snippet->readAccess())) {
235 if ($new_id != $current_id) {
238 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'', TRUE,
'snippet_asset');
239 if (!$asset->deleteLink($link[
'linkid'])) {
243 $new_snippet = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($new_id);
245 if (!$asset->createLink($new_snippet, SQ_LINK_NOTICE,
'snippet_asset')) {
249 if (!$current_id && $new_id) {
250 $asset->linksUpdated();
254 }
else if ($current_id) {
256 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'', TRUE,
'snippet_asset');
257 if (!$asset->deleteLink($link[
'linkid'])) {
263 $bc_container_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2,
'bodycopy_container', FALSE,
'minor');
264 if (!empty($bc_container_link)) {
265 $container = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bc_container_link[0][
'majorid']);
266 $edit_fns = $container->getEditFns();
267 $edit_fns->generateContentFile($container);