Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

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