Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

boot.php 42KB

10 years ago
10 years ago
4 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
8 years ago
9 years ago
9 years ago
8 years ago
8 years ago
8 years ago
10 years ago
9 years ago
10 years ago
10 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
4 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
2 years ago
9 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. <?php
  2. /** @file boot.php
  3. *
  4. * This file defines some global constants and includes the central App class.
  5. */
  6. /**
  7. * Friendica
  8. *
  9. * Friendica is a communications platform for integrated social communications
  10. * utilising decentralised communications and linkage to several indie social
  11. * projects - as well as popular mainstream providers.
  12. *
  13. * Our mission is to free our friends and families from the clutches of
  14. * data-harvesting corporations, and pave the way to a future where social
  15. * communications are free and open and flow between alternate providers as
  16. * easily as email does today.
  17. */
  18. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
  19. use Friendica\App;
  20. use Friendica\Core\System;
  21. use Friendica\Core\Config;
  22. use Friendica\Core\PConfig;
  23. use Friendica\Database\DBM;
  24. use Friendica\Util\Lock;
  25. require_once 'include/network.php';
  26. require_once 'include/plugin.php';
  27. require_once 'include/text.php';
  28. require_once 'include/datetime.php';
  29. require_once 'include/pgettext.php';
  30. require_once 'include/nav.php';
  31. require_once 'include/cache.php';
  32. require_once 'include/features.php';
  33. require_once 'include/identity.php';
  34. require_once 'update.php';
  35. require_once 'include/dbstructure.php';
  36. require_once 'include/poller.php';
  37. define ( 'FRIENDICA_PLATFORM', 'Friendica');
  38. define ( 'FRIENDICA_CODENAME', 'Asparagus');
  39. define ( 'FRIENDICA_VERSION', '3.6-dev' );
  40. define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
  41. define ( 'DB_UPDATE_VERSION', 1235 );
  42. /**
  43. * @brief Constant with a HTML line break.
  44. *
  45. * Contains a HTML line break (br) element and a real carriage return with line
  46. * feed for the source.
  47. * This can be used in HTML and JavaScript where needed a line break.
  48. */
  49. define ( 'EOL', "<br />\r\n" );
  50. define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
  51. /**
  52. * @brief Image storage quality.
  53. *
  54. * Lower numbers save space at cost of image detail.
  55. * For ease of upgrade, please do not change here. Change jpeg quality with
  56. * $a->config['system']['jpeg_quality'] = n;
  57. * in .htconfig.php, where n is netween 1 and 100, and with very poor results
  58. * below about 50
  59. *
  60. */
  61. define ( 'JPEG_QUALITY', 100 );
  62. /**
  63. * $a->config['system']['png_quality'] from 0 (uncompressed) to 9
  64. */
  65. define ( 'PNG_QUALITY', 8 );
  66. /**
  67. *
  68. * An alternate way of limiting picture upload sizes. Specify the maximum pixel
  69. * length that pictures are allowed to be (for non-square pictures, it will apply
  70. * to the longest side). Pictures longer than this length will be resized to be
  71. * this length (on the longest side, the other side will be scaled appropriately).
  72. * Modify this value using
  73. *
  74. * $a->config['system']['max_image_length'] = n;
  75. *
  76. * in .htconfig.php
  77. *
  78. * If you don't want to set a maximum length, set to -1. The default value is
  79. * defined by 'MAX_IMAGE_LENGTH' below.
  80. *
  81. */
  82. define ( 'MAX_IMAGE_LENGTH', -1 );
  83. /**
  84. * Not yet used
  85. */
  86. define ( 'DEFAULT_DB_ENGINE', 'InnoDB' );
  87. /**
  88. * @name SSL Policy
  89. *
  90. * SSL redirection policies
  91. * @{
  92. */
  93. define ( 'SSL_POLICY_NONE', 0 );
  94. define ( 'SSL_POLICY_FULL', 1 );
  95. define ( 'SSL_POLICY_SELFSIGN', 2 );
  96. /* @}*/
  97. /**
  98. * @name Logger
  99. *
  100. * log levels
  101. * @{
  102. */
  103. define ( 'LOGGER_NORMAL', 0 );
  104. define ( 'LOGGER_TRACE', 1 );
  105. define ( 'LOGGER_DEBUG', 2 );
  106. define ( 'LOGGER_DATA', 3 );
  107. define ( 'LOGGER_ALL', 4 );
  108. /* @}*/
  109. /**
  110. * @name Cache
  111. *
  112. * Cache levels
  113. * @{
  114. */
  115. define ( 'CACHE_MONTH', 0 );
  116. define ( 'CACHE_WEEK', 1 );
  117. define ( 'CACHE_DAY', 2 );
  118. define ( 'CACHE_HOUR', 3 );
  119. define ( 'CACHE_HALF_HOUR', 4 );
  120. define ( 'CACHE_QUARTER_HOUR', 5 );
  121. define ( 'CACHE_FIVE_MINUTES', 6 );
  122. define ( 'CACHE_MINUTE', 7 );
  123. /* @}*/
  124. /**
  125. * @name Register
  126. *
  127. * Registration policies
  128. * @{
  129. */
  130. define ( 'REGISTER_CLOSED', 0 );
  131. define ( 'REGISTER_APPROVE', 1 );
  132. define ( 'REGISTER_OPEN', 2 );
  133. /** @}*/
  134. /**
  135. * @name Contact_is
  136. *
  137. * Relationship types
  138. * @{
  139. */
  140. define ( 'CONTACT_IS_FOLLOWER', 1);
  141. define ( 'CONTACT_IS_SHARING', 2);
  142. define ( 'CONTACT_IS_FRIEND', 3);
  143. /** @}*/
  144. /**
  145. * @name Update
  146. *
  147. * DB update return values
  148. * @{
  149. */
  150. define ( 'UPDATE_SUCCESS', 0);
  151. define ( 'UPDATE_FAILED', 1);
  152. /** @}*/
  153. /**
  154. * @name page/profile types
  155. *
  156. * PAGE_NORMAL is a typical personal profile account
  157. * PAGE_SOAPBOX automatically approves all friend requests as CONTACT_IS_SHARING, (readonly)
  158. * PAGE_COMMUNITY automatically approves all friend requests as CONTACT_IS_SHARING, but with
  159. * write access to wall and comments (no email and not included in page owner's ACL lists)
  160. * PAGE_FREELOVE automatically approves all friend requests as full friends (CONTACT_IS_FRIEND).
  161. *
  162. * @{
  163. */
  164. define ( 'PAGE_NORMAL', 0 );
  165. define ( 'PAGE_SOAPBOX', 1 );
  166. define ( 'PAGE_COMMUNITY', 2 );
  167. define ( 'PAGE_FREELOVE', 3 );
  168. define ( 'PAGE_BLOG', 4 );
  169. define ( 'PAGE_PRVGROUP', 5 );
  170. /** @}*/
  171. /**
  172. * @name account types
  173. *
  174. * ACCOUNT_TYPE_PERSON - the account belongs to a person
  175. * Associated page types: PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE
  176. *
  177. * ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
  178. * Associated page type: PAGE_SOAPBOX
  179. *
  180. * ACCOUNT_TYPE_NEWS - the account is a news reflector
  181. * Associated page type: PAGE_SOAPBOX
  182. *
  183. * ACCOUNT_TYPE_COMMUNITY - the account is community forum
  184. * Associated page types: PAGE_COMMUNITY, PAGE_PRVGROUP
  185. * @{
  186. */
  187. define ( 'ACCOUNT_TYPE_PERSON', 0 );
  188. define ( 'ACCOUNT_TYPE_ORGANISATION',1 );
  189. define ( 'ACCOUNT_TYPE_NEWS', 2 );
  190. define ( 'ACCOUNT_TYPE_COMMUNITY', 3 );
  191. /** @}*/
  192. /**
  193. * @name CP
  194. *
  195. * Type of the community page
  196. * @{
  197. */
  198. define ( 'CP_NO_COMMUNITY_PAGE', -1 );
  199. define ( 'CP_USERS_ON_SERVER', 0 );
  200. define ( 'CP_GLOBAL_COMMUNITY', 1 );
  201. /** @}*/
  202. /**
  203. * @name Protocols
  204. *
  205. * Different protocols that we are storing
  206. * @{
  207. */
  208. define('PROTOCOL_UNKNOWN', 0);
  209. define('PROTOCOL_DFRN', 1);
  210. define('PROTOCOL_DIASPORA', 2);
  211. define('PROTOCOL_OSTATUS_SALMON', 3);
  212. define('PROTOCOL_OSTATUS_FEED', 4); // Deprecated
  213. define('PROTOCOL_GS_CONVERSATION', 5); // Deprecated
  214. define('PROTOCOL_SPLITTED_CONV', 6);
  215. /** @}*/
  216. /**
  217. * @name Network
  218. *
  219. * Network and protocol family types
  220. * @{
  221. */
  222. define ( 'NETWORK_DFRN', 'dfrn'); // Friendica, Mistpark, other DFRN implementations
  223. define ( 'NETWORK_ZOT', 'zot!'); // Zot!
  224. define ( 'NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations
  225. define ( 'NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol
  226. define ( 'NETWORK_DIASPORA', 'dspr'); // Diaspora
  227. define ( 'NETWORK_MAIL', 'mail'); // IMAP/POP
  228. define ( 'NETWORK_MAIL2', 'mai2'); // extended IMAP/POP
  229. define ( 'NETWORK_FACEBOOK', 'face'); // Facebook API
  230. define ( 'NETWORK_LINKEDIN', 'lnkd'); // LinkedIn
  231. define ( 'NETWORK_XMPP', 'xmpp'); // XMPP
  232. define ( 'NETWORK_MYSPACE', 'mysp'); // MySpace
  233. define ( 'NETWORK_GPLUS', 'goog'); // Google+
  234. define ( 'NETWORK_PUMPIO', 'pump'); // pump.io
  235. define ( 'NETWORK_TWITTER', 'twit'); // Twitter
  236. define ( 'NETWORK_DIASPORA2', 'dspc'); // Diaspora connector
  237. define ( 'NETWORK_STATUSNET', 'stac'); // Statusnet connector
  238. define ( 'NETWORK_APPNET', 'apdn'); // app.net
  239. define ( 'NETWORK_NEWS', 'nntp'); // Network News Transfer Protocol
  240. define ( 'NETWORK_ICALENDAR', 'ical'); // iCalendar
  241. define ( 'NETWORK_PNUT', 'pnut'); // pnut.io
  242. define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder
  243. /** @}*/
  244. /**
  245. * These numbers are used in stored permissions
  246. * and existing allocations MUST NEVER BE CHANGED
  247. * OR RE-ASSIGNED! You may only add to them.
  248. */
  249. $netgroup_ids = array(
  250. NETWORK_DFRN => (-1),
  251. NETWORK_ZOT => (-2),
  252. NETWORK_OSTATUS => (-3),
  253. NETWORK_FEED => (-4),
  254. NETWORK_DIASPORA => (-5),
  255. NETWORK_MAIL => (-6),
  256. NETWORK_MAIL2 => (-7),
  257. NETWORK_FACEBOOK => (-8),
  258. NETWORK_LINKEDIN => (-9),
  259. NETWORK_XMPP => (-10),
  260. NETWORK_MYSPACE => (-11),
  261. NETWORK_GPLUS => (-12),
  262. NETWORK_PUMPIO => (-13),
  263. NETWORK_TWITTER => (-14),
  264. NETWORK_DIASPORA2 => (-15),
  265. NETWORK_STATUSNET => (-16),
  266. NETWORK_APPNET => (-17),
  267. NETWORK_NEWS => (-18),
  268. NETWORK_ICALENDAR => (-19),
  269. NETWORK_PNUT => (-20),
  270. NETWORK_PHANTOM => (-127),
  271. );
  272. /**
  273. * Maximum number of "people who like (or don't like) this" that we will list by name
  274. */
  275. define ( 'MAX_LIKERS', 75);
  276. /**
  277. * Communication timeout
  278. */
  279. define ( 'ZCURL_TIMEOUT' , (-1));
  280. /**
  281. * @name Notify
  282. *
  283. * Email notification options
  284. * @{
  285. */
  286. define ( 'NOTIFY_INTRO', 0x0001 );
  287. define ( 'NOTIFY_CONFIRM', 0x0002 );
  288. define ( 'NOTIFY_WALL', 0x0004 );
  289. define ( 'NOTIFY_COMMENT', 0x0008 );
  290. define ( 'NOTIFY_MAIL', 0x0010 );
  291. define ( 'NOTIFY_SUGGEST', 0x0020 );
  292. define ( 'NOTIFY_PROFILE', 0x0040 );
  293. define ( 'NOTIFY_TAGSELF', 0x0080 );
  294. define ( 'NOTIFY_TAGSHARE', 0x0100 );
  295. define ( 'NOTIFY_POKE', 0x0200 );
  296. define ( 'NOTIFY_SHARE', 0x0400 );
  297. define ( 'SYSTEM_EMAIL', 0x4000 );
  298. define ( 'NOTIFY_SYSTEM', 0x8000 );
  299. /* @}*/
  300. /**
  301. * @name Term
  302. *
  303. * Tag/term types
  304. * @{
  305. */
  306. define ( 'TERM_UNKNOWN', 0 );
  307. define ( 'TERM_HASHTAG', 1 );
  308. define ( 'TERM_MENTION', 2 );
  309. define ( 'TERM_CATEGORY', 3 );
  310. define ( 'TERM_PCATEGORY', 4 );
  311. define ( 'TERM_FILE', 5 );
  312. define ( 'TERM_SAVEDSEARCH', 6 );
  313. define ( 'TERM_CONVERSATION', 7 );
  314. define ( 'TERM_OBJ_POST', 1 );
  315. define ( 'TERM_OBJ_PHOTO', 2 );
  316. /**
  317. * @name Namespaces
  318. *
  319. * Various namespaces we may need to parse
  320. * @{
  321. */
  322. define ( 'NAMESPACE_ZOT', 'http://purl.org/zot' );
  323. define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
  324. define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' );
  325. define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
  326. define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
  327. define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/' );
  328. define ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' );
  329. define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
  330. define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
  331. define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );
  332. define ( 'NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0' );
  333. define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from' );
  334. define ( 'NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0' );
  335. define ( 'NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/' );
  336. define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
  337. define ( 'NAMESPACE_MASTODON', 'http://mastodon.social/schema/1.0' );
  338. /* @}*/
  339. /**
  340. * @name Activity
  341. *
  342. * Activity stream defines
  343. * @{
  344. */
  345. define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
  346. define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
  347. define ( 'ACTIVITY_ATTEND', NAMESPACE_ZOT . '/activity/attendyes' );
  348. define ( 'ACTIVITY_ATTENDNO', NAMESPACE_ZOT . '/activity/attendno' );
  349. define ( 'ACTIVITY_ATTENDMAYBE', NAMESPACE_ZOT . '/activity/attendmaybe' );
  350. define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
  351. define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
  352. define ( 'ACTIVITY_REQ_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'request-friend' );
  353. define ( 'ACTIVITY_UNFRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'remove-friend' );
  354. define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
  355. define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
  356. define ( 'ACTIVITY_JOIN', NAMESPACE_ACTIVITY_SCHEMA . 'join' );
  357. define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
  358. define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
  359. define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
  360. define ( 'ACTIVITY_FAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
  361. define ( 'ACTIVITY_UNFAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'unfavorite' );
  362. define ( 'ACTIVITY_SHARE', NAMESPACE_ACTIVITY_SCHEMA . 'share' );
  363. define ( 'ACTIVITY_DELETE', NAMESPACE_ACTIVITY_SCHEMA . 'delete' );
  364. define ( 'ACTIVITY_POKE', NAMESPACE_ZOT . '/activity/poke' );
  365. define ( 'ACTIVITY_MOOD', NAMESPACE_ZOT . '/activity/mood' );
  366. define ( 'ACTIVITY_OBJ_BOOKMARK', NAMESPACE_ACTIVITY_SCHEMA . 'bookmark' );
  367. define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
  368. define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' );
  369. define ( 'ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person' );
  370. define ( 'ACTIVITY_OBJ_IMAGE', NAMESPACE_ACTIVITY_SCHEMA . 'image' );
  371. define ( 'ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo' );
  372. define ( 'ACTIVITY_OBJ_VIDEO', NAMESPACE_ACTIVITY_SCHEMA . 'video' );
  373. define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' );
  374. define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' );
  375. define ( 'ACTIVITY_OBJ_EVENT', NAMESPACE_ACTIVITY_SCHEMA . 'event' );
  376. define ( 'ACTIVITY_OBJ_GROUP', NAMESPACE_ACTIVITY_SCHEMA . 'group' );
  377. define ( 'ACTIVITY_OBJ_TAGTERM', NAMESPACE_DFRN . '/tagterm' );
  378. define ( 'ACTIVITY_OBJ_PROFILE', NAMESPACE_DFRN . '/profile' );
  379. define ( 'ACTIVITY_OBJ_QUESTION', 'http://activityschema.org/object/question' );
  380. /* @}*/
  381. /**
  382. * @name Gravity
  383. *
  384. * Item weight for query ordering
  385. * @{
  386. */
  387. define ( 'GRAVITY_PARENT', 0);
  388. define ( 'GRAVITY_LIKE', 3);
  389. define ( 'GRAVITY_COMMENT', 6);
  390. /* @}*/
  391. /**
  392. * @name Priority
  393. *
  394. * Process priority for the worker
  395. * @{
  396. */
  397. define('PRIORITY_UNDEFINED', 0);
  398. define('PRIORITY_CRITICAL', 10);
  399. define('PRIORITY_HIGH', 20);
  400. define('PRIORITY_MEDIUM', 30);
  401. define('PRIORITY_LOW', 40);
  402. define('PRIORITY_NEGLIGIBLE',50);
  403. /* @}*/
  404. /**
  405. * @name Social Relay settings
  406. *
  407. * See here: https://github.com/jaywink/social-relay
  408. * and here: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts
  409. * @{
  410. */
  411. define('SR_SCOPE_NONE', '');
  412. define('SR_SCOPE_ALL', 'all');
  413. define('SR_SCOPE_TAGS', 'tags');
  414. /* @}*/
  415. /**
  416. * Lowest possible date time value
  417. */
  418. define ('NULL_DATE', '0001-01-01 00:00:00');
  419. // Normally this constant is defined - but not if "pcntl" isn't installed
  420. if (!defined("SIGTERM")) {
  421. define("SIGTERM", 15);
  422. }
  423. /**
  424. * Depending on the PHP version this constant does exist - or not.
  425. * See here: http://php.net/manual/en/curl.constants.php#117928
  426. */
  427. if (!defined('CURLE_OPERATION_TIMEDOUT')) {
  428. define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED);
  429. }
  430. /**
  431. *
  432. * Reverse the effect of magic_quotes_gpc if it is enabled.
  433. * Please disable magic_quotes_gpc so we don't have to do this.
  434. * See http://php.net/manual/en/security.magicquotes.disabling.php
  435. *
  436. */
  437. function startup() {
  438. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  439. set_time_limit(0);
  440. // This has to be quite large to deal with embedded private photos
  441. ini_set('pcre.backtrack_limit', 500000);
  442. if (get_magic_quotes_gpc()) {
  443. $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  444. while (list($key, $val) = each($process)) {
  445. foreach ($val as $k => $v) {
  446. unset($process[$key][$k]);
  447. if (is_array($v)) {
  448. $process[$key][stripslashes($k)] = $v;
  449. $process[] = &$process[$key][stripslashes($k)];
  450. } else {
  451. $process[$key][stripslashes($k)] = stripslashes($v);
  452. }
  453. }
  454. }
  455. unset($process);
  456. }
  457. }
  458. /**
  459. * @brief Retrieve the App structure
  460. *
  461. * Useful in functions which require it but don't get it passed to them
  462. */
  463. function get_app() {
  464. global $a;
  465. if (empty($a)) {
  466. $a = new App(dirname(__DIR__));
  467. }
  468. return $a;
  469. }
  470. /**
  471. * @brief Multi-purpose function to check variable state.
  472. *
  473. * Usage: x($var) or $x($array, 'key')
  474. *
  475. * returns false if variable/key is not set
  476. * if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0.
  477. * e.g. x('') or x(0) returns 0;
  478. *
  479. * @param string|array $s variable to check
  480. * @param string $k key inside the array to check
  481. *
  482. * @return bool|int
  483. */
  484. function x($s, $k = NULL) {
  485. if ($k != NULL) {
  486. if ((is_array($s)) && (array_key_exists($k, $s))) {
  487. if ($s[$k]) {
  488. return (int) 1;
  489. }
  490. return (int) 0;
  491. }
  492. return false;
  493. } else {
  494. if (isset($s)) {
  495. if ($s) {
  496. return (int) 1;
  497. }
  498. return (int) 0;
  499. }
  500. return false;
  501. }
  502. }
  503. /**
  504. * @brief Called from db initialisation if db is dead.
  505. */
  506. function system_unavailable() {
  507. include('system_unavailable.php');
  508. system_down();
  509. killme();
  510. }
  511. /**
  512. * @brief Returns the baseurl.
  513. *
  514. * @see System::baseUrl()
  515. *
  516. * @return string
  517. * @TODO Function is deprecated and only used in some addons
  518. */
  519. function z_root() {
  520. return System::baseUrl();
  521. }
  522. /**
  523. * @brief Return absolut URL for given $path.
  524. *
  525. * @param string $path
  526. *
  527. * @return string
  528. */
  529. function absurl($path) {
  530. if (strpos($path, '/') === 0) {
  531. return z_path() . $path;
  532. }
  533. return $path;
  534. }
  535. /**
  536. * @brief Function to check if request was an AJAX (xmlhttprequest) request.
  537. *
  538. * @return boolean
  539. */
  540. function is_ajax() {
  541. return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  542. }
  543. /**
  544. * @brief Function to check if request was an AJAX (xmlhttprequest) request.
  545. *
  546. * @param $via_worker boolean Is the check run via the poller?
  547. */
  548. function check_db($via_worker) {
  549. $build = Config::get('system', 'build');
  550. if (!x($build)) {
  551. Config::set('system', 'build', DB_UPDATE_VERSION);
  552. $build = DB_UPDATE_VERSION;
  553. }
  554. if ($build != DB_UPDATE_VERSION) {
  555. // When we cannot execute the database update via the worker, we will do it directly
  556. if (!Worker::add(PRIORITY_CRITICAL, 'dbupdate') && $via_worker) {
  557. update_db(get_app());
  558. }
  559. }
  560. }
  561. /**
  562. * Sets the base url for use in cmdline programs which don't have
  563. * $_SERVER variables
  564. */
  565. function check_url(App $a) {
  566. $url = Config::get('system', 'url');
  567. // if the url isn't set or the stored url is radically different
  568. // than the currently visited url, store the current value accordingly.
  569. // "Radically different" ignores common variations such as http vs https
  570. // and www.example.com vs example.com.
  571. // We will only change the url to an ip address if there is no existing setting
  572. if (!x($url)) {
  573. $url = Config::set('system', 'url', System::baseUrl());
  574. }
  575. if ((!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->get_hostname))) {
  576. $url = Config::set('system', 'url', System::baseUrl());
  577. }
  578. return;
  579. }
  580. /**
  581. * @brief Automatic database updates
  582. */
  583. function update_db(App $a) {
  584. $build = Config::get('system', 'build');
  585. if (!x($build)) {
  586. $build = Config::set('system', 'build', DB_UPDATE_VERSION);
  587. }
  588. if ($build != DB_UPDATE_VERSION) {
  589. $stored = intval($build);
  590. $current = intval(DB_UPDATE_VERSION);
  591. if ($stored < $current) {
  592. Config::load('database');
  593. // We're reporting a different version than what is currently installed.
  594. // Run any existing update scripts to bring the database up to current.
  595. // make sure that boot.php and update.php are the same release, we might be
  596. // updating right this very second and the correct version of the update.php
  597. // file may not be here yet. This can happen on a very busy site.
  598. if (DB_UPDATE_VERSION == UPDATE_VERSION) {
  599. // Compare the current structure with the defined structure
  600. $t = Config::get('database', 'dbupdate_' . DB_UPDATE_VERSION);
  601. if ($t !== false) {
  602. return;
  603. }
  604. Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, time());
  605. // run old update routine (wich could modify the schema and
  606. // conflits with new routine)
  607. for ($x = $stored; $x < NEW_UPDATE_ROUTINE_VERSION; $x++) {
  608. $r = run_update_function($x);
  609. if (!$r) {
  610. break;
  611. }
  612. }
  613. if ($stored < NEW_UPDATE_ROUTINE_VERSION) {
  614. $stored = NEW_UPDATE_ROUTINE_VERSION;
  615. }
  616. // run new update routine
  617. // it update the structure in one call
  618. $retval = update_structure(false, true);
  619. if ($retval) {
  620. update_fail(
  621. DB_UPDATE_VERSION,
  622. $retval
  623. );
  624. return;
  625. } else {
  626. Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
  627. }
  628. // run any left update_nnnn functions in update.php
  629. for ($x = $stored; $x < $current; $x ++) {
  630. $r = run_update_function($x);
  631. if (!$r) {
  632. break;
  633. }
  634. }
  635. }
  636. }
  637. }
  638. return;
  639. }
  640. function run_update_function($x) {
  641. if (function_exists('update_' . $x)) {
  642. // There could be a lot of processes running or about to run.
  643. // We want exactly one process to run the update command.
  644. // So store the fact that we're taking responsibility
  645. // after first checking to see if somebody else already has.
  646. // If the update fails or times-out completely you may need to
  647. // delete the config entry to try again.
  648. $t = Config::get('database', 'update_' . $x);
  649. if ($t !== false) {
  650. return false;
  651. }
  652. Config::set('database', 'update_' . $x, time());
  653. // call the specific update
  654. $func = 'update_' . $x;
  655. $retval = $func();
  656. if ($retval) {
  657. //send the administrator an e-mail
  658. update_fail(
  659. $x,
  660. sprintf(t('Update %s failed. See error logs.'), $x)
  661. );
  662. return false;
  663. } else {
  664. Config::set('database', 'update_' . $x, 'success');
  665. Config::set('system', 'build', $x + 1);
  666. return true;
  667. }
  668. } else {
  669. Config::set('database', 'update_' . $x, 'success');
  670. Config::set('system', 'build', $x + 1);
  671. return true;
  672. }
  673. return true;
  674. }
  675. /**
  676. * @brief Synchronise plugins:
  677. *
  678. * $a->config['system']['addon'] contains a comma-separated list of names
  679. * of plugins/addons which are used on this system.
  680. * Go through the database list of already installed addons, and if we have
  681. * an entry, but it isn't in the config list, call the uninstall procedure
  682. * and mark it uninstalled in the database (for now we'll remove it).
  683. * Then go through the config list and if we have a plugin that isn't installed,
  684. * call the install procedure and add it to the database.
  685. *
  686. * @param App $a
  687. *
  688. */
  689. function check_plugins(App $a) {
  690. $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
  691. if (DBM::is_result($r)) {
  692. $installed = $r;
  693. } else {
  694. $installed = array();
  695. }
  696. $plugins = Config::get('system', 'addon');
  697. $plugins_arr = array();
  698. if ($plugins) {
  699. $plugins_arr = explode(',', str_replace(' ', '', $plugins));
  700. }
  701. $a->plugins = $plugins_arr;
  702. $installed_arr = array();
  703. if (count($installed)) {
  704. foreach ($installed as $i) {
  705. if (!in_array($i['name'], $plugins_arr)) {
  706. uninstall_plugin($i['name']);
  707. } else {
  708. $installed_arr[] = $i['name'];
  709. }
  710. }
  711. }
  712. if (count($plugins_arr)) {
  713. foreach ($plugins_arr as $p) {
  714. if (!in_array($p, $installed_arr)) {
  715. install_plugin($p);
  716. }
  717. }
  718. }
  719. load_hooks();
  720. return;
  721. }
  722. function get_guid($size = 16, $prefix = "") {
  723. if ($prefix == "") {
  724. $a = get_app();
  725. $prefix = hash("crc32", $a->get_hostname());
  726. }
  727. while (strlen($prefix) < ($size - 13)) {
  728. $prefix .= mt_rand();
  729. }
  730. if ($size >= 24) {
  731. $prefix = substr($prefix, 0, $size - 22);
  732. return(str_replace(".", "", uniqid($prefix, true)));
  733. } else {
  734. $prefix = substr($prefix, 0, max($size - 13, 0));
  735. return(uniqid($prefix));
  736. }
  737. }
  738. /**
  739. * @brief Wrapper for adding a login box.
  740. *
  741. * @param bool $register
  742. * If $register == true provide a registration link.
  743. * This will most always depend on the value of $a->config['register_policy'].
  744. * @param bool $hiddens
  745. *
  746. * @return string
  747. * Returns the complete html for inserting into the page
  748. *
  749. * @hooks 'login_hook'
  750. * string $o
  751. */
  752. function login($register = false, $hiddens = false) {
  753. $a = get_app();
  754. $o = "";
  755. $reg = false;
  756. if ($register) {
  757. $reg = array(
  758. 'title' => t('Create a New Account'),
  759. 'desc' => t('Register')
  760. );
  761. }
  762. $noid = Config::get('system', 'no_openid');
  763. $dest_url = $a->query_string;
  764. if (local_user()) {
  765. $tpl = get_markup_template("logout.tpl");
  766. } else {
  767. $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"), array(
  768. '$baseurl' => $a->get_baseurl(true)
  769. ));
  770. $tpl = get_markup_template("login.tpl");
  771. $_SESSION['return_url'] = $a->query_string;
  772. $a->module = 'login';
  773. }
  774. $o .= replace_macros($tpl, array(
  775. '$dest_url' => $dest_url,
  776. '$logout' => t('Logout'),
  777. '$login' => t('Login'),
  778. '$lname' => array('username', t('Nickname or Email: ') , '', ''),
  779. '$lpassword' => array('password', t('Password: '), '', ''),
  780. '$lremember' => array('remember', t('Remember me'), 0, ''),
  781. '$openid' => !$noid,
  782. '$lopenid' => array('openid_url', t('Or login using OpenID: '),'',''),
  783. '$hiddens' => $hiddens,
  784. '$register' => $reg,
  785. '$lostpass' => t('Forgot your password?'),
  786. '$lostlink' => t('Password Reset'),
  787. '$tostitle' => t('Website Terms of Service'),
  788. '$toslink' => t('terms of service'),
  789. '$privacytitle' => t('Website Privacy Policy'),
  790. '$privacylink' => t('privacy policy'),
  791. ));
  792. call_hooks('login_hook', $o);
  793. return $o;
  794. }
  795. /**
  796. * @brief Used to end the current process, after saving session state.
  797. */
  798. function killme() {
  799. global $session_exists;
  800. if (!get_app()->is_backend()) {
  801. if (!$session_exists) {
  802. session_abort();
  803. } else {
  804. session_write_close();
  805. }
  806. }
  807. exit();
  808. }
  809. /**
  810. * @brief Redirect to another URL and terminate this process.
  811. */
  812. function goaway($s) {
  813. if (!strstr(normalise_link($s), "http://")) {
  814. $s = System::baseUrl() . "/" . $s;
  815. }
  816. header("Location: $s");
  817. killme();
  818. }
  819. /**
  820. * @brief Returns the user id of locally logged in user or false.
  821. *
  822. * @return int|bool user id or false
  823. */
  824. function local_user() {
  825. if (x($_SESSION, 'authenticated') && x($_SESSION, 'uid')) {
  826. return intval($_SESSION['uid']);
  827. }
  828. return false;
  829. }
  830. /**
  831. * @brief Returns the public contact id of logged in user or false.
  832. *
  833. * @return int|bool public contact id or false
  834. */
  835. function public_contact() {
  836. static $public_contact_id = false;
  837. if (!$public_contact_id && x($_SESSION, 'authenticated')) {
  838. if (x($_SESSION, 'my_address')) {
  839. // Local user
  840. $public_contact_id = intval(get_contact($_SESSION['my_address'], 0));
  841. } elseif (x($_SESSION, 'visitor_home')) {
  842. // Remote user
  843. $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0));
  844. }
  845. } elseif (!x($_SESSION, 'authenticated')) {
  846. $public_contact_id = false;
  847. }
  848. return $public_contact_id;
  849. }
  850. /**
  851. * @brief Returns contact id of authenticated site visitor or false
  852. *
  853. * @return int|bool visitor_id or false
  854. */
  855. function remote_user() {
  856. // You cannot be both local and remote
  857. if (local_user()) {
  858. return false;
  859. }
  860. if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) {
  861. return intval($_SESSION['visitor_id']);
  862. }
  863. return false;
  864. }
  865. /**
  866. * @brief Show an error message to user.
  867. *
  868. * This function save text in session, to be shown to the user at next page load
  869. *
  870. * @param string $s - Text of notice
  871. */
  872. function notice($s) {
  873. $a = get_app();
  874. if (!x($_SESSION, 'sysmsg')) {
  875. $_SESSION['sysmsg'] = array();
  876. }
  877. if ($a->interactive) {
  878. $_SESSION['sysmsg'][] = $s;
  879. }
  880. }
  881. /**
  882. * @brief Show an info message to user.
  883. *
  884. * This function save text in session, to be shown to the user at next page load
  885. *
  886. * @param string $s - Text of notice
  887. */
  888. function info($s) {
  889. $a = get_app();
  890. if (local_user() && PConfig::get(local_user(), 'system', 'ignore_info')) {
  891. return;
  892. }
  893. if (!x($_SESSION, 'sysmsg_info')) {
  894. $_SESSION['sysmsg_info'] = array();
  895. }
  896. if ($a->interactive) {
  897. $_SESSION['sysmsg_info'][] = $s;
  898. }
  899. }
  900. /**
  901. * @brief Wrapper around config to limit the text length of an incoming message
  902. *
  903. * @return int
  904. */
  905. function get_max_import_size() {
  906. $a = get_app();
  907. return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 );
  908. }
  909. /**
  910. * @brief compatibilty wrapper for Worker::add function
  911. *
  912. * @param (integer|array) priority or parameter array, strings are deprecated and are ignored
  913. *
  914. * @return boolean "false" if proc_run couldn't be executed
  915. */
  916. function proc_run() {
  917. $proc_args = func_get_args();
  918. call_user_func_array('Friendica\Core\Worker::add', $proc_args);
  919. }
  920. function current_theme() {
  921. $app_base_themes = array('duepuntozero', 'dispy', 'quattro');
  922. $a = get_app();
  923. $page_theme = null;
  924. // Find the theme that belongs to the user whose stuff we are looking at
  925. if ($a->profile_uid && ($a->profile_uid != local_user())) {
  926. $r = q("select theme from user where uid = %d limit 1",
  927. intval($a->profile_uid)
  928. );
  929. if (DBM::is_result($r)) {
  930. $page_theme = $r[0]['theme'];
  931. }
  932. }
  933. // Allow folks to over-rule user themes and always use their own on their own site.
  934. // This works only if the user is on the same server
  935. if ($page_theme && local_user() && (local_user() != $a->profile_uid)) {
  936. if (PConfig::get(local_user(), 'system', 'always_my_theme')) {
  937. $page_theme = null;
  938. }
  939. }
  940. // $mobile_detect = new Mobile_Detect();
  941. // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
  942. $is_mobile = $a->is_mobile || $a->is_tablet;
  943. $standard_system_theme = Config::get('system', 'theme', '');
  944. $standard_theme_name = ((isset($_SESSION) && x($_SESSION, 'theme')) ? $_SESSION['theme'] : $standard_system_theme);
  945. if ($is_mobile) {
  946. if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
  947. $system_theme = $standard_system_theme;
  948. $theme_name = $standard_theme_name;
  949. } else {
  950. $system_theme = Config::get('system', 'mobile-theme', '');
  951. if ($system_theme == '') {
  952. $system_theme = $standard_system_theme;
  953. }
  954. $theme_name = ((isset($_SESSION) && x($_SESSION, 'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
  955. if ($theme_name === '---') {
  956. // user has selected to have the mobile theme be the same as the normal one
  957. $system_theme = $standard_system_theme;
  958. $theme_name = $standard_theme_name;
  959. if ($page_theme) {
  960. $theme_name = $page_theme;
  961. }
  962. }
  963. }
  964. } else {
  965. $system_theme = $standard_system_theme;
  966. $theme_name = $standard_theme_name;
  967. if ($page_theme) {
  968. $theme_name = $page_theme;
  969. }
  970. }
  971. if ($theme_name &&
  972. (file_exists('view/theme/' . $theme_name . '/style.css') ||
  973. file_exists('view/theme/' . $theme_name . '/style.php'))) {
  974. return($theme_name);
  975. }
  976. foreach ($app_base_themes as $t) {
  977. if (file_exists('view/theme/' . $t . '/style.css') ||
  978. file_exists('view/theme/' . $t . '/style.php')) {
  979. return($t);
  980. }
  981. }
  982. $fallback = array_merge(glob('view/theme/*/style.css'), glob('view/theme/*/style.php'));
  983. if (count($fallback)) {
  984. return (str_replace('view/theme/', '', substr($fallback[0], 0, -10)));
  985. }
  986. /// @TODO No final return statement?
  987. }
  988. /**
  989. * @brief Return full URL to theme which is currently in effect.
  990. *
  991. * Provide a sane default if nothing is chosen or the specified theme does not exist.
  992. *
  993. * @return string
  994. */
  995. function current_theme_url() {
  996. $a = get_app();
  997. $t = current_theme();
  998. $opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : '');
  999. if (file_exists('view/theme/' . $t . '/style.php')) {
  1000. return('view/theme/' . $t . '/style.pcss' . $opts);
  1001. }
  1002. return('view/theme/' . $t . '/style.css');
  1003. }
  1004. function feed_birthday($uid, $tz) {
  1005. /**
  1006. *
  1007. * Determine the next birthday, but only if the birthday is published
  1008. * in the default profile. We _could_ also look for a private profile that the
  1009. * recipient can see, but somebody could get mad at us if they start getting
  1010. * public birthday greetings when they haven't made this info public.
  1011. *
  1012. * Assuming we are able to publish this info, we are then going to convert
  1013. * the start time from the owner's timezone to UTC.
  1014. *
  1015. * This will potentially solve the problem found with some social networks
  1016. * where birthdays are converted to the viewer's timezone and salutations from
  1017. * elsewhere in the world show up on the wrong day. We will convert it to the
  1018. * viewer's timezone also, but first we are going to convert it from the birthday
  1019. * person's timezone to GMT - so the viewer may find the birthday starting at
  1020. * 6:00PM the day before, but that will correspond to midnight to the birthday person.
  1021. *
  1022. */
  1023. $birthday = '';
  1024. if (!strlen($tz)) {
  1025. $tz = 'UTC';
  1026. }
  1027. $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
  1028. intval($uid)
  1029. );
  1030. if (DBM::is_result($p)) {
  1031. $tmp_dob = substr($p[0]['dob'], 5);
  1032. if (intval($tmp_dob)) {
  1033. $y = datetime_convert($tz, $tz, 'now', 'Y');
  1034. $bd = $y . '-' . $tmp_dob . ' 00:00';
  1035. $t_dob = strtotime($bd);
  1036. $now = strtotime(datetime_convert($tz, $tz, 'now'));
  1037. if ($t_dob < $now) {
  1038. $bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
  1039. }
  1040. $birthday = datetime_convert($tz, 'UTC', $bd, ATOM_TIME);
  1041. }
  1042. }
  1043. return $birthday;
  1044. }
  1045. /**
  1046. * @brief Check if current user has admin role.
  1047. *
  1048. * @return bool true if user is an admin
  1049. */
  1050. function is_site_admin() {
  1051. $a = get_app();
  1052. $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
  1053. //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
  1054. if (local_user() && x($a->user, 'email') && x($a->config, 'admin_email') && in_array($a->user['email'], $adminlist)) {
  1055. return true;
  1056. }
  1057. return false;
  1058. }
  1059. /**
  1060. * @brief Returns querystring as string from a mapped array.
  1061. *
  1062. * @param array $params mapped array with query parameters
  1063. * @param string $name of parameter, default null
  1064. *
  1065. * @return string
  1066. */
  1067. function build_querystring($params, $name = null) {
  1068. $ret = "";
  1069. foreach ($params as $key => $val) {
  1070. if (is_array($val)) {
  1071. /// @TODO maybe not compare against null, use is_null()
  1072. if ($name == null) {
  1073. $ret .= build_querystring($val, $key);
  1074. } else {
  1075. $ret .= build_querystring($val, $name . "[$key]");
  1076. }
  1077. } else {
  1078. $val = urlencode($val);
  1079. /// @TODO maybe not compare against null, use is_null()
  1080. if ($name != null) {
  1081. /// @TODO two string concated, can be merged to one
  1082. $ret .= $name . "[$key]" . "=$val&";
  1083. } else {
  1084. $ret .= "$key=$val&";
  1085. }
  1086. }
  1087. }
  1088. return $ret;
  1089. }
  1090. function explode_querystring($query) {
  1091. $arg_st = strpos($query, '?');
  1092. if ($arg_st !== false) {
  1093. $base = substr($query, 0, $arg_st);
  1094. $arg_st += 1;
  1095. } else {
  1096. $base = '';
  1097. $arg_st = 0;
  1098. }
  1099. $args = explode('&', substr($query, $arg_st));
  1100. foreach ($args as $k => $arg) {
  1101. /// @TODO really compare type-safe here?
  1102. if ($arg === '') {
  1103. unset($args[$k]);
  1104. }
  1105. }
  1106. $args = array_values($args);
  1107. if (!$base) {
  1108. $base = $args[0];
  1109. unset($args[0]);
  1110. $args = array_values($args);
  1111. }
  1112. return array(
  1113. 'base' => $base,
  1114. 'args' => $args,
  1115. );
  1116. }
  1117. /**
  1118. * Returns the complete URL of the current page, e.g.: http(s)://something.com/network
  1119. *
  1120. * Taken from http://webcheatsheet.com/php/get_current_page_url.php
  1121. */
  1122. function curPageURL() {
  1123. $pageURL = 'http';
  1124. if ($_SERVER["HTTPS"] == "on") {
  1125. $pageURL .= "s";
  1126. }
  1127. $pageURL .= "://";
  1128. if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
  1129. $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
  1130. } else {
  1131. $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
  1132. }
  1133. return $pageURL;
  1134. }
  1135. function random_digits($digits) {
  1136. $rn = '';
  1137. for ($i = 0; $i < $digits; $i++) {
  1138. /// @TODO rand() is different to mt_rand() and maybe lesser "random"
  1139. $rn .= rand(0, 9);
  1140. }
  1141. return $rn;
  1142. }
  1143. function get_server() {
  1144. $server = Config::get("system", "directory");
  1145. if ($server == "") {
  1146. $server = "http://dir.friendica.social";
  1147. }
  1148. return($server);
  1149. }
  1150. function get_temppath() {
  1151. $a = get_app();
  1152. $temppath = Config::get("system", "temppath");
  1153. if (($temppath != "") && App::directory_usable($temppath)) {
  1154. // We have a temp path and it is usable
  1155. return App::realpath($temppath);
  1156. }
  1157. // We don't have a working preconfigured temp path, so we take the system path.
  1158. $temppath = sys_get_temp_dir();
  1159. // Check if it is usable
  1160. if (($temppath != "") && App::directory_usable($temppath)) {
  1161. // Always store the real path, not the path through symlinks
  1162. $temppath = App::realpath($temppath);
  1163. // To avoid any interferences with other systems we create our own directory
  1164. $new_temppath = $temppath . "/" . $a->get_hostname();
  1165. if (!is_dir($new_temppath)) {
  1166. /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
  1167. mkdir($new_temppath);
  1168. }
  1169. if (App::directory_usable($new_temppath)) {
  1170. // The new path is usable, we are happy
  1171. Config::set("system", "temppath", $new_temppath);
  1172. return $new_temppath;
  1173. } else {
  1174. // We can't create a subdirectory, strange.
  1175. // But the directory seems to work, so we use it but don't store it.
  1176. return $temppath;
  1177. }
  1178. }
  1179. // Reaching this point means that the operating system is configured badly.
  1180. return '';
  1181. }
  1182. function get_cachefile($file, $writemode = true) {
  1183. $cache = get_itemcachepath();
  1184. if ((!$cache) || (!is_dir($cache))) {
  1185. return("");
  1186. }
  1187. $subfolder = $cache . "/" . substr($file, 0, 2);
  1188. $cachepath = $subfolder . "/" . $file;
  1189. if ($writemode) {
  1190. if (!is_dir($subfolder)) {
  1191. mkdir($subfolder);
  1192. chmod($subfolder, 0777);
  1193. }
  1194. }
  1195. /// @TODO no need to put braces here
  1196. return $cachepath;
  1197. }
  1198. function clear_cache($basepath = "", $path = "") {
  1199. if ($path == "") {
  1200. $basepath = get_itemcachepath();
  1201. $path = $basepath;
  1202. }
  1203. if (($path == "") || (!is_dir($path))) {
  1204. return;
  1205. }
  1206. if (substr(realpath($path), 0, strlen($basepath)) != $basepath) {
  1207. return;
  1208. }
  1209. $cachetime = (int) Config::get('system', 'itemcache_duration');
  1210. if ($cachetime == 0) {
  1211. $cachetime = 86400;
  1212. }
  1213. if (is_writable($path)) {
  1214. if ($dh = opendir($path)) {
  1215. while (($file = readdir($dh)) !== false) {
  1216. $fullpath = $path . "/" . $file;
  1217. if ((filetype($fullpath) == "dir") && ($file != ".") && ($file != "..")) {
  1218. clear_cache($basepath, $fullpath);
  1219. }
  1220. if ((filetype($fullpath) == "file") && (filectime($fullpath) < (time() - $cachetime))) {
  1221. unlink($fullpath);
  1222. }
  1223. }
  1224. closedir($dh);
  1225. }
  1226. }
  1227. }
  1228. function get_itemcachepath() {
  1229. // Checking, if the cache is deactivated
  1230. $cachetime = (int) Config::get('system', 'itemcache_duration');
  1231. if ($cachetime < 0) {
  1232. return "";
  1233. }
  1234. $itemcache = Config::get('system', 'itemcache');
  1235. if (($itemcache != "") && App::directory_usable($itemcache)) {
  1236. return App::realpath($itemcache);
  1237. }
  1238. $temppath = get_temppath();
  1239. if ($temppath != "") {
  1240. $itemcache = $temppath . "/itemcache";
  1241. if (!file_exists($itemcache) && !is_dir($itemcache)) {
  1242. mkdir($itemcache);
  1243. }
  1244. if (App::directory_usable($itemcache)) {
  1245. Config::set("system", "itemcache", $itemcache);
  1246. return $itemcache;
  1247. }
  1248. }
  1249. return "";
  1250. }
  1251. /**
  1252. * @brief Returns the path where spool files are stored
  1253. *
  1254. * @return string Spool path
  1255. */
  1256. function get_spoolpath() {
  1257. $spoolpath = Config::get('system', 'spoolpath');
  1258. if (($spoolpath != "") && App::directory_usable($spoolpath)) {
  1259. // We have a spool path and it is usable
  1260. return $spoolpath;
  1261. }
  1262. // We don't have a working preconfigured spool path, so we take the temp path.
  1263. $temppath = get_temppath();
  1264. if ($temppath != "") {
  1265. // To avoid any interferences with other systems we create our own directory
  1266. $spoolpath = $temppath . "/spool";
  1267. if (!is_dir($spoolpath)) {
  1268. mkdir($spoolpath);
  1269. }
  1270. if (App::directory_usable($spoolpath)) {
  1271. // The new path is usable, we are happy
  1272. Config::set("system", "spoolpath", $spoolpath);
  1273. return $spoolpath;
  1274. } else {
  1275. // We can't create a subdirectory, strange.
  1276. // But the directory seems to work, so we use it but don't store it.
  1277. return $temppath;
  1278. }
  1279. }
  1280. // Reaching this point means that the operating system is configured badly.
  1281. return "";
  1282. }
  1283. /// @deprecated
  1284. function set_template_engine(App $a, $engine = 'internal') {
  1285. /// @note This function is no longer necessary, but keep it as a wrapper to the class method
  1286. /// to avoid breaking themes again unnecessarily
  1287. /// @TODO maybe output a warning here so the theme developer can see it? PHP won't show such warnings like Java does.
  1288. $a->set_template_engine($engine);
  1289. }
  1290. if (!function_exists('exif_imagetype')) {
  1291. function exif_imagetype($file) {
  1292. $size = getimagesize($file);
  1293. return $size[2];
  1294. }
  1295. }
  1296. function validate_include(&$file) {
  1297. $orig_file = $file;
  1298. $file = realpath($file);
  1299. if (strpos($file, getcwd()) !== 0) {
  1300. return false;
  1301. }
  1302. $file = str_replace(getcwd() . "/", "", $file, $count);
  1303. if ($count != 1) {
  1304. return false;
  1305. }
  1306. if ($orig_file !== $file) {
  1307. return false;
  1308. }
  1309. $valid = false;
  1310. if (strpos($file, "include/") === 0) {
  1311. $valid = true;
  1312. }
  1313. if (strpos($file, "addon/") === 0) {
  1314. $valid = true;
  1315. }
  1316. // Simply return flag
  1317. return ($valid);
  1318. }
  1319. function current_load() {
  1320. if (!function_exists('sys_getloadavg')) {
  1321. return false;
  1322. }
  1323. $load_arr = sys_getloadavg();
  1324. if (!is_array($load_arr)) {
  1325. return false;
  1326. }
  1327. return max($load_arr[0], $load_arr[1]);
  1328. }
  1329. /**
  1330. * @brief get c-style args
  1331. *
  1332. * @return int
  1333. */
  1334. function argc() {
  1335. return get_app()->argc;
  1336. }
  1337. /**
  1338. * @brief Returns the value of a argv key
  1339. *
  1340. * @param int $x argv key
  1341. * @return string Value of the argv key
  1342. */
  1343. function argv($x) {
  1344. if (array_key_exists($x, get_app()->argv)) {
  1345. return get_app()->argv[$x];
  1346. }
  1347. return '';
  1348. }
  1349. /**
  1350. * @brief Get the data which is needed for infinite scroll
  1351. *
  1352. * For invinite scroll we need the page number of the actual page
  1353. * and the the URI where the content of the next page comes from.
  1354. * This data is needed for the js part in main.js.
  1355. * Note: infinite scroll does only work for the network page (module)
  1356. *
  1357. * @param string $module The name of the module (e.g. "network")
  1358. * @return array Of infinite scroll data
  1359. * 'pageno' => $pageno The number of the actual page
  1360. * 'reload_uri' => $reload_uri The URI of the content we have to load
  1361. */
  1362. function infinite_scroll_data($module) {
  1363. if (PConfig::get(local_user(), 'system', 'infinite_scroll')
  1364. && ($module == "network") && ($_GET["mode"] != "minimal")) {
  1365. // get the page number
  1366. if (is_string($_GET["page"])) {
  1367. $pageno = $_GET["page"];
  1368. } else {
  1369. $pageno = 1;
  1370. }
  1371. $reload_uri = "";
  1372. // try to get the uri from which we load the content
  1373. foreach ($_GET AS $param => $value) {
  1374. if (($param != "page") && ($param != "q")) {
  1375. $reload_uri .= "&" . $param . "=" . urlencode($value);
  1376. }
  1377. }
  1378. if (($a->page_offset != "") && ! strstr($reload_uri, "&offset=")) {
  1379. $reload_uri .= "&offset=" . urlencode($a->page_offset);
  1380. }
  1381. $arr = array("pageno" => $pageno, "reload_uri" => $reload_uri);
  1382. return $arr;
  1383. }
  1384. }