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