boot.php 70 KB

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