framework.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.2.0');
  23. define('GNUSOCIAL_LIFECYCLE', 'beta4'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
  24. define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);
  25. define('GNUSOCIAL_CODENAME', 'Not decided yet');
  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('APPS_PER_PAGE', 20);
  34. define('PEOPLETAGS_PER_PAGE', 20);
  35. define('GROUPS_PER_MINILIST', 8);
  36. define('PROFILES_PER_MINILIST', 8);
  37. define('FOREIGN_NOTICE_SEND', 1);
  38. define('FOREIGN_NOTICE_RECV', 2);
  39. define('FOREIGN_NOTICE_SEND_REPLY', 4);
  40. define('FOREIGN_FRIEND_SEND', 1);
  41. define('FOREIGN_FRIEND_RECV', 2);
  42. define('NOTICE_INBOX_SOURCE_SUB', 1);
  43. define('NOTICE_INBOX_SOURCE_GROUP', 2);
  44. define('NOTICE_INBOX_SOURCE_REPLY', 3);
  45. define('NOTICE_INBOX_SOURCE_FORWARD', 4);
  46. define('NOTICE_INBOX_SOURCE_PROFILE_TAG', 5);
  47. define('NOTICE_INBOX_SOURCE_GATEWAY', -1);
  48. // append our extlib dir as the last-resort place to find libs
  49. set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');
  50. // To protect against upstream libraries which haven't updated
  51. // for PHP 5.3 where dl() function may not be present...
  52. if (!function_exists('dl')) {
  53. // function_exists() returns false for things in disable_functions,
  54. // but they still exist and we'll die if we try to redefine them.
  55. //
  56. // Fortunately trying to call the disabled one will only trigger
  57. // a warning, not a fatal, so it's safe to leave it for our case.
  58. // Callers will be suppressing warnings anyway.
  59. $disabled = array_filter(array_map('trim', explode(',', ini_get('disable_functions'))));
  60. if (!in_array('dl', $disabled)) {
  61. function dl($library) {
  62. return false;
  63. }
  64. }
  65. }
  66. // global configuration object
  67. require_once 'PEAR.php';
  68. require_once 'PEAR/Exception.php';
  69. global $_PEAR;
  70. $_PEAR = new PEAR;
  71. $_PEAR->setErrorHandling(PEAR_ERROR_CALLBACK, 'PEAR_ErrorToPEAR_Exception');
  72. require_once 'DB.php';
  73. require_once 'DB/DataObject.php';
  74. require_once 'DB/DataObject/Cast.php'; # for dates
  75. global $_DB;
  76. $_DB = new DB;
  77. require_once(INSTALLDIR.'/lib/language.php');
  78. // This gets included before the config file, so that admin code and plugins
  79. // can use it
  80. require_once(INSTALLDIR.'/lib/event.php');
  81. require_once(INSTALLDIR.'/lib/plugin.php');
  82. function addPlugin($name, array $attrs=array())
  83. {
  84. return GNUsocial::addPlugin($name, $attrs);
  85. }
  86. function _have_config()
  87. {
  88. return GNUsocial::haveConfig();
  89. }
  90. function GNUsocial_class_autoload($cls)
  91. {
  92. if (file_exists(INSTALLDIR.'/classes/' . $cls . '.php')) {
  93. require_once(INSTALLDIR.'/classes/' . $cls . '.php');
  94. } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($cls) . '.php')) {
  95. require_once(INSTALLDIR.'/lib/' . strtolower($cls) . '.php');
  96. } else if (mb_substr($cls, -6) == 'Action' &&
  97. file_exists(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
  98. require_once(INSTALLDIR.'/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
  99. } else if ($cls === 'OAuthRequest' || $cls === 'OAuthException') {
  100. require_once('OAuth.php');
  101. } else {
  102. Event::handle('Autoload', array(&$cls));
  103. }
  104. }
  105. // Autoload function queue, starting with our own discovery method
  106. spl_autoload_register('GNUsocial_class_autoload');
  107. /**
  108. * Extlibs with namespaces (or directly in extlib/)
  109. * This covers libraries such as: Validate and \Michelf\Markdown
  110. *
  111. * The namespaced based structure is called "PSR-0 autoloading standard":
  112. * \<Vendor Name>\(<Namespace>\)*<Class Name>
  113. * and is available here: http://www.php-fig.org/psr/psr-0/
  114. */
  115. spl_autoload_register(function($class){
  116. $class_base = preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\'));
  117. $file = INSTALLDIR."/extlib/{$class_base}.php";
  118. if (file_exists($file)) {
  119. require_once $file;
  120. return;
  121. }
  122. # Try if the system has this external library
  123. $file = "/usr/share/php/{$class_base}.php";
  124. if (file_exists($file)) {
  125. require_once $file;
  126. return;
  127. }
  128. });
  129. require_once INSTALLDIR.'/lib/util.php';
  130. require_once INSTALLDIR.'/lib/action.php';
  131. require_once INSTALLDIR.'/lib/mail.php';
  132. //set PEAR error handling to use regular PHP exceptions
  133. function PEAR_ErrorToPEAR_Exception(PEAR_Error $err)
  134. {
  135. //DB_DataObject throws error when an empty set would be returned
  136. //That behavior is weird, and not how the rest of StatusNet works.
  137. //So just ignore those errors.
  138. if ($err->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
  139. return;
  140. }
  141. $msg = $err->getMessage();
  142. $userInfo = $err->getUserInfo();
  143. // Log this; push the message up as an exception
  144. common_log(LOG_ERR, "PEAR Error: $msg ($userInfo)");
  145. // HACK: queue handlers get kicked by the long-query killer, and
  146. // keep the same broken connection. We die here to get a new
  147. // process started.
  148. if (php_sapi_name() == 'cli' && preg_match('/nativecode=2006/', $userInfo)) {
  149. common_log(LOG_ERR, "Lost DB connection; dying.");
  150. exit(100);
  151. }
  152. if ($err->getCode()) {
  153. throw new PEAR_Exception($err->getMessage(), $err->getCode());
  154. }
  155. throw new PEAR_Exception($err->getMessage());
  156. }