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

  • cApiAction
  • cApiActionCollection
  • cApiActionlog
  • cApiActionlogCollection
  • cApiArea
  • cApiAreaCollection
  • cApiArticle
  • cApiArticleCollection
  • cApiArticleLanguage
  • cApiArticleLanguageCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiDbfs
  • cApiDbfsCollection
  • cApiFile
  • cApiFileCollection
  • cApiFileInformation
  • cApiFileInformationCollection
  • cApiFrameFile
  • cApiFrameFileCollection
  • cApiFrontendGroup
  • cApiFrontendGroupCollection
  • cApiFrontendGroupMember
  • cApiFrontendGroupMemberCollection
  • cApiFrontendPermission
  • cApiFrontendPermissionCollection
  • cApiFrontendUser
  • cApiFrontendUserCollection
  • cApiGroup
  • cApiGroupCollection
  • cApiGroupMember
  • cApiGroupMemberCollection
  • cApiGroupProperty
  • cApiGroupPropertyCollection
  • cApiInUse
  • cApiInUseCollection
  • cApiIso3166
  • cApiIso3166Collection
  • cApiIso6392
  • cApiIso6392Collection
  • cApiKeyword
  • cApiKeywordCollection
  • cApiLanguage
  • cApiLanguageCollection
  • cApiLayout
  • cApiLayoutCollection
  • cApiMailLog
  • cApiMailLogCollection
  • cApiMailLogSuccess
  • cApiMailLogSuccessCollection
  • cApiMetaTag
  • cApiMetaTagCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  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->file_exists($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 file_exists($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:      * Checks, if a dbfs directory exists.
204:      *
205:      * @global int $client
206:      * @param string $path
207:      * @return bool
208:      */
209:     public function dir_exists($path) {
210:         global $client;
211: 
212:         $path = cApiDbfs::stripPath($path);
213: 
214:         if ($path == '') {
215:             return true;
216:         }
217: 
218:         $client = (int) $client;
219: 
220:         $this->select("dirname = '" . $path . "' AND filename = '.' AND idclient = " . $client . " LIMIT 1");
221:         if ($this->next()) {
222:             return true;
223:         } else {
224:             return false;
225:         }
226:     }
227: 
228:     /**
229:      *
230:      * @param string $path
231:      * @return string
232:      */
233:     public function parent_dir($path) {
234:         $path = dirname($path);
235: 
236:         return $path;
237:     }
238: 
239:     /**
240:      *
241:      * @param string $path
242:      * @param string $mimetype
243:      * @param string $content
244:      * @return void Ambigous object>
245:      */
246:     public function create($path, $mimetype = '', $content = '') {
247:         global $client, $auth;
248: 
249:         $client = (int) $client;
250: 
251:         if (substr($path, 0, 1) == '/') {
252:             $path = substr($path, 1);
253:         }
254: 
255:         $dir = dirname($path);
256:         $file = basename($path);
257: 
258:         if ($dir == '.') {
259:             $dir = '';
260:         }
261: 
262:         if ($file == '') {
263:             return;
264:         }
265: 
266:         if ($file != '.') {
267:             if ($dir != '') {
268:                 // Check if the directory exists. If not, create it.
269:                 $this->select("dirname = '" . $dir . "' AND filename = '.' AND idclient = " . $client . " LIMIT 1");
270:                 if (!$this->next()) {
271:                     $this->create($dir . '/.');
272:                 }
273:             }
274:         } else {
275:             $parent = $this->parent_dir($dir);
276: 
277:             if ($parent != '.') {
278:                 if (!$this->dir_exists($parent)) {
279:                     $this->create($parent . '/.');
280:                 }
281:             }
282:         }
283: 
284:         if ($dir && !$this->dir_exists($dir) || $file != '.') {
285:             $item = parent::createNewItem();
286:             $item->set('idclient', $client);
287:             $item->set('dirname', $dir);
288:             $item->set('filename', $file);
289:             $item->set('size', strlen($content));
290: 
291:             if ($mimetype != '') {
292:                 $item->set('mimetype', $mimetype);
293:             }
294: 
295:             $item->set('content', $content);
296:             $item->set('created', date('Y-m-d H:i:s'), false);
297:             $item->set('author', $auth->auth['uid']);
298:             $item->store();
299:         }
300:         return ($item);
301:     }
302: 
303:     /**
304:      *
305:      * @param string $path
306:      * @param string $content
307:      */
308:     public function setContent($path, $content) {
309:         global $client;
310: 
311:         $client = (int) $client;
312:         $path = cApiDbfs::stripPath($path);
313:         $dirname = dirname($path);
314:         $filename = basename($path);
315: 
316:         if ($dirname == '.') {
317:             $dirname = '';
318:         }
319: 
320:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
321:         if (($item = $this->next()) !== false) {
322:             $item->set('content', $content);
323:             $item->set('size', strlen($content));
324:             $item->store();
325:         }
326:     }
327: 
328:     /**
329:      *
330:      * @param string $path
331:      * @return Ambigous <mixed, bool>
332:      */
333:     public function getSize($path) {
334:         global $client;
335: 
336:         $client = (int) $client;
337:         $path = cApiDbfs::stripPath($path);
338:         $dirname = dirname($path);
339:         $filename = basename($path);
340: 
341:         if ($dirname == '.') {
342:             $dirname = '';
343:         }
344: 
345:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
346:         if (($item = $this->next()) !== false) {
347:             return $item->get('size');
348:         }
349:     }
350: 
351:     /**
352:      *
353:      * @param string $path
354:      * @return Ambigous <mixed, bool>
355:      */
356:     public function getContent($path) {
357:         global $client;
358: 
359:         $client = (int) $client;
360:         $dirname = dirname($path);
361:         $filename = basename($path);
362: 
363:         if ($dirname == '.') {
364:             $dirname = '';
365:         }
366: 
367:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
368:         if (($item = $this->next()) !== false) {
369:             return ($item->get("content"));
370:         }
371:     }
372: 
373:     /**
374:      *
375:      * @param string $path
376:      */
377:     public function remove($path) {
378:         global $client;
379: 
380:         $client = (int) $client;
381:         $path = cApiDbfs::stripPath($path);
382:         $dirname = dirname($path);
383:         $filename = basename($path);
384: 
385:         if ($dirname == '.') {
386:             $dirname = '';
387:         }
388: 
389:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
390:         if (($item = $this->next()) !== false) {
391:             $this->delete($item->get('iddbfs'));
392:         }
393:     }
394: 
395:     /**
396:      * Checks if time management is activated and if yes then check if file is
397:      * in period
398:      *
399:      * @param string $sPath
400:      * @param cApiPropertyCollection $oProperties
401:      * @return bool $bAvailable
402:      */
403:     public function checkTimeManagement($sPath, $oProperties) {
404:         global $contenido;
405:         if ($contenido) {
406:             return true;
407:         }
408:         $sPath = cSecurity::toString($sPath);
409:         $bAvailable = true;
410:         $iTimeMng = cSecurity::toInteger($oProperties->getValue('upload', $sPath, 'file', 'timemgmt'));
411:         if ($iTimeMng == 0) {
412:             return true;
413:         }
414:         $sStartDate = $oProperties->getValue('upload', $sPath, 'file', 'datestart');
415:         $sEndDate = $oProperties->getValue('upload', $sPath, 'file', 'dateend');
416: 
417:         $iNow = time();
418: 
419:         if ($iNow < $this->dateToTimestamp($sStartDate) || ($iNow > $this->dateToTimestamp($sEndDate) && (int) $this->dateToTimestamp($sEndDate) > 0)) {
420: 
421:             return false;
422:         }
423:         return $bAvailable;
424:     }
425: 
426:     /**
427:      * converts date to timestamp:
428:      *
429:      * @param string $sDate
430:      * @return int $iTimestamp
431:      */
432:     public function dateToTimestamp($sDate) {
433:         return strtotime($sDate);
434:     }
435: }
436: 
437: /**
438:  * DBFS item
439:  *
440:  * @package Core
441:  * @subpackage GenericDB_Model
442:  */
443: class cApiDbfs extends Item {
444: 
445:     /**
446:      * DBFS protocol
447:      *
448:      * @var string
449:      */
450:     const PROTOCOL_DBFS = 'dbfs:';
451: 
452:     /**
453:      * Constructor Function
454:      *
455:      * @param mixed $mId Specifies the ID of item to load
456:      */
457:     public function __construct($mId = false) {
458:         global $cfg;
459:         parent::__construct($cfg['tab']['dbfs'], 'iddbfs');
460:         if ($mId !== false) {
461:             $this->loadByPrimaryKey($mId);
462:         }
463:     }
464: 
465:     public function store() {
466:         global $auth;
467: 
468:         $this->set('modified', date('Y-m-d H:i:s'), false);
469:         $this->set('modifiedby', $auth->auth['uid']);
470: 
471:         return parent::store();
472:     }
473: 
474:     /**
475:      * Removes the DBFS protocol and leading '/' from received path.
476:      *
477:      * @param string $path
478:      * @return string
479:      */
480:     public static function stripPath($path) {
481:         $path = self::stripProtocol($path);
482:         if (substr($path, 0, 1) == '/') {
483:             $path = substr($path, 1);
484:         }
485:         return $path;
486:     }
487: 
488:     /**
489:      * Removes the DBFS protocol received path.
490:      *
491:      * @param string $path
492:      * @return string
493:      */
494:     public static function stripProtocol($path) {
495:         if (self::isDbfs($path)) {
496:             $path = substr($path, strlen(cApiDbfs::PROTOCOL_DBFS));
497:         }
498:         return $path;
499:     }
500: 
501:     /**
502:      * Checks if passed file id a DBFS
503:      *
504:      * @param string $file
505:      * @return bool
506:      */
507:     public static function isDbfs($file) {
508:         return (substr($file, 0, 5) == self::PROTOCOL_DBFS);
509:     }
510: }
511: 
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0