Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

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

Functions

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