1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude('includes', 'functions.con.php');
19: cInclude('includes', 'functions.upl.php');
20:
21: 22: 23: 24: 25: 26:
27: class cContentTypeImgeditor extends cContentTypeAbstractTabbed {
28:
29: 30: 31: 32: 33:
34: private $_dirname;
35:
36: 37: 38: 39: 40:
41: private $_filename;
42:
43: 44: 45: 46: 47:
48: protected $_imagePath;
49:
50: 51: 52: 53: 54:
55: private $_fileType;
56:
57: 58: 59: 60: 61:
62: private $_fileSize;
63:
64: 65: 66: 67: 68:
69: private $_medianame;
70:
71: 72: 73: 74: 75:
76: protected $_description;
77:
78: 79: 80: 81: 82:
83: private $_keywords;
84:
85: 86: 87: 88: 89:
90: private $_internalNotice;
91:
92: 93: 94: 95: 96:
97: private $_copyright;
98:
99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109:
110: public function __construct($rawSettings, $id, array $contentTypes) {
111:
112:
113: $this->_type = 'CMS_IMGEDITOR';
114: $this->_prefix = 'imgeditor';
115: $this->_formFields = array(
116: 'image_filename',
117: 'image_medianame',
118: 'image_description',
119: 'image_keywords',
120: 'image_internal_notice',
121: 'image_copyright'
122: );
123: parent::__construct($rawSettings, $id, $contentTypes);
124:
125:
126: $upload = new cApiUpload($this->_rawSettings);
127: $this->_filename = $upload->get('filename');
128: $this->_dirname = $upload->get('dirname');
129: $this->_imagePath = $this->_generateImagePath();
130: $this->_fileType = $upload->get('filetype');
131: $this->_fileSize = $upload->get('size');
132:
133:
134: $uploadMeta = new cApiUploadMeta();
135: $uploadMeta->loadByMany(array(
136: 'idupl' => $this->_rawSettings,
137: 'idlang' => $this->_lang
138: ));
139: $this->_medianame = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
140: $this->_description = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
141: $this->_keywords = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
142: $this->_internalNotice = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
143: $this->_copyright = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
144:
145:
146:
147:
148: if (isset($_POST[$this->_prefix . '_action']) && $_POST[$this->_prefix . '_action'] === 'store' && isset($_POST[$this->_prefix . '_id']) && (int) $_POST[$this->_prefix . '_id'] == $this->_id) {
149: $this->_storeSettings();
150: $path = $this->_cfg['path']['contenido_fullhtml'] . "external/backendedit/front_content.php?area=con_editcontent&idart=$this->_idArt&idcat=$this->_idCat&changeview=edit&client=$this->_client";
151: header('location:' . $this->_session->url($path));
152: }
153: }
154:
155: 156: 157: 158: 159:
160: private function _generateImagePath() {
161: if (!empty($this->_filename)) {
162: if (cApiDbfs::isDbfs($this->_dirname)) {
163: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
164: } else {
165: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
166: }
167: }
168:
169: return '';
170: }
171:
172: 173: 174: 175: 176: 177:
178: protected function _storeSettings() {
179:
180: $filename = basename($_POST['image_filename']);
181: $dirname = dirname($_POST['image_filename']);
182: if ($dirname === '\\' || $dirname === '/') {
183: $dirname = '';
184: } else {
185: $dirname .= '/';
186: }
187:
188:
189: $upload = new cApiUpload();
190: $upload->loadByMany(array(
191: 'filename' => $filename,
192: 'dirname' => $dirname,
193: 'idclient' => $this->_client
194: ), false);
195:
196: $this->_rawSettings = $upload->get('idupl');
197:
198:
199: conSaveContentEntry($this->_idArtLang, 'CMS_IMGEDITOR', $this->_id, $this->_rawSettings);
200: conMakeArticleIndex($this->_idArtLang, $this->_idArt);
201: conGenerateCodeForArtInAllCategories($this->_idArt);
202:
203:
204: $medianame = $_POST['image_medianame'];
205: $description = $_POST['image_description'];
206: $keywords = $_POST['image_keywords'];
207: $internal_notice = $_POST['image_internal_notice'];
208: $copyright = $_POST['image_copyright'];
209:
210:
211: $uploadMeta = new cApiUploadMeta();
212: $uploadMeta->loadByMany(array(
213: 'idupl' => $this->_rawSettings,
214: 'idlang' => $this->_lang
215: ));
216:
217: if ($uploadMeta->get('id_uplmeta') != false) {
218: $uploadMeta->set('idupl', $this->_rawSettings);
219: $uploadMeta->set('idlang', $this->_lang);
220: $uploadMeta->set('medianame', $medianame);
221: $uploadMeta->set('description', $description);
222: $uploadMeta->set('keywords', $keywords);
223: $uploadMeta->set('internal_notice', $internal_notice);
224: $uploadMeta->set('copyright', $copyright);
225: $uploadMeta->store();
226: } else {
227:
228: $uploadMetaCollection = new cApiUploadMetaCollection();
229: $uploadMetaCollection->create($this->_rawSettings, $this->_lang, $medianame, $description, $keywords, $internal_notice, $copyright);
230: }
231: }
232:
233: 234: 235: 236: 237: 238: 239:
240: public function generateViewCode() {
241: $image = new cHTMLImage($this->_imagePath);
242: $image->setAlt($this->_description);
243:
244: return $this->_encodeForOutput($image->render());
245: }
246:
247: 248: 249: 250: 251: 252:
253: public function generateEditCode() {
254:
255: $templateTop = new cTemplate();
256: $templateTop->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
257: $templateTop->set('s', 'ICON', 'images/but_editimage.gif');
258: $templateTop->set('s', 'ID', $this->_id);
259: $templateTop->set('s', 'PREFIX', $this->_prefix);
260: $templateTop->set('s', 'HEADLINE', i18n('Image settings'));
261: $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
262:
263: $tabMenu = array(
264: 'directories' => i18n('Directories'),
265: 'meta' => i18n('Meta'),
266: 'upload' => i18n('Upload')
267: );
268:
269: $templateTabs = new cTemplate();
270:
271:
272: $templateTabs->set('d', 'TAB_ID', 'upload');
273: $templateTabs->set('d', 'TAB_CLASS', 'upload');
274: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabUpload());
275: $templateTabs->set('s', 'PREFIX', $this->_prefix);
276: $templateTabs->next();
277:
278:
279: $templateTabs->set('d', 'TAB_ID', 'directories');
280: $templateTabs->set('d', 'TAB_CLASS', 'directories');
281: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabDirectories());
282: $templateTabs->next();
283:
284:
285: $templateTabs->set('d', 'TAB_ID', 'meta');
286: $templateTabs->set('d', 'TAB_CLASS', 'meta');
287: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabMeta());
288: $templateTabs->next();
289:
290: $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
291:
292:
293: $templateBottom = new cTemplate();
294: $templateBottom->set('s', 'PATH_BACKEND', $this->_cfg['path']['contenido_fullhtml']);
295: $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
296: $templateBottom->set('s', 'ID', $this->_id);
297: $templateBottom->set('s', 'PREFIX', $this->_prefix);
298: $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
299: $templateBottom->set('s', 'CONTENIDO', $_REQUEST['contenido']);
300: $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
301: $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
302: $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsImgeditor.js');
303: $templateBottom->set('s', 'JS_CLASS_NAME', 'cContentTypeImgeditor');
304: $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
305:
306: $code = $this->_encodeForOutput($codeTop);
307: $code .= $this->_generateTabMenuCode($tabMenu);
308: $code .= $this->_encodeForOutput($codeTabs);
309: $code .= $this->_generateActionCode();
310: $code .= $this->_encodeForOutput($codeBottom);
311:
312: return $code;
313: }
314:
315: 316: 317: 318: 319: 320:
321: private function _generateTabDirectories() {
322:
323:
324: $wrapper = new cHTMLDiv();
325: $wrapperContent = array();
326:
327: $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
328: $liRoot = new cHTMLListItem('root', 'last');
329: $aUpload = new cHTMLLink('#');
330: $aUpload->setClass('on');
331: $aUpload->setAttribute('title', 'upload');
332: $aUpload->setContent('Uploads');
333: $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
334: $div = new cHTMLDiv(array(
335: '<em><a href="#"></a></em>',
336: $aUpload
337: ));
338: $liRoot->setContent(array(
339: $div,
340: $directoryListCode
341: ));
342: $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
343: $directoryList->setContent($conStrTree);
344: $wrapperContent[] = $directoryList;
345:
346: $wrapperContent[] = new cHTMLDiv($this->generateFileSelect($this->_dirname), 'directoryFile', 'directoryFile' . '_' . $this->_id);
347:
348: $directoryShow = new cHTMLDiv('', 'directoryShow', 'directoryShow_' . $this->_id);
349: $imagePath = $this->_imagePath;
350: $imageFilename = str_replace($this->_cfgClient[$this->_client]['path']['htmlpath'], $this->_cfgClient[$this->_client]['path']['frontend'], $imagePath);
351: $imageFiletype = substr($imagePath, strlen($imagePath) - 4, 4);
352: $imageExtensions = array(
353: '.gif',
354: '.png',
355: '.jpg',
356: 'jpeg'
357: );
358: if (in_array($imageFiletype, $imageExtensions)) {
359: $imagePath = cApiImgScale($imageFilename, 428, 210);
360: }
361: $image = new cHTMLImage($imagePath);
362: $directoryShow->setContent($image);
363: $wrapperContent[] = $directoryShow;
364:
365: $wrapper->setContent($wrapperContent);
366: return $wrapper->render();
367: }
368:
369: 370: 371: 372: 373: 374:
375: private function _generateTabMeta() {
376:
377: $wrapper = new cHTMLDiv();
378: $wrapperContent = array();
379:
380: $imageMetaUrl = new cHTMLSpan();
381: $imageMetaUrl->setID('image_meta_url_' . $this->_id);
382: $imageMetaUrl->setClass('image_meta_url');
383: $wrapperContent[] = new cHTMLDiv(array(
384: '<b>' . i18n('Selected file') . '</b>',
385: $imageMetaUrl
386: ));
387: $wrapperContent[] = new cHTMLLabel(i18n('Title'), 'image_medianame_' . $this->_id);
388: $wrapperContent[] = new cHTMLTextbox('image_medianame', $this->_medianame, '', '', 'image_medianame_' . $this->_id);
389: $wrapperContent[] = new cHTMLLabel(i18n('Description'), 'image_description_' . $this->_id);
390: $wrapperContent[] = new cHTMLTextarea('image_description', $this->_description, '', '', 'image_description_' . $this->_id);
391: $wrapperContent[] = new cHTMLLabel(i18n('Keywords'), 'image_keywords_' . $this->_id);
392: $wrapperContent[] = new cHTMLTextbox('image_keywords', $this->_keywords, '', '', 'image_keywords_' . $this->_id);
393: $wrapperContent[] = new cHTMLLabel(i18n('Internal notes'), 'image_internal_notice_' . $this->_id);
394: $wrapperContent[] = new cHTMLTextbox('image_internal_notice', $this->_internalNotice, '', '', 'image_internal_notice_' . $this->_id);
395: $wrapperContent[] = new cHTMLLabel(i18n('Copyright'), 'image_copyright_' . $this->_id);
396: $wrapperContent[] = new cHTMLTextbox('image_copyright', $this->_copyright, '', '', 'image_copyright_' . $this->_id);
397:
398: $wrapper->setContent($wrapperContent);
399: return $wrapper->render();
400: }
401:
402: 403: 404: 405: 406:
407: private function _generateTabUpload() {
408:
409: $wrapper = new cHTMLDiv();
410: $wrapperContent = array();
411:
412:
413: $newDirForm = new cHTMLForm();
414: $newDirForm->setAttribute('name', 'newdir');
415: $newDirForm->setAttribute('method', 'post');
416: $newDirForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
417: $caption1Span = new cHTMLSpan();
418: $caption1Span->setID('caption1');
419: $newDirHead = new cHTMLDiv(array(
420: '<b>' . i18n('Create a directory in') . '</b>',
421: $caption1Span
422: ));
423: $area = new cHTMLHiddenField('area', 'upl');
424: $action = new cHTMLHiddenField('action', 'upl_mkdir');
425: $frame = new cHTMLHiddenField('frame', '2');
426: $appendparameters = new cHTMLHiddenField('appendparameters');
427: $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
428: $path = new cHTMLHiddenField('path');
429: $foldername = new cHTMLTextbox('foldername');
430: $button = new cHTMLButton('', '', '', false, NULL, '', 'image');
431: $button->setAttribute('src', $this->_cfg['path']['contenido_fullhtml'] . 'images/submit.gif');
432: $newDirContent = new cHTMLDiv(array(
433: $area,
434: $action,
435: $frame,
436: $appendparameters,
437: $contenido,
438: $path,
439: $foldername,
440: $button
441: ));
442: $newDirForm->setContent(array(
443: $newDirHead,
444: $newDirContent
445: ));
446: $wrapperContent[] = $newDirForm;
447:
448:
449: $propertiesForm = new cHTMLForm();
450: $propertiesForm->setID('properties' . $this->_id);
451: $propertiesForm->setAttribute('name', 'properties');
452: $propertiesForm->setAttribute('method', 'post');
453: $propertiesForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
454: $propertiesForm->setAttribute('enctype', 'multipart/form-data');
455: $frame = new cHTMLHiddenField('frame', '4');
456: $area = new cHTMLHiddenField('area', 'upl');
457: $path = new cHTMLHiddenField('path');
458: $file = new cHTMLHiddenField('file');
459: $action = new cHTMLHiddenField('action', 'upl_upload');
460: $appendparameters = new cHTMLHiddenField('appendparameters');
461: $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
462: $caption2Span = new cHTMLSpan();
463: $caption2Span->setID('caption2');
464: $propertiesHead = new cHTMLDiv(array(
465: '<b>' . i18n('Path') . '</b>',
466: $caption2Span
467: ));
468: $imageUpload = new cHTMLUpload('file[]', '', '', 'cms_image_m' . $this->_id, false, '', '', 'file');
469: $imageUpload->setClass('jqueryAjaxUpload');
470: $propertiesForm->setContent(array(
471: $frame,
472: $area,
473: $path,
474: $file,
475: $action,
476: $appendparameters,
477: $contenido,
478: $propertiesHead,
479: $imageUpload
480: ));
481: $wrapperContent[] = $propertiesForm;
482:
483: $wrapperContent[] = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/ajax-loader.gif', 'loading');
484:
485: $wrapper->setContent($wrapperContent);
486: return $wrapper->render();
487: }
488:
489: 490: 491: 492: 493: 494:
495: public function generateFileSelect($directoryPath = '') {
496:
497: if (substr($directoryPath, -1) != '/') {
498: $directoryPath .= '/';
499: }
500:
501: $htmlSelect = new cHTMLSelectElement('image_filename', '', 'image_filename_' . $this->_id);
502: $htmlSelect->setSize(16);
503: $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
504: $htmlSelect->addOptionElement(0, $htmlSelectOption);
505:
506: $i = 1;
507: if (is_dir($this->_uploadPath . $directoryPath)) {
508: if ($handle = opendir($this->_uploadPath . $directoryPath)) {
509: while (($entry = readdir($handle)) != false) {
510: if (is_file($this->_uploadPath . $directoryPath . $entry)) {
511: $htmlSelectOption = new cHTMLOptionElement($entry, $directoryPath . $entry);
512: $htmlSelect->addOptionElement($i, $htmlSelectOption);
513: $i++;
514: }
515: }
516: closedir($handle);
517: }
518: }
519:
520: if ($i === 0) {
521: $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '', false);
522: $htmlSelectOption->setAlt(i18n('No files found'));
523: $htmlSelectOption->setDisabled(true);
524: $htmlSelect->addOptionElement($i, $htmlSelectOption);
525: $htmlSelect->setDisabled(true);
526: }
527:
528:
529: if (isset($this->_dirname)) {
530: $htmlSelect->setDefault($this->_dirname . $this->_filename);
531: } else {
532: $htmlSelect->setDefault('');
533: }
534:
535: return $htmlSelect->render();
536: }
537:
538: 539: 540: 541: 542: 543: 544: 545:
546: protected function _isActiveDirectory(array $dirData) {
547: return $dirData['path'] . $dirData['name'] . '/' === $this->_dirname;
548: }
549:
550: 551: 552: 553: 554: 555: 556: 557:
558: protected function _shouldDirectoryBeExpanded(array $dirData) {
559: return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
560: }
561:
562: 563: 564: 565: 566: 567: 568:
569: public function getImageMeta($filename, $dirname) {
570: $upload = new cApiUpload();
571: $upload->loadByMany(array(
572: 'filename' => $filename,
573: 'dirname' => $dirname,
574: 'idclient' => $this->_client
575: ), false);
576: $idupl = $upload->get('idupl');
577:
578: $uploadMeta = new cApiUploadMeta();
579: $uploadMeta->loadByMany(array(
580: 'idupl' => $idupl,
581: 'idlang' => $this->_lang
582: ));
583:
584: $imageMeta = array();
585: $imageMeta['medianame'] = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
586: $imageMeta['description'] = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
587: $imageMeta['keywords'] = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
588: $imageMeta['internal_notice'] = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
589: $imageMeta['copyright'] = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
590:
591: return json_encode($imageMeta);
592: }
593:
594: 595: 596: 597: 598: 599: 600: 601: 602: 603:
604: public function uplmkdir($path, $name) {
605: return uplmkdir($path, $name);
606: }
607:
608: 609: 610: 611: 612: 613:
614: public function uplupload($path) {
615: if (count($_FILES) === 1) {
616: foreach ($_FILES['file']['name'] as $key => $value) {
617: if (file_exists($_FILES['file']['tmp_name'][$key])) {
618: $friendlyName = uplCreateFriendlyName($_FILES['file']['name'][$key]);
619: move_uploaded_file($_FILES['file']['tmp_name'][$key], $this->_cfgClient[$this->_client]['upl']['path'] . $path . $friendlyName);
620:
621: uplSyncDirectory($path);
622:
623: $upload = new cApiUpload();
624: $upload->loadByMany(array(
625: 'dirname' => $path,
626: 'filename' => $_FILES['file']['name'][$key]
627: ), false);
628: if ($upload->get('idupl') != false) {
629: $uplfilename = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $upload->get('dirname') . $upload->get('filename');
630: } else {
631: $uplfilename = 'error';
632: }
633: }
634: }
635: }
636:
637: return $uplfilename;
638: }
639:
640: }