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', 'last');
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 ($handle = opendir($this->_uploadPath . $directoryPath)) {
571: while (($entry = readdir($handle)) != false) {
572: if (is_file($this->_uploadPath . $directoryPath . $entry) && (! (strpos($entry, ".") === 0))) {
573: $file = array();
574: $file["name"] = $entry;
575: $file["path"] = $directoryPath . $entry;
576: $files[] = $file;
577: }
578: }
579: closedir($handle);
580: }
581: }
582:
583: usort($files, function($a, $b) {
584: $a = mb_strtolower($a["name"]);
585: $b = mb_strtolower($b["name"]);
586: if($a < $b) {
587: return -1;
588: } else if($a > $b) {
589: return 1;
590: } else {
591: return 0;
592: }
593: });
594:
595: $i = 1;
596: foreach($files as $file) {
597: $htmlSelectOption = new cHTMLOptionElement($file["name"], $file["path"]);
598: $htmlSelect->addOptionElement($i, $htmlSelectOption);
599: $i++;
600: }
601:
602: if ($i === 0) {
603: $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '', false);
604: $htmlSelectOption->setAlt(i18n('No files found'));
605: $htmlSelectOption->setDisabled(true);
606: $htmlSelect->addOptionElement($i, $htmlSelectOption);
607: $htmlSelect->setDisabled(true);
608: }
609:
610:
611: if (isset($this->_dirname)) {
612: $htmlSelect->setDefault($this->_dirname . $this->_filename);
613: } else {
614: $htmlSelect->setDefault('');
615: }
616:
617: return $htmlSelect->render();
618: }
619:
620: 621: 622: 623: 624: 625: 626: 627:
628: protected function _isActiveDirectory(array $dirData) {
629: return $dirData['path'] . $dirData['name'] . '/' === $this->_dirname;
630: }
631:
632: 633: 634: 635: 636: 637: 638: 639:
640: protected function _shouldDirectoryBeExpanded(array $dirData) {
641: return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
642: }
643:
644: 645: 646: 647: 648: 649: 650:
651: public function getImageMeta($filename, $dirname) {
652: $upload = new cApiUpload();
653: $upload->loadByMany(array(
654: 'filename' => $filename,
655: 'dirname' => $dirname,
656: 'idclient' => $this->_client
657: ), false);
658: $idupl = $upload->get('idupl');
659:
660: $uploadMeta = new cApiUploadMeta();
661: $uploadMeta->loadByMany(array(
662: 'idupl' => $idupl,
663: 'idlang' => $this->_lang
664: ));
665:
666: $imageMeta = array();
667: $imageMeta['medianame'] = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
668: $imageMeta['description'] = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
669: $imageMeta['keywords'] = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
670: $imageMeta['internal_notice'] = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
671: $imageMeta['copyright'] = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
672:
673: return json_encode($imageMeta);
674: }
675:
676: 677: 678: 679: 680: 681: 682: 683: 684: 685:
686: public function uplmkdir($path, $name) {
687: return uplmkdir($path, $name);
688: }
689:
690: 691: 692: 693: 694: 695:
696: public function uplupload($path) {
697: if (count($_FILES) === 1) {
698: foreach ($_FILES['file']['name'] as $key => $value) {
699: if (file_exists($_FILES['file']['tmp_name'][$key])) {
700: $friendlyName = uplCreateFriendlyName($_FILES['file']['name'][$key]);
701: move_uploaded_file($_FILES['file']['tmp_name'][$key], $this->_cfgClient[$this->_client]['upl']['path'] . $path . $friendlyName);
702:
703: cDebug::out(":::" . $path);
704: uplSyncDirectory($path);
705:
706: $upload = new cApiUpload();
707: $upload->loadByMany(array(
708: 'dirname' => $path,
709: 'filename' => $_FILES['file']['name'][$key]
710: ), false);
711: if ($upload->get('idupl') != false) {
712: $uplfilename = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $upload->get('dirname') . $upload->get('filename');
713: } else {
714: $uplfilename = 'error';
715: }
716: }
717: }
718: }
719:
720: return $uplfilename;
721: }
722:
723: }