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