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 upload collection and item class.
  4:  * @todo Reset in/out filters of parent classes.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       GenericDB_Model
  8:  * @version          SVN Revision $Rev:$
  9:  *
 10:  * @author           Timo Hummel
 11:  * @copyright        four for business AG <www.4fb.de>
 12:  * @license          http://www.contenido.org/license/LIZENZ.txt
 13:  * @link             http://www.4fb.de
 14:  * @link             http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Upload collection
 21:  *
 22:  * @package Core
 23:  * @subpackage GenericDB_Model
 24:  */
 25: class cApiUploadCollection extends ItemCollection {
 26: 
 27:     /**
 28:      * Constructor Function
 29:      *
 30:      * @global array $cfg
 31:      */
 32:     public function __construct() {
 33:         global $cfg;
 34:         parent::__construct($cfg['tab']['upl'], 'idupl');
 35:         $this->_setItemClass('cApiUpload');
 36: 
 37:         // set the join partners so that joins can be used via link() method
 38:         $this->_setJoinPartner('cApiClientCollection');
 39:     }
 40: 
 41:     /**
 42:      * Syncronizes upload directory and file with database.
 43:      *
 44:      * @global int $client
 45:      * @param string $sDirname
 46:      * @param string $sFilename
 47:      * @return cApiUpload
 48:      * @param int $clientid
 49:      */
 50:     public function sync($sDirname, $sFilename, $client = 0) {
 51:         $client = cSecurity::toInteger($client);
 52:         if ($client <= 0) {
 53:             global $client;
 54:         }
 55: 
 56:         $sDirname = $this->escape($sDirname);
 57:         $sFilename = $this->escape($sFilename);
 58:         if (strstr(strtolower($_ENV['OS']), 'windows') === false) {
 59:             // Unix style OS distinguish between lower and uppercase file names,
 60:             // i.e. test.gif is not the same as Test.gif
 61:             $this->select("dirname = BINARY '$sDirname' AND filename = BINARY '$sFilename' AND idclient = " . (int) $client);
 62:         } else {
 63:             // Windows OS doesn't distinguish between lower and uppercase file
 64:             // names, i.e. test.gif is the same as Test.gif in file system
 65:             $this->select("dirname = '$sDirname' AND filename = '$sFilename' AND idclient = " . (int) $client);
 66:         }
 67: 
 68:         if (($oItem = $this->next()) !== false) {
 69:             $oItem->update();
 70:         } else {
 71:             $sFiletype = (string) uplGetFileExtension($sFilename);
 72:             $iFilesize = cApiUpload::getFileSize($sDirname, $sFilename);
 73:             $oItem = $this->create($sDirname, $sFilename, $sFiletype, $iFilesize, '');
 74:         }
 75: 
 76:         return $oItem;
 77:     }
 78: 
 79:     /**
 80:      * Creates a upload entry.
 81:      *
 82:      * @global int $client
 83:      * @global array $cfg
 84:      * @global object $auth
 85:      * @param string $sDirname
 86:      * @param string $sFilename
 87:      * @param string $sFiletype
 88:      * @param int $iFileSize
 89:      * @param string $sDescription
 90:      * @param int $iStatus
 91:      * @return cApiUpload
 92:      */
 93:     public function create($sDirname, $sFilename, $sFiletype = '', $iFileSize = 0, $sDescription = '', $iStatus = 0) {
 94:         global $client, $cfg, $auth;
 95: 
 96:         $oItem = parent::createNewItem();
 97: 
 98:         $oItem->set('idclient', $client);
 99:         $oItem->set('filename', $sFilename, false);
100:         $oItem->set('filetype', $sFiletype, false);
101:         $oItem->set('size', $iFileSize, false);
102:         $oItem->set('dirname', $sDirname, false);
103:         // $oItem->set('description', $sDescription, false);
104:         $oItem->set('status', $iStatus, false);
105:         $oItem->set('author', $auth->auth['uid']);
106:         $oItem->set('created', date('Y-m-d H:i:s'), false);
107:         $oItem->store();
108: 
109:         return $oItem;
110:     }
111: 
112:     /**
113:      * Deletes upload file and it's properties
114:      *
115:      * @global cApiCecRegistry $_cecRegistry
116:      * @global array $cfgClient
117:      * @global int $client
118:      * @param int $id
119:      * @return bool
120:      * @fixme Code is similar/redundant to include.upl_files_overview.php 216-230
121:      */
122:     public function delete($id) {
123:         global $cfgClient, $client;
124: 
125:         $oUpload = new cApiUpload();
126:         $oUpload->loadByPrimaryKey($id);
127: 
128:         $sDirFileName = $oUpload->get('dirname') . $oUpload->get('filename');
129: 
130:         // call chain for deleted file
131:         $_cecIterator = cRegistry::getCecRegistry()->getIterator('Contenido.Upl_edit.Delete');
132:         if ($_cecIterator->count() > 0) {
133:             while (($chainEntry = $_cecIterator->next()) !== false) {
134:                 $chainEntry->execute($oUpload->get('idupl'), $oUpload->get('dirname'), $oUpload->get('filename'));
135:             }
136:         }
137: 
138:         // delete from dbfs or filesystem
139:         if (cApiDbfs::isDbfs($sDirFileName)) {
140:             $oDbfs = new cApiDbfsCollection();
141:             $oDbfs->remove($sDirFileName);
142:         } elseif (cFileHandler::exists($cfgClient[$client]['upl']['path'] . $sDirFileName)) {
143:             unlink($cfgClient[$client]['upl']['path'] . $sDirFileName);
144:         }
145: 
146:         // delete properties
147:         // note: parents delete methos does normally this job, but the
148:         // properties are stored by using dirname + filename instead of idupl
149:         $oUpload->deletePropertiesByItemid($sDirFileName);
150: 
151:         $this->deleteUploadMetaData($id);
152: 
153:         // delete in DB
154:         return parent::delete($id);
155:     }
156: 
157:     /**
158:      *
159:      *
160:      *
161:      * Deletes meta-data from con_upl_meta table if file is deleting
162:      *
163:      * @param int $idupl
164:      * @return bool
165:      */
166:     protected function deleteUploadMetaData($idupl) {
167:         global $client, $db, $cfg;
168:         $sql = "DELETE FROM `%s` WHERE %s = '%s'";
169:         return $db->query($sql, $cfg['tab']['upl_meta'], 'idupl', (int) $idupl);
170:     }
171: 
172:     /**
173:      * Deletes upload directory by its dirname.
174:      *
175:      * @global int $client
176:      * @param string $sDirname
177:      */
178:     public function deleteByDirname($sDirname) {
179:         global $client;
180: 
181:         $this->select("dirname = '" . $this->escape($sDirname) . "' AND idclient = " . (int) $client);
182:         while (($oUpload = $this->next()) !== false) {
183:             $this->delete($oUpload->get('idupl'));
184:         }
185:     }
186: 
187: }
188: 
189: /**
190:  * Upload item
191:  *
192:  * @package Core
193:  * @subpackage GenericDB_Model
194:  */
195: class cApiUpload extends Item {
196: 
197:     /**
198:      * Property collection instance
199:      *
200:      * @var cApiPropertyCollection
201:      */
202:     protected $_oPropertyCollection;
203: 
204:     /**
205:      * Constructor Function
206:      *
207:      * @param mixed $mId Specifies the ID of item to load
208:      */
209:     public function __construct($mId = false) {
210:         global $cfg;
211:         parent::__construct($cfg['tab']['upl'], 'idupl');
212:         if ($mId !== false) {
213:             $this->loadByPrimaryKey($mId);
214:         }
215:     }
216: 
217:     /**
218:      * Updates upload recordset
219:      */
220:     public function update() {
221:         $sDirname = $this->get('dirname');
222:         $sFilename = $this->get('filename');
223:         $sExtension = (string) uplGetFileExtension($sFilename);
224:         $iFileSize = self::getFileSize($sDirname, $sFilename);
225: 
226:         $bTouched = false;
227: 
228:         if ($this->get('filetype') != $sExtension) {
229:             $this->set('filetype', $sExtension);
230:             $bTouched = true;
231:         }
232: 
233:         if ($this->get('size') != $iFileSize) {
234:             $this->set('size', $iFileSize);
235:             $bTouched = true;
236:         }
237: 
238:         if ($bTouched == true) {
239:             $this->store();
240:         }
241:     }
242: 
243:     /**
244:      * Stores made changes
245:      *
246:      * @global object $auth
247:      * @global cApiCecRegistry $_cecRegistry
248:      * @return bool
249:      */
250:     public function store() {
251:         global $auth, $_cecRegistry;
252: 
253:         $this->set('modifiedby', $auth->auth['uid']);
254:         $this->set('lastmodified', date('Y-m-d H:i:s'), false);
255: 
256:         // Call chain
257:         $_cecIterator = $_cecRegistry->getIterator('Contenido.Upl_edit.SaveRows');
258:         if ($_cecIterator->count() > 0) {
259:             while (($chainEntry = $_cecIterator->next()) !== false) {
260:                 $chainEntry->execute($this->get('idupl'), $this->get('dirname'), $this->get('filename'));
261:             }
262:         }
263: 
264:         return parent::store();
265:     }
266: 
267:     /**
268:      * Deletes all upload properties by it's itemid
269:      *
270:      * @param string $sItemid
271:      */
272:     public function deletePropertiesByItemid($sItemid) {
273:         $oPropertiesColl = $this->_getPropertiesCollectionInstance();
274:         $oPropertiesColl->deleteProperties('upload', $sItemid);
275:     }
276: 
277:     /**
278:      * Returns the filesize
279:      *
280:      * @param string $sDirname
281:      * @param string $sFilename
282:      * @return string
283:      */
284:     public static function getFileSize($sDirname, $sFilename) {
285:         global $client, $cfgClient;
286: 
287:         $bIsDbfs = cApiDbfs::isDbfs($sDirname);
288:         if (!$bIsDbfs) {
289:             $sDirname = $cfgClient[$client]['upl']['path'] . $sDirname;
290:         }
291: 
292:         $sFilePathName = $sDirname . $sFilename;
293: 
294:         $iFileSize = 0;
295:         if ($bIsDbfs) {
296:             $oDbfsCol = new cApiDbfsCollection();
297:             $iFileSize = $oDbfsCol->getSize($sFilePathName);
298:         } elseif (cFileHandler::exists($sFilePathName)) {
299:             $iFileSize = filesize($sFilePathName);
300:         }
301: 
302:         return $iFileSize;
303:     }
304: 
305:     /**
306:      * Lazy instantiation and return of properties object
307:      *
308:      * @global int $client
309:      * @return cApiPropertyCollection
310:      */
311:     protected function _getPropertiesCollectionInstanceX() {
312:         global $client;
313: 
314:         // Runtime on-demand allocation of the properties object
315:         if (!is_object($this->_oPropertyCollection)) {
316:             $this->_oPropertyCollection = new cApiPropertyCollection();
317:             $this->_oPropertyCollection->changeClient($client);
318:         }
319:         return $this->_oPropertyCollection;
320:     }
321: 
322: }
323: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0