PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mediamanager-1.0/configure.php

https://github.com/robertleeplummerjr/bluebox
PHP | 179 lines | 29 code | 1 blank | 149 comment | 0 complexity | ec0501d7fec11b37a49cbb35d48d1182 MD5 | raw file
  1. <?php defined('SYSPATH') or die('No direct access allowed.');
  2. /*
  3. * Bluebox Modular Telephony Software Library / Application
  4. *
  5. * The contents of this file are subject to the Mozilla Public License
  6. * Version 1.1 (the "License"); you may not use this file except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS"
  11. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  12. * License for the specific language governing rights and limitations
  13. * under the License.
  14. *
  15. * The Initial Developer of the Original Code is Darren Schreiber <d@d-man.org> .
  16. *
  17. * Portions created by the Initial Developer are Copyright (C)
  18. * the Initial Developer. All Rights Reserved.
  19. *
  20. * Contributor(s):
  21. *
  22. *
  23. */
  24. /**
  25. * configure.php - Global Media Management System
  26. *
  27. * @author Darren Schreiber <d@d-man.org>
  28. * @license MPL
  29. * @package Bluebox
  30. * @subpackage MediaManager
  31. */
  32. class MediaManager_Configure extends Bluebox_Configure
  33. {
  34. public static $version = 0.1;
  35. public static $packageName = 'mediamanager';
  36. public static $displayName = 'Media Manager';
  37. public static $author = 'Darren Schreiber';
  38. public static $vendor = 'Bluebox';
  39. public static $license = 'MPL';
  40. public static $summary = 'Manage sound/media files on this system. Provides upload/download facilities and allows for managing built-in system files.';
  41. public static $default = TRUE;
  42. public static $type = Package_Manager::TYPE_MODULE;
  43. public static $required = array(
  44. 'core' => 0.1,
  45. 'not' => array('mediafile' => 0.1)
  46. );
  47. public static $navStructures = array(
  48. array(
  49. 'navLabel' => 'Global Media',
  50. 'summary' => 'Modify and maintain media (sound) files for the entire system',
  51. 'navIcon' => 'assets/img/icons/mainToolsX.png',
  52. 'navBranch' => '/Media/',
  53. 'navURL' => '/globalmedia/index',
  54. 'navSubmenu' => array(
  55. 'Upload Audio' => '/globalmedia/add'
  56. )
  57. )/*,
  58. array (
  59. 'navLabel' => 'Custom Media',
  60. 'summary' => 'Modify and maintain media (sound) files for this account',
  61. 'navIcon' => 'assets/img/icons/mainToolsX.png',
  62. 'navBranch' => '/Media/',
  63. 'navURL' => '/accountmedia/index',
  64. 'navSubmenu' => array(
  65. 'Upload Audio' => '/globalmedia/add'
  66. )
  67. )*/
  68. );
  69. /*
  70. public static function _checkDirectory()
  71. {
  72. $upload_dir = rtrim(Kohana::config('upload.directory') , '/') . '/';
  73. // Check if the upload.directory can be written to
  74. if (!filesystem::is_writable($upload_dir)) {
  75. // if the directory exists then produce and error that it isnt writtable
  76. if (is_dir($upload_dir)) return 'The upload directory ' . $upload_dir . ' can not be written to!';
  77. // If the upload directory doesnt exist see if we have permissions one directory up to create it
  78. $pos = strrpos(rtrim(Kohana::config('upload.directory') , '/') , '/');
  79. if ($pos !== false && !filesystem::is_writable(substr($upload_dir, 0, $pos + 1))) return 'The upload directory ' . $upload_dir . ' can not be created!';
  80. else return true;
  81. } else {
  82. return true;
  83. }
  84. }
  85. public static function _checkUploadCapability()
  86. {
  87. **
  88. * These vars configure the error and warning (respectively) threashold
  89. * for file upload parameters. Memory_limit, and post_max_size will
  90. * base their threasholds on these values as well.
  91. *
  92. $min_upload_max_filesize = 2097152;
  93. $recommended_upload_max_filesize = 5242880;
  94. **
  95. * This is the min amount of memory that a script should need,
  96. * used in addtion with min_upload_max_filesize to determine if
  97. * there is enough memory per script
  98. *
  99. $min_script_memory_limit = 5242880;
  100. **
  101. * These are the error and warnign threasholds for
  102. * max_execution_time (in seconds)
  103. *
  104. $min_max_execution_time = 30;
  105. $recommended_max_execution_time = 60;
  106. $issues = array(
  107. 'errors' => false,
  108. 'warnings' => false
  109. );
  110. // Make sure that file uploads are enabled
  111. $file_uploads = ini_get('file_uploads');
  112. if (empty($file_uploads) || $file_uploads === false) $issues['errors'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php', 'file_uploads', array(
  113. 'target' => '_blank'
  114. )) . ' is disabled!';
  115. // Check if we met the upload_max_filesize limit
  116. $upload_max_filesize = self::return_bytes(ini_get('upload_max_filesize'));
  117. if (empty($upload_max_filesize) || (int)$upload_max_filesize < $min_upload_max_filesize) $issues['errors'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize', 'upload_max_filesize', array(
  118. 'target' => '_blank'
  119. )) . ' is bellow ' . self::bytesToMb($min_upload_max_filesize) . '!';
  120. else if ((int)$upload_max_filesize < $recommended_upload_max_filesize) $issues['warnings'][] = 'Recommend setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize', 'upload_max_filesize', array(
  121. 'target' => '_blank'
  122. )) . ' larger than ' . self::bytesToMb($recommended_upload_max_filesize);
  123. // Check if post_max_size is equal to or larger than upload_max_filesize
  124. $post_max_size = self::return_bytes(ini_get('post_max_size'));
  125. if (empty($post_max_size) || (int)$post_max_size < $min_upload_max_filesize) $issues['errors'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php#ini.post-max-size', 'post_max_size ', array(
  126. 'target' => '_blank'
  127. )) . ' is bellow ' . self::bytesToMb($min_upload_max_filesize) . '!';
  128. else if ($post_max_size != '-1' && (int)$post_max_size < $upload_max_filesize) $issues['warnings'][] = 'Recommend setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php#ini.post-max-size', 'post_max_size ', array(
  129. 'target' => '_blank'
  130. )) . ' larger than ' . self::bytesToMb($upload_max_filesize);
  131. // Check if memory limit is acceptable
  132. $memory_limit = self::return_bytes(ini_get('memory_limit'));
  133. if ((empty($memory_limit) || (int)$memory_limit < ($min_upload_max_filesize + $min_script_memory_limit)) && $memory_limit != - 1) $issues['errors'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php#ini.memory-limit', 'memory_limit ', array(
  134. 'target' => '_blank'
  135. )) . ' is bellow ' . self::bytesToMb($min_upload_max_filesize + $min_script_memory_limit) . '!';
  136. else if ($memory_limit != - 1 && (int)$memory_limit < ($recommended_upload_max_filesize + $min_script_memory_limit)) $issues['warnings'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/ini.core.php#ini.memory-limit', 'memory_limit ', array(
  137. 'target' => '_blank'
  138. )) . ' larger than ' . self::bytesToMb($recommended_upload_max_filesize + $min_script_memory_limit);
  139. // Ensure max_execution_time is acceptable
  140. $max_execution_time = ini_get('max_execution_time');
  141. if (empty($max_execution_time) || (int)$max_execution_time < $min_max_execution_time) $issues['errors'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time', 'max_execution_time ', array(
  142. 'target' => '_blank'
  143. )) . ' is bellow ' . $min_max_execution_time . ' sec !';
  144. else if ((int)$max_execution_time < $recommended_max_execution_time) $issues['warnings'][] = 'Recommend setting ' . html::anchor('http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time', 'max_execution_time ', array(
  145. 'target' => '_blank'
  146. )) . ' larger than ' . $recommended_max_execution_time . ' sec';
  147. // Ensure max_input_time is acceptable
  148. $max_input_time = ini_get('max_input_time');
  149. if (empty($max_input_time) || (int)$max_input_time < $min_max_execution_time * 2) $issues['errors'][] = 'PHP setting ' . html::anchor('http://www.php.net/manual/en/info.configuration.php#ini.max_input_time', 'max_input_time ', array(
  150. 'target' => '_blank'
  151. )) . ' is bellow ' . $min_max_execution_time * 2 . ' sec !';
  152. else if ((int)$max_input_time < ($recommended_max_execution_time * 2)) $issues['warnings'][] = 'Recommend setting ' . html::anchor('http://www.php.net/manual/en/info.configuration.php#ini.max_input_time', 'max_input_time ', array(
  153. 'target' => '_blank'
  154. )) . ' larger than ' . $recommended_max_execution_time * 2 . ' sec';
  155. return $issues;
  156. }
  157. private function return_bytes($val)
  158. {
  159. $val = trim($val);
  160. $last = strtolower(substr($val, strlen($val / 1) , 1));
  161. if ($last == 'g') $val = $val * 1024 * 1024 * 1024;
  162. if ($last == 'm') $val = $val * 1024 * 1024;
  163. if ($last == 'k') $val = $val * 1024;
  164. return $val;
  165. }
  166. private function bytesToMb($byte)
  167. {
  168. return $byte / 1048576 . 'Mb';
  169. }*/
  170. }