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