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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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:      * @throws cDbException
112:      * @throws cException
113:      */
114:     public function __construct($rawSettings, $id, array $contentTypes) {
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:         // Define settings for this content type as an array
159:         $this->_settings = array();
160:     }
161: 
162:     /**
163:      * Return the raw settings of a content type
164:      *
165:      * @param string $contentTypeName
166:      *                         Content type name
167:      * @param int    $id
168:      *                         ID of the content type
169:      * @param array  $contentTypes
170:      *                         Content type array
171:      * @param bool   $editable [optional]
172:      * @return mixed
173:      * @throws cDbException
174:      * @throws cException
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:             // get the idtype of the content type
182:             $typeItem = new cApiType();
183:             $typeItem->loadByType($contentTypeName);
184:             $idtype = $typeItem->get('idtype');
185:             // first load the appropriate content entry in order to get the
186:             // settings
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:      * Return the absolute path of the image
218:      *
219:      * @return string
220:      */
221:     public function getAbsolutePath() {
222:         return $this->_cfgClient[$this->_client]['upl']['path'] . $this->_dirname . $this->_filename;
223:     }
224: 
225:     /**
226:      * Return the path of the image relative to the upload directory of the client
227:      *
228:      * @return string
229:      */
230:     public function getRelativePath() {
231:         return $this->_dirname . $this->_filename;
232:     }
233: 
234:     /**
235:      * Returns the absolute URL of the image
236:      *
237:      * @return string
238:      */
239:     public function getAbsoluteURL() {
240:         return $this->_generateImagePath();
241:     }
242: 
243:     /**
244:      * Returns the URL of the image relative to the client base URL
245:      *
246:      * @return string
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:      * Returns an associative array containing the meta information of the image
262:      *
263:      * The array contains the following keys:
264:      * 'medianame'
265:      * 'description'
266:      * 'keywords'
267:      * 'internalnotice'
268:      * 'copyright'
269:      *
270:      * @return array
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:      * Generates the link to the image for use in the src attribute.
284:      *
285:      * @return string
286:      *         the link to the image
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:      * Stores all values from the $_POST array in the $_settings attribute
302:      * (associative array) and saves them in the database (XML).
303:      *
304:      * @throws cDbException
305:      * @throws cException
306:      */
307:     protected function _storeSettings() {
308:         // prepare the filename and dirname
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:         // get the upload ID
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:         // save the content types
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:         // insert / update meta data
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:         // load meta data object
343:         $uploadMeta = new cApiUploadMeta();
344:         $uploadMeta->loadByMany(array(
345:             'idupl' => $this->_rawSettings,
346:             'idlang' => $this->_lang
347:         ));
348:         // if meta data object already exists, update the values
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:             // if meta data object does not exist yet, create a new one
360:             $uploadMetaCollection = new cApiUploadMetaCollection();
361:             $uploadMetaCollection->create($this->_rawSettings, $this->_lang, $medianame, $description, $keywords, $internal_notice, $copyright);
362:         }
363:     }
364: 
365:     /**
366:      * Generates the code which should be shown if this content type is shown in
367:      * the frontend.
368:      *
369:      * @return string
370:      *         escaped HTML code which sould be shown if content type is shown in frontend
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:      * Generates the code which should be shown if this content type is edited.
381:      *
382:      * @return string
383:      *         escaped HTML code which should be shown if content type is edited
384:      * @throws cInvalidArgumentException
385:      */
386:     public function generateEditCode() {
387:         // construct the top code of the template
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:         // create code for upload tab
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:         // create code for directories tab
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:         // create code for meta tab
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:         // Write setting dirname (without backslash at the end)
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:         // construct the bottom code of the template
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:      * Generates code for the directories tab in which various settings can be
454:      * made.
455:      *
456:      * @return string
457:      *         the code for the directories tab
458:      */
459:     private function _generateTabDirectories() {
460:         // define a wrapper which contains the whole content of the directories
461:         // tab
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:      * Generates code for the meta tab in which the images's meta data can be
490:      * edited.
491:      *
492:      * @return string
493:      *         the code for the meta tab
494:      */
495:     private function _generateTabMeta() {
496:         // define a wrapper which contains the whole content of the meta tab
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:      * Generates code for the upload tab in which new images can be uploaded.
524:      *
525:      * @return string
526:      *         the code for the upload tab
527:      */
528:     private function _generateTabUpload() {
529:         // define a wrapper which contains the whole content of the upload tab
530:         $wrapper = new cHTMLDiv();
531:         $wrapperContent = array();
532: 
533:         // create a new directory form
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:         // upload a new file form
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:      * Generate a select box containing all files in the given directory.
612:      *
613:      * @SuppressWarnings docBlocks
614:      * @param string $directoryPath [optional]
615:      *         directory of the files
616:      * @return string
617:      *         rendered cHTMLSelectElement
618:      */
619:     public function generateFileSelect($directoryPath = '') {
620:         // make sure the path ends with a slash
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:         // set default value
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:      * Checks whether the directory defined by the given directory
683:      * information is the currently active directory.
684:      * Overwrite in subclasses if you use getDirectoryList!
685:      *
686:      * @param array $dirData
687:      *         directory information
688:      * @return bool
689:      *         whether the directory is the currently active directory
690:      */
691:     protected function _isActiveDirectory(array $dirData) {
692:         return $dirData['path'] . $dirData['name'] . '/' === $this->_dirname;
693:     }
694: 
695:     /**
696:      * Checks whether the directory defined by the given directory information
697:      * should be shown expanded.
698:      * Overwrite in subclasses if you use getDirectoryList!
699:      *
700:      * @param array $dirData
701:      *         directory information
702:      * @return bool
703:      *         whether the directory should be shown expanded
704:      */
705:     protected function _shouldDirectoryBeExpanded(array $dirData) {
706:         return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
707:     }
708: 
709:     /**
710:      * Gets the meta data of the image with the given filename/dirname.
711:      *
712:      * @param string $filename
713:      *         the filename of the image
714:      * @param string $dirname
715:      *         the dirname of the image
716:      * @return string
717:      *         JSON-encoded array with meta data
718:      * @throws cDbException
719:      * @throws cException
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:      * Creates an upload directory.
748:      * Wrapper function for uplmkdir in functions.upl.php.
749:      *
750:      * @param string $path
751:      *         Path to directory to create, either path from client upload
752:      *         directory or a dbfs path
753:      * @param string $name
754:      *         Name of directory to create
755:      * @return string|void
756:      *         value of filemode as string ('0702') or nothing
757:      */
758:     public function uplmkdir($path, $name) {
759:         return uplmkdir($path, $name);
760:     }
761: 
762:     /**
763:      * Uploads the transmitted files saved in the $_FILES array.
764:      *
765:      * @param string $path
766:      *         the path to which the file should be uploaded
767:      * @return string
768:      *         the filename of the uploaded file
769:      * @throws cDbException
770:      * @throws cException
771:      * @throws cInvalidArgumentException
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: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0