Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cCodeGeneratorAbstract
  • cCodeGeneratorFactory
  • cCodeGeneratorStandard
  • cContentTypeAbstract
  • cContentTypeAbstractTabbed
  • cContentTypeDate
  • cContentTypeFilelist
  • cContentTypeHead
  • cContentTypeHtml
  • cContentTypeHtmlhead
  • cContentTypeImg
  • cContentTypeImgdescr
  • cContentTypeImgeditor
  • cContentTypeLink
  • cContentTypeLinkdescr
  • cContentTypeLinkeditor
  • cContentTypeLinktarget
  • cContentTypeRaw
  • cContentTypeTeaser
  • cContentTypeText
  • cTypeGenerator
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the cContentTypeImgeditor class.
  5:  *
  6:  * @package Core
  7:  * @subpackage ContentType
  8:  * @author Fulai Zhang
  9:  * @author Simon Sprankel
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 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:  * Content type CMS_IMGEDITOR which lets the editor select an image.
 23:  *
 24:  * @package Core
 25:  * @subpackage ContentType
 26:  */
 27: class cContentTypeImgeditor extends cContentTypeAbstractTabbed {
 28: 
 29:     /**
 30:      * The name of the directory where the image is stored.
 31:      *
 32:      * @var string
 33:      */
 34:     private $_dirname;
 35: 
 36:     /**
 37:      * The name of the image file.
 38:      *
 39:      * @var string
 40:      */
 41:     private $_filename;
 42: 
 43:     /**
 44:      * The full path to the image file.
 45:      *
 46:      * @var string
 47:      */
 48:     protected $_imagePath;
 49: 
 50:     /**
 51:      * The file type of the image file.
 52:      *
 53:      * @var string
 54:      */
 55:     private $_fileType;
 56: 
 57:     /**
 58:      * The size of the image file.
 59:      *
 60:      * @var string
 61:      */
 62:     private $_fileSize;
 63: 
 64:     /**
 65:      * The medianame of the image.
 66:      *
 67:      * @var string
 68:      */
 69:     private $_medianame;
 70: 
 71:     /**
 72:      * The description of the image.
 73:      *
 74:      * @var string
 75:      */
 76:     protected $_description;
 77: 
 78:     /**
 79:      * The keywords of the image.
 80:      *
 81:      * @var string
 82:      */
 83:     private $_keywords;
 84: 
 85:     /**
 86:      * The internal notice of the image.
 87:      *
 88:      * @var string
 89:      */
 90:     private $_internalNotice;
 91: 
 92:     /**
 93:      * The copyright of the image.
 94:      *
 95:      * @var string
 96:      */
 97:     private $_copyright;
 98: 
 99:     /**
100:      * Constructor to create an instance of this class.
101:      *
102:      * Initialises class attributes and handles store events.
103:      *
104:      * @param string $rawSettings
105:      *         the raw settings in an XML structure or as plaintext
106:      * @param int $id
107:      *         ID of the content type, e.g. 3 if CMS_DATE[3] is used
108:      * @param array $contentTypes
109:      *         array containing the values of all content types
110:      */
111:     public function __construct($rawSettings, $id, array $contentTypes) {
112: 
113:         // TODO is this required?
114:         global $area;
115: 
116:         // set props
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:         // call parent constructor
129:         parent::__construct($rawSettings, $id, $contentTypes);
130: 
131:         // if form is submitted, store the current teaser settings
132:         // notice: also check the ID of the content type (there could be more
133:         // than one content type of the same type on the same page!)
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:         // get image information from con_upl from the database
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:         // get image information from con_upl_meta from the database
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: 
160:     /**
161:      * Return the raw settings of a content type
162:      *
163:      * @param string $contentTypeName
164:      *         Content type name
165:      * @param int $id
166:      *         ID of the content type
167:      * @param array $contentTypes
168:      *         Content type array
169:      * @param bool $editable [optional]
170:      * @return mixed
171:      */
172:     protected function _getRawSettings($contentTypeName, $id, array $contentTypes, $editable = false) {
173:         $cfg = cRegistry::getConfig();
174: 
175:         if (!isset($contentTypes[$contentTypeName][$id])) {
176:             $idArtLang = cRegistry::getArticleLanguageId();
177:             // get the idtype of the content type
178:             $typeItem = new cApiType();
179:             $typeItem->loadByType($contentTypeName);
180:             $idtype = $typeItem->get('idtype');
181:             // first load the appropriate content entry in order to get the
182:             // settings
183:             if ($editable == false) {
184:                 $content = new cApiContent();
185:                 $content->loadByMany(array(
186:                     'idartlang' => $idArtLang,
187:                     'idtype' => $idtype,
188:                     'typeid' => $id
189:                 ));
190:                 return $content->get('value');
191:             } else if ($editable == true) {
192:                 $db = cRegistry::getDb();
193:                 $sql = "SELECT max(version) AS max
194:                         FROM " . $cfg["tab"]["content_version"] . " WHERE idartlang = " . $idArtLang . " AND typeid = " . $id .
195:                         " AND idtype = '" . $idtype . "'";
196:                 $db->query($sql);
197:                 while($db->nextRecord()) {
198:                     $idContentVersion = $db->f('max');
199:                 }
200: 
201:                 $contentVersion = new cApiContentVersion($idContentVersion);
202: 
203:                 if ($contentVersion->get('deleted') != 1) {
204:                     return $contentVersion->get('value');
205:                 }
206:             }
207:         } else {
208:             return $contentTypes[$contentTypeName][$id];
209:         }
210:     }
211: 
212:     /**
213:      * Return the absolute path of the image
214:      *
215:      * @return string
216:      */
217:     public function getAbsolutePath() {
218:         return $this->_cfgClient[$this->_client]['upl']['path'] . $this->_dirname . $this->_filename;
219:     }
220: 
221:     /**
222:      * Return the path of the image relative to the upload directory of the client
223:      *
224:      * @return string
225:      */
226:     public function getRelativePath() {
227:         return $this->_dirname . $this->_filename;
228:     }
229: 
230:     /**
231:      * Returns the absolute URL of the image
232:      *
233:      * @return string
234:      */
235:     public function getAbsoluteURL() {
236:         return $this->_generateImagePath();
237:     }
238: 
239:     /**
240:      * Returns the URL of the image relative to the client base URL
241:      *
242:      * @return string
243:      */
244:     public function getRelativeURL() {
245:         if (!empty($this->_filename)) {
246:             if (cApiDbfs::isDbfs($this->_dirname)) {
247:                 return 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
248:             } else {
249:                 return $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
250:             }
251:         }
252: 
253:         return '';
254:     }
255: 
256:     /**
257:      * Returns an associative array containing the meta information of the image
258:      *
259:      * The array contains the following keys:
260:      * 'medianame'
261:      * 'description'
262:      * 'keywords'
263:      * 'internalnotice'
264:      * 'copyright'
265:      *
266:      * @return array
267:      */
268:     public function getMetaData() {
269:         return array(
270:             'medianame' => $this->_medianame,
271:             'description' => $this->_description,
272:             'keywords' => $this->_keywords,
273:             'internalnotice' => $this->_internalNotice,
274:             'copyright' => $this->_copyright
275:         );
276:     }
277: 
278:     /**
279:      * Generates the link to the image for use in the src attribute.
280:      *
281:      * @return string
282:      *         the link to the image
283:      */
284:     private function _generateImagePath() {
285:         if (!empty($this->_filename)) {
286:             if (cApiDbfs::isDbfs($this->_dirname)) {
287:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
288:             } else {
289:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
290:             }
291:         }
292: 
293:         return '';
294:     }
295: 
296:     /**
297:      * Stores all values from the $_POST array in the $_settings attribute
298:      * (associative array) and saves them in the database (XML).
299:      */
300:     protected function _storeSettings() {
301:         // prepare the filename and dirname
302:         $filename = basename($_POST['image_filename']);
303:         $dirname = dirname($_POST['image_filename']);
304:         if ($dirname === '\\' || $dirname === '/') {
305:             $dirname = '';
306:         } else {
307:             $dirname .= '/';
308:         }
309: 
310:         // get the upload ID
311:         $upload = new cApiUpload();
312:         $upload->loadByMany(array(
313:             'filename' => $filename,
314:             'dirname' => $dirname,
315:             'idclient' => $this->_client
316:         ), false);
317: 
318:         $this->_rawSettings = $upload->get('idupl');
319: 
320:         // save the content types
321:         conSaveContentEntry($this->_idArtLang, 'CMS_IMGEDITOR', $this->_id, $this->_rawSettings);
322:         $versioning = new cContentVersioning();
323:         if ($versioning->getState() != 'advanced') {
324:             conMakeArticleIndex($this->_idartlang, $this->_idart);
325:         }
326:         conGenerateCodeForArtInAllCategories($this->_idArt);
327: 
328:         // insert / update meta data
329:         $medianame = $_POST['image_medianame'];
330:         $description = $_POST['image_description'];
331:         $keywords = $_POST['image_keywords'];
332:         $internal_notice = $_POST['image_internal_notice'];
333:         $copyright = $_POST['image_copyright'];
334: 
335:         // load meta data object
336:         $uploadMeta = new cApiUploadMeta();
337:         $uploadMeta->loadByMany(array(
338:             'idupl' => $this->_rawSettings,
339:             'idlang' => $this->_lang
340:         ));
341:         // if meta data object already exists, update the values
342:         if ($uploadMeta->get('id_uplmeta') != false) {
343:             $uploadMeta->set('idupl', $this->_rawSettings);
344:             $uploadMeta->set('idlang', $this->_lang);
345:             $uploadMeta->set('medianame', $medianame);
346:             $uploadMeta->set('description', $description);
347:             $uploadMeta->set('keywords', $keywords);
348:             $uploadMeta->set('internal_notice', $internal_notice);
349:             $uploadMeta->set('copyright', $copyright);
350:             $uploadMeta->store();
351:         } else {
352:             // if meta data object does not exist yet, create a new one
353:             $uploadMetaCollection = new cApiUploadMetaCollection();
354:             $uploadMetaCollection->create($this->_rawSettings, $this->_lang, $medianame, $description, $keywords, $internal_notice, $copyright);
355:         }
356:     }
357: 
358:     /**
359:      * Generates the code which should be shown if this content type is shown in
360:      * the frontend.
361:      *
362:      * @return string
363:      *         escaped HTML code which sould be shown if content type is shown in frontend
364:      */
365:     public function generateViewCode() {
366:         $image = new cHTMLImage($this->_imagePath);
367:         $image->setAlt($this->_description);
368: 
369:         return $this->_encodeForOutput($image->render());
370:     }
371: 
372:     /**
373:      * Generates the code which should be shown if this content type is edited.
374:      *
375:      * @return string
376:      *         escaped HTML code which should be shown if content type is edited
377:      */
378:     public function generateEditCode() {
379:         // construct the top code of the template
380:         $templateTop = new cTemplate();
381:         $templateTop->set('s', 'ICON', 'images/but_editimage.gif');
382:         $templateTop->set('s', 'ID', $this->_id);
383:         $templateTop->set('s', 'PREFIX', $this->_prefix);
384:         $templateTop->set('s', 'HEADLINE', i18n('Image settings'));
385:         $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
386: 
387:         $tabMenu = array(
388:             'directories' => i18n('Directories'),
389:             'meta' => i18n('Meta'),
390:             'upload' => i18n('Upload')
391:         );
392: 
393:         $templateTabs = new cTemplate();
394: 
395:         // create code for upload tab
396:         $templateTabs->set('d', 'TAB_ID', 'upload');
397:         $templateTabs->set('d', 'TAB_CLASS', 'upload');
398:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabUpload());
399:         $templateTabs->set('s', 'PREFIX', $this->_prefix);
400:         $templateTabs->next();
401: 
402:         // create code for directories tab
403:         $templateTabs->set('d', 'TAB_ID', 'directories');
404:         $templateTabs->set('d', 'TAB_CLASS', 'directories');
405:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabDirectories());
406:         $templateTabs->next();
407: 
408:         // create code for meta tab
409:         $templateTabs->set('d', 'TAB_ID', 'meta');
410:         $templateTabs->set('d', 'TAB_CLASS', 'meta');
411:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabMeta());
412:         $templateTabs->next();
413: 
414:         $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
415: 
416:         // construct the bottom code of the template
417:         $templateBottom = new cTemplate();
418:         $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
419:         $templateBottom->set('s', 'ID', $this->_id);
420:         $templateBottom->set('s', 'PREFIX', $this->_prefix);
421:         $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
422:         $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
423:         $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
424:         $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsImgeditor.js');
425:         $templateBottom->set('s', 'JS_CLASS_NAME', 'Con.cContentTypeImgeditor');
426:         $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
427: 
428:         $code = $this->_encodeForOutput($codeTop);
429:         $code .= $this->_generateTabMenuCode($tabMenu);
430:         $code .= $this->_encodeForOutput($codeTabs);
431:         $code .= $this->_generateActionCode();
432:         $code .= $this->_encodeForOutput($codeBottom);
433: 
434:         return $code;
435:     }
436: 
437:     /**
438:      * Generates code for the directories tab in which various settings can be
439:      * made.
440:      *
441:      * @return string
442:      *         the code for the directories tab
443:      */
444:     private function _generateTabDirectories() {
445:         // define a wrapper which contains the whole content of the directories
446:         // tab
447:         $wrapper = new cHTMLDiv();
448:         $wrapperContent = array();
449: 
450:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
451:         $liRoot = new cHTMLListItem('root', 'root');
452:         $aUpload = new cHTMLLink('#');
453:         $aUpload->setClass('on');
454:         $aUpload->setAttribute('title', 'upload');
455:         $aUpload->setContent('Uploads');
456:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
457:         $div = new cHTMLDiv(array(
458:             '<em><a href="#"></a></em>',
459:             $aUpload
460:         ));
461:         $liRoot->setContent(array(
462:             $div,
463:             $directoryListCode
464:         ));
465:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
466:         $directoryList->setContent($conStrTree);
467:         $wrapperContent[] = $directoryList;
468: 
469:         $wrapperContent[] = new cHTMLDiv($this->generateFileSelect($this->_dirname), 'directoryFile', 'directoryFile' . '_' . $this->_id);
470: 
471:         $directoryShow = new cHTMLDiv('', 'directoryShow', 'directoryShow_' . $this->_id);
472:         $imagePath = $this->_imagePath;
473:         $imageFilename = str_replace($this->_cfgClient[$this->_client]['path']['htmlpath'], $this->_cfgClient[$this->_client]['path']['frontend'], $imagePath);
474:         $imageFiletype = substr($imagePath, strlen($imagePath) - 4, 4);
475:         $imageExtensions = array(
476:             '.gif',
477:             '.png',
478:             '.jpg',
479:             'jpeg'
480:         );
481:         if (in_array($imageFiletype, $imageExtensions)) {
482:             $imagePath = cApiImgScale($imageFilename, 428, 210);
483:         }
484:         $image = new cHTMLImage($imagePath);
485:         $directoryShow->setContent($image);
486:         $wrapperContent[] = $directoryShow;
487: 
488:         $wrapper->setContent($wrapperContent);
489:         return $wrapper->render();
490:     }
491: 
492:     /**
493:      * Generates code for the meta tab in which the images's meta data can be
494:      * edited.
495:      *
496:      * @return string
497:      *         the code for the meta tab
498:      */
499:     private function _generateTabMeta() {
500:         // define a wrapper which contains the whole content of the meta tab
501:         $wrapper = new cHTMLDiv();
502:         $wrapperContent = array();
503: 
504:         $imageMetaUrl = new cHTMLSpan();
505:         $imageMetaUrl->setID('image_meta_url_' . $this->_id);
506:         $imageMetaUrl->setClass('image_meta_url');
507:         $wrapperContent[] = new cHTMLDiv(array(
508:             '<b>' . i18n('Selected file') . '</b>',
509:             $imageMetaUrl
510:         ));
511:         $wrapperContent[] = new cHTMLLabel(i18n('Title'), 'image_medianame_' . $this->_id);
512:         $wrapperContent[] = new cHTMLTextbox('image_medianame', $this->_medianame, '', '', 'image_medianame_' . $this->_id);
513:         $wrapperContent[] = new cHTMLLabel(i18n('Description'), 'image_description_' . $this->_id);
514:         $wrapperContent[] = new cHTMLTextarea('image_description', $this->_description, '', '', 'image_description_' . $this->_id);
515:         $wrapperContent[] = new cHTMLLabel(i18n('Keywords'), 'image_keywords_' . $this->_id);
516:         $wrapperContent[] = new cHTMLTextbox('image_keywords', $this->_keywords, '', '', 'image_keywords_' . $this->_id);
517:         $wrapperContent[] = new cHTMLLabel(i18n('Internal notes'), 'image_internal_notice_' . $this->_id);
518:         $wrapperContent[] = new cHTMLTextbox('image_internal_notice', $this->_internalNotice, '', '', 'image_internal_notice_' . $this->_id);
519:         $wrapperContent[] = new cHTMLLabel(i18n('Copyright'), 'image_copyright_' . $this->_id);
520:         $wrapperContent[] = new cHTMLTextbox('image_copyright', $this->_copyright, '', '', 'image_copyright_' . $this->_id);
521: 
522:         $wrapper->setContent($wrapperContent);
523:         return $wrapper->render();
524:     }
525: 
526:     /**
527:      * Generates code for the upload tab in which new images can be uploaded.
528:      *
529:      * @return string
530:      *         the code for the upload tab
531:      */
532:     private function _generateTabUpload() {
533:         // define a wrapper which contains the whole content of the upload tab
534:         $wrapper = new cHTMLDiv();
535:         $wrapperContent = array();
536: 
537:         // create a new directory form
538:         $newDirForm = new cHTMLForm();
539:         $newDirForm->setAttribute('name', 'newdir');
540:         $newDirForm->setAttribute('method', 'post');
541:         $newDirForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
542:         $caption1Span = new cHTMLSpan();
543:         $caption1Span->setID('caption1');
544:         $newDirHead = new cHTMLDiv(array(
545:             '<b>' . i18n('Create a directory in') . '</b>',
546:             $caption1Span
547:         ));
548:         $area = new cHTMLHiddenField('area', 'upl');
549:         $action = new cHTMLHiddenField('action', 'upl_mkdir');
550:         $frame = new cHTMLHiddenField('frame', '2');
551:         $appendparameters = new cHTMLHiddenField('appendparameters');
552:         $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
553:         $path = new cHTMLHiddenField('path');
554:         $foldername = new cHTMLTextbox('foldername');
555:         $button = new cHTMLButton('', '', '', false, NULL, '', 'image');
556:         $button->setAttribute('src', $this->_cfg['path']['contenido_fullhtml'] . 'images/submit.gif');
557:         $newDirContent = new cHTMLDiv(array(
558:             $area,
559:             $action,
560:             $frame,
561:             $appendparameters,
562:             $contenido,
563:             $path,
564:             $foldername,
565:             $button
566:         ));
567:         $newDirForm->setContent(array(
568:             $newDirHead,
569:             $newDirContent
570:         ));
571:         $wrapperContent[] = $newDirForm;
572: 
573:         // upload a new file form
574:         $propertiesForm = new cHTMLForm();
575:         $propertiesForm->setID('properties' . $this->_id);
576:         $propertiesForm->setAttribute('name', 'properties');
577:         $propertiesForm->setAttribute('method', 'post');
578:         $propertiesForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
579:         $propertiesForm->setAttribute('enctype', 'multipart/form-data');
580:         $frame = new cHTMLHiddenField('frame', '4');
581:         $area = new cHTMLHiddenField('area', 'upl');
582:         $path = new cHTMLHiddenField('path');
583:         $file = new cHTMLHiddenField('file');
584:         $action = new cHTMLHiddenField('action', 'upl_upload');
585:         $appendparameters = new cHTMLHiddenField('appendparameters');
586:         $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
587:         $caption2Span = new cHTMLSpan();
588:         $caption2Span->setID('caption2');
589:         $propertiesHead = new cHTMLDiv(array(
590:             '<b>' . i18n('Path') . '</b>',
591:             $caption2Span
592:         ));
593:         $imageUpload = new cHTMLUpload('file[]', '', '', 'cms_image_m' . $this->_id, false, '', '', 'file');
594:         $imageUpload->setClass('jqueryAjaxUpload');
595:         $propertiesForm->setContent(array(
596:             $frame,
597:             $area,
598:             $path,
599:             $file,
600:             $action,
601:             $appendparameters,
602:             $contenido,
603:             $propertiesHead,
604:             $imageUpload
605:         ));
606:         $wrapperContent[] = $propertiesForm;
607: 
608:         $wrapperContent[] = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/ajax-loader.gif', 'loading');
609: 
610:         $wrapper->setContent($wrapperContent);
611:         return $wrapper->render();
612:     }
613: 
614:     /**
615:      * Generate a select box containing all files in the given directory.
616:      *
617:      * @SuppressWarnings docBlocks
618:      * @param string $directoryPath [optional]
619:      *         directory of the files
620:      * @return string
621:      *         rendered cHTMLSelectElement
622:      */
623:     public function generateFileSelect($directoryPath = '') {
624:         // make sure the path ends with a slash
625:         if (substr($directoryPath, -1) != '/') {
626:             $directoryPath .= '/';
627:         }
628: 
629:         $htmlSelect = new cHTMLSelectElement('image_filename', '', 'image_filename_' . $this->_id);
630:         $htmlSelect->setSize(16);
631:         $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
632:         $htmlSelect->addOptionElement(0, $htmlSelectOption);
633: 
634:         $files = array();
635:         if (is_dir($this->_uploadPath . $directoryPath)) {
636:             if (false !== ($handle = cDirHandler::read($this->_uploadPath . $directoryPath, false, false, true))) {
637:                 foreach ($handle as $entry) {
638:                     if (false === cFileHandler::fileNameBeginsWithDot($entry)) {
639:                         $file = array();
640:                         $file["name"] = $entry;
641:                         $file["path"] = $directoryPath . $entry;
642:                         $files[] = $file;
643:                     }
644:                 }
645:             }
646:         }
647: 
648:         usort($files, function($a, $b) {
649:             $a = mb_strtolower($a["name"]);
650:             $b = mb_strtolower($b["name"]);
651:             if($a < $b) {
652:                 return -1;
653:             } else if($a > $b) {
654:                 return 1;
655:             } else {
656:                 return 0;
657:             }
658:         });
659: 
660:         $i = 1;
661:         foreach($files as $file) {
662:             $htmlSelectOption = new cHTMLOptionElement($file["name"], $file["path"]);
663:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
664:             $i++;
665:         }
666: 
667:         if ($i === 0) {
668:             $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '', false);
669:             $htmlSelectOption->setAlt(i18n('No files found'));
670:             $htmlSelectOption->setDisabled(true);
671:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
672:             $htmlSelect->setDisabled(true);
673:         }
674: 
675:         // set default value
676:         if (isset($this->_dirname)) {
677:             $htmlSelect->setDefault($this->_dirname . $this->_filename);
678:         } else {
679:             $htmlSelect->setDefault('');
680:         }
681: 
682:         return $htmlSelect->render();
683:     }
684: 
685:     /**
686:      * Checks whether the directory defined by the given directory
687:      * information is the currently active directory.
688:      * Overwrite in subclasses if you use getDirectoryList!
689:      *
690:      * @param array $dirData
691:      *         directory information
692:      * @return bool
693:      *         whether the directory is the currently active directory
694:      */
695:     protected function _isActiveDirectory(array $dirData) {
696:         return $dirData['path'] . $dirData['name'] . '/' === $this->_dirname;
697:     }
698: 
699:     /**
700:      * Checks whether the directory defined by the given directory information
701:      * should be shown expanded.
702:      * Overwrite in subclasses if you use getDirectoryList!
703:      *
704:      * @param array $dirData
705:      *         directory information
706:      * @return bool
707:      *         whether the directory should be shown expanded
708:      */
709:     protected function _shouldDirectoryBeExpanded(array $dirData) {
710:         return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
711:     }
712: 
713:     /**
714:      * Gets the meta data of the image with the given filename/dirname.
715:      *
716:      * @param string $filename
717:      *         the filename of the image
718:      * @param string $dirname
719:      *         the dirname of the image
720:      * @return string
721:      *         JSON-encoded array with meta data
722:      */
723:     public function getImageMeta($filename, $dirname) {
724:         $upload = new cApiUpload();
725:         $upload->loadByMany(array(
726:             'filename' => $filename,
727:             'dirname' => $dirname,
728:             'idclient' => $this->_client
729:         ), false);
730:         $idupl = $upload->get('idupl');
731: 
732:         $uploadMeta = new cApiUploadMeta();
733:         $uploadMeta->loadByMany(array(
734:             'idupl' => $idupl,
735:             'idlang' => $this->_lang
736:         ));
737: 
738:         $imageMeta = array();
739:         $imageMeta['medianame'] = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
740:         $imageMeta['description'] = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
741:         $imageMeta['keywords'] = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
742:         $imageMeta['internal_notice'] = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
743:         $imageMeta['copyright'] = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
744: 
745:         return json_encode($imageMeta);
746:     }
747: 
748:     /**
749:      * Creates an upload directory.
750:      * Wrapper function for uplmkdir in functions.upl.php.
751:      *
752:      * @param string $path
753:      *         Path to directory to create, either path from client upload
754:      *         directory or a dbfs path
755:      * @param string $name
756:      *         Name of directory to create
757:      * @return string|void
758:      *         value of filemode as string ('0702') or nothing
759:      */
760:     public function uplmkdir($path, $name) {
761:         return uplmkdir($path, $name);
762:     }
763: 
764:     /**
765:      * Uploads the transmitted files saved in the $_FILES array.
766:      *
767:      * @param string $path
768:      *         the path to which the file should be uploaded
769:      * @return string
770:      *         the filename of the uploaded file
771:      */
772:     public function uplupload($path) {
773:         if (count($_FILES) === 1) {
774:             foreach ($_FILES['file']['name'] as $key => $value) {
775:                 if (file_exists($_FILES['file']['tmp_name'][$key])) {
776:                     $friendlyName = uplCreateFriendlyName($_FILES['file']['name'][$key]);
777:                     move_uploaded_file($_FILES['file']['tmp_name'][$key], $this->_cfgClient[$this->_client]['upl']['path'] . $path . $friendlyName);
778: 
779:                     cDebug::out(":::" . $path);
780:                     uplSyncDirectory($path);
781: 
782:                     $upload = new cApiUpload();
783:                     $upload->loadByMany(array(
784:                         'dirname' => $path,
785:                         'filename' => $_FILES['file']['name'][$key]
786:                     ), false);
787:                     if ($upload->get('idupl') != false) {
788:                         $uplfilename = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $upload->get('dirname') . $upload->get('filename');
789:                     } else {
790:                         $uplfilename = 'error';
791:                     }
792:                 }
793:             }
794:         }
795: 
796:         return $uplfilename;
797:     }
798: 
799: }
800: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0