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