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

/galleries/tags/version 3.0.22beta/admin/index.php

http://bitcero-modules.googlecode.com/
PHP | 175 lines | 128 code | 29 blank | 18 comment | 10 complexity | 9a6793503a70c43c4dfec68399bee2a7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: index.php 706 2011-08-08 22:07:13Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // MyGalleries
  5. // Module for advanced image galleries management
  6. // Author: Eduardo Cort?Šs <i.bitcero@gmail.com>
  7. // Email: i.bitcero@gmail.com
  8. // License: GPL 2.0
  9. // --------------------------------------------------------------
  10. define('RMCLOCATION','dashboard');
  11. include 'header.php';
  12. function count_files($path){
  13. $file_count = 0;
  14. $dir = opendir($path);
  15. while (($file = readdir($dir)) !== false){
  16. if ($file == '.' || $file=='..') continue;
  17. if (is_dir($path . '/'.$file)){
  18. $file_count += count_files($path . '/'.$file);
  19. } else {
  20. $file_count++;
  21. }
  22. }
  23. closedir($dir);
  24. return $file_count;
  25. }
  26. function show_dashboard(){
  27. global $xoopsModuleConfig;
  28. $db = Database::getInstance();
  29. // Sets count
  30. $sql = "SELECT COUNT(*) FROM ".$db->prefix("gs_sets");
  31. list($set_count) = $db->fetchRow($db->query($sql));
  32. // Pictures count
  33. $sql = "SELECT COUNT(*) FROM ".$db->prefix("gs_images");
  34. list($pic_count) = $db->fetchRow($db->query($sql));
  35. // Users count
  36. $sql = "SELECT COUNT(*) FROM ".$db->prefix("gs_users");
  37. list($user_count) = $db->fetchRow($db->query($sql));
  38. // Tags count
  39. $sql = "SELECT COUNT(*) FROM ".$db->prefix("gs_tags");
  40. list($tag_count) = $db->fetchRow($db->query($sql));
  41. // E-Cards count
  42. $sql = "SELECT COUNT(*) FROM ".$db->prefix("gs_postcards");
  43. list($post_count) = $db->fetchRow($db->query($sql));
  44. // Used space
  45. $space = RMUtilities::formatBytesSize(GSFunctions::folderSize($xoopsModuleConfig['storedir']));
  46. // Number of files
  47. $file_count = count_files(rtrim($xoopsModuleConfig['storedir'], '/'));
  48. // First picture
  49. $sql = "SELECT * FROM ".$db->prefix("gs_images")." ORDER BY `created` ASC LIMIT 0,1";
  50. $result = $db->query($sql);
  51. if($db->getRowsNum($result)>0){
  52. $img = new GSImage();
  53. $img->assignVars($db->fetchArray($result));
  54. $user = new GSUser($img->owner(), 1);
  55. $tf = new RMTimeFormatter(0, '%M% %d%, %Y%');
  56. $first_pic['date'] = $tf->format($img->created());
  57. $first_pic['link'] = $user->userURL().($xoopsModuleConfig['urlmode'] ? 'img/'.$img->id().'/set/' : '&amp;img='.$img->id());
  58. }
  59. xoops_cp_header();
  60. GSFunctions::toolbar();
  61. RMTemplate::get()->add_style('dashboard.css','galleries');
  62. RMTemplate::get()->add_style('admin.css','galleries');
  63. RMTemplate::get()->add_head('<script type="text/javascript">var xurl = "'.XOOPS_URL.'";</script>');
  64. RMTemplate::get()->add_local_script('dashboard.js','galleries');
  65. include RMTemplate::get()->get_template('admin/gs_dashboard.php', 'module', 'galleries');
  66. xoops_cp_footer();
  67. }
  68. function send_pictures(){
  69. global $xoopsLogger;
  70. $xoopsLogger->renderingEnabled = false;
  71. error_reporting(0);
  72. $xoopsLogger->activated = false;
  73. $db = Database::getInstance();
  74. $limit = rmc_server_var($_GET, 'limit', 5);
  75. // recent pictures
  76. $sql = "SELECT * FROM ".$db->prefix("gs_images")." ORDER BY `created` DESC LIMIT 0,$limit";
  77. $result = $db->query($sql);
  78. $recents = GSFunctions::process_image_data($result);
  79. ob_start();
  80. ?>
  81. <?php foreach($recents as $pic): ?>
  82. <a href="<?php echo $pic['link']; ?>" target="_blank" title="<?php echo $pic['title']; ?>"><img src="<?php echo $pic['thumbnail']; ?>" alt="<?php echo $pic['title']; ?>" /></a>
  83. <?php endforeach; ?>
  84. <?php
  85. $recents = ob_get_clean();
  86. echo $recents; die();
  87. }
  88. function send_sets(){
  89. global $xoopsLogger, $xoopsModuleConfig;
  90. $xoopsLogger->renderingEnabled = false;
  91. error_reporting(0);
  92. $xoopsLogger->activated = false;
  93. $mc =& $xoopsModuleConfig;
  94. $db = Database::getInstance();
  95. $limit = rmc_server_var($_GET, 'limit', 5);
  96. // recent pictures
  97. $sql = "SELECT * FROM ".$db->prefix("gs_sets")." ORDER BY `date` DESC LIMIT 0,$limit";
  98. $result = $db->query($sql);
  99. $sets = array();
  100. $users = array();
  101. while($row = $db->fetchArray($result)){
  102. $set = new GSSet();
  103. $set->assignVars($row);
  104. $pics = $set->getPics('RAND()');
  105. $img = new GSImage($pics[0]);
  106. if (!isset($users[$img->owner()])) $users[$img->owner()] = new GSUser($img->owner(), 1);
  107. if($img->isNew()){
  108. $image = array(
  109. 'title' => __('Empty album','galleries'),
  110. 'link' => '',
  111. 'thumbnail' => GS_URL.'/images/empty.jpg'
  112. );
  113. } else {
  114. $image = array(
  115. 'title' => $img->title(),
  116. 'link' => $users[$img->owner()]->userURL().($mc['urlmode'] ? 'img/'.$img->id().'/' : '&amp;img='.$img->id()),
  117. 'thumbnail'=>$users[$img->owner()]->filesURL().'/ths/'.$img->image()
  118. );
  119. }
  120. $sets[] = array(
  121. 'title' => $set->title(),
  122. 'link' => $set->url(),
  123. 'image' => $image
  124. );
  125. }
  126. ob_start();
  127. ?>
  128. <?php foreach($sets as $set): ?>
  129. <a href="<?php echo $set['link']; ?>" target="_blank" title="<?php echo $set['title']; ?>"><img src="<?php echo $set['image']['thumbnail']; ?>" alt="<?php echo $set['title']; ?>" /></a>
  130. <?php endforeach; ?>
  131. <?php
  132. $recents = ob_get_clean();
  133. echo $recents; die();
  134. }
  135. $action = rmc_server_var($_REQUEST, 'action', '');
  136. switch($action){
  137. case 'pictures':
  138. send_pictures();
  139. break;
  140. case 'sets':
  141. send_sets();
  142. break;
  143. default:
  144. show_dashboard();
  145. break;
  146. }