Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
image.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/files/file/file.inc';
19 require_once SQ_DATA_PATH.'/private/conf/tools.inc';
20 require_once SQ_CORE_PACKAGE_PATH.'/interfaces/bridge/bridge.inc';
21 
22 
34 class Image extends File implements Bridge
35 {
36 
41  var $allowed_extensions = Array('gif', 'jpg', 'jpeg', 'png');
42 
43 
50  function Image($assetid=0)
51  {
52  $this->_ser_attrs = TRUE;
53  parent::__construct($assetid);
54 
55  }//end constructor
56 
57 
83  function cloneComponents(&$clone, $components, $override=FALSE)
84  {
85  // need to go through the varieties that have already been added, and
86  // re-upload/create them underneath this asset - to get the file
87  // versioning correct
88 
89  if (in_array('attributes', $components) || in_array('all', $components)) {
90 
91  $varieties = $this->attr('varieties');
92  $old_base_path = $this->data_path.'/varieties';
93  $new_base_path = $clone->data_path.'/varieties';
94 
95  create_directory($new_base_path);
96 
97  // file versioning magick :D
98  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
99 
100  if (isset($varieties['data']) && is_array($varieties['data'])) {
101  foreach ($varieties['data'] as $variety_shadowid => $variety) {
102  $old_variety_path = $old_base_path.'/'.$variety['filename'];
103  $new_variety_path = $new_base_path.'/'.$variety['filename'];
104 
105  if (!copy($old_variety_path, $new_variety_path)) {
106  trigger_localised_error('CORE0036', E_USER_WARNING, $old_variety_path, $new_variety_path);
107  return FALSE;
108  }
109 
110  if (!$fv->add($clone->data_path_suffix.'/varieties', $new_variety_path)) {
111  return FALSE;
112  }
113 
114  if (!$fv->checkOut($clone->data_path_suffix.'/varieties/'.$variety['filename'], $clone->data_path.'/varieties')) {
115  trigger_localised_error('CORE0103', E_USER_WARNING);
116  return FALSE;
117  }
118  }
119  }
120  }//end if attributes|all
121 
122  return parent::cloneComponents($clone, $components, $override);
123 
124  }//end cloneComponents()
125 
126 
134  public function saveSystemVersion()
135  {
136  if (!parent::saveSystemVersion()) return FALSE;
137 
138  $varieties = $this->attr('varieties');
139  if (!empty($varieties['lookups'])) {
140  // make sure our varieties system directory exists
141  if (!create_directory($this->data_path.'/.sq_system/varieties')) {
142  trigger_localised_error('CORE0050', E_USER_WARNING, $this->name);
143  return FALSE;
144  }
145 
146  // make sure there is nothing in the varieties system directory
147  if (!clear_directory($this->data_path.'/.sq_system/varieties')) {
148  trigger_localised_error('CORE0046', E_USER_WARNING, $this->name);
149  return FALSE;
150  }
151 
152  // store the current version of each image variety file
153  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
154  $versions = Array();
155 
156  foreach ($varieties['lookups'] as $varietyid) {
157  $variety = $this->getAsset($this->id.':'.$varietyid);
158  if (is_null($variety)) continue;
159 
160  $file_info = $fv->_checkOutCheck($variety->data_path_suffix.'/'.$variety->attr('filename'));
161  $versions[$variety->attr('filename')] = $file_info['version'];
162  }//end foreach
163 
164  if (!array_to_file($versions, 'versions', $this->data_path.'/.sq_system/varieties/sq_system_version_no')) {
165  trigger_localised_error('CORE0051', E_USER_WARNING, $this->name);
166  return FALSE;
167  }
168  }// end if
169 
170  return TRUE;
171 
172  }//end saveSystemVersion()
173 
174 
181  public function revertToSystemVersion()
182  {
183  //grab version info first before it is cleared
184  if (is_file($this->data_path.'/.sq_system/varieties/sq_system_version_no')) {
185  include ($this->data_path.'/.sq_system/varieties/sq_system_version_no');
186  }
187 
188  if (!parent::revertToSystemVersion()) return FALSE;
189 
190  $varieties = $this->attr('varieties');
191  if (!empty($varieties['lookups'])) {
192  // make sure our varieties directory exists
193  if (!create_directory($this->data_path.'/varieties')) {
194  trigger_localised_error('CORE0049', E_USER_WARNING, $this->name);
195  return FALSE;
196  }
197 
198  // make sure our varieties directory is clear
199  if (!clear_directory($this->data_path.'/varieties')) {
200  trigger_localised_error('CORE0045', E_USER_WARNING, $this->name);
201  return FALSE;
202  }
203 
204  foreach ($varieties['lookups'] as $varietyid) {
205  $variety = $this->getAsset($this->id.':'.$varietyid);
206  if (is_null($variety)) continue;
207 
208  $file_version = isset($versions[$variety->attr('filename')]) ? $versions[$variety->attr('filename')] : NULL;
209  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
210 
211  // check out the old version of the file into the private data directory
212  $rep_path = $variety->data_path_suffix.'/'.$variety->attr('filename');
213  if (!$fv->checkOut($rep_path, $variety->data_path, $file_version)) {
214  trigger_localised_error('CORE0044', E_USER_WARNING, $variety->attr('filename'));
215  return FALSE;
216  }
217 
218  // create a new versioning entry for the old version
219  $file_info = $fv->_checkOutCheck($rep_path, $file_version);
220  $fv->_updateFile($file_info['fileid'], $variety->data_path_suffix, $variety->data_path.'/'.$variety->attr('filename'));
221 
222  // check out the new version
223  if (!$fv->checkOut($rep_path, $variety->data_path)) {
224  trigger_localised_error('CORE0044', E_USER_WARNING, $variety->attr('filename'));
225  return FALSE;
226  }
227 
228  }//end foreach
229  }
230 
231  return TRUE;
232 
233  }//end revertToSystemVersion()
234 
235 
242  function getExistingFile()
243  {
244  $info = parent::getExistingFile();
245  if (!empty($info['path'])) {
246  $size = getimagesize($info['path']);
247  $info['width'] = $size[0];
248  $info['height'] = $size[1];
249  }
250 
251  return $info;
252 
253  }//end getExistingFile()
254 
255 
269  function printImageTag($alt='', $title='', $return=FALSE)
270  {
271  if ($title == '') {
272  $title = ($alt != '') ? $alt : $this->attr('title');
273  }
274  if ($alt == '') $alt = $this->attr('alt');
275 
276  $tag = '<img src="'.$this->getURL().'" width="'.$this->attr('width').'" height="'.$this->attr('height').'" alt="'.htmlentities($alt).'" title="'.htmlentities($title).'" />';
277  if ($return) return $tag;
278  echo $tag;
279 
280  }//end printImageTag()
281 
282 
291  function paintBackend(&$o)
292  {
293  if (!isset($_REQUEST['asset_ei_screen'])) {
294  return parent::paintBackend($o);
295  }
296 
297  switch ($_REQUEST['asset_ei_screen']) {
298  case 'image_info' :
299  include_once SQ_FUDGE_PATH.'/var_serialise/var_serialise.inc';
300  $output = Array();
301  $output['alt'] = $this->attr('alt');
302  $output['width'] = $this->attr('width');
303  $output['height'] = $this->attr('height');
304  $output['caption'] = $this->attr('caption');
305  $output['name'] = $this->name;
306 
307  echo var_serialise($output);
308  exit();
309  default :
310  return parent::paintBackend($o);
311 
312  }//end switch
313 
314  }//end paintBackend()
315 
316 
317 //-- VARIETIES --//
318 
319 
338  function saveVariety($variety, $recreate_image=TRUE, $save_attrs=TRUE, $file_versioning=TRUE, $check_write_access=TRUE)
339  {
340  if ($check_write_access && !$this->writeAccess('attributes')) {
341  trigger_localised_error('CORE0069', E_USER_WARNING, $this->name, $this->id);
342  return FALSE;
343 
344  }
345 
346  // use attr() instead of just ->name because if the variety hasn't been created yet it won't have a name
347  $name = $variety->attr('name');
348  if (trim($name) == '') {
349  trigger_localised_error('CORE0100', E_USER_WARNING);
350  return FALSE;
351 
352  }
353 
354  $varieties = $this->attr('varieties');
355 
356  // check if this is already one of our varieties
357  if ($variety->id) {
358  list($assetid, $varietyid) = explode(':', $variety->id, 2);
359  if ($assetid != $this->id) {
360  trigger_localised_error('CORE0099', E_USER_WARNING);
361  return FALSE;
362 
363  }
364 
365  if (isset($varieties['data'][$varietyid])) {
366  if ($varieties['data'][$varietyid]['name'] != $name) {
367  trigger_localised_error('CORE0097', E_USER_WARNING, $varietyid);
368  return FALSE;
369 
370  }
371  } else {
372  trigger_localised_error('CORE0098', E_USER_WARNING, $varietyid, $this->name, $this->id);
373  return FALSE;
374 
375  }
376 
377  } else {
378 
379  if (isset($varieties['lookups'][$name])) {
380  $varietyid = $varieties['lookups'][$name];
381  } else {
382  $varietyid = 'v'.$this->attr('variety_count');
383  if (!isset($varieties['lookups'])) {
384  $varieties['lookups'] = Array();
385  }
386  $varieties['lookups'][$name] = $varietyid;
387 
388  if (!$this->setAttrValue('variety_count', $this->attr('variety_count') + 1)) {
389  return FALSE;
390  }
391 
392  }
393 
394  }//end if
395 
396  if (!isset($varieties['data'])) {
397  $varieties['data'] = Array();
398  }
399  $varieties['data'][$varietyid] = Array();
400  foreach ($variety->vars as $attr_name => $attr_data) {
401  $varieties['data'][$varietyid][$attr_name] = $attr_data['value'];
402  }
403 
404  if (!$this->setAttrValue('varieties', $varieties)) {
405  return FALSE;
406  }
407 
408  $variety = $this->getAsset($this->id.':'.$varietyid);
409  if (is_null($variety)) return FALSE;
410 
411  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
412  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
413 
414  // create the actual scaled image if necessary and add any lookups
415  if ($recreate_image) {
416  if (!$variety->updateImage($file_versioning)) {
417  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
418  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
419  return FALSE;
420 
421  }
422 
423  // Now get the variables again because updateImage() can update stuff
424  foreach ($variety->vars as $attr_name => $attr_data) {
425  $varieties['data'][$varietyid][$attr_name] = $attr_data['value'];
426  }
427  if (!$this->setAttrValue('varieties', $varieties)) {
428  return FALSE;
429  }
430  }
431 
432  if ($save_attrs && !$this->saveAttributes()) {
433  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
434  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
435  return FALSE;
436  }
437 
438  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
439  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
440  return $varietyid;
441 
442  }//end saveVariety()
443 
444 
453  function deleteVariety($varietyid)
454  {
455  if (!$this->writeAccess('attributes')) {
456  trigger_localised_error('CORE0070', E_USER_WARNING, $this->name, $this->id);
457  return FALSE;
458  }
459 
460  if (strpos($varietyid, ':') !== FALSE) {
461  list($assetid, $varietyid) = explode(':', $varietyid, 2);
462  if ($assetid != $this->id) {
463  trigger_localised_error('CORE088', E_USER_WARNING);
464  return FALSE;
465  }
466  }
467 
468  $variety = $this->getAsset($this->id.':'.$varietyid);
469  if (is_null($variety)) return FALSE;
470 
471  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
472  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
473 
474  // delete the actual scaled image files
475  if (!$variety->deleteImage()) {
476  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
477  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
478  return FALSE;
479  }
480 
481  $varieties = $this->attr('varieties');
482 
483  if (!isset($varieties['data'][$varietyid])) {
484  trigger_localised_error('CORE87', $varietyid, E_USER_WARNING);
485  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
486  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
487  return FALSE;
488  }
489 
490  unset($varieties['data'][$varietyid]);
491  $lookup_name = array_search($varietyid, $varieties['lookups']);
492  if ($lookup_name !== FALSE) {
493  unset($varieties['lookups'][$lookup_name]);
494  }
495 
496  if (!$this->setAttrValue('varieties', $varieties) || !$this->saveAttributes()) {
497  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
498  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
499  return FALSE;
500  }
501 
502  if (!$this->updateLookups()) {
503  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
504  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
505  return FALSE;
506  }
507 
508  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
509  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
510  return TRUE;
511 
512  }//end deleteVariety()
513 
514 
515 //-- VARIETY FILES --//
516 
517 
524  protected function _checkFileState()
525  {
526  if ($this->status & SQ_SC_STATUS_SAFE_EDITING) return TRUE; //don't touch public file in safe edit
527 
528  $varieties = $this->attr('varieties');
529  if (!empty($varieties)) {
530  foreach ($varieties['lookups'] as $varietyid) {
531  $variety = $this->getAsset($this->id.':'.$varietyid);
532  if (is_null($variety)) continue;
533 
534  if (!$variety->checkFileState($this->effectiveUnrestricted() && $this->attr('allow_unrestricted'))) {
535  return FALSE;
536  }
537  }
538  }
539 
540  return parent::_checkFileState();
541 
542  }//end _checkFileState()
543 
544 
552  function updateLookups($auto_add_remaps = TRUE)
553  {
554  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
555  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
556 
557  if (!parent::updateLookups($auto_add_remaps)) {
558  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
559  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
560  return FALSE;
561  }
562 
563  $varieties = $this->attr('varieties');
564  if (!empty($varieties)) {
565  foreach ($varieties['lookups'] as $varietyid) {
566  $variety = $this->getAsset($this->id.':'.$varietyid);
567  if (is_null($variety)) continue;
568 
569  if (!$variety->updateLookups()) {
570  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
571  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
572  return FALSE;
573  }
574 
575  }//end foreach
576  }// end if
577 
578  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
579  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
580  return TRUE;
581 
582  }//end updateLookups()
583 
584 
585 //-- BRIDGE INTERFACE --//
586 
587 
603  function getAsset($assetid, $type_code='', $mute_errors=FALSE)
604  {
605  $asset = NULL;
606  $id_parts = explode(':', $assetid);
607 
608  if (isset($id_parts[1])) {
609  $shadowid = $id_parts[1];
610  } else {
611  return $asset;
612  }
613 
614  // Varieties are preceded with a 'v'
615  if ($shadowid{0} == 'v') {
616 
617  $varieties = $this->attr('varieties');
618 
619  if (!isset($varieties['data'][$shadowid])) {
620  if(!$mute_errors) {
621  trigger_localised_error('CORE0073', E_USER_WARNING, $this->id, $shadowid);
622  }
623  return $asset;
624  }
625 
626  $GLOBALS['SQ_SYSTEM']->am->includeAsset('image_variety');
627  $asset = new Image_Variety($this->id.':'.$shadowid, $varieties['data'][$shadowid]);
628 
629  }//end if
630 
631  return $asset;
632 
633  }//end getAsset()
634 
635 
656  function getLinks($assetid, $link_types, $type_code='', $strict_type_code=TRUE, $side_of_link='major', $sort_by=NULL)
657  {
658  // only TYPE_2 links are ever returned
659  if (!($link_types & SQ_LINK_TYPE_2)) {
660  return Array();
661  }
662 
663  // we can check the type codes outside the loop because they are only ever going to be a single type
664  if ($type_code) {
665  // if we are looking for children, they will be image_variety,
666  // if we are looking for parent, they will whatever this class is
667  $ret_type_code = ($side_of_link == 'major') ? 'image_variety' : $this->type();
668  if ($strict_type_code) {
669  if (is_array($type_code)) {
670  if (!in_array($ret_type_code, $type_code)) {
671  return Array();
672  }
673  } else {
674  if ($ret_type_code != $type_code) return Array();
675  }
676  } else {
677  $descendants = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE);
678  if (!in_array($ret_type_code, $descendants)) {
679  return Array();
680  }
681  }
682 
683  }//end if type_code
684 
685  if (!isset($this->_tmp['getLinks'][$assetid][$side_of_link])) {
686 
687  $links = Array();
688  $varieties = $this->attr('varieties');
689 
690  if (!empty($varieties)) {
691 
692  // if we are looking from this asset and not a shadow asset
693  if ($this->id == $assetid) {
694  if ($side_of_link == 'minor') {
695  // should never happen...but anyway
696  trigger_localised_error('CORE0089', E_USER_ERROR);
697 
698  } else {
699  $i = 0;
700  foreach ($varieties['data'] as $varid => $data) {
701  $links[] = Array(
702  'linkid' => 0,
703  'minorid' => $this->id.':'.$varid,
704  'minor_type_code' => 'image_variety',
705  'majorid' => $this->id,
706  'value' => '',
707  'link_type' => SQ_LINK_TYPE_2,
708  'is_dependant' => TRUE,
709  'is_exclusive' => TRUE,
710  'sort_order' => $i,
711  'locked' => 0,
712  );
713  $i++;
714  }// end foreach
715 
716  }// endif
717 
718 
719  // looking from shadow asset
720  } else {
721 
722  // because the varieties are only ever going to be one level down
723  // if we are looking up the tree all we can see is this image asset
724  if ($side_of_link == 'minor') {
725  list(,$shadowid) = explode(':', $assetid);
726 
727  if (!isset($varieties['data'][$shadowid])) {
728  trigger_localised_error('CORE0074', E_USER_WARNING, $assetid, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->type(), 'name'), $this->id);
729  return Array();
730 
731  } else {
732  $links[] = Array(
733  'linkid' => 0,
734  'majorid' => $this->id,
735  'major_type_code' => $this->type(),
736  'value' => '',
737  'link_type' => SQ_LINK_TYPE_2,
738  'is_dependant' => TRUE,
739  'is_exclusive' => TRUE,
740  'sort_order' => array_search($assetid, array_keys($varieties['data'])),
741  'locked' => 0,
742  );
743  }//endif
744 
745  // because the varieties are only ever going to be one level down
746  // if we are looking down the tree there will be nothing
747  } else {
748  $links = Array();
749 
750  }//endif
751 
752  }//end else - looking from shadow asset
753 
754  if (!is_null($sort_by)) {
755  uasort($links, create_function('$a,$b', 'return $a["'.$sort_by.'"] < $b["'.$sort_by.'"];'));
756  }
757 
758  }//end if
759 
760  $this->_tmp['getLinks'][$assetid][$side_of_link] = $links;
761 
762  }//end if
763 
764  return $this->_tmp['getLinks'][$assetid][$side_of_link];
765 
766  }//end getLinks()
767 
768 
790  function getChildren($assetid, $type_code='', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
791  {
792  // if this is a shadow asset, then it has no children
793  if (!is_numeric($assetid)) return Array();
794 
795  // we can check the type codes outside the loop because they are only ever going to be a single type
796  if ($type_code) {
797 
798  $ret_type_code = 'image_variety';
799  if ($strict_type_code) {
800  if (is_array($type_code)) {
801  if (!in_array($ret_type_code, $type_code)) {
802  return Array();
803  }
804  } else {
805  if ($ret_type_code != $type_code) return Array();
806  }
807  } else {
808  $descendants = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE);
809  if (!in_array($ret_type_code, $descendants)) {
810  return Array();
811  }
812  }
813 
814  }//end if type_code
815 
816  $children = Array();
817 
818  $varieties = $this->attr('varieties');
819  if (!empty($varieties)) {
820  foreach ($varieties['data'] as $varid => $data) {
821  $children[$this->id.':'.$varid] = Array(Array('type_code' => 'image_variety'));
822  }// end foreach
823  }
824 
825  return $children;
826 
827  }//end getChildren()
828 
829 
845  function getParents($assetid, $type_code='', $strict_type_code=TRUE)
846  {
847  if ($assetid == $this->id || strpos($assetid, ':v') === FALSE) {
848  // should never happen...but anyway
849  trigger_localised_error('CORE0090', E_USER_ERROR);
850  }
851 
852  $parents = $GLOBALS['SQ_SYSTEM']->am->getParents($this->id, $type_code, $strict_type_code);
853 
854  // Now add this class only if it is a valid type code
855  if ($type_code) {
856 
857  $ret_type_code = $this->type();
858  if ($strict_type_code) {
859  if (is_array($type_code)) {
860  if (!in_array($ret_type_code, $type_code)) {
861  return $parents;
862  }
863  } else {
864  if ($ret_type_code != $type_code) return $parents;
865  }
866  } else {
867  $descendants = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type_code, TRUE);
868  if (!in_array($ret_type_code, $descendants)) {
869  return $parents;
870  }
871  }
872 
873  }//end if type_code
874 
875  $parents[] = $this->id;
876 
877  return $parents;
878 
879  }//end getParents()
880 
881 
888  function printBody()
889  {
890  $this->printImageTag();
891 
892  }//end printBody()
893 
894 
910  {
911  $keywords = parent::getAvailableKeywords();
912 
913  $varieties = $this->attr('varieties');
914  if (!empty($varieties)) {
915  foreach ($varieties['lookups'] as $varietyid) {
916  $variety = $this->getAsset($this->id.':'.$varietyid);
917  if (is_null($variety)) continue;
918  $keywords['image_v_'.$variety->name] = 'Image variety '.$variety->name;
919  $keywords['image_v_'.$variety->name.'_url'] = 'Image variety '.$variety->name.' URL';
920  $keywords['image_v_'.$variety->name.'_width'] = 'Image variety '.$variety->name.' Width';
921  $keywords['image_v_'.$variety->name.'_height'] = 'Image variety '.$variety->name.' Height';
922  }
923  }
924  $keywords['image_width'] = 'Width of the image in pixels';
925  $keywords['image_height'] = 'Height of the image in pixels';
926  $keywords['image_tag'] = 'HTML IMG tag to display this image';
927 
928  $embedded_data = $this->attr('embedded_data');
929  if (!empty($embedded_data)) {
930  foreach ($embedded_data as $keyword => $value_set) {
931  if (empty($value_set)) continue;
932 
933  $keywords['image_embedded_'.$keyword] = 'Embedded Data: "'.$value_set['name'].'"';
934  }
935  }
936 
937  return $keywords;
938 
939  }//end getAvailableKeywords()
940 
941 
949  {
950  return $this->attr('width');
951 
952  }//end getImageWidthKeywordReplacement()
953 
954 
962  {
963  return $this->attr('height');
964 
965  }//end getImageHeightKeywordReplacement()
966 
967 
975  {
976  return $this->printImageTag('', '', TRUE);
977 
978  }//end getImageTagKeywordReplacement()
979 
980 
995  function getKeywordReplacement($keyword)
996  {
997  $replacement = NULL;
998 
999  // Remove any modifiers from keyword...saving the full keyword for
1000  // later in case we have to pass it to the parent asset type
1001  $full_keyword = $keyword;
1002  $keyword = parse_keyword($keyword, $modifiers);
1003  $contextid = extract_context_modifier($modifiers);
1004 
1005  if ($contextid !== NULL) {
1006  // If we were able to extract a context ID to change to, and it's
1007  // different to our current one, then change and then reload a copy
1008  // of the asset in that context (as we would need to do anyway)
1009 
1010  if ((int)$contextid !== $GLOBALS['SQ_SYSTEM']->getContextId()) {
1011  $GLOBALS['SQ_SYSTEM']->changeContext($contextid);
1012  $contexted_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->id);
1013 
1014  // Get the keyword without any modifiers
1015  $replacement = $contexted_asset->getKeywordReplacement($keyword);
1016 
1017  // Then apply the ones we had remaining, then return it
1018  apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $contexted_asset->id));
1019 
1020  unset($contexted_asset);
1021  $GLOBALS['SQ_SYSTEM']->restoreContext();
1022  return $replacement;
1023 
1024  }//end if contextid is not the currently active context
1025 
1026  }//end if contextid is not NULL
1027 
1028  if (0 === strpos($keyword, 'image_v_')) {
1029  $varieties = $this->attr('varieties');
1030  if (empty($varieties)) return '';
1031  $variety_name = substr($keyword, 8);
1032  $url_only = FALSE;
1033  if (substr($variety_name, -4) == '_url') {
1034  $variety_name = substr($variety_name, 0, strlen($variety_name) - 4);
1035  $url_only = TRUE;
1036  } else if (substr($variety_name, -6) == '_width') {
1037  $variety_name = substr($variety_name, 0, strlen($variety_name) - 6);
1038  $size = $this->_varietyImageSize($variety_name);
1039  if (isset($size[0])) $replacement = $size[0];
1040  } else if (substr($variety_name, -7) == '_height') {
1041  $variety_name = substr($variety_name, 0, strlen($variety_name) - 7);
1042  $size = $this->_varietyImageSize($variety_name);
1043  if (isset($size[1])) $replacement = $size[1];
1044  }
1045  $variety_id = array_get_index($varieties['lookups'], $variety_name);
1046  if (!empty($variety_id) && !$replacement) {
1047  $variety = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->id.':'.$variety_id);
1048  if ($url_only) {
1049  $string = $variety->getURL();
1050  } else {
1051  $string = $variety->printImageTag($this->attr('alt'), $this->attr('title'), TRUE);
1052  }
1053  $replacement = $string;
1054  }
1055  } else if (0 === strpos($keyword, 'image_embedded_')) {
1056  $embedded_key = substr($keyword, strlen('image_embedded_'));
1057  $replacement = $this->_getEmbeddedKeywordReplacement($embedded_key);
1058  }
1059 
1060  if ($replacement !== NULL) {
1061  if (count($modifiers) > 0) {
1062  apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $this->id));
1063  }
1064  } else {
1065  // Use the full keyword to send up, so modifiers still get respected
1066  $replacement = parent::getKeywordReplacement($full_keyword);
1067  }
1068 
1069  return $replacement;
1070 
1071  }//end getKeywordReplacement()
1072 
1073 
1082  function _varietyImageSize($variety_name)
1083  {
1084  $varieties = $this->attr('varieties');
1085  if (isset($varieties['data'][$varieties['lookups'][$variety_name]]['filename'])) {
1086  $filename = $varieties['data'][$varieties['lookups'][$variety_name]]['filename'];
1087  $varietyid = $varieties['lookups'][$variety_name];
1088  $variety = $this->getAsset($this->id.':'.$varietyid);
1089 
1090  if ($this->useSystemVersion()) {
1091  if (is_file($this->data_path.'/varieties/sq_system_version_no')) {
1092  include ($this->data_path.'/varieties/sq_system_version_no');
1093  }
1094  $file_version = isset($versions[$filename]) ? $versions[$filename] : NULL;
1095  $fv = $GLOBALS['SQ_SYSTEM']->getFileVersioning();
1096  $rep_path = $variety->data_path_suffix.'/'.$filename;
1097  if (!$fv->checkOut($rep_path, $variety->data_path, $file_version)) {
1098  trigger_localised_error('CORE0044', E_USER_WARNING, $variety->attr('filename'));
1099  return FALSE;
1100  }
1101 
1102  // create a new versioning entry for the old version
1103  $file_info = $fv->_checkOutCheck($rep_path, $file_version);
1104  $size = getimagesize($file_info['source_file']);
1105  } else {
1106  $size = getimagesize($this->data_path.'/varieties/'.$filename);
1107  }
1108 
1109  return $size;
1110  }
1111 
1112  }//end _varietyImageSize()
1113 
1114 
1124  {
1125  $replacement = '';
1126 
1127  $embedded_data = $this->attr('embedded_data');
1128  $data_set = array_get_index($embedded_data, $keyword);
1129  if (is_null($data_set)) return $replacement;
1130 
1131  $replacement = implode(',', $data_set['value']);
1132 
1133  return $replacement;
1134 
1135  }//end _getEmbeddedKeywordReplacement()
1136 
1137 
1148  function getLineageFromURL($assetid, $protocol, $url)
1149  {
1150  return Array();
1151 
1152  }//end getLineageFromURL()
1153 
1154 
1175  function getPermission($assetid, $permission, $granted=NULL, $and_greater=TRUE, $expand_groups=FALSE, $all_info=FALSE)
1176  {
1177  return Array();
1178 
1179  }//end getPermission()
1180 
1181 
1193  function setPermission($assetid, $userid, $permission, $granted)
1194  {
1195  return FALSE;
1196 
1197  }//end setPermission()
1198 
1199 
1210  function deletePermission($assetid, $userid, $permission)
1211  {
1212  return FALSE;
1213 
1214  }//end deletePermission()
1215 
1216 
1231  function getAssetInfo($assetids, $type_code=Array(), $strict_type_code=TRUE, $field='')
1232  {
1233  $info = Array();
1234  foreach ($assetids as $assetid) {
1235  $asset = $this->getAsset($assetid, '', TRUE);
1236 
1237  // Only add if there is an asset to get info for
1238  if ($asset !== NULL) {
1239  if (!empty($field)) {
1240  if ($field == 'assetid') {
1241  $info[$assetid] = $assetid;
1242  } else if ($field == 'type_code') {
1243  $info[$assetid] = $asset->type();
1244  } else if (in_array($field , Array('version', 'name', 'short_name', 'status'))) {
1245  $info[$assetid] = $asset->$field;
1246  } else {
1247  $info[$assetid] = $this->$field;
1248  }
1249  } else {
1250  $info[$assetid] = Array(
1251  'assetid' => $assetid,
1252  'type_code' => $asset->type(),
1253  'version' => $asset->version,
1254  'name' => $asset->name,
1255  'short_name' => $asset->short_name,
1256  'status' => $asset->status,
1257  'languages' => $asset->languages,
1258  'charset' => $asset->charset,
1259  'force_secure' => $this->force_secure,
1260  'created' => $asset->created,
1261  'created_userid' => $asset->created_userid,
1262  'updated' => $asset->updated,
1263  'updated_userid' => $asset->updated_userid,
1264  'published' => $asset->published,
1265  'published_userid' => $asset->published_userid,
1266  'status_changed' => $asset->status_changed,
1267  'status_changed_userid' => $asset->status_changed_userid,
1268  );
1269  }
1270 
1271  }
1272 
1273  }//end foreach
1274 
1275  return $info;
1276 
1277  }//end getAssetInfo()
1278 
1279 
1291  function assetExists($assetids)
1292  {
1293  return FALSE;
1294 
1295  }//end assetExists()
1296 
1297 
1319  function getLink($assetid, $link_type=NULL, $type_code='', $strict_type_code=TRUE, $value=NULL, $side_of_link='major', $exclusive=NULL)
1320  {
1321  return Array();
1322 
1323  }//end getLink()
1324 
1325 
1337  function getLinkById($linkid, $assetid=0, $side_of_link='major')
1338  {
1339  return Array();
1340 
1341  }//end getLinkById()
1342 
1343 
1365  function countLinks($assetid, $side_of_link='major', $link_types=0, $type_code='', $strict_type_code=TRUE, $ignore_linkid=0)
1366  {
1367  return 0;
1368 
1369  }//end countLinks()
1370 
1371 
1392  function getLinkByAsset($assetid, $other_assetid, $link_types=NULL, $value=NULL, $side_of_link='major', $force_array=FALSE, $dependant=NULL, $exclusive=NULL)
1393  {
1394  return Array();
1395 
1396  }//end getLinkByAsset()
1397 
1398 
1408  function getAllChildLinks($assetid, $link_type=0)
1409  {
1410  return Array();
1411 
1412  }//end getAllChildLinks()
1413 
1414 
1429  function updateLink($linkid, $link_type=NULL, $value=NULL, $sort_order=NULL)
1430  {
1431  return FALSE;
1432 
1433  }//end updateLink()
1434 
1435 
1445  function deleteAssetLink($linkid, $moving=FALSE)
1446  {
1447  return FALSE;
1448 
1449  }//end deleteAssetLink()
1450 
1451 
1468  function createAssetLink(&$major, &$minor, $link_type, $value='', $sort_order=NULL, $dependant='0', $exclusive='0', $moving=FALSE)
1469  {
1470  return 0;
1471 
1472  }//end createAssetLink()
1473 
1474 
1483  function getAssetMapAssetInfo($assetid)
1484  {
1485  return Array();
1486 
1487  }//end getAssetMapAssetInfo()
1488 
1489 
1498  public function validFile(Array $info)
1499  {
1500  if (!parent::validFile($info)) {
1501  return FALSE;
1502  }
1503 
1504  if (getimagesize($info['path']) === FALSE) {
1505  trigger_error('Uploaded file is not a valid image file', E_USER_WARNING);
1506  return FALSE;
1507  }
1508 
1509  return TRUE;
1510 
1511  }//end validFile()
1512 
1513 
1514 }//end class
1515 
1516 ?>