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