Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
image_variety.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset.inc';
19 
31 class Image_Variety extends Asset
32 {
33 
38  var $_imageid = 0;
39 
44  var $_varietyid = 0;
45 
46 
54  function Image_Variety($assetid=0, $data=Array())
55  {
56  $this->Asset();
57 
58  if (!$assetid) return;
59  list($this->_imageid, $this->_varietyid) = explode(':v', $assetid);
60 
61  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
62  if (is_null($image)) return;
63 
64  // set the data paths
65  $this->data_path = $image->data_path.'/varieties';
66  $this->data_path_suffix = $image->data_path_suffix.'/varieties';
67  $this->data_path_public = $image->data_path_public.'/varieties';
68 
69  // if there is no varietyid then we haven't been created yet, so don't do anymore
70  if (!$this->_varietyid) return;
71 
72  $this->id = $assetid;
73 
74  foreach ($data as $attr_name => $attr_value) {
75  if (!isset($this->vars[$attr_name])) continue;
76  $this->vars[$attr_name]['value'] = ($this->vars[$attr_name]['type'] == 'serialise') ? unserialize($attr_value) : $attr_value;
77  }
78 
79  // set general object properties, now we have the name of the thing
80  $this->name = $this->_getName();
81  $this->short_name = $this->_getName('short_name');
82  $this->status = $image->status;
83  $this->version = '0.1';
84 
85  }//end constructor
86 
87 
99  function setAttrValue($name, $value)
100  {
101  switch ($name) {
102  case 'name' :
103  if (trim($this->attr('name')) != '') {
104  trigger_localised_error('CORE0116', E_USER_WARNING);
105  return FALSE;
106  } else if (trim($value) == '') {
107  trigger_localised_error('CORE0120', E_USER_WARNING);
108  } else {
109  // make sure the name is valid for a web path
110  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
111  list($value) = make_valid_web_paths(Array(trim($value)));
112  }
113  break;
114 
115  case 'width' :
116  case 'height' :
117  if ((int) $value < 0) {
118  trigger_localised_error('CORE0101', E_USER_WARNING, $name, $this->name, $this->id);
119  return FALSE;
120  }
121  if ((int) $value == 0 && ($this->attr('constrain') == 'none' || ($this->attr('constrain') == $name && $this->attr('variety_type') == 'resize'))) {
122  trigger_localised_error('CORE0102', E_USER_WARNING, $name, $this->name, $this->id);
123  return FALSE;
124  }
125  // If constrain = dimension but there's none set, use the value from here
126  if ($this->attr('constrain') == 'dimension') {
127  $this->setAttrValue('dimension', $value);
128  }
129  break;
130 
131  }// end switch
132 
133 
134 
135  return parent::setAttrValue($name, $value);
136 
137  }//end setAttrValue()
138 
139 
151  function processStatusChange($new_status, $update_parent=TRUE)
152  {
153  return TRUE;
154 
155  }//end processStatusChange()
156 
157 
171  function saveAttributes($dont_run_updated=FALSE)
172  {
173  if (!$this->id) return TRUE;
174  if (empty($this->_tmp['vars_set'])) return TRUE;
175 
176  if (!$GLOBALS['SQ_REVERT_TO_SYSTEM_VERSION'] && !$this->writeAccess('attributes')) {
177  trigger_localised_error('CORE0121', E_USER_WARNING, $this->name, $this->id);
178  return FALSE;
179  }
180 
181  if ($this->attr('variety_type') == 'resize' && $this->attr('constrain') != 'none') {
182  if ((int) $this->attr($this->attr('constrain')) == 0) {
183  trigger_localised_error('CORE0096', E_USER_WARNING, $this->name, $this->id, $this->attr('constrain'));
184  return FALSE;
185  }
186  }
187 
188  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
189  return (bool) $image->saveVariety($this);
190 
191  }//end saveAttributes()
192 
193 
208  function _updated($update_parents=TRUE)
209  {
210  $this->name = $this->_getName();
211  $this->short_name = $this->_getName('short_name');
212 
213  return TRUE;
214 
215  }//end _updated()
216 
217 
224  function canClone()
225  {
226  return FALSE;
227 
228  }//end canClone()
229 
230 
239  function _getName($short_name=FALSE)
240  {
241  return $this->attr('name');
242 
243  }//end _getName()
244 
245 
254  function updateImage($file_versioning=TRUE)
255  {
256  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
257  if (is_null($image)) return FALSE;
258 
259  if ($this->attr('variety_type') == 'resize') {
260 
261  if ($file_versioning) {
262  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
263  require_once SQ_FUDGE_PATH.'/image/image_manip.inc';
264  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
265  }
266 
267  if (!is_dir($this->data_path) && !create_directory($this->data_path)) {
268  return FALSE;
269  }
270 
271  $source_image_info = $image->getExistingFile();
272  if (empty($source_image_info)) return TRUE;
273 
274  $ext = get_file_type($image->name);
275 
276  $s_file = $source_image_info['path'];
277 
278  $d_old_filename = $this->attr('filename');
279  $d_new_filename = $this->name.'.'.$ext;
280  $d_old_file = $this->data_path.'/'.$d_old_filename;
281  $d_new_file = $this->data_path.'/'.$d_new_filename;
282  $d_width = (int) $this->attr('width');
283  $d_height = (int) $this->attr('height');
284  $d_dimension = (int) $this->attr('dimension');
285 
286  // if either are blank calc the other to scale
287  switch ($this->attr('constrain')) {
288  case 'width' :
289  if ($d_width <= 0) {
290  trigger_localised_error('CORE0007', E_USER_WARNING);
291  return FALSE;
292  }
293 
294  $d_height = round((int) $source_image_info['height'] * ($d_width / (int) $source_image_info['width']));
295  break;
296 
297  case 'height' :
298  if ($d_height <= 0) {
299  trigger_localised_error('CORE0006', E_USER_WARNING);
300  return FALSE;
301  }
302  $d_width = round((int) $source_image_info['width'] * ($d_height / (int) $source_image_info['height']));
303  break;
304 
305  case 'dimension' :
306  $old_width = (int) $source_image_info['width'];
307  $old_height = (int) $source_image_info['height'];
308  $proportion = 1;
309  if ($old_width > $old_height) {
310  $proportion = $d_dimension / $old_width;
311  } else {
312  $proportion = $d_dimension / $old_height;
313  }
314  $d_width = round($old_width * $proportion);
315  $d_height = round($old_height * $proportion);
316  break;
317  }
318 
319  if ($d_width <= 0 || $d_height <= 0) {
320  trigger_localised_error('CORE0005', E_USER_WARNING);
321  return FALSE;
322  }
323 
324  // if the filename has changed then we need to remove the old file
325  if ($d_old_filename != $d_new_filename) {
326  $this->deleteImage();
327 
328  } else {
329  if ($file_versioning) {
330  // make sure we have the latest version checked out if we are modifying the file
331  $up_to_date = $fv->upToDate($d_new_file);
332  if ($up_to_date & FUDGE_FV_OLD_VERSION) {
333  if (!$fv->checkOut($this->data_path_suffix.'/'.$d_new_filename, $this->data_path)) {
334  trigger_localised_error('COR0103', E_USER_WARNING);
335  return FALSE;
336  }
337  }
338  }
339 
340  }// endif
341 
342  require_once(SQ_FUDGE_PATH.'/image/image_manip.inc');
343  if (!Image_Manip::resize($s_file, $d_new_file, $d_width, $d_height)) {
344  return FALSE;
345  }
346 
347  if ($file_versioning) {
348  $up_to_date = $fv->upToDate($d_new_file);
349 
350  // file not in repository
351  if ($up_to_date & FUDGE_FV_NOT_CHECKED_OUT) {
352  if (!$fv->add($this->data_path_suffix, $d_new_file, '')) {
353  return FALSE;
354  }
355 
356  if (!$fv->checkOut($this->data_path_suffix.'/'.$d_new_filename, $this->data_path)) {
357  trigger_localised_error('COR0103', E_USER_WARNING);
358  return FALSE;
359  }
360 
361  } else if ($up_to_date & FUDGE_FV_MODIFIED) {
362  if (!$fv->commit($d_new_file, '', FALSE)) return FALSE;
363 
364  }
365  }
366 
367  // if the filename has changed then we need to upadte the look ups
368  if ($d_old_filename != $d_new_filename) {
369  if (!$this->setAttrValue('filename', $d_new_filename)) {
370  return FALSE;
371  }
372  }
373 
374  }//end if
375 
376  if (!$this->updateLookups($image->usePublicPath())) {
377  return FALSE;
378  }
379 
380  return TRUE;
381 
382  }//end updateImage()
383 
384 
391  function deleteImage()
392  {
393  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
394 
395  if (!is_dir($this->data_path)) return TRUE;
396 
397  $d_filename = $this->attr('filename');
398  $d_file = $this->data_path.'/'.$d_filename;
399 
400  if (empty($d_filename)) return TRUE;
401 
402  if (!$this->setAttrValue('filename', '')) return FALSE;
403 
404  // make sure we have the latest version checked out if we are modifying the file
405  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
406  $up_to_date = $fv->upToDate($d_file);
407 
408  $updated = $this->updateLookups(FALSE);
409  if (!$updated) return FALSE;
410 
411  // file not in repository, hmm, something must have gone wrong, let's see if there is a file there and remove it.
412  if (($up_to_date & FUDGE_FV_NOT_CHECKED_OUT)) {
413  if (file_exists($d_file)) {
414  if (!unlink($d_file)) return FALSE;
415  }
416 
417  } else {
418  if (!($fv->remove($d_file, '') & FUDGE_FV_OK)) {
419  trigger_localised_error('CORE0041', E_USER_WARNING, $d_filename);
420  return FALSE;
421  }
422 
423  }//end if
424 
425  return TRUE;
426 
427 
428  }//end deleteImage()
429 
430 
439  function checkFileState($public)
440  {
441  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
442 
443  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
444 
445  $filename = $this->attr('filename');
446  if (!$filename) return TRUE;
447  $unrestricted = $this->data_path_public.'/'.$filename;
448 
449  // if we should be storing our file in the public
450  // data directory for all the world to see
451  if ($public) {
452  // make sure our data directory exists
453  if (!create_directory($this->data_path_public)) {
454  return FALSE;
455  }
456 
457  // if there is no current file or if the current file is out of date, check out a fresh copy
458  if ($fv->upToDate($unrestricted) & (FUDGE_FV_NOT_CHECKED_OUT | FUDGE_FV_OLD_VERSION)) {
459  if (!$fv->checkOut($this->data_path_suffix.'/'.$filename, $this->data_path_public)) {
460  trigger_localised_error('COR0103', E_USER_WARNING);
461  return FALSE;
462  }
463  }
464  } else {
465  // need to make sure our file is in the NOT in the public data directory
466  if (is_file($unrestricted)) {
467  if (!$fv->clearOut($unrestricted) & FUDGE_FV_OK) {
468  trigger_localised_error('COR0104', E_USER_WARNING);
469  return FALSE;
470  }
471  }
472  }//end if
473 
474  return TRUE;
475 
476  }//end checkFileState()
477 
478 
485  protected function _removePublicFile()
486  {
487 
488  $filename = $this->attr('filename');
489  if (!$filename) return TRUE;
490 
491  $unrestricted = $this->data_path_public.'/'.$filename;
492  if (is_file($unrestricted)) {
493  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
494  if (!$fv->clearOut($unrestricted) & FUDGE_FV_OK) {
495  trigger_localised_error('COR0104', E_USER_WARNING);
496  return FALSE;
497  }
498  }
499 
500  return TRUE;
501 
502  }//end _removePublicFile()
503 
504 
512  protected function _updatePublicFile()
513  {
514  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
515 
516  $filename = $this->attr('filename');
517  if (!$filename) return TRUE;
518 
519  $unrestricted = $this->data_path_public.'/'.$filename;
520 
521  // make sure our data directory exists
522  if (!create_directory($this->data_path_public)) {
523  return FALSE;
524  }
525 
526  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
527  // if there is no current file or if the current file is out of date, check out a fresh copy
528  if ($fv->upToDate($unrestricted) & (FUDGE_FV_NOT_CHECKED_OUT | FUDGE_FV_OLD_VERSION)) {
529  if (!$fv->checkOut($this->data_path_suffix.'/'.$filename, $this->data_path_public)) {
530  trigger_localised_error('COR0103', E_USER_WARNING);
531  return FALSE;
532  }
533  }
534 
535  return TRUE;
536 
537  }//end _updatePublicFile()
538 
539 
547  function updateLookups()
548  {
549  // if we aren't meant to be having the public paths, let our parent run as normal
550  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
551  if (!empty($image)) {
552  $public = $image->usePublicPath();
553  }
554  if (!$public) return parent::updateLookups();
555 
556  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
557  $db = MatrixDAL::getDb();
558  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
559 
560  unset($this->_tmp['lookups']);
561  unset($this->_tmp['url']);
562  unset($this->_tmp['href']);
563 
564  // Remove all the old URLs
565  try {
566  $bind_vars = Array('assetid' => $this->id);
567  MatrixDAL::executeQuery('core', 'deleteLookup', $bind_vars);
568  } catch (DALException $e) {
569  throw new Exception('Unable to delete lookups of asset "'.$this->name.'" (#'.$this->id.') due to database error: '.$e->getMessage());
570  }
571 
572  $filename = $this->attr('filename');
573 
574  // if there is no filename there is nothing more for us to do
575  if (!$filename) {
576  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
577  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
578  return TRUE;
579  }
580 
581  $web_path = str_replace(sq_web_path('root_url').'/', '', $this->getWebDataPath()).'/'.$filename;
582 
583  // Basically what we are going to do here is find all our parents that are sites
584  // and take the system root urls that are closest to these site urls and tack on __data/... bit
585  $save_urls = Array();
586  $root_urls = explode("\n", trim(SQ_CONF_SYSTEM_ROOT_URLS));
587 
588  if (!SQ_CONF_STATIC_ROOT_URL == '') {
589  if (!$GLOBALS['SQ_SYSTEM']->am->assetInTrash($this->id, TRUE)){
590  // use the static root URL data
591  $web_path = str_replace(sq_web_path('data').'/', '', $web_path);
592  $save_urls[SQ_CONF_STATIC_ROOT_URL] = Array('http' => SQ_CONF_STATIC_ROOT_HTTP, 'https' => SQ_CONF_STATIC_ROOT_HTTPS);
593  }
594  } else {
595 
596  $site_parents = $GLOBALS['SQ_SYSTEM']->am->getParents($this->id, 'site', FALSE);
597  foreach ($site_parents as $assetid => $type_code) {
598  $site = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
599  if (is_null($site)) continue;
600  $urls = $site->getSiteURLS();
601 
602  foreach ($urls as $urlid => $data) {
603 
604  $root_url = '';
605 
606  foreach ($root_urls as $tmp_url) {
607  if (substr($data['url'], 0, strlen($tmp_url)) == $tmp_url) {
608  $root_url = $tmp_url;
609  continue;
610  }
611  }
612 
613  if (empty($root_url)) continue;
614 
615  if (isset($save_urls[$root_url])) {
616  if (empty($save_urls[$root_url]['http'])) {
617  $save_urls[$root_url]['http'] = $data['http'];
618  }
619  if (empty($save_urls[$root_url]['https'])) {
620  $save_urls[$root_url]['https'] = $data['https'];
621  }
622  } else {
623  $save_urls[$root_url] = Array('http' => $data['http'], 'https' => $data['https']);
624  }
625 
626  }//end foreach
627 
628  }//end foreach
629 
630  }//end else - if SQ_CONF_STATIC_ROOT_URL is not empty
631 
632  foreach ($save_urls as $url => $url_data) {
633 
634  try {
635  $bind_vars = Array(
636  'url' => $url.'/'.$web_path,
637  'assetid' => $this->id,
638  'http' => ($this->force_secure === '1') ? '0' : $url_data['http'],
639  'https' => ($this->force_secure === '-') ? '0' : $url_data['https'],
640  'root_urlid' => 0,
641  );
642 
643  MatrixDAL::executeQuery('core', 'insertLookup', $bind_vars);
644  } catch (DALException $e) {
645  throw new Exception('Unable to delete lookups of asset "'.$this->name.'" (#'.$this->id.') due to database error: '.$e->getMessage());
646  }
647 
648  // NOTE: we are not going to update the design's lookups because no
649  // designs can be attached to a file anyway (well not at this time)
650  // and it's one thing less to worry about updating for the moment
651 
652  }//end foreach
653 
654  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
655  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
656 
657  //Bug #5072: Trashed file assets still accessible via public data URL
658  //We only reached here because we are supposed to have a public web path but
659  //if we e.g. have moved to the trash or under a site with no URL, we should remove the public file.
660  if (empty($save_urls)){
661  $this->_removePublicFile();
662  } else {
663  $this->_updatePublicFile();
664  }
665 
666  return TRUE;
667 
668  }//end updateLookups()
669 
670 
679  function getWebDataPath()
680  {
681  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
682  if (is_null($image)) return FALSE;
683 
684  return $image->getWebDataPath().'/varieties';
685 
686  }//end getWebDataPath()
687 
688 
695  function getWebPaths()
696  {
697  $filename = $this->attr('filename');
698  if ($filename) {
699  return Array($filename);
700  } else {
701  return Array();
702  }
703 
704  }//end getWebPaths()
705 
706 
715  function paintBackend(&$o)
716  {
717  if (!isset($_REQUEST['asset_ei_screen'])) {
718  return parent::paintBackend($o);
719  }
720  switch ($_REQUEST['asset_ei_screen']) {
721  case 'image_info' :
722  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
723  if (is_null($image)) exit();
724 
725  include_once SQ_FUDGE_PATH.'/var_serialise/var_serialise.inc';
726 
727  $filename = $this->data_path.'/'.$this->attr('filename');
728  $size = getimagesize($filename);
729 
730  $ouput = Array();
731  $output['alt'] = $image->attr('alt');
732  $output['width'] = $size[0];
733  $output['height'] = $size[1];
734  $output['name'] = $this->name;
735  echo var_serialise($output);
736  exit();
737  default :
738  return parent::paintBackend($o);
739 
740  }//end switch
741 
742  }//end paintBackend()
743 
744 
751  function printFrontend()
752  {
753  // if we are in limbo, we want to show our editing interface and design
754  // instead of just sending our file over
755  // there is an exception to it: In Limbo, if we have ?a=<assetid> at the end of the URL
756  // and <assetid> value is different from the current asset assetid we are sending our file over
757  if (SQ_IN_LIMBO && !(isset($_REQUEST['a']) && $_REQUEST['a'] == $this->id)) {
758  return parent::printFrontend();
759  }
760 
761  if (!$this->readAccess()) {
762  $GLOBALS['SQ_SYSTEM']->paintLogin(translate('login'), translate('cannot_access_asset', $this->name));
763  return;
764  }
765 
766  $GLOBALS['SQ_SYSTEM']->setGlobalDefine('SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', FALSE);
767 
768  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
769  if (is_null($image)) return FALSE;
770 
771  if (($this->status & SQ_SC_STATUS_SAFE_EDITING) && ($GLOBALS['SQ_SYSTEM']->user instanceof Public_User)) {
772  if (is_file($image->data_path.'/varieties/sq_system_version_no')) {
773  include ($image->data_path.'/varieties/sq_system_version_no');
774  $file_version = isset($versions[$this->attr('filename')]) ? $versions[$this->attr('filename')] : NULL;
775  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
776  $rep_file = $this->data_path_suffix.'/'.$this->attr('filename');
777  $info = $fv->_checkOutCheck($rep_file, $file_version);
778 
779  $filename = $info['filename'];
780  $ext = get_file_type($filename);
781  $file = $info['source_file'];
782  }
783  } else {
784  $ext = get_file_type($image->name);
785  $filename = $this->name.'.'.$ext;
786  $file = $this->data_path.'/'.$filename;
787  }
788 
789  if (isset($file) && file_exists($file)) {
790  require_once SQ_FUDGE_PATH.'/standards_lists/mime_types.inc';
791  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
792  $type = (empty($standards_lists_mime_types[$ext])) ? 'text/plain' : $standards_lists_mime_types[$ext];
793 
794  // get protocol information
795  $ssl_connection = FALSE;
796  $url_info = parse_url(current_url());
797  $protocol = (isset($url_info['scheme'])) ? $url_info['scheme'] : NULL;
798  if (!is_null($protocol) && $protocol == 'https') {
799  $ssl_connection = TRUE;
800  }
801 
802  $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cache_manager');
803  $using_ie6 = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== FALSE;
804 
805  // send cacheable headers if file asset meets the credentials
806  if (basename($_SERVER['PHP_SELF']) != SQ_CONF_NOCACHE_SUFFIX && SQ_CONF_SEND_CACHEABLE_HEADER && ($GLOBALS['SQ_SYSTEM']->user instanceof Public_User) && empty($_POST) && $cm->cacheableHeadersEnabledForCurrentProtocol() && $this->status >= SQ_STATUS_LIVE && $this->readAccess()) {
807  header('Cache-Control: '.$cm->cacheControlLevel());
808  header('Pragma: cache');
809  header('Expires: '.gmdate('D, d M Y H:i:s', (time()+86400)).' GMT');
810  header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($file)).' GMT');
811  } else if (!$using_ie6 || !$ssl_connection) {
812  header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
813  header('Pragma: no-cache');
814  header('Expires: '.gmdate('D, d M Y H:i:s', time()-3600).' GMT');
815  } else {
816  // internet explorer has a problem with SSL connection (https)
817  // cant send no-cache header or we will get "cannot download file" error
818  // http://support.microsoft.com/default.aspx?scid=kb;en-us;812935
819  // http://support.microsoft.com/default.aspx?scid=kb;en-us;316431
820  header('Cache-Control: max-age=0, must-revalidate');
821  header('Pragma: private');
822  header('Expires: '.gmdate('D, d M Y H:i:s', time()-3600).' GMT');
823  }
824 
825  header('Content-Type: '.$type);
826  header('Content-Disposition: inline; filename='.$filename.';');
827  header('Content-Length: '.filesize($file));
828 
829  readfile($file);
830  @ob_flush();
831  }//end if
832 
833  }//end printFrontend()
834 
835 
849  function printImageTag($alt, $title, $return=FALSE)
850  {
851  $filename = $this->attr('filename');
852  if (!$filename) return;
853  $size = getimagesize($this->data_path.'/'.$filename);
854 
855  $tag = '<img src="'.$this->getURL().'" '.$size[3].' alt="'.$alt.'" title="'.$title.'" />';
856  if ($return) return $tag;
857  echo $tag;
858 
859  }//end printImageTag()
860 
861 
870  function getKeywordReplacement($keyword)
871  {
872  $replacement = NULL;
873 
874  // Remove any modifiers from keyword
875  $full_keyword = $keyword;
876  $keyword = parse_keyword($keyword, $modifiers);
877  $contextid = extract_context_modifier($modifiers);
878 
879  if ($contextid !== NULL) {
880  // If we were able to extract a context ID to change to, and it's
881  // different to our current one, then change and then reload a copy
882  // of the asset in that context (as we would need to do anyway)
883 
884  if ((int)$contextid !== $GLOBALS['SQ_SYSTEM']->getContextId()) {
885  $GLOBALS['SQ_SYSTEM']->changeContext($contextid);
886  $contexted_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->id);
887 
888  // Get the keyword without any modifiers
889  $replacement = $contexted_asset->getKeywordReplacement($keyword);
890 
891  // Then apply the ones we had remaining, then return it
892  apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $contexted_asset->id));
893 
894  unset($contexted_asset);
895  $GLOBALS['SQ_SYSTEM']->restoreContext();
896  return $replacement;
897 
898  }//end if contextid is not the currently active context
899 
900  }//end if contextid is not NULL
901 
902  // additional shadow asset keyword replacement
903  // Note: using the full keyword is NOT wanted here, since the modifiers
904  // are still being applied below.
905  $replacement = parent::getKeywordReplacement($keyword);
906  if (empty($replacement)) {
907  switch ($keyword) {
908  case 'asset_name_linked' :
909  $replacement = '<a href="'.$this->getUrl().'">'.$this->name.'</a>';
910  break;
911  case 'asset_contents' :
912  $replacement = $this->printImageTag($this->name, $this->name, TRUE);
913  break;
914  default :
915 
916  break;
917  }
918  }
919 
920  if (count($modifiers) > 0) {
921  apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $this->id));
922  }
923 
924  return $replacement;
925 
926  }//end getKeywordReplacement()
927 
928 
929 //-- PERMISSIONS/ACCESS (DEFERS TO IMAGE) --//
930 
931 
941  function readAccess($assetids=Array())
942  {
943  if (!$this->id) return TRUE;
944 
945  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
946  if (is_null($image)) return FALSE;
947 
948  return $image->readAccess($assetids);
949 
950  }//end readAccess()
951 
952 
965  function writeAccess($lock_type='', $assetids=Array())
966  {
967  if (!$this->id) return TRUE;
968 
969  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
970  if (is_null($image)) return FALSE;
971 
972  return $image->writeAccess($lock_type, $assetids);
973 
974  }//end writeAccess()
975 
976 
989  function adminAccess($lock_type='', $assetids=Array())
990  {
991  if (!$this->id) return TRUE;
992 
993  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
994  if (is_null($image)) return FALSE;
995 
996  return $image->adminAccess($lock_type, $assetids);
997 
998  }//end adminAccess()
999 
1000 
1013  function liveEditAccess($lock_type)
1014  {
1015  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
1016  if (is_null($image)) return FALSE;
1017 
1018  return $image->liveEditAccess($lock_type);
1019 
1020  }//end liveEditAccess()
1021 
1022 
1038  function checkAccess($perm, $lock_type, $assetids=Array())
1039  {
1040  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
1041  if (is_null($image)) return FALSE;
1042 
1043  return $image->checkAccess($perm, $lock_type, $assetids);
1044 
1045  }//end checkAccess()
1046 
1047 
1059  function _checkPermissionAccess($perm, $assetids=Array())
1060  {
1061  $image = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_imageid);
1062  if (is_null($image)) return FALSE;
1063 
1064  return $image->_checkPermissionAccess($perm, $assetids);
1065 
1066  }//end _checkPermissionAccess()
1067 
1068 
1069 }//end class
1070 
1071 ?>