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 CONTENIDO upload functions.
  4:  *
  5:  * @package Core
  6:  * @subpackage Backend
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Jan Lengowski, Timo Trautmann
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: cInclude('includes', 'functions.file.php');
 18: 
 19: /**
 20:  * Function reduces long path names and creates a dynamic tooltipp which shows
 21:  * the full path name on mouseover
 22:  *
 23:  * @param string $sDisplayPath Original filepath
 24:  * @param int $iLimit Limit of chars which were displayed directly. If the path
 25:  *        string is shorter there will be no tooltipp
 26:  * @return string Contains short path name and tooltipp if neccessary
 27:  */
 28: function generateDisplayFilePath($sDisplayPath, $iLimit) {
 29:     $sDisplayPath = (string) $sDisplayPath;
 30:     $iLimit = (int) $iLimit;
 31: 
 32:     if (strlen($sDisplayPath) > $iLimit) {
 33:         $sDisplayPathShort = cApiStrTrimHard($sDisplayPath, $iLimit);
 34: 
 35:         $sTooltippString = '';
 36:         $iCharcount = 0;
 37: 
 38:         $aPathFragments = explode('/', $sDisplayPath);
 39: 
 40:         foreach ($aPathFragments as $sFragment) {
 41:             if ($sFragment != '') {
 42:                 if (strlen($sFragment) > ($iLimit - 5)) {
 43:                     $sFragment = cApiStrTrimHard($sFragment, $iLimit);
 44:                 }
 45: 
 46:                 if ($iCharcount + strlen($sFragment) + 1 > $iLimit) {
 47:                     $sTooltippString .= '<br>' . $sFragment . '/';
 48:                     $iCharcount = strlen($sFragment);
 49:                 } else {
 50:                     $iCharcount = $iCharcount + 1 + strlen($sFragment);
 51:                     $sTooltippString .= $sFragment . '/';
 52:                 }
 53:             }
 54:         }
 55: 
 56:         $sDisplayPath = '<span title="' . $sTooltippString . '" class="tooltip">' . $sDisplayPathShort . '</span>';
 57:     }
 58:     return $sDisplayPath;
 59: }
 60: 
 61: /**
 62:  * Returns array structure of passed directory.
 63:  * Parses the directory recursively and
 64:  * collects informations about found subdirectories.
 65:  *
 66:  * @param string $sCurrentDir Directory to parse
 67:  * @param string $sStartDir Start directory. Will be used by recursion.
 68:  * @param array $aFiles Files array structure. Will be used by recursion.
 69:  * @param int $iDepth Nesting depth of found files. Will be used by recursion.
 70:  * @param string $sPathString Path used to create full path to files. Will be
 71:  *        used by recursion.
 72:  * @return array Indexed arraay containing assoziative directory informations
 73:  */
 74: function uplDirectoryListRecursive($sCurrentDir, $sStartDir = '', $aFiles = array(), $iDepth = -1, $sPathString = '') {
 75:     $iDepth++;
 76: 
 77:     $aDirsToExclude = uplGetDirectoriesToExclude();
 78: 
 79:     // remember where we started from
 80:     if (empty($sStartDir)) {
 81:         $sStartDir = $sCurrentDir;
 82:     }
 83: 
 84:     if (chdir($sCurrentDir) == false) {
 85:         return $aFiles;
 86:     }
 87: 
 88:     // list the files in the dir
 89:     $aCurrentFiles = array();
 90:     if (false === ($handle = cDirHandler::read('.', false, true))) {
 91:         return $aFiles;
 92:     }
 93:     foreach ($handle as $file) {
 94:         if (!in_array(strtolower($file), $aDirsToExclude)) {
 95:             $aCurrentFiles[] = $file;
 96:         }
 97:     }
 98:     sort($aCurrentFiles);
 99: 
100:     foreach ($aCurrentFiles as $file) {
101:         $sFilePathName = getcwd() . '/' . $file;
102:         if ((filetype($sFilePathName) == 'dir') && (opendir($sFilePathName) !== false)) {
103:             $_aFile = array(
104:                     'name' => $file,
105:                     'depth' => $iDepth,
106:                     'pathstring' => $sPathString . $file . '/'
107:             );
108: 
109:             $aFiles[] = $_aFile;
110: 
111:             $aFiles = uplDirectoryListRecursive($sFilePathName, getcwd(), $aFiles, $iDepth, $_aFile['pathstring']);
112:         }
113:     }
114: 
115:     chdir($sStartDir);
116:     return $aFiles;
117: }
118: 
119: /**
120:  * Checks if passed upload directory contains at least one file or directory
121:  *
122:  * @param string $sDir
123:  * @return bool
124:  * @todo Function name is misleading, should be renamed to uplIsEmpty
125:  */
126: function uplHasFiles($sDir) {
127:     global $client, $cfgClient;
128: 
129:     $handle = cDirHandler::read($cfgClient[$client]['upl']['path'] . $sDir);
130:     
131:     if (!$handle) {
132:         return false;
133:     }
134:     
135:     $bHasContent = false;
136:     if (is_dir($cfgClient[$client]['upl']['path'] . $sDir)) {
137:         foreach ($handle as $sDirEntry) {
138:             if (cFileHandler::fileNameIsDot($sDirEntry) === false) {
139:                 $bHasContent = true;
140:                 break;
141:             }
142:         }
143:     }
144:     return $bHasContent;
145: }
146: 
147: /**
148:  * Checks if passed upload directory contains at least one directory
149:  *
150:  * @param string $sDir
151:  * @return bool
152:  */
153: function uplHasSubdirs($sDir) {
154:     global $client, $cfgClient;
155:     
156:     $handle = cDirHandler::read($cfgClient[$client]['upl']['path'] . $sDir); 
157:     if (!$handle) {
158:         return false;
159:     }
160:     
161:     $bHasSubdir = false;
162:     if (is_dir($cfgClient[$client]['upl']['path'] . $sDir)) {
163:         foreach ($handle as $sDirEntry) {
164:             if (cFileHandler::fileNameIsDot($sDirEntry) === false) {
165:                 $bHasSubdir = true;
166:                 break;
167:             }
168:         }
169:     }
170: 
171:     return $bHasSubdir;
172: }
173: 
174: /**
175:  * Sync database contents with directory and vice versa.
176:  * - Removes all db entries pointing to non existing directories
177:  * - Removes all db entries pointing to non existing upload files
178:  * - Syncs found files in passed path with the database
179:  *
180:  * @param string $sPath Specifies the path to scan
181:  */
182: function uplSyncDirectory($sPath) {
183:     global $cfgClient, $client, $cfg, $db;
184: 
185:     if (cApiDbfs::isDbfs($sPath)) {
186:         return uplSyncDirectoryDBFS($sPath);
187:     }
188: 
189:     $oUploadsColl = new cApiUploadCollection();
190: 
191:     // get current upload directory, it's subdirectories and remove all database
192:     // entries pointing to a non existing upload directory on the file system
193:     $sql = 'SELECT DISTINCT(dirname) AS dirname FROM ' . $cfg['tab']['upl'] . ' WHERE ' . 'idclient=' . (int) $client . ' AND dirname LIKE "' . $db->escape($sPath) . '%"';
194:     $db->query($sql);
195:     while ($db->nextRecord()) {
196:         $sCurrDirname = $db->f('dirname');
197:         $sSubDir = substr($sCurrDirname, strlen($sPath));
198:         if (substr_count($sSubDir, '/') <= 1 && !cApiDbfs::isDbfs($sCurrDirname)) {
199:             // subdirectory is a direct descendant, process this directory too
200:             $sFullPath = $cfgClient[$client]['upl']['path'] . $sCurrDirname;
201:             if (!is_dir($sFullPath)) {
202:                 $oUploadsColl->deleteByDirname($sCurrDirname);
203:             }
204:         }
205:     }
206: 
207:     // delete all db entries related to current directory without existing file
208:     // on file system
209:     $oUploadsColl->select("dirname='" . $oUploadsColl->escape($sPath) . "' AND idclient=" . (int) $client);
210:     while (($oUpload = $oUploadsColl->next()) !== false) {
211:         if (!cFileHandler::exists($cfgClient[$client]['upl']['path'] . $oUpload->get('dirname') . $oUpload->get('filename'))) {
212:             $oUploadsColl->delete($oUpload->get('idupl'));
213:         }
214:     }
215: 
216:     // sync all files in current directory with database
217:     $sFullPath = $cfgClient[$client]['upl']['path'] . $sPath;
218:     if (is_dir($sFullPath)) {
219:         $aDirsToExclude = uplGetDirectoriesToExclude();
220:         if (false !== ($handle = cDirHandler::read($sFullPath))) {
221:             foreach ($handle as $file) {
222:                 if (!in_array(strtolower($file), $aDirsToExclude)) {
223:                     cDebug::out($sPath . "::" . $file);
224:                     $oUploadsColl->sync($sPath, $file);
225:                 }
226:             }
227:         }
228:     }
229: }
230: 
231: /**
232:  * Sync database contents with DBFS
233:  *
234:  * @param string $sPath Specifies the path to scan
235:  */
236: function uplSyncDirectoryDBFS($sPath) {
237:     global $cfgClient, $client, $cfg, $db;
238: 
239:     $oUploadsColl = new cApiUploadCollection();
240:     $oPropertiesColl = new cApiPropertyCollection();
241:     $oDBFSColl = new cApiDbfsCollection();
242: 
243:     if ($oDBFSColl->dirExists($sPath)) {
244:         $sStripPath = cApiDbfs::stripPath($sPath);
245:         $oDBFSColl->select("dirname = '$sStripPath'");
246:         while (($oFile = $oDBFSColl->next()) !== false) {
247:             if ($oFile->get('filename') != '.') {
248:                 $oUploadsColl->sync($sPath . "/", $oFile->get('filename'));
249:             }
250:         }
251:     }
252: 
253:     $oUploadsColl->select("dirname='$sPath/' AND idclient='$client'");
254:     while (($oUpload = $oUploadsColl->next()) !== false) {
255:         if (!$oDBFSColl->fileExists($oUpload->get('dirname') . $oUpload->get('filename'))) {
256:             $oUploadsColl->delete($oUpload->get("idupl"));
257:         }
258:     }
259: 
260:     $oPropertiesColl->select("idclient='$client' AND itemtype='upload' AND type='file' AND itemid LIKE '" . $sPath . "%'");
261:     while (($oProperty = $oPropertiesColl->next()) !== false) {
262:         if (!$oDBFSColl->fileExists($oProperty->get('itemid'))) {
263:             $oPropertiesColl->delete($oProperty->get('idproperty'));
264:         }
265:     }
266: 
267:     return;
268: }
269: 
270: /**
271:  * Creates a upload directory, either in filesystem or in dbfs.
272:  *
273:  * @param string $sPath Path to directory to create, either path from client
274:  *        upload
275:  *        directory or a dbfs path
276:  * @param string $sName Name of directory to create
277:  * @return string void value of filemode as string ('0702') or nothing
278:  */
279: function uplmkdir($sPath, $sName) {
280:     global $cfgClient, $client, $action;
281: 
282:     // Check DB filesystem
283:     if (cApiDbfs::isDbfs($sPath)) {
284:         $sPath = cApiDbfs::stripPath($sPath);
285:         $sFullPath = $sPath . '/' . $sName . '/.';
286: 
287:         $dbfs = new cApiDbfsCollection();
288:         $dbfs->create($sFullPath);
289:         return;
290:     }
291: 
292:     // Check directory name
293:     $dName = uplCreateFriendlyName($sName);
294:     $dName = strtr($dName, "'", '.');
295:     if ($dName != $sName) {
296:         $action = 'upl_mkdir';
297:         return '0703';
298:     }
299: 
300:     // Check dir or create new
301:     $dPath = $cfgClient[$client]['upl']['path'] . $sPath . $dName;
302:     if (cDirHandler::read($dPath) === false) {
303:         // Create new dir
304:         return cDirHandler::create($dPath);
305:     } else {
306:         // Directory already exist
307:         $action = 'upl_mkdir';
308:         return '0702';
309:     }
310: }
311: 
312: /**
313:  * Renames a upload directory, updates all found upoad files containing the old
314:  * directory name and updates also all entries in propertoes table related to
315:  * affected upload files.
316:  *
317:  * @param string $sOldName
318:  * @param string $sNewName
319:  * @param string $sParent
320:  * @throws cException if the upload path can not be renamed
321:  */
322: function uplRenameDirectory($sOldName, $sNewName, $sParent) {
323:     global $cfgClient, $client, $cfg, $db;
324: 
325:     // rename directory
326:     $sOldUplPath = $cfgClient[$client]['upl']['path'] . $sParent . $sOldName;
327:     $sNewUplPath = $cfgClient[$client]['upl']['path'] . $sParent . $sNewName . '/';
328:     if (!$bResult = rename($sOldUplPath, $sNewUplPath)) {
329:         throw new cException("Couldn't rename upload path {$sOldUplPath} to {$sNewUplPath}");
330:     }
331: 
332:     // fetch all directory strings starting with the old path, and replace them
333:     // with the new path
334:     $oUploadColl = new cApiUploadCollection();
335:     $oUploadColl->select("idclient=" . (int) $client . " AND dirname LIKE '" . $oUploadColl->escape($sParent . $sOldName) . "%'");
336:     while (($oUpload = $oUploadColl->next()) !== false) {
337:         $sDirName = $oUpload->get('dirname');
338:         $sJunk = substr($sDirName, strlen($sParent) + strlen($sOldName));
339:         $sNewName2 = $sParent . $sNewName . $sJunk;
340:         $oUpload->set('dirname', $sNewName2, false);
341:         $oUpload->store();
342:     }
343: 
344:     // update all upload item properties starting with the old path, replace
345:     // itemid with the new path
346:     $oPropertyColl = new cApiPropertyCollection();
347:     $oPropertyColl->select("idclient=" . (int) $client . " AND itemtype='upload' AND type='file' AND itemid LIKE '" . $oPropertyColl->escape($sParent . $sOldName) . "%'");
348:     while (($oProperty = $oPropertyColl->next()) !== false) {
349:         $sDirName = $oProperty->get('itemid');
350:         $sJunk = substr($sDirName, strlen($sParent) + strlen($sOldName));
351:         $sNewName2 = $sParent . $sNewName . $sJunk;
352:         $oProperty->set('itemid', $sNewName2, false);
353:         $oProperty->store();
354:     }
355: }
356: 
357: /**
358:  * Parses passed directory recursively and stores some properties in TreeItem
359:  *
360:  * @param string $sDirectory
361:  * @param TreeItem $oRootItem
362:  * @param int $iLevel
363:  * @param string $sParent
364:  * @param int $iRenameLevel
365:  * @return array List of invalid directories
366:  */
367: function uplRecursiveDirectoryList($sDirectory, TreeItem $oRootItem, $iLevel, $sParent = '', $iRenameLevel = 0) {
368:     $aInvalidDirectories = array();
369: 
370:     if (true === is_dir($sDirectory)) {
371:         $aDirsToExclude = uplGetDirectoriesToExclude();
372: 
373:         $aFiles = array();
374: 
375:         // list the files in the dir
376:         foreach (cDirHandler::read($sDirectory, false, true) as $key => $file) {
377:             if (!in_array(strtolower($file), $aDirsToExclude)) {
378:                 if (strpos($file, ".") === 0) {
379:                     continue;
380:                 }
381:                 if (@chdir($sDirectory . $file . '/')) {
382:                     if (uplCreateFriendlyName($file) == $file) {
383:                         $aFiles[] = $file;
384:                     } else {
385:                         if ($_GET['force_rename'] == 'true') {
386:                             if ($iRenameLevel == 0 || $iRenameLevel == $iLevel) {
387:                                 uplRenameDirectory($file, uplCreateFriendlyName($file), $sParent);
388:                                 $iRenameLevel = $iLevel;
389:                                 $aFiles[] = uplCreateFriendlyName($file);
390:                             } else {
391:                                 $aInvalidDirectories[] = $file;
392:                             }
393:                         } else {
394:                             $aInvalidDirectories[] = $file;
395:                         }
396:                     }
397:                 }
398:             }
399:         }
400: 
401:         sort($aFiles);
402:         foreach ($aFiles as $key => $file) {
403:             $oItem = new TreeItem($file, $sDirectory . $file . '/', true);
404:             $oItem->custom['level'] = $iLevel;
405:             $oItem->custom['lastitem'] = ($key == count($aFiles) - 1);
406:             $oItem->custom['parent'] = $sDirectory;
407: 
408:             $oRootItem->addItem($oItem);
409:             $aArrayTemp = uplRecursiveDirectoryList($sDirectory . $file . '/', $oItem, $iLevel + 1, $sParent . $file . '/', $iRenameLevel);
410:             $aInvalidDirectories = array_merge($aInvalidDirectories, $aArrayTemp);
411:             unset($oItem);
412:         }
413:     }
414: 
415:     return $aInvalidDirectories;
416: }
417: 
418: /**
419:  * Collects informations about all available dbfs directories stored in TreeItem
420:  *
421:  * @param string $directory Not used at te moment!
422:  * @param TreeItem $oRootItem
423:  * @param int $level Not used at te moment!
424:  */
425: function uplRecursiveDBDirectoryList($directory, TreeItem $oRootItem, $level, $client) {
426:     $dbfs = new cApiDbfsCollection();
427:     $dbfs->select("filename = '.' AND idclient=" . cSecurity::toInteger($client), 'dirname', 'dirname ASC');
428:     $count = 0;
429:     $lastlevel = 0;
430:     $item['.'] = $oRootItem;
431: 
432:     $prevobj = array(); // TODO: what was this array supposed to be?
433:     $lprevobj = new stdClass(); // TODO: what was this object supposed to be?
434: 
435:     while (($dbitem = $dbfs->next()) !== false) {
436:         $dirname = $dbitem->get('dirname');
437:         $level = substr_count($dirname, '/') + 2;
438:         $file = basename($dbitem->get('dirname'));
439:         $parent = dirname($dbitem->get('dirname'));
440: 
441:         if ($dirname != '.' && $file != '.') {
442:             $item[$dirname] = new TreeItem($file, cApiDbfs::PROTOCOL_DBFS . '/' . $dirname, true);
443:             $item[$dirname]->custom['level'] = $level;
444:             $item[$dirname]->custom['parent'] = $parent;
445:             $item[$dirname]->custom['lastitem'] = true;
446: 
447:             if ($prevobj[$level]->custom['level'] == $level) {
448:                 if (is_object($prevobj[$level])) {
449:                     $prevobj[$level]->custom['lastitem'] = false;
450:                 }
451:             }
452: 
453:             if ($lastlevel > $level) {
454:                 unset($prevobj[$lastlevel]);
455:                 $lprevobj->custom['lastitem'] = true;
456:             }
457: 
458:             $prevobj[$level] = $item[$dirname];
459:             $lprevobj = $item[$dirname];
460: 
461:             $lastlevel = $level;
462: 
463:             if (is_object($item[$parent])) {
464:                 $item[$parent]->addItem($item[$dirname]);
465:             }
466: 
467:             $count++;
468:         }
469:     }
470: }
471: 
472: /**
473:  * Returns thumbnail for a specific upload file
474:  *
475:  * @param string $sFile Filename to retrieve the thumbnail for
476:  * @param int $iMaxSize Thumb dimension (size of with and heigth)
477:  * @return string
478:  */
479: function uplGetThumbnail($sFile, $iMaxSize) {
480:     global $client, $cfgClient;
481: 
482:     if ($iMaxSize == -1) {
483:         return uplGetFileIcon($sFile);
484:     }
485: 
486:     $sFileType = strtolower(getFileType($sFile));
487: 
488:     switch ($sFileType) {
489:         case "png":
490:         case "gif":
491:         case "tiff":
492:         case "tif":
493:         case "bmp":
494:         case "jpeg":
495:         case "jpg":
496:         case "iff":
497:         case "xbm":
498:         case "wbmp":
499:             $img = cApiImgScale($cfgClient[$client]['upl']['path'] . $sFile, $iMaxSize, $iMaxSize, false, false, 50);
500:             if ($img !== false) {
501:                 return $img;
502:             }
503:             $img = cApiImgScale(cRegistry::getBackendPath() . 'images/unknown.jpg', $iMaxSize, $iMaxSize, false, false, 50);
504:             if ($img !== false) {
505:                 return $img;
506:             } else {
507:                 return uplGetFileIcon($sFile);
508:             }
509:             break;
510:         default:
511:             return uplGetFileIcon($sFile);
512:             break;
513:     }
514: }
515: 
516: /**
517:  * Returns the icon for a file type
518:  *
519:  * @param string $sFile Filename to retrieve the extension for
520:  * @return string Icon for the file type
521:  */
522: function uplGetFileIcon($sFile) {
523:     global $cfg;
524: 
525:     $sPathFiletypes = cRegistry::getBackendUrl() . $cfg['path']['images'] . 'filetypes/';
526:     $sFileType = strtolower(getFileType($sFile));
527: 
528:     switch ($sFileType) {
529:         case "sxi":
530:         case "sti":
531:         case "pps":
532:         case "pot":
533:         case "kpr":
534:         case "pptx":
535:         case "potx":
536:         case "pptm":
537:         case "potm":
538:         case "ppt":
539:             $icon = "ppt.gif";
540:             break;
541:         case "doc":
542:         case "dot":
543:         case "sxw":
544:         case "stw":
545:         case "sdw":
546:         case "docx":
547:         case "dotx":
548:         case "docm":
549:         case "dotm":
550:         case "kwd":
551:             $icon = "word.gif";
552:             break;
553:         case "xls":
554:         case "sxc":
555:         case "stc":
556:         case "xlw":
557:         case "xlt":
558:         case "csv":
559:         case "ksp":
560:         case "xlsx":
561:         case "xltx":
562:         case "xlsm":
563:         case "xlsb":
564:         case "xltm":
565:         case "sdc":
566:             $icon = "excel.gif";
567:             break;
568:         case "txt":
569:         case "rtf":
570:             $icon = "txt.gif";
571:             break;
572:         case "gif":
573:             $icon = "gif.gif";
574:             break;
575:         case "png":
576:             $icon = "png.gif";
577:             break;
578:         case "jpeg":
579:         case "jpg":
580:             $icon = "jpg.gif";
581:             break;
582:         case "html":
583:         case "htm":
584:             $icon = "html.gif";
585:             break;
586:         case "lha":
587:         case "rar":
588:         case "arj":
589:         case "bz2":
590:         case "bz":
591:         case "gz":
592:         case "tar":
593:         case "tbz2":
594:         case "tbz":
595:         case "tgz":
596:         case "zip":
597:             $icon = "zip.gif";
598:             break;
599:         case "pdf":
600:             $icon = "pdf.gif";
601:             break;
602:         case "mov":
603:         case "avi":
604:         case "mpg":
605:         case "mpeg":
606:         case "wmv":
607:             $icon = "movie.gif";
608:             break;
609:         case "swf":
610:             $icon = "swf.gif";
611:             break;
612:         case "js":
613:             $icon = "js.gif";
614:             break;
615:         case "vcf":
616:             $icon = "vcf.gif";
617:             break;
618:         case "odf":
619:             $icon = "odf.gif";
620:             break;
621:         case "php":
622:             $icon = "php.gif";
623:             break;
624:         case "mp3":
625:         case "wma":
626:         case "ogg":
627:         case "mp4":
628:             $icon = "sound.gif";
629:             break;
630:         case "psd":
631:         case "ai":
632:         case "eps":
633:         case "cdr":
634:         case "qxp":
635:         case "ps":
636:             $icon = "design.gif";
637:             break;
638:         case "css":
639:             $icon = "css.gif";
640:             break;
641:         default:
642:             if (cFileHandler::exists($sPathFiletypes . $sFileType . '.gif')) {
643:                 $icon = $sFileType . '.gif';
644:             } else {
645:                 $icon = "unknown.gif";
646:             }
647:             break;
648:     }
649: 
650:     return $sPathFiletypes . $icon;
651: }
652: 
653: /**
654:  * Returns the description for a file type
655:  *
656:  * @param string $sExtension Extension to use
657:  * @return string Text for the file type
658:  */
659: function uplGetFileTypeDescription($sExtension) {
660:     global $cfg;
661: 
662:     switch ($sExtension) {
663:         // Presentation files
664:         case "sxi":
665:             return (i18n("OpenOffice.org Presentation"));
666:         case "sti":
667:             return (i18n("OpenOffice.org Presentation Template"));
668:         case "pps":
669:             return (i18n("Microsoft PowerPoint Screen Presentation"));
670:         case "pot":
671:             return (i18n("Microsoft PowerPoint Presentation Template"));
672:         case "kpr":
673:             return (i18n("KDE KPresenter Document"));
674:         case "ppt":
675:             return (i18n("Microsoft PowerPoint Presentation Template"));
676: 
677:         // Document files
678:         case "doc":
679:             return (i18n("Microsoft Word Document or regular text file"));
680:         case "dot":
681:             return (i18n("Microsoft Word Template"));
682:         case "sxw":
683:             return (i18n("OpenOffice.org Text Document"));
684:         case "stw":
685:             return (i18n("OpenOffice.org Text Document Template"));
686:         case "sdw":
687:             return (i18n("StarOffice 5.0 Text Document"));
688:         case "kwd":
689:             return (i18n("KDE KWord Document"));
690: 
691:         // Spreadsheet files
692:         case "xls":
693:             return (i18n("Microsoft Excel Worksheet"));
694:         case "sxc":
695:             return (i18n("OpenOffice.org Table"));
696:         case "stc":
697:             return (i18n("OpenOffice.org Table Template"));
698:         case "xlw":
699:             return (i18n("Microsoft Excel File"));
700:         case "xlt":
701:             return (i18n("Microsoft Excel Template"));
702:         case "csv":
703:             return (i18n("Comma Seperated Value File"));
704:         case "ksp":
705:             return (i18n("KDE KSpread Document"));
706:         case "sdc":
707:             return (i18n("StarOffice 5.0 Table"));
708: 
709:         // Text types
710:         case "txt":
711:             return (i18n("Plain Text"));
712:         case "rtf":
713:             return (i18n("Rich Text Format"));
714: 
715:         // Images
716:         case "gif":
717:             return (i18n("GIF Image"));
718:         case "png":
719:             return (i18n("PNG Image"));
720:         case "jpeg":
721:             return (i18n("JPEG Image"));
722:         case "jpg":
723:             return (i18n("JPEG Image"));
724:         case "tif":
725:             return (i18n("TIFF Image"));
726:         case "psd":
727:             return (i18n("Adobe Photoshop Image"));
728: 
729:         // HTML
730:         case "html":
731:             return (i18n("Hypertext Markup Language Document"));
732:         case "htm":
733:             return (i18n("Hypertext Markup Language Document"));
734:         case "css":
735:             return (i18n("Cascading Style Sheets"));
736: 
737:         // Archives
738:         case "lha":
739:             return (i18n("LHA Archive"));
740:         case "rar":
741:             return (i18n("RAR Archive"));
742:         case "arj":
743:             return (i18n("ARJ Archive"));
744:         case "bz2":
745:             return (i18n("bz2-compressed File"));
746:         case "bz":
747:             return (i18n("bzip-compressed File"));
748:         case "zip":
749:             return (i18n("ZIP Archive"));
750:         case "tar":
751:             return (i18n("TAR Archive"));
752:         case "gz":
753:             return (i18n("GZ Compressed File"));
754: 
755:         // Source files
756:         case "c":
757:             return (i18n("C Program Code"));
758:         case "c++":
759:         case "cc":
760:         case "cpp":
761:             return (i18n("C++ Program Code"));
762:         case "hpp":
763:         case "h":
764:             return (i18n("C or C++ Program Header"));
765:         case "php":
766:         case "php3":
767:         case "php4":
768:             return (i18n("PHP Program Code"));
769:         case "phps":
770:             return (i18n("PHP Source File"));
771: 
772:         case "pdf":
773:             return (i18n("Adobe Acrobat Portable Document"));
774: 
775:         // Movies
776:         case "mov":
777:             return (i18n("QuickTime Movie"));
778:         case "avi":
779:             return (i18n("avi Movie"));
780:         case "mpg":
781:         case "mpeg":
782:             return (i18n("MPEG Movie"));
783:         case "wmv":
784:             return (i18n("Windows Media Video"));
785:         case "mp4":
786:             return (i18n("MPEG-4 Movie"));
787: 
788:         default:
789:             return (i18n($sExtension . "-File"));
790:     }
791: }
792: 
793: /**
794:  * Removes unwanted characters from passed filename.
795:  *
796:  * @param string $sFilename
797:  * @return string
798:  */
799: function uplCreateFriendlyName($filename) {
800:     global $cfg, $lang;
801: 
802:     $oLang = new cApiLanguage();
803:     $oLang->loadByPrimaryKey($lang);
804: 
805:     if (!is_array($cfg['upl']['allow_additional_chars'])) {
806:         $filename = str_replace(" ", "_", $filename);
807:     } elseif (in_array(' ', $cfg['upl']['allow_additional_chars']) === FALSE) {
808:         $filename = str_replace(" ", "_", $filename);
809:     }
810: 
811:     $chars = '';
812:     if (is_array($cfg['upl']['allow_additional_chars'])) {
813:         $chars = implode("", $cfg['upl']['allow_additional_chars']);
814:         $chars = str_replace(array(
815:             '-',
816:             '[',
817:             ']'
818:         ), '', $chars);
819:     }
820: 
821:     $filename = cApiStrReplaceDiacritics($filename, strtoupper($oLang->getField('encoding')));
822:     $filename = preg_replace("/[^A-Za-z0-9._\-" . $chars . "]/i", '', $filename);
823: 
824:     return $filename;
825: }
826: 
827: function uplSearch($searchfor) {
828:     $client = cRegistry::getClientId();
829:     $client = cSecurity::toInteger($client);
830:     $lang = cRegistry::getLanguageId();
831:     $lang = cSecurity::toInteger($lang);
832: 
833:     $uploadsColl = new cApiUploadCollection();
834:     $uplMetaColl = new cApiUploadMetaCollection();
835: 
836:     $searchfordb = $uplMetaColl->escape($searchfor);
837: 
838:     $items = array();
839: 
840:     // Search for description, ranking *5
841:     $uplMetaColl->link('cApiUploadCollection');
842:     $uplMetaColl->setWhereGroup('description', 'capiuploadcollection.idclient', $client);
843:     $uplMetaColl->setWhereGroup('description', 'capiuploadmetacollection.idlang', $lang);
844:     $uplMetaColl->setWhereGroup('description', 'capiuploadmetacollection.description', '%' . $searchfordb . '%', 'LIKE');
845:     $uplMetaColl->query();
846:     while (($item = $uplMetaColl->next()) !== false) {
847:         $items[$item->get('idupl')] += (substr_count(strtolower($item->get('description')), strtolower($searchfor)) * 5);
848:     }
849: 
850:     // Search for medianame, ranking *4
851:     $uplMetaColl->resetQuery();
852:     $uplMetaColl->link('cApiUploadCollection');
853:     $uplMetaColl->setWhereGroup('medianame', 'capiuploadcollection.idclient', $client);
854:     $uplMetaColl->setWhereGroup('medianame', 'capiuploadmetacollection.idlang', $lang);
855:     $uplMetaColl->setWhereGroup('medianame', 'capiuploadmetacollection.medianame', '%' . $searchfordb . '%', 'LIKE');
856:     $uplMetaColl->query();
857:     while (($item = $uplMetaColl->next()) !== false) {
858:         $items[$item->get('idupl')] += (substr_count(strtolower($item->get('medianame')), strtolower($searchfor)) * 4);
859:     }
860: 
861:     // Search for file name, ranking +4
862:     $uploadsColl->select("idclient='" . $client . "' AND filename LIKE '%" . $searchfordb . "%'");
863:     while (($item = $uploadsColl->next()) !== false) {
864:         $items[$item->get('idupl')] += 4;
865:     }
866: 
867:     // Search for keywords, ranking *3
868:     $uplMetaColl->resetQuery();
869:     $uplMetaColl->link('cApiUploadCollection');
870:     $uplMetaColl->setWhereGroup('keywords', 'capiuploadcollection.idclient', $client);
871:     $uplMetaColl->setWhereGroup('keywords', 'capiuploadmetacollection.idlang', $lang);
872:     $uplMetaColl->setWhereGroup('keywords', 'capiuploadmetacollection.keywords', '%' . $searchfordb . '%', 'LIKE');
873:     $uplMetaColl->query();
874:     while (($item = $uplMetaColl->next()) !== false) {
875:         $items[$item->get('idupl')] += (substr_count(strtolower($item->get('keywords')), strtolower($searchfor)) * 3);
876:     }
877: 
878:     // Search for copyright, ranking *2
879:     $uplMetaColl->resetQuery();
880:     $uplMetaColl->link('cApiUploadCollection');
881:     $uplMetaColl->setWhereGroup('copyright', 'capiuploadcollection.idclient', $client);
882:     $uplMetaColl->setWhereGroup('copyright', 'capiuploadmetacollection.idlang', $lang);
883:     $uplMetaColl->setWhereGroup('copyright', 'capiuploadmetacollection.copyright', '%' . $searchfordb . '%', 'LIKE');
884:     $uplMetaColl->query();
885:     while (($item = $uplMetaColl->next()) !== false) {
886:         $items[$item->get('idupl')] += (substr_count(strtolower($item->get('copyright')), strtolower($searchfor)) * 2);
887:     }
888: 
889:     // Search for internal_notice, ranking *1
890:     $uplMetaColl->resetQuery();
891:     $uplMetaColl->link('cApiUploadCollection');
892:     $uplMetaColl->setWhereGroup('internal_notice', 'capiuploadcollection.idclient', $client);
893:     $uplMetaColl->setWhereGroup('internal_notice', 'capiuploadmetacollection.idlang', $lang);
894:     $uplMetaColl->setWhereGroup('internal_notice', 'capiuploadmetacollection.internal_notice', '%' . $searchfordb . '%', 'LIKE');
895:     $uplMetaColl->query();
896:     while (($item = $uplMetaColl->next()) !== false) {
897:         $items[$item->get('idupl')] += (substr_count(strtolower($item->get('internal_notice')), strtolower($searchfor)));
898:     }
899: 
900:     return $items;
901: }
902: 
903: /**
904:  * Returns file extension
905:  *
906:  * @param string $sFile
907:  * @return string
908:  */
909: function uplGetFileExtension($sFile) {
910:     // Fetch the dot position
911:     $iDotPosition = strrpos($sFile, '.');
912:     $sExtension = substr($sFile, $iDotPosition + 1);
913:     if (strpos($sExtension, '/') !== false) {
914:         return false;
915:     } else {
916:         return $sExtension;
917:     }
918: }
919: 
920: /**
921:  * Returns list of directory names to exclude e.
922:  * g. from directory listings.
923:  *
924:  * @return array
925:  */
926: function uplGetDirectoriesToExclude() {
927:     static $mDirsToExclude = NULL;
928:     if (isset($mDirsToExclude)) {
929:         return $mDirsToExclude;
930:     }
931: 
932:     $mDirsToExclude = trim(getSystemProperty('system', 'upldirlist-dirstoexclude'));
933:     if ($mDirsToExclude === '') {
934:         $mDirsToExclude = '.,..,.svn,.cvs';
935:         setSystemProperty('system', 'upldirlist-dirstoexclude', $mDirsToExclude);
936:     }
937:     $mDirsToExclude = explode(',', $mDirsToExclude);
938:     foreach ($mDirsToExclude as $pos => $item) {
939:         $mDirsToExclude[$pos] = trim($item);
940:     }
941:     return $mDirsToExclude;
942: }
943: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen