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