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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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
  • cApiArticleLanguageVersion
  • cApiArticleLanguageVersionCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiContentVersion
  • cApiContentVersionCollection
  • 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
  • cApiMetaTagVersion
  • cApiMetaTagVersionCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiSearchTracking
  • cApiSearchTrackingCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserPasswordRequest
  • cApiUserPasswordRequestCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the upload collection and item class.
  4:  *
  5:  * @package Core
  6:  * @subpackage GenericDB_Model
  7:  * @author Timo Hummel
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Upload collection
 18:  *
 19:  * @package Core
 20:  * @subpackage GenericDB_Model
 21:  */
 22: class cApiUploadCollection extends ItemCollection {
 23:     /**
 24:      * Constructor to create an instance of this class.
 25:      *
 26:      * @throws cInvalidArgumentException
 27:      * @global array $cfg
 28:      */
 29:     public function __construct() {
 30:         global $cfg;
 31:         parent::__construct($cfg['tab']['upl'], 'idupl');
 32:         $this->_setItemClass('cApiUpload');
 33: 
 34:         // set the join partners so that joins can be used via link() method
 35:         $this->_setJoinPartner('cApiClientCollection');
 36:     }
 37: 
 38:     /**
 39:      * Syncronizes upload directory and file with database.
 40:      *
 41:      * @param string $sDirname
 42:      * @param string $sFilename
 43:      * @param int    $client
 44:      *
 45:      * @return cApiUpload
 46:      * @throws cDbException
 47:      * @throws cException
 48:      * @throws cInvalidArgumentException
 49:      * @global int   $client
 50:      */
 51:     public function sync($sDirname, $sFilename, $client = 0) {
 52:         $client = cSecurity::toInteger($client);
 53: 
 54:         if ($client <= 0) {
 55:             global $client;
 56:         }
 57: 
 58:         // build escaped vars for SQL
 59:         $escClient = cSecurity::toInteger($client);
 60:         $escDirname = $this->escape($sDirname);
 61:         $escFilename = $this->escape($sFilename);
 62: 
 63:         // Unix style OS distinguish between lower and uppercase file names,
 64:         // i.e. test.gif is not the same as Test.gif
 65:         // Windows OS doesn't distinguish between lower and uppercase file
 66:         // names, i.e. test.gif is the same as Test.gif in file system
 67:         $os = cString::toLowerCase(getenv('OS'));
 68:         $isWindows = (false !== cString::findFirstPos($os, 'windows'));
 69:         $binary = $isWindows ? '' : 'BINARY';
 70: 
 71:         $this->select("idclient = $escClient AND dirname = $binary '$escDirname' AND filename = $binary '$escFilename'");
 72: 
 73:         if (false !== $oItem = $this->next()) {
 74:             $oItem->update();
 75:         } else {
 76:             $sFiletype = cFileHandler::getExtension($sDirname . $sFilename);
 77:             $iFilesize = cApiUpload::getFileSize($sDirname, $sFilename);
 78:             $oItem = $this->create($sDirname, $sFilename, $sFiletype, $iFilesize, '');
 79:         }
 80: 
 81:         return $oItem;
 82:     }
 83: 
 84:     /**
 85:      * Creates a upload entry.
 86:      *
 87:      * @param string  $sDirname
 88:      * @param string  $sFilename
 89:      * @param string  $sFiletype    [optional]
 90:      * @param int     $iFileSize    [optional]
 91:      * @param string  $sDescription [optional]
 92:      * @param int     $iStatus      [optional]
 93:      * @return cApiUpload
 94:      * @throws cDbException
 95:      * @throws cException
 96:      * @throws cInvalidArgumentException
 97:      * @global int    $client
 98:      * @global array  $cfg
 99:      * @global object $auth
100:      */
101:     public function create($sDirname, $sFilename, $sFiletype = '', $iFileSize = 0,
102:             $sDescription = '', $iStatus = 0) {
103: 
104:         $client = cRegistry::getClientId();
105:         $auth = cRegistry::getAuth();
106: 
107:         $oItem = $this->createNewItem();
108: 
109:         $oItem->set('idclient', $client);
110:         $oItem->set('filename', $sFilename, false);
111:         $oItem->set('filetype', $sFiletype, false);
112:         $oItem->set('size', $iFileSize, false);
113:         $oItem->set('dirname', $sDirname, false);
114:         // $oItem->set('description', $sDescription, false);
115:         $oItem->set('status', $iStatus, false);
116:         $oItem->set('author', $auth->auth['uid']);
117:         $oItem->set('created', date('Y-m-d H:i:s'), false);
118:         $oItem->store();
119: 
120:         return $oItem;
121:     }
122: 
123:     /**
124:      * Deletes upload file and it's properties
125:      *
126:      * @todo Code is similar/redundant to include.upl_files_overview.php 216-230
127:      * @param int              $id
128:      * 
129:      * @return bool
130:      * 
131:      * @throws cDbException
132:      * @throws cException
133:      * @global cApiCecRegistry $_cecRegistry
134:      * @global array           $cfgClient
135:      * @global int             $client
136:      */
137:     public function delete($id) {
138: 
139:         $client = cRegistry::getClientId();
140:         $cfgClient = cRegistry::getClientConfig();
141: 
142:         $oUpload = new cApiUpload();
143:         $oUpload->loadByPrimaryKey($id);
144: 
145:         $sDirFileName = $oUpload->get('dirname') . $oUpload->get('filename');
146: 
147:         // call chain for deleted file
148:         $_cecIterator = cRegistry::getCecRegistry()->getIterator('Contenido.Upl_edit.Delete');
149:         if ($_cecIterator->count() > 0) {
150:             while (($chainEntry = $_cecIterator->next()) !== false) {
151:                 $chainEntry->execute($oUpload->get('idupl'), $oUpload->get('dirname'), $oUpload->get('filename'));
152:             }
153:         }
154: 
155:         // delete from dbfs or filesystem
156:         if (cApiDbfs::isDbfs($sDirFileName)) {
157:             $oDbfs = new cApiDbfsCollection();
158:             $oDbfs->remove($sDirFileName);
159:         } elseif (cFileHandler::exists($cfgClient[$client]['upl']['path'] . $sDirFileName)) {
160:             unlink($cfgClient[$client]['upl']['path'] . $sDirFileName);
161:         }
162: 
163:         // delete properties
164:         // note: parents delete methos does normally this job, but the
165:         // properties are stored by using dirname + filename instead of idupl
166:         $oUpload->deletePropertiesByItemid($sDirFileName);
167: 
168:         $this->deleteUploadMetaData($id);
169: 
170:         // delete in DB
171:         return parent::delete($id);
172:     }
173: 
174:     /**
175:      * Deletes meta-data from con_upl_meta table if file is deleting
176:      *
177:      * @param int $idupl
178:      * @return bool
179:      * @throws cDbException
180:      */
181:     protected function deleteUploadMetaData($idupl) {
182:         global $client, $db, $cfg;
183:         $sql = "DELETE FROM `%s` WHERE %s = '%s'";
184:         return $db->query($sql, $cfg['tab']['upl_meta'], 'idupl', (int) $idupl);
185:     }
186: 
187:     /**
188:      * Deletes upload directory by its dirname.
189:      *
190:      * @param string $sDirname
191:      *
192:      * @throws cDbException
193:      * @throws cException
194:      * @global int   $client
195:      */
196:     public function deleteByDirname($sDirname) {
197:         global $client;
198: 
199:         $this->select("dirname = '" . $this->escape($sDirname) . "' AND idclient = " . (int) $client);
200:         while (($oUpload = $this->next()) !== false) {
201:             $this->delete($oUpload->get('idupl'));
202:         }
203:     }
204: }
205: 
206: /**
207:  * Upload item
208:  *
209:  * @package Core
210:  * @subpackage GenericDB_Model
211:  */
212: class cApiUpload extends Item {
213: 
214:     /**
215:      * Property collection instance
216:      *
217:      * @var cApiPropertyCollection
218:      */
219:     protected $_oPropertyCollection;
220: 
221:     /**
222:      * Constructor to create an instance of this class.
223:      *
224:      * @param mixed $mId [optional]
225:      *                   Specifies the ID of item to load
226:      *                   
227:      * @throws cDbException
228:      * @throws cException
229:      */
230:     public function __construct($mId = false) {
231:         global $cfg;
232:         parent::__construct($cfg['tab']['upl'], 'idupl');
233:         if ($mId !== false) {
234:             $this->loadByPrimaryKey($mId);
235:         }
236:     }
237: 
238:     /**
239:      * Updates upload recordset.
240:      * 
241:      * @throws cDbException
242:      * @throws cException
243:      * @throws cInvalidArgumentException
244:      */
245:     public function update() {
246:         $sDirname = $this->get('dirname');
247:         $sFilename = $this->get('filename');
248:         $sExtension = cFileHandler::getExtension($sDirname . $sFilename);
249:         $iFileSize = self::getFileSize($sDirname, $sFilename);
250: 
251:         $bTouched = false;
252: 
253:         if ($this->get('filetype') != $sExtension) {
254:             $this->set('filetype', $sExtension);
255:             $bTouched = true;
256:         }
257: 
258:         if ($this->get('size') != $iFileSize) {
259:             $this->set('size', $iFileSize);
260:             $bTouched = true;
261:         }
262: 
263:         if ($bTouched == true) {
264:             $this->store();
265:         }
266:     }
267: 
268:     /**
269:      * Stores made changes
270:      *
271:      * @return bool
272:      * @throws cDbException
273:      * @throws cInvalidArgumentException
274:      * @global object          $auth
275:      * @global cApiCecRegistry $_cecRegistry
276:      */
277:     public function store() {
278:         global $auth, $_cecRegistry;
279: 
280:         $this->set('modifiedby', $auth->auth['uid']);
281:         $this->set('lastmodified', date('Y-m-d H:i:s'), false);
282: 
283:         // Call chain
284:         $_cecIterator = $_cecRegistry->getIterator('Contenido.Upl_edit.SaveRows');
285:         if ($_cecIterator->count() > 0) {
286:             while (($chainEntry = $_cecIterator->next()) !== false) {
287:                 $chainEntry->execute($this->get('idupl'), $this->get('dirname'), $this->get('filename'));
288:             }
289:         }
290: 
291:         return parent::store();
292:     }
293: 
294:     /**
295:      * Deletes all upload properties by it's itemid
296:      *
297:      * @param string $sItemid
298:      *
299:      * @throws cDbException
300:      * @throws cInvalidArgumentException
301:      */
302:     public function deletePropertiesByItemid($sItemid) {
303:         $oPropertiesColl = $this->_getPropertiesCollectionInstance();
304:         $oPropertiesColl->deleteProperties('upload', $sItemid);
305:     }
306: 
307:     /**
308:      * Returns the filesize
309:      *
310:      * @param string $sDirname
311:      * @param string $sFilename
312:      * @return string
313:      * @throws cDbException
314:      * @throws cException
315:      */
316:     public static function getFileSize($sDirname, $sFilename) {
317:         global $client, $cfgClient;
318: 
319:         $bIsDbfs = cApiDbfs::isDbfs($sDirname);
320:         if (!$bIsDbfs) {
321:             $sDirname = $cfgClient[$client]['upl']['path'] . $sDirname;
322:         }
323: 
324:         $sFilePathName = $sDirname . $sFilename;
325: 
326:         $iFileSize = 0;
327:         if ($bIsDbfs) {
328:             $oDbfsCol = new cApiDbfsCollection();
329:             $iFileSize = $oDbfsCol->getSize($sFilePathName);
330:         } elseif (cFileHandler::exists($sFilePathName)) {
331:             $iFileSize = filesize($sFilePathName);
332:         }
333: 
334:         return $iFileSize;
335:     }
336: 
337:     /**
338:      * Lazy instantiation and return of properties object
339:      *
340:      * @global int $client
341:      * @return cApiPropertyCollection
342:      */
343:     protected function _getPropertiesCollectionInstanceX() {
344:         global $client;
345: 
346:         // Runtime on-demand allocation of the properties object
347:         if (!is_object($this->_oPropertyCollection)) {
348:             $this->_oPropertyCollection = new cApiPropertyCollection();
349:             $this->_oPropertyCollection->changeClient($client);
350:         }
351:         return $this->_oPropertyCollection;
352:     }
353: }
354: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0