PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/MicroTiny/filepicker.php

https://github.com/tedkulp/cmsmadesimple-2-0
PHP | 176 lines | 144 code | 30 blank | 2 comment | 38 complexity | 183bbf7c29ba089bac503ac0c136b449 MD5 | raw file
  1. <?php
  2. $CMS_ADMIN_PAGE=1;
  3. $path = dirname(dirname(dirname(__FILE__)));
  4. require_once($path . DIRECTORY_SEPARATOR . 'include.php');
  5. $urlext='?'.CMS_SECURE_PARAM_NAME.'='.$_SESSION[CMS_USER_KEY];
  6. check_login(); $userid = get_userid();
  7. $config=&$gCms->GetConfig();
  8. $modules =&$gCms->modules;
  9. $tiny=$modules["MicroTiny"]['object'];
  10. $tiny->curlang=get_preference($userid, 'default_cms_language');
  11. $filepickerstyle=$tiny->GetPreference("filepickerstyle","both");
  12. $tiny->smarty->assign("filepickerstyle",$filepickerstyle);
  13. $tiny->smarty->assign("rooturl",$config["root_url"]);
  14. $tiny->smarty->assign("admindir",$config["admin_dir"]);
  15. $tiny->smarty->assign("filepickertitle",$tiny->Lang("filepickertitle"));
  16. $tiny->smarty->assign("youareintext",$tiny->Lang("youareintext"));
  17. $rootpath=""; $rooturl="";
  18. if ($_GET["type"]=="image") {
  19. $rootpath=$config["image_uploads_path"];
  20. $rooturl=$config["image_uploads_url"];
  21. $tiny->smarty->assign("isimage","1");
  22. } else {
  23. $rootpath=$config["uploads_path"];
  24. $rooturl=$config["uploads_url"];
  25. $tiny->smarty->assign("isimage","0");
  26. }
  27. if (strtolower(substr($rooturl,0,5))=="https") {
  28. $rooturl=substr($rooturl,8); //remove https:/
  29. } else {
  30. $rooturl=substr($rooturl,7); //remove http:/
  31. }
  32. $rooturl=substr($rooturl,strpos($rooturl,"/")); //Remove domain
  33. $subdir="";
  34. if (isset($_GET["subdir"])) $subdir=trim($_GET["subdir"]);
  35. $subdir=str_replace(".","",$subdir); //avoid hacking attempts
  36. if ($subdir!="" && $subdir[0]=="/") $subdir=substr($subdir,1);
  37. $thisdir=$rootpath.'/';
  38. if ($subdir!="") $thisdir.=$subdir."/";
  39. $thisurl=$rooturl.'/';
  40. if ($subdir!="") $thisurl.=$subdir."/";
  41. $tiny->smarty->assign("subdir",$subdir);
  42. function sortfiles($file1,$file2) {
  43. if ($file1["isdir"] && !$file2["isdir"]) return -1;
  44. if (!$file1["isdir"] && $file2["isdir"]) return 1;
  45. return strnatcasecmp($file1["name"],$file2["name"]);
  46. }
  47. $fmmodule=$tiny->GetModuleInstance("FileManager");
  48. $files = Array();
  49. $d = dir($thisdir);
  50. while ($entry = $d->read()) {
  51. if ($entry[0]==".") continue;
  52. if (substr($entry,0,6)=="thumb_") {
  53. if ($tiny->GetPreference("showthumbnailfiles")!="1") {
  54. continue;
  55. }
  56. }
  57. $file=array();
  58. $file["name"]=$entry;
  59. $file["isimage"]="0";
  60. $file["fullpath"]=$thisdir.$entry;
  61. $file["fullurl"]=$thisurl.$entry;
  62. $file["ext"]=strtolower(substr($entry,strrpos($entry,".")));
  63. $file["isdir"]=is_dir($file["fullpath"]);
  64. if (!$file["isdir"]) {
  65. if ($_GET["type"]=="image") {
  66. if ($file["ext"]!=".jpeg" && $file["ext"]!=".jpg" && $file["ext"]!=".gif" && $file["ext"]!=".png") {
  67. continue;
  68. }
  69. // }
  70. // if ($file["ext"]==".jpg" || $file["ext"]==".gif" || $file["ext"]==".png") {
  71. else {
  72. $file["isimage"]="1";
  73. }
  74. if ($filepickerstyle!="filename") {
  75. if ($tiny->GetPreference("showthumbnailfiles")=="1") {
  76. $file["thumbnail"]=$tiny->GetThumbnailFile(str_replace("thumb_","",$entry),$thisdir,$thisurl);
  77. } else {
  78. $file["thumbnail"]=$tiny->GetThumbnailFile($entry,$thisdir,$thisurl);
  79. }
  80. }
  81. $imgsize=@getimagesize($file["fullpath"]);
  82. if ($imgsize) {
  83. $file["dimensions"]=$imgsize[0]."x".$imgsize[1];
  84. } else {
  85. $file["dimensions"]="&nbsp;";
  86. }
  87. }
  88. }
  89. if ($fmmodule) {
  90. $file["fileicon"]=$fmmodule->GetFileIcon($file["ext"],$file["isdir"]);
  91. }
  92. if (!$file["isdir"]) {
  93. $info=@stat($file["fullpath"]);
  94. if ($info) {
  95. $file["size"]=$info["size"];
  96. }
  97. }
  98. $files[]=$file;
  99. }
  100. $d->close();
  101. usort($files,"sortfiles");
  102. $showfiles=array();
  103. if ($subdir!="") {
  104. $onerow = new stdClass();
  105. $onerow->isdir="1";
  106. $onerow->thumbnail="";
  107. $onerow->dimensions="";
  108. $onerow->size="";
  109. $newsubdir=dirname($subdir);
  110. $onerow->namelink="<a href='".$config["root_url"]."/modules/MicroTiny/filepicker.php".$urlext."&amp;type=".$_GET["type"]."&amp;subdir=".$newsubdir."'>[..]</a>\n";
  111. array_push($showfiles, $onerow);
  112. }
  113. $filecount=0;
  114. $dircount=0;
  115. foreach($files as $file) {
  116. $onerow = new stdClass();
  117. $onerow->name=$file["name"];
  118. $onerow->name=$file["name"];
  119. $onerow->fileicon=$file["fileicon"];
  120. if ($file["isdir"]) {
  121. $onerow->isdir="1";
  122. $onerow->namelink="<a href='".$config["root_url"]."/modules/MicroTiny/filepicker.php".$urlext."&amp;type=".$_GET["type"]."&amp;subdir=".$subdir."/".$file["name"]."'>[".$file["name"]."]</a>\n";
  123. $dircount++;
  124. } else {
  125. $onerow->isdir="0";
  126. $onerow->isimage=$file["isimage"];
  127. if (isset($file["thumbnail"])) $onerow->thumbnail=$file["thumbnail"];
  128. $onerow->fullurl=$file["fullurl"];
  129. if (isset($file["dimensions"])) {
  130. $onerow->dimensions=$file["dimensions"];
  131. } else {
  132. $onerow->dimensions="&nbsp;";
  133. }
  134. $onerow->size=number_format($file["size"],0,"",$tiny->Lang("thousanddelimiter"));
  135. $filecount++;
  136. }
  137. array_push($showfiles, $onerow);
  138. }
  139. $tiny->smarty->assign('dircount', $dircount);
  140. $tiny->smarty->assign('filecount', $filecount);
  141. $tiny->smarty->assign('sizetext', $tiny->Lang("size"));
  142. $tiny->smarty->assign('dimensionstext', $tiny->Lang("dimensions"));
  143. $tiny->smarty->assign_by_ref('files', $showfiles);
  144. $tiny->smarty->assign('filescount', count($showfiles));
  145. echo $tiny->ProcessTemplate('filepicker.tpl');
  146. ?>