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