Nctext.php
11.5 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
/**
* @package anc_text
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Text_Helper_Nctext extends Mage_Core_Helper_Abstract {
public function printAdminId() {
$admin_id = Mage::getSingleton('admin/session')->getUser()->getId();
}
public function getNcUserAlbumWithTexts($param_customerId){
// $nctext = Mage::helper('anc_text/ncmodel')->getNcText($param_nctext_id)->;
}
public function getNcTextMetaDataAsHtml($param_nctext_id) {
$Quoteitemoption_Collection = Mage::helper('anc_text/ncmodel')->getNcTextMetaData($param_nctext_id);
$nctext_quoteitemoptions = $Quoteitemoption_Collection->getItems();
$return_html = 'Dieses Bild haben Sie bis jetzt '.count($nctext_quoteitemoptions).' mal verwendet! ';
foreach($nctext_quoteitemoptions as $nctext_quoteitemoption) {
$return_html .= $nctext_quoteitemoption->getOrdertime().' ';
}
return $return_html;
}
/**
* return the path from the anc_text/nctext with the $param_nctext_id
*
* @param int $param_nctext_id
* @param string $param_kindOfPath relative || absolute
* @param string $param_kindOfFile original || thumbnail
* @return string
*/
public function getNcTextPath($param_nctext_id, $param_kindOfPath, $param_kindOfFile, $param_NoPrivacy=false) {
return null;
$nctext = Mage::helper('anc_text/ncmodel')->getNcText($param_nctext_id);
if(is_object($nctext)) {
$mainpath = $this->getMainPath($nctext, $param_NoPrivacy);
if($mainpath) {
if($param_kindOfFile === 'original') {
} else if($param_kindOfFile === 'thumbnail') {
if($this->generateThumbnail($mainpath, $nctext)) {
} else {
$param_kindOfFile = 'original';
}
} else {
return false;
}
if(is_file($this->getPath('absolute', $this->getAncTextPath($param_kindOfFile).$mainpath, $param_kindOfFile, $nctext))) {
return $this->getPath($param_kindOfPath, $this->getAncTextPath($param_kindOfFile).$mainpath, $param_kindOfFile, $nctext);
} else {
return false;
}
} else {
// D::ulli("getNcTextPath($param_nctext_id, $param_kindOfPath, $param_kindOfFile) FALSE: es gab getMainPath probleme");
}
} else {
return false;
}
}
private function getPath($param_kindOfPath, $param_partOfPath, $param_kindOfFile, Anc_Text_Model_Nctext $param_nctext=null) {
return null;
if($param_kindOfPath==='relative') {
$root = '';
} else if($param_kindOfPath==='absolute') {
$root = Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath();
}
if(is_null($param_nctext)) {
return $root.$param_partOfPath.DS.$param_kindOfFile.DS;
} else {
return $root.$param_partOfPath.DS.$param_kindOfFile.DS.$param_nctext->getFile();
}
}
public function generateThumbnail($param_path, Anc_Text_Model_Nctext $param_nctext) {
return null;
if(!file_exists($this->getPath('absolute', $this->getAncTextPath('thumbnail').$param_path, 'thumbnail', $param_nctext))) {
$originalpath = $this->getPath('absolute', $this->getAncTextPath('original').$param_path, 'original', $param_nctext);
$thumbnail_filepath = $this->getPath('absolute', $this->getAncTextPath('thumbnail').$param_path, 'thumbnail', $param_nctext);
if(file_exists($originalpath)) {
return mcImagick::makeThumbnail($originalpath, $thumbnail_filepath);
} else {
return false;
}
} else {
return true;
}
}
public function getPathForNewNcText($param_kindOfFile='original') {
return null;
$mainpath = $this->getMainPath();
if($mainpath) {
$path = Mage::helper('anc_lib/ncfilepath')->getThisMagentoInstallationPath().$this->getAncTextPath().$mainpath.DS.$param_kindOfFile;
return $path;
} else {
return false;
}
}
private $CropfilePath = array();
/**
* wenn es die optionalen individuelle optionen gibt, und diese im frontend durch js:crop gesetzt wurden, gibt es ein gecroptest bild zurück
*
*
* @param int $param_item_id - AncText item id
* @return string
*/
public function getCropfilePath($param_item_id) {
if(!array_key_exists($param_item_id, $this->CropfilePath) || !$this->CropfilePath[$param_item_id]) {
$ItemProductOptionByOptionSku = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPAncText);
// D::s($ItemProductOptionByOptionSku,$ItemProductOptionByOptionSku,5,1,1);
return null;
if ($ItemProductOptionByOptionSku) {
$imgUrl = Mage::helper('anc_text/nctext')->getNcTextPath($ItemProductOptionByOptionSku, 'absolute', 'original');
$nctext = Mage::helper('anc_text/ncmodel')->getNcText($ItemProductOptionByOptionSku);
$mainpath = $this->getMainPath($nctext, false);
$crop_filepath = $this->getPath('absolute', $this->getAncTextPath('crop').$mainpath, 'crop', null);
$Cropdata = $this->getCropdata($param_item_id);
if(is_array($Cropdata) && !empty($Cropdata)) {
$returnpath = $this->crop($imgUrl, $crop_filepath, $Cropdata, $nctext->getFile());
} else {
$returnpath = $imgUrl;
}
$this->CropfilePath[$param_item_id] = $returnpath;
}
}
return $this->CropfilePath[$param_item_id];
}
public function getCropdata($param_item_id) {
return null;
$return = array();
$return['cropH'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_cropH);
$return['cropW'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_cropW);
$return['imgH'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_imgH);
$return['imgW'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_imgW);
$return['imgInitH'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_imgInitH);
$return['imgInitW'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_imgInitW);
$return['imgX1'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_imgX1);
$return['imgY1'] = Mage::helper('anc_lib/quoteitem')->getItemProductOptionByOptionSku($param_item_id, Mage::helper('anc_text/ncconstant')->ancSPText_KEY_imgY1);
if($return['imgInitW'] || $return['imgInitH'] || $return['imgW'] || $return['imgH'] || $return['imgY1'] || $return['imgX1'] || $return['cropW'] || $return['cropH']) {
return $return;
} else {
return false;
}
}
/**
* cropt das bild (schneiden, vergrößern etc) in ein temporäres verzeichnis
*
* !!! THIS IS JUST AN EXAMPLE !!!, PLEASE USE TextMagick or some other quality text processing libraries
*
* @param string $imgUrl
* @param string $targetpath
* @param array $Cropdata = array(
* imgInitW // your text original width (the one we recieved after upload)
* imgInitH // your text original height (the one we recieved after upload)
* imgW // your new scaled text width
* imgH // your new scaled text height
* imgX1 // top left corner of the cropped text in relation to scaled text
* imgY1 // top left corner of the cropped text in relation to scaled text
* cropW // cropped text width
* cropH // cropped text height
* )
* @param string $filenamepart=''
* @return string
*/
private function crop($imgUrl, $targetpath, $Cropdata, $filenamepart='') {
return null;
mcDir::create($targetpath);
$jpeg_quality = 100;
$output_filename = $targetpath."/".$filenamepart."cropped_".rand();
$what = gettextsize($imgUrl);
switch(strtolower($what['mime']))
{
case 'text/png':
$img_r = textcreatefrompng($imgUrl);
$source_text = textcreatefrompng($imgUrl);
$type = '.png';
break;
case 'text/jpeg':
$img_r = textcreatefromjpeg($imgUrl);
$source_text = textcreatefromjpeg($imgUrl);
$type = '.jpeg';
break;
case 'text/gif':
$img_r = textcreatefromgif($imgUrl);
$source_text = textcreatefromgif($imgUrl);
$type = '.gif';
break;
default: die('text type not supported');
}
$resizedText = textcreatetruecolor($Cropdata['imgW'], $Cropdata['imgH']);
textcopyresampled($resizedText, $source_text, 0, 0, 0, 0, $Cropdata['imgW'],
$Cropdata['imgH'], $Cropdata['imgInitW'], $Cropdata['imgInitH']);
$dest_text = textcreatetruecolor($Cropdata['cropW'], $Cropdata['cropH']);
textcopyresampled($dest_text, $resizedText, 0, 0, $Cropdata['imgX1'], $Cropdata['imgY1'], $Cropdata['cropW'],
$Cropdata['cropH'], $Cropdata['cropW'], $Cropdata['cropH']);
textjpeg($dest_text, $output_filename.$type, $jpeg_quality);
return $output_filename.$type ;
}
/**
* gibt den pfad für das
*
* @return string
*/
private function getAncTextPath($param_kindOfFile) {
if($param_kindOfFile==='thumbnail' || $param_kindOfFile==='crop') {
$tmp = true;
} else {
$tmp = false;
}
return Mage::helper('anc_lib/ncfilepath')->getModuleFilepath('anc_text',$tmp);
}
/**
* gibt den wesentlichen Part zurück vom Pfad zur NcText datei ... ob benutzer, öffentlich oder so
*
* @param Anc_Text_Model_Nctext $param_nctext
* @return string|boolean
*/
private function getMainPath(Anc_Text_Model_Nctext $param_nctext=null, $param_NoPrivacy=false) {
$admin_logged_in = Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn();
if(Mage::app()->getStore()->isAdmin()){
$vartest='true';
}
if(is_object($param_nctext)
&& (
(
$param_nctext->getCustomerId() == 0
&& $param_nctext->getAdminUserId() > 0
)
)
)
{
$path .= DS.'admin'.DS.$param_nctext->getAdminUserId();
}
// wenns ein objekt gibt, dann überprüf auch ob du darfst
else if(is_object($param_nctext)
&& (
$param_NoPrivacy
||
(
($param_nctext->getCustomerId()==0 || $param_nctext->getCustomerId()===Mage::getSingleton('customer/session')->getCustomer()->getId())
||
Mage::app()->getStore()->isAdmin()
)
)
) {
$path .= DS.'customer'.DS.$param_nctext->getCustomerId();
// ansonsten bei keinem objekt einfach
} else if(!is_object($param_nctext)) {
# Ensure we are in the admin session namespace for checking the admin user..
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
$path .= DS.'customer'.DS.Mage::getSingleton('customer/session')->getCustomer()->getId();
} else if($admin_logged_in){
$path .= DS.'admin'.DS.Mage::getSingleton('admin/session')->getUser()->getId();;
}else{
$path .= DS.'customer'.DS.'0';
}
} else {
return false;
}
return $path;
}
}