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