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
    • 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
  • SimpleXMLExtended
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

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