1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
<?php
class Image extends BeditaStreamModel {
var $actsAs = array();
public $objectTypesGroups = array('multimedia', 'leafs', 'related');
protected $modelBindings = array(
'detailed' => array(
'BEObject' => array(
'ObjectType',
'Permission',
'UserCreated',
'UserModified',
'RelatedObject',
'Category',
'ObjectProperty',
'LangText',
'Annotation',
'Alias',
'Version' => array('User.realname', 'User.userid')
),
'Content',
'Stream'
),
'default' => array(
'BEObject' => array(
'ObjectProperty',
'LangText',
'ObjectType',
'RelatedObject',
'Category',
'Annotation'
),
'Content',
'Stream'
),
'minimum' => array(
'BEObject' => array('ObjectType','Category'),
'Content',
'Stream'
),
'frontend' => array(
'BEObject' => array(
'LangText',
'ObjectProperty',
'Category',
'RelatedObject'
),
'Content',
'Stream'
),
'api' => array(
'BEObject' => array(
'LangText',
'ObjectProperty',
'Category'
),
'Content',
'Stream'
)
);
public function setImageDim(&$id) {
$data = $this->find('first', array(
'conditions' => array('Image.id' => $id),
'contain' => array('Stream')));
return $this->setImageDimArray($data);
}
public function setImageDimArray(array &$data) {
$conf = Configure::getInstance();
$res = false;
if(empty($data['uri'])) {
throw new BeditaException(__('Missing img path', true) . ' - ' . print_r($data, true));
}
if (!preg_match($conf->validate_resource['URL'], $data['uri'])) {
if ( !$imageSize =@ getimagesize($conf->mediaRoot . $data['uri']) )
throw new BeditaException(__('Get image size failed', true) . ' - ' . $data['uri']);
if ($imageSize[0] == 0 || $imageSize[1] == 0)
throw new BeditaException(__("Can't get dimension ", true) . ' - ' . $data['uri']);
$this->id = $data['id'];
$data['width'] = $imageSize[0];
$data['height'] = $imageSize[1];
if (!$this->saveField('width', $data['width']))
throw new BeditaException(__('Error saving width field', true));
if (!$this->saveField('height', $data['height']))
throw new BeditaException(__('Error saving height field', true));
$res = true;
}
return $res;
}
}