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
    • NavigationMain
    • 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

  • cAjaxRequest
  • cAutoload
  • cBackend
  • cEffectiveSetting
  • cGuiScrollListAlltranslations
  • cHTMLValidator
  • cMailer
  • cModuleFileTranslation
  • cModuleHandler
  • cModuleSearch
  • cModuleSynchronizer
  • cModuleTemplateHandler
  • CodeMirror
  • cPasswordRequest
  • cPermission
  • cRegistry
  • cSystemPurge
  • cSystemtest
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • _processCmsTags
  • addArtspec
  • addslashes_deep
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • endsWith
  • extractNumber
  • generateDisplayFilePath
  • generateInfoButton
  • generateJs
  • getAktuellType
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • modTestModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setHelpContext
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • stripslashes_deep
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • xmlFileToArray
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  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: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: cInclude('includes', 'functions.file.php');
 19: 
 20: 
 21: /**
 22:  * Function reduces long path names and creates a dynamic tooltipp which shows
 23:  * the full path name on mouseover
 24:  *
 25:  * @param string $sDisplayPath Original filepath
 26:  * @param int $iLimit Limit of chars which were displayed directly. If the path
 27:  *        string is shorter there will be no tooltipp
 28:  * @return string Contains short path name and tooltipp if neccessary
 29:  */
 30: function generateDisplayFilePath($sDisplayPath, $iLimit) {
 31:     $sDisplayPath = (string) $sDisplayPath;
 32:     $iLimit = (int) $iLimit;
 33: 
 34:     if (strlen($sDisplayPath) > $iLimit) {
 35:         $sDisplayPathShort = cApiStrTrimHard($sDisplayPath, $iLimit);
 36: 
 37:         $sTooltippString = '';
 38:         $iCharcount = 0;
 39: 
 40:         $aPathFragments = explode('/', $sDisplayPath);
 41: 
 42:         foreach ($aPathFragments as $sFragment) {
 43:             if ($sFragment != '') {
 44:                 if (strlen($sFragment) > ($iLimit - 5)) {
 45:                     $sFragment = cApiStrTrimHard($sFragment, $iLimit);
 46:                 }
 47: 
 48:                 if ($iCharcount + strlen($sFragment) + 1 > $iLimit) {
 49:                     $sTooltippString .= '<br>' . $sFragment . '/';
 50:                     $iCharcount = strlen($sFragment);
 51:                 } else {
 52:                     $iCharcount = $iCharcount + 1 + strlen($sFragment);
 53:                     $sTooltippString .= $sFragment . '/';
 54:                 }
 55:             }
 56:         }
 57: 
 58:         $sDisplayPath = '<span title="' . $sTooltippString . '" class="tooltip">' . $sDisplayPathShort . '</span>';
 59:     }
 60:     return $sDisplayPath;
 61: }
 62: 
 63: /**
 64:  * Returns array structure of passed directory.
 65:  * Parses the directory recursively and
 66:  * collects informations about found subdirectories.
 67:  *
 68:  * @param string $sCurrentDir Directory to parse
 69:  * @param string $sStartDir Start directory. Will be used by recursion.
 70:  * @param array $aFiles Files array structure. Will be used by recursion.
 71:  * @param int $iDepth Nesting depth of found files. Will be used by recursion.
 72:  * @param string $sPathString Path used to create full path to files. Will be
 73:  *        used by recursion.
 74:  * @return array Indexed arraay containing assoziative directory informations
 75:  */
 76: function uplDirectoryListRecursive($sCurrentDir, $sStartDir = '', $aFiles = array(), $iDepth = -1, $sPathString = '') {
 77:     $iDepth++;
 78: 
 79:     $aDirsToExclude = uplGetDirectoriesToExclude();
 80: 
 81:     // remember where we started from
 82:     if (empty($sStartDir)) {
 83:         $sStartDir = $sCurrentDir;
 84:     }
 85: 
 86:     if (chdir($sCurrentDir) == false) {
 87:         return $aFiles;
 88:     }
 89:     $hDir = opendir('.');
 90: 
 91:     // list the files in the dir
 92:     $aCurrentFiles = array();
 93:     while (false !== ($file = readdir($hDir))) {
 94:     //foreach(cDirHandler::read('.',false,true) as $key => $file){
 95:         if (is_dir($file) && !in_array(strtolower($file), $aDirsToExclude)) {
 96:             $aCurrentFiles[] = $file;
 97:         }
 98:     }
 99:     sort($aCurrentFiles);
100: 
101:     foreach ($aCurrentFiles as $file) {
102:         $sFilePathName = getcwd() . '/' . $file;
103:         if ((filetype($sFilePathName) == 'dir') && (opendir($sFilePathName) !== false)) {
104:             $_aFile = array(
105:                 'name' => $file,
106:                 'depth' => $iDepth,
107:                 'pathstring' => $sPathString . $file . '/'
108:             );
109: 
110:             $aFiles[] = $_aFile;
111: 
112:             $aFiles = uplDirectoryListRecursive($sFilePathName, getcwd(), $aFiles, $iDepth, $_aFile['pathstring']);
113:         }
114:     }
115: 
116:     closedir($hDir);
117:     chdir($sStartDir);
118:     return $aFiles;
119: }
120: 
121: /**
122:  * Checks if passed upload directory contains at least one file or directory
123:  *
124:  * @param string $sDir
125:  * @return bool
126:  * @todo Function name is misleading, should be renamed to uplIsEmpty
127:  */
128: function uplHasFiles($sDir) {
129:     global $client, $cfgClient;
130: 
131:     if (!$hDir = @opendir($cfgClient[$client]['upl']['path'] . $sDir)) {
132:         return false;
133:     }
134: 
135:     $bHasContent = false;
136:     if(is_dir($cfgClient[$client]['upl']['path'] . $sDir)){
137:     while (false !== ($sDirEntry = readdir($hDir))) {
138:         if ($sDirEntry != '.' && $sDirEntry != '..') {
139:             $bHasContent = true;
140:             break;
141:         }
142:     }
143:     closedir($hDir);
144:     }
145:     return $bHasContent;
146: }
147: 
148: /**
149:  * Checks if passed upload directory contains at least one directory
150:  *
151:  * @param string $sDir
152:  * @return bool
153:  */
154: function uplHasSubdirs($sDir) {
155:     global $client, $cfgClient;
156: 
157:     if (!$hDir = @opendir($cfgClient[$client]['upl']['path'] . $sDir)) {
158:         return true;
159:     }
160: 
161:     $bHasSubdir = false;
162:     if(is_dir($cfgClient[$client]['upl']['path'] . $sDir)){
163:     while (false !== ($sDirEntry = readdir($hDir))) {
164:         if ($sDirEntry != '.' && $sDirEntry != '..') {
165:             if (is_dir($cfgClient[$client]['upl']['path'] . $sDir . $sDirEntry)) {
166:                 $bHasSubdir = true;
167:                 break;
168:             }
169:         }
170:     }
171:     closedir($hDir);
172:     }
173: 
174:     return $bHasSubdir;
175: }
176: 
177: /**
178:  * Sync database contents with directory and vice versa.
179:  * - Removes all db entries pointing to non existing directories
180:  * - Removes all db entries pointing to non existing upload files
181:  * - Syncs found files in passed path with the database
182:  *
183:  * @param string $sPath Specifies the path to scan
184:  */
185: function uplSyncDirectory($sPath) {
186:     global $cfgClient, $client, $cfg, $db;
187: 
188:     if (cApiDbfs::isDbfs($sPath)) {
189:         return uplSyncDirectoryDBFS($sPath);
190:     }
191: 
192:     $oUploadsColl = new cApiUploadCollection();
193: 
194:     // get current upload directory, it's subdirectories and remove all database
195:     // entries pointing to a non existing upload directory on the file system
196:     $sql = 'SELECT DISTINCT(dirname) AS dirname FROM ' . $cfg['tab']['upl'] . ' WHERE ' . 'idclient=' . (int) $client . ' AND dirname LIKE "' . $db->escape($sPath) . '%"';
197:     $db->query($sql);
198:     while ($db->nextRecord()) {
199:         $sCurrDirname = $db->f('dirname');
200:         $sSubDir = substr($sCurrDirname, strlen($sPath));
201:         if (substr_count($sSubDir, '/') <= 1 && !cApiDbfs::isDbfs($sCurrDirname)) {
202:             // subdirectory is a direct descendant, process this directory too
203:             $sFullPath = $cfgClient[$client]['upl']['path'] . $sCurrDirname;
204:             if (!is_dir($sFullPath)) {
205:                 $oUploadsColl->deleteByDirname($sCurrDirname);
206:             }
207:         }
208:     }
209: 
210:     // delete all db entries related to current directory without existing file
211:     // on file system
212:     $oUploadsColl->select("dirname='" . $oUploadsColl->escape($sPath) . "' AND idclient=" . (int) $client);
213:     while (($oUpload = $oUploadsColl->next()) !== false) {
214:         if (!cFileHandler::exists($cfgClient[$client]['upl']['path'] . $oUpload->get('dirname') . $oUpload->get('filename'))) {
215:             $oUploadsColl->delete($oUpload->get('idupl'));
216:         }
217:     }
218: 
219:     // sync all files in current directory with database
220:     $sFullPath = $cfgClient[$client]['upl']['path'] . $sPath;
221:     if (is_dir($sFullPath)) {
222:         $aDirsToExclude = uplGetDirectoriesToExclude();
223:         if (($hDir = opendir($sFullPath)) !== false) {
224:             while (false !== ($file = readdir($hDir))) {
225:             //foreach(cDirHandler::read($sDirectory,false,true) as $key => $file){
226:                 if (!in_array(strtolower($file), $aDirsToExclude)) {
227:                     if (is_file($sFullPath . $file)) {
228:                         $oUploadsColl->sync($sPath, $file);
229:                     }
230:                 }
231:             }
232:             closedir($hDir);
233:         }
234:     }
235: }
236: 
237: /**
238:  * Sync database contents with DBFS
239:  *
240:  * @param string $sPath Specifies the path to scan
241:  */
242: function uplSyncDirectoryDBFS($sPath) {
243:     global $cfgClient, $client, $cfg, $db;
244: 
245:     $oUploadsColl = new cApiUploadCollection();
246:     $oPropertiesColl = new cApiPropertyCollection();
247:     $oDBFSColl = new cApiDbfsCollection();
248: 
249:     if ($oDBFSColl->dir_exists($sPath)) {
250:         $sStripPath = cApiDbfs::stripPath($sPath);
251:         $oDBFSColl->select("dirname = '$sStripPath'");
252:         while (($oFile = $oDBFSColl->next()) !== false) {
253:             if ($oFile->get('filename') != '.') {
254:                 $oUploadsColl->sync($sPath . "/", $oFile->get('filename'));
255:             }
256:         }
257:     }
258: 
259:     $oUploadsColl->select("dirname='$sPath/' AND idclient='$client'");
260:     while (($oUpload = $oUploadsColl->next()) !== false) {
261:         if (!$oDBFSColl->file_exists($oUpload->get('dirname') . $oUpload->get('filename'))) {
262:             $oUploadsColl->delete($oUpload->get("idupl"));
263:         }
264:     }
265: 
266:     $oPropertiesColl->select("idclient='$client' AND itemtype='upload' AND type='file' AND itemid LIKE '" . $sPath . "%'");
267:     while (($oProperty = $oPropertiesColl->next()) !== false) {
268:         if (!$oDBFSColl->file_exists($oProperty->get('itemid'))) {
269:             $oPropertiesColl->delete($oProperty->get('idproperty'));
270:         }
271:     }
272: 
273:     return;
274: }
275: 
276: /**
277:  * Creates a upload directory, either in filesystem or in dbfs.
278:  *
279:  * @param string $sPath Path to directory to create, either path from client
280:  *        upload
281:  *        directory or a dbfs path
282:  * @param string $sName Name of directory to create
283:  * @param string|void Octal value of filemode as string ('0702') or nothing
284:  */
285: function uplmkdir($sPath, $sName) {
286:     global $cfgClient, $client, $action;
287: 
288:     if (cApiDbfs::isDbfs($sPath)) {
289:         $sPath = cApiDbfs::stripPath($sPath);
290:         $sFullPath = $sPath . '/' . $sName . '/.';
291: 
292:         $dbfs = new cApiDbfsCollection();
293:         $dbfs->create($sFullPath);
294:         return;
295:     }
296: 
297:     $sName = uplCreateFriendlyName($sName);
298:     $sName = strtr($sName, "'", '.');
299:     if (cFileHandler::exists($cfgClient[$client]['upl']['path'] . $sPath . $sName)) {
300:         $action = 'upl_mkdir';
301:         return '0702';
302:     } else {
303:         $oldumask = umask(0);
304:         @mkdir($cfgClient[$client]['upl']['path'] . $sPath . $sName, 0775);
305:         umask($oldumask);
306:     }
307: }
308: 
309: /**
310:  * Renames a upload directory, updates all found upoad files containing the old
311:  * directory name and updates also all entries in propertoes table related to
312:  * affected upload files.
313:  *
314:  * @param string $sOldName
315:  * @param string $sNewName
316:  * @param string $sParent
317:  * @throws cException if the upload path can not be renamed
318:  */
319: function uplRenameDirectory($sOldName, $sNewName, $sParent) {
320:     global $cfgClient, $client, $cfg, $db;
321: 
322:     // rename directory
323:     $sOldUplPath = $cfgClient[$client]['upl']['path'] . $sParent . $sOldName;
324:     $sNewUplPath = $cfgClient[$client]['upl']['path'] . $sParent . $sNewName . '/';
325:     if (!$bResult = rename($sOldUplPath, $sNewUplPath)) {
326:         throw new cException("Couldn't rename upload path {$sOldUplPath} to {$sNewUplPath}");
327:     }
328: 
329:     // fetch all directory strings starting with the old path, and replace them
330:     // with the new path
331:     $oUploadColl = new cApiUploadCollection();
332:     $oUploadColl->select("idclient=" . (int) $client . " AND dirname LIKE '" . $oUploadColl->escape($sParent . $sOldName) . "%'");
333:     while (($oUpload = $oUploadColl->next()) !== false) {
334:         $sDirName = $oUpload->get('dirname');
335:         $sJunk = substr($sDirName, strlen($sParent) + strlen($sOldName));
336:         $sNewName2 = $sParent . $sNewName . $sJunk;
337:         $oUpload->set('dirname', $oUpload->escape($sNewName2), false);
338:         $oUpload->store();
339:     }
340: 
341:     // update all upload item properties starting with the old path, replace
342:     // itemid with the new path
343:     $oPropertyColl = new cApiPropertyCollection();
344:     $oPropertyColl->select("idclient=" . (int) $client . " AND itemtype='upload' AND type='file' AND itemid LIKE '" . $oPropertyColl->escape($sParent . $sOldName) . "%'");
345:     while (($oProperty = $oPropertyColl->next()) !== false) {
346:         $sDirName = $oProperty->get('itemid');
347:         $sJunk = substr($sDirName, strlen($sParent) + strlen($sOldName));
348:         $sNewName2 = $sParent . $sNewName . $sJunk;
349:         $oProperty->set('itemid', $oProperty->escape($sNewName2), false);
350:         $oProperty->store();
351:     }
352: }
353: 
354: /**
355:  * Parses passed directory recursively and stores some properties in TreeItem
356:  *
357:  * @param string $sDirectory
358:  * @param TreeItem $oRootItem
359:  * @param int $iLevel
360:  * @param string $sParent
361:  * @param int $iRenameLevel
362:  * @return array List of invalid directories
363:  */
364: function uplRecursiveDirectoryList($sDirectory, TreeItem $oRootItem, $iLevel, $sParent = '', $iRenameLevel = 0) {
365:     $aInvalidDirectories = array();
366: 
367:     $hDir = @opendir($sDirectory);
368: 
369:     if ($hDir) {
370:         $aDirsToExclude = uplGetDirectoriesToExclude();
371: 
372:         $aFiles = array();
373: 
374:         // list the files in the dir
375:         foreach(cDirHandler::read($sDirectory,false,true) as $key => $file){
376:         //while (false !== ($file = readdir($hDir))) {
377:             if (!in_array(strtolower($file), $aDirsToExclude)) {
378:                 if (@chdir($sDirectory . $file . '/')) {
379:                     if (uplCreateFriendlyName($file) == $file) {
380:                         $aFiles[] = $file;
381:                     } else {
382:                         if ($_GET['force_rename'] == 'true') {
383:                             if ($iRenameLevel == 0 || $iRenameLevel == $iLevel) {
384:                                 uplRenameDirectory($file, uplCreateFriendlyName($file), $sParent);
385:                                 $iRenameLevel = $iLevel;
386:                                 $aFiles[] = uplCreateFriendlyName($file);
387:                             } else {
388:                                 $aInvalidDirectories[] = $file;
389:                             }
390:                         } else {
391:                             $aInvalidDirectories[] = $file;
392:                         }
393:                     }
394:                 }
395:             }
396:         }
397: 
398:         sort($aFiles);
399:         foreach ($aFiles as $key => $file) {
400:             $oItem = new TreeItem($file, $sDirectory . $file . '/', true);
401:             $oItem->custom['level'] = $iLevel;
402:             $oItem->custom['lastitem'] = ($key == count($aFiles) - 1);
403:             $oItem->custom['parent'] = $sDirectory;
404: 
405:             $oRootItem->addItem($oItem);
406:             $aArrayTemp = uplRecursiveDirectoryList($sDirectory . $file . '/', $oItem, $iLevel + 1, $sParent . $file . '/', $iRenameLevel);
407:             $aInvalidDirectories = array_merge($aInvalidDirectories, $aArrayTemp);
408:             unset($oItem);
409:         }
410: 
411:         closedir($hDir);
412:     }
413: 
414:     return $aInvalidDirectories;
415: }
416: 
417: /**
418:  * Collects informations about all available dbfs directories stored in TreeItem
419:  *
420:  * @param string $directory Not used at te moment!
421:  * @param TreeItem $oRootItem
422:  * @param int $level Not used at te moment!
423:  */
424: function uplRecursiveDBDirectoryList($directory, TreeItem $oRootItem, $level, $client) {
425:     $dbfs = new cApiDbfsCollection();
426:     $dbfs->select("filename = '.' AND idclient=" . cSecurity::toInteger($client), 'dirname', 'dirname ASC');
427:     $count = 0;
428:     $lastlevel = 0;
429:     $item['.'] = $oRootItem;
430: 
431:     $prevobj = array(); // TODO: what was this array supposed to be?
432:     $lprevobj = new stdClass(); // TODO: what was this object supposed to be?
433: 
434:     while (($dbitem = $dbfs->next()) !== false) {
435:         $dirname = $dbitem->get('dirname');
436:         $level = substr_count($dirname, '/') + 2;
437:         $file = basename($dbitem->get('dirname'));
438:         $parent = dirname($dbitem->get('dirname'));
439: 
440:         if ($dirname != '.' && $file != '.') {
441:             $item[$dirname] = new TreeItem($file, 'dbfs:/' . $dirname, true);
442:             $item[$dirname]->custom['level'] = $level;
443:             $item[$dirname]->custom['parent'] = $parent;
444:             $item[$dirname]->custom['lastitem'] = true;
445: 
446:             if ($prevobj[$level]->custom['level'] == $level) {
447:                 if (is_object($prevobj[$level])) {
448:                     $prevobj[$level]->custom['lastitem'] = false;
449:                 }
450:             }
451: 
452:             if ($lastlevel > $level) {
453:                 unset($prevobj[$lastlevel]);
454:                 $lprevobj->custom['lastitem'] = true;
455:             }
456: 
457:             $prevobj[$level] = $item[$dirname];
458:             $lprevobj = $item[$dirname];
459: 
460:             $lastlevel = $level;
461: 
462:             if (is_object($item[$parent])) {
463:                 $item[$parent]->addItem($item[$dirname]);
464:             }
465: 
466:             $count++;
467:         }
468:     }
469: }
470: 
471: /**
472:  * Returns thumbnail for a specific upload file
473:  *
474:  * @param string $sFile Filename to retrieve the thumbnail for
475:  * @param int $iMaxSize Thumb dimension (size of with and heigth)
476:  * @return string
477:  */
478: function uplGetThumbnail($sFile, $iMaxSize) {
479:     global $client, $cfgClient;
480: 
481:     if ($iMaxSize == -1) {
482:         return uplGetFileIcon($sFile);
483:     }
484: 
485:     $sFileType = strtolower(getFileType($sFile));
486: 
487:     switch ($sFileType) {
488:         case "png":
489:         case "gif":
490:         case "tiff":
491:         case "tif":
492:         case "bmp":
493:         case "jpeg":
494:         case "jpg":
495:         case "bmp":
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.0 API documentation generated by ApiGen 2.8.0