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