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