Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • 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
  • cContentTypeTeaser
  • cContentTypeText
  • cTypeGenerator
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the cContentTypeImgeditor class.
  4:  *
  5:  * @package Core
  6:  * @subpackage ContentType
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Fulai Zhang, 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:      * Initialises class attributes and handles store events.
101:      *
102:      * @param string $rawSettings the raw settings in an XML structure or as
103:      *        plaintext
104:      * @param int $id ID of the content type, e.g. 3 if CMS_DATE[3] is
105:      *        used
106:      * @param array $contentTypes array containing the values of all content
107:      *        types
108:      */
109:     public function __construct($rawSettings, $id, array $contentTypes) {
110:         // change attributes from the parent class and call the parent
111:         // constructor
112:         $this->_type = 'CMS_IMGEDITOR';
113:         $this->_prefix = 'imgeditor';
114:         $this->_formFields = array(
115:             'image_filename',
116:             'image_medianame',
117:             'image_description',
118:             'image_keywords',
119:             'image_internal_notice',
120:             'image_copyright'
121:         );
122:         parent::__construct($rawSettings, $id, $contentTypes);
123: 
124:         // get image information from con_upl from the database
125:         $upload = new cApiUpload($this->_rawSettings);
126:         $this->_filename = $upload->get('filename');
127:         $this->_dirname = $upload->get('dirname');
128:         $this->_imagePath = $this->_generateImagePath();
129:         $this->_fileType = $upload->get('filetype');
130:         $this->_fileSize = $upload->get('size');
131: 
132:         // get image information from con_upl_meta from the database
133:         $uploadMeta = new cApiUploadMeta();
134:         $uploadMeta->loadByMany(array(
135:             'idupl' => $this->_rawSettings,
136:             'idlang' => $this->_lang
137:         ));
138:         $this->_medianame = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
139:         $this->_description = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
140:         $this->_keywords = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
141:         $this->_internalNotice = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
142:         $this->_copyright = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
143: 
144:         // if form is submitted, store the current teaser settings
145:         // notice: also check the ID of the content type (there could be more
146:         // than one content type of the same type on the same page!)
147:         if (isset($_POST[$this->_prefix . '_action']) && $_POST[$this->_prefix . '_action'] === 'store' && isset($_POST[$this->_prefix . '_id']) && (int) $_POST[$this->_prefix . '_id'] == $this->_id) {
148:             $this->_storeSettings();
149:             $path = $this->_cfg['path']['contenido_fullhtml'] . "external/backendedit/front_content.php?area=con_editcontent&idart=$this->_idArt&idcat=$this->_idCat&changeview=edit&client=$this->_client";
150:             header('location:' . $this->_session->url($path));
151:         }
152:     }
153: 
154:     /**
155:      * Return the absolute path of the image
156:      *
157:      * @return string
158:      */
159:     public function getAbsolutePath() {
160:         return $this->_cfgClient[$this->_client]['upl']['path'] . $this->_dirname . $this->_filename;
161:     }
162: 
163:     /**
164:      * Return the path of the image relative to the upload directory of the client
165:      *
166:      * @return string
167:      */
168:     public function getRelativePath() {
169:         return $this->_dirname . $this->_filename;
170:     }
171: 
172:     /**
173:      * Returns the absolute URL of the image
174:      *
175:      * @return string
176:      */
177:     public function getAbsoluteURL() {
178:         return $this->_generateImagePath();
179:     }
180: 
181:     /**
182:      * Returns the URL of the image relative to the client base URL
183:      *
184:      * @return string
185:      */
186:     public function getRelativeURL() {
187:         if (!empty($this->_filename)) {
188:             if (cApiDbfs::isDbfs($this->_dirname)) {
189:                 return 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
190:             } else {
191:                 return $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
192:             }
193:         }
194: 
195:         return '';
196:     }
197: 
198:     /**
199:      * Returns an associative array containing the meta information of the image
200:      *
201:      * The array contains the following keys:
202:      * 'medianame'
203:      * 'description'
204:      * 'keywords'
205:      * 'internalnotice'
206:      * 'copyright'
207:      *
208:      * @return array
209:      */
210:     public function getMetaData() {
211:         return array(
212:             'medianame' => $this->_medianame,
213:             'description' => $this->_description,
214:             'keywords' => $this->_keywords,
215:             'internalnotice' => $this->_internalNotice,
216:             'copyright' => $this->_copyright
217:         );
218:     }
219: 
220:     /**
221:      * Generates the link to the image for use in the src attribute.
222:      *
223:      * @return string the link to the image
224:      */
225:     private function _generateImagePath() {
226:         if (!empty($this->_filename)) {
227:             if (cApiDbfs::isDbfs($this->_dirname)) {
228:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . 'dbfs.php?file=' . urlencode($this->_dirname . $this->_filename);
229:             } else {
230:                 return $this->_cfgClient[$this->_client]['path']['htmlpath'] . $this->_cfgClient[$this->_client]['upload'] . $this->_dirname . $this->_filename;
231:             }
232:         }
233: 
234:         return '';
235:     }
236: 
237:     /**
238:      * Stores all values from the $_POST array in the $_settings attribute
239:      * (associative array) and saves them in the database (XML).
240:      *
241:      */
242:     protected function _storeSettings() {
243:         // prepare the filename and dirname
244:         $filename = basename($_POST['image_filename']);
245:         $dirname = dirname($_POST['image_filename']);
246:         if ($dirname === '\\' || $dirname === '/') {
247:             $dirname = '';
248:         } else {
249:             $dirname .= '/';
250:         }
251: 
252:         // get the upload ID
253:         $upload = new cApiUpload();
254:         $upload->loadByMany(array(
255:             'filename' => $filename,
256:             'dirname' => $dirname,
257:             'idclient' => $this->_client
258:         ), false);
259: 
260:         $this->_rawSettings = $upload->get('idupl');
261: 
262:         // save the content types
263:         conSaveContentEntry($this->_idArtLang, 'CMS_IMGEDITOR', $this->_id, $this->_rawSettings);
264:         conMakeArticleIndex($this->_idArtLang, $this->_idArt);
265:         conGenerateCodeForArtInAllCategories($this->_idArt);
266: 
267:         // insert / update meta data
268:         $medianame = $_POST['image_medianame'];
269:         $description = $_POST['image_description'];
270:         $keywords = $_POST['image_keywords'];
271:         $internal_notice = $_POST['image_internal_notice'];
272:         $copyright = $_POST['image_copyright'];
273: 
274:         // load meta data object
275:         $uploadMeta = new cApiUploadMeta();
276:         $uploadMeta->loadByMany(array(
277:             'idupl' => $this->_rawSettings,
278:             'idlang' => $this->_lang
279:         ));
280:         // if meta data object already exists, update the values
281:         if ($uploadMeta->get('id_uplmeta') != false) {
282:             $uploadMeta->set('idupl', $this->_rawSettings);
283:             $uploadMeta->set('idlang', $this->_lang);
284:             $uploadMeta->set('medianame', $medianame);
285:             $uploadMeta->set('description', $description);
286:             $uploadMeta->set('keywords', $keywords);
287:             $uploadMeta->set('internal_notice', $internal_notice);
288:             $uploadMeta->set('copyright', $copyright);
289:             $uploadMeta->store();
290:         } else {
291:             // if meta data object does not exist yet, create a new one
292:             $uploadMetaCollection = new cApiUploadMetaCollection();
293:             $uploadMetaCollection->create($this->_rawSettings, $this->_lang, $medianame, $description, $keywords, $internal_notice, $copyright);
294:         }
295:     }
296: 
297:     /**
298:      * Generates the code which should be shown if this content type is shown in
299:      * the frontend.
300:      *
301:      * @return string escaped HTML code which sould be shown if content type is
302:      *         shown in frontend
303:      */
304:     public function generateViewCode() {
305:         $image = new cHTMLImage($this->_imagePath);
306:         $image->setAlt($this->_description);
307: 
308:         return $this->_encodeForOutput($image->render());
309:     }
310: 
311:     /**
312:      * Generates the code which should be shown if this content type is edited.
313:      *
314:      * @return string escaped HTML code which should be shown if content type is
315:      *         edited
316:      */
317:     public function generateEditCode() {
318:         // construct the top code of the template
319:         $templateTop = new cTemplate();
320:         $templateTop->set('s', 'ICON', 'images/but_editimage.gif');
321:         $templateTop->set('s', 'ID', $this->_id);
322:         $templateTop->set('s', 'PREFIX', $this->_prefix);
323:         $templateTop->set('s', 'HEADLINE', i18n('Image settings'));
324:         $codeTop = $templateTop->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_top.html', true);
325: 
326:         $tabMenu = array(
327:             'directories' => i18n('Directories'),
328:             'meta' => i18n('Meta'),
329:             'upload' => i18n('Upload')
330:         );
331: 
332:         $templateTabs = new cTemplate();
333: 
334:         // create code for upload tab
335:         $templateTabs->set('d', 'TAB_ID', 'upload');
336:         $templateTabs->set('d', 'TAB_CLASS', 'upload');
337:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabUpload());
338:         $templateTabs->set('s', 'PREFIX', $this->_prefix);
339:         $templateTabs->next();
340: 
341:         // create code for directories tab
342:         $templateTabs->set('d', 'TAB_ID', 'directories');
343:         $templateTabs->set('d', 'TAB_CLASS', 'directories');
344:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabDirectories());
345:         $templateTabs->next();
346: 
347:         // create code for meta tab
348:         $templateTabs->set('d', 'TAB_ID', 'meta');
349:         $templateTabs->set('d', 'TAB_CLASS', 'meta');
350:         $templateTabs->set('d', 'TAB_CONTENT', $this->_generateTabMeta());
351:         $templateTabs->next();
352: 
353:         $codeTabs = $templateTabs->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_tabs.html', true);
354: 
355:         // construct the bottom code of the template
356:         $templateBottom = new cTemplate();
357:         $templateBottom->set('s', 'PATH_FRONTEND', $this->_cfgClient[$this->_client]['path']['htmlpath']);
358:         $templateBottom->set('s', 'ID', $this->_id);
359:         $templateBottom->set('s', 'PREFIX', $this->_prefix);
360:         $templateBottom->set('s', 'IDARTLANG', $this->_idArtLang);
361:         $templateBottom->set('s', 'FIELDS', "'" . implode("','", $this->_formFields) . "'");
362:         $templateBottom->set('s', 'SETTINGS', json_encode($this->_settings));
363:         $templateBottom->set('s', 'JS_CLASS_SCRIPT', $this->_cfg['path']['contenido_fullhtml'] . 'scripts/content_types/cmsImgeditor.js');
364:         $templateBottom->set('s', 'JS_CLASS_NAME', 'Con.cContentTypeImgeditor');
365:         $codeBottom = $templateBottom->generate($this->_cfg['path']['contenido'] . 'templates/standard/template.cms_abstract_tabbed_edit_bottom.html', true);
366: 
367:         $code = $this->_encodeForOutput($codeTop);
368:         $code .= $this->_generateTabMenuCode($tabMenu);
369:         $code .= $this->_encodeForOutput($codeTabs);
370:         $code .= $this->_generateActionCode();
371:         $code .= $this->_encodeForOutput($codeBottom);
372: 
373:         return $code;
374:     }
375: 
376:     /**
377:      * Generates code for the directories tab in which various settings can be
378:      * made.
379:      *
380:      * @return string - the code for the directories tab
381:      */
382:     private function _generateTabDirectories() {
383:         // define a wrapper which contains the whole content of the directories
384:         // tab
385:         $wrapper = new cHTMLDiv();
386:         $wrapperContent = array();
387: 
388:         $directoryList = new cHTMLDiv('', 'directoryList', 'directoryList' . '_' . $this->_id);
389:         $liRoot = new cHTMLListItem('root', 'last');
390:         $aUpload = new cHTMLLink('#');
391:         $aUpload->setClass('on');
392:         $aUpload->setAttribute('title', 'upload');
393:         $aUpload->setContent('Uploads');
394:         $directoryListCode = $this->generateDirectoryList($this->buildDirectoryList());
395:         $div = new cHTMLDiv(array(
396:             '<em><a href="#"></a></em>',
397:             $aUpload
398:         ));
399:         $liRoot->setContent(array(
400:             $div,
401:             $directoryListCode
402:         ));
403:         $conStrTree = new cHTMLList('ul', 'con_str_tree', 'con_str_tree', $liRoot);
404:         $directoryList->setContent($conStrTree);
405:         $wrapperContent[] = $directoryList;
406: 
407:         $wrapperContent[] = new cHTMLDiv($this->generateFileSelect($this->_dirname), 'directoryFile', 'directoryFile' . '_' . $this->_id);
408: 
409:         $directoryShow = new cHTMLDiv('', 'directoryShow', 'directoryShow_' . $this->_id);
410:         $imagePath = $this->_imagePath;
411:         $imageFilename = str_replace($this->_cfgClient[$this->_client]['path']['htmlpath'], $this->_cfgClient[$this->_client]['path']['frontend'], $imagePath);
412:         $imageFiletype = substr($imagePath, strlen($imagePath) - 4, 4);
413:         $imageExtensions = array(
414:             '.gif',
415:             '.png',
416:             '.jpg',
417:             'jpeg'
418:         );
419:         if (in_array($imageFiletype, $imageExtensions)) {
420:             $imagePath = cApiImgScale($imageFilename, 428, 210);
421:         }
422:         $image = new cHTMLImage($imagePath);
423:         $directoryShow->setContent($image);
424:         $wrapperContent[] = $directoryShow;
425: 
426:         $wrapper->setContent($wrapperContent);
427:         return $wrapper->render();
428:     }
429: 
430:     /**
431:      * Generates code for the meta tab in which the images's meta data can be
432:      * edited.
433:      *
434:      * @return string - the code for the meta tab
435:      */
436:     private function _generateTabMeta() {
437:         // define a wrapper which contains the whole content of the meta tab
438:         $wrapper = new cHTMLDiv();
439:         $wrapperContent = array();
440: 
441:         $imageMetaUrl = new cHTMLSpan();
442:         $imageMetaUrl->setID('image_meta_url_' . $this->_id);
443:         $imageMetaUrl->setClass('image_meta_url');
444:         $wrapperContent[] = new cHTMLDiv(array(
445:             '<b>' . i18n('Selected file') . '</b>',
446:             $imageMetaUrl
447:         ));
448:         $wrapperContent[] = new cHTMLLabel(i18n('Title'), 'image_medianame_' . $this->_id);
449:         $wrapperContent[] = new cHTMLTextbox('image_medianame', $this->_medianame, '', '', 'image_medianame_' . $this->_id);
450:         $wrapperContent[] = new cHTMLLabel(i18n('Description'), 'image_description_' . $this->_id);
451:         $wrapperContent[] = new cHTMLTextarea('image_description', $this->_description, '', '', 'image_description_' . $this->_id);
452:         $wrapperContent[] = new cHTMLLabel(i18n('Keywords'), 'image_keywords_' . $this->_id);
453:         $wrapperContent[] = new cHTMLTextbox('image_keywords', $this->_keywords, '', '', 'image_keywords_' . $this->_id);
454:         $wrapperContent[] = new cHTMLLabel(i18n('Internal notes'), 'image_internal_notice_' . $this->_id);
455:         $wrapperContent[] = new cHTMLTextbox('image_internal_notice', $this->_internalNotice, '', '', 'image_internal_notice_' . $this->_id);
456:         $wrapperContent[] = new cHTMLLabel(i18n('Copyright'), 'image_copyright_' . $this->_id);
457:         $wrapperContent[] = new cHTMLTextbox('image_copyright', $this->_copyright, '', '', 'image_copyright_' . $this->_id);
458: 
459:         $wrapper->setContent($wrapperContent);
460:         return $wrapper->render();
461:     }
462: 
463:     /**
464:      * Generates code for the upload tab in which new images can be uploaded.
465:      *
466:      * @return string - the code for the upload tab
467:      */
468:     private function _generateTabUpload() {
469:         // define a wrapper which contains the whole content of the upload tab
470:         $wrapper = new cHTMLDiv();
471:         $wrapperContent = array();
472: 
473:         // create a new directory form
474:         $newDirForm = new cHTMLForm();
475:         $newDirForm->setAttribute('name', 'newdir');
476:         $newDirForm->setAttribute('method', 'post');
477:         $newDirForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
478:         $caption1Span = new cHTMLSpan();
479:         $caption1Span->setID('caption1');
480:         $newDirHead = new cHTMLDiv(array(
481:             '<b>' . i18n('Create a directory in') . '</b>',
482:             $caption1Span
483:         ));
484:         $area = new cHTMLHiddenField('area', 'upl');
485:         $action = new cHTMLHiddenField('action', 'upl_mkdir');
486:         $frame = new cHTMLHiddenField('frame', '2');
487:         $appendparameters = new cHTMLHiddenField('appendparameters');
488:         $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
489:         $path = new cHTMLHiddenField('path');
490:         $foldername = new cHTMLTextbox('foldername');
491:         $button = new cHTMLButton('', '', '', false, NULL, '', 'image');
492:         $button->setAttribute('src', $this->_cfg['path']['contenido_fullhtml'] . 'images/submit.gif');
493:         $newDirContent = new cHTMLDiv(array(
494:             $area,
495:             $action,
496:             $frame,
497:             $appendparameters,
498:             $contenido,
499:             $path,
500:             $foldername,
501:             $button
502:         ));
503:         $newDirForm->setContent(array(
504:             $newDirHead,
505:             $newDirContent
506:         ));
507:         $wrapperContent[] = $newDirForm;
508: 
509:         // upload a new file form
510:         $propertiesForm = new cHTMLForm();
511:         $propertiesForm->setID('properties' . $this->_id);
512:         $propertiesForm->setAttribute('name', 'properties');
513:         $propertiesForm->setAttribute('method', 'post');
514:         $propertiesForm->setAttribute('action', $this->_cfg['path']['contenido_fullhtml'] . 'main.php');
515:         $propertiesForm->setAttribute('enctype', 'multipart/form-data');
516:         $frame = new cHTMLHiddenField('frame', '4');
517:         $area = new cHTMLHiddenField('area', 'upl');
518:         $path = new cHTMLHiddenField('path');
519:         $file = new cHTMLHiddenField('file');
520:         $action = new cHTMLHiddenField('action', 'upl_upload');
521:         $appendparameters = new cHTMLHiddenField('appendparameters');
522:         $contenido = new cHTMLHiddenField('contenido', $_REQUEST['contenido']);
523:         $caption2Span = new cHTMLSpan();
524:         $caption2Span->setID('caption2');
525:         $propertiesHead = new cHTMLDiv(array(
526:             '<b>' . i18n('Path') . '</b>',
527:             $caption2Span
528:         ));
529:         $imageUpload = new cHTMLUpload('file[]', '', '', 'cms_image_m' . $this->_id, false, '', '', 'file');
530:         $imageUpload->setClass('jqueryAjaxUpload');
531:         $propertiesForm->setContent(array(
532:             $frame,
533:             $area,
534:             $path,
535:             $file,
536:             $action,
537:             $appendparameters,
538:             $contenido,
539:             $propertiesHead,
540:             $imageUpload
541:         ));
542:         $wrapperContent[] = $propertiesForm;
543: 
544:         $wrapperContent[] = new cHTMLImage($this->_cfg['path']['contenido_fullhtml'] . 'images/ajax-loader.gif', 'loading');
545: 
546:         $wrapper->setContent($wrapperContent);
547:         return $wrapper->render();
548:     }
549: 
550:     /**
551:      * Generate a select box containing all files in the given directory.
552:      *
553:      * @param string $directoryPath directory of the files
554:      * @return string rendered cHTMLSelectElement
555:      */
556:     public function generateFileSelect($directoryPath = '') {
557:         // make sure the path ends with a slash
558:         if (substr($directoryPath, -1) != '/') {
559:             $directoryPath .= '/';
560:         }
561: 
562:         $htmlSelect = new cHTMLSelectElement('image_filename', '', 'image_filename_' . $this->_id);
563:         $htmlSelect->setSize(16);
564:         $htmlSelectOption = new cHTMLOptionElement('Kein', '', false);
565:         $htmlSelect->addOptionElement(0, $htmlSelectOption);
566: 
567:         $filenameEntries = array();
568:         if (is_dir($this->_uploadPath . $directoryPath)) {
569:             if ($handle = opendir($this->_uploadPath . $directoryPath)) {
570:                 while (($entry = readdir($handle)) != false) {
571:                     if (is_file($this->_uploadPath . $directoryPath . $entry) && (! (strpos($entry, ".") === 0))) {
572:                         $htmlSelectOption = new cHTMLOptionElement($entry, $directoryPath . $entry);
573:                         $htmlSelect->addOptionElement($i, $htmlSelectOption);
574:                         $i++;
575:                     }
576:                 }
577:                 closedir($handle);
578:             }
579:         }
580: 
581:         sort($filenameEntries, SORT_STRING);
582: 
583:         $i = 1;
584:         foreach($filenameEntries as $filename) {
585:             $htmlSelectOption = new cHTMLOptionElement($filename, $directoryPath . $filename);
586:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
587:             $i++;
588:         }
589: 
590:         if ($i === 0) {
591:             $htmlSelectOption = new cHTMLOptionElement(i18n('No files found'), '', false);
592:             $htmlSelectOption->setAlt(i18n('No files found'));
593:             $htmlSelectOption->setDisabled(true);
594:             $htmlSelect->addOptionElement($i, $htmlSelectOption);
595:             $htmlSelect->setDisabled(true);
596:         }
597: 
598:         // set default value
599:         if (isset($this->_dirname)) {
600:             $htmlSelect->setDefault($this->_dirname . $this->_filename);
601:         } else {
602:             $htmlSelect->setDefault('');
603:         }
604: 
605:         return $htmlSelect->render();
606:     }
607: 
608:     /**
609:      * Checks whether the directory defined by the given directory
610:      * information is the currently active directory.
611:      * Overwrite in subclasses if you use getDirectoryList!
612:      *
613:      * @param array $dirData directory information
614:      * @return boolean whether the directory is the currently active directory
615:      */
616:     protected function _isActiveDirectory(array $dirData) {
617:         return $dirData['path'] . $dirData['name'] . '/' === $this->_dirname;
618:     }
619: 
620:     /**
621:      * Checks whether the directory defined by the given directory information
622:      * should be shown expanded.
623:      * Overwrite in subclasses if you use getDirectoryList!
624:      *
625:      * @param array $dirData directory information
626:      * @return boolean whether the directory should be shown expanded
627:      */
628:     protected function _shouldDirectoryBeExpanded(array $dirData) {
629:         return $this->_isSubdirectory($dirData['path'] . $dirData['name'], $this->_dirname);
630:     }
631: 
632:     /**
633:      * Gets the meta data of the image with the given filename/dirname.
634:      *
635:      * @param string $filename the filename of the image
636:      * @param string $dirname the dirname of the image
637:      * @return string JSON-encoded array with meta data
638:      */
639:     public function getImageMeta($filename, $dirname) {
640:         $upload = new cApiUpload();
641:         $upload->loadByMany(array(
642:             'filename' => $filename,
643:             'dirname' => $dirname,
644:             'idclient' => $this->_client
645:         ), false);
646:         $idupl = $upload->get('idupl');
647: 
648:         $uploadMeta = new cApiUploadMeta();
649:         $uploadMeta->loadByMany(array(
650:             'idupl' => $idupl,
651:             'idlang' => $this->_lang
652:         ));
653: 
654:         $imageMeta = array();
655:         $imageMeta['medianame'] = ($uploadMeta->get('medianame') !== false) ? $uploadMeta->get('medianame') : '';
656:         $imageMeta['description'] = ($uploadMeta->get('description') !== false) ? $uploadMeta->get('description') : '';
657:         $imageMeta['keywords'] = ($uploadMeta->get('keywords') !== false) ? $uploadMeta->get('keywords') : '';
658:         $imageMeta['internal_notice'] = ($uploadMeta->get('internal_notice') !== false) ? $uploadMeta->get('internal_notice') : '';
659:         $imageMeta['copyright'] = ($uploadMeta->get('copyright') !== false) ? $uploadMeta->get('copyright') : '';
660: 
661:         return json_encode($imageMeta);
662:     }
663: 
664:     /**
665:      * Creates an upload directory.
666:      * Wrapper function for uplmkdir in functions.upl.php.
667:      *
668:      * @param string $path Path to directory to create, either path from client
669:      *        upload
670:      *        directory or a dbfs path
671:      * @param string $name Name of directory to create
672:      * @return string void value of filemode as string ('0702') or nothing
673:      */
674:     public function uplmkdir($path, $name) {
675:         return uplmkdir($path, $name);
676:     }
677: 
678:     /**
679:      * Uploads the transmitted files saved in the $_FILES array.
680:      *
681:      * @param string $path the path to which the file should be uploaded
682:      * @return string the filename of the uploaded file
683:      */
684:     public function uplupload($path) {
685:         if (count($_FILES) === 1) {
686:             foreach ($_FILES['file']['name'] as $key => $value) {
687:                 if (file_exists($_FILES['file']['tmp_name'][$key])) {
688:                     $friendlyName = uplCreateFriendlyName($_FILES['file']['name'][$key]);
689:                     move_uploaded_file($_FILES['file']['tmp_name'][$key], $this->_cfgClient[$this->_client]['upl']['path'] . $path . $friendlyName);
690: 
691:                     cDebug::out(":::" . $path);
692:                     uplSyncDirectory($path);
693: 
694:                     $upload = new cApiUpload();
695:                     $upload->loadByMany(array(
696:                         'dirname' => $path,
697:                         'filename' => $_FILES['file']['name'][$key]
698:                     ), false);
699:                     if ($upload->get('idupl') != false) {
700:                         $uplfilename = $this->_cfgClient[$this->_client]['upl']['htmlpath'] . $upload->get('dirname') . $upload->get('filename');
701:                     } else {
702:                         $uplfilename = 'error';
703:                     }
704:                 }
705:             }
706:         }
707: 
708:         return $uplfilename;
709:     }
710: 
711: }
CMS CONTENIDO 4.9.4 API documentation generated by ApiGen 2.8.0