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.

142 lines
3.6 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($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($a->get_baseurl()."/fbrowser/image/".$mode, 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 ",
  31. intval(local_user())
  32. );
  33. // anon functions only from 5.3.0... meglio tardi che mai..
  34. $folder1 = function($el) use ($mode) {return array(bin2hex($el['album']).$mode,$el['album']);};
  35. $albums = array_map( $folder1 , $albums);
  36. }
  37. $album = "";
  38. if ($a->argc==3){
  39. $album = hex2bin($a->argv[2]);
  40. $sql_extra = sprintf("AND `album` = '%s' ",dbesc($album));
  41. $sql_extra2 = "";
  42. $path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/".$mode, $album);
  43. }
  44. $r = q("SELECT `resource-id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc`
  45. FROM `photo` WHERE `uid` = %d AND (height <= 320 AND width <= 320) $sql_extra
  46. GROUP BY `resource-id` $sql_extra2",
  47. intval(local_user())
  48. );
  49. function files1($rr){
  50. global $a;
  51. $types = Photo::supportedTypes();
  52. $ext = $types[$rr['type']];
  53. if($a->theme['template_engine'] === 'internal') {
  54. $filename_e = template_escape($rr['filename']);
  55. }
  56. else {
  57. $filename_e = $rr['filename'];
  58. }
  59. return array(
  60. $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['hiq'] . '.' .$ext,
  61. $filename_e,
  62. $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['loq'] . '.'. $ext
  63. );
  64. }
  65. $files = array_map("files1", $r);
  66. $tpl = get_markup_template($template_file);
  67. $o = replace_macros($tpl, array(
  68. '$type' => 'image',
  69. '$baseurl' => $a->get_baseurl(),
  70. '$path' => $path,
  71. '$folders' => $albums,
  72. '$files' =>$files,
  73. '$cancel' => t('Cancel'),
  74. '$nickname' => $a->user['nickname'],
  75. ));
  76. break;
  77. case "file":
  78. if ($a->argc==2){
  79. $files = q("SELECT id, filename, filetype FROM `attach` WHERE `uid` = %d ",
  80. intval(local_user())
  81. );
  82. function files2($rr){ global $a;
  83. list($m1,$m2) = explode("/",$rr['filetype']);
  84. $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
  85. if($a->theme['template_engine'] === 'internal') {
  86. $filename_e = template_escape($rr['filename']);
  87. }
  88. else {
  89. $filename_e = $rr['filename'];
  90. }
  91. return array( $a->get_baseurl() . '/attach/' . $rr['id'], $filename_e, $a->get_baseurl() . '/images/icons/16/' . $filetype . '.png');
  92. }
  93. $files = array_map("files2", $files);
  94. //echo "<pre>"; var_dump($files); killme();
  95. $tpl = get_markup_template($template_file);
  96. $o = replace_macros($tpl, array(
  97. '$type' => 'file',
  98. '$baseurl' => $a->get_baseurl(),
  99. '$path' => array( array($a->get_baseurl()."/fbrowser/file/", t("Files")) ),
  100. '$folders' => false,
  101. '$files' =>$files,
  102. '$cancel' => t('Cancel'),
  103. '$nickname' => $a->user['nickname'],
  104. ));
  105. }
  106. break;
  107. }
  108. if (x($_GET,'mode')) {
  109. return $o;
  110. } else {
  111. echo $o;
  112. killme();
  113. }
  114. }