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