/administrator/components/com_installer/models/warnings.php

https://github.com/gpongelli/joomla-cms · PHP · 117 lines · 71 code · 13 blank · 33 comment · 12 complexity · 68fc0aa0ce2e668061e89cfc0e04e075 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_installer
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Extension Manager Templates Model
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_installer
  15. * @since 1.6
  16. */
  17. class InstallerModelWarnings extends JModelList
  18. {
  19. /**
  20. * Extension Type
  21. * @var string
  22. */
  23. public $type = 'warnings';
  24. /**
  25. * Return the byte value of a particular string.
  26. *
  27. * @param string String optionally with G, M or K suffix
  28. *
  29. * @return int size in bytes
  30. *
  31. * @since 1.6
  32. */
  33. public function return_bytes($val)
  34. {
  35. $val = trim($val);
  36. $last = strtolower($val{strlen($val) - 1});
  37. switch($last) {
  38. // The 'G' modifier is available since PHP 5.1.0
  39. case 'g':
  40. $val *= 1024;
  41. case 'm':
  42. $val *= 1024;
  43. case 'k':
  44. $val *= 1024;
  45. }
  46. return $val;
  47. }
  48. /**
  49. * Load the data.
  50. *
  51. * @since 1.6
  52. */
  53. public function getItems()
  54. {
  55. static $messages;
  56. if ($messages) {
  57. return $messages;
  58. }
  59. $messages = array();
  60. $file_uploads = ini_get('file_uploads');
  61. if(!$file_uploads)
  62. {
  63. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_FILEUPLOADSDISABLED'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_FILEUPLOADISDISABLEDDESC'));
  64. }
  65. $upload_dir = ini_get('upload_tmp_dir');
  66. if (!$upload_dir) {
  67. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTSET'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTSETDESC'));
  68. } else {
  69. if (!is_writeable($upload_dir)) {
  70. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTWRITEABLE'), 'description' => JText::sprintf('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTWRITEABLEDESC', $upload_dir));
  71. }
  72. }
  73. $config = JFactory::getConfig();
  74. $tmp_path = $config->get('tmp_path');
  75. if (!$tmp_path) {
  76. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTSET'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTSETDESC'));
  77. } else {
  78. if (!is_writeable($tmp_path)) {
  79. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTWRITEABLE'), 'description' => JText::sprintf('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTWRITEABLEDESC', $tmp_path));
  80. }
  81. }
  82. $memory_limit = $this->return_bytes(ini_get('memory_limit'));
  83. if ($memory_limit < (8 * 1024 * 1024)) { // 8MB
  84. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_LOWMEMORYWARN'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_LOWMEMORYDESC'));
  85. } elseif ($memory_limit < (16 * 1024 * 1024)) { //16MB
  86. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_MEDMEMORYWARN'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_MEDMEMORYDESC'));
  87. }
  88. $post_max_size = $this->return_bytes(ini_get('post_max_size'));
  89. $upload_max_filesize = $this->return_bytes(ini_get('upload_max_filesize'));
  90. if ($post_max_size < $upload_max_filesize)
  91. {
  92. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_UPLOADBIGGERTHANPOST'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_UPLOADBIGGERTHANPOSTDESC'));
  93. }
  94. if ($post_max_size < (4 * 1024 * 1024)) // 4MB
  95. {
  96. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_SMALLPOSTSIZE'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_SMALLPOSTSIZEDESC'));
  97. }
  98. if ($upload_max_filesize < (4 * 1024 * 1024)) // 4MB
  99. {
  100. $messages[] = array('message' => JText::_('COM_INSTALLER_MSG_WARNINGS_SMALLUPLOADSIZE'), 'description' => JText::_('COM_INSTALLER_MSG_WARNINGS_SMALLUPLOADSIZEDESC'));
  101. }
  102. return $messages;
  103. }
  104. }