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: public function __construct($rawSettings, $id, array $contentTypes) {
110: global $area;
111:
112:
113:
114: $this->_type = 'CMS_IMGEDITOR';
115: $this->_prefix = 'imgeditor';
116: $this->_formFields = array(
117: 'image_filename',
118: 'image_medianame',
119: 'image_description',
120: 'image_keywords',
121: 'image_internal_notice',
122: 'image_copyright'
123: );
124: parent::__construct($rawSettings, $id, $contentTypes);
125:
126:
127:
128:
129: if (isset($_POST[$this->_prefix . '_action']) && $_POST[$this->_prefix . '_action'] === 'store' && isset($_POST[$this->_prefix . '_id']) && (int) $_POST[$this->_prefix . '_id'] == $this->_id) {
130: $this->_storeSettings();
131: }
132:
133:
134: $upload = new cApiUpload($this->_rawSettings);
135: $this->_filename = $upload->get('filename');
136: $this->_dirname = $upload->get('dirname');
137: $this->_imagePath = $this->_generateImagePath();
138: $this->_fileType = $upload->get('filetype');
139: $this->_fileSize = $upload->get('size');
140:
141:
142: $uploadMeta = new cApiUploadMeta();
143: $uploadMeta->loadByMany(array(
144: 'idupl' => $this->_rawSettings,
145: 'idlang' => $this->_lang
146: ));
147: $this->_medianame = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
148: $this->_description = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
149: $this->_keywords = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
150: $this->_internalNotice = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
151: $this->_copyright = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
152:
153: }
154:
155: 156: 157: 158: 159:
160: public function getAbsolutePath() {
161: return $this->_cfgClient[$this->_client]['upl']['path'] . $this->_dirname . $this->_filename;
162: }
163:
164: 165: 166: 167: 168:
169: public function getRelativePath() {
170: return $this->_dirname . $this->_filename;
171: }
172:
173: 174: 175: 176: 177:
178: public function getAbsoluteURL() {
179: return $this->_generateImagePath();
180: }
181:
182: 183: 184: 185: 186:
187: public function getRelativeURL() {
188: if (!empty($this->_filename)) {
189: if (cApiDbfs::isDbfs($this->_dirname)) {
190: return 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
191: } else {
192: return $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
193: }
194: }
195:
196: return '';
197: }
198:
199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210:
211: public function getMetaData() {
212: return array(
213: 'medianame' => $this->_medianame,
214: 'description' => $this->_description,
215: 'keywords' => $this->_keywords,
216: 'internalnotice' => $this->_internalNotice,
217: 'copyright' => $this->_copyright
218: );
219: }
220:
221: 222: 223: 224: 225:
226: private function _generateImagePath() {
227: if (!empty($this->_filename)) {
228: if (cApiDbfs::isDbfs($this->_dirname)) {
229: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
230: } else {
231: return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
232: }
233: }
234:
235: return '';
236: }
237:
238: 239: 240: 241: 242:
243: protected function _storeSettings() {
244:
245: $filename = basename($_POST['image_filename']);
246: $dirname = dirname($_POST['image_filename']);
247: if ($dirname === '\\' || $dirname === '/') {
248: $dirname = '';
249: } else {
250: $dirname .= '/';
251: }
252:
253:
254: $upload = new cApiUpload();
255: $upload->loadByMany(array(
256: 'filename' => $filename,
257: 'dirname' => $dirname,
258: 'idclient' => $this->_client
259: ), false);
260:
261: $this->_rawSettings = $upload->get('idupl');
262:
263:
264: conSaveContentEntry($this->_idArtLang, 'CMS_IMGEDITOR', $this->_id, $this->_rawSettings);
265: conMakeArticleIndex($this->_idArtLang, $this->_idArt);
266: conGenerateCodeForArtInAllCategories($this->_idArt);
267:
268:
269: $medianame = $_POST['image_medianame'];
270: $description = $_POST['image_description'];
271: $keywords = $_POST['image_keywords'];
272: $internal_notice = $_POST['image_internal_notice'];
273: $copyright = $_POST['image_copyright'];
274:
275:
276: $uploadMeta = new cApiUploadMeta();
277: $uploadMeta->loadByMany(array(
278: 'idupl' => $this->_rawSettings,
279: 'idlang' => $this->_lang
280: ));
281:
282: if ($uploadMeta->get('id_uplmeta') != false) {
283: $uploadMeta->set('idupl', $this->_rawSettings);
284: $uploadMeta->set('idlang', $this->_lang);
285: $uploadMeta->set('medianame', $medianame);
286: $uploadMeta->set('description', $description);
287: $uploadMeta->set('keywords', $keywords);
288: $uploadMeta->set('internal_notice', $internal_notice);
289: $uploadMeta->set('copyright', $copyright);
290: $uploadMeta->store();
291: } else {
292:
293: $uploadMetaCollection = new cApiUploadMetaCollection();
294: $uploadMetaCollection->create($this->_rawSettings, $this->_lang, $medianame, $description, $keywords, $internal_notice, $copyright);
295: }
296: }
297:
298: 299: 300: 301: 302: 303: 304:
305: public function generateViewCode() {
306: $image = new cHTMLImage($this->_imagePath);
307: $image->setAlt($this->_description);
308:
309: return $this->_encodeForOutput($image->render());
310: }
311:
312: 313: 314: 315: 316: 317:
318: public function generateEditCode() {
319:
320: $templateTop = new cTemplate();
321: $templateTop->set('s', 'ICON', 'images/but_editimage.gif');
322: $templateTop->set('s', 'ID', $this->_id);
323: $templateTop->set('s', 'PREFIX', $this->_prefix);
324: $templateTop->set('s', 'HEADLINE', i18n('Image settings'));
325: $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
326:
327: $tabMenu = array(
328: 'directories' => i18n('Directories'),
329: 'meta' => i18n('Meta'),
330: 'upload' => i18n('Upload')
331: );
332:
333: $templateTabs = new cTemplate();
334:
335:
336: $templateTabs->set('d', 'TAB_ID', 'upload');
337: $templateTabs->set('d', 'TAB_CLASS', 'upload');
338: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabUpload());
339: $templateTabs->set('s', 'PREFIX', $this->_prefix);
340: $templateTabs->next();
341:
342:
343: $templateTabs->set('d', 'TAB_ID', 'directories');
344: $templateTabs->set('d', 'TAB_CLASS', 'directories');
345: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabDirectories());
346: $templateTabs->next();
347:
348:
349: $templateTabs->set('d', 'TAB_ID', 'meta');
350: $templateTabs->set('d', 'TAB_CLASS', 'meta');
351: $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabMeta());
352: $templateTabs->next();
353:
354: $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
355:
356:
357: $templateBottom = new cTemplate();
358: $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
359: $templateBottom->set('s', 'ID', $this->_id);
360: $templateBottom->set('s', 'PREFIX', $this->_prefix);
361: $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
362: $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
363: $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
364: $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsImgeditor.js');
365: $templateBottom->set('s', 'JS_CLASS_NAME', 'Con.cContentTypeImgeditor');
366: $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
367:
368: $code = $this->_encodeForOutput($codeTop);
369: $code .= $this->_generateTabMenuCode($tabMenu);
370: $code .= $this->_encodeForOutput($codeTabs);
371: $code .= $this->_generateActionCode();
372: $code .= $this->_encodeForOutput($codeBottom);
373:
374: return $code;
375: }
376:
377: 378: 379: 380: 381: 382:
383: private function _generateTabDirectories() {
384:
385:
386: $wrapper = new cHTMLDiv();
387: $wrapperContent = array();
388:
389: $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
390: $liRoot = new cHTMLListItem('root', 'root');
391: $aUpload = new cHTMLLink('#');
392: $aUpload->setClass('on');
393: $aUpload->setAttribute('title', 'upload');
394: $aUpload->setContent('Uploads');
395: $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
396: $div = new cHTMLDiv(array(
397: '<em><a href="#"></a></em>',
398: $aUpload
399: ));
400: $liRoot->setContent(array(
401: $div,
402: $directoryListCode
403: ));
404: $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
405: $directoryList->setContent($conStrTree);
406: $wrapperContent[] = $directoryList;
407:
408: $wrapperContent[] = new cHTMLDiv($this->generateFileSelect($this->_dirname), 'directoryFile', 'directoryFile' . '_' . $this->_id);
409:
410: $directoryShow = new cHTMLDiv('', 'directoryShow', 'directoryShow_' . $this->_id);
411: $imagePath = $this->_imagePath;
412: $imageFilename = str_replace($this->_cfgClient[$this->_client]['path']['htmlpath'], $this->_cfgClient[$this->_client]['path']['frontend'], $imagePath);
413: $imageFiletype = substr($imagePath, strlen($imagePath) - 4, 4);
414: $imageExtensions = array(
415: '.gif',
416: '.png',
417: '.jpg',
418: 'jpeg'
419: );
420: if (in_array($imageFiletype, $imageExtensions)) {
421: $imagePath = cApiImgScale($imageFilename, 428, 210);
422: }
423: $image = new cHTMLImage($imagePath);
424: $directoryShow->setContent($image);
425: $wrapperContent[] = $directoryShow;
426:
427: $wrapper->setContent($wrapperContent);
428: return $wrapper->render();
429: }
430:
431: 432: 433: 434: 435: 436:
437: private function _generateTabMeta() {
438:
439: $wrapper = new cHTMLDiv();
440: $wrapperContent = array();
441:
442: $imageMetaUrl = new cHTMLSpan();
443: $imageMetaUrl->setID('image_meta_url_' . $this->_id);
444: $imageMetaUrl->setClass('image_meta_url');
445: $wrapperContent[] = new cHTMLDiv(array(
446: '<b>' . i18n('Selected file') . '</b>',
447: $imageMetaUrl
448: ));
449: $wrapperContent[] = new cHTMLLabel(i18n('Title'), 'image_medianame_' . $this->_id);
450: $wrapperContent[] = new cHTMLTextbox('image_medianame', $this->_medianame, '', '', 'image_medianame_' . $this->_id);
451: $wrapperContent[] = new cHTMLLabel(i18n('Description'), 'image_description_' . $this->_id);
452: $wrapperContent[] = new cHTMLTextarea('image_description', $this->_description, '', '', 'image_description_' . $this->_id);
453: $wrapperContent[] = new cHTMLLabel(i18n('Keywords'), 'image_keywords_' . $this->_id);
454: $wrapperContent[] = new cHTMLTextbox('image_keywords', $this->_keywords, '', '', 'image_keywords_' . $this->_id);
455: $wrapperContent[] = new cHTMLLabel(i18n('Internal notes'), 'image_internal_notice_' . $this->_id);
456: $wrapperContent[] = new cHTMLTextbox('image_internal_notice', $this->_internalNotice, '', '', 'image_internal_notice_' . $this->_id);
457: $wrapperContent[] = new cHTMLLabel(i18n('Copyright'), 'image_copyright_' . $this->_id);
458: $wrapperContent[] = new cHTMLTextbox('image_copyright', $this->_copyright, '', '', 'image_copyright_' . $this->_id);
459:
460: $wrapper->setContent($wrapperContent);
461: return $wrapper->render();
462: }
463:
464: 465: 466: 467: 468:
469: private function _generateTabUpload() {
470:
471: $wrapper = new cHTMLDiv();
472: $wrapperContent = array();
473:
474:
475: $newDirForm = new cHTMLForm();
476: $newDirForm->setAttribute('name', 'newdir');
477: $newDirForm->setAttribute('method', 'post');
478: $newDirForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
479: $caption1Span = new cHTMLSpan();
480: $caption1Span->setID('caption1');
481: $newDirHead = new cHTMLDiv(array(
482: '<b>' . i18n('Create a directory in') . '</b>',
483: $caption1Span
484: ));
485: $area = new cHTMLHiddenField('area', 'upl');
486: $action = new cHTMLHiddenField('action', 'upl_mkdir');
487: $frame = new cHTMLHiddenField('frame', '2');
488: $appendparameters = new cHTMLHiddenField('appendparameters');
489: $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
490: $path = new cHTMLHiddenField('path');
491: $foldername = new cHTMLTextbox('foldername');
492: $button = new cHTMLButton('', '', '', false, NULL, '', 'image');
493: $button->setAttribute('src', $this->_cfg['path']['contenido_fullhtml'] . 'images/submit.gif');
494: $newDirContent = new cHTMLDiv(array(
495: $area,
496: $action,
497: $frame,
498: $appendparameters,
499: $contenido,
500: $path,
501: $foldername,
502: $button
503: ));
504: $newDirForm->setContent(array(
505: $newDirHead,
506: $newDirContent
507: ));
508: $wrapperContent[] = $newDirForm;
509:
510:
511: $propertiesForm = new cHTMLForm();
512: $propertiesForm->setID('properties' . $this->_id);
513: $propertiesForm->setAttribute('name', 'properties');
514: $propertiesForm->setAttribute('method', 'post');
515: $propertiesForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
516: $propertiesForm->setAttribute('enctype', 'multipart/form-data');
517: $frame = new cHTMLHiddenField('frame', '4');
518: $area = new cHTMLHiddenField('area', 'upl');
519: $path = new cHTMLHiddenField('path');
520: $file = new cHTMLHiddenField('file');
521: $action = new cHTMLHiddenField('action', 'upl_upload');
522: $appendparameters = new cHTMLHiddenField('appendparameters');
523: $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
524: $caption2Span = new cHTMLSpan();
525: $caption2Span->setID('caption2');
526: $propertiesHead = new cHTMLDiv(array(
527: '<b>' . i18n('Path') . '</b>',
528: $caption2Span
529: ));
530: $imageUpload = new cHTMLUpload('file[]', '', '', 'cms_image_m' . $this->_id, false, '', '', 'file');
531: $imageUpload->setClass('jqueryAjaxUpload');
532: $propertiesForm->setContent(array(
533: $frame,
534: $area,
535: $path,
536: $file,
537: $action,
538: $appendparameters,
539: $contenido,
540: $propertiesHead,
541: $imageUpload
542: ));
543: $wrapperContent[] = $propertiesForm;
544:
545: $wrapperContent[] = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/ajax-loader.gif', 'loading');
546:
547: $wrapper->setContent($wrapperContent);
548: return $wrapper->render();
549: }
550:
551: 552: 553: 554: 555: 556:
557: public function generateFileSelect($directoryPath = '') {
558:
559: if (substr($directoryPath, -1) != '/') {
560: $directoryPath .= '/';
561: }
562:
563: $htmlSelect = new cHTMLSelectElement('image_filename', '', 'image_filename_' . $this->_id);
564: $htmlSelect->setSize(16);
565: $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
566: $htmlSelect->addOptionElement(0, $htmlSelectOption);
567:
568: $files = array();
569: if (is_dir($this->_uploadPath . $directoryPath)) {
570: if (false !== ($handle = cDirHandler::read($this->_uploadPath . $directoryPath, false, false, true))) {
571: foreach ($handle as $entry) {
572: if (false === cFileHandler::fileNameBeginsWithDot($entry)) {
573: $file = array();
574: $file["name"] = $entry;
575: $file["path"] = $directoryPath . $entry;
576: $files[] = $file;
577: }
578: }
579: }
580: }
581:
582: usort($files, function($a, $b) {
583: $a = mb_strtolower($a["name"]);
584: $b = mb_strtolower($b["name"]);
585: if($a < $b) {
586: return -1;
587: } else if($a > $b) {
588: return 1;
589: } else {
590: return 0;
591: }
592: });
593:
594: $i = 1;
595: foreach($files as $file) {
596: $htmlSelectOption = new cHTMLOptionElement($file["name"], $file["path"]);
597: $htmlSelect->addOptionElement($i, $htmlSelectOption);
598: $i++;
599: }
600:
601: if ($i === 0) {
602: $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '', false);
603: $htmlSelectOption->setAlt(i18n('No files found'));
604: $htmlSelectOption->setDisabled(true);
605: $htmlSelect->addOptionElement($i, $htmlSelectOption);
606: $htmlSelect->setDisabled(true);
607: }
608:
609:
610: if (isset($this->_dirname)) {
611: $htmlSelect->setDefault($this->_dirname . $this->_filename);
612: } else {
613: $htmlSelect->setDefault('');
614: }
615:
616: return $htmlSelect->render();
617: }
618:
619: 620: 621: 622: 623: 624: 625: 626:
627: protected function _isActiveDirectory(array $dirData) {
628: return $dirData['path'] . $dirData['name'] . '/' === $this->_dirname;
629: }
630:
631: 632: 633: 634: 635: 636: 637: 638:
639: protected function _shouldDirectoryBeExpanded(array $dirData) {
640: return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
641: }
642:
643: 644: 645: 646: 647: 648: 649:
650: public function getImageMeta($filename, $dirname) {
651: $upload = new cApiUpload();
652: $upload->loadByMany(array(
653: 'filename' => $filename,
654: 'dirname' => $dirname,
655: 'idclient' => $this->_client
656: ), false);
657: $idupl = $upload->get('idupl');
658:
659: $uploadMeta = new cApiUploadMeta();
660: $uploadMeta->loadByMany(array(
661: 'idupl' => $idupl,
662: 'idlang' => $this->_lang
663: ));
664:
665: $imageMeta = array();
666: $imageMeta['medianame'] = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
667: $imageMeta['description'] = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
668: $imageMeta['keywords'] = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
669: $imageMeta['internal_notice'] = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
670: $imageMeta['copyright'] = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
671:
672: return json_encode($imageMeta);
673: }
674:
675: 676: 677: 678: 679: 680: 681: 682: 683: 684:
685: public function uplmkdir($path, $name) {
686: return uplmkdir($path, $name);
687: }
688:
689: 690: 691: 692: 693: 694:
695: public function uplupload($path) {
696: if (count($_FILES) === 1) {
697: foreach ($_FILES['file']['name'] as $key => $value) {
698: if (file_exists($_FILES['file']['tmp_name'][$key])) {
699: $friendlyName = uplCreateFriendlyName($_FILES['file']['name'][$key]);
700: move_uploaded_file($_FILES['file']['tmp_name'][$key], $this->_cfgClient[$this->_client]['upl']['path'] . $path . $friendlyName);
701:
702: cDebug::out(":::" . $path);
703: uplSyncDirectory($path);
704:
705: $upload = new cApiUpload();
706: $upload->loadByMany(array(
707: 'dirname' => $path,
708: 'filename' => $_FILES['file']['name'][$key]
709: ), false);
710: if ($upload->get('idupl') != false) {
711: $uplfilename = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $upload->get('dirname') . $upload->get('filename');
712: } else {
713: $uplfilename = 'error';
714: }
715: }
716: }
717: }
718:
719: return $uplfilename;
720: }
721:
722: }