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 DBFS collection and item class.
  4:  *
  5:  * @package Core
  6:  * @subpackage GenericDB_Model
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Murat Purc <murat@purc.de>
 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.file.php');
 19: 
 20: /**
 21:  * DFFS item collection
 22:  *
 23:  * @package Core
 24:  * @subpackage GenericDB_Model
 25:  */
 26: class cApiDbfsCollection extends ItemCollection {
 27: 
 28:     /**
 29:      * Constructor Function
 30:      */
 31:     public function __construct() {
 32:         global $cfg;
 33:         parent::__construct($cfg['tab']['dbfs'], 'iddbfs');
 34:         $this->_setItemClass('cApiDbfs');
 35: 
 36:         // set the join partners so that joins can be used via link() method
 37:         $this->_setJoinPartner('cApiClientCollection');
 38:     }
 39: 
 40:     /**
 41:      * Outputs dbfs file related by it's path property
 42:      *
 43:      * @param string $path
 44:      */
 45:     public function outputFile($path) {
 46:         global $cfg, $client, $auth;
 47: 
 48:         $path = $this->escape($path);
 49:         $client = (int) $client;
 50:         $path = cApiDbfs::stripPath($path);
 51:         $dir = dirname($path);
 52:         $file = basename($path);
 53: 
 54:         if ($dir == '.') {
 55:             $dir = '';
 56:         }
 57: 
 58:         $this->select("dirname = '" . $dir . "' AND filename = '" . $file . "' AND idclient = " . $client . " LIMIT 1");
 59: 
 60:         if (($item = $this->next()) !== false) {
 61:             $properties = new cApiPropertyCollection();
 62:             // Check if we're allowed to access it
 63:             $protocol = cApiDbfs::PROTOCOL_DBFS;
 64: 
 65:             if ($properties->getValue('upload', $protocol . $dir . '/' . $file, 'file', 'protected') == '1') {
 66:                 if ($auth->auth['uid'] == 'nobody') {
 67:                     header('HTTP/1.0 403 Forbidden');
 68:                     return;
 69:                 }
 70:             }
 71:             $mimetype = $item->get('mimetype');
 72: 
 73:             header('Cache-Control: '); // leave blank to avoid IE errors
 74:             header('Pragma: '); // leave blank to avoid IE errors
 75:             header("Content-Type: $mimetype");
 76:             header('Etag: ' . md5(mt_rand()));
 77: 
 78:             // Check, if output of Content-Disposition header should be skipped
 79:             // for the mimetype
 80:             $contentDispositionHeader = true;
 81:             foreach ($cfg['dbfs']['skip_content_disposition_header_for_mimetypes'] as $mt) {
 82:                 if (strtolower($mt) == strtolower($mimetype)) {
 83:                     $contentDispositionHeader = false;
 84:                     break;
 85:                 }
 86:             }
 87:             if ($contentDispositionHeader) {
 88:                 header('Content-Disposition: attachment; filename=' . $file);
 89:             }
 90: 
 91:             echo $item->get('content');
 92:         }
 93:     }
 94: 
 95:     /**
 96:      * Writes physical existing file into dbfs
 97:      *
 98:      * @param string $localfile
 99:      * @param string $targetfile
100:      */
101:     public function writeFromFile($localfile, $targetfile) {
102:         $targetfile = cApiDbfs::stripPath($targetfile);
103:         $stat = cFileHandler::info($localfile);
104:         $mimetype = $stat['mime'];
105: 
106:         $this->write($targetfile, cFileHandler::read($localfile), $mimetype);
107:     }
108: 
109:     /**
110:      * Writes dbfs file into phsical file system
111:      *
112:      * @param string $sourcefile
113:      * @param string $localfile
114:      */
115:     public function writeToFile($sourcefile, $localfile) {
116:         $sourcefile = cApiDbfs::stripPath($sourcefile);
117: 
118:         cFileHandler::write($localfile, $this->read($sourcefile));
119:     }
120: 
121:     /**
122:      * Writes dbfs file, creates if if not exists.
123:      *
124:      * @param string $file
125:      * @param string $content
126:      * @param string $mimetype
127:      */
128:     public function write($file, $content = '', $mimetype = '') {
129:         $file = cApiDbfs::stripPath($file);
130: 
131:         if (!$this->fileExists($file)) {
132:             $this->create($file, $mimetype);
133:         }
134:         $this->setContent($file, $content);
135:     }
136: 
137:     /**
138:      * Checks if passed dbfs path has any files.
139:      *
140:      * @global int $client
141:      * @param string $path
142:      * @return bool
143:      */
144:     public function hasFiles($path) {
145:         global $client;
146: 
147:         $path = cApiDbfs::stripPath($path);
148:         $client = (int) $client;
149: 
150:         // Are there any subdirs?
151:         $this->select("dirname LIKE '" . $path . "/%' AND idclient = " . $client . " LIMIT 1");
152:         if ($this->count() > 0) {
153:             return true;
154:         }
155: 
156:         $this->select("dirname LIKE '" . $path . "%' AND idclient = " . $client . " LIMIT 2");
157:         if ($this->count() > 1) {
158:             return true;
159:         } else {
160:             return false;
161:         }
162:     }
163: 
164:     /**
165:      * Reads content from dbfs file.
166:      *
167:      * @param string $file
168:      * @return string
169:      */
170:     public function read($file) {
171:         return ($this->getContent($file));
172:     }
173: 
174:     /**
175:      * Checks, if a dbfs file exists.
176:      *
177:      * @global int $client
178:      * @param string $path
179:      * @return bool
180:      */
181:     public function fileExists($path) {
182:         global $client;
183: 
184:         $path = cApiDbfs::stripPath($path);
185:         $dir = dirname($path);
186:         $file = basename($path);
187: 
188:         if ($dir == '.') {
189:             $dir = '';
190:         }
191: 
192:         $client = (int) $client;
193: 
194:         $this->select("dirname = '" . $dir . "' AND filename = '" . $file . "' AND idclient = " . $client . " LIMIT 1");
195:         if ($this->next()) {
196:             return true;
197:         } else {
198:             return false;
199:         }
200:     }
201: 
202:     /**
203:      * @deprecated [20131106]  Use cApiDbfsCollection->fileExists() instead
204:      */
205:     public function file_exists($path) {
206:         cDeprecated('The method file_exists() is deprecated. Use fileExists() instead.');
207:         return $this->fileExists($path);
208:     }
209: 
210:     /**
211:      * Checks, if a dbfs directory exists.
212:      *
213:      * @global int $client
214:      * @param string $path
215:      * @return bool
216:      */
217:     public function dirExists($path) {
218:         global $client;
219: 
220:         $path = cApiDbfs::stripPath($path);
221: 
222:         if ($path == '') {
223:             return true;
224:         }
225: 
226:         $client = (int) $client;
227: 
228:         $this->select("dirname = '" . $path . "' AND filename = '.' AND idclient = " . $client . " LIMIT 1");
229:         if ($this->next()) {
230:             return true;
231:         } else {
232:             return false;
233:         }
234:     }
235: 
236:     /**
237:      * @deprecated [20131106]  Use cApiDbfsCollection->dirExists() instead
238:      */
239:     public function dir_exists($path) {
240:         cDeprecated('The method dir_exists() is deprecated. Use dirExists() instead.');
241:         return $this->dirExists($path);
242:     }
243: 
244:     /**
245:      *
246:      * @param string $path
247:      * @return string
248:      */
249:     public function parentDir($path) {
250:         $path = dirname($path);
251: 
252:         return $path;
253:     }
254: 
255:     /**
256:      * @deprecated [20131106]  Use cApiDbfsCollection->parentDir() instead
257:      */
258:     public function parent_dir($path) {
259:         cDeprecated('The method parent_dir() is deprecated. Use parentDir() instead.');
260:         return $this->parentDir($path);
261:     }
262: 
263:     /**
264:      * Creates a dbfs item entry
265:      * @param string $path
266:      * @param string $mimetype
267:      * @param string $content
268:      * @return  cApiDbfs|false
269:      */
270:     public function create($path, $mimetype = '', $content = '') {
271:         global $client, $auth;
272: 
273:         $client = (int) $client;
274:         $item = false;
275: 
276:         if (substr($path, 0, 1) == '/') {
277:             $path = substr($path, 1);
278:         }
279: 
280:         $dir = dirname($path);
281:         $file = basename($path);
282: 
283:         if ($dir == '.') {
284:             $dir = '';
285:         }
286: 
287:         if ($file == '') {
288:             return $item;
289:         }
290: 
291:         if ($file != '.') {
292:             if ($dir != '') {
293:                 // Check if the directory exists. If not, create it.
294:                 $this->select("dirname = '" . $dir . "' AND filename = '.' AND idclient = " . $client . " LIMIT 1");
295:                 if (!$this->next()) {
296:                     $this->create($dir . '/.');
297:                 }
298:             }
299:         } else {
300:             $parent = $this->parentDir($dir);
301: 
302:             if ($parent != '.') {
303:                 if (!$this->dirExists($parent)) {
304:                     $this->create($parent . '/.');
305:                 }
306:             }
307:         }
308: 
309:         if ($dir && !$this->dirExists($dir) || $file != '.') {
310:             $item = $this->createNewItem();
311:             $item->set('idclient', $client);
312:             $item->set('dirname', $dir);
313:             $item->set('filename', $file);
314:             $item->set('size', strlen($content));
315: 
316:             if ($mimetype != '') {
317:                 $item->set('mimetype', $mimetype);
318:             }
319: 
320:             $item->set('content', $content);
321:             $item->set('created', date('Y-m-d H:i:s'), false);
322:             $item->set('author', $auth->auth['uid']);
323:             $item->store();
324:         }
325: 
326:         return $item;
327:     }
328: 
329:     /**
330:      *
331:      * @param string $path
332:      * @param string $content
333:      */
334:     public function setContent($path, $content) {
335:         global $client;
336: 
337:         $client = (int) $client;
338:         $path = cApiDbfs::stripPath($path);
339:         $dirname = dirname($path);
340:         $filename = basename($path);
341: 
342:         if ($dirname == '.') {
343:             $dirname = '';
344:         }
345: 
346:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
347:         if (($item = $this->next()) !== false) {
348:             $item->set('content', $content);
349:             $item->set('size', strlen($content));
350:             $item->store();
351:         }
352:     }
353: 
354:     /**
355:      *
356:      * @param string $path
357:      * @return Ambigous <mixed, bool>
358:      */
359:     public function getSize($path) {
360:         global $client;
361: 
362:         $client = (int) $client;
363:         $path = cApiDbfs::stripPath($path);
364:         $dirname = dirname($path);
365:         $filename = basename($path);
366: 
367:         if ($dirname == '.') {
368:             $dirname = '';
369:         }
370: 
371:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
372:         if (($item = $this->next()) !== false) {
373:             return $item->get('size');
374:         }
375:     }
376: 
377:     /**
378:      *
379:      * @param string $path
380:      * @return Ambigous <mixed, bool>
381:      */
382:     public function getContent($path) {
383:         global $client;
384: 
385:         $client = (int) $client;
386:         $dirname = dirname($path);
387:         $filename = basename($path);
388: 
389:         if ($dirname == '.') {
390:             $dirname = '';
391:         }
392: 
393:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
394:         if (($item = $this->next()) !== false) {
395:             return ($item->get("content"));
396:         }
397:     }
398: 
399:     /**
400:      *
401:      * @param string $path
402:      */
403:     public function remove($path) {
404:         global $client;
405: 
406:         $client = (int) $client;
407:         $path = cApiDbfs::stripPath($path);
408:         $dirname = dirname($path);
409:         $filename = basename($path);
410: 
411:         if ($dirname == '.') {
412:             $dirname = '';
413:         }
414: 
415:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
416:         if (($item = $this->next()) !== false) {
417:             $this->delete($item->get('iddbfs'));
418:         }
419:     }
420: 
421:     /**
422:      * Checks if time management is activated and if yes then check if file is
423:      * in period
424:      *
425:      * @param string $sPath
426:      * @param cApiPropertyCollection $oProperties
427:      * @return bool $bAvailable
428:      */
429:     public function checkTimeManagement($sPath, $oProperties) {
430:         global $contenido;
431:         if ($contenido) {
432:             return true;
433:         }
434:         $sPath = cSecurity::toString($sPath);
435:         $bAvailable = true;
436:         $iTimeMng = cSecurity::toInteger($oProperties->getValue('upload', $sPath, 'file', 'timemgmt'));
437:         if ($iTimeMng == 0) {
438:             return true;
439:         }
440:         $sStartDate = $oProperties->getValue('upload', $sPath, 'file', 'datestart');
441:         $sEndDate = $oProperties->getValue('upload', $sPath, 'file', 'dateend');
442: 
443:         $iNow = time();
444: 
445:         if ($iNow < $this->dateToTimestamp($sStartDate) || ($iNow > $this->dateToTimestamp($sEndDate) && (int) $this->dateToTimestamp($sEndDate) > 0)) {
446: 
447:             return false;
448:         }
449:         return $bAvailable;
450:     }
451: 
452:     /**
453:      * converts date to timestamp:
454:      *
455:      * @param string $sDate
456:      * @return int $iTimestamp
457:      */
458:     public function dateToTimestamp($sDate) {
459:         return strtotime($sDate);
460:     }
461: }
462: 
463: /**
464:  * DBFS item
465:  *
466:  * @package Core
467:  * @subpackage GenericDB_Model
468:  */
469: class cApiDbfs extends Item {
470: 
471:     /**
472:      * DBFS protocol
473:      *
474:      * @var string
475:      */
476:     const PROTOCOL_DBFS = 'dbfs:';
477: 
478:     /**
479:      * Constructor Function
480:      *
481:      * @param mixed $mId Specifies the ID of item to load
482:      */
483:     public function __construct($mId = false) {
484:         global $cfg;
485:         parent::__construct($cfg['tab']['dbfs'], 'iddbfs');
486:         if ($mId !== false) {
487:             $this->loadByPrimaryKey($mId);
488:         }
489:     }
490: 
491:     public function store() {
492:         global $auth;
493: 
494:         $this->set('modified', date('Y-m-d H:i:s'), false);
495:         $this->set('modifiedby', $auth->auth['uid']);
496: 
497:         return parent::store();
498:     }
499: 
500:     /**
501:      * Sets the value of a specific field.
502:      * Ensures to bypass any set inFilter for 'content' field which is a blob.
503:      *
504:      * @param string $sField Field name
505:      * @param string $mValue Value to set
506:      * @param bool $bSafe Flag to run defined inFilter on passed value
507:      * @return bool
508:      */
509:     public function setField($sField, $mValue, $bSafe = true) {
510:         if ('content' === $sField) {
511:             // Disable always filter for field 'content'
512:             return parent::setField($sField, $mValue, false);
513:         } else {
514:             return parent::setField($sField, $mValue, $bSafe);
515:         }
516:     }
517: 
518:     /**
519:      * User defined value getter for cApiDbfs.
520:      * Ensures to bypass any set outFilter for 'content' field which is a blob.
521:      *
522:      * @param string $sField Specifies the field to retrieve
523:      * @param bool $bSafe Flag to run defined outFilter on passed value
524:      * @return mixed Value of the field
525:      */
526:     public function getField($sField, $bSafe = true) {
527:         if ('content' === $sField) {
528:             // Disable always filter for field 'content'
529:             return parent::getField($sField, false);
530:         } else {
531:             return parent::getField($sField, $bSafe);
532:         }
533:     }
534: 
535:     /**
536:      * Removes the DBFS protocol and leading '/' from received path.
537:      *
538:      * @param string $path
539:      * @return string
540:      */
541:     public static function stripPath($path) {
542:         $path = self::stripProtocol($path);
543:         if (substr($path, 0, 1) == '/') {
544:             $path = substr($path, 1);
545:         }
546:         return $path;
547:     }
548: 
549:     /**
550:      * Removes the DBFS protocol received path.
551:      *
552:      * @param string $path
553:      * @return string
554:      */
555:     public static function stripProtocol($path) {
556:         if (self::isDbfs($path)) {
557:             $path = substr($path, strlen(cApiDbfs::PROTOCOL_DBFS));
558:         }
559:         return $path;
560:     }
561: 
562:     /**
563:      * Checks if passed file id a DBFS
564:      *
565:      * @param string $file
566:      * @return bool
567:      */
568:     public static function isDbfs($file) {
569:         return (substr($file, 0, 5) == self::PROTOCOL_DBFS);
570:     }
571: }
572: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen