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.

159 lines
4.9 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. <?php
  2. /**
  3. * @package Widgets
  4. *
  5. * @file Media.php
  6. * This file is part of MOVIM.
  7. *
  8. * @brief The media manager.
  9. *
  10. * @author Timothée Jaussoin <edhelas@gmail.com>
  11. *
  12. * @version 1.0
  13. * @date 07 December 2011
  14. *
  15. * Copyright (C)2010 MOVIM project
  16. *
  17. * See COPYING for licensing information.
  18. */
  19. class Media extends WidgetBase {
  20. function load()
  21. {
  22. $this->addcss('media.css');
  23. $this->addjs('media.js');
  24. if(!is_dir($this->user->userdir) && $this->user->userdir != '') {
  25. mkdir($this->user->userdir);
  26. touch($this->user->userdir.'index.html');
  27. }
  28. $this->registerEvent('media', 'onMediaUploaded');
  29. }
  30. function ajaxRefreshMedia()
  31. {
  32. $html = $this->mainFolder();
  33. RPC::call('movim_fill', 'media', $html);
  34. RPC::commit();
  35. }
  36. function ajaxDeleteItem($name)
  37. {
  38. unlink($this->user->userdir.$name);
  39. $this->ajaxRefreshMedia();
  40. }
  41. function listFiles()
  42. {
  43. $html = '<ul class="thumb">';
  44. foreach($this->user->getDir() as $file) {
  45. $p = new \Picture;
  46. $html .=
  47. '<li style="background-image: url('.$p->get($this->user->userdir.$file, 300).');">
  48. <a href="'.Route::urlize('media', $file).'">
  49. </a>
  50. <div
  51. class="remove"
  52. onclick="'.
  53. $this->genCallAjax(
  54. 'ajaxDeleteItem',
  55. "'".$file."'"
  56. ).'">
  57. x
  58. </div>
  59. </li>
  60. ';
  61. }
  62. $html .= '</ul>';
  63. return $html;
  64. }
  65. function mainFolder()
  66. {
  67. $percent = number_format(($this->user->dirSize()/$this->user->sizelimit)*100, 2);
  68. $html =
  69. $this->listFiles().'
  70. <span class="size"
  71. title="'.sizeToCleanSize($this->user->dirSize()).' '.t('on').' '.sizeToCleanSize($this->user->sizelimit).'"
  72. >'.
  73. $percent.'%
  74. </span>';
  75. return $html;
  76. }
  77. function pictureViewer($f)
  78. {
  79. if(file_exists($this->user->userdir.$f) && getimagesize($this->user->userdir.$f) != 0) {
  80. $er = @exif_read_data($this->user->userdir.$f);
  81. $exif = '';
  82. if($er) {
  83. if(isset($er['FileName']))
  84. $exif .= '<li><span>'.t('Name').'</span>'.$er['FileName'].'</li>';
  85. if(isset($er['COMPUTED']['Width']) && isset($er['COMPUTED']['Height']))
  86. $exif .= '<li><span>'.t('Resolution').'</span>'.$er['COMPUTED']['Width'].'x'.$er['COMPUTED']['Height'].'</li>';
  87. if(isset($er['FileSize']))
  88. $exif .= '<li><span>'.t('Size').'</span>'.sizeToCleanSize($er['FileSize']).'</li>';
  89. if(isset($er['DateTime']))
  90. $exif .= '<li><span>'.t('Date').'</span>'.prepareDate(strtotime($er['DateTime'])).'</li>';
  91. if(isset($er['ISOSpeedRatings']))
  92. $exif .= '<li><span>'.t('ISO').'</span>'.$er['ISOSpeedRatings'].'</li>';
  93. if(isset($er['Model']))
  94. $exif .= '<li><span>'.t('Camera').'</span>'.$er['Model'].'</li>';
  95. if(isset($er['Artist']))
  96. $exif .= '<li><span>'.t('Artist').'</span>'.$er['Artist'].'</li>';
  97. }
  98. $exif .= '<li><span>'.t('Original').'</span><a target="_blank" href="'.$this->user->useruri.$f.'">'.t('Link').'</a></li>';
  99. $html = '
  100. <div class="viewer">
  101. <img src="'.$this->user->useruri.$f.'" style="max-width: '.$er['COMPUTED']['Width'].'px"/>
  102. <div class="exif">
  103. <ul>
  104. '.$exif.'
  105. </ul>
  106. </div>
  107. </div>';
  108. return $html;
  109. }
  110. }
  111. function build()
  112. {
  113. $refresh = $this->genCallAjax('ajaxRefreshMedia');
  114. ?>
  115. <script type="text/javascript">
  116. function refreshMedia() {
  117. <?php echo $refresh; ?>
  118. }
  119. </script>
  120. <?php
  121. if(isset($_GET['f'])) {
  122. ?>
  123. <div class="tabelem" title="<?php echo t('Viewer'); ?>" id="viewer">
  124. <?php echo $this->pictureViewer($_GET['f']); ?>
  125. </div>
  126. <?php
  127. }
  128. ?>
  129. <div class="tabelem" title="<?php echo t('Media'); ?>" id="media">
  130. <?php echo $this->mainFolder(); ?>
  131. <div class="clear"></div>
  132. </div>
  133. <?php
  134. }
  135. }