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