Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
image_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
40  function Image_Management(&$pm)
41  {
42  $this->Asset_Management($pm);
43 
44  $this->vars = Array(
45  'alt' => Array(
46  'added' => '0.2',
47  'type' => 'text',
48  'default' => '',
49  'description' => 'The text to be used in the Alt attribute of the IMG tag',
50  'is_admin' => FALSE,
51  'is_contextable' => TRUE,
52  ),
53  'caption' => Array(
54  'added' => '0.2',
55  'type' => 'text',
56  'default' => '',
57  'description' => 'Some text to be associated with the image and can be accessed and printed out separately if required',
58  'is_admin' => FALSE,
59  'is_contextable' => TRUE,
60  ),
61  'width' => Array(
62  'added' => '0.2',
63  'type' => 'int',
64  'default' => 0,
65  'description' => 'Width of the image (generated from the image file)',
66  'is_admin' => FALSE,
67  ),
68  'height' => Array(
69  'added' => '0.2',
70  'type' => 'int',
71  'default' => 0,
72  'description' => 'Height of the image (generated from the image file)',
73  'is_admin' => FALSE,
74  ),
75  'size' => Array(
76  'added' => '0.2',
77  'type' => 'int',
78  'default' => 0,
79  'description' => 'Size (in bytes) of the image (generated from the image file)',
80  'is_admin' => FALSE,
81  ),
82  'varieties' => Array(
83  'added' => '0.3',
84  'type' => 'serialise',
85  'default' => Array(),
86  'is_admin' => TRUE,
87  ),
88  'variety_count' => Array(
89  'added' => '0.3',
90  'type' => 'int',
91  'default' => 1,
92  'is_admin' => TRUE,
93  ),
94  'embedded_data' => Array(
95  'added' => '0.4',
96  'type' => 'serialise',
97  'default' => Array(),
98  'description' => 'Embedded Metadata placed by Photoshop',
99  'is_admin' => TRUE,
100  ),
101  );
102 
103 
104  }//end constructor
105 
106 
115  function _upgrade($current_version)
116  {
117  if (!parent::_upgrade($current_version)) return FALSE;
118 
119  $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(), 'name'));
120 
121  if (version_compare($current_version, '0.2', '<')) {
122  // version 0.1 -> 0.2
123  // Added the attributes of which alt, title, width, height, size need to be set
124  pre_echo('STARTING '.$asset_name.' UPGRADE - FROM VERSION 0.1');
125  $images = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE, TRUE);
126  foreach ($images as $assetid => $type_code) {
127  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
128  if (is_null($asset)) continue;
129 
130  if (!$asset->setAttrValue('alt', $asset->name) || !$asset->setAttrValue('title', $asset->name)) {
131  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to set alt and/or title', "\n";
132  continue;
133  }
134 
135  $info = $asset->getExistingFile();
136  if (!empty($info)) {
137  if (!$asset->setAttrValue('width', $info['width']) || !$asset->setAttrValue('height', $info['height']) || !$asset->setAttrValue('size', $info['size'])) {
138  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to set width, height and/or size', "\n";
139  continue;
140  }
141  }//end if
142 
143  if (!$asset->saveAttributes()) {
144  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to save attributes', "\n";
145  continue;
146  }
147  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
148  unset($asset);
149 
150  }//end foreach
151  pre_echo($asset_name.' UPGRADE COMPLETE - FROM VERSION 0.1');
152 
153  }//end if - upgrade to version 0.2
154 
155  return TRUE;
156 
157  }//end _upgrade()
158 
159 
160 }//end class
161 ?>