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