PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/php/lib/Gloo/Config.php

http://webgloo.googlecode.com/
PHP | 216 lines | 155 code | 48 blank | 13 comment | 14 complexity | d05073dc48702ad60d36910963f7d1ae MD5 | raw file
  1. <?php
  2. /*
  3. *
  4. * configuration items for gloo v2
  5. * PHP singleton implementation need not be thread safe!
  6. * I do not think there is even the concept of thread safe in PHP!
  7. *
  8. *
  9. *
  10. */
  11. class Gloo_Config {
  12. static private $instance = NULL;
  13. private $ini_array;
  14. private $isIndigloo ;
  15. static function getInstance() {
  16. if (self::$instance == NULL) {
  17. self::$instance = new Gloo_Config();
  18. }
  19. return self::$instance;
  20. }
  21. function __construct() {
  22. $iniFile = $_SERVER['GLOO_CONFIG_DIR'] . '/gloo_config.ini';
  23. file_exists($iniFile) || die("unable to open gloo_config.ini file ");
  24. // create config object
  25. $this->ini_array = parse_ini_file($iniFile);
  26. $host = $_SERVER["HTTP_HOST"];
  27. $host = strtolower($host);
  28. $pos = strpos($host,"indigloo.com");
  29. $this->isIndigloo = ($pos === false) ? false : true ;
  30. }
  31. function isRequired($name, $value) {
  32. if (empty($value)) {
  33. trigger_error("Default $name is empty in config", E_USER_ERROR);
  34. }
  35. return $value;
  36. }
  37. function __destruct() {
  38. }
  39. function mysql_host() {
  40. $host = ($this->isIndigloo)? $this->ini_array['mysql.indigloo.host'] : $this->ini_array['mysql.host'] ;
  41. return $host;
  42. }
  43. function mysql_db() {
  44. $db = ($this->isIndigloo)? $this->ini_array['mysql.indigloo.database'] : $this->ini_array['mysql.database'] ;
  45. return $db;
  46. }
  47. function mysql_user() {
  48. $user = ($this->isIndigloo)? $this->ini_array['mysql.indigloo.user'] : $this->ini_array['mysql.user'] ;
  49. return $user;
  50. }
  51. function mysql_password() {
  52. $password = ($this->isIndigloo)? $this->ini_array['mysql.indigloo.password'] : $this->ini_array['mysql.password'] ;
  53. return $password;
  54. }
  55. function is_debug() {
  56. $val = $this->ini_array['debug.mode'];
  57. if (intval($val) == 1) {
  58. return true;
  59. } else {
  60. return false;
  61. }
  62. }
  63. function log_level() {
  64. return $this->ini_array['log.level'];
  65. }
  66. function system_page_records() {
  67. return $this->ini_array['system.page.records'];
  68. }
  69. function max_file_size() {
  70. return $this->ini_array['max.file.size'];
  71. }
  72. function max_foto_size() {
  73. return $this->ini_array['max.foto.size'];
  74. }
  75. function thumbnail_width() {
  76. return $this->ini_array['thumbnail.width'];
  77. }
  78. function thumbnail_height() {
  79. return $this->ini_array['thumbnail.height'];
  80. }
  81. function aws_bucket() {
  82. return $this->ini_array['aws.bucket'];
  83. }
  84. function aws_access_key() {
  85. return $this->ini_array['aws.access.key'];
  86. }
  87. function aws_secret_key() {
  88. return $this->ini_array['aws.secret.key'];
  89. }
  90. function image_404_uri() {
  91. return $this->ini_array['image.404.uri'];
  92. }
  93. function thumbnail_404_uri() {
  94. return $this->ini_array['thumbnail.404.uri'];
  95. }
  96. function hasSmtpServer() {
  97. $val = $this->ini_array['smtp.provider'];
  98. // php === operator does a type check as well
  99. // php == will convert type before check and we do not want that
  100. if(empty($val) || ($val === 'Off') || ($val === 'off'))
  101. return false ;
  102. else
  103. return true ;
  104. }
  105. function smtp_host() {
  106. if($this->hasSmtpServer())
  107. return $this->ini_array['smtp.host'];
  108. else
  109. trigger_error('smtp.server config flag is set to Off',E_USER_ERROR);
  110. }
  111. function smtp_port() {
  112. return $this->ini_array['smtp.port'];
  113. }
  114. function smtp_user() {
  115. return $this->ini_array['smtp.user'];
  116. }
  117. function smtp_password() {
  118. $password = $this->ini_array['smtp.password'];
  119. $password = Gloo_Util::base64Decrypt($password);
  120. return $password;
  121. }
  122. function default_theme() {
  123. $theme = $this->isRequired('Theme', $this->ini_array['default.theme']);
  124. return $theme;
  125. }
  126. function log_location() {
  127. return $this->ini_array['log.location'];
  128. }
  129. //farm specific messages
  130. function getFarmName() {
  131. return $this->ini_array['farm.name'];
  132. }
  133. function getFarmDomain() {
  134. return $this->ini_array['farm.domain'];
  135. }
  136. function getFarmURI() {
  137. return $this->ini_array['farm.uri'];
  138. }
  139. function getFarmAdminEmail() {
  140. return $this->ini_array['farm.admin.email'];
  141. }
  142. function getFarmBuilderName() {
  143. return $this->ini_array['farm.builder.name'];
  144. }
  145. function getFarmLogoPath() {
  146. return $this->ini_array['farm.logo.path'];
  147. }
  148. function getFarmOrganizationId() {
  149. return $this->ini_array['farm.organization.id'];
  150. }
  151. function getFarmOrganizationDomain() {
  152. return $this->ini_array['farm.organization.domain'];
  153. }
  154. function getFarmNewSiteDomain() {
  155. return $this->ini_array['farm.new.site.domain'];
  156. }
  157. function isLocalStore() {
  158. $val = $this->ini_array['file.store.type'];
  159. if(empty($val) || ($val == 'local'))
  160. return true ;
  161. else
  162. return false ;
  163. }
  164. function getLocalStorePath() {
  165. return $this->ini_array['local.store.path'];
  166. }
  167. }
  168. ?>