photos.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * GNU Social
  4. * Copyright (C) 2010, Free Software Foundation, Inc.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENCE:
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Widget
  23. * @package GNU Social
  24. * @author Ian Denhardt <ian@zenhack.net>
  25. * @author Sean Corbett <sean@gnu.org>
  26. * @author Max Shinn <trombonechamp@gmail.com>
  27. * @copyright 2010 Free Software Foundation, Inc.
  28. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  29. */
  30. if (!defined('STATUSNET')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR.'/lib/personalgroupnav.php';
  34. class PhotosAction extends Action
  35. {
  36. var $user = null;
  37. function prepare($args)
  38. {
  39. parent::prepare($args);
  40. $args = $this->returnToArgs();
  41. $username = $args[1]['nickname'];
  42. $this->albumid = $args[1]['albumid'];
  43. if (common_valid_profile_tag($username) == 0) {
  44. $this->user = null;
  45. } else {
  46. $this->user = Profile::getKV('nickname', $username);
  47. }
  48. return true;
  49. }
  50. function handle($args)
  51. {
  52. parent::handle($args);
  53. $this->showPage();
  54. }
  55. function title()
  56. {
  57. if (empty($this->user)) {
  58. return _m('No such user.');
  59. } else {
  60. return sprintf(_m("%s's Photos."), $this->user->nickname);
  61. }
  62. }
  63. function showLocalNav()
  64. {
  65. $nav = new PersonalGroupNav($this);
  66. $nav->show();
  67. }
  68. function showResizeImagesBox()
  69. {
  70. $this->elementStart('select', array('onchange' => 'return scalePhotosToSize(this.value)'));
  71. $this->element('option', array('value' => ''), "");
  72. $this->element('option', array('value' => '60'), _("Thumbnail"));
  73. $this->element('option', array('value' => '120'), _("Medium"));
  74. $this->element('option', array('value' => '400'), _("Normal"));
  75. $this->elementEnd('select');
  76. }
  77. function showAlbums()
  78. {
  79. $album = new GNUsocialPhotoAlbum();
  80. $album->profile_id = $this->user->id;
  81. $albums = array();
  82. if (!$album->find()) {
  83. GNUsocialPhotoAlbum::newAlbum($this->user->id, 'Default');
  84. }
  85. $this->elementStart('div', array('class' => 'galleryheader'));
  86. //$this->element('a', array('href' => '#',
  87. // 'onclick' => 'return increasePhotoSize()'), '+');
  88. //$this->raw(' | ');
  89. //$this->element('a', array('href' => '#',
  90. // 'onclick' => 'return decreasePhotoSize()'), '-');
  91. $this->showResizeImagesBox();
  92. $this->elementEnd('div');
  93. while ($album->fetch()) {
  94. $this->elementStart('div', array('class' => 'photocontainer'));
  95. $this->elementStart('a', array('href' => $album->getPageLink()));
  96. $this->element('img', array('src' => $album->getThumbUri(),
  97. 'class' => 'albumingallery'));
  98. $this->elementEnd('a');
  99. $this->element('h3', array(), $album->album_name);
  100. $this->elementEnd('div');
  101. }
  102. }
  103. function showAlbum($album_id)
  104. {
  105. $album = GNUsocialPhotoAlbum::getKV('album_id', $album_id);
  106. if (!$album) {
  107. return;
  108. }
  109. $page = $_GET['pageid'];
  110. if (!filter_var($page, FILTER_VALIDATE_INT)){
  111. $page = 1;
  112. }
  113. $photos = GNUsocialPhoto::getGalleryPage($page, $album->album_id, 9);
  114. $this->elementStart('div', array('class' => 'galleryheader'));
  115. if ($page > 1) {
  116. $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page-1)), 'Previous page');
  117. $this->raw(' | ');
  118. }
  119. if (GNUsocialPhoto::getGalleryPage($page+1, $album->album_id, 9)) {
  120. $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page+1) ), 'Next page');
  121. $this->raw(' | ');
  122. }
  123. //$this->element('a', array('href' => '#',
  124. // 'onclick' => 'return increasePhotoSize()'), '+');
  125. //$this->raw(' | ');
  126. //$this->element('a', array('href' => '#',
  127. // 'onclick' => 'return decreasePhotoSize()'), '-');
  128. //$this->raw(' | ');
  129. $this->showResizeImagesBox();
  130. $this->elementEnd('div');
  131. foreach ($photos as $photo) {
  132. $this->elementStart('a', array('href' => $photo->getPageLink()));
  133. $this->elementStart('div', array('class' => 'photocontainer'));
  134. $this->element('img', array('src' => $photo->thumb_uri,
  135. 'class' => 'photoingallery'));
  136. $this->element('div', array('class' => 'phototitle'), $photo->title);
  137. $this->elementEnd('div');
  138. $this->elementEnd('a');
  139. }
  140. }
  141. function showContent()
  142. {
  143. if (!empty($this->albumid))
  144. $this->showAlbum($this->albumid);
  145. else
  146. $this->showAlbums();
  147. }
  148. }