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.

155 lines
3.8KB

  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($a){
  12. if (!local_user())
  13. killme();
  14. if ($a->argc==1)
  15. killme();
  16. $template_file = "filebrowser.tpl";
  17. $mode = "";
  18. if (x($_GET,'mode')) {
  19. $template_file = "filebrowser_plain.tpl";
  20. $mode = "?mode=".$_GET['mode'];
  21. }
  22. //echo "<pre>"; var_dump($a->argv); killme();
  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. $a->get_baseurl() . '/photos/' . $a->user['nickname'] . '/image/' . $rr['resource-id'],
  71. $filename_e,
  72. $a->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' => $a->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. }
  99. else {
  100. $filename_e = $rr['filename'];
  101. }
  102. return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png');
  103. }
  104. $files = array_map("_map_files2", $files);
  105. $tpl = get_markup_template($template_file);
  106. $o = replace_macros($tpl, array(
  107. '$type' => 'file',
  108. '$baseurl' => $a->get_baseurl(),
  109. '$path' => array( array( "", t("Files")) ),
  110. '$folders' => false,
  111. '$files' =>$files,
  112. '$cancel' => t('Cancel'),
  113. '$nickname' => $a->user['nickname'],
  114. ));
  115. }
  116. break;
  117. }
  118. if (x($_GET,'mode')) {
  119. return $o;
  120. } else {
  121. echo $o;
  122. killme();
  123. }
  124. }