PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/cpgNGDevel/displayimage.php

https://github.com/cpg-contrib/coppermine
PHP | 347 lines | 158 code | 53 blank | 136 comment | 54 complexity | da932e825335df5713aac4e4627351e9 MD5 | raw file
  1. <?php
  2. /**
  3. * displayimage.php
  4. *
  5. * Script to display images.
  6. *
  7. * This script displays individual image. It also displays the pic info, filmstrip, comments,
  8. * and other related data.
  9. *
  10. * @package cpgNG
  11. * @author Abbas <abbas@sanisoft.com>
  12. * @version $Id$
  13. */
  14. error_reporting(E_ALL);
  15. /**#@+
  16. * Constant to prevent direct execution of config.inc.php
  17. */
  18. define('IN_COPPERMINE', true);
  19. define('DISPLAYIMAGE_PHP', true);
  20. define('INDEX_PHP', true);
  21. define('DB_INPUT_PHP', true);
  22. define('DELETE_PHP', true);
  23. /**#@-*/
  24. /**
  25. * Requires initialization file
  26. */
  27. require('include/init.inc.php');
  28. /**#@+
  29. * Include all the classes
  30. */
  31. require_once('classes/cpgAlbumFactory.class.php');
  32. require_once('classes/cpgTemplate.class.php');
  33. require('classes/cpgDisplayImageData.class.php');
  34. require_once('classes/cpgProcessComments.class.php');
  35. require_once('classes/cpgPluginManager.class.php');
  36. /**#@-*/
  37. /**
  38. * If smilies is enabled then include smilies.inc.php
  39. */
  40. if ($config->conf['enable_smilies']) {
  41. include('include/smilies.inc.php');
  42. }
  43. /**
  44. * Create a new template object
  45. */
  46. $t = cpgTemplate::getInstance();
  47. /**
  48. * Create object of comment class
  49. */
  50. $commentsObj = new cpgProcessComments;
  51. /**
  52. * If comment is set to delete then delete the comment
  53. */
  54. if (isset($_GET['event']) && $_GET['event'] == 'deleteComment' && isset($_GET['msg_id']) && !empty($_GET['msg_id'])) {
  55. $commentsObj->deleteComment((int)$_GET['msg_id']);
  56. }
  57. /**
  58. * If comment is set to update then update the comment
  59. */
  60. else if (isset($_POST['event']) && $_POST['event'] == 'updateComment' && isset($_POST['msg_id']) && !empty($_POST['msg_id'])) {
  61. $commentResult = $commentsObj->updateComment((int)$_POST['msg_id'], $_POST['msg_author'], $_POST['msg_body']);
  62. $t->assign('commentResult', $commentResult);
  63. }
  64. if (isset($_GET['pid'])) {
  65. /**
  66. * @var Integer
  67. * Variable to hold picture id
  68. */
  69. $pid = (int)$_GET['pid'];
  70. } else {
  71. $pid = 0;
  72. }
  73. /**
  74. * This will be set for meta albums and while nevigating the pictures.
  75. * This will have no effect when coming from thumbnails.
  76. */
  77. if (isset($_GET['album']) && !empty($_GET['album'])) {
  78. /**
  79. * @var String/Integer
  80. * Variable to hold albumName/ablbumId
  81. */
  82. $album = $_GET['album'];
  83. }
  84. if (isset($_GET['meta']) && !empty($_GET['meta'])) {
  85. $meta = $_GET['meta'];
  86. }
  87. if (isset($_GET['cat']) && !empty($_GET['cat'])) {
  88. $cat = $_GET['cat'];
  89. }
  90. /**
  91. * If album and meta are not set then get the album from pid
  92. */
  93. if (!$album && !$meta) {
  94. $album = cpgUtils::getAid('pid', $pid);
  95. }
  96. /**
  97. * Create a new album object
  98. */
  99. $albumData = cpgAlbumFactory::getAlbumObj(!empty($meta) ? $meta : $album);
  100. if (isset($_GET['pos'])) {
  101. /**
  102. * @var Integer
  103. * Variable to hold picture position
  104. */
  105. $pos = (int)$_GET['pos'];
  106. }
  107. /**
  108. * Array to store misc data
  109. */
  110. $miscArr = array();
  111. /**
  112. * If comment is posted then add the comment
  113. */
  114. if (isset($_POST['event']) && $_POST['event'] == 'comment') {
  115. $commentResult = $commentsObj->addComment((int)$_POST['pid'], $_POST['msg_author'], $_POST['msg_body']);
  116. $t->assign("commentResult", $commentResult);
  117. }
  118. /**
  119. * Get the breadcrumb data for the current page
  120. */
  121. $breadcrumb = $albumData->getBreadcrumbData ($album, $cat, $meta);
  122. /**
  123. * Get the HTML for the breadcrumb
  124. */
  125. $breadcrumbHTML = $t->getBreadcrumbHTML($breadcrumb);
  126. /**
  127. * Create a new cpgDisplayimage object to get the picture details
  128. */
  129. $imgData = new cpgDisplayImageData;
  130. if (is_int($pos)) {
  131. /**
  132. * Get picture data
  133. */
  134. $data = $albumData->getPicData(!empty($album) ? $album : 0, $picCount, $album_name, $pos, 1, $cat, false, true, $auth->user['uid']);
  135. $imgData->picData = $data[0];
  136. /**
  137. * If total number of pictures comes out to be zero then die
  138. */
  139. if ($picCount == 0) {
  140. cpgUtils::cpgDie(INFORMATION, $lang_errors['no_img_to_display'], __FILE__, __LINE__);
  141. } elseif ($pos >= $picCount) {
  142. $pos = $picCount - 1;
  143. $humanPos = $pos + 1;
  144. $data = $albumData->getPicData(!empty($album) ? $album : 0, $picCount, $album_name, $pos, 1, $cat, false, true, $auth->user['uid']);
  145. $imgData->picData = $data[0];
  146. } elseif ($pid > 0 && $pos >= $picCount) {
  147. $pos = $picCount - 1;
  148. $humanPos = $pos + 1;
  149. }
  150. } elseif ($pid > 0) {
  151. /**
  152. * Now we need the position of this picture in the album.
  153. **/
  154. $allPicData = $albumData->getPicData($album, $picCount, $album_name, -1, -1, $cat, false);
  155. for($pos = 0; $allPicData[$pos]['pid'] != $pid && $pos < $picCount; $pos++);
  156. $imgData->picData = $allPicData[$pos];
  157. $prevPicId = $allPicData[$pos-1]['pid'];
  158. $nextPicId = $allPicData[$pos+1]['pid'];
  159. }
  160. if (!$imgData->picData['pid']) {
  161. cpgUtils::cpgDie(INFORMATION, $lang_errors['no_img_to_display']);
  162. } elseif ($pid == 0) {
  163. $pid = $imgData->picData['pid'];
  164. }
  165. /**
  166. * Retrieve data for the current album
  167. */
  168. if (isset($imgData->picData)) {
  169. $imgData->getAlbumData();
  170. }
  171. /**
  172. * Get the comments for the picture
  173. */
  174. $picComments = $commentsObj->getPicComments($imgData->picData);
  175. if (is_array($picComments)) {
  176. reset($picComments);
  177. $childParent = array();
  178. foreach ($picComments as $cmtId => $cmtDetails) {
  179. $childParent[(int)$cmtId] = (int)$cmtDetails['msg_parent'];
  180. }
  181. reset($childParent);
  182. $commentTree = array();
  183. foreach ($childParent as $k => $v) {
  184. if ($v == 0) {
  185. cpgUtils::buildTree($k, $childParent);
  186. }
  187. }
  188. $t->assign('commentTree', $commentTree);
  189. $referer = urlencode($_SERVER['PHP_SELF'].(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] ? '?'.$_SERVER['QUERY_STRING'] : ''));
  190. $t->assign('referer', $referer);
  191. }
  192. /**
  193. * Show the comment input box if user is allowed to post comments
  194. */
  195. if ($auth->isDefined("USER_CAN_POST_COMMENTS") && $imgData->currentAlbumData['comments'] == 'YES') {
  196. $miscArr['showCommentInput'] = 1;
  197. if ($auth->isDefined("USER_ID")) {
  198. $miscArr['userName'] = $auth->isDefined("USER_NAME");
  199. $miscArr['userStatus'] = 'loggedin';
  200. } else {
  201. $miscArr['userName'] = isset($auth->user['name']) ? strtr($auth->user['name'], $HTML_SUBST) : $lang_display_comments['your_name'];
  202. $miscArr['userStatus'] = 'anon';
  203. }
  204. $miscArr['maxComSize'] = $config->conf['max_com_size'];
  205. $miscArr['enableSmilies'] = $config->conf['enable_smilies'];
  206. }
  207. /**
  208. * Show bbcode help if set in config
  209. */
  210. if ($config->conf['show_bbcode_help']) {
  211. $miscArr['bbcodeHelp'] = cpgUtils::cpgDisplayHelp('f=index.html&base=64&h='.urlencode(base64_encode(serialize($lang_bbcode_help_title.'&nbsp;'))).'&t='.urlencode(base64_encode(serialize($lang_bbcode_help))),470,245);
  212. }
  213. /**
  214. * Decode bbcode from the pic caption
  215. */
  216. $imgData->picData['caption'] = cpgUtils::bbDecode($imgData->picData['caption']);
  217. /**
  218. * Get the picture/file information
  219. */
  220. $picInfo = $imgData->getPicInfo();
  221. /**
  222. * Get the data required to display the picture/file and insert it in $picData array
  223. */
  224. $imgData->getPicHtmlData(!empty($meta) ? $meta : $album);
  225. /**
  226. * Check whether user can rate pictures and display rating box accordingly
  227. */
  228. if (!($auth->isDefined("USER_CAN_RATE_PICTURES") && $imgData->currentAlbumData['votes'] == 'YES')) {
  229. $votes = "";
  230. } else {
  231. $votes = $imgData->picData['votes'] ? sprintf($lang_rate_pic['rating'], round($imgData->picData['pic_rating'] / 2000, 1), $imgData->picData['votes']) : $lang_rate_pic['no_votes'];
  232. }
  233. $imgData->buildLinks(!empty($meta) ? $meta : '', !empty($album) ? $album : '', !empty($cat) ? $cat : '', $pos, $picCount, $nextPicId, $prevPicId);
  234. /**
  235. * Get the film strip data in an array.
  236. */
  237. if ($config->conf['display_film_strip']) {
  238. $filmStrip = $albumData->getFilmStripData(!empty($meta) ? $meta : "", !empty($album) ? $album : "", $pos, $cat);
  239. } else {
  240. $filmStrip = "";
  241. }
  242. // Include plugins for 'displayimage' namespace
  243. cpgPluginManager::invokePlugins('displayimage');
  244. /**
  245. * Get the html for the displaying whole page in a variable
  246. */
  247. $CONTENT = $t->getDisplayImageHTML($imgData->picData, $picCount, $pos, $votes, $picComments, $picInfo, $filmStrip, $miscArr);
  248. $pictureTitle = $imgData->picData['title'] ? $imgData->picData['title'] : strtr(preg_replace("/(.+)\..*?\Z/", "\\1", htmlspecialchars($imgData->picData['filename'])), "_", " ");
  249. /**#@+
  250. * Assign to smarty
  251. */
  252. $t->assign('breadcrumbHTML', $breadcrumbHTML);
  253. $t->assign('CONTENT', $CONTENT);
  254. $t->assign('SUB_TITLE', $album_name.'/'.$pictureTitle);
  255. $t->assign('GALLERY_DESCRIPTION', $config->conf['gallery_description']);
  256. /**#@-*/
  257. /**#@+
  258. * Assign lang array to smarty
  259. */
  260. $t->assign('lang_main_menu', $lang_main_menu);
  261. $t->assign('lang_gallery_admin_menu', $lang_gallery_admin_menu);
  262. /**#@-*/
  263. /**
  264. * Assign user related data
  265. */
  266. if (!$auth->isDefined('USER_ID')) {
  267. $t->assign('loggedin', 0);
  268. } else {
  269. $t->assign('loggedin', 1);
  270. }
  271. /**#@+
  272. * Assign user related data to smarty
  273. */
  274. $t->assign('GALLERY_ADMIN_MODE', GALLERY_ADMIN_MODE);
  275. $t->assign('USER_ADMIN_MODE', USER_ADMIN_MODE);
  276. $t->assign('USER_CAN_CREATE_ALBUMS', $auth->isDefined("USER_CAN_CREATE_ALBUMS"));
  277. $t->assign('USER_IS_ADMIN', $auth->isDefined("USER_IS_ADMIN"));
  278. $t->assign('USER_CAN_UPLOAD_PICTURES', $auth->isDefined("USER_CAN_UPLOAD_PICTURES"));
  279. $t->assign('REFERER', $REFERER);
  280. $t->assign('cat', $cat);
  281. $t->assign('USER_NAME', $auth->isDefined("USER_NAME"));
  282. $t->assign('my_cat_id', FIRST_USER_CAT + $auth->isDefined("USER_ID"));
  283. /**#@-*/
  284. /**
  285. * Cleanup connections, freeze objects in session, set user cookie.
  286. */
  287. include ('include/cleanUp.inc.php');
  288. /**
  289. * Display the common html file
  290. */
  291. $t->display ('main.html');
  292. $time_end = cpgGetMicroTime();
  293. $time = round($time_end - $cpg_time_start, 3);
  294. ?>