Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.8 KiB

  1. <?php
  2. /**
  3. * @package Friendica\modules
  4. * @subpackage FileBrowser
  5. * @author Fabio Comuni <fabrixxm@kirgroup.com>
  6. */
  7. require_once('include/Photo.php');
  8. /**
  9. * @param App $a
  10. */
  11. function fbrowser_content(App $a) {
  12. if (!local_user()) {
  13. killme();
  14. }
  15. if ($a->argc == 1) {
  16. killme();
  17. }
  18. $template_file = "filebrowser.tpl";
  19. $mode = "";
  20. if (x($_GET,'mode')) {
  21. $mode = "?mode=".$_GET['mode'];
  22. }
  23. switch ($a->argv[1]) {
  24. case "image":
  25. $path = array(array("", t("Photos")));
  26. $albums = false;
  27. $sql_extra = "";
  28. $sql_extra2 = " ORDER BY created DESC LIMIT 0, 10";
  29. if ($a->argc==2){
  30. $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' ",
  31. intval(local_user()),
  32. dbesc('Contact Photos'),
  33. dbesc( t('Contact Photos'))
  34. );
  35. function _map_folder1($el){return array(bin2hex($el['album']),$el['album']);};
  36. $albums = array_map( "_map_folder1" , $albums);
  37. }
  38. $album = "";
  39. if ($a->argc==3){
  40. $album = hex2bin($a->argv[2]);
  41. $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
  42. $sql_extra2 = "";
  43. $path[]=array($a->argv[2], $album);
  44. }
  45. $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
  46. FROM `photo` WHERE `uid` = %d $sql_extra AND `album` != '%s' AND `album` != '%s'
  47. GROUP BY `resource-id` $sql_extra2",
  48. intval(local_user()),
  49. dbesc('Contact Photos'),
  50. dbesc( t('Contact Photos'))
  51. );
  52. function _map_files1($rr){
  53. $a = get_app();
  54. $types = Photo::supportedTypes();
  55. $ext = $types[$rr['type']];
  56. if($a->theme['template_engine'] === 'internal') {
  57. $filename_e = template_escape($rr['filename']);
  58. }
  59. else {
  60. $filename_e = $rr['filename'];
  61. }
  62. // Take the largest picture that is smaller or equal 640 pixels
  63. $p = q("SELECT `scale` FROM `photo` WHERE `resource-id` = '%s' AND `height` <= 640 AND `width` <= 640 ORDER BY `resource-id`, `scale` LIMIT 1",
  64. dbesc($rr['resource-id']));
  65. if ($p)
  66. $scale = $p[0]["scale"];
  67. else
  68. $scale = $rr['loq'];
  69. return array(
  70. App::get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
  71. $filename_e,
  72. App::get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $scale . '.'. $ext
  73. );
  74. }
  75. $files = array_map("_map_files1", $r);
  76. $tpl = get_markup_template($template_file);
  77. $o = replace_macros($tpl, array(
  78. '$type' => 'image',
  79. '$baseurl' => App::get_baseurl(),
  80. '$path' => $path,
  81. '$folders' => $albums,
  82. '$files' => $files,
  83. '$cancel' => t('Cancel'),
  84. '$nickname' => $a->user['nickname'],
  85. ));
  86. break;
  87. case "file":
  88. if ($a->argc==2) {
  89. $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
  90. intval(local_user())
  91. );
  92. function _map_files2($rr){
  93. $a = get_app();
  94. list($m1,$m2) = explode("/",$rr['filetype']);
  95. $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
  96. if ($a->theme['template_engine'] === 'internal') {
  97. $filename_e = template_escape($rr['filename']);
  98. } else {
  99. $filename_e = $rr['filename'];
  100. }
  101. return array( App::get_baseurl() . '/attach/' . $rr['id'], $filename_e, App::get_baseurl() . '/images/icons/16/' . $filetype . '.png');
  102. }
  103. $files = array_map("_map_files2", $files);
  104. $tpl = get_markup_template($template_file);
  105. $o = replace_macros($tpl, array(
  106. '$type' => 'file',
  107. '$baseurl' => App::get_baseurl(),
  108. '$path' => array( array( "", t("Files")) ),
  109. '$folders' => false,
  110. '$files' =>$files,
  111. '$cancel' => t('Cancel'),
  112. '$nickname' => $a->user['nickname'],
  113. ));
  114. }
  115. break;
  116. }
  117. if (x($_GET,'mode')) {
  118. return $o;
  119. } else {
  120. echo $o;
  121. killme();
  122. }
  123. }