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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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: 
 54:         if ($client <= 0) {
 55:             global $client;
 56:         }
 57: 
 58:         // build escaped vars for SQL 
 59:         $escClient = cSecurity::toInteger($client);
 60:         $escDirname = $this->escape($sDirname);
 61:         $escFilename = $this->escape($sFilename);
 62: 
 63:         // Unix style OS distinguish between lower and uppercase file names,
 64:         // i.e. test.gif is not the same as Test.gif
 65:         // Windows OS doesn't distinguish between lower and uppercase file
 66:         // names, i.e. test.gif is the same as Test.gif in file system
 67:         $os = strtolower(getenv('OS'));
 68:         $isWindows = (false !== strpos($os, 'windows'));
 69:         $binary = $isWindows ? '' : 'BINARY';
 70: 
 71:         $this->select("idclient = $escClient AND dirname = $binary '$escDirname' AND filename = $binary '$escFilename'");
 72: 
 73:         if (false !== $oItem = $this->next()) {
 74:             $oItem->update();
 75:         } else {
 76:             $sFiletype = (string) uplGetFileExtension($sFilename);
 77:             $iFilesize = cApiUpload::getFileSize($sDirname, $sFilename);
 78:             $oItem = $this->create($sDirname, $sFilename, $sFiletype, $iFilesize, '');
 79:         }
 80: 
 81:         return $oItem;
 82:     }
 83: 
 84:     /**
 85:      * Creates a upload entry.
 86:      *
 87:      * @global int $client
 88:      * @global array $cfg
 89:      * @global object $auth
 90:      * @param string $sDirname
 91:      * @param string $sFilename
 92:      * @param string $sFiletype
 93:      * @param int $iFileSize
 94:      * @param string $sDescription
 95:      * @param int $iStatus
 96:      * @return cApiUpload
 97:      */
 98:     public function create($sDirname, $sFilename, $sFiletype = '', $iFileSize = 0, $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:      * @global cApiCecRegistry $_cecRegistry
121:      * @global array $cfgClient
122:      * @global int $client
123:      * @param int $id
124:      * @return bool @fixme Code is similar/redundant to
125:      *         include.upl_files_overview.php 216-230
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 Specifies the ID of item to load
209:      */
210:     public function __construct($mId = false) {
211:         global $cfg;
212:         parent::__construct($cfg['tab']['upl'], 'idupl');
213:         if ($mId !== false) {
214:             $this->loadByPrimaryKey($mId);
215:         }
216:     }
217: 
218:     /**
219:      * Updates upload recordset
220:      */
221:     public function update() {
222:         $sDirname = $this->get('dirname');
223:         $sFilename = $this->get('filename');
224:         $sExtension = (string) uplGetFileExtension($sFilename);
225:         $iFileSize = self::getFileSize($sDirname, $sFilename);
226: 
227:         $bTouched = false;
228: 
229:         if ($this->get('filetype') != $sExtension) {
230:             $this->set('filetype', $sExtension);
231:             $bTouched = true;
232:         }
233: 
234:         if ($this->get('size') != $iFileSize) {
235:             $this->set('size', $iFileSize);
236:             $bTouched = true;
237:         }
238: 
239:         if ($bTouched == true) {
240:             $this->store();
241:         }
242:     }
243: 
244:     /**
245:      * Stores made changes
246:      *
247:      * @global object $auth
248:      * @global cApiCecRegistry $_cecRegistry
249:      * @return bool
250:      */
251:     public function store() {
252:         global $auth, $_cecRegistry;
253: 
254:         $this->set('modifiedby', $auth->auth['uid']);
255:         $this->set('lastmodified', date('Y-m-d H:i:s'), false);
256: 
257:         // Call chain
258:         $_cecIterator = $_cecRegistry->getIterator('Contenido.Upl_edit.SaveRows');
259:         if ($_cecIterator->count() > 0) {
260:             while (($chainEntry = $_cecIterator->next()) !== false) {
261:                 $chainEntry->execute($this->get('idupl'), $this->get('dirname'), $this->get('filename'));
262:             }
263:         }
264: 
265:         return parent::store();
266:     }
267: 
268:     /**
269:      * Deletes all upload properties by it's itemid
270:      *
271:      * @param string $sItemid
272:      */
273:     public function deletePropertiesByItemid($sItemid) {
274:         $oPropertiesColl = $this->_getPropertiesCollectionInstance();
275:         $oPropertiesColl->deleteProperties('upload', $sItemid);
276:     }
277: 
278:     /**
279:      * Returns the filesize
280:      *
281:      * @param string $sDirname
282:      * @param string $sFilename
283:      * @return string
284:      */
285:     public static function getFileSize($sDirname, $sFilename) {
286:         global $client, $cfgClient;
287: 
288:         $bIsDbfs = cApiDbfs::isDbfs($sDirname);
289:         if (!$bIsDbfs) {
290:             $sDirname = $cfgClient[$client]['upl']['path'] . $sDirname;
291:         }
292: 
293:         $sFilePathName = $sDirname . $sFilename;
294: 
295:         $iFileSize = 0;
296:         if ($bIsDbfs) {
297:             $oDbfsCol = new cApiDbfsCollection();
298:             $iFileSize = $oDbfsCol->getSize($sFilePathName);
299:         } elseif (cFileHandler::exists($sFilePathName)) {
300:             $iFileSize = filesize($sFilePathName);
301:         }
302: 
303:         return $iFileSize;
304:     }
305: 
306:     /**
307:      * Lazy instantiation and return of properties object
308:      *
309:      * @global int $client
310:      * @return cApiPropertyCollection
311:      */
312:     protected function _getPropertiesCollectionInstanceX() {
313:         global $client;
314: 
315:         // Runtime on-demand allocation of the properties object
316:         if (!is_object($this->_oPropertyCollection)) {
317:             $this->_oPropertyCollection = new cApiPropertyCollection();
318:             $this->_oPropertyCollection->changeClient($client);
319:         }
320:         return $this->_oPropertyCollection;
321:     }
322: }
323: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen