18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
43 parent::__construct($assetid);
58 $allowed = parent::_getAllowedLinks();
59 $allowed[SQ_LINK_TYPE_1][
'page'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
60 $allowed[SQ_LINK_TYPE_1][
'file'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
61 $allowed[SQ_LINK_TYPE_1][
'folder'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
62 $allowed[SQ_LINK_TYPE_1][
'data_source'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
63 $allowed[SQ_LINK_TYPE_1][
'link'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
65 $allowed[SQ_LINK_TYPE_2][
'page'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
66 $allowed[SQ_LINK_TYPE_2][
'file'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
67 $allowed[SQ_LINK_TYPE_2][
'folder'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
68 $allowed[SQ_LINK_TYPE_2][
'data_source'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
69 $allowed[SQ_LINK_TYPE_2][
'link'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
71 $allowed[SQ_LINK_TYPE_3][
'page'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
73 $allowed[SQ_LINK_NOTICE][
'page'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
74 $allowed[SQ_LINK_NOTICE][
'link'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
93 if (!parent::_preCreateCheck($link))
return FALSE;
95 $name = trim($this->
attr(
'name'));
97 trigger_localised_error(
'CORE0083', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'));
118 if (!parent::_createAdditional($link))
return FALSE;
135 protected function _getName($short_name=FALSE, $contextid=NULL)
138 if ($contextid === NULL) {
139 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
143 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
144 if (empty($values) === TRUE) {
145 return parent::_getName($short_name, $contextid);
147 return $values[$this->id];
163 $link_str =
'<a href="'.$this->_getLinkURL().
'"';
165 $relation = $this->
attr(
'link_relation');
166 if (!empty($relation)) {
167 $link_str .=
' rel="'.$relation.
'"';
170 $link_str .=
'>'.$this->_getName().
'</a>';
193 $keywords = parent::getAvailableKeywords();
195 $asset =
new Asset();
197 foreach ($asset->getAvailableKeywords() as $keyword => $desc) {
198 $keywords[
'link_target_'.$keyword] =
'Referring Asset: '.$desc;
200 $keywords[
'link_url'] =
'The Link URL for this asset';
201 $keywords[
'link_relation'] =
'Link relation for this asset';
227 $full_keyword = $keyword;
228 $keyword = parse_keyword($keyword, $modifiers);
229 $contextid = extract_context_modifier($modifiers);
231 if ($contextid !== NULL) {
236 if ((
int)$contextid !== $GLOBALS[
'SQ_SYSTEM']->getContextId()) {
237 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
238 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
241 $replacement = $contexted_asset->getKeywordReplacement($keyword);
244 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $contexted_asset->id));
246 unset($contexted_asset);
247 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
254 if (preg_match(
'|^link\_target\_(.*)|', $keyword, $matches)) {
258 $replacement = $linked_asset->getKeywordReplacement($matches[1]);
262 }
else if ($keyword ===
'link_url') {
263 $replacement = $this->_getLinkURL();
264 }
else if ($keyword ===
'link_relation') {
265 $replacement = $this->_getLinkRelation();
267 return parent::getKeywordReplacement($full_keyword);
270 if (count($modifiers) > 0) {
271 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
287 $linked_assetid = $this->
attr(
'link_asset_id');
288 $linked_url = $this->
attr(
'link_url');
290 $linked_asset = NULL;
293 if (!empty($linked_assetid)) {
294 $linked_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($linked_assetid);
296 }
else if (!empty($linked_url)) {
298 $linked_url = preg_replace(
'|^.*://|',
'', $linked_url);
299 $linked_url = preg_replace(
'|\?.*$|',
'', $linked_url);
301 $linked_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(NULL, $linked_url, FALSE, TRUE);
304 return $linked_asset;
317 return $this->_getLinkURL();
328 private function _getLinkURL()
330 $url = $this->
attr(
'link_url');
331 if (empty($url) || (trim($url) ==
'')) {
333 $assetid = $this->
attr(
'link_asset_id');
335 if (!empty($assetid)) {
336 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
337 if (!is_null($asset)) $url = $asset->getURL();
352 private function _getLinkRelation()
354 return $this->
attr(
'link_relation') ? $this->
attr(
'link_relation') :
'';