Просмотр файла mc-2.7.0/modules/downloads/helpers/downloads_widget.php

Размер файла: 3.39Kb
  1. <?php
  2.  
  3. /**
  4. * MobileCMS
  5. *
  6. * Open source content management system for mobile sites
  7. *
  8. * @author MobileCMS Team <support@mobilecms.pro>
  9. * @copyright Copyright (c) 2011-2019, MobileCMS Team
  10. * @link https://mobilecms.pro Official site
  11. * @license MIT license
  12. */
  13. defined('IN_SYSTEM') or die('<b>403<br />Запрет доступа!</b>');
  14.  
  15. //---------------------------------------------
  16.  
  17. /**
  18. * Виджет загрузок
  19. */
  20. class downloads_widget {
  21.  
  22. /**
  23. * Показ виджета
  24. */
  25. public static function display($widget_id) {
  26. $db = Registry::get('db');
  27. $widget = $db->get_row("SELECT * FROM #__index_page_widgets WHERE widget_id = $widget_id");
  28. $config = parse_ini_string($widget['config']);
  29. if (!is_numeric($config['directory_id']))
  30. return 'Виджет ' . $widget['title'] . ' не настроен, либо настроен не верно!<br />';
  31.  
  32. # Получаем количество файлов в папке
  33. $files = $db->get_row("SELECT COUNT(*) AS all_files, COUNT(CASE WHEN time > UNIX_TIMESTAMP() - 86400 THEN 1 END) AS new_day FROM #__downloads_files WHERE " . ($config['directory_id'] != 0 ? "path_to_file LIKE '%/" . $config['directory_id'] . "/%' AND" : "") . " real_name != '' AND status = 'active'");
  34. return '<img src="' . URL . 'modules/downloads/images/' . ($config['directory_id'] == 0 ? 'downloads' : 'default/directory') . '.png" alt="" /> <a href="' . URL . 'downloads/' . $config['directory_id'] . '">' . $config['directory_name'] . '</a> <span class="count">[' . $files['all_files'] . ']</span>' . ($files['new_day'] > 0 ? ' <span class="new">+' . $files['new_day'] . '</span>' : '') . '<br />';
  35. }
  36.  
  37. /**
  38. * Настройка виджета
  39. */
  40. public static function setup($widget) {
  41. $db = Registry::get('db');
  42. $tpl = Registry::get('tpl');
  43.  
  44. if (isset($_POST['submit'])) {
  45. if ($_POST['directory_id'] != 0 && !$directory = $db->get_row("SELECT directory_id, name FROM #__downloads_directories WHERE directory_id = '" . intval($_POST['directory_id']) . "'")) {
  46. $error .= 'Папка не найдена!<br />';
  47. }
  48.  
  49. if (!$error) {
  50. if ($_POST['directory_id'] == 0)
  51. $directory = array(
  52. 'directory_id' => 0,
  53. 'name' => 'Загрузки'
  54. );
  55.  
  56. $config = 'directory_id = "' . $directory['directory_id'] . '"' . PHP_EOL;
  57. $config .= 'directory_name = "' . a_safe($directory['name']) . '"';
  58.  
  59. $db->query("UPDATE #__index_page_widgets SET
  60. config = '$config'
  61. WHERE widget_id = '" . $widget['widget_id'] . "'
  62. ");
  63.  
  64. a_notice('Изменения сохранены', a_url('index_page/admin'));
  65. }
  66. }
  67. if (!isset($_POST['submit']) OR $error) {
  68. $config = parse_ini_string($widget['config']);
  69.  
  70. $form_data = '
  71. <p>
  72. <label>ID папки (укажите 0 если хотите сослаться на модуль "Загрузки"):</label>
  73. <input name="directory_id" type="text" value="' . $config['directory_id'] . '">
  74. </p>';
  75.  
  76. $tpl->assign(array(
  77. 'form_data' => $form_data,
  78. 'error' => $error
  79. ));
  80.  
  81. $tpl->display('widget_setup');
  82. }
  83. }
  84.  
  85. }
  86.  
  87. ?>