17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
39 function paintTagging(&$owner, &$o, &$ei, $keywords=NULL)
41 $root = $ei->findScreen(
'static_screen_tagging');
42 if (is_null($root))
return FALSE;
43 $write_access = $owner->writeAccess(
'menu');
44 $prefix = $owner->getPrefix();
45 $print_commit_button = FALSE;
47 foreach ($root->children() as $section) {
50 if (is_null($keywords)) {
52 if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || ((
int)$section->attributes()->limbo_access) == 0)) {
57 $section_access = $ei->_getAccess($owner, $section, $prefix);
58 if (!($section_access & SQ_EI_READ)) {
62 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower( str_replace(
' ',
'_', (
string)$section->attributes()->name) )])) {
66 $section_name = isset($section->attributes()->display_name) ? $section->attributes()->display_name : $section->attributes()->name;
67 $o->openSection($section_name);
69 if (!($num_fields = count($section->children()))) {
73 foreach ($section->children() as $field) {
75 $field_access = $ei->_getAccess($owner, $field, $prefix);
76 if (!($field_access & SQ_EI_READ)) {
80 switch (strtolower((
string)$field->attributes()->code)) {
87 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
93 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager', TRUE);
97 <a href=
"#" onClick=
"Javascript: var win = window.open('<?php echo sq_web_path('lib'); ?>/tag_suggestion/tag_suggestion.php?assetid=<?php echo $owner->id; ?>&prefix=<?php echo $prefix; ?>', 'keywords', 'toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1,width=580,height=320'); return FALSE;">
98 <?php echo translate(
'tag_suggestion') ?></a>
100 $replacements_link = ob_get_contents();
102 echo(translate(
'tagging_suggest_indexed', $replacements_link));
106 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
107 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][strtolower((
string)$field->attributes()->code)]] = ob_get_contents();
116 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
120 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
121 $current_tag_links = $tag_manager->getTagLinks($owner->id);
126 $current_tag_ids = Array();
127 foreach ($current_tag_links as $key => $current_tag_link) {
128 $current_tag_ids[$key] = $current_tag_link[
'minorid'];
131 if ($tag_manager->isTagSourceRestricted()) {
133 if ($tag_manager->attr(
'thesaurus')) {
134 multiple_asset_finder($prefix.
'_tags', $current_tag_ids, Array(
'thesaurus_term'=>
'D'));
135 $o->note(translate(
'tag_thesaurus_note', get_asset_tag_line($tag_manager->attr(
'thesaurus'),
'details')));
137 $o->note(translate(
'tag_no_thesaurus_set_note'));
141 multiple_asset_finder($prefix.
'_tags', $current_tag_ids, Array(
'thesaurus_term'=>
'D'));
145 foreach ($current_tag_links as $key => $current_tag_link) {
146 echo get_asset_tag_line($current_tag_link[
'minorid']).
'<br>';
150 if (isset($field->note) && (strlen((
string)$field->note) > 0)) {
151 $o->note((
string)$field->note);
154 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
155 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][strtolower((
string)$field->attributes()->code)]] = ob_get_contents();
163 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
164 $current_tag_links = $tag_manager->getTagLinks($owner->id);
166 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
173 foreach ($current_tag_links as $key => $current_tag_link) {
174 echo get_asset_tag_line($current_tag_link[
'minorid']).text_box($prefix.
'_weights['.$current_tag_link[
'linkid'].
']', $current_tag_link[
'value'], 4).
'<br>';
177 foreach ($current_tag_links as $key => $current_tag_link) {
178 echo get_asset_tag_line($current_tag_link[
'minorid']).
' '.translate(
'weight').
': '.$current_tag_link[
'value'].
'<br>';
182 if (isset($field->note) && (strlen((
string)$field->note) > 0)) {
183 $o->note((
string)$field->note);
188 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
189 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][strtolower((
string)$field->attributes()->code)]] = ob_get_contents();
197 $kiddies = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($owner->id, Array(), FALSE, FALSE);
198 $kiddies = array_filter($kiddies);
199 if (count($kiddies)) {
200 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
204 $o->openSection(translate(
'cascade_options'));
205 $o->openField(
'Note');
206 echo translate(
'action_affects_assets_below_this', count($kiddies), htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
208 $o->openField(
' ');
209 check_box($prefix.
'_tagging[cascade_changes]',
'1', TRUE);
210 label(translate(
'cascade_tag_changes'), $prefix.
'_tagging[cascade_changes]');
213 $o->note(translate(
'tagging_cascade_changes_note'));
214 check_box($prefix.
'_tagging[manual_cascade]');
215 label(translate(
'manually_cascade_all_tags'), $prefix.
'_tagging[manual_cascade]');
218 $o->note(translate(
'tagging_manual_cascade_note'));
223 if (!is_null($keywords) && isset($keywords[
'fields'][strtolower((
string)$field->attributes()->code)])) {
224 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][strtolower((
string)$field->attributes()->code)]] = ob_get_contents();
239 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower( str_replace(
' ',
'_', (
string)$section->attributes()->name) )])) {
240 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'sections'][strtolower( str_replace(
' ',
'_', (
string)$section->attributes()->name) )]] = ob_get_contents();
245 return $write_access;
260 function paintInlineTagging(&$owner, &$o, &$ei)
262 $prefix = $owner->getPrefix();
264 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
265 $current_tag_links = $tag_manager->getTagLinks($owner->id);
267 if (empty($current_tag_links))
return FALSE;
269 $o->openSection(translate(
'content_tags'));
270 $o->openField(
' ');
272 <table
class=
"sq-backend-table">
274 <td
class=
"sq-backend-table-header">
275 <?php echo translate(
'content_tag'); ?>
277 <td
class=
"sq-backend-table-header" align=
"right">
278 <?php echo translate(
'weight'); ?>
283 foreach ($current_tag_links as $key => $current_tag_link) {
286 <td
class=
"sq-backend-table-cell">
288 echo get_asset_tag_line($current_tag_link[
'minorid']);
291 <td
class=
"sq-backend-table-cell" align=
"right">
293 echo $current_tag_link[
'value'];
320 function processTagging(&$owner, &$o, $ei)
323 if (!$owner->writeAccess(
'menu'))
return FALSE;
324 $prefix = $owner->getPrefix();
326 $tag_manager = $GLOBALS[
'SQ_SYSTEM']->getTagManager();
327 $submitted_tags = array_get_index($_REQUEST, $prefix.
'_tags', Array());
329 $cascade_changes = FALSE;
330 if (isset($_POST[$prefix.
'_tagging'][
'cascade_changes']) && $_POST[$prefix.
'_tagging'][
'cascade_changes'] ) {
332 $cascade_changes = TRUE;
337 $manual_cascade = FALSE;
338 if (isset($_POST[$prefix.
'_tagging'][
'manual_cascade']) && $_POST[$prefix.
'_tagging'][
'manual_cascade'] ) {
339 $manual_cascade = TRUE;
340 $cascade_changes = FALSE;
346 foreach ($submitted_tags as $key => $submitted_tag) {
347 $submitted_tag_ids[$key] = $submitted_tag[
'assetid'];
350 $current_tag_links = $tag_manager->getTagLinks($owner->id);
351 $current_tag_ids = Array();
352 $current_weights = Array();
354 foreach ($current_tag_links as $key => $current_tag_link) {
355 $current_tag_ids[$key] = $current_tag_link[
'minorid'];
356 $current_weights[$current_tag_link[
'linkid']] = $current_tag_link[
'value'];
361 $new_tag_ids = array_diff($submitted_tag_ids, $current_tag_ids);
362 foreach ($new_tag_ids as $one_tag_id) {
364 if (empty($one_tag_id))
continue;
366 if ($cascade_changes) {
369 'tag_id' => $one_tag_id,
374 $tag_manager->setTag($owner->id, $one_tag_id,
'1');
379 $submitted_weights = array_get_index($_REQUEST, $prefix.
'_weights', Array());
380 foreach ($submitted_weights as $linkid => $weight) {
381 if (empty($weight)) $submitted_weights[$linkid] = 1;
384 $modified_weights = array_diff_assoc($submitted_weights, $current_weights);
385 foreach ($modified_weights as $linkid => $weight) {
386 if ($cascade_changes) {
387 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
390 'tag_id' => $link[
'minorid'],
395 $tag_manager->setTagWeight($linkid, $weight);
401 $deleted_tag_ids = array_diff($current_tag_ids, $submitted_tag_ids);
402 foreach ($deleted_tag_ids as $one_tag_id) {
403 if (empty($one_tag_id))
continue;
405 if ($cascade_changes) {
408 'tag_id' => $one_tag_id,
409 'action' =>
'delete',
413 $tag_manager->deleteTag($owner->id, $one_tag_id);
419 if ($manual_cascade) {
420 $current_tag_links = $tag_manager->getTagLinks($owner->id);
422 foreach ($current_tag_links as $link) {
424 'tag_id' => $link[
'minorid'],
426 'weight' => $link[
'value'],
432 if (!empty($tag_vars)) {
433 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
437 'type_code' => $owner->type(),
440 'tag_changes' => $tag_vars,
443 $hh->queueHipo(
'hipo_job_edit_tags', $vars);