Hubzilla core code
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.
 
 
 
 
 
 

2626 lines
76 KiB

  1. <?php
  2. /**
  3. * @file boot.php
  4. *
  5. * @brief This file defines some global constants and includes the central App class.
  6. */
  7. /**
  8. *
  9. * This is an open source decentralised communications
  10. * platform combined with a decentralised identity/authentication framework
  11. * wrapped in an extensible content management system, providing website designers
  12. * the ability to embed fully decentralised communications and social tools
  13. * into many traditional website designs (blogs, forums, small business
  14. * websites, charitable organisations, etc.). Also provided is DNS mobility
  15. * and internet scale privacy/access control.
  16. *
  17. * This allows any individual website to participate in a matrix of linked
  18. * sites and people and media sharing which is far greater than the reach
  19. * of an individual site.
  20. *
  21. * If you are reading the source code and come across a function
  22. * or code block which is not documented, but you have a good idea what it
  23. * does, please add some descriptive comments and push it to the main project.
  24. * Even if your description isn't perfect, it gives us a base which we
  25. * can build on and correct - so that eventually everything is fully
  26. * documented.
  27. */
  28. // composer autoloader for all namespaced Classes
  29. require_once('vendor/autoload.php');
  30. require_once('include/config.php');
  31. require_once('include/network.php');
  32. require_once('include/plugin.php');
  33. require_once('include/text.php');
  34. require_once('include/datetime.php');
  35. require_once('include/language.php');
  36. require_once('include/nav.php');
  37. require_once('include/permissions.php');
  38. require_once('include/features.php');
  39. require_once('include/taxonomy.php');
  40. require_once('include/channel.php');
  41. require_once('include/connections.php');
  42. require_once('include/account.php');
  43. require_once('include/zid.php');
  44. require_once('include/xchan.php');
  45. require_once('include/hubloc.php');
  46. require_once('include/attach.php');
  47. require_once('include/bbcode.php');
  48. define ( 'PLATFORM_NAME', 'hubzilla' );
  49. define ( 'STD_VERSION', '4.6' );
  50. define ( 'ZOT_REVISION', '6.0a' );
  51. define ( 'DB_UPDATE_VERSION', 1234 );
  52. define ( 'PROJECT_BASE', __DIR__ );
  53. /**
  54. * @brief Constant with a HTML line break.
  55. *
  56. * Contains a HTML line break (br) element and a real carriage return with line
  57. * feed for the source.
  58. * This can be used in HTML and JavaScript where needed a line break.
  59. */
  60. define ( 'EOL', '<br>' . "\r\n" );
  61. define ( 'EMPTY_STR', '' );
  62. define ( 'ATOM_TIME', 'Y-m-d\\TH:i:s\\Z' ); // aka ISO 8601 "Zulu"
  63. define ( 'TEMPLATE_BUILD_PATH', 'store/[data]/smarty3' );
  64. define ( 'DIRECTORY_MODE_NORMAL', 0x0000); // A directory client
  65. define ( 'DIRECTORY_MODE_PRIMARY', 0x0001); // There can only be *one* primary directory server in a directory_realm.
  66. define ( 'DIRECTORY_MODE_SECONDARY', 0x0002); // All other mirror directory servers
  67. define ( 'DIRECTORY_MODE_STANDALONE', 0x0100); // A detached (off the grid) hub with itself as directory server.
  68. // We will look for upstream directories whenever me make contact
  69. // with other sites, but if this is a new installation and isn't
  70. // a standalone hub, we need to seed the service with a starting
  71. // point to go out and find the rest of the world.
  72. define ( 'DIRECTORY_REALM', 'RED_GLOBAL');
  73. define ( 'DIRECTORY_FALLBACK_MASTER', 'https://hub.netzgemeinde.eu');
  74. $DIRECTORY_FALLBACK_SERVERS = array(
  75. 'https://hub.netzgemeinde.eu',
  76. 'https://zotsite.net',
  77. 'https://hub.libranet.de'
  78. );
  79. /**
  80. *
  81. * Image storage quality. Lower numbers save space at cost of image detail.
  82. * For ease of upgrade, please do not change here. Change jpeg quality with
  83. * App::$config['system']['jpeg_quality'] = n;
  84. * in .htconfig.php, where n is netween 1 and 100, and with very poor results
  85. * below about 50
  86. */
  87. define ( 'JPEG_QUALITY', 100 );
  88. /**
  89. * App::$config['system']['png_quality'] from 0 (uncompressed) to 9
  90. */
  91. define ( 'PNG_QUALITY', 8 );
  92. /**
  93. * Language detection parameters
  94. */
  95. define ( 'LANGUAGE_DETECT_MIN_LENGTH', 128 );
  96. define ( 'LANGUAGE_DETECT_MIN_CONFIDENCE', 0.01 );
  97. /**
  98. * Default permissions for file-based storage (webDAV, etc.)
  99. * These files will be owned by the webserver who will need write
  100. * access to the "storage" folder.
  101. * Ideally you should make this 700, however some hosted platforms
  102. * may not let you change ownership of this directory so we're
  103. * defaulting to both owner-write and group-write privilege.
  104. * This should work for most cases without modification.
  105. * Over-ride this in your .htconfig.php if you need something
  106. * either more or less restrictive.
  107. */
  108. if(! defined('STORAGE_DEFAULT_PERMISSIONS')) {
  109. define ( 'STORAGE_DEFAULT_PERMISSIONS', 0770 );
  110. }
  111. /**
  112. *
  113. * An alternate way of limiting picture upload sizes. Specify the maximum pixel
  114. * length that pictures are allowed to be (for non-square pictures, it will apply
  115. * to the longest side). Pictures longer than this length will be resized to be
  116. * this length (on the longest side, the other side will be scaled appropriately).
  117. * Modify this value using
  118. *
  119. * App::$config['system']['max_image_length'] = n;
  120. *
  121. * in .htconfig.php
  122. *
  123. * If you don't want to set a maximum length, set to -1. The default value is
  124. * defined by 'MAX_IMAGE_LENGTH' below.
  125. *
  126. */
  127. define ( 'MAX_IMAGE_LENGTH', -1 );
  128. /**
  129. * log levels
  130. */
  131. define ( 'LOGGER_NORMAL', 0 );
  132. define ( 'LOGGER_TRACE', 1 );
  133. define ( 'LOGGER_DEBUG', 2 );
  134. define ( 'LOGGER_DATA', 3 );
  135. define ( 'LOGGER_ALL', 4 );
  136. /**
  137. * registration policies
  138. */
  139. define ( 'REGISTER_CLOSED', 0 );
  140. define ( 'REGISTER_APPROVE', 1 );
  141. define ( 'REGISTER_OPEN', 2 );
  142. /**
  143. * site access policy
  144. */
  145. define ( 'ACCESS_PRIVATE', 0 );
  146. define ( 'ACCESS_PAID', 1 );
  147. define ( 'ACCESS_FREE', 2 );
  148. define ( 'ACCESS_TIERED', 3 );
  149. /**
  150. * DB update return values
  151. */
  152. define ( 'UPDATE_SUCCESS', 0);
  153. define ( 'UPDATE_FAILED', 1);
  154. define ( 'CLIENT_MODE_NORMAL', 0x0000);
  155. define ( 'CLIENT_MODE_LOAD', 0x0001);
  156. define ( 'CLIENT_MODE_UPDATE', 0x0002);
  157. /**
  158. *
  159. * Channel pageflags
  160. *
  161. */
  162. define ( 'PAGE_NORMAL', 0x0000 );
  163. define ( 'PAGE_HIDDEN', 0x0001 );
  164. define ( 'PAGE_AUTOCONNECT', 0x0002 );
  165. define ( 'PAGE_APPLICATION', 0x0004 );
  166. define ( 'PAGE_ALLOWCODE', 0x0008 );
  167. define ( 'PAGE_PREMIUM', 0x0010 );
  168. define ( 'PAGE_ADULT', 0x0020 );
  169. define ( 'PAGE_CENSORED', 0x0040 ); // Site admin has blocked this channel from appearing in casual search results and site feeds
  170. define ( 'PAGE_SYSTEM', 0x1000 );
  171. define ( 'PAGE_HUBADMIN', 0x2000 ); // set this to indicate a preferred admin channel rather than the
  172. // default channel of any accounts with the admin role.
  173. define ( 'PAGE_REMOVED', 0x8000 );
  174. /**
  175. * Photo usage types
  176. */
  177. define ( 'PHOTO_NORMAL', 0x0000 );
  178. define ( 'PHOTO_PROFILE', 0x0001 );
  179. define ( 'PHOTO_XCHAN', 0x0002 );
  180. define ( 'PHOTO_THING', 0x0004 );
  181. define ( 'PHOTO_COVER', 0x0010 );
  182. define ( 'PHOTO_CACHE', 0x0020 );
  183. define ( 'PHOTO_ADULT', 0x0008 );
  184. define ( 'PHOTO_FLAG_OS', 0x4000 );
  185. define ( 'PHOTO_RES_ORIG', 0 );
  186. define ( 'PHOTO_RES_1024', 1 ); // rectangular 1024 max width or height, floating height if not (4:3)
  187. define ( 'PHOTO_RES_640', 2 ); // to accomodate SMBC vertical comic strips without scrunching the width
  188. define ( 'PHOTO_RES_320', 3 ); // accordingly
  189. define ( 'PHOTO_RES_PROFILE_300', 4 ); // square 300 px
  190. define ( 'PHOTO_RES_PROFILE_80', 5 ); // square 80 px
  191. define ( 'PHOTO_RES_PROFILE_48', 6 ); // square 48 px
  192. define ( 'PHOTO_RES_COVER_1200', 7 ); // 1200w x 435h (2.75:1)
  193. define ( 'PHOTO_RES_COVER_850', 8 ); // 850w x 310h
  194. define ( 'PHOTO_RES_COVER_425', 9 ); // 425w x 160h
  195. /**
  196. * Menu types
  197. */
  198. define ( 'MENU_SYSTEM', 0x0001 );
  199. define ( 'MENU_BOOKMARK', 0x0002 );
  200. /**
  201. * Network and protocol family types
  202. */
  203. define ( 'NETWORK_FRND', 'friendica-over-diaspora'); // Friendica, Mistpark, other DFRN implementations
  204. define ( 'NETWORK_DFRN', 'dfrn'); // Friendica, Mistpark, other DFRN implementations
  205. define ( 'NETWORK_ZOT', 'zot'); // Zot!
  206. define ( 'NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations
  207. define ( 'NETWORK_GNUSOCIAL', 'gnusoc'); // status.net, identi.ca, GNU-social, other OStatus implementations
  208. define ( 'NETWORK_FEED', 'rss'); // RSS/Atom feeds with no known "post/notify" protocol
  209. define ( 'NETWORK_DIASPORA', 'diaspora'); // Diaspora
  210. define ( 'NETWORK_ACTIVITYPUB', 'activitypub');
  211. define ( 'NETWORK_MAIL', 'mail'); // IMAP/POP
  212. define ( 'NETWORK_MAIL2', 'mai2'); // extended IMAP/POP
  213. define ( 'NETWORK_FACEBOOK', 'face'); // Facebook API
  214. define ( 'NETWORK_LINKEDIN', 'lnkd'); // LinkedIn
  215. define ( 'NETWORK_XMPP', 'xmpp'); // XMPP
  216. define ( 'NETWORK_MYSPACE', 'mysp'); // MySpace
  217. define ( 'NETWORK_GPLUS', 'goog'); // Google+
  218. define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder
  219. /**
  220. * Permissions
  221. */
  222. define ( 'PERMS_R_STREAM', 0x00001);
  223. define ( 'PERMS_R_PROFILE', 0x00002);
  224. define ( 'PERMS_R_PHOTOS', 0x00004);
  225. define ( 'PERMS_R_ABOOK', 0x00008);
  226. define ( 'PERMS_W_STREAM', 0x00010);
  227. define ( 'PERMS_W_WALL', 0x00020);
  228. define ( 'PERMS_W_TAGWALL', 0x00040);
  229. define ( 'PERMS_W_COMMENT', 0x00080);
  230. define ( 'PERMS_W_MAIL', 0x00100);
  231. define ( 'PERMS_W_PHOTOS', 0x00200);
  232. define ( 'PERMS_W_CHAT', 0x00400);
  233. define ( 'PERMS_A_DELEGATE', 0x00800);
  234. define ( 'PERMS_R_STORAGE', 0x01000);
  235. define ( 'PERMS_W_STORAGE', 0x02000);
  236. define ( 'PERMS_R_PAGES', 0x04000);
  237. define ( 'PERMS_W_PAGES', 0x08000);
  238. define ( 'PERMS_A_REPUBLISH', 0x10000);
  239. define ( 'PERMS_W_LIKE', 0x20000);
  240. // General channel permissions
  241. // 0 = Only you
  242. define ( 'PERMS_PUBLIC' , 0x0001 ); // anybody
  243. define ( 'PERMS_NETWORK' , 0x0002 ); // anybody in this network
  244. define ( 'PERMS_SITE' , 0x0004 ); // anybody on this site
  245. define ( 'PERMS_CONTACTS' , 0x0008 ); // any of my connections
  246. define ( 'PERMS_SPECIFIC' , 0x0080 ); // only specific connections
  247. define ( 'PERMS_AUTHED' , 0x0100 ); // anybody authenticated (could include visitors from other networks)
  248. define ( 'PERMS_PENDING' , 0x0200 ); // any connections including those who haven't yet been approved
  249. // Address book flags
  250. define ( 'ABOOK_FLAG_BLOCKED' , 0x0001);
  251. define ( 'ABOOK_FLAG_IGNORED' , 0x0002);
  252. define ( 'ABOOK_FLAG_HIDDEN' , 0x0004);
  253. define ( 'ABOOK_FLAG_ARCHIVED' , 0x0008);
  254. define ( 'ABOOK_FLAG_PENDING' , 0x0010);
  255. define ( 'ABOOK_FLAG_UNCONNECTED', 0x0020);
  256. define ( 'ABOOK_FLAG_SELF' , 0x0080);
  257. define ( 'ABOOK_FLAG_FEED' , 0x0100);
  258. define ( 'MAIL_DELETED', 0x0001);
  259. define ( 'MAIL_REPLIED', 0x0002);
  260. define ( 'MAIL_ISREPLY', 0x0004);
  261. define ( 'MAIL_SEEN', 0x0008);
  262. define ( 'MAIL_RECALLED', 0x0010);
  263. define ( 'MAIL_OBSCURED', 0x0020);
  264. define ( 'ATTACH_FLAG_DIR', 0x0001);
  265. define ( 'ATTACH_FLAG_OS', 0x0002);
  266. define ( 'MENU_ITEM_ZID', 0x0001);
  267. define ( 'MENU_ITEM_NEWWIN', 0x0002);
  268. define ( 'MENU_ITEM_CHATROOM', 0x0004);
  269. define ( 'SITE_TYPE_ZOT', 0);
  270. define ( 'SITE_TYPE_NOTZOT', 1);
  271. define ( 'SITE_TYPE_UNKNOWN', 2);
  272. /**
  273. * Poll/Survey types
  274. */
  275. define ( 'POLL_SIMPLE_RATING', 0x0001); // 1-5
  276. define ( 'POLL_TENSCALE', 0x0002); // 1-10
  277. define ( 'POLL_MULTIPLE_CHOICE', 0x0004);
  278. define ( 'POLL_OVERWRITE', 0x8000); // If you vote twice remove the prior entry
  279. define ( 'UPDATE_FLAGS_UPDATED', 0x0001);
  280. define ( 'UPDATE_FLAGS_FORCED', 0x0002);
  281. define ( 'UPDATE_FLAGS_DELETED', 0x1000);
  282. define ( 'DROPITEM_NORMAL', 0);
  283. define ( 'DROPITEM_PHASE1', 1);
  284. define ( 'DROPITEM_PHASE2', 2);
  285. /**
  286. * Maximum number of "people who like (or don't like) this" that we will list by name
  287. */
  288. define ( 'MAX_LIKERS', 10);
  289. /**
  290. * Communication timeout
  291. */
  292. define ( 'ZCURL_TIMEOUT' , (-1));
  293. /**
  294. * email notification options
  295. */
  296. define ( 'NOTIFY_INTRO', 0x0001 );
  297. define ( 'NOTIFY_CONFIRM', 0x0002 );
  298. define ( 'NOTIFY_WALL', 0x0004 );
  299. define ( 'NOTIFY_COMMENT', 0x0008 );
  300. define ( 'NOTIFY_MAIL', 0x0010 );
  301. define ( 'NOTIFY_SUGGEST', 0x0020 );
  302. define ( 'NOTIFY_PROFILE', 0x0040 );
  303. define ( 'NOTIFY_TAGSELF', 0x0080 );
  304. define ( 'NOTIFY_TAGSHARE', 0x0100 );
  305. define ( 'NOTIFY_POKE', 0x0200 );
  306. define ( 'NOTIFY_LIKE', 0x0400 );
  307. define ( 'NOTIFY_SYSTEM', 0x8000 );
  308. /**
  309. * visual notification options
  310. */
  311. define ( 'VNOTIFY_NETWORK', 0x0001 );
  312. define ( 'VNOTIFY_CHANNEL', 0x0002 );
  313. define ( 'VNOTIFY_MAIL', 0x0004 );
  314. define ( 'VNOTIFY_EVENT', 0x0008 );
  315. define ( 'VNOTIFY_EVENTTODAY', 0x0010 );
  316. define ( 'VNOTIFY_BIRTHDAY', 0x0020 );
  317. define ( 'VNOTIFY_SYSTEM', 0x0040 );
  318. define ( 'VNOTIFY_INFO', 0x0080 );
  319. define ( 'VNOTIFY_ALERT', 0x0100 );
  320. define ( 'VNOTIFY_INTRO', 0x0200 );
  321. define ( 'VNOTIFY_REGISTER', 0x0400 );
  322. define ( 'VNOTIFY_FILES', 0x0800 );
  323. define ( 'VNOTIFY_PUBS', 0x1000 );
  324. define ( 'VNOTIFY_LIKE', 0x2000 );
  325. define ( 'VNOTIFY_FORUMS', 0x4000 );
  326. /**
  327. * Tag/term types
  328. */
  329. define ( 'TERM_UNKNOWN', 0 );
  330. define ( 'TERM_HASHTAG', 1 );
  331. define ( 'TERM_MENTION', 2 );
  332. define ( 'TERM_CATEGORY', 3 );
  333. define ( 'TERM_PCATEGORY', 4 );
  334. define ( 'TERM_FILE', 5 );
  335. define ( 'TERM_SAVEDSEARCH', 6 );
  336. define ( 'TERM_THING', 7 );
  337. define ( 'TERM_BOOKMARK', 8 );
  338. define ( 'TERM_HIERARCHY', 9 );
  339. define ( 'TERM_COMMUNITYTAG', 10 );
  340. define ( 'TERM_FORUM', 11 );
  341. define ( 'TERM_EMOJI', 12 );
  342. define ( 'TERM_OBJ_POST', 1 );
  343. define ( 'TERM_OBJ_PHOTO', 2 );
  344. define ( 'TERM_OBJ_PROFILE', 3 );
  345. define ( 'TERM_OBJ_CHANNEL', 4 );
  346. define ( 'TERM_OBJ_OBJECT', 5 );
  347. define ( 'TERM_OBJ_THING', 6 );
  348. define ( 'TERM_OBJ_APP', 7 );
  349. /**
  350. * various namespaces we may need to parse
  351. */
  352. define ( 'PROTOCOL_ZOT', 'http://purl.org/zot/protocol' );
  353. define ( 'PROTOCOL_ZOT6', 'http://purl.org/zot/protocol/6.0' );
  354. define ( 'NAMESPACE_ZOT', 'http://purl.org/zot' );
  355. define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
  356. define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' );
  357. define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
  358. define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
  359. define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/' );
  360. define ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' );
  361. define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
  362. define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
  363. define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );
  364. define ( 'NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0' );
  365. define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from' );
  366. define ( 'NAMESPACE_OSTATUS', 'http://ostatus.org/schema/1.0' );
  367. define ( 'NAMESPACE_STATUSNET', 'http://status.net/schema/api/1/' );
  368. define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
  369. define ( 'NAMESPACE_YMEDIA', 'http://search.yahoo.com/mrss/' );
  370. // We should be using versioned jsonld contexts so that signatures will be slightly more reliable.
  371. // Why signatures are unreliable by design is a problem nobody seems to care about
  372. // "because it's a proposed W3C standard". .
  373. // Anyway, if you use versioned contexts, communication with Mastodon fails. Have not yet investigated
  374. // the reason for the dependency but for the current time, use the standard non-versioned context.
  375. //define ( 'ACTIVITYSTREAMS_JSONLD_REV', 'https://www.w3.org/ns/activitystreams-history/v1.8.jsonld' );
  376. define ( 'ACTIVITYSTREAMS_JSONLD_REV', 'https://www.w3.org/ns/activitystreams' );
  377. define ( 'ZOT_APSCHEMA_REV', '/apschema/v1.8' );
  378. /**
  379. * activity stream defines
  380. */
  381. define ( 'ACTIVITY_PUBLIC_INBOX', 'https://www.w3.org/ns/activitystreams#Public' );
  382. define ( 'ACTIVITY_REACT', NAMESPACE_ZOT . '/activity/react' );
  383. define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
  384. define ( 'ACTIVITY_DISLIKE', NAMESPACE_ZOT . '/activity/dislike' );
  385. define ( 'ACTIVITY_AGREE', NAMESPACE_ZOT . '/activity/agree' );
  386. define ( 'ACTIVITY_DISAGREE', NAMESPACE_ZOT . '/activity/disagree' );
  387. define ( 'ACTIVITY_ABSTAIN', NAMESPACE_ZOT . '/activity/abstain' );
  388. define ( 'ACTIVITY_ATTEND', NAMESPACE_ZOT . '/activity/attendyes' );
  389. define ( 'ACTIVITY_ATTENDNO', NAMESPACE_ZOT . '/activity/attendno' );
  390. define ( 'ACTIVITY_ATTENDMAYBE', NAMESPACE_ZOT . '/activity/attendmaybe' );
  391. define ( 'ACTIVITY_POLLRESPONSE', NAMESPACE_ZOT . '/activity/pollresponse' );
  392. define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_ZOT . '/activity/heart' );
  393. define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
  394. define ( 'ACTIVITY_REQ_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'request-friend' );
  395. define ( 'ACTIVITY_UNFRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'remove-friend' );
  396. define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
  397. define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
  398. define ( 'ACTIVITY_JOIN', NAMESPACE_ACTIVITY_SCHEMA . 'join' );
  399. define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
  400. define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
  401. define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
  402. define ( 'ACTIVITY_SHARE', NAMESPACE_ACTIVITY_SCHEMA . 'share' );
  403. define ( 'ACTIVITY_FAVORITE', NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
  404. define ( 'ACTIVITY_CREATE', NAMESPACE_ACTIVITY_SCHEMA . 'create' );
  405. define ( 'ACTIVITY_DELETE', NAMESPACE_ACTIVITY_SCHEMA . 'delete' );
  406. define ( 'ACTIVITY_WIN', NAMESPACE_ACTIVITY_SCHEMA . 'win' );
  407. define ( 'ACTIVITY_LOSE', NAMESPACE_ACTIVITY_SCHEMA . 'lose' );
  408. define ( 'ACTIVITY_TIE', NAMESPACE_ACTIVITY_SCHEMA . 'tie' );
  409. define ( 'ACTIVITY_COMPLETE', NAMESPACE_ACTIVITY_SCHEMA . 'complete' );
  410. define ( 'ACTIVITY_POKE', NAMESPACE_ZOT . '/activity/poke' );
  411. define ( 'ACTIVITY_MOOD', NAMESPACE_ZOT . '/activity/mood' );
  412. define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
  413. define ( 'ACTIVITY_OBJ_ACTIVITY',NAMESPACE_ACTIVITY_SCHEMA . 'activity' );
  414. define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' );
  415. define ( 'ACTIVITY_OBJ_ARTICLE', NAMESPACE_ACTIVITY_SCHEMA . 'article' );
  416. define ( 'ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person' );
  417. define ( 'ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo' );
  418. define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' );
  419. define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' );
  420. define ( 'ACTIVITY_OBJ_EVENT', NAMESPACE_ACTIVITY_SCHEMA . 'event' );
  421. define ( 'ACTIVITY_OBJ_GROUP', NAMESPACE_ACTIVITY_SCHEMA . 'group' );
  422. define ( 'ACTIVITY_OBJ_GAME', NAMESPACE_ACTIVITY_SCHEMA . 'game' );
  423. define ( 'ACTIVITY_OBJ_WIKI', NAMESPACE_ACTIVITY_SCHEMA . 'wiki' );
  424. define ( 'ACTIVITY_OBJ_TAGTERM', NAMESPACE_ZOT . '/activity/tagterm' );
  425. define ( 'ACTIVITY_OBJ_PROFILE', NAMESPACE_ZOT . '/activity/profile' );
  426. define ( 'ACTIVITY_OBJ_THING', NAMESPACE_ZOT . '/activity/thing' );
  427. define ( 'ACTIVITY_OBJ_LOCATION',NAMESPACE_ZOT . '/activity/location' );
  428. define ( 'ACTIVITY_OBJ_FILE', NAMESPACE_ZOT . '/activity/file' );
  429. define ( 'ACTIVITY_OBJ_CARD', NAMESPACE_ZOT . '/activity/card' );
  430. /**
  431. * Account Flags
  432. */
  433. define ( 'ACCOUNT_OK', 0x0000 );
  434. define ( 'ACCOUNT_UNVERIFIED', 0x0001 );
  435. define ( 'ACCOUNT_BLOCKED', 0x0002 );
  436. define ( 'ACCOUNT_EXPIRED', 0x0004 );
  437. define ( 'ACCOUNT_REMOVED', 0x0008 );
  438. define ( 'ACCOUNT_PENDING', 0x0010 );
  439. /**
  440. * Account roles
  441. */
  442. define ( 'ACCOUNT_ROLE_SYSTEM', 0x0002 );
  443. define ( 'ACCOUNT_ROLE_DEVELOPER', 0x0004 );
  444. define ( 'ACCOUNT_ROLE_ADMIN', 0x1000 );
  445. /**
  446. * Item visibility
  447. */
  448. define ( 'ITEM_VISIBLE', 0x0000);
  449. define ( 'ITEM_HIDDEN', 0x0001);
  450. define ( 'ITEM_BLOCKED', 0x0002);
  451. define ( 'ITEM_MODERATED', 0x0004);
  452. define ( 'ITEM_SPAM', 0x0008);
  453. define ( 'ITEM_DELETED', 0x0010);
  454. define ( 'ITEM_UNPUBLISHED', 0x0020);
  455. define ( 'ITEM_WEBPAGE', 0x0040); // is a static web page, not a conversational item
  456. define ( 'ITEM_DELAYED_PUBLISH', 0x0080);
  457. define ( 'ITEM_BUILDBLOCK', 0x0100); // Named thusly to make sure nobody confuses this with ITEM_BLOCKED
  458. define ( 'ITEM_PDL', 0x0200); // Page Description Language - e.g. Comanche
  459. define ( 'ITEM_BUG', 0x0400); // Is a bug, can be used by the internal bug tracker
  460. define ( 'ITEM_PENDING_REMOVE', 0x0800); // deleted, notification period has lapsed
  461. define ( 'ITEM_DOC', 0x1000); // hubzilla only, define here so that item import does the right thing
  462. define ( 'ITEM_CARD', 0x2000);
  463. define ( 'ITEM_ARTICLE', 0x4000);
  464. define ( 'ITEM_TYPE_POST', 0 );
  465. define ( 'ITEM_TYPE_BLOCK', 1 );
  466. define ( 'ITEM_TYPE_PDL', 2 );
  467. define ( 'ITEM_TYPE_WEBPAGE', 3 );
  468. define ( 'ITEM_TYPE_BUG', 4 );
  469. define ( 'ITEM_TYPE_DOC', 5 );
  470. define ( 'ITEM_TYPE_CARD', 6 );
  471. define ( 'ITEM_TYPE_ARTICLE', 7 );
  472. //OSADA ITEM_TYPE_MAIL = 8
  473. define ( 'ITEM_TYPE_CUSTOM', 9 );
  474. define ( 'ITEM_IS_STICKY', 1000 );
  475. define ( 'DBTYPE_MYSQL', 0 );
  476. define ( 'DBTYPE_POSTGRES', 1 );
  477. function sys_boot() {
  478. // our central App object
  479. App::init();
  480. /*
  481. * Load the configuration file which contains our DB credentials.
  482. * Ignore errors. If the file doesn't exist or is empty, we are running in
  483. * installation mode.
  484. */
  485. // miniApp is a conversion object from old style .htconfig.php files
  486. $a = new miniApp;
  487. App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
  488. @include('.htconfig.php');
  489. // allow somebody to set some initial settings just in case they can't
  490. // install without special fiddling
  491. if(App::$install && file_exists('.htpreconfig.php'))
  492. @include('.htpreconfig.php');
  493. if(array_key_exists('default_timezone',get_defined_vars())) {
  494. App::$config['system']['timezone'] = $default_timezone;
  495. }
  496. $a->convert();
  497. App::$config['system']['server_role'] = 'pro';
  498. App::$timezone = ((App::$config['system']['timezone']) ? App::$config['system']['timezone'] : 'UTC');
  499. date_default_timezone_set(App::$timezone);
  500. if(! defined('DEFAULT_PLATFORM_ICON')) {
  501. define( 'DEFAULT_PLATFORM_ICON', '/images/hz-32.png' );
  502. }
  503. if(! defined('DEFAULT_NOTIFY_ICON')) {
  504. define( 'DEFAULT_NOTIFY_ICON', '/images/hz-white-64.png' );
  505. }
  506. App::head_set_icon(DEFAULT_PLATFORM_ICON);
  507. /*
  508. * Try to open the database;
  509. */
  510. require_once('include/dba/dba_driver.php');
  511. if(! App::$install) {
  512. DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, App::$install);
  513. if(! DBA::$dba->connected) {
  514. system_unavailable();
  515. }
  516. unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
  517. /*
  518. * Load configs from db. Overwrite configs from .htconfig.php
  519. */
  520. load_config('system');
  521. load_config('feature');
  522. App::$session = new Zotlabs\Web\Session();
  523. App::$session->init();
  524. load_hooks();
  525. /**
  526. * @hooks init_1
  527. */
  528. call_hooks('init_1');
  529. }
  530. }
  531. function startup() {
  532. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  533. // Some hosting providers block/disable this
  534. @set_time_limit(0);
  535. if(function_exists ('ini_set')) {
  536. // This has to be quite large to deal with embedded private photos
  537. @ini_set('pcre.backtrack_limit', 500000);
  538. // Use cookies to store the session ID on the client side
  539. @ini_set('session.use_only_cookies', 1);
  540. // Disable transparent Session ID support
  541. @ini_set('session.use_trans_sid', 0);
  542. }
  543. }
  544. /**
  545. * class miniApp
  546. *
  547. * this is a transient structure which is needed to convert the $a->config settings
  548. * from older (existing) htconfig files which used a global App ($a) into the updated App structure
  549. * which is now static (although currently constructed at startup). We are only converting
  550. * 'system' config settings.
  551. */
  552. class miniApp {
  553. public $config = array('system' => array());
  554. public function convert() {
  555. if($this->config['system']) {
  556. foreach($this->config['system'] as $k => $v)
  557. App::$config['system'][$k] = $v;
  558. }
  559. }
  560. }
  561. /**
  562. * class: App
  563. *
  564. * @brief Our main application structure for the life of this page.
  565. *
  566. * Primarily deals with the URL that got us here
  567. * and tries to make some sense of it, and
  568. * stores our page contents and config storage
  569. * and anything else that might need to be passed around
  570. * before we spit the page out.
  571. *
  572. */
  573. class App {
  574. public static $install = false; // true if we are installing the software
  575. public static $account = null; // account record of the logged-in account
  576. public static $channel = null; // channel record of the current channel of the logged-in account
  577. public static $observer = null; // xchan record of the page observer
  578. public static $profile_uid = 0; // If applicable, the channel_id of the "page owner"
  579. public static $poi = null; // "person of interest", generally a referenced connection
  580. private static $oauth_key = null; // consumer_id of oauth request, if used
  581. public static $layout = array(); // Comanche parsed template
  582. public static $pdl = null; // Comanche page description
  583. private static $perms = null; // observer permissions
  584. private static $widgets = array(); // widgets for this page
  585. public static $config = array(); // config cache
  586. public static $override_intltext_templates = array();
  587. public static $override_markup_templates = array();
  588. public static $override_templateroot = null;
  589. public static $override_helproot = null;
  590. public static $override_helpfiles = array();
  591. public static $session = null;
  592. public static $groups;
  593. public static $language;
  594. public static $langsave;
  595. public static $rtl = false;
  596. public static $plugins_admin;
  597. public static $module_loaded = false;
  598. public static $query_string;
  599. public static $page;
  600. public static $profile;
  601. public static $user;
  602. public static $cid;
  603. public static $contact;
  604. public static $contacts;
  605. public static $content;
  606. public static $data = array();
  607. public static $error = false;
  608. public static $emojitab = false;
  609. public static $cmd;
  610. public static $argv;
  611. public static $argc;
  612. public static $module;
  613. public static $pager;
  614. public static $strings;
  615. public static $stringsave; // used in push_lang() and pop_lang()
  616. public static $hooks;
  617. public static $timezone;
  618. public static $interactive = true;
  619. public static $plugins;
  620. private static $apps = array();
  621. public static $identities;
  622. public static $css_sources = array();
  623. public static $js_sources = array();
  624. public static $linkrel = array();
  625. public static $theme_info = array();
  626. public static $is_sys = false;
  627. public static $nav_sel;
  628. public static $comanche;
  629. public static $channel_links;
  630. public static $category;
  631. // Allow themes to control internal parameters
  632. // by changing App values in theme.php
  633. public static $sourcename = '';
  634. public static $videowidth = 425;
  635. public static $videoheight = 350;
  636. public static $force_max_items = 0;
  637. public static $theme_thread_allow = true;
  638. /**
  639. * @brief An array for all theme-controllable parameters
  640. *
  641. * Mostly unimplemented yet. Only options 'template_engine' and
  642. * beyond are used.
  643. */
  644. private static $theme = array(
  645. 'sourcename' => '',
  646. 'videowidth' => 425,
  647. 'videoheight' => 350,
  648. 'force_max_items' => 0,
  649. 'thread_allow' => true,
  650. 'stylesheet' => '',
  651. 'template_engine' => 'smarty3',
  652. );
  653. /**
  654. * @brief An array of registered template engines ('name'=>'class name')
  655. */
  656. public static $template_engines = array();
  657. /**
  658. * @brief An array of instanced template engines ('name'=>'instance')
  659. */
  660. public static $template_engine_instance = array();
  661. private static $ldelim = array(
  662. 'internal' => '',
  663. 'smarty3' => '{{'
  664. );
  665. private static $rdelim = array(
  666. 'internal' => '',
  667. 'smarty3' => '}}'
  668. );
  669. // These represent the URL which was used to access the page
  670. private static $scheme;
  671. private static $hostname;
  672. private static $path;
  673. // This is our standardised URL - regardless of what was used
  674. // to access the page
  675. private static $baseurl;
  676. private static $meta;
  677. /**
  678. * App constructor.
  679. */
  680. public static function init() {
  681. // we'll reset this after we read our config file
  682. date_default_timezone_set('UTC');
  683. self::$config = array('system'=>array());
  684. self::$page = array();
  685. self::$pager= array();
  686. self::$query_string = '';
  687. startup();
  688. set_include_path(
  689. 'include' . PATH_SEPARATOR
  690. . 'library' . PATH_SEPARATOR
  691. . 'library/langdet' . PATH_SEPARATOR
  692. . '.' );
  693. self::$scheme = 'http';
  694. if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS'])
  695. self::$scheme = 'https';
  696. elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443))
  697. self::$scheme = 'https';
  698. if(x($_SERVER,'SERVER_NAME')) {
  699. self::$hostname = punify($_SERVER['SERVER_NAME']);
  700. if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
  701. self::$hostname .= ':' . $_SERVER['SERVER_PORT'];
  702. /*
  703. * Figure out if we are running at the top of a domain
  704. * or in a sub-directory and adjust accordingly
  705. */
  706. $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
  707. if(isset($path) && strlen($path) && ($path != self::$path))
  708. self::$path = $path;
  709. }
  710. if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") {
  711. self::$query_string = str_replace(['<','>'],['&lt;','&gt;'],substr($_SERVER['QUERY_STRING'], 2));
  712. // removing trailing / - maybe a nginx problem
  713. if (substr(self::$query_string, 0, 1) == "/")
  714. self::$query_string = substr(self::$query_string, 1);
  715. // change the first & to ?
  716. self::$query_string = preg_replace('/&/','?',self::$query_string,1);
  717. }
  718. if(x($_GET,'q'))
  719. self::$cmd = escape_tags(trim($_GET['q'],'/\\'));
  720. // Serve raw files from the file system in certain cases.
  721. $filext = pathinfo(self::$cmd, PATHINFO_EXTENSION);
  722. $serve_rawfiles=[
  723. 'jpg'=>'image/jpeg',
  724. 'jpeg'=>'image/jpeg',
  725. 'gif'=>'image/gif',
  726. 'png'=>'image/png',
  727. 'ico'=>'image/vnd.microsoft.icon',
  728. 'css'=>'text/css',
  729. 'js'=>'text/javascript',
  730. 'htm'=>'text/html',
  731. 'html'=>'text/html',
  732. 'map'=>'application/octet-stream',
  733. 'ttf'=>'font/ttf',
  734. 'woff'=>'font/woff',
  735. 'woff2'=>'font/woff2',
  736. 'svg'=>'image/svg+xml'];
  737. if (array_key_exists($filext, $serve_rawfiles) && file_exists(self::$cmd)) {
  738. $staticfilecwd = getcwd();
  739. $staticfilerealpath = realpath(self::$cmd);
  740. if(strpos($staticfilerealpath,$staticfilecwd) !== 0) {
  741. http_status_exit(404,'not found');
  742. }
  743. $staticfileetag = '"'.md5($staticfilerealpath.filemtime(self::$cmd)).'"';
  744. header("ETag: ".$staticfileetag);
  745. header("Cache-control: max-age=2592000");
  746. if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
  747. // If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache
  748. // So send a 304 Not Modified response header and exit
  749. if($_SERVER['HTTP_IF_NONE_MATCH'] == $staticfileetag) {
  750. http_status_exit(304,'not modified');
  751. }
  752. }
  753. header("Content-type: ".$serve_rawfiles[$filext]);
  754. $handle = fopen(self::$cmd, "rb");
  755. fpassthru($handle);
  756. fclose($handle);
  757. killme();
  758. }
  759. // unix style "homedir"
  760. if((substr(self::$cmd, 0, 1) === '~') || (substr(self::$cmd, 0, 1) === '@'))
  761. self::$cmd = 'channel/' . substr(self::$cmd, 1);
  762. /*
  763. * Break the URL path into C style argc/argv style arguments for our
  764. * modules. Given "http://example.com/module/arg1/arg2", self::$argc
  765. * will be 3 (integer) and self::$argv will contain:
  766. * [0] => 'module'
  767. * [1] => 'arg1'
  768. * [2] => 'arg2'
  769. *
  770. * There will always be one argument. If provided a naked domain
  771. * URL, self::$argv[0] is set to "home".
  772. *
  773. * If $argv[0] has a period in it, for example foo.json; rewrite
  774. * to module = 'foo' and set $_REQUEST['module_format'] = 'json';
  775. */
  776. self::$argv = explode('/', self::$cmd);
  777. self::$argc = count(self::$argv);
  778. if ((array_key_exists('0', self::$argv)) && strlen(self::$argv[0])) {
  779. if(strpos(self::$argv[0],'.')) {
  780. $_REQUEST['module_format'] = substr(self::$argv[0],strpos(self::$argv[0],'.')+1);
  781. self::$argv[0] = substr(self::$argv[0],0,strpos(self::$argv[0],'.'));
  782. }
  783. self::$module = str_replace(".", "_", self::$argv[0]);
  784. self::$module = str_replace("-", "_", self::$module);
  785. if(strpos(self::$module,'_') === 0)
  786. self::$module = substr(self::$module,1);
  787. } else {
  788. self::$argc = 1;
  789. self::$argv = array('home');
  790. self::$module = 'home';
  791. }
  792. /*
  793. * See if there is any page number information, and initialise
  794. * pagination
  795. */
  796. self::$pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
  797. self::$pager['itemspage'] = 60;
  798. self::$pager['start'] = (self::$pager['page'] * self::$pager['itemspage']) - self::$pager['itemspage'];
  799. if(self::$pager['start'] < 0)
  800. self::$pager['start'] = 0;
  801. self::$pager['total'] = 0;
  802. /*
  803. * register template engines
  804. */
  805. self::$meta= new Zotlabs\Web\HttpMeta();
  806. // create an instance of the smarty template engine so we can register it.
  807. $smarty = new Zotlabs\Render\SmartyTemplate();
  808. /// @todo validate if this is still the desired behavior
  809. self::register_template_engine(get_class($smarty));
  810. }
  811. public static function get_baseurl($ssl = false) {
  812. if(is_array(self::$config)
  813. && array_key_exists('system',self::$config)
  814. && is_array(self::$config['system'])
  815. && array_key_exists('baseurl',self::$config['system'])
  816. && strlen(self::$config['system']['baseurl'])) {
  817. // get_baseurl() is a heavily used function.
  818. // Do not use punify() here until we find a library that performs better than what we have now.
  819. //$url = punify(self::$config['system']['baseurl']);
  820. $url = self::$config['system']['baseurl'];
  821. $url = trim($url,'\\/');
  822. return $url;
  823. }
  824. $scheme = self::$scheme;
  825. self::$baseurl = $scheme . "://" . punify(self::$hostname) . ((isset(self::$path) && strlen(self::$path)) ? '/' . self::$path : '' );
  826. return self::$baseurl;
  827. }
  828. public static function set_baseurl($url) {
  829. if(is_array(self::$config)
  830. && array_key_exists('system',self::$config)
  831. && is_array(self::$config['system'])
  832. && array_key_exists('baseurl',self::$config['system'])
  833. && strlen(self::$config['system']['baseurl'])) {
  834. $url = punify(self::$config['system']['baseurl']);
  835. $url = trim($url,'\\/');
  836. }
  837. $parsed = @parse_url($url);
  838. self::$baseurl = $url;
  839. if($parsed !== false) {
  840. self::$scheme = $parsed['scheme'];
  841. self::$hostname = punify($parsed['host']);
  842. if(x($parsed,'port'))
  843. self::$hostname .= ':' . $parsed['port'];
  844. if(x($parsed,'path'))
  845. self::$path = trim($parsed['path'],'\\/');
  846. }
  847. }
  848. public static function get_scheme() {
  849. return self::$scheme;
  850. }
  851. public static function get_hostname() {
  852. return self::$hostname;
  853. }
  854. public static function set_hostname($h) {
  855. self::$hostname = $h;
  856. }
  857. public static function set_path($p) {
  858. self::$path = trim(trim($p), '/');
  859. }
  860. public static function get_path() {
  861. return self::$path;
  862. }
  863. public static function get_channel_links() {
  864. $s = '';
  865. $x = self::$channel_links;
  866. if($x && is_array($x) && count($x)) {
  867. foreach($x as $y) {
  868. if($s) {
  869. $s .= ',';
  870. }
  871. $s .= '<' . $y['url'] . '>; rel="' . $y['rel'] . '"; type="' . $y['type'] . '"';
  872. }
  873. }
  874. return $s;
  875. }
  876. public static function set_account($acct) {
  877. self::$account = $acct;
  878. }
  879. public static function get_account() {
  880. return self::$account;
  881. }
  882. public static function set_channel($channel) {
  883. self::$channel = $channel;
  884. }
  885. public static function get_channel() {
  886. return self::$channel;
  887. }
  888. public static function set_observer($xchan) {
  889. self::$observer = $xchan;
  890. }
  891. public static function get_observer() {
  892. return self::$observer;
  893. }
  894. public static function set_perms($perms) {
  895. self::$perms = $perms;
  896. }
  897. public static function get_perms() {
  898. return self::$perms;
  899. }
  900. public static function set_oauth_key($consumer_id) {
  901. self::$oauth_key = $consumer_id;
  902. }
  903. public static function get_oauth_key() {
  904. return self::$oauth_key;
  905. }
  906. public static function get_apps() {
  907. return self::$apps;
  908. }
  909. public static function set_apps($arr) {
  910. self::$apps = $arr;
  911. }
  912. public static function set_groups($g) {
  913. self::$groups = $g;
  914. }
  915. public static function get_groups() {
  916. return self::$groups;
  917. }
  918. public static function set_pager_total($n) {
  919. self::$pager['total'] = intval($n);
  920. }
  921. public static function set_pager_itemspage($n) {
  922. self::$pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
  923. self::$pager['start'] = (self::$pager['page'] * self::$pager['itemspage']) - self::$pager['itemspage'];
  924. }
  925. public static function build_pagehead() {
  926. $user_scalable = ((local_channel()) ? get_pconfig(local_channel(),'system','user_scalable') : 0);
  927. if ($user_scalable === false)
  928. $user_scalable = 0;
  929. $preload_images = ((local_channel()) ? get_pconfig(local_channel(),'system','preload_images') : 0);
  930. if ($preload_images === false)
  931. $preload_images = 0;
  932. $interval = ((local_channel()) ? get_pconfig(local_channel(),'system','update_interval') : 80000);
  933. if($interval < 10000)
  934. $interval = 80000;
  935. if(! x(self::$page,'title'))
  936. self::$page['title'] = self::$config['system']['sitename'];
  937. $pagemeta = [ 'og:title' => self::$page['title'] ];
  938. call_hooks('page_meta',$pagemeta);
  939. foreach ($pagemeta as $metaproperty => $metavalue) {
  940. self::$meta->set($metaproperty,$metavalue);
  941. }
  942. self::$meta->set('generator', Zotlabs\Lib\System::get_platform_name());
  943. head_add_link(['rel' => 'shortcut icon', 'href' => head_get_icon()]);
  944. $x = [ 'header' => '' ];
  945. /**
  946. * @hooks build_pagehead
  947. * Called when creating the HTML page header.
  948. * * \e string \b header - Return the HTML header which should be added
  949. */
  950. call_hooks('build_pagehead', $x);
  951. /* put the head template at the beginning of page['htmlhead']
  952. * since the code added by the modules frequently depends on it
  953. * being first
  954. */
  955. self::$page['htmlhead'] = replace_macros(get_markup_template('head.tpl'),
  956. [
  957. '$preload_images' => $preload_images,
  958. '$user_scalable' => $user_scalable,
  959. '$query' => urlencode(self::$query_string),
  960. '$baseurl' => self::get_baseurl(),
  961. '$local_channel' => local_channel(),
  962. '$metas' => self::$meta->get(),
  963. '$plugins' => $x['header'],
  964. '$update_interval' => $interval,
  965. '$head_css' => head_get_css(),
  966. '$head_js' => head_get_js(),
  967. '$linkrel' => head_get_links(),
  968. '$js_strings' => js_strings(),
  969. '$zid' => get_my_address(),
  970. '$channel_id' => self::$profile['uid'],
  971. '$auto_save_draft' => ((feature_enabled(self::$profile['uid'], 'auto_save_draft')) ? "true" : "false")
  972. ]
  973. ) . self::$page['htmlhead'];
  974. // always put main.js at the end
  975. self::$page['htmlhead'] .= head_get_main_js();
  976. }
  977. /**
  978. * @brief Register template engine class.
  979. *
  980. * If $name is "", is used class static property $class::$name.
  981. *
  982. * @param string $class
  983. * @param string $name
  984. */
  985. public static function register_template_engine($class, $name = '') {
  986. if(! $name) {
  987. $v = get_class_vars($class);
  988. if(x($v, "name")) {
  989. $name = $v['name'];
  990. }
  991. }
  992. if (! $name) {
  993. echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
  994. killme();
  995. }
  996. self::$template_engines[$name] = $class;
  997. }
  998. /**
  999. * @brief Return template engine instance.
  1000. *
  1001. * If $name is not defined, return engine defined by theme, or default.
  1002. *
  1003. * @param string $name Template engine name
  1004. *
  1005. * @return object Template Engine instance
  1006. */
  1007. public static function template_engine($name = ''){
  1008. if($name !== '') {
  1009. $template_engine = $name;
  1010. }
  1011. else {
  1012. $template_engine = 'smarty3';
  1013. if(x(self::$theme, 'template_engine')) {
  1014. $template_engine = self::$theme['template_engine'];
  1015. }
  1016. }
  1017. if(isset(self::$template_engines[$template_engine])){
  1018. if(isset(self::$template_engine_instance[$template_engine])){
  1019. return self::$template_engine_instance[$template_engine];
  1020. }
  1021. else {
  1022. $class = self::$template_engines[$template_engine];
  1023. $obj = new $class;
  1024. self::$template_engine_instance[$template_engine] = $obj;
  1025. return $obj;
  1026. }
  1027. }
  1028. echo "template engine <tt>$template_engine</tt> is not registered!\n";
  1029. killme();
  1030. }
  1031. /**
  1032. * @brief Returns the active template engine.
  1033. *
  1034. * @return string
  1035. */
  1036. public static function get_template_engine() {
  1037. return self::$theme['template_engine'];
  1038. }
  1039. public static function set_template_engine($engine = 'smarty3') {
  1040. self::$theme['template_engine'] = $engine;
  1041. }
  1042. public static function get_template_ldelim($engine = 'smarty3') {
  1043. return self::$ldelim[$engine];
  1044. }
  1045. public static function get_template_rdelim($engine = 'smarty3') {
  1046. return self::$rdelim[$engine];
  1047. }
  1048. public static function head_set_icon($icon) {
  1049. self::$data['pageicon'] = $icon;
  1050. }
  1051. public static function head_get_icon() {
  1052. $icon = self::$data['pageicon'];
  1053. if(! strpos($icon,'://'))
  1054. $icon = z_root() . $icon;
  1055. return $icon;
  1056. }
  1057. } // End App class
  1058. /**
  1059. * @brief Multi-purpose function to check variable state.
  1060. *
  1061. * Usage: x($var) or $x($array, 'key')
  1062. *
  1063. * returns false if variable/key is not set
  1064. * if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0.
  1065. * e.g. x('') or x(0) returns 0;
  1066. *
  1067. * @param string|array $s variable to check
  1068. * @param string $k key inside the array to check
  1069. *
  1070. * @return bool|int
  1071. */
  1072. function x($s, $k = null) {
  1073. if($k != null) {
  1074. if((is_array($s)) && (array_key_exists($k, $s))) {
  1075. if($s[$k])
  1076. return (int) 1;
  1077. return (int) 0;
  1078. }
  1079. return false;
  1080. }
  1081. else {
  1082. if(isset($s)) {
  1083. if($s) {
  1084. return (int) 1;
  1085. }
  1086. return (int) 0;
  1087. }
  1088. return false;
  1089. }
  1090. }
  1091. /**
  1092. * @brief Called from db initialisation if db is dead.
  1093. *
  1094. * @ref include/system_unavailable.php will handle everything further.
  1095. */
  1096. function system_unavailable() {
  1097. include('include/system_unavailable.php');
  1098. system_down();
  1099. killme();
  1100. }
  1101. function clean_urls() {
  1102. // if(App::$config['system']['clean_urls'])
  1103. return true;
  1104. // return false;
  1105. }
  1106. function z_path() {
  1107. $base = z_root();
  1108. if(! clean_urls())
  1109. $base .= '/?q=';
  1110. return $base;
  1111. }
  1112. /**
  1113. * @brief Returns the baseurl.
  1114. *
  1115. * @see App::get_baseurl()
  1116. *
  1117. * @return string
  1118. */
  1119. function z_root() {
  1120. return App::get_baseurl();
  1121. }
  1122. /**
  1123. * @brief Return absolute URL for given $path.
  1124. *
  1125. * @param string $path
  1126. *
  1127. * @return string
  1128. */
  1129. function absurl($path) {
  1130. if(strpos($path, '/') === 0)
  1131. return z_path() . $path;
  1132. return $path;
  1133. }
  1134. function os_mkdir($path, $mode = 0777, $recursive = false) {
  1135. $oldumask = @umask(0);
  1136. $result = @mkdir($path, $mode, $recursive);
  1137. @umask($oldumask);
  1138. return $result;
  1139. }
  1140. /**
  1141. * @brief Recursively delete a directory.
  1142. *
  1143. * @param string $path
  1144. * @return boolean
  1145. */
  1146. function rrmdir($path) {
  1147. if(is_dir($path) === true) {
  1148. $files = array_diff(scandir($path), array('.', '..'));
  1149. foreach($files as $file) {
  1150. rrmdir(realpath($path) . '/' . $file);
  1151. }
  1152. return rmdir($path);
  1153. }
  1154. elseif(is_file($path) === true) {
  1155. return unlink($path);
  1156. }
  1157. return false;
  1158. }
  1159. /**
  1160. * @brief Function to check if request was an AJAX (xmlhttprequest) request.
  1161. *
  1162. * @return boolean
  1163. */
  1164. function is_ajax() {
  1165. return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
  1166. }
  1167. /**
  1168. * Primarily involved with database upgrade, but also sets the
  1169. * base url for use in cmdline programs which don't have
  1170. * $_SERVER variables, and synchronising the state of installed plugins.
  1171. */
  1172. function check_config() {
  1173. $saved = get_config('system','urlverify');
  1174. if(! $saved)
  1175. set_config('system','urlverify',bin2hex(z_root()));
  1176. if(($saved) && ($saved != bin2hex(z_root()))) {
  1177. // our URL changed. Do something.
  1178. $oldurl = hex2bin($saved);
  1179. logger('Baseurl changed!');
  1180. $oldhost = substr($oldurl, strpos($oldurl, '//') + 2);
  1181. $host = substr(z_root(), strpos(z_root(), '//') + 2);
  1182. $is_ip_addr = ((preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$host)) ? true : false);
  1183. $was_ip_addr = ((preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$oldhost)) ? true : false);
  1184. // only change the url to an ip address if it was already an ip and not a dns name
  1185. if((! $is_ip_addr) || ($is_ip_addr && $was_ip_addr)) {
  1186. fix_system_urls($oldurl,z_root());
  1187. set_config('system', 'urlverify', bin2hex(z_root()));
  1188. }
  1189. else
  1190. logger('Attempt to change baseurl from a DNS name to an IP address was refused.');
  1191. }
  1192. // This will actually set the url to the one stored in .htconfig, and ignore what
  1193. // we're passing - unless we are installing and it has never been set.
  1194. App::set_baseurl(z_root());
  1195. // Make sure each site has a system channel. This is now created on install
  1196. // so we just need to keep this around a couple of weeks until the hubs that
  1197. // already exist have one
  1198. $syschan_exists = get_sys_channel();
  1199. if (! $syschan_exists)
  1200. create_sys_channel();
  1201. $x = new \Zotlabs\Lib\DB_Upgrade(DB_UPDATE_VERSION);
  1202. plugins_sync();
  1203. load_hooks();
  1204. check_for_new_perms();
  1205. check_cron_broken();
  1206. }
  1207. function fix_system_urls($oldurl, $newurl) {
  1208. require_once('include/crypto.php');
  1209. logger('fix_system_urls: renaming ' . $oldurl . ' to ' . $newurl);
  1210. // Basically a site rename, but this can happen if you change from http to https for instance - even if the site name didn't change
  1211. // This should fix URL changes on our site, but other sites will end up with orphan hublocs which they will try to contact and will
  1212. // cause wasted communications.
  1213. // What we need to do after fixing this up is to send a revocation of the old URL to every other site that we communicate with so
  1214. // that they can clean up their hubloc tables (this includes directories).
  1215. // It's a very expensive operation so you don't want to have to do it often or after your site gets to be large.
  1216. $r = q("select xchan.*, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url like '%s'",
  1217. dbesc($oldurl . '%')
  1218. );
  1219. if($r) {
  1220. foreach($r as $rv) {
  1221. $channel_address = substr($rv['hubloc_addr'],0,strpos($rv['hubloc_addr'],'@'));
  1222. // get the associated channel. If we don't have a local channel, do nothing for this entry.
  1223. $c = q("select * from channel where channel_hash = '%s' limit 1",
  1224. dbesc($rv['hubloc_hash'])
  1225. );
  1226. if(! $c)
  1227. continue;
  1228. $parsed = @parse_url($newurl);
  1229. if(! $parsed)
  1230. continue;
  1231. $newhost = $parsed['host'];
  1232. // sometimes parse_url returns unexpected results.
  1233. if(strpos($newhost,'/') !== false)
  1234. $newhost = substr($newhost,0,strpos($newhost,'/'));
  1235. $rhs = $newhost . (($parsed['port']) ? ':' . $parsed['port'] : '');
  1236. // paths aren't going to work. You have to be at the (sub)domain root
  1237. // . (($parsed['path']) ? $parsed['path'] : '');
  1238. // The xchan_url might point to another nomadic identity clone
  1239. $replace_xchan_url = ((strpos($rv['xchan_url'],$oldurl) !== false) ? true : false);
  1240. $x = q("update xchan set xchan_addr = '%s', xchan_url = '%s', xchan_connurl = '%s', xchan_follow = '%s', xchan_connpage = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'",
  1241. dbesc($channel_address . '@' . $rhs),
  1242. dbesc(($replace_xchan_url) ? str_replace($oldurl,$newurl,$rv['xchan_url']) : $rv['xchan_url']),
  1243. dbesc(str_replace($oldurl,$newurl,$rv['xchan_connurl'])),
  1244. dbesc(str_replace($oldurl,$newurl,$rv['xchan_follow'])),
  1245. dbesc(str_replace($oldurl,$newurl,$rv['xchan_connpage'])),
  1246. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_l'])),
  1247. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_m'])),
  1248. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_s'])),
  1249. dbesc(datetime_convert()),
  1250. dbesc($rv['xchan_hash'])
  1251. );
  1252. $y = q("update hubloc set hubloc_addr = '%s', hubloc_url = '%s', hubloc_id_url = '%s', hubloc_url_sig = '%s', hubloc_host = '%s', hubloc_callback = '%s' where hubloc_hash = '%s' and hubloc_url = '%s'",
  1253. dbesc($channel_address . '@' . $rhs),
  1254. dbesc($newurl),
  1255. dbesc(str_replace($oldurl,$newurl,$rv['hubloc_id_url'])),
  1256. dbesc(($rv['hubloc_network'] === 'zot6') ? \Zotlabs\Lib\Libzot::sign($newurl,$c[0]['channel_prvkey']) : base64url_encode(rsa_sign($newurl,$c[0]['channel_prvkey']))),
  1257. dbesc($newhost),
  1258. dbesc(($rv['hubloc_network'] === 'zot6') ? $newurl . '/zot' : $newurl . '/post'),
  1259. dbesc($rv['xchan_hash']),
  1260. dbesc($oldurl)
  1261. );
  1262. $z = q("update profile set photo = '%s', thumb = '%s' where uid = %d",
  1263. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_l'])),
  1264. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_m'])),
  1265. intval($c[0]['channel_id'])
  1266. );
  1267. $m = q("select abook_id, abook_instance from abook where abook_instance like '%s' and abook_channel = %d",
  1268. dbesc('%' . $oldurl . '%'),
  1269. intval($c[0]['channel_id'])
  1270. );
  1271. if($m) {
  1272. foreach($m as $mm) {
  1273. q("update abook set abook_instance = '%s' where abook_id = %d",
  1274. dbesc(str_replace($oldurl,$newurl,$mm['abook_instance'])),
  1275. intval($mm['abook_id'])
  1276. );
  1277. }
  1278. }
  1279. Zotlabs\Daemon\Master::Summon(array('Notifier', 'refresh_all', $c[0]['channel_id']));
  1280. }
  1281. }
  1282. // now replace any remote xchans whose photos are stored locally (which will be most if not all remote xchans)
  1283. $r = q("select * from xchan where xchan_photo_l like '%s'",
  1284. dbesc($oldurl . '%')
  1285. );
  1286. if($r) {
  1287. foreach($r as $rv) {
  1288. $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' where xchan_hash = '%s'",
  1289. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_l'])),
  1290. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_m'])),
  1291. dbesc(str_replace($oldurl,$newurl,$rv['xchan_photo_s'])),
  1292. dbesc($rv['xchan_hash'])
  1293. );
  1294. }
  1295. }
  1296. }
  1297. /**
  1298. * @brief Wrapper for adding a login box.
  1299. *
  1300. * If $register == true provide a registration link. This will most always depend
  1301. * on the value of App::$config['system']['register_policy'].
  1302. * Returns the complete html for inserting into the page
  1303. *
  1304. * @param boolean $register (optional) default false
  1305. * @param string $form_id (optional) default \e main-login
  1306. * @param boolean $hiddens (optional) default false
  1307. * @param boolean $login_page (optional) default true
  1308. * @return string Parsed HTML code.
  1309. */
  1310. function login($register = false, $form_id = 'main-login', $hiddens = false, $login_page = true) {
  1311. $o = '';
  1312. $reg = null;
  1313. // Here's the current description of how the register link works (2018-05-15)
  1314. // Register links are enabled on the site home page and login page and navbar.
  1315. // They are not shown by default on other pages which may require login.
  1316. // If the register link is enabled and registration is closed, the request is directed
  1317. // to /pubsites. If registration is allowed, /register is the default destination
  1318. // system.register_link can over-ride the default behaviour and redirect to an arbitrary
  1319. // webpage for paid/custom or organisational registrations, regardless of whether
  1320. // registration is allowed.
  1321. // system.register_link may or may not be the same destination as system.sellpage
  1322. // system.sellpage is the destination linked from the /pubsites page on other sites. If
  1323. // system.sellpage is not set, the 'register' link in /pubsites will go to 'register' on your
  1324. // site.
  1325. // If system.register_link is set to the word 'none', no registration link will be shown on
  1326. // your site.
  1327. $register_policy = get_config('system','register_policy');
  1328. $reglink = get_config('system', 'register_link', z_root() . '/' . ((intval($register_policy) === REGISTER_CLOSED) ? 'pubsites' : 'register'));
  1329. if($reglink !== 'none') {
  1330. $reg = [
  1331. 'title' => t('Create an account to access services and applications'),
  1332. 'desc' => t('Register'),
  1333. 'link' => $reglink
  1334. ];
  1335. }
  1336. $dest_url = z_root() . '/' . App::$query_string;
  1337. if(local_channel()) {
  1338. $tpl = get_markup_template("logout.tpl");
  1339. }
  1340. else {
  1341. $tpl = get_markup_template("login.tpl");
  1342. if(strlen(App::$query_string))
  1343. $_SESSION['login_return_url'] = App::$query_string;
  1344. }
  1345. $o .= replace_macros($tpl,array(
  1346. '$dest_url' => $dest_url,
  1347. '$login_page' => $login_page,
  1348. '$logout' => t('Logout'),
  1349. '$login' => t('Login'),
  1350. '$remote_login' => t('Remote Authentication'),
  1351. '$form_id' => $form_id,
  1352. '$lname' => array('username', t('Login/Email') , '', ''),
  1353. '$lpassword' => array('password', t('Password'), '', ''),
  1354. '$remember_me' => array((($login_page) ? 'remember' : 'remember_me'), t('Remember me'), '', '',array(t('No'),t('Yes'))),
  1355. '$hiddens' => $hiddens,
  1356. '$register' => $reg,
  1357. '$lostpass' => t('Forgot your password?'),
  1358. '$lostlink' => t('Password Reset'),
  1359. ));
  1360. /**
  1361. * @hooks login_hook
  1362. * Called when generating the login form.
  1363. * * \e string with parsed HTML
  1364. */
  1365. call_hooks('login_hook', $o);
  1366. return $o;
  1367. }
  1368. /**
  1369. * @brief Used to end the current process, after saving session state.
  1370. */
  1371. function killme() {
  1372. register_shutdown_function('shutdown');
  1373. exit;
  1374. }
  1375. /**
  1376. * @brief Redirect to another URL and terminate this process.
  1377. */
  1378. function goaway($s) {
  1379. header("Location: $s");
  1380. killme();
  1381. }
  1382. function shutdown() {
  1383. }
  1384. /**
  1385. * @brief Returns the entity id of locally logged in account or false.
  1386. *
  1387. * Returns numeric account_id if authenticated or 0. It is possible to be
  1388. * authenticated and not connected to a channel.
  1389. *
  1390. * @return int|bool account_id or false
  1391. */
  1392. function get_account_id() {
  1393. if(intval($_SESSION['account_id']))
  1394. return intval($_SESSION['account_id']);
  1395. if(App::$account)
  1396. return intval(App::$account['account_id']);
  1397. return false;
  1398. }
  1399. /**
  1400. * @brief Returns the entity id (channel_id) of locally logged in channel or false.
  1401. *
  1402. * Returns authenticated numeric channel_id if authenticated and connected to
  1403. * a channel or 0. Sometimes referred to as $uid in the code.
  1404. *
  1405. * Before 2.1 this function was called local_user().
  1406. *
  1407. * @since 2.1
  1408. * @return int|bool channel_id or false
  1409. */
  1410. function local_channel() {
  1411. if(session_id()
  1412. && array_key_exists('authenticated',$_SESSION) && $_SESSION['authenticated']
  1413. && array_key_exists('uid',$_SESSION) && intval($_SESSION['uid']))
  1414. return intval($_SESSION['uid']);
  1415. return false;
  1416. }
  1417. /**
  1418. * @brief Returns a xchan_hash (visitor_id) of remote authenticated visitor
  1419. * or false.
  1420. *
  1421. * Returns authenticated string hash of Red global identifier (xchan_hash), if
  1422. * authenticated via remote auth, or an empty string.
  1423. *
  1424. * Before 2.1 this function was called remote_user().
  1425. *
  1426. * @since 2.1
  1427. * @return string|bool visitor_id or false
  1428. */
  1429. function remote_channel() {
  1430. if(session_id()
  1431. && array_key_exists('authenticated',$_SESSION) && $_SESSION['authenticated']
  1432. && array_key_exists('visitor_id',$_SESSION) && $_SESSION['visitor_id'])
  1433. return $_SESSION['visitor_id'];
  1434. return false;
  1435. }
  1436. function can_view_public_stream() {
  1437. if(observer_prohibited(true)) {
  1438. return false;
  1439. }
  1440. if(! (intval(get_config('system','open_pubstream',1)))) {
  1441. if(! get_observer_hash()) {
  1442. return false;
  1443. }
  1444. }
  1445. $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false);
  1446. $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true);
  1447. if(! ($site_firehose || $net_firehose)) {
  1448. return false;
  1449. }
  1450. return true;
  1451. }
  1452. /**
  1453. * @brief Show an error or alert text on next page load.
  1454. *
  1455. * Contents of $s are displayed prominently on the page the next time
  1456. * a page is loaded. Usually used for errors or alerts.
  1457. *
  1458. * For informational text use info().
  1459. *
  1460. * @param string $s Text to display
  1461. */
  1462. function notice($s) {
  1463. if(! session_id())
  1464. return;
  1465. if(! x($_SESSION, 'sysmsg')) $_SESSION['sysmsg'] = array();
  1466. // ignore duplicated error messages which haven't yet been displayed
  1467. // - typically seen as multiple 'permission denied' messages
  1468. // as a result of auto-reloading a protected page with &JS=1
  1469. if(in_array($s, $_SESSION['sysmsg']))
  1470. return;
  1471. if(App::$interactive) {
  1472. $_SESSION['sysmsg'][] = $s;
  1473. }
  1474. }
  1475. /**
  1476. * @brief Show an information text on next page load.
  1477. *
  1478. * Contents of $s are displayed prominently on the page the next time a page is
  1479. * loaded. Usually used for information.
  1480. *
  1481. * For error and alerts use notice().
  1482. *
  1483. * @param string $s Text to display
  1484. */
  1485. function info($s) {
  1486. if(! session_id())
  1487. return;
  1488. if(! x($_SESSION, 'sysmsg_info'))
  1489. $_SESSION['sysmsg_info'] = array();
  1490. if(in_array($s, $_SESSION['sysmsg_info']))
  1491. return;
  1492. if(App::$interactive)
  1493. $_SESSION['sysmsg_info'][] = $s;
  1494. }
  1495. /**
  1496. * @brief Wrapper around config to limit the text length of an incoming message.
  1497. *
  1498. * @return int
  1499. */
  1500. function get_max_import_size() {
  1501. return(intval(get_config('system', 'max_import_size')));
  1502. }
  1503. /**
  1504. * @brief Wrap calls to proc_close(proc_open()) and call hook
  1505. * so plugins can take part in process :)
  1506. *
  1507. * args:
  1508. * $cmd program to run
  1509. * next args are passed as $cmd command line
  1510. *
  1511. * e.g.:
  1512. * @code{.php}proc_run("ls", "-la", "/tmp");@endcode
  1513. *
  1514. * $cmd and string args are surrounded with ""
  1515. */
  1516. function proc_run(){
  1517. $args = func_get_args();
  1518. if(! count($args))
  1519. return;
  1520. $args = flatten_array_recursive($args);
  1521. $arr = [
  1522. 'args' => $args,
  1523. 'run_cmd' => true
  1524. ];
  1525. /**
  1526. * @hooks proc_run
  1527. * Called when invoking PHP sub processes.
  1528. * * \e array \b args
  1529. * * \e boolean \b run_cmd
  1530. */
  1531. call_hooks('proc_run', $arr);
  1532. if(! $arr['run_cmd'])
  1533. return;
  1534. if(count($args) && $args[0] === 'php')
  1535. $args[0] = ((x(App::$config,'system')) && (x(App::$config['system'],'php_path')) && (strlen(App::$config['system']['php_path'])) ? App::$config['system']['php_path'] : 'php');
  1536. // redirect proc_run statements of legacy daemon processes to the newer Daemon Master object class
  1537. // We will keep this interface until everybody has transitioned. (2016-05-20)
  1538. if(strstr($args[1],'include/')) {
  1539. // convert 'include/foo.php' to 'Foo'
  1540. $orig = substr(ucfirst(substr($args[1],8)),0,-4);
  1541. logger('proc_run_redirect: ' . $orig);
  1542. if(file_exists('Zotlabs/Daemon/' . $orig . '.php')) {
  1543. array_shift($args); // daemons are all run by php, pop it off the top of the array
  1544. $args[0] = $orig; // replace with the new daemon name
  1545. logger('Redirecting old proc_run interface: ' . print_r($args,true), LOGGER_DEBUG, LOG_DEBUG);
  1546. \Zotlabs\Daemon\Master::Summon($args); // summon the daemon
  1547. return;
  1548. }
  1549. }
  1550. $args = array_map('escapeshellarg',$args);
  1551. $cmdline = implode($args," ");
  1552. if(is_windows()) {
  1553. $cwd = getcwd();
  1554. $cmd = "cmd /c start \"title\" /D \"$cwd\" /b $cmdline";
  1555. proc_close(proc_open($cmd, array(), $foo));
  1556. }
  1557. else {
  1558. if(get_config('system','use_proc_open'))
  1559. proc_close(proc_open($cmdline ." &", array(), $foo));
  1560. else
  1561. exec($cmdline . ' > /dev/null &');
  1562. }
  1563. }
  1564. /**
  1565. * @brief Checks if we are running on M$ Windows.
  1566. *
  1567. * @return bool true if we run on M$ Windows
  1568. *
  1569. * It's possible you might be able to run on WAMP or XAMPP, and this
  1570. * has been accomplished, but is not officially supported. Good luck.
  1571. *
  1572. */
  1573. function is_windows() {
  1574. return ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false);
  1575. }
  1576. /**
  1577. * @brief Check if current user has admin role.
  1578. *
  1579. * Check if the current user has ACCOUNT_ROLE_ADMIN.
  1580. *
  1581. * @return bool true if user is an admin
  1582. */
  1583. function is_site_admin() {
  1584. if(! session_id())
  1585. return false;
  1586. if($_SESSION['delegate'])
  1587. return false;
  1588. if((intval($_SESSION['authenticated']))
  1589. && (is_array(App::$account))
  1590. && (App::$account['account_roles'] & ACCOUNT_ROLE_ADMIN))
  1591. return true;
  1592. return false;
  1593. }
  1594. /**
  1595. * @brief Check if current user has developer role.
  1596. *
  1597. * Check if the current user has ACCOUNT_ROLE_DEVELOPER.
  1598. *
  1599. * @return bool true if user is a developer
  1600. */
  1601. function is_developer() {
  1602. if(! session_id())
  1603. return false;
  1604. if((intval($_SESSION['authenticated']))
  1605. && (is_array(App::$account))
  1606. && (App::$account['account_roles'] & ACCOUNT_ROLE_DEVELOPER))
  1607. return true;
  1608. return false;
  1609. }
  1610. function load_contact_links($uid) {
  1611. $ret = array();
  1612. if(! $uid || x(App::$contacts,'empty'))
  1613. return;
  1614. // logger('load_contact_links');
  1615. $r = q("SELECT abook_id, abook_flags, abook_my_perms, abook_their_perms, xchan_hash, xchan_photo_m, xchan_name, xchan_url, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d ",
  1616. intval($uid)
  1617. );
  1618. if($r) {
  1619. foreach($r as $rv){
  1620. $ret[$rv['xchan_hash']] = $rv;
  1621. }
  1622. }
  1623. else
  1624. $ret['empty'] = true;
  1625. App::$contacts = $ret;
  1626. }
  1627. /**
  1628. * @brief Returns querystring as string from a mapped array.
  1629. *
  1630. * @param array $params mapped array with query parameters
  1631. * @param string $name of parameter, default null
  1632. *
  1633. * @return string
  1634. */
  1635. function build_querystring($params, $name = null) {
  1636. $ret = '';
  1637. foreach($params as $key => $val) {
  1638. if(is_array($val)) {
  1639. if($name === null) {
  1640. $ret .= build_querystring($val, $key);
  1641. } else {
  1642. $ret .= build_querystring($val, $name . "[$key]");
  1643. }
  1644. } else {
  1645. $val = urlencode($val);
  1646. if($name != null) {
  1647. $ret .= $name . "[$key]" . "=$val&";
  1648. } else {
  1649. $ret .= "$key=$val&";
  1650. }
  1651. }
  1652. }
  1653. return $ret;
  1654. }
  1655. /**
  1656. * @brief Much better way of dealing with c-style args.
  1657. */
  1658. function argc() {
  1659. return App::$argc;
  1660. }
  1661. function argv($x) {
  1662. if(array_key_exists($x,App::$argv))
  1663. return App::$argv[$x];
  1664. return '';
  1665. }
  1666. function dba_timer() {
  1667. return microtime(true);
  1668. }
  1669. /**
  1670. * @brief Returns xchan_hash from the observer.
  1671. *
  1672. * Observer can be a local or remote channel.
  1673. *
  1674. * @return string xchan_hash from observer, otherwise empty string if no observer
  1675. */
  1676. function get_observer_hash() {
  1677. $observer = App::get_observer();
  1678. if(is_array($observer))
  1679. return $observer['xchan_hash'];
  1680. return '';
  1681. }
  1682. /**
  1683. * @brief Returns the complete URL of the current page, e.g.: http(s)://something.com/network
  1684. *
  1685. * Taken from http://webcheatsheet.com/php/get_current_page_url.php
  1686. *
  1687. * @return string
  1688. */
  1689. function curPageURL() {
  1690. $pageURL = 'http';
  1691. if ($_SERVER["HTTPS"] == "on") {
  1692. $pageURL .= "s";
  1693. }
  1694. $pageURL .= "://";
  1695. if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
  1696. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  1697. } else {
  1698. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  1699. }
  1700. return $pageURL;
  1701. }
  1702. /**
  1703. * @brief Returns a custom navigation by name???
  1704. *
  1705. * If no $navname provided load default page['nav']
  1706. *
  1707. * @todo not fully implemented yet
  1708. *
  1709. * @param string $navname
  1710. *
  1711. * @return mixed
  1712. */
  1713. function get_custom_nav($navname) {
  1714. if (! $navname)
  1715. return App::$page['nav'];
  1716. // load custom nav menu by name here
  1717. }
  1718. /**
  1719. * @brief Loads a page definition file for a module.
  1720. *
  1721. * If there is no parsed Comanche template already load a module's pdl file
  1722. * and parse it with Comanche.
  1723. *
  1724. */
  1725. function load_pdl() {
  1726. App::$comanche = new Zotlabs\Render\Comanche();
  1727. if (! count(App::$layout)) {
  1728. $arr = [
  1729. 'module' => App::$module,
  1730. 'layout' => ''
  1731. ];
  1732. /**
  1733. * @hooks load_pdl
  1734. * Called when we load a PDL file or description.
  1735. * * \e string \b module
  1736. * * \e string \b layout
  1737. */
  1738. call_hooks('load_pdl', $arr);
  1739. $layout = $arr['layout'];
  1740. $n = 'mod_' . App::$module . '.pdl' ;
  1741. $u = App::$comanche->get_channel_id();
  1742. if($u)
  1743. $s = get_pconfig($u, 'system', $n);
  1744. if(! $s)
  1745. $s = $layout;
  1746. if((! $s) && (($p = theme_include($n)) != ''))
  1747. $s = @file_get_contents($p);
  1748. elseif(file_exists('addon/'. App::$module . '/' . $n))
  1749. $s = @file_get_contents('addon/'. App::$module . '/' . $n);
  1750. $arr = [
  1751. 'module' => App::$module,
  1752. 'layout' => $s
  1753. ];
  1754. call_hooks('alter_pdl',$arr);
  1755. $s = $arr['layout'];
  1756. if($s) {
  1757. App::$comanche->parse($s);
  1758. App::$pdl = $s;
  1759. }
  1760. }
  1761. }
  1762. function exec_pdl() {
  1763. if(App::$pdl) {
  1764. App::$comanche->parse(App::$pdl,1);
  1765. }
  1766. }
  1767. /**
  1768. * @brief build the page.
  1769. *
  1770. * Build the page - now that we have all the components
  1771. *
  1772. */
  1773. function construct_page() {
  1774. exec_pdl();
  1775. $comanche = ((count(App::$layout)) ? true : false);
  1776. require_once(theme_include('theme_init.php'));
  1777. $installing = false;
  1778. $uid = ((App::$profile_uid) ? App::$profile_uid : local_channel());
  1779. $navbar = get_config('system','navbar','default');
  1780. if($uid) {
  1781. $navbar = get_pconfig($uid,'system','navbar',$navbar);
  1782. }
  1783. if($comanche && App::$layout['navbar']) {
  1784. $navbar = App::$layout['navbar'];
  1785. }
  1786. if (App::$module == 'setup') {
  1787. $installing = true;
  1788. } else {
  1789. nav($navbar);
  1790. }
  1791. $current_theme = Zotlabs\Render\Theme::current();
  1792. // logger('current_theme: ' . print_r($current_theme,true));
  1793. // Zotlabs\Render\Theme::debug();
  1794. if (($p = theme_include($current_theme[0] . '.js')) != '')
  1795. head_add_js('/' . $p);
  1796. if (($p = theme_include('mod_' . App::$module . '.php')) != '')
  1797. require_once($p);
  1798. require_once('include/js_strings.php');
  1799. if (x(App::$page, 'template_style'))
  1800. head_add_css(App::$page['template_style'] . '.css');
  1801. else
  1802. head_add_css(((x(App::$page, 'template')) ? App::$page['template'] : 'default' ) . '.css');
  1803. if (($p = theme_include('mod_' . App::$module . '.css')) != '')
  1804. head_add_css('mod_' . App::$module . '.css');
  1805. head_add_css(Zotlabs\Render\Theme::url($installing));
  1806. if (($p = theme_include('mod_' . App::$module . '.js')) != '')
  1807. head_add_js('mod_' . App::$module . '.js');
  1808. App::build_pagehead();
  1809. if(App::$page['pdl_content']) {
  1810. App::$page['content'] = App::$comanche->region(App::$page['content']);
  1811. }
  1812. // Let's say we have a comanche declaration '[region=nav][/region][region=content]$nav $content[/region]'.
  1813. // The text 'region=' identifies a section of the layout by that name. So what we want to do here is leave
  1814. // App::$page['nav'] empty and put the default content from App::$page['nav'] and App::$page['section']
  1815. // into a new region called App::$data['content']. It is presumed that the chosen layout file for this comanche page
  1816. // has a '<content>' element instead of a '<section>'.
  1817. // This way the Comanche layout can include any existing content, alter the layout by adding stuff around it or changing the
  1818. // layout completely with a new layout definition, or replace/remove existing content.
  1819. if($comanche) {
  1820. $arr = [
  1821. 'module' => App::$module,
  1822. 'layout' => App::$layout
  1823. ];
  1824. /**
  1825. * @hooks construct_page
  1826. * General purpose hook to provide content to certain page regions.
  1827. * Called when constructing the Comanche page.
  1828. * * \e string \b module
  1829. * * \e string \b layout
  1830. */
  1831. call_hooks('construct_page', $arr);
  1832. App::$layout = $arr['layout'];
  1833. foreach(App::$layout as $k => $v) {
  1834. if((strpos($k, 'region_') === 0) && strlen($v)) {
  1835. if(strpos($v, '$region_') !== false) {
  1836. $v = preg_replace_callback('/\$region_([a-zA-Z0-9]+)/ism', array(App::$comanche,'replace_region'), $v);
  1837. }
  1838. // And a couple of convenience macros
  1839. if(strpos($v, '$htmlhead') !== false) {
  1840. $v = str_replace('$htmlhead', App::$page['htmlhead'], $v);
  1841. }
  1842. if(strpos($v, '$nav') !== false) {
  1843. $v = str_replace('$nav', App::$page['nav'], $v);
  1844. }
  1845. if(strpos($v, '$content') !== false) {
  1846. $v = str_replace('$content', App::$page['content'], $v);
  1847. }
  1848. App::$page[substr($k, 7)] = $v;
  1849. }
  1850. }
  1851. }
  1852. $page = App::$page;
  1853. $profile = App::$profile;
  1854. // There's some experimental support for right-to-left text in the view/php/default.php page template.
  1855. // In v1.9 we started providing direction preference in the per language hstrings.php file
  1856. // This requires somebody with fluency in a RTL language to make happen
  1857. $page['direction'] = 0; // ((App::$rtl) ? 1 : 0);
  1858. header("Content-type: text/html; charset=utf-8");
  1859. // security headers - see https://securityheaders.io
  1860. if(App::get_scheme() === 'https' && App::$config['system']['transport_security_header'])
  1861. header("Strict-Transport-Security: max-age=31536000");
  1862. if(App::$config['system']['content_security_policy']) {
  1863. $cspsettings = Array (
  1864. 'script-src' => Array ("'self'","'unsafe-inline'","'unsafe-eval'"),
  1865. 'style-src' => Array ("'self'","'unsafe-inline'")
  1866. );
  1867. call_hooks('content_security_policy',$cspsettings);
  1868. // Legitimate CSP directives (cxref: https://content-security-policy.com/)
  1869. $validcspdirectives=Array(
  1870. "default-src", "script-src", "style-src",
  1871. "img-src", "connect-src", "font-src",
  1872. "object-src", "media-src", 'frame-src',
  1873. 'sandbox', 'report-uri', 'child-src',
  1874. 'form-action', 'frame-ancestors', 'plugin-types'
  1875. );
  1876. $cspheader = "Content-Security-Policy:";
  1877. foreach ($cspsettings as $cspdirective => $csp) {
  1878. if (!in_array($cspdirective,$validcspdirectives)) {
  1879. logger("INVALID CSP DIRECTIVE: ".$cspdirective,LOGGER_DEBUG);
  1880. continue;
  1881. }
  1882. $cspsettingsarray=array_unique($cspsettings[$cspdirective]);
  1883. $cspsetpolicy = implode(' ',$cspsettingsarray);
  1884. if ($cspsetpolicy) {
  1885. $cspheader .= " ".$cspdirective." ".$cspsetpolicy.";";
  1886. }
  1887. }
  1888. header($cspheader);
  1889. }
  1890. if(App::$config['system']['x_security_headers']) {
  1891. header("X-Frame-Options: SAMEORIGIN");
  1892. header("X-Xss-Protection: 1; mode=block;");
  1893. header("X-Content-Type-Options: nosniff");
  1894. }
  1895. if(App::$config['system']['public_key_pins']) {
  1896. header("Public-Key-Pins: " . App::$config['system']['public_key_pins']);
  1897. }
  1898. require_once(theme_include(
  1899. ((x(App::$page, 'template')) ? App::$page['template'] : 'default' ) . '.php' )
  1900. );
  1901. }
  1902. /**
  1903. * @brief Returns appplication root directory.
  1904. *
  1905. * @return string
  1906. */
  1907. function appdirpath() {
  1908. return dirname(__FILE__);
  1909. }
  1910. /**
  1911. * @brief Set a pageicon.
  1912. *
  1913. * @param string $icon
  1914. */
  1915. function head_set_icon($icon) {
  1916. App::$data['pageicon'] = $icon;
  1917. }
  1918. /**
  1919. * @brief Get the pageicon.
  1920. *
  1921. * @return string absolut path to pageicon
  1922. */
  1923. function head_get_icon() {
  1924. $icon = App::$data['pageicon'];
  1925. if(! strpos($icon, '://'))
  1926. $icon = z_root() . $icon;
  1927. return $icon;
  1928. }
  1929. /**
  1930. * @brief Return the Realm of the directory.
  1931. *
  1932. * @return string
  1933. */
  1934. function get_directory_realm() {
  1935. if($x = get_config('system', 'directory_realm'))
  1936. return $x;
  1937. return DIRECTORY_REALM;
  1938. }
  1939. /**
  1940. * @brief Return the primary directory server.
  1941. *
  1942. * @return string
  1943. */
  1944. function get_directory_primary() {
  1945. $dirmode = intval(get_config('system','directory_mode'));
  1946. if($dirmode == DIRECTORY_MODE_STANDALONE || $dirmode == DIRECTORY_MODE_PRIMARY) {
  1947. return z_root();
  1948. }
  1949. if($x = get_config('system', 'directory_primary'))
  1950. return $x;
  1951. return DIRECTORY_FALLBACK_MASTER;
  1952. }
  1953. /**
  1954. * @brief Return relative date of last completed poller execution.
  1955. *
  1956. * @return string relative date of last completed poller execution
  1957. */
  1958. function get_poller_runtime() {
  1959. $t = get_config('system', 'lastpoll');
  1960. return relative_date($t);
  1961. }
  1962. function z_get_upload_dir() {
  1963. $upload_dir = get_config('system','uploaddir');
  1964. if(! $upload_dir)
  1965. $upload_dir = ini_get('upload_tmp_dir');
  1966. if(! $upload_dir)
  1967. $upload_dir = sys_get_temp_dir();
  1968. return $upload_dir;
  1969. }
  1970. function z_get_temp_dir() {
  1971. $temp_dir = get_config('system','tempdir');
  1972. if(! $temp_dir)
  1973. $temp_dir = sys_get_temp_dir();
  1974. return $temp_dir;
  1975. }
  1976. /**
  1977. * @brief Check if server certificate is valid.
  1978. *
  1979. * Notify admin if not.
  1980. */
  1981. function z_check_cert() {
  1982. if(strpos(z_root(), 'https://') !== false) {
  1983. $x = z_fetch_url(z_root() . '/siteinfo.json');
  1984. if(! $x['success']) {
  1985. $recurse = 0;
  1986. $y = z_fetch_url(z_root() . '/siteinfo.json', false, $recurse, ['novalidate' => true]);
  1987. if($y['success'])
  1988. cert_bad_email();
  1989. }
  1990. }
  1991. }
  1992. /**
  1993. * @brief Send email to admin if server has an invalid certificate.
  1994. *
  1995. * If a hub is available over https it must have a publicly valid certificate.
  1996. */
  1997. function cert_bad_email() {
  1998. return z_mail(
  1999. [
  2000. 'toEmail' => \App::$config['system']['admin_email'],
  2001. 'messageSubject' => sprintf(t('[$Projectname] Website SSL error for %s'), App::get_hostname()),
  2002. 'textVersion' => replace_macros(get_intltext_template('cert_bad_eml.tpl'),
  2003. [
  2004. '$sitename' => App::$config['system']['sitename'],
  2005. '$siteurl' => z_root(),
  2006. '$error' => t('Website SSL certificate is not valid. Please correct.')
  2007. ]
  2008. )
  2009. ]
  2010. );
  2011. }
  2012. function check_for_new_perms() {
  2013. // Do not execute if we are in the middle of a git update and the relevant versions don't match
  2014. if( \Zotlabs\Access\Permissions::version() != \Zotlabs\Access\PermissionRoles::version())
  2015. return;
  2016. $pregistered = get_config('system','perms');
  2017. $pcurrent = array_keys(\Zotlabs\Access\Permissions::Perms());
  2018. if(! $pregistered) {
  2019. set_config('system','perms',$pcurrent);
  2020. return;
  2021. }
  2022. $found_new_perm = false;
  2023. foreach($pcurrent as $p) {
  2024. if(! in_array($p,$pregistered)) {
  2025. $found_new_perm = true;
  2026. // for all channels
  2027. $c = q("select channel_id from channel where true");
  2028. if($c) {
  2029. foreach($c as $cc) {
  2030. // get the permission role
  2031. $r = q("select v from pconfig where uid = %d and cat = 'system' and k = 'permissions_role'",
  2032. intval($cc['channel_id'])
  2033. );
  2034. if($r) {
  2035. // get a list of connections
  2036. $x = q("select abook_xchan from abook where abook_channel = %d and abook_self = 0",
  2037. intval($cc['channel_id'])
  2038. );
  2039. // get the permissions role details
  2040. $rp = \Zotlabs\Access\PermissionRoles::role_perms($r[0]['v']);
  2041. if($rp) {
  2042. // for custom permission roles we need to customise how we initiate this new permission
  2043. if(array_key_exists('role',$rp) && ($rp['role'] === 'custom' || $rp['role'] === '')) {
  2044. \Zotlabs\Access\PermissionRoles::new_custom_perms($cc['channel_id'],$p,$x);
  2045. }
  2046. else {
  2047. // set the channel limits if appropriate or 0
  2048. if(array_key_exists('limits',$rp) && array_key_exists($p,$rp['limits'])) {
  2049. \Zotlabs\Access\PermissionLimits::Set($cc['channel_id'],$p,$rp['limits'][$p]);
  2050. }
  2051. else {
  2052. \Zotlabs\Access\PermissionLimits::Set($cc['channel_id'],$p,0);
  2053. }
  2054. $set = ((array_key_exists('perms_connect',$rp) && in_array($p,$rp['perms_connect'])) ? 1 : 0);
  2055. // foreach connection set to the perms_connect value
  2056. if($x) {
  2057. foreach($x as $xx) {
  2058. set_abconfig($cc['channel_id'],$xx['abook_xchan'],'my_perms',$p,intval($set));
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. // We should probably call perms_refresh here, but this should get pushed in 24 hours and there is no urgency
  2069. if($found_new_perm)
  2070. set_config('system','perms',$pcurrent);
  2071. }
  2072. /**
  2073. * @brief Send warnings every 3-5 days if cron is not running.
  2074. */
  2075. function check_cron_broken() {
  2076. $d = get_config('system','lastcron');
  2077. if((! $d) || ($d < datetime_convert('UTC','UTC','now - 4 hours'))) {
  2078. Zotlabs\Daemon\Master::Summon(array('Cron'));
  2079. set_config('system','lastcron',datetime_convert());
  2080. }
  2081. $t = get_config('system','lastcroncheck');
  2082. if(! $t) {
  2083. // never checked before. Start the timer.
  2084. set_config('system','lastcroncheck',datetime_convert());
  2085. return;
  2086. }
  2087. if($t > datetime_convert('UTC','UTC','now - 3 days')) {
  2088. // Wait for 3 days before we do anything so as not to swamp the admin with messages
  2089. return;
  2090. }
  2091. set_config('system','lastcroncheck',datetime_convert());
  2092. if(($d) && ($d > datetime_convert('UTC','UTC','now - 3 days'))) {
  2093. // Scheduled tasks have run successfully in the last 3 days.
  2094. return;
  2095. }
  2096. return z_mail(
  2097. [
  2098. 'toEmail' => \App::$config['system']['admin_email'],
  2099. 'messageSubject' => sprintf(t('[$Projectname] Cron tasks not running on %s'), App::get_hostname()),
  2100. 'textVersion' => replace_macros(get_intltext_template('cron_bad_eml.tpl'),
  2101. [
  2102. '$sitename' => App::$config['system']['sitename'],
  2103. '$siteurl' => z_root(),
  2104. '$error' => t('Cron/Scheduled tasks not running.'),
  2105. '$lastdate' => (($d)? $d : t('never'))
  2106. ]
  2107. )
  2108. ]
  2109. );
  2110. }
  2111. /**
  2112. * @brief
  2113. *
  2114. * @param boolean $allow_account (optional) default false
  2115. * @return boolean
  2116. */
  2117. function observer_prohibited($allow_account = false) {
  2118. if($allow_account) {
  2119. return (((get_config('system', 'block_public')) && (! get_account_id()) && (! remote_channel())) ? true : false );
  2120. }
  2121. return (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false );
  2122. }