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