18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
61 if (!parent::_preCreateCheck($link))
return FALSE;
63 $name = trim($this->
attr(
'name'));
65 trigger_localised_error(
'CORE0083', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
85 return $this->
attr(
'name');
100 SQ_LINK_TYPE_1 => Array(),
101 SQ_LINK_TYPE_2 => Array(),
102 SQ_LINK_TYPE_3 => Array(),
103 SQ_LINK_NOTICE => Array(),
117 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
118 return $mm->getMetadataFieldDefaultValue($this->
id);
135 require_once SQ_FUDGE_PATH.
'/general/text.inc';
136 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
139 if (is_null($value_str)) {
145 if (!$this->
attr(
'value_components') && $this->
attr(
'frontend') ==
'hide') {
150 $used_keywords = retrieve_keywords_replacements($value_str,
'.');
152 $used_keywords = $mm->generateKeywordReplacements($asset, $used_keywords, FALSE);
154 return replace_keywords($value_str, $used_keywords);
187 $regex =
'/([;=\\\\])/';
190 $str = preg_replace($regex, $replace, $value);
191 foreach ($components as $k => $v) {
192 $str .=
'; '.preg_replace($regex, $replace, $k).
'='.preg_replace($regex, $replace, $v);
195 if (!empty($components)) $str .=
';';
235 $str = str_replace(
'%',
'%'.ord(
'%').
'%', $str);
237 $str = preg_replace(
'/\\\\([;=\\\\])/e',
'"%".ord("\\1")."%"', $str);
240 $check_component = !empty($components);
241 $parts = explode(
';', $str);
242 foreach ($parts as $part) {
243 if ($part ==
'')
continue;
244 $pair = explode(
'=', $part, 2);
247 $pair[0] = preg_replace(
'/^\s*(\S+)\s*$/',
'$1', $pair[0]);
250 $pair[0] = trim($pair[0]);
253 $pair[0] = preg_replace(
'/%(\d+)%/e',
'chr($1)', $pair[0]);
255 if (isset($pair[1])) {
256 $pair[1] = preg_replace(
'/%(\d+)%/e',
'chr($1)', $pair[1]);
259 if (!isset($pair[1])) {
260 if ($value !=
'') $value .=
'; ';
263 }
else if (!$check_component || isset($components[$pair[0]])) {
264 $components[$pair[0]] = $pair[1];
287 $field_name_original = $this->
attr(
'name');
288 $field_name = str_replace(
'\'',
'', $field_name_original);
289 $field_name = str_replace(
'\"',
'', $field_name);
290 if ($field_name != $field_name_original) {
294 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
295 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
297 $default_val = self::encodeValueString($this->
attr(
'default'), $this->
attr(
'value_components'));
301 if ((array_key_exists(
'vars_set', $this->_tmp) === TRUE) && (array_key_exists(
'default', $this->_tmp[
'vars_set']) === TRUE)) {
302 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
304 if (!$mm->setMetadataFieldDefaultValue($this->id, $default_val)) {
305 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
306 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
311 if (!parent::saveAttributes($dont_run_updated)) {
312 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
313 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
317 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
318 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
336 public function delete($release_lock=TRUE)
338 if (parent::delete($release_lock)) {
339 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
342 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
346 $sql =
'DELETE FROM sq_ast_mdata_val WHERE ';
347 $sql .=
'fieldid = :fieldid';
352 }
catch (Exception $e) {
353 throw new Exception(
'Unable to delete metadata value for fieldid #'.$this->
id.
' due to the following database error:'.$e->getMessage());
359 $sql =
'DELETE FROM sq_ast_mdata_dflt_val WHERE ';
360 $sql .=
'assetid = :assetid';
365 }
catch (Exception $e) {
366 throw new Exception(
'Unable to delete metadata default value for assetid #'.$this->
id.
' due to the following database error:'.$e->getMessage());
369 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
370 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();