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

  • 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 = cSecurity::escapeDB($path, null);
 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 for the mimetype
 79:             $contentDispositionHeader = true;
 80:             foreach ($cfg['dbfs']['skip_content_disposition_header_for_mimetypes'] as $mt) {
 81:                 if (strtolower($mt) == strtolower($mimetype)) {
 82:                     $contentDispositionHeader = false;
 83:                     break;
 84:                 }
 85:             }
 86:             if ($contentDispositionHeader) {
 87:                 header('Content-Disposition: attachment; filename=' . $file);
 88:             }
 89: 
 90:             echo $item->get('content');
 91:         }
 92:     }
 93: 
 94:     /**
 95:      * Writes physical existing file into dbfs
 96:      *
 97:      * @param string $localfile
 98:      * @param string $targetfile
 99:      */
100:     public function writeFromFile($localfile, $targetfile) {
101:         $targetfile = cApiDbfs::stripPath($targetfile);
102:         $stat = cFileHandler::info($localfile);
103:         $mimetype = $stat['mime'];
104: 
105:         $this->write($targetfile, cFileHandler::read($localfile), $mimetype);
106:     }
107: 
108:     /**
109:      * Writes dbfs file into phsical file system
110:      *
111:      * @param string $sourcefile
112:      * @param string $localfile
113:      */
114:     public function writeToFile($sourcefile, $localfile) {
115:         $sourcefile = cApiDbfs::stripPath($sourcefile);
116: 
117:         cFileHandler::write($localfile, $this->read($sourcefile));
118:     }
119: 
120:     /**
121:      * Writes dbfs file, creates if if not exists.
122:      *
123:      * @param string $file
124:      * @param string $content
125:      * @param string $mimetype
126:      */
127:     public function write($file, $content = '', $mimetype = '') {
128:         $file = cApiDbfs::stripPath($file);
129: 
130:         if (!$this->file_exists($file)) {
131:             $this->create($file, $mimetype);
132:         }
133:         $this->setContent($file, $content);
134:     }
135: 
136:     /**
137:      * Checks if passed dbfs path has any files.
138:      *
139:      * @global int $client
140:      * @param string $path
141:      * @return bool
142:      */
143:     public function hasFiles($path) {
144:         global $client;
145: 
146:         $path = cApiDbfs::stripPath($path);
147:         $client = (int) $client;
148: 
149:         // Are there any subdirs?
150:         $this->select("dirname LIKE '" . $path . "/%' AND idclient = " . $client . " LIMIT 1");
151:         if ($this->count() > 0) {
152:             return true;
153:         }
154: 
155:         $this->select("dirname LIKE '" . $path . "%' AND idclient = " . $client . " LIMIT 2");
156:         if ($this->count() > 1) {
157:             return true;
158:         } else {
159:             return false;
160:         }
161:     }
162: 
163:     /**
164:      * Reads content from dbfs file.
165:      *
166:      * @param string $file
167:      * @return string
168:      */
169:     public function read($file) {
170:         return ($this->getContent($file));
171:     }
172: 
173:     /**
174:      * Checks, if a dbfs file exists.
175:      *
176:      * @global int $client
177:      * @param string $path
178:      * @return bool
179:      */
180:     public function file_exists($path) {
181:         global $client;
182: 
183:         $path = cApiDbfs::stripPath($path);
184:         $dir = dirname($path);
185:         $file = basename($path);
186: 
187:         if ($dir == '.') {
188:             $dir = '';
189:         }
190: 
191:         $client = (int) $client;
192: 
193:         $this->select("dirname = '" . $dir . "' AND filename = '" . $file . "' AND idclient = " . $client . " LIMIT 1");
194:         if ($this->next()) {
195:             return true;
196:         } else {
197:             return false;
198:         }
199:     }
200: 
201:     /**
202:      * Checks, if a dbfs directory exists.
203:      *
204:      * @global int $client
205:      * @param string $path
206:      * @return bool
207:      */
208:     public function dir_exists($path) {
209:         global $client;
210: 
211:         $path = cApiDbfs::stripPath($path);
212: 
213:         if ($path == "") {
214:             return true;
215:         }
216: 
217:         $client = (int) $client;
218: 
219:         $this->select("dirname = '" . $path . "' AND filename = '.' AND idclient = " . $client . " LIMIT 1");
220:         if ($this->next()) {
221:             return true;
222:         } else {
223:             return false;
224:         }
225:     }
226: 
227:     public function parent_dir($path) {
228:         $path = dirname($path);
229: 
230:         return $path;
231:     }
232: 
233:     public function create($path, $mimetype = '', $content = '') {
234:         global $client, $auth;
235: 
236:         $client = (int) $client;
237: 
238:         if (substr($path, 0, 1) == '/') {
239:             $path = substr($path, 1);
240:         }
241: 
242:         $dir = dirname($path);
243:         $file = basename($path);
244: 
245:         if ($dir == '.') {
246:             $dir = '';
247:         }
248: 
249:         if ($file == '') {
250:             return;
251:         }
252: 
253:         if ($file != '.') {
254:             if ($dir != '') {
255:                 // Check if the directory exists. If not, create it.
256:                 $this->select("dirname = '" . $dir . "' AND filename = '.' AND idclient = " . $client . " LIMIT 1");
257:                 if (!$this->next()) {
258:                     $this->create($dir . '/.');
259:                 }
260:             }
261:         } else {
262:             $parent = $this->parent_dir($dir);
263: 
264:             if ($parent != '.') {
265:                 if (!$this->dir_exists($parent)) {
266:                     $this->create($parent . '/.');
267:                 }
268:             }
269:         }
270: 
271:         if ($dir && !$this->dir_exists($dir) || $file != '.') {
272:             $item = parent::createNewItem();
273:             $item->set('idclient', $client);
274:             $item->set('dirname', $dir);
275:             $item->set('filename', $file);
276:             $item->set('size', strlen($content));
277: 
278:             if ($mimetype != '') {
279:                 $item->set('mimetype', $mimetype);
280:             }
281: 
282:             $item->set('content', $content);
283:             $item->set('created', date('Y-m-d H:i:s'), false);
284:             $item->set('author', $auth->auth['uid']);
285:             $item->store();
286:         }
287:         return ($item);
288:     }
289: 
290:     public function setContent($path, $content) {
291:         global $client;
292: 
293:         $client = (int) $client;
294:         $path = cApiDbfs::stripPath($path);
295:         $dirname = dirname($path);
296:         $filename = basename($path);
297: 
298:         if ($dirname == '.') {
299:             $dirname = '';
300:         }
301: 
302:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
303:         if (($item = $this->next()) !== false) {
304:             $item->set('content', $content);
305:             $item->set('size', strlen($content));
306:             $item->store();
307:         }
308:     }
309: 
310:     public function getSize($path) {
311:         global $client;
312: 
313:         $client = (int) $client;
314:         $path = cApiDbfs::stripPath($path);
315:         $dirname = dirname($path);
316:         $filename = basename($path);
317: 
318:         if ($dirname == '.') {
319:             $dirname = '';
320:         }
321: 
322:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
323:         if (($item = $this->next()) !== false) {
324:             return $item->get('size');
325:         }
326:     }
327: 
328:     public function getContent($path) {
329:         global $client;
330: 
331:         $client = (int) $client;
332:         $dirname = dirname($path);
333:         $filename = basename($path);
334: 
335:         if ($dirname == '.') {
336:             $dirname = '';
337:         }
338: 
339:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
340:         if (($item = $this->next()) !== false) {
341:             return ($item->get("content"));
342:         }
343:     }
344: 
345:     public function remove($path) {
346:         global $client;
347: 
348:         $client = (int) $client;
349:         $path = cApiDbfs::stripPath($path);
350:         $dirname = dirname($path);
351:         $filename = basename($path);
352: 
353:         if ($dirname == ".") {
354:             $dirname = "";
355:         }
356: 
357:         $this->select("dirname = '" . $dirname . "' AND filename = '" . $filename . "' AND idclient = " . $client . " LIMIT 1");
358:         if (($item = $this->next()) !== false) {
359:             $this->delete($item->get('iddbfs'));
360:         }
361:     }
362: 
363:     /**
364:      * Checks if time management is activated and if yes then check if file is
365:      * in period
366:      *
367:      * @param string $sPath
368:      * @return bool $bAvailable
369:      */
370:     public function checkTimeManagement($sPath, $oProperties) {
371:         global $contenido;
372:         if ($contenido) {
373:             return true;
374:         }
375:         $sPath = cSecurity::toString($sPath);
376:         $bAvailable = true;
377:         $iTimeMng = cSecurity::toInteger($oProperties->getValue('upload', $sPath, 'file', 'timemgmt'));
378:         if ($iTimeMng == 0) {
379:             return true;
380:         }
381:         $sStartDate = $oProperties->getValue('upload', $sPath, 'file', 'datestart');
382:         $sEndDate = $oProperties->getValue('upload', $sPath, 'file', 'dateend');
383: 
384:         $iNow = time();
385: 
386:         if ($iNow < $this->dateToTimestamp($sStartDate) || ($iNow > $this->dateToTimestamp($sEndDate) && (int) $this->dateToTimestamp($sEndDate) > 0)) {
387: 
388:             return false;
389:         }
390:         return $bAvailable;
391:     }
392: 
393:     /**
394:      * converts date to timestamp:
395:      *
396:      * @param string $sDate
397:      * @return int $iTimestamp
398:      */
399:     public function dateToTimestamp($sDate) {
400:         return strtotime($sDate);
401:     }
402: }
403: 
404: /**
405:  * DBFS item
406:  *
407:  * @package Core
408:  * @subpackage GenericDB_Model
409:  */
410: class cApiDbfs extends Item {
411: 
412:     const PROTOCOL_DBFS = 'dbfs:';
413: 
414:     /**
415:      * Constructor Function
416:      *
417:      * @param mixed $mId Specifies the ID of item to load
418:      */
419:     public function __construct($mId = false) {
420:         global $cfg;
421:         parent::__construct($cfg['tab']['dbfs'], 'iddbfs');
422:         if ($mId !== false) {
423:             $this->loadByPrimaryKey($mId);
424:         }
425:     }
426: 
427:     public function store() {
428:         global $auth;
429: 
430:         $this->set('modified', date('Y-m-d H:i:s'), false);
431:         $this->set('modifiedby', $auth->auth['uid']);
432: 
433:         return parent::store();
434:     }
435: 
436:     /**
437:      * Removes the DBFS protocol and leading '/' from received path.
438:      *
439:      * @param string $path
440:      * @return string
441:      */
442:     public static function stripPath($path) {
443:         $path = self::stripProtocol($path);
444:         if (substr($path, 0, 1) == '/') {
445:             $path = substr($path, 1);
446:         }
447:         return $path;
448:     }
449: 
450:     /**
451:      * Removes the DBFS protocol received path.
452:      *
453:      * @param string $path
454:      * @return string
455:      */
456:     public static function stripProtocol($path) {
457:         if (self::isDbfs($path)) {
458:             $path = substr($path, strlen(cApiDbfs::PROTOCOL_DBFS));
459:         }
460:         return $path;
461:     }
462: 
463:     /**
464:      * Checks if passed file id a DBFS
465:      *
466:      * @param string $file
467:      * @return bool
468:      */
469:     public static function isDbfs($file) {
470:         return (substr($file, 0, 5) == self::PROTOCOL_DBFS);
471:     }
472: 
473: }
474: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0