framework.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008-2010, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('GNUSOCIAL')) { exit(1); }
  20. define('GNUSOCIAL_ENGINE', 'GNU social');
  21. define('GNUSOCIAL_ENGINE_URL', 'https://www.gnu.org/software/social/');
  22. define('GNUSOCIAL_BASE_VERSION', '1.1.3');
  23. define('GNUSOCIAL_LIFECYCLE', 'release'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
  24. define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
  25. define('GNUSOCIAL_CODENAME', 'The Spanish Invasion');
  26. define('AVATAR_PROFILE_SIZE', 96);
  27. define('AVATAR_STREAM_SIZE', 48);
  28. define('AVATAR_MINI_SIZE', 24);
  29. define('NOTICES_PER_PAGE', 20);
  30. define('PROFILES_PER_PAGE', 20);
  31. define('MESSAGES_PER_PAGE', 20);
  32. define('GROUPS_PER_PAGE', 20);
  33. define('FOREIGN_NOTICE_SEND', 1);
  34. define('FOREIGN_NOTICE_RECV', 2);
  35. define('FOREIGN_NOTICE_SEND_REPLY', 4);
  36. define('FOREIGN_FRIEND_SEND', 1);
  37. define('FOREIGN_FRIEND_RECV', 2);
  38. define('NOTICE_INBOX_SOURCE_SUB', 1);
  39. define('NOTICE_INBOX_SOURCE_GROUP', 2);
  40. define('NOTICE_INBOX_SOURCE_REPLY', 3);
  41. define('NOTICE_INBOX_SOURCE_FORWARD', 4);
  42. define('NOTICE_INBOX_SOURCE_PROFILE_TAG', 5);
  43. define('NOTICE_INBOX_SOURCE_GATEWAY', -1);
  44. // append our extlib dir as the last-resort place to find libs
  45. set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');
  46. // To protect against upstream libraries which haven't updated
  47. // for PHP 5.3 where dl() function may not be present...
  48. if (!function_exists('dl')) {
  49. // function_exists() returns false for things in disable_functions,
  50. // but they still exist and we'll die if we try to redefine them.
  51. //
  52. // Fortunately trying to call the disabled one will only trigger
  53. // a warning, not a fatal, so it's safe to leave it for our case.
  54. // Callers will be suppressing warnings anyway.
  55. $disabled = array_filter(array_map('trim', explode(',', ini_get('disable_functions'))));
  56. if (!in_array('dl', $disabled)) {
  57. function dl($library) {
  58. return false;
  59. }
  60. }
  61. }
  62. // global configuration object
  63. require_once 'PEAR.php';
  64. require_once 'PEAR/Exception.php';
  65. global $_PEAR;
  66. $_PEAR = new PEAR;
  67. $_PEAR->setErrorHandling(PEAR_ERROR_CALLBACK, 'PEAR_ErrorToPEAR_Exception');
  68. require_once 'DB.php';
  69. require_once 'DB/DataObject.php';
  70. require_once 'DB/DataObject/Cast.php'; # for dates
  71. global $_DB;
  72. $_DB = new DB;
  73. require_once(INSTALLDIR.'/lib/language.php');
  74. // This gets included before the config file, so that admin code and plugins
  75. // can use it
  76. require_once(INSTALLDIR.'/lib/event.php');
  77. require_once(INSTALLDIR.'/lib/plugin.php');
  78. function addPlugin($name, array $attrs=array())
  79. {
  80. return StatusNet::addPlugin($name, $attrs);
  81. }
  82. function _have_config()
  83. {
  84. return StatusNet::haveConfig();
  85. }
  86. function GNUsocial_class_autoload($cls)
  87. {
  88. if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
  89. require_once(INSTALLDIR.'/classes/' . $cls . '.php');
  90. } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
  91. require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
  92. } else if (mb_substr($cls, -6) == 'Action' &&
  93. file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
  94. require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
  95. } else if ($cls === 'OAuthRequest' || $cls === 'OAuthException') {
  96. require_once('OAuth.php');
  97. } else {
  98. Event::handle('Autoload', array(&$cls));
  99. }
  100. }
  101. // Autoload function queue, starting with our own discovery method
  102. spl_autoload_register('GNUsocial_class_autoload');
  103. /**
  104. * Extlibs with namespaces (or directly in extlib/)
  105. * This covers libraries such as: Validate and \Michelf\Markdown
  106. *
  107. * The namespaced based structure is called "PSR-0 autoloading standard":
  108. * \<Vendor Name>\(<Namespace>\)*<Class Name>
  109. * and is available here: http://www.php-fig.org/psr/psr-0/
  110. */
  111. spl_autoload_register(function($class){
  112. $file = INSTALLDIR.'/extlib/'.preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
  113. if (file_exists($file)) {
  114. require_once $file;
  115. }
  116. });
  117. require_once INSTALLDIR.'/lib/util.php';
  118. require_once INSTALLDIR.'/lib/action.php';
  119. require_once INSTALLDIR.'/lib/mail.php';
  120. //set PEAR error handling to use regular PHP exceptions
  121. function PEAR_ErrorToPEAR_Exception($err)
  122. {
  123. //DB_DataObject throws error when an empty set would be returned
  124. //That behavior is weird, and not how the rest of StatusNet works.
  125. //So just ignore those errors.
  126. if ($err->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
  127. return;
  128. }
  129. $msg = $err->getMessage();
  130. $userInfo = $err->getUserInfo();
  131. // Log this; push the message up as an exception
  132. common_log(LOG_ERR, "PEAR Error: $msg ($userInfo)");
  133. // HACK: queue handlers get kicked by the long-query killer, and
  134. // keep the same broken connection. We die here to get a new
  135. // process started.
  136. if (php_sapi_name() == 'cli' && preg_match('/nativecode=2006/', $userInfo)) {
  137. common_log(LOG_ERR, "Lost DB connection; dying.");
  138. exit(100);
  139. }
  140. if ($err->getCode()) {
  141. throw new PEAR_Exception($err->getMessage(), $err->getCode());
  142. }
  143. throw new PEAR_Exception($err->getMessage());
  144. }