17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
40 function paintMetadata(&$owner, &$o, &$ei, $keywords=NULL, Array $layout_options=Array())
42 $root = $ei->findScreen(
'static_screen_metadata');
43 if (is_null($root))
return FALSE;
45 $prefix = $owner->getPrefix();
46 $print_commit_button = FALSE;
48 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
49 $schemas = $mm->getSchemas($owner->id, TRUE);
50 $metadata_warnings = Array();
51 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
55 $print_cascade_values_option = TRUE;
57 if ((!SQ_IN_BACKEND) && (isset($layout_options[
'show_cascade_metadata_field']))) {
58 $print_cascade_values_option = $layout_options[
'show_cascade_metadata_field'];
61 foreach ($root->section as $section) {
63 if (is_null($keywords)) {
65 if (SQ_IN_LIMBO && (!isset($section->attributes()->limbo_access) || (
int)$section->attributes()->limbo_access == 0)) {
70 $section_access = $ei->_getAccess($owner, $section, $prefix);
71 if (!($section_access & SQ_EI_READ)) {
75 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower(str_replace(
' ',
'_', (
string) $section->attributes()->name))])) {
80 $o->openSection(array_get_index($section->attributes,
'display_name', (
string) $section->attributes()->name));
82 if (!($num_fields = count($section->children()))) {
86 foreach ($section->field as $field) {
87 $field_access = $ei->_getAccess($owner, $field, $prefix);
88 if (!($field_access & SQ_EI_READ)) {
92 switch (strtolower((
string) $field->attributes()->code)) {
95 case 'metadata_current' :
98 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_current'])) {
102 if ($contextid === 0) {
103 $metadata_basename =
'metadata.php';
105 $metadata_basename =
'metadata.'.$contextid.
'.php';
107 $metadata_default_name =
'metadata.php';
110 if (empty($schemas)) {
111 echo translate(
'no_metadata_schemas_applied');
112 }
else if (file_exists($owner->data_path.
'/'.$metadata_basename)) {
114 require($owner->data_path.
'/'.$metadata_basename);
115 $metadata = ob_get_contents();
117 }
else if (file_exists($owner->data_path.
'/'.$metadata_default_name)) {
121 require($owner->data_path.
'/'.$metadata_default_name);
122 $metadata = ob_get_contents();
128 if ($metadata !== NULL) {
129 echo nl2br(htmlspecialchars(trim($metadata)));
133 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_current'])) {
134 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][
'metadata_current']] = ob_get_contents();
143 case 'metadata_instructions' :
145 $o->openField(
' ');
146 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_instructions'])) {
151 $replacements_link =
'<a href="'.sq_web_path(
'data').
'/asset_types/metadata_field/popups/keywords.php?assetid='.$owner->id.
'&all=0" onclick="var win = window.open(this.href, \'keywords\', \'toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1,width=580,height=320\'); return false;">'.translate(
'click_here').
'</a>';
152 echo
'<p>'.translate(
'metadata_keyword_replacements_usage', $replacements_link).
'</p>';
154 $sm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'search_manager', TRUE);
155 if (!empty($sm) && $sm->attr(
'indexing')) {
158 $replacements_link =
'<a href="'.sq_web_path(
'data').
'/asset_types/metadata_field/popups/keyword_extraction.php?assetid='.$owner->id.
'" onclick="var win = window.open(this.href, \'keywords\', \'toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=1,width=580,height=320\'); return false;">'.translate(
'keyword_extraction').
'</a>';
159 echo
'<p>'.translate(
'metadata_indexed_keywords', $replacements_link).
'</p>';
164 echo
'<p>'.translate(
'metadata_explain_use_default').
'</p>';
167 echo
'<p>'.translate(
'metadata_explain_cascade_value').
'</p>';
170 echo
'<p> '.translate(
'denotes_required_field',
'<span class="sq-backend-warning">*</span>').
'</p>';
173 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_instructions'])) {
174 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][
'metadata_instructions']] = ob_get_contents();
183 case 'metadata_values' :
184 if (empty($schemas)) {
185 $o->openField(
' ');
186 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_values'])) {
190 echo translate(
'must_apply_one_or_more_schemas');
193 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_values'])) {
194 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][
'metadata_values']] = ob_get_contents();
199 $write_access = $owner->writeAccess(
'metadata');
200 $print_commit_button = FALSE;
202 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_values'])) {
206 $values = $mm->getMetadata($owner->id);
207 foreach ($schemas as $schemaid) {
208 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
209 if (is_null($schema))
continue;
210 $edit_fns = $schema->getEditFns();
213 if ((!is_null($keywords) && isset($keywords[
'fields'][
'metadata_values'])) || !SQ_IN_LIMBO) {
214 if ($edit_fns->paintInlineValueInterface($schema, $o, $values, $write_access, $print_cascade_values_option, $owner->type())) {
215 $print_commit_button = TRUE;
219 $print_commit_button = TRUE;
224 if (!is_null($keywords) && isset($keywords[
'fields'][
'metadata_values'])) {
227 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][
'metadata_values']] =
'<table>'.ob_get_contents().
'</table>';
236 $note = (string) $field->note;
244 if (!is_null($keywords) && isset($keywords[
'sections'][strtolower(str_replace(
' ',
'_', $section->attributes()->name))])) {
245 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'sections'][strtolower(str_replace(
' ',
'_', $section->attributes()->name))]] = ob_get_contents();
251 $field_names = Array();
252 $duplicate_field_names = Array();
253 $field_ids = $mm->getMetadataFields($schemas);
254 if (!empty($field_ids)) {
255 foreach ($field_ids as $field_assetid => $field_info) {
256 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($field_assetid);
257 if (!isset($field_names[$field->attr(
'name')])) {
258 $field_names[$field->attr(
'name')] = 1;
260 $duplicate_field_names[$field->attr(
'name')] = $field->attr(
'name');
262 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($field);
266 if (!empty($duplicate_field_names)) {
267 $o->openSection(translate(
'warning'));
268 $o->openField(
' ');
272 foreach ($duplicate_field_names as $name) {
273 ?><li><?php echo $name ?></li><?php
275 ?></ul><span
class=
"sq-backend-warning"><?php echo translate(
'duplicate_metadata_fields'); ?></span>
283 if (!empty($metadata_warnings[
'keyword_circular_references'])) {
284 $o->openSection(translate(
'warning'));
285 $o->openField(
' ');
289 foreach ($metadata_warnings[
'keyword_circular_references'] as $name) {
290 ?><li><?php echo $name ?></li><?php
292 ?></ul><span
class=
"sq-backend-warning"><?php echo translate(
'circular_reference_metadata_field_keywords'); ?></span>
300 if (!is_null($keywords) && isset($keywords[
'fields'])) {
303 $schemas = $mm->getSchemas($owner->id, TRUE);
304 $write_access = $owner->writeAccess(
'metadata');
306 foreach ($keywords[
'fields'] as $field_assetid => $keyword) {
309 if ($mm->isMetadataFieldAssetid($field_assetid)) {
311 $schemaid = $GLOBALS[
'SQ_SYSTEM']->am->getParents($field_assetid,
'metadata_schema');
315 if (empty($owner->id) || (array_intersect($schemas, array_keys($schemaid)) != Array())) {
316 $value = $mm->getMetadataInterfaceValueByAssetid($owner->id, $field_assetid);
318 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($field_assetid);
319 $edit_fns = $field->getEditFns();
322 $edit_fns->paintValueInterface($field, $o, $value, $write_access, FALSE, $print_cascade_values_option, $owner->type());
323 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][$field_assetid]] = ob_get_contents();
329 if (preg_match(
'/section_(\d+)_(name|description|values)/', $field_assetid, $matches)) {
331 $section_id = $matches[1];
332 $keyword_suffix = $matches[2];
333 $schemaid = $GLOBALS[
'SQ_SYSTEM']->am->getParents($section_id,
'metadata_schema');
337 if (empty($owner->id) || (array_intersect($schemas, array_keys($schemaid)) != Array())) {
338 $section = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($section_id);
340 if ($keyword_suffix ==
'values') {
342 $values = $mm->getMetadata($owner->id);
343 $edit_fns = $section->getEditFns();
344 $edit_fns->paintInlineValueInterface($section, $o, $values, $write_access, $print_cascade_values_option, $owner->type());
345 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][$field_assetid]] = ob_get_contents();
349 echo $section->attr($keyword_suffix);
350 $ei->_tmp[
'layout_keyword_replacements'][$keywords[
'fields'][$field_assetid]] = ob_get_contents();
358 return $print_commit_button;
373 function processMetadata(&$owner, &$o, $ei)
376 if (!$owner->writeAccess(
'metadata'))
return FALSE;
378 $cascade_values_asset_ids = Array();
380 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
381 $schemas = $mm->getSchemas($owner->id, TRUE);
383 if (!empty($schemas)) {
384 $new_values = Array();
385 foreach ($schemas as $schemaid) {
386 $schema = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($schemaid);
387 $edit_fns = $schema->getEditFns();
388 if ($edit_fns->processInlineValueInterface($schema, $new_values, $cascade_values_asset_ids, $owner->type())) {
394 $mm->setMetadata($owner->id, $new_values);
397 $regen_all_contexts = FALSE;
398 foreach ($new_values as $fieldid => $field_data) {
399 $field = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($fieldid);
400 if (!$field)
continue;
403 $regen_all_contexts = TRUE;
408 if ($regen_all_contexts) {
409 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
410 foreach ($all_contexts as $contextid => $context_data) {
411 $mm->generateContentFile($owner->id, FALSE, $contextid);
414 $mm->generateContentFile($owner->id);
418 if (!empty($cascade_values_asset_ids)) {
419 $metadata_values_vars = Array();
420 foreach($cascade_values_asset_ids as $asset_id => $val) {
421 $field_value = Array($asset_id => $new_values[$asset_id]);
422 $metadata_values_vars[$asset_id] = Array(
'field_asset_id' => $asset_id,
'field_value' => $field_value);
426 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
428 'assets' => Array($owner->id => Array(
'type_code' => $owner->type())),
429 'metadata_field_value_changes' => $metadata_values_vars,
430 'dependants_only' => 1,
431 'contextid' => $GLOBALS[
'SQ_SYSTEM']->getContextId(),
434 $hh->queueHipo(
'hipo_job_edit_metadata_field_values', $vars);