deprecated-1.9.php 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849
  1. <?php
  2. /**
  3. * Return the full URL of the current page.
  4. *
  5. * @return string The URL
  6. * @todo Combine / replace with current_page_url(). full_url() is based on the
  7. * request only while current_page_url() uses the configured site url.
  8. * @deprecated 1.9 Use current_page_url()
  9. */
  10. function full_url() {
  11. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use current_page_url()', 1.9);
  12. $request = _elgg_services()->request;
  13. $url = $request->getSchemeAndHttpHost();
  14. // This is here to prevent XSS in poorly written browsers used by 80% of the population.
  15. // svn commit [5813]: https://github.com/Elgg/Elgg/commit/0c947e80f512cb0a482b1864fd0a6965c8a0cd4a
  16. // @todo encoding like this should occur when inserting into web page, not here
  17. $quotes = array('\'', '"');
  18. $encoded = array('%27', '%22');
  19. return $url . str_replace($quotes, $encoded, $request->getRequestUri());
  20. }
  21. /**
  22. * Sets the URL handler for a particular entity type and subtype
  23. *
  24. * @param string $entity_type The entity type
  25. * @param string $entity_subtype The entity subtype
  26. * @param string $function_name The function to register
  27. *
  28. * @return bool Depending on success
  29. * @see get_entity_url()
  30. * @see \ElggEntity::getURL()
  31. * @since 1.8.0
  32. * @deprecated 1.9.0 Use the plugin hook in \ElggEntity::getURL()
  33. */
  34. function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) {
  35. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use the plugin hook in \ElggEntity::getURL()', 1.9);
  36. global $CONFIG;
  37. if (!is_callable($function_name, true)) {
  38. return false;
  39. }
  40. if (!isset($CONFIG->entity_url_handler)) {
  41. $CONFIG->entity_url_handler = array();
  42. }
  43. if (!isset($CONFIG->entity_url_handler[$entity_type])) {
  44. $CONFIG->entity_url_handler[$entity_type] = array();
  45. }
  46. $CONFIG->entity_url_handler[$entity_type][$entity_subtype] = $function_name;
  47. return true;
  48. }
  49. /**
  50. * Sets the URL handler for a particular relationship type
  51. *
  52. * @param string $relationship_type The relationship type.
  53. * @param string $function_name The function to register
  54. *
  55. * @return bool Depending on success
  56. * @deprecated 1.9 Use the plugin hook in \ElggRelationship::getURL()
  57. */
  58. function elgg_register_relationship_url_handler($relationship_type, $function_name) {
  59. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use the plugin hook in getURL()', 1.9);
  60. global $CONFIG;
  61. if (!is_callable($function_name, true)) {
  62. return false;
  63. }
  64. if (!isset($CONFIG->relationship_url_handler)) {
  65. $CONFIG->relationship_url_handler = array();
  66. }
  67. $CONFIG->relationship_url_handler[$relationship_type] = $function_name;
  68. return true;
  69. }
  70. /**
  71. * Get the url for a given relationship.
  72. *
  73. * @param int $id Relationship ID
  74. *
  75. * @return string
  76. * @deprecated 1.9 Use \ElggRelationship::getURL()
  77. */
  78. function get_relationship_url($id) {
  79. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggRelationship::getURL()', 1.9);
  80. global $CONFIG;
  81. $id = (int)$id;
  82. if ($relationship = get_relationship($id)) {
  83. $view = elgg_get_viewtype();
  84. $guid = $relationship->guid_one;
  85. $type = $relationship->relationship;
  86. $url = "";
  87. $function = "";
  88. if (isset($CONFIG->relationship_url_handler[$type])) {
  89. $function = $CONFIG->relationship_url_handler[$type];
  90. }
  91. if (isset($CONFIG->relationship_url_handler['all'])) {
  92. $function = $CONFIG->relationship_url_handler['all'];
  93. }
  94. if (is_callable($function)) {
  95. $url = call_user_func($function, $relationship);
  96. }
  97. if ($url == "") {
  98. $nameid = $relationship->id;
  99. $url = elgg_get_site_url() . "export/$view/$guid/relationship/$nameid/";
  100. }
  101. return $url;
  102. }
  103. return false;
  104. }
  105. /**
  106. * Sets the URL handler for a particular extender type and name.
  107. * It is recommended that you do not call this directly, instead use
  108. * one of the wrapper functions such as elgg_register_annotation_url_handler().
  109. *
  110. * @param string $extender_type Extender type ('annotation', 'metadata')
  111. * @param string $extender_name The name of the extender
  112. * @param string $function_name The function to register
  113. *
  114. * @return bool
  115. * @deprecated 1.9 Use plugin hook in \ElggExtender::getURL()
  116. */
  117. function elgg_register_extender_url_handler($extender_type, $extender_name, $function_name) {
  118. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use the plugin hook in getURL()', 1.9, 2);
  119. global $CONFIG;
  120. if (!is_callable($function_name, true)) {
  121. return false;
  122. }
  123. if (!isset($CONFIG->extender_url_handler)) {
  124. $CONFIG->extender_url_handler = array();
  125. }
  126. if (!isset($CONFIG->extender_url_handler[$extender_type])) {
  127. $CONFIG->extender_url_handler[$extender_type] = array();
  128. }
  129. $CONFIG->extender_url_handler[$extender_type][$extender_name] = $function_name;
  130. return true;
  131. }
  132. /**
  133. * Get the URL of a given elgg extender.
  134. * Used by get_annotation_url and get_metadata_url.
  135. *
  136. * @param \ElggExtender $extender An extender object
  137. *
  138. * @return string
  139. * @deprecated 1.9 Use method getURL()
  140. */
  141. function get_extender_url(\ElggExtender $extender) {
  142. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggExtender::getURL()', 1.9);
  143. global $CONFIG;
  144. $view = elgg_get_viewtype();
  145. $guid = $extender->entity_guid;
  146. $type = $extender->type;
  147. $url = "";
  148. $function = "";
  149. if (isset($CONFIG->extender_url_handler[$type][$extender->name])) {
  150. $function = $CONFIG->extender_url_handler[$type][$extender->name];
  151. }
  152. if (isset($CONFIG->extender_url_handler[$type]['all'])) {
  153. $function = $CONFIG->extender_url_handler[$type]['all'];
  154. }
  155. if (isset($CONFIG->extender_url_handler['all']['all'])) {
  156. $function = $CONFIG->extender_url_handler['all']['all'];
  157. }
  158. if (is_callable($function)) {
  159. $url = call_user_func($function, $extender);
  160. }
  161. if ($url == "") {
  162. $nameid = $extender->id;
  163. if ($type == 'volatile') {
  164. $nameid = $extender->name;
  165. }
  166. $url = "export/$view/$guid/$type/$nameid/";
  167. }
  168. return elgg_normalize_url($url);
  169. }
  170. /**
  171. * Get the URL for this annotation.
  172. *
  173. * @param int $id Annotation id
  174. *
  175. * @return string|bool False on failure
  176. * @deprecated 1.9 Use method getURL() on annotation object
  177. */
  178. function get_annotation_url($id) {
  179. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggAnnotation::getURL()', 1.9);
  180. $id = (int)$id;
  181. if ($extender = elgg_get_annotation_from_id($id)) {
  182. return get_extender_url($extender);
  183. }
  184. return false;
  185. }
  186. /**
  187. * Register a metadata url handler.
  188. *
  189. * @param string $extender_name The name, default 'all'.
  190. * @param string $function The function name.
  191. *
  192. * @return bool
  193. * @deprecated 1.9 Use the plugin hook in \ElggExtender::getURL()
  194. */
  195. function elgg_register_metadata_url_handler($extender_name, $function) {
  196. // deprecation notice comes from elgg_register_extender_url_handler()
  197. return elgg_register_extender_url_handler('metadata', $extender_name, $function);
  198. }
  199. /**
  200. * Register an annotation url handler.
  201. *
  202. * @param string $extender_name The name, default 'all'.
  203. * @param string $function_name The function.
  204. *
  205. * @return string
  206. * @deprecated 1.9 Use the plugin hook in \ElggExtender::getURL()
  207. */
  208. function elgg_register_annotation_url_handler($extender_name = "all", $function_name) {
  209. // deprecation notice comes from elgg_register_extender_url_handler()
  210. return elgg_register_extender_url_handler('annotation', $extender_name, $function_name);
  211. }
  212. /**
  213. * Return a list of this group's members.
  214. *
  215. * @param int $group_guid The ID of the container/group.
  216. * @param int $limit The limit
  217. * @param int $offset The offset
  218. * @param int $site_guid The site
  219. * @param bool $count Return the users (false) or the count of them (true)
  220. *
  221. * @return mixed
  222. * @deprecated 1.9 Use \ElggGroup::getMembers()
  223. */
  224. function get_group_members($group_guid, $limit = 10, $offset = 0, $site_guid = 0, $count = false) {
  225. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::getMembers()', 1.9);
  226. // in 1.7 0 means "not set." rewrite to make sense.
  227. if (!$site_guid) {
  228. $site_guid = ELGG_ENTITIES_ANY_VALUE;
  229. }
  230. return elgg_get_entities_from_relationship(array(
  231. 'relationship' => 'member',
  232. 'relationship_guid' => $group_guid,
  233. 'inverse_relationship' => true,
  234. 'type' => 'user',
  235. 'limit' => $limit,
  236. 'offset' => $offset,
  237. 'count' => $count,
  238. 'site_guid' => $site_guid
  239. ));
  240. }
  241. /**
  242. * Add an object to the given group.
  243. *
  244. * @param int $group_guid The group to add the object to.
  245. * @param int $object_guid The guid of the elgg object (must be \ElggObject or a child thereof)
  246. *
  247. * @return bool
  248. * @throws InvalidClassException
  249. * @deprecated 1.9 Use \ElggGroup::addObjectToGroup()
  250. */
  251. function add_object_to_group($group_guid, $object_guid) {
  252. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::addObjectToGroup()', 1.9);
  253. $group_guid = (int)$group_guid;
  254. $object_guid = (int)$object_guid;
  255. $group = get_entity($group_guid);
  256. $object = get_entity($object_guid);
  257. if ((!$group) || (!$object)) {
  258. return false;
  259. }
  260. if (!($group instanceof \ElggGroup)) {
  261. $msg = "GUID:" . $group_guid . " is not a valid " . '\ElggGroup';
  262. throw new \InvalidClassException($msg);
  263. }
  264. if (!($object instanceof \ElggObject)) {
  265. $msg = "GUID:" . $object_guid . " is not a valid " . '\ElggObject';
  266. throw new \InvalidClassException($msg);
  267. }
  268. $object->container_guid = $group_guid;
  269. return $object->save();
  270. }
  271. /**
  272. * Remove an object from the given group.
  273. *
  274. * @param int $group_guid The group to remove the object from
  275. * @param int $object_guid The object to remove
  276. *
  277. * @return bool
  278. * @throws InvalidClassException
  279. * @deprecated 1.9 Use \ElggGroup::removeObjectFromGroup()
  280. */
  281. function remove_object_from_group($group_guid, $object_guid) {
  282. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::removeObjectFromGroup()', 1.9);
  283. $group_guid = (int)$group_guid;
  284. $object_guid = (int)$object_guid;
  285. $group = get_entity($group_guid);
  286. $object = get_entity($object_guid);
  287. if ((!$group) || (!$object)) {
  288. return false;
  289. }
  290. if (!($group instanceof \ElggGroup)) {
  291. $msg = "GUID:" . $group_guid . " is not a valid " . '\ElggGroup';
  292. throw new \InvalidClassException($msg);
  293. }
  294. if (!($object instanceof \ElggObject)) {
  295. $msg = "GUID:" . $object_guid . " is not a valid " . '\ElggObject';
  296. throw new \InvalidClassException($msg);
  297. }
  298. $object->container_guid = $object->owner_guid;
  299. return $object->save();
  300. }
  301. /**
  302. * Return whether a given user is a member of the group or not.
  303. *
  304. * @param int $group_guid The group ID
  305. * @param int $user_guid The user guid
  306. *
  307. * @return bool
  308. * @deprecated 1.9 Use Use \ElggGroup::isMember()
  309. */
  310. function is_group_member($group_guid, $user_guid) {
  311. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup::isMember()', 1.9);
  312. $object = check_entity_relationship($user_guid, 'member', $group_guid);
  313. if ($object) {
  314. return true;
  315. } else {
  316. return false;
  317. }
  318. }
  319. /**
  320. * Return all groups a user is a member of.
  321. *
  322. * @param int $user_guid GUID of user
  323. *
  324. * @return array|false
  325. * @deprecated 1.9 Use \ElggUser::getGroups()
  326. */
  327. function get_users_membership($user_guid) {
  328. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::getGroups()', 1.9);
  329. $options = array(
  330. 'type' => 'group',
  331. 'relationship' => 'member',
  332. 'relationship_guid' => $user_guid,
  333. 'inverse_relationship' => false,
  334. 'limit' => false,
  335. );
  336. return elgg_get_entities_from_relationship($options);
  337. }
  338. /**
  339. * Determines whether or not a user is another user's friend.
  340. *
  341. * @param int $user_guid The GUID of the user
  342. * @param int $friend_guid The GUID of the friend
  343. *
  344. * @return bool
  345. * @deprecated 1.9 Use \ElggUser::isFriendsOf() or \ElggUser::isFriendsWith()
  346. */
  347. function user_is_friend($user_guid, $friend_guid) {
  348. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::isFriendsOf() or \ElggUser::isFriendsWith()', 1.9);
  349. return check_entity_relationship($user_guid, "friend", $friend_guid) !== false;
  350. }
  351. /**
  352. * Obtains a given user's friends
  353. *
  354. * @param int $user_guid The user's GUID
  355. * @param string $subtype The subtype of users, if any
  356. * @param int $limit Number of results to return (default 10)
  357. * @param int $offset Indexing offset, if any
  358. *
  359. * @return \ElggUser[]|false Either an array of \ElggUsers or false, depending on success
  360. * @deprecated 1.9 Use \ElggUser::getFriends()
  361. */
  362. function get_user_friends($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
  363. $offset = 0) {
  364. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::getFriends()', 1.9);
  365. return elgg_get_entities_from_relationship(array(
  366. 'relationship' => 'friend',
  367. 'relationship_guid' => $user_guid,
  368. 'type' => 'user',
  369. 'subtype' => $subtype,
  370. 'limit' => $limit,
  371. 'offset' => $offset
  372. ));
  373. }
  374. /**
  375. * Obtains the people who have made a given user a friend
  376. *
  377. * @param int $user_guid The user's GUID
  378. * @param string $subtype The subtype of users, if any
  379. * @param int $limit Number of results to return (default 10)
  380. * @param int $offset Indexing offset, if any
  381. *
  382. * @return \ElggUser[]|false Either an array of \ElggUsers or false, depending on success
  383. * @deprecated 1.9 Use \ElggUser::getFriendsOf()
  384. */
  385. function get_user_friends_of($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
  386. $offset = 0) {
  387. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::getFriendsOf()', 1.9);
  388. return elgg_get_entities_from_relationship(array(
  389. 'relationship' => 'friend',
  390. 'relationship_guid' => $user_guid,
  391. 'inverse_relationship' => true,
  392. 'type' => 'user',
  393. 'subtype' => $subtype,
  394. 'limit' => $limit,
  395. 'offset' => $offset
  396. ));
  397. }
  398. /**
  399. * Adds a user to another user's friends list.
  400. *
  401. * @param int $user_guid The GUID of the friending user
  402. * @param int $friend_guid The GUID of the user to friend
  403. *
  404. * @return bool Depending on success
  405. * @deprecated 1.9 Use \ElggUser::addFriend()
  406. */
  407. function user_add_friend($user_guid, $friend_guid) {
  408. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::addFriend()', 1.9);
  409. $user_guid = (int) $user_guid;
  410. $friend_guid = (int) $friend_guid;
  411. if ($user_guid == $friend_guid) {
  412. return false;
  413. }
  414. if (!$friend = get_entity($friend_guid)) {
  415. return false;
  416. }
  417. if (!$user = get_entity($user_guid)) {
  418. return false;
  419. }
  420. if ((!($user instanceof \ElggUser)) || (!($friend instanceof \ElggUser))) {
  421. return false;
  422. }
  423. return add_entity_relationship($user_guid, "friend", $friend_guid);
  424. }
  425. /**
  426. * Removes a user from another user's friends list.
  427. *
  428. * @param int $user_guid The GUID of the friending user
  429. * @param int $friend_guid The GUID of the user on the friends list
  430. *
  431. * @return bool Depending on success
  432. * @deprecated 1.9 Use \ElggUser::removeFriend()
  433. */
  434. function user_remove_friend($user_guid, $friend_guid) {
  435. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser::removeFriend()', 1.9);
  436. $user_guid = (int) $user_guid;
  437. $friend_guid = (int) $friend_guid;
  438. // perform cleanup for access lists.
  439. $collections = get_user_access_collections($user_guid);
  440. if ($collections) {
  441. foreach ($collections as $collection) {
  442. remove_user_from_access_collection($friend_guid, $collection->id);
  443. }
  444. }
  445. return remove_entity_relationship($user_guid, "friend", $friend_guid);
  446. }
  447. /**
  448. * Add a user to a site.
  449. *
  450. * @param int $site_guid Site guid
  451. * @param int $user_guid User guid
  452. *
  453. * @return bool
  454. * @deprecated 1.9 Use \ElggSite::addEntity()
  455. */
  456. function add_site_user($site_guid, $user_guid) {
  457. elgg_deprecated_notice('add_site_user() is deprecated. Use \ElggEntity::addEntity()', 1.9);
  458. $site_guid = (int)$site_guid;
  459. $user_guid = (int)$user_guid;
  460. return add_entity_relationship($user_guid, "member_of_site", $site_guid);
  461. }
  462. /**
  463. * Remove a user from a site.
  464. *
  465. * @param int $site_guid Site GUID
  466. * @param int $user_guid User GUID
  467. *
  468. * @return bool
  469. * @deprecated 1.9 Use \ElggSite::removeEntity()
  470. */
  471. function remove_site_user($site_guid, $user_guid) {
  472. elgg_deprecated_notice('remove_site_user() is deprecated. Use \ElggEntity::removeEntity()', 1.9);
  473. $site_guid = (int)$site_guid;
  474. $user_guid = (int)$user_guid;
  475. return remove_entity_relationship($user_guid, "member_of_site", $site_guid);
  476. }
  477. /**
  478. * Add an object to a site.
  479. *
  480. * @param int $site_guid Site GUID
  481. * @param int $object_guid Object GUID
  482. *
  483. * @return mixed
  484. * @deprecated 1.9 Use \ElggSite::addEntity()
  485. */
  486. function add_site_object($site_guid, $object_guid) {
  487. elgg_deprecated_notice('add_site_object() is deprecated. Use \ElggEntity::addEntity()', 1.9);
  488. $site_guid = (int)$site_guid;
  489. $object_guid = (int)$object_guid;
  490. return add_entity_relationship($object_guid, "member_of_site", $site_guid);
  491. }
  492. /**
  493. * Remove an object from a site.
  494. *
  495. * @param int $site_guid Site GUID
  496. * @param int $object_guid Object GUID
  497. *
  498. * @return bool
  499. * @deprecated 1.9 Use \ElggSite::removeEntity()
  500. */
  501. function remove_site_object($site_guid, $object_guid) {
  502. elgg_deprecated_notice('remove_site_object() is deprecated. Use \ElggEntity::removeEntity()', 1.9);
  503. $site_guid = (int)$site_guid;
  504. $object_guid = (int)$object_guid;
  505. return remove_entity_relationship($object_guid, "member_of_site", $site_guid);
  506. }
  507. /**
  508. * Get the objects belonging to a site.
  509. *
  510. * @param int $site_guid Site GUID
  511. * @param string $subtype Subtype
  512. * @param int $limit Limit
  513. * @param int $offset Offset
  514. *
  515. * @return mixed
  516. * @deprecated 1.9 Use \ElggSite::getEntities()
  517. */
  518. function get_site_objects($site_guid, $subtype = "", $limit = 10, $offset = 0) {
  519. elgg_deprecated_notice('get_site_objects() is deprecated. Use \ElggSite::getEntities()', 1.9);
  520. $site_guid = (int)$site_guid;
  521. $limit = (int)$limit;
  522. $offset = (int)$offset;
  523. return elgg_get_entities_from_relationship(array(
  524. 'relationship' => 'member_of_site',
  525. 'relationship_guid' => $site_guid,
  526. 'inverse_relationship' => true,
  527. 'type' => 'object',
  528. 'subtype' => $subtype,
  529. 'limit' => $limit,
  530. 'offset' => $offset
  531. ));
  532. }
  533. /**
  534. * Get the sites this object is part of
  535. *
  536. * @param int $object_guid The object's GUID
  537. * @param int $limit Number of results to return
  538. * @param int $offset Any indexing offset
  539. *
  540. * @return array On success, an array of \ElggSites
  541. * @deprecated 1.9 Use \ElggEntity::getSites()
  542. */
  543. function get_object_sites($object_guid, $limit = 10, $offset = 0) {
  544. elgg_deprecated_notice('get_object_sites() is deprecated. Use \ElggEntity::getSites()', 1.9);
  545. $object_guid = (int)$object_guid;
  546. $limit = (int)$limit;
  547. $offset = (int)$offset;
  548. return elgg_get_entities_from_relationship(array(
  549. 'relationship' => 'member_of_site',
  550. 'relationship_guid' => $object_guid,
  551. 'type' => 'site',
  552. 'limit' => $limit,
  553. 'offset' => $offset,
  554. ));
  555. }
  556. /**
  557. * Get the sites this user is part of
  558. *
  559. * @param int $user_guid The user's GUID
  560. * @param int $limit Number of results to return
  561. * @param int $offset Any indexing offset
  562. *
  563. * @return \ElggSite[]|false On success, an array of \ElggSites
  564. * @deprecated 1.9 Use \ElggEntity::getSites()
  565. */
  566. function get_user_sites($user_guid, $limit = 10, $offset = 0) {
  567. elgg_deprecated_notice('get_user_sites() is deprecated. Use \ElggEntity::getSites()', 1.9);
  568. $user_guid = (int)$user_guid;
  569. $limit = (int)$limit;
  570. $offset = (int)$offset;
  571. return elgg_get_entities_from_relationship(array(
  572. 'site_guids' => ELGG_ENTITIES_ANY_VALUE,
  573. 'relationship' => 'member_of_site',
  574. 'relationship_guid' => $user_guid,
  575. 'inverse_relationship' => false,
  576. 'type' => 'site',
  577. 'limit' => $limit,
  578. 'offset' => $offset,
  579. ));
  580. }
  581. /**
  582. * Determines whether or not the specified user can edit the specified piece of extender
  583. *
  584. * @param int $extender_id The ID of the piece of extender
  585. * @param string $type 'metadata' or 'annotation'
  586. * @param int $user_guid The GUID of the user
  587. *
  588. * @return bool
  589. * @deprecated 1.9 Use the appropriate canEdit() method on metadata or annotations
  590. */
  591. function can_edit_extender($extender_id, $type, $user_guid = 0) {
  592. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggExtender::canEdit()', 1.9);
  593. // Since Elgg 1.0, Elgg has returned false from can_edit_extender()
  594. // if no user was logged in. This breaks the access override so we add this
  595. // special check here.
  596. if (!elgg_check_access_overrides($user_guid)) {
  597. if (!elgg_is_logged_in()) {
  598. return false;
  599. }
  600. }
  601. $user_guid = (int)$user_guid;
  602. $user = get_user($user_guid);
  603. if (!$user) {
  604. $user = elgg_get_logged_in_user_entity();
  605. $user_guid = elgg_get_logged_in_user_guid();
  606. }
  607. $functionname = "elgg_get_{$type}_from_id";
  608. if (is_callable($functionname)) {
  609. $extender = call_user_func($functionname, $extender_id);
  610. } else {
  611. return false;
  612. }
  613. if (!($extender instanceof \ElggExtender)) {
  614. return false;
  615. }
  616. /* @var \ElggExtender $extender */
  617. // If the owner is the specified user, great! They can edit.
  618. if ($extender->getOwnerGUID() == $user_guid) {
  619. return true;
  620. }
  621. // If the user can edit the entity this is attached to, great! They can edit.
  622. $entity = $extender->getEntity();
  623. if ($entity->canEdit($user_guid)) {
  624. return true;
  625. }
  626. // Trigger plugin hook - note that $user may be null
  627. $params = array('entity' => $entity, 'user' => $user);
  628. return elgg_trigger_plugin_hook('permissions_check', $type, $params, false);
  629. }
  630. /**
  631. * The algorithm working out the size of font based on the number of tags.
  632. * This is quick and dirty.
  633. *
  634. * @param int $min Min size
  635. * @param int $max Max size
  636. * @param int $number_of_tags The number of tags
  637. * @param int $buckets The number of buckets
  638. *
  639. * @return int
  640. * @access private
  641. * @deprecated 1.9
  642. */
  643. function calculate_tag_size($min, $max, $number_of_tags, $buckets = 6) {
  644. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  645. $delta = (($max - $min) / $buckets);
  646. $thresholds = array();
  647. for ($n = 1; $n <= $buckets; $n++) {
  648. $thresholds[$n - 1] = ($min + $n) * $delta;
  649. }
  650. // Correction
  651. if ($thresholds[$buckets - 1] > $max) {
  652. $thresholds[$buckets - 1] = $max;
  653. }
  654. $size = 0;
  655. for ($n = 0; $n < count($thresholds); $n++) {
  656. if ($number_of_tags >= $thresholds[$n]) {
  657. $size = $n;
  658. }
  659. }
  660. return $size;
  661. }
  662. /**
  663. * This function generates an array of tags with a weighting.
  664. *
  665. * @param array $tags The array of tags.
  666. * @param int $buckets The number of buckets
  667. *
  668. * @return array An associated array of tags with a weighting, this can then be mapped to a display class.
  669. * @access private
  670. * @deprecated 1.9
  671. */
  672. function generate_tag_cloud(array $tags, $buckets = 6) {
  673. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  674. $cloud = array();
  675. $min = 65535;
  676. $max = 0;
  677. foreach ($tags as $tag) {
  678. $cloud[$tag]++;
  679. if ($cloud[$tag] > $max) {
  680. $max = $cloud[$tag];
  681. }
  682. if ($cloud[$tag] < $min) {
  683. $min = $cloud[$tag];
  684. }
  685. }
  686. foreach ($cloud as $k => $v) {
  687. $cloud[$k] = calculate_tag_size($min, $max, $v, $buckets);
  688. }
  689. return $cloud;
  690. }
  691. /**
  692. * Invalidate the metadata cache based on options passed to various *_metadata functions
  693. *
  694. * @param string $action Action performed on metadata. "delete", "disable", or "enable"
  695. * @param array $options Options passed to elgg_(delete|disable|enable)_metadata
  696. * @return void
  697. * @deprecated 1.9
  698. */
  699. function elgg_invalidate_metadata_cache($action, array $options) {
  700. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  701. _elgg_invalidate_metadata_cache($action, $options);
  702. }
  703. global $METASTRINGS_DEADNAME_CACHE;
  704. $METASTRINGS_DEADNAME_CACHE = array();
  705. /**
  706. * Return the meta string id for a given tag, or false.
  707. *
  708. * @param string $string The value to store
  709. * @param bool $case_sensitive Do we want to make the query case sensitive?
  710. * If not there may be more than one result
  711. *
  712. * @return int|array|false meta string id, array of ids or false if none found
  713. * @deprecated 1.9 Use elgg_get_metastring_id()
  714. */
  715. function get_metastring_id($string, $case_sensitive = TRUE) {
  716. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_metastring_id()', 1.9);
  717. global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
  718. $string = sanitise_string($string);
  719. // caching doesn't work for case insensitive searches
  720. if ($case_sensitive) {
  721. $result = array_search($string, $METASTRINGS_CACHE, true);
  722. if ($result !== false) {
  723. return $result;
  724. }
  725. // See if we have previously looked for this and found nothing
  726. if (in_array($string, $METASTRINGS_DEADNAME_CACHE, true)) {
  727. return false;
  728. }
  729. // Experimental memcache
  730. $msfc = null;
  731. static $metastrings_memcache;
  732. if ((!$metastrings_memcache) && (is_memcache_available())) {
  733. $metastrings_memcache = new \ElggMemcache('metastrings_memcache');
  734. }
  735. if ($metastrings_memcache) {
  736. $msfc = $metastrings_memcache->load($string);
  737. }
  738. if ($msfc) {
  739. return $msfc;
  740. }
  741. }
  742. // Case sensitive
  743. if ($case_sensitive) {
  744. $query = "SELECT * from {$CONFIG->dbprefix}metastrings where string= BINARY '$string' limit 1";
  745. } else {
  746. $query = "SELECT * from {$CONFIG->dbprefix}metastrings where string = '$string'";
  747. }
  748. $row = FALSE;
  749. $metaStrings = get_data($query);
  750. if (is_array($metaStrings)) {
  751. if (sizeof($metaStrings) > 1) {
  752. $ids = array();
  753. foreach ($metaStrings as $metaString) {
  754. $ids[] = $metaString->id;
  755. }
  756. return $ids;
  757. } else if (isset($metaStrings[0])) {
  758. $row = $metaStrings[0];
  759. }
  760. }
  761. if ($row) {
  762. $METASTRINGS_CACHE[$row->id] = $row->string; // Cache it
  763. // Attempt to memcache it if memcache is available
  764. if ($metastrings_memcache) {
  765. $metastrings_memcache->save($row->string, $row->id);
  766. }
  767. return $row->id;
  768. } else {
  769. $METASTRINGS_DEADNAME_CACHE[$string] = $string;
  770. }
  771. return false;
  772. }
  773. /**
  774. * Add a metastring.
  775. * It returns the id of the metastring. If it does not exist, it will be created.
  776. *
  777. * @param string $string The value (whatever that is) to be stored
  778. * @param bool $case_sensitive Do we want to make the query case sensitive?
  779. *
  780. * @return mixed Integer tag or false.
  781. * @deprecated 1.9 Use elgg_get_metastring_id()
  782. */
  783. function add_metastring($string, $case_sensitive = true) {
  784. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_metastring_id()', 1.9);
  785. global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
  786. $sanstring = sanitise_string($string);
  787. $id = get_metastring_id($string, $case_sensitive);
  788. if ($id) {
  789. return $id;
  790. }
  791. $result = insert_data("INSERT into {$CONFIG->dbprefix}metastrings (string) values ('$sanstring')");
  792. if ($result) {
  793. $METASTRINGS_CACHE[$result] = $string;
  794. if (isset($METASTRINGS_DEADNAME_CACHE[$string])) {
  795. unset($METASTRINGS_DEADNAME_CACHE[$string]);
  796. }
  797. }
  798. return $result;
  799. }
  800. /**
  801. * When given an ID, returns the corresponding metastring
  802. *
  803. * @param int $id Metastring ID
  804. *
  805. * @return string Metastring
  806. * @deprecated 1.9
  807. */
  808. function get_metastring($id) {
  809. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9);
  810. global $CONFIG, $METASTRINGS_CACHE;
  811. $id = (int) $id;
  812. if (isset($METASTRINGS_CACHE[$id])) {
  813. return $METASTRINGS_CACHE[$id];
  814. }
  815. $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where id='$id' limit 1");
  816. if ($row) {
  817. $METASTRINGS_CACHE[$id] = $row->string;
  818. return $row->string;
  819. }
  820. return false;
  821. }
  822. /**
  823. * Obtains a list of objects owned by a user's friends
  824. *
  825. * @param int $user_guid The GUID of the user to get the friends of
  826. * @param string $subtype Optionally, the subtype of objects
  827. * @param int $limit The number of results to return (default 10)
  828. * @param int $offset Indexing offset, if any
  829. * @param int $timelower The earliest time the entity can have been created. Default: all
  830. * @param int $timeupper The latest time the entity can have been created. Default: all
  831. *
  832. * @return \ElggObject[]|false An array of \ElggObjects or false, depending on success
  833. * @deprecated 1.9 Use elgg_get_entities_from_relationship()
  834. */
  835. function get_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
  836. $offset = 0, $timelower = 0, $timeupper = 0) {
  837. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_entities_from_relationship()', 1.9);
  838. return elgg_get_entities_from_relationship(array(
  839. 'type' => 'object',
  840. 'subtype' => $subtype,
  841. 'limit' => $limit,
  842. 'offset' => $offset,
  843. 'created_time_lower' => $timelower,
  844. 'created_time_upper' => $timeupper,
  845. 'relationship' => 'friend',
  846. 'relationship_guid' => $user_guid,
  847. 'relationship_join_on' => 'container_guid',
  848. ));
  849. }
  850. /**
  851. * Counts the number of objects owned by a user's friends
  852. *
  853. * @param int $user_guid The GUID of the user to get the friends of
  854. * @param string $subtype Optionally, the subtype of objects
  855. * @param int $timelower The earliest time the entity can have been created. Default: all
  856. * @param int $timeupper The latest time the entity can have been created. Default: all
  857. *
  858. * @return int The number of objects
  859. * @deprecated 1.9 Use elgg_get_entities_from_relationship()
  860. */
  861. function count_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE,
  862. $timelower = 0, $timeupper = 0) {
  863. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_get_entities_from_relationship()', 1.9);
  864. return elgg_get_entities_from_relationship(array(
  865. 'type' => 'object',
  866. 'subtype' => $subtype,
  867. 'created_time_lower' => $timelower,
  868. 'created_time_upper' => $timeupper,
  869. 'relationship' => 'friend',
  870. 'relationship_guid' => $user_guid,
  871. 'relationship_join_on' => 'container_guid',
  872. 'count' => true,
  873. ));
  874. }
  875. /**
  876. * Displays a list of a user's friends' objects of a particular subtype, with navigation.
  877. *
  878. * @see elgg_view_entity_list
  879. *
  880. * @param int $user_guid The GUID of the user
  881. * @param string $subtype The object subtype
  882. * @param int $limit The number of entities to display on a page
  883. * @param bool $full_view Whether or not to display the full view (default: true)
  884. * @param bool $listtypetoggle Whether or not to allow you to flip to gallery mode (default: true)
  885. * @param bool $pagination Whether to display pagination (default: true)
  886. * @param int $timelower The earliest time the entity can have been created. Default: all
  887. * @param int $timeupper The latest time the entity can have been created. Default: all
  888. *
  889. * @return string
  890. * @deprecated 1.9 Use elgg_list_entities_from_relationship()
  891. */
  892. function list_user_friends_objects($user_guid, $subtype = "", $limit = 10, $full_view = true,
  893. $listtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) {
  894. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use elgg_list_entities_from_relationship()', 1.9);
  895. return elgg_list_entities_from_relationship(array(
  896. 'type' => 'object',
  897. 'subtype' => $subtype,
  898. 'limit' => $limit,
  899. 'created_time_lower' => $timelower,
  900. 'created_time_upper' => $timeupper,
  901. 'full_view' => $full_view,
  902. 'list_type_toggle' => $listtypetoggle,
  903. 'pagination' => $pagination,
  904. 'relationship' => 'friend',
  905. 'relationship_guid' => $user_guid,
  906. 'relationship_join_on' => 'container_guid',
  907. ));
  908. }
  909. /**
  910. * Encode a location into a latitude and longitude, caching the result.
  911. *
  912. * Works by triggering the 'geocode' 'location' plugin
  913. * hook, and requires a geocoding plugin to be installed.
  914. *
  915. * @param string $location The location, e.g. "London", or "24 Foobar Street, Gotham City"
  916. * @return string|false
  917. * @deprecated 1.9.0 See geolocation plugin on github
  918. */
  919. function elgg_geocode_location($location) {
  920. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. See geolocation plugin on github', 1.9);
  921. global $CONFIG;
  922. if (is_array($location)) {
  923. return false;
  924. }
  925. $location = sanitise_string($location);
  926. // Look for cached version
  927. $query = "SELECT * from {$CONFIG->dbprefix}geocode_cache WHERE location='$location'";
  928. $cached_location = get_data_row($query);
  929. if ($cached_location) {
  930. return array('lat' => $cached_location->lat, 'long' => $cached_location->long);
  931. }
  932. // Trigger geocode event if not cached
  933. $return = false;
  934. $return = elgg_trigger_plugin_hook('geocode', 'location', array('location' => $location), $return);
  935. // If returned, cache and return value
  936. if (($return) && (is_array($return))) {
  937. $lat = (float)$return['lat'];
  938. $long = (float)$return['long'];
  939. // Put into cache at the end of the page since we don't really care that much
  940. $query = "INSERT DELAYED INTO {$CONFIG->dbprefix}geocode_cache "
  941. . " (location, lat, `long`) VALUES ('$location', '{$lat}', '{$long}')"
  942. . " ON DUPLICATE KEY UPDATE lat='{$lat}', `long`='{$long}'";
  943. execute_delayed_write_query($query);
  944. }
  945. return $return;
  946. }
  947. /**
  948. * Return entities within a given geographic area.
  949. *
  950. * Also accepts all options available to elgg_get_entities().
  951. *
  952. * @see elgg_get_entities
  953. *
  954. * @param array $options Array in format:
  955. *
  956. * latitude => FLOAT Latitude of the location
  957. *
  958. * longitude => FLOAT Longitude of the location
  959. *
  960. * distance => FLOAT/ARR (
  961. * latitude => float,
  962. * longitude => float,
  963. * )
  964. * The distance in degrees that determines the search box. A
  965. * single float will result in a square in degrees.
  966. * @warning The Earth is round.
  967. *
  968. * @see \ElggEntity::setLatLong()
  969. *
  970. * @return mixed If count, int. If not count, array. false on errors.
  971. * @since 1.8.0
  972. * @deprecated 1.9.0 See geolocation plugin on github
  973. */
  974. function elgg_get_entities_from_location(array $options = array()) {
  975. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. See geolocation plugin on github', 1.9);
  976. global $CONFIG;
  977. if (!isset($options['latitude']) || !isset($options['longitude']) ||
  978. !isset($options['distance'])) {
  979. return false;
  980. }
  981. if (!is_array($options['distance'])) {
  982. $lat_distance = (float)$options['distance'];
  983. $long_distance = (float)$options['distance'];
  984. } else {
  985. $lat_distance = (float)$options['distance']['latitude'];
  986. $long_distance = (float)$options['distance']['longitude'];
  987. }
  988. $lat = (float)$options['latitude'];
  989. $long = (float)$options['longitude'];
  990. $lat_min = $lat - $lat_distance;
  991. $lat_max = $lat + $lat_distance;
  992. $long_min = $long - $long_distance;
  993. $long_max = $long + $long_distance;
  994. $wheres = array();
  995. $wheres[] = "lat_name.string='geo:lat'";
  996. $wheres[] = "lat_value.string >= $lat_min";
  997. $wheres[] = "lat_value.string <= $lat_max";
  998. $wheres[] = "lon_name.string='geo:long'";
  999. $wheres[] = "lon_value.string >= $long_min";
  1000. $wheres[] = "lon_value.string <= $long_max";
  1001. $joins = array();
  1002. $joins[] = "JOIN {$CONFIG->dbprefix}metadata lat on e.guid=lat.entity_guid";
  1003. $joins[] = "JOIN {$CONFIG->dbprefix}metastrings lat_name on lat.name_id=lat_name.id";
  1004. $joins[] = "JOIN {$CONFIG->dbprefix}metastrings lat_value on lat.value_id=lat_value.id";
  1005. $joins[] = "JOIN {$CONFIG->dbprefix}metadata lon on e.guid=lon.entity_guid";
  1006. $joins[] = "JOIN {$CONFIG->dbprefix}metastrings lon_name on lon.name_id=lon_name.id";
  1007. $joins[] = "JOIN {$CONFIG->dbprefix}metastrings lon_value on lon.value_id=lon_value.id";
  1008. // merge wheres to pass to get_entities()
  1009. if (isset($options['wheres']) && !is_array($options['wheres'])) {
  1010. $options['wheres'] = array($options['wheres']);
  1011. } elseif (!isset($options['wheres'])) {
  1012. $options['wheres'] = array();
  1013. }
  1014. $options['wheres'] = array_merge($options['wheres'], $wheres);
  1015. // merge joins to pass to get_entities()
  1016. if (isset($options['joins']) && !is_array($options['joins'])) {
  1017. $options['joins'] = array($options['joins']);
  1018. } elseif (!isset($options['joins'])) {
  1019. $options['joins'] = array();
  1020. }
  1021. $options['joins'] = array_merge($options['joins'], $joins);
  1022. return elgg_get_entities_from_relationship($options);
  1023. }
  1024. /**
  1025. * Returns a viewable list of entities from location
  1026. *
  1027. * @param array $options Options array
  1028. *
  1029. * @see elgg_list_entities()
  1030. * @see elgg_get_entities_from_location()
  1031. *
  1032. * @return string The viewable list of entities
  1033. * @since 1.8.0
  1034. * @deprecated 1.9.0 See geolocation plugin on github
  1035. */
  1036. function elgg_list_entities_from_location(array $options = array()) {
  1037. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. See geolocation plugin on github', 1.9);
  1038. return elgg_list_entities($options, 'elgg_get_entities_from_location');
  1039. }
  1040. // Some distances in degrees (approximate)
  1041. // @todo huh? see warning on elgg_get_entities_from_location()
  1042. // @deprecated 1.9.0
  1043. define("MILE", 0.01515);
  1044. define("KILOMETER", 0.00932);
  1045. /**
  1046. * Get the current Elgg version information
  1047. *
  1048. * @param bool $humanreadable Whether to return a human readable version (default: false)
  1049. *
  1050. * @return string|false Depending on success
  1051. * @deprecated 1.9 Use elgg_get_version()
  1052. */
  1053. function get_version($humanreadable = false) {
  1054. elgg_deprecated_notice('get_version() has been deprecated by elgg_get_version()', 1.9);
  1055. return elgg_get_version($humanreadable);
  1056. }
  1057. /**
  1058. * Sanitise a string for database use, but with the option of escaping extra characters.
  1059. *
  1060. * @param string $string The string to sanitise
  1061. * @param string $extra_escapeable Extra characters to escape with '\\'
  1062. *
  1063. * @return string The escaped string
  1064. * @deprecated 1.9
  1065. */
  1066. function sanitise_string_special($string, $extra_escapeable = '') {
  1067. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9);
  1068. $string = sanitise_string($string);
  1069. for ($n = 0; $n < strlen($extra_escapeable); $n++) {
  1070. $string = str_replace($extra_escapeable[$n], "\\" . $extra_escapeable[$n], $string);
  1071. }
  1072. return $string;
  1073. }
  1074. /**
  1075. * Establish database connections
  1076. *
  1077. * If the configuration has been set up for multiple read/write databases, set those
  1078. * links up separately; otherwise just create the one database link.
  1079. *
  1080. * @return void
  1081. * @access private
  1082. * @deprecated 1.9
  1083. */
  1084. function setup_db_connections() {
  1085. elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9);
  1086. _elgg_services()->db->setupConnections();
  1087. }
  1088. /**
  1089. * Returns (if required, also creates) a database link resource.
  1090. *
  1091. * Database link resources are stored in the {@link $dblink} global. These
  1092. * resources are created by {@link setup_db_connections()}, which is called if
  1093. * no links exist.
  1094. *
  1095. * @param string $dblinktype The type of link we want: "read", "write" or "readwrite".
  1096. *
  1097. * @return resource Database link
  1098. * @access private
  1099. * @deprecated 1.9
  1100. */
  1101. function get_db_link($dblinktype) {
  1102. elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9);
  1103. return _elgg_services()->db->getLink($dblinktype);
  1104. }
  1105. /**
  1106. * Optimize a table.
  1107. *
  1108. * Executes an OPTIMIZE TABLE query on $table. Useful after large DB changes.
  1109. *
  1110. * @param string $table The name of the table to optimise
  1111. *
  1112. * @return bool
  1113. * @access private
  1114. * @deprecated 1.9
  1115. */
  1116. function optimize_table($table) {
  1117. elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9);
  1118. $table = sanitise_string($table);
  1119. return _elgg_services()->db->updateData("OPTIMIZE TABLE $table");
  1120. }
  1121. /**
  1122. * Return tables matching the database prefix {@link $CONFIG->dbprefix}% in the currently
  1123. * selected database.
  1124. *
  1125. * @return array|false List of tables or false on failure
  1126. * @static array $tables Tables found matching the database prefix
  1127. * @access private
  1128. * @deprecated 1.9
  1129. */
  1130. function get_db_tables() {
  1131. elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9);
  1132. static $tables;
  1133. if (isset($tables)) {
  1134. return $tables;
  1135. }
  1136. $table_prefix = elgg_get_config('dbprefix');
  1137. $result = get_data("SHOW TABLES LIKE '$table_prefix%'");
  1138. $tables = array();
  1139. if (is_array($result) && !empty($result)) {
  1140. foreach ($result as $row) {
  1141. $row = (array) $row;
  1142. if (is_array($row) && !empty($row)) {
  1143. foreach ($row as $element) {
  1144. $tables[] = $element;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. return $tables;
  1150. }
  1151. /**
  1152. * Get the last database error for a particular database link
  1153. *
  1154. * @param resource $dblink The DB link
  1155. *
  1156. * @return string Database error message
  1157. * @access private
  1158. * @deprecated 1.9
  1159. */
  1160. function get_db_error($dblink) {
  1161. elgg_deprecated_notice(__FUNCTION__ . ' is a private function and should not be used.', 1.9);
  1162. return mysql_error($dblink);
  1163. }
  1164. /**
  1165. * Queue a query for execution upon shutdown.
  1166. *
  1167. * You can specify a handler function if you care about the result. This function will accept
  1168. * the raw result from {@link mysql_query()}.
  1169. *
  1170. * @param string $query The query to execute
  1171. * @param resource $dblink The database link to use or the link type (read | write)
  1172. * @param string $handler A callback function to pass the results array to
  1173. *
  1174. * @return boolean Whether successful.
  1175. * @deprecated 1.9 Use execute_delayed_write_query() or execute_delayed_read_query()
  1176. */
  1177. function execute_delayed_query($query, $dblink, $handler = "") {
  1178. elgg_deprecated_notice("execute_delayed_query() has been deprecated", 1.9);
  1179. return _elgg_services()->db->registerDelayedQuery($query, $dblink, $handler);
  1180. }
  1181. /**
  1182. * Return a timestamp for the start of a given day (defaults today).
  1183. *
  1184. * @param int $day Day
  1185. * @param int $month Month
  1186. * @param int $year Year
  1187. *
  1188. * @return int
  1189. * @access private
  1190. * @deprecated 1.9
  1191. */
  1192. function get_day_start($day = null, $month = null, $year = null) {
  1193. elgg_deprecated_notice('get_day_start() has been deprecated', 1.9);
  1194. return mktime(0, 0, 0, $month, $day, $year);
  1195. }
  1196. /**
  1197. * Return a timestamp for the end of a given day (defaults today).
  1198. *
  1199. * @param int $day Day
  1200. * @param int $month Month
  1201. * @param int $year Year
  1202. *
  1203. * @return int
  1204. * @access private
  1205. * @deprecated 1.9
  1206. */
  1207. function get_day_end($day = null, $month = null, $year = null) {
  1208. elgg_deprecated_notice('get_day_end() has been deprecated', 1.9);
  1209. return mktime(23, 59, 59, $month, $day, $year);
  1210. }
  1211. /**
  1212. * Return the notable entities for a given time period.
  1213. *
  1214. * @todo this function also accepts an array(type => subtypes) for 3rd arg. Should we document this?
  1215. *
  1216. * @param int $start_time The start time as a unix timestamp.
  1217. * @param int $end_time The end time as a unix timestamp.
  1218. * @param string $type The type of entity (eg "user", "object" etc)
  1219. * @param string $subtype The arbitrary subtype of the entity
  1220. * @param int $owner_guid The GUID of the owning user
  1221. * @param string $order_by The field to order by; by default, time_created desc
  1222. * @param int $limit The number of entities to return; 10 by default
  1223. * @param int $offset The indexing offset, 0 by default
  1224. * @param boolean $count Set to true to get a count instead of entities. Defaults to false.
  1225. * @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any.
  1226. * @param mixed $container_guid Container or containers to get entities from (default: any).
  1227. *
  1228. * @return array|false
  1229. * @access private
  1230. * @deprecated 1.9
  1231. */
  1232. function get_notable_entities($start_time, $end_time, $type = "", $subtype = "", $owner_guid = 0,
  1233. $order_by = "asc", $limit = 10, $offset = 0, $count = false, $site_guid = 0,
  1234. $container_guid = null) {
  1235. elgg_deprecated_notice('get_notable_entities() has been deprecated', 1.9);
  1236. global $CONFIG;
  1237. if ($subtype === false || $subtype === null || $subtype === 0) {
  1238. return false;
  1239. }
  1240. $start_time = (int)$start_time;
  1241. $end_time = (int)$end_time;
  1242. $order_by = sanitise_string($order_by);
  1243. $limit = (int)$limit;
  1244. $offset = (int)$offset;
  1245. $site_guid = (int) $site_guid;
  1246. if ($site_guid == 0) {
  1247. $site_guid = $CONFIG->site_guid;
  1248. }
  1249. $where = array();
  1250. if (is_array($type)) {
  1251. $tempwhere = "";
  1252. if (sizeof($type)) {
  1253. foreach ($type as $typekey => $subtypearray) {
  1254. foreach ($subtypearray as $subtypeval) {
  1255. $typekey = sanitise_string($typekey);
  1256. if (!empty($subtypeval)) {
  1257. $subtypeval = (int) get_subtype_id($typekey, $subtypeval);
  1258. } else {
  1259. $subtypeval = 0;
  1260. }
  1261. if (!empty($tempwhere)) {
  1262. $tempwhere .= " or ";
  1263. }
  1264. $tempwhere .= "(e.type = '{$typekey}' and e.subtype = {$subtypeval})";
  1265. }
  1266. }
  1267. }
  1268. if (!empty($tempwhere)) {
  1269. $where[] = "({$tempwhere})";
  1270. }
  1271. } else {
  1272. $type = sanitise_string($type);
  1273. $subtype = get_subtype_id($type, $subtype);
  1274. if ($type != "") {
  1275. $where[] = "e.type='$type'";
  1276. }
  1277. if ($subtype !== "") {
  1278. $where[] = "e.subtype=$subtype";
  1279. }
  1280. }
  1281. if ($owner_guid != "") {
  1282. if (!is_array($owner_guid)) {
  1283. $owner_array = array($owner_guid);
  1284. $owner_guid = (int) $owner_guid;
  1285. $where[] = "e.owner_guid = '$owner_guid'";
  1286. } else if (sizeof($owner_guid) > 0) {
  1287. $owner_array = array_map('sanitise_int', $owner_guid);
  1288. // Cast every element to the owner_guid array to int
  1289. $owner_guid = implode(",", $owner_guid);
  1290. $where[] = "e.owner_guid in ({$owner_guid})";
  1291. }
  1292. if (is_null($container_guid)) {
  1293. $container_guid = $owner_array;
  1294. }
  1295. }
  1296. if ($site_guid > 0) {
  1297. $where[] = "e.site_guid = {$site_guid}";
  1298. }
  1299. if (!is_null($container_guid)) {
  1300. if (is_array($container_guid)) {
  1301. foreach ($container_guid as $key => $val) {
  1302. $container_guid[$key] = (int) $val;
  1303. }
  1304. $where[] = "e.container_guid in (" . implode(",", $container_guid) . ")";
  1305. } else {
  1306. $container_guid = (int) $container_guid;
  1307. $where[] = "e.container_guid = {$container_guid}";
  1308. }
  1309. }
  1310. // Add the calendar stuff
  1311. $cal_join = "
  1312. JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
  1313. JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
  1314. JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
  1315. JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
  1316. JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
  1317. JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
  1318. ";
  1319. $where[] = "cal_start_name.string='calendar_start'";
  1320. $where[] = "cal_start_value.string>=$start_time";
  1321. $where[] = "cal_end_name.string='calendar_end'";
  1322. $where[] = "cal_end_value.string <= $end_time";
  1323. if (!$count) {
  1324. $query = "SELECT e.* from {$CONFIG->dbprefix}entities e $cal_join where ";
  1325. } else {
  1326. $query = "SELECT count(e.guid) as total from {$CONFIG->dbprefix}entities e $cal_join where ";
  1327. }
  1328. foreach ($where as $w) {
  1329. $query .= " $w and ";
  1330. }
  1331. $query .= _elgg_get_access_where_sql();
  1332. if (!$count) {
  1333. $query .= " order by n.calendar_start $order_by";
  1334. // Add order and limit
  1335. if ($limit) {
  1336. $query .= " limit $offset, $limit";
  1337. }
  1338. $dt = get_data($query, "entity_row_to_elggstar");
  1339. return $dt;
  1340. } else {
  1341. $total = get_data_row($query);
  1342. return $total->total;
  1343. }
  1344. }
  1345. /**
  1346. * Return the notable entities for a given time period based on an item of metadata.
  1347. *
  1348. * @param int $start_time The start time as a unix timestamp.
  1349. * @param int $end_time The end time as a unix timestamp.
  1350. * @param mixed $meta_name Metadata name
  1351. * @param mixed $meta_value Metadata value
  1352. * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
  1353. * @param string $entity_subtype The subtype of the entity.
  1354. * @param int $owner_guid Owner GUID
  1355. * @param int $limit Limit
  1356. * @param int $offset Offset
  1357. * @param string $order_by Optional ordering.
  1358. * @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any.
  1359. * @param bool $count If true, returns count instead of entities. (Default: false)
  1360. *
  1361. * @return int|array A list of entities, or a count if $count is set to true
  1362. * @access private
  1363. * @deprecated 1.9
  1364. */
  1365. function get_notable_entities_from_metadata($start_time, $end_time, $meta_name, $meta_value = "",
  1366. $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "",
  1367. $site_guid = 0, $count = false) {
  1368. elgg_deprecated_notice('get_notable_entities_from_metadata() has been deprecated', 1.9);
  1369. global $CONFIG;
  1370. $meta_n = get_metastring_id($meta_name);
  1371. $meta_v = get_metastring_id($meta_value);
  1372. $start_time = (int)$start_time;
  1373. $end_time = (int)$end_time;
  1374. $entity_type = sanitise_string($entity_type);
  1375. $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
  1376. $limit = (int)$limit;
  1377. $offset = (int)$offset;
  1378. if ($order_by == "") {
  1379. $order_by = "e.time_created desc";
  1380. }
  1381. $order_by = sanitise_string($order_by);
  1382. $site_guid = (int) $site_guid;
  1383. if ((is_array($owner_guid) && (count($owner_guid)))) {
  1384. foreach ($owner_guid as $key => $guid) {
  1385. $owner_guid[$key] = (int) $guid;
  1386. }
  1387. } else {
  1388. $owner_guid = (int) $owner_guid;
  1389. }
  1390. if ($site_guid == 0) {
  1391. $site_guid = $CONFIG->site_guid;
  1392. }
  1393. //$access = get_access_list();
  1394. $where = array();
  1395. if ($entity_type != "") {
  1396. $where[] = "e.type='$entity_type'";
  1397. }
  1398. if ($entity_subtype) {
  1399. $where[] = "e.subtype=$entity_subtype";
  1400. }
  1401. if ($meta_name != "") {
  1402. $where[] = "m.name_id='$meta_n'";
  1403. }
  1404. if ($meta_value != "") {
  1405. $where[] = "m.value_id='$meta_v'";
  1406. }
  1407. if ($site_guid > 0) {
  1408. $where[] = "e.site_guid = {$site_guid}";
  1409. }
  1410. if (is_array($owner_guid)) {
  1411. $where[] = "e.container_guid in (" . implode(",", $owner_guid) . ")";
  1412. } else if ($owner_guid > 0) {
  1413. $where[] = "e.container_guid = {$owner_guid}";
  1414. }
  1415. // Add the calendar stuff
  1416. $cal_join = "
  1417. JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
  1418. JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
  1419. JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
  1420. JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
  1421. JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
  1422. JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
  1423. ";
  1424. $where[] = "cal_start_name.string='calendar_start'";
  1425. $where[] = "cal_start_value.string>=$start_time";
  1426. $where[] = "cal_end_name.string='calendar_end'";
  1427. $where[] = "cal_end_value.string <= $end_time";
  1428. if (!$count) {
  1429. $query = "SELECT distinct e.* ";
  1430. } else {
  1431. $query = "SELECT count(distinct e.guid) as total ";
  1432. }
  1433. $query .= "from {$CONFIG->dbprefix}entities e"
  1434. . " JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid $cal_join where";
  1435. foreach ($where as $w) {
  1436. $query .= " $w and ";
  1437. }
  1438. // Add access controls
  1439. $query .= _elgg_get_access_where_sql(array('table_alias' => 'e'));
  1440. $query .= ' and ' . _elgg_get_access_where_sql(array('table_alias' => "m"));
  1441. if (!$count) {
  1442. // Add order and limit
  1443. $query .= " order by $order_by limit $offset, $limit";
  1444. return get_data($query, "entity_row_to_elggstar");
  1445. } else {
  1446. if ($row = get_data_row($query)) {
  1447. return $row->total;
  1448. }
  1449. }
  1450. return false;
  1451. }
  1452. /**
  1453. * Return the notable entities for a given time period based on their relationship.
  1454. *
  1455. * @param int $start_time The start time as a unix timestamp.
  1456. * @param int $end_time The end time as a unix timestamp.
  1457. * @param string $relationship The relationship eg "friends_of"
  1458. * @param int $relationship_guid The guid of the entity to use query
  1459. * @param bool $inverse_relationship Reverse the normal function of the query to say
  1460. * "give me all entities for whom $relationship_guid is a
  1461. * $relationship of"
  1462. * @param string $type Entity type
  1463. * @param string $subtype Entity subtype
  1464. * @param int $owner_guid Owner GUID
  1465. * @param string $order_by Optional Order by
  1466. * @param int $limit Limit
  1467. * @param int $offset Offset
  1468. * @param boolean $count If true returns a count of entities (default false)
  1469. * @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any
  1470. *
  1471. * @return array|int|false An array of entities, or the number of entities, or false on failure
  1472. * @access private
  1473. * @deprecated 1.9
  1474. */
  1475. function get_noteable_entities_from_relationship($start_time, $end_time, $relationship,
  1476. $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0,
  1477. $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) {
  1478. elgg_deprecated_notice('get_noteable_entities_from_relationship() has been deprecated', 1.9);
  1479. global $CONFIG;
  1480. $start_time = (int)$start_time;
  1481. $end_time = (int)$end_time;
  1482. $relationship = sanitise_string($relationship);
  1483. $relationship_guid = (int)$relationship_guid;
  1484. $inverse_relationship = (bool)$inverse_relationship;
  1485. $type = sanitise_string($type);
  1486. $subtype = get_subtype_id($type, $subtype);
  1487. $owner_guid = (int)$owner_guid;
  1488. if ($order_by == "") {
  1489. $order_by = "time_created desc";
  1490. }
  1491. $order_by = sanitise_string($order_by);
  1492. $limit = (int)$limit;
  1493. $offset = (int)$offset;
  1494. $site_guid = (int) $site_guid;
  1495. if ($site_guid == 0) {
  1496. $site_guid = $CONFIG->site_guid;
  1497. }
  1498. //$access = get_access_list();
  1499. $where = array();
  1500. if ($relationship != "") {
  1501. $where[] = "r.relationship='$relationship'";
  1502. }
  1503. if ($relationship_guid) {
  1504. $where[] = $inverse_relationship ?
  1505. "r.guid_two='$relationship_guid'" : "r.guid_one='$relationship_guid'";
  1506. }
  1507. if ($type != "") {
  1508. $where[] = "e.type='$type'";
  1509. }
  1510. if ($subtype) {
  1511. $where[] = "e.subtype=$subtype";
  1512. }
  1513. if ($owner_guid != "") {
  1514. $where[] = "e.container_guid='$owner_guid'";
  1515. }
  1516. if ($site_guid > 0) {
  1517. $where[] = "e.site_guid = {$site_guid}";
  1518. }
  1519. // Add the calendar stuff
  1520. $cal_join = "
  1521. JOIN {$CONFIG->dbprefix}metadata cal_start on e.guid=cal_start.entity_guid
  1522. JOIN {$CONFIG->dbprefix}metastrings cal_start_name on cal_start.name_id=cal_start_name.id
  1523. JOIN {$CONFIG->dbprefix}metastrings cal_start_value on cal_start.value_id=cal_start_value.id
  1524. JOIN {$CONFIG->dbprefix}metadata cal_end on e.guid=cal_end.entity_guid
  1525. JOIN {$CONFIG->dbprefix}metastrings cal_end_name on cal_end.name_id=cal_end_name.id
  1526. JOIN {$CONFIG->dbprefix}metastrings cal_end_value on cal_end.value_id=cal_end_value.id
  1527. ";
  1528. $where[] = "cal_start_name.string='calendar_start'";
  1529. $where[] = "cal_start_value.string>=$start_time";
  1530. $where[] = "cal_end_name.string='calendar_end'";
  1531. $where[] = "cal_end_value.string <= $end_time";
  1532. // Select what we're joining based on the options
  1533. $joinon = "e.guid = r.guid_one";
  1534. if (!$inverse_relationship) {
  1535. $joinon = "e.guid = r.guid_two";
  1536. }
  1537. if ($count) {
  1538. $query = "SELECT count(distinct e.guid) as total ";
  1539. } else {
  1540. $query = "SELECT distinct e.* ";
  1541. }
  1542. $query .= " from {$CONFIG->dbprefix}entity_relationships r"
  1543. . " JOIN {$CONFIG->dbprefix}entities e on $joinon $cal_join where ";
  1544. foreach ($where as $w) {
  1545. $query .= " $w and ";
  1546. }
  1547. // Add access controls
  1548. $query .= _elgg_get_access_where_sql();
  1549. if (!$count) {
  1550. $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
  1551. return get_data($query, "entity_row_to_elggstar");
  1552. } else {
  1553. if ($count = get_data_row($query)) {
  1554. return $count->total;
  1555. }
  1556. }
  1557. return false;
  1558. }
  1559. /**
  1560. * Get all entities for today.
  1561. *
  1562. * @param string $type The type of entity (eg "user", "object" etc)
  1563. * @param string $subtype The arbitrary subtype of the entity
  1564. * @param int $owner_guid The GUID of the owning user
  1565. * @param string $order_by The field to order by; by default, time_created desc
  1566. * @param int $limit The number of entities to return; 10 by default
  1567. * @param int $offset The indexing offset, 0 by default
  1568. * @param boolean $count If true returns a count of entities (default false)
  1569. * @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any
  1570. * @param mixed $container_guid Container(s) to get entities from (default: any).
  1571. *
  1572. * @return array|false
  1573. * @access private
  1574. * @deprecated 1.9
  1575. */
  1576. function get_todays_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "",
  1577. $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null) {
  1578. elgg_deprecated_notice('get_todays_entities() has been deprecated', 1.9);
  1579. $day_start = get_day_start();
  1580. $day_end = get_day_end();
  1581. return get_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $order_by,
  1582. $limit, $offset, $count, $site_guid, $container_guid);
  1583. }
  1584. /**
  1585. * Get entities for today from metadata.
  1586. *
  1587. * @param mixed $meta_name Metadata name
  1588. * @param mixed $meta_value Metadata value
  1589. * @param string $entity_type The type of entity to look for, eg 'site' or 'object'
  1590. * @param string $entity_subtype The subtype of the entity.
  1591. * @param int $owner_guid Owner GUID
  1592. * @param int $limit Limit
  1593. * @param int $offset Offset
  1594. * @param string $order_by Optional ordering.
  1595. * @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any.
  1596. * @param bool $count If true, returns count instead of entities. (Default: false)
  1597. *
  1598. * @return int|array A list of entities, or a count if $count is set to true
  1599. * @access private
  1600. * @deprecated 1.9
  1601. */
  1602. function get_todays_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "",
  1603. $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0,
  1604. $count = false) {
  1605. elgg_deprecated_notice('get_todays_entities_from_metadata() has been deprecated', 1.9);
  1606. $day_start = get_day_start();
  1607. $day_end = get_day_end();
  1608. return get_notable_entities_from_metadata($day_start, $day_end, $meta_name, $meta_value,
  1609. $entity_type, $entity_subtype, $owner_guid, $limit, $offset, $order_by, $site_guid, $count);
  1610. }
  1611. /**
  1612. * Get entities for today from a relationship
  1613. *
  1614. * @param string $relationship The relationship eg "friends_of"
  1615. * @param int $relationship_guid The guid of the entity to use query
  1616. * @param bool $inverse_relationship Reverse the normal function of the query to say
  1617. * "give me all entities for whom $relationship_guid is a
  1618. * $relationship of"
  1619. * @param string $type Entity type
  1620. * @param string $subtype Entity subtype
  1621. * @param int $owner_guid Owner GUID
  1622. * @param string $order_by Optional Order by
  1623. * @param int $limit Limit
  1624. * @param int $offset Offset
  1625. * @param boolean $count If true returns a count of entities (default false)
  1626. * @param int $site_guid Site to get entities for. Default 0 = current site. -1 = any
  1627. *
  1628. * @return array|int|false An array of entities, or the number of entities, or false on failure
  1629. * @access private
  1630. * @deprecated 1.9
  1631. */
  1632. function get_todays_entities_from_relationship($relationship, $relationship_guid,
  1633. $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0,
  1634. $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) {
  1635. elgg_deprecated_notice('get_todays_entities_from_relationship() has been deprecated', 1.9);
  1636. $day_start = get_day_start();
  1637. $day_end = get_day_end();
  1638. return get_notable_entities_from_relationship($day_start, $day_end, $relationship,
  1639. $relationship_guid, $inverse_relationship, $type, $subtype, $owner_guid, $order_by,
  1640. $limit, $offset, $count, $site_guid);
  1641. }
  1642. /**
  1643. * Returns a viewable list of entities for a given time period.
  1644. *
  1645. * @see elgg_view_entity_list
  1646. *
  1647. * @param int $start_time The start time as a unix timestamp.
  1648. * @param int $end_time The end time as a unix timestamp.
  1649. * @param string $type The type of entity (eg "user", "object" etc)
  1650. * @param string $subtype The arbitrary subtype of the entity
  1651. * @param int $owner_guid The GUID of the owning user
  1652. * @param int $limit The number of entities to return; 10 by default
  1653. * @param boolean $fullview Whether or not to display the full view (default: true)
  1654. * @param boolean $listtypetoggle Whether or not to allow gallery view
  1655. * @param boolean $navigation Display pagination? Default: true
  1656. *
  1657. * @return string A viewable list of entities
  1658. * @access private
  1659. * @deprecated 1.9
  1660. */
  1661. function list_notable_entities($start_time, $end_time, $type= "", $subtype = "", $owner_guid = 0,
  1662. $limit = 10, $fullview = true, $listtypetoggle = false, $navigation = true) {
  1663. elgg_deprecated_notice('list_notable_entities() has been deprecated', 1.9);
  1664. $offset = (int) get_input('offset');
  1665. $count = get_notable_entities($start_time, $end_time, $type, $subtype,
  1666. $owner_guid, "", $limit, $offset, true);
  1667. $entities = get_notable_entities($start_time, $end_time, $type, $subtype,
  1668. $owner_guid, "", $limit, $offset);
  1669. return elgg_view_entity_list($entities, $count, $offset, $limit,
  1670. $fullview, $listtypetoggle, $navigation);
  1671. }
  1672. /**
  1673. * Return a list of today's entities.
  1674. *
  1675. * @see list_notable_entities
  1676. *
  1677. * @param string $type The type of entity (eg "user", "object" etc)
  1678. * @param string $subtype The arbitrary subtype of the entity
  1679. * @param int $owner_guid The GUID of the owning user
  1680. * @param int $limit The number of entities to return; 10 by default
  1681. * @param boolean $fullview Whether or not to display the full view (default: true)
  1682. * @param boolean $listtypetoggle Whether or not to allow gallery view
  1683. * @param boolean $navigation Display pagination? Default: true
  1684. *
  1685. * @return string A viewable list of entities
  1686. * @access private
  1687. * @deprecated 1.9
  1688. */
  1689. function list_todays_entities($type= "", $subtype = "", $owner_guid = 0, $limit = 10,
  1690. $fullview = true, $listtypetoggle = false, $navigation = true) {
  1691. elgg_deprecated_notice('list_todays_entities() has been deprecated', 1.9);
  1692. $day_start = get_day_start();
  1693. $day_end = get_day_end();
  1694. return list_notable_entities($day_start, $day_end, $type, $subtype, $owner_guid, $limit,
  1695. $fullview, $listtypetoggle, $navigation);
  1696. }
  1697. /**
  1698. * Regenerates the simple cache.
  1699. *
  1700. * Not required any longer since cached files are created on demand.
  1701. *
  1702. * @warning This does not invalidate the cache, but actively rebuilds it.
  1703. *
  1704. * @param string $viewtype Optional viewtype to regenerate. Defaults to all valid viewtypes.
  1705. *
  1706. * @return void
  1707. * @since 1.8.0
  1708. * @deprecated 1.9 Use elgg_invalidate_simplecache()
  1709. */
  1710. function elgg_regenerate_simplecache($viewtype = NULL) {
  1711. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_invalidate_simplecache()', 1.9);
  1712. elgg_invalidate_simplecache();
  1713. }
  1714. /**
  1715. * @access private
  1716. * @deprecated 1.9 Use elgg_get_system_cache()
  1717. */
  1718. function elgg_get_filepath_cache() {
  1719. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_get_system_cache()', 1.9);
  1720. return elgg_get_system_cache();
  1721. }
  1722. /**
  1723. * @access private
  1724. * @deprecated 1.9 Use elgg_reset_system_cache()
  1725. */
  1726. function elgg_filepath_cache_reset() {
  1727. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_reset_system_cache()', 1.9);
  1728. elgg_reset_system_cache();
  1729. }
  1730. /**
  1731. * @access private
  1732. * @deprecated 1.9 Use elgg_save_system_cache()
  1733. */
  1734. function elgg_filepath_cache_save($type, $data) {
  1735. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_save_system_cache()', 1.9);
  1736. return elgg_save_system_cache($type, $data);
  1737. }
  1738. /**
  1739. * @access private
  1740. * @deprecated 1.9 Use elgg_load_system_cache()
  1741. */
  1742. function elgg_filepath_cache_load($type) {
  1743. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_load_system_cache()', 1.9);
  1744. return elgg_load_system_cache($type);
  1745. }
  1746. /**
  1747. * @access private
  1748. * @deprecated 1.9 Use elgg_enable_system_cache()
  1749. */
  1750. function elgg_enable_filepath_cache() {
  1751. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_enable_system_cache()', 1.9);
  1752. elgg_enable_system_cache();
  1753. }
  1754. /**
  1755. * @access private
  1756. * @deprecated 1.9 Use elgg_disable_system_cache()
  1757. */
  1758. function elgg_disable_filepath_cache() {
  1759. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_disable_system_cache()', 1.9);
  1760. elgg_disable_system_cache();
  1761. }
  1762. /**
  1763. * Unregisters an entity type and subtype as a public-facing type.
  1764. *
  1765. * @warning With a blank subtype, it unregisters that entity type including
  1766. * all subtypes. This must be called after all subtypes have been registered.
  1767. *
  1768. * @param string $type The type of entity (object, site, user, group)
  1769. * @param string $subtype The subtype to register (may be blank)
  1770. *
  1771. * @return true|false Depending on success
  1772. * @deprecated 1.9 Use {@link elgg_unregister_entity_type()}
  1773. */
  1774. function unregister_entity_type($type, $subtype) {
  1775. elgg_deprecated_notice("unregister_entity_type() was deprecated by elgg_unregister_entity_type()", 1.9);
  1776. return elgg_unregister_entity_type($type, $subtype);
  1777. }
  1778. /**
  1779. * Function to determine if the object trying to attach to other, has already done so
  1780. *
  1781. * @param int $guid_one This is the target object
  1782. * @param int $guid_two This is the object trying to attach to $guid_one
  1783. *
  1784. * @return bool
  1785. * @access private
  1786. * @deprecated 1.9 Use check_entity_relationship()
  1787. */
  1788. function already_attached($guid_one, $guid_two) {
  1789. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  1790. if ($attached = check_entity_relationship($guid_one, "attached", $guid_two)) {
  1791. return true;
  1792. } else {
  1793. return false;
  1794. }
  1795. }
  1796. /**
  1797. * Function to get all objects attached to a particular object
  1798. *
  1799. * @param int $guid Entity GUID
  1800. * @param string $type The type of object to return e.g. 'file', 'friend_of' etc
  1801. *
  1802. * @return ElggObject[] array of objects
  1803. * @access private
  1804. * @deprecated 1.9 Use elgg_get_entities_from_relationship()
  1805. */
  1806. function get_attachments($guid, $type = "") {
  1807. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  1808. $options = array(
  1809. 'relationship' => 'attached',
  1810. 'relationship_guid' => $guid,
  1811. 'inverse_relationship' => false,
  1812. 'types' => $type,
  1813. 'subtypes' => '',
  1814. 'owner_guid' => 0,
  1815. 'order_by' => 'time_created desc',
  1816. 'limit' => 10,
  1817. 'offset' => 0,
  1818. 'count' => false,
  1819. 'site_guid' => 0
  1820. );
  1821. $attached = elgg_get_entities_from_relationship($options);
  1822. return $attached;
  1823. }
  1824. /**
  1825. * Function to remove a particular attachment between two objects
  1826. *
  1827. * @param int $guid_one This is the target object
  1828. * @param int $guid_two This is the object to remove from $guid_one
  1829. *
  1830. * @return void
  1831. * @access private
  1832. * @deprecated 1.9 Use remove_entity_relationship()
  1833. */
  1834. function remove_attachment($guid_one, $guid_two) {
  1835. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  1836. if (already_attached($guid_one, $guid_two)) {
  1837. remove_entity_relationship($guid_one, "attached", $guid_two);
  1838. }
  1839. }
  1840. /**
  1841. * Function to start the process of attaching one object to another
  1842. *
  1843. * @param int $guid_one This is the target object
  1844. * @param int $guid_two This is the object trying to attach to $guid_one
  1845. *
  1846. * @return true|void
  1847. * @access private
  1848. * @deprecated 1.9 Use add_entity_relationship()
  1849. */
  1850. function make_attachment($guid_one, $guid_two) {
  1851. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  1852. if (!(already_attached($guid_one, $guid_two))) {
  1853. if (add_entity_relationship($guid_one, "attached", $guid_two)) {
  1854. return true;
  1855. }
  1856. }
  1857. }
  1858. /**
  1859. * Returns the URL for an entity.
  1860. *
  1861. * @param int $entity_guid The GUID of the entity
  1862. *
  1863. * @return string The URL of the entity
  1864. * @deprecated 1.9 Use \ElggEntity::getURL()
  1865. */
  1866. function get_entity_url($entity_guid) {
  1867. elgg_deprecated_notice('get_entity_url has been deprecated in favor of \ElggEntity::getURL', '1.9');
  1868. if ($entity = get_entity($entity_guid)) {
  1869. return $entity->getURL();
  1870. }
  1871. return false;
  1872. }
  1873. /**
  1874. * Delete an entity.
  1875. *
  1876. * Removes an entity and its metadata, annotations, relationships, river entries,
  1877. * and private data.
  1878. *
  1879. * Optionally can remove entities contained and owned by $guid.
  1880. *
  1881. * @warning If deleting recursively, this bypasses ownership of items contained by
  1882. * the entity. That means that if the container_guid = $guid, the item will be deleted
  1883. * regardless of who owns it.
  1884. *
  1885. * @param int $guid The guid of the entity to delete
  1886. * @param bool $recursive If true (default) then all entities which are
  1887. * owned or contained by $guid will also be deleted.
  1888. *
  1889. * @return bool
  1890. * @access private
  1891. * @deprecated 1.9 Use \ElggEntity::delete() instead.
  1892. */
  1893. function delete_entity($guid, $recursive = true) {
  1894. elgg_deprecated_notice('delete_entity has been deprecated in favor of \ElggEntity::delete', '1.9');
  1895. $guid = (int)$guid;
  1896. if ($entity = get_entity($guid)) {
  1897. return $entity->delete($recursive);
  1898. }
  1899. return false;
  1900. }
  1901. /**
  1902. * Enable an entity.
  1903. *
  1904. * @warning In order to enable an entity using \ElggEntity::enable(),
  1905. * you must first use {@link access_show_hidden_entities()}.
  1906. *
  1907. * @param int $guid GUID of entity to enable
  1908. * @param bool $recursive Recursively enable all entities disabled with the entity?
  1909. *
  1910. * @return bool
  1911. * @deprecated 1.9 Use elgg_enable_entity()
  1912. */
  1913. function enable_entity($guid, $recursive = true) {
  1914. elgg_deprecated_notice('enable_entity has been deprecated in favor of elgg_enable_entity', '1.9');
  1915. $guid = (int)$guid;
  1916. // Override access only visible entities
  1917. $old_access_status = access_get_show_hidden_status();
  1918. access_show_hidden_entities(true);
  1919. $result = false;
  1920. if ($entity = get_entity($guid)) {
  1921. $result = $entity->enable($recursive);
  1922. }
  1923. access_show_hidden_entities($old_access_status);
  1924. return $result;
  1925. }
  1926. /**
  1927. * Returns if $user_guid can edit the metadata on $entity_guid.
  1928. *
  1929. * @tip Can be overridden by by registering for the permissions_check:metadata
  1930. * plugin hook.
  1931. *
  1932. * @warning If a $user_guid isn't specified, the currently logged in user is used.
  1933. *
  1934. * @param int $entity_guid The GUID of the entity
  1935. * @param int $user_guid The GUID of the user
  1936. * @param \ElggMetadata $metadata The metadata to specifically check (if any; default null)
  1937. *
  1938. * @return bool Whether the user can edit metadata on the entity.
  1939. * @deprecated 1.9 Use \ElggEntity::canEditMetadata
  1940. */
  1941. function can_edit_entity_metadata($entity_guid, $user_guid = 0, $metadata = null) {
  1942. elgg_deprecated_notice('can_edit_entity_metadata has been deprecated in favor of \ElggEntity::canEditMetadata', '1.9');
  1943. if ($entity = get_entity($entity_guid)) {
  1944. return $entity->canEditMetadata($metadata, $user_guid);
  1945. } else {
  1946. return false;
  1947. }
  1948. }
  1949. /**
  1950. * Disable an entity.
  1951. *
  1952. * Disabled entities do not show up in list or elgg_get_entities()
  1953. * calls, but still exist in the database.
  1954. *
  1955. * Entities are disabled by setting disabled = yes in the
  1956. * entities table.
  1957. *
  1958. * You can ignore the disabled field by using {@link access_show_hidden_entities()}.
  1959. *
  1960. * @param int $guid The guid
  1961. * @param string $reason Optional reason
  1962. * @param bool $recursive Recursively disable all entities owned or contained by $guid?
  1963. *
  1964. * @return bool
  1965. * @see access_show_hidden_entities()
  1966. * @access private
  1967. * @deprecated 1.9 Use \ElggEntity::disable instead.
  1968. */
  1969. function disable_entity($guid, $reason = "", $recursive = true) {
  1970. elgg_deprecated_notice('disable_entity was deprecated in favor of \ElggEntity::disable', '1.9');
  1971. if ($entity = get_entity($guid)) {
  1972. return $entity->disable($reason, $recursive);
  1973. }
  1974. return false;
  1975. }
  1976. /**
  1977. * Returns if $user_guid is able to edit $entity_guid.
  1978. *
  1979. * @tip Can be overridden by registering for the permissions_check plugin hook.
  1980. *
  1981. * @warning If a $user_guid is not passed it will default to the logged in user.
  1982. *
  1983. * @param int $entity_guid The GUID of the entity
  1984. * @param int $user_guid The GUID of the user
  1985. *
  1986. * @return bool
  1987. * @deprecated 1.9 Use \ElggEntity::canEdit instead
  1988. */
  1989. function can_edit_entity($entity_guid, $user_guid = 0) {
  1990. elgg_deprecated_notice('can_edit_entity was deprecated in favor of \ElggEntity::canEdit', '1.9');
  1991. if ($entity = get_entity($entity_guid)) {
  1992. return $entity->canEdit($user_guid);
  1993. }
  1994. return false;
  1995. }
  1996. /**
  1997. * Join a user to a group.
  1998. *
  1999. * @param int $group_guid The group GUID.
  2000. * @param int $user_guid The user GUID.
  2001. *
  2002. * @return bool
  2003. * @deprecated 1.9 Use \ElggGroup::join instead.
  2004. */
  2005. function join_group($group_guid, $user_guid) {
  2006. elgg_deprecated_notice('join_group was deprecated in favor of \ElggGroup::join', '1.9');
  2007. $group = get_entity($group_guid);
  2008. $user = get_entity($user_guid);
  2009. if ($group instanceof \ElggGroup && $user instanceof \ElggUser) {
  2010. return $group->join($user);
  2011. }
  2012. return false;
  2013. }
  2014. /**
  2015. * Remove a user from a group.
  2016. *
  2017. * @param int $group_guid The group.
  2018. * @param int $user_guid The user.
  2019. *
  2020. * @return bool Whether the user was removed from the group.
  2021. * @deprecated 1.9 Use \ElggGroup::leave()
  2022. */
  2023. function leave_group($group_guid, $user_guid) {
  2024. elgg_deprecated_notice('leave_group was deprecated in favor of \ElggGroup::leave', '1.9');
  2025. $group = get_entity($group_guid);
  2026. $user = get_entity($user_guid);
  2027. if ($group instanceof \ElggGroup && $user instanceof \ElggUser) {
  2028. return $group->leave($user);
  2029. }
  2030. return false;
  2031. }
  2032. /**
  2033. * Create paragraphs from text with line spacing
  2034. *
  2035. * @param string $string The string
  2036. * @return string
  2037. * @deprecated 1.9 Use elgg_autop instead
  2038. **/
  2039. function autop($string) {
  2040. elgg_deprecated_notice('autop has been deprecated in favor of elgg_autop', '1.9');
  2041. return elgg_autop($string);
  2042. }
  2043. /**
  2044. * Register a function as a web service method
  2045. *
  2046. * @deprecated 1.9 Enable the web services plugin and use elgg_ws_expose_function().
  2047. */
  2048. function expose_function($method, $function, array $parameters = NULL, $description = "",
  2049. $call_method = "GET", $require_api_auth = false, $require_user_auth = false) {
  2050. elgg_deprecated_notice("expose_function() deprecated for the function elgg_ws_expose_function() in web_services plugin", 1.9);
  2051. if (!elgg_admin_notice_exists("elgg:ws:1.9")) {
  2052. elgg_add_admin_notice("elgg:ws:1.9", "The web services are now a plugin in Elgg 1.9.
  2053. You must enable this plugin and update your web services to use elgg_ws_expose_function().");
  2054. }
  2055. if (function_exists("elgg_ws_expose_function")) {
  2056. return elgg_ws_expose_function($method, $function, $parameters, $description, $call_method, $require_api_auth, $require_user_auth);
  2057. }
  2058. }
  2059. /**
  2060. * Unregister a web services method
  2061. *
  2062. * @param string $method The api name that was exposed
  2063. * @return void
  2064. * @deprecated 1.9 Enable the web services plugin and use elgg_ws_unexpose_function().
  2065. */
  2066. function unexpose_function($method) {
  2067. elgg_deprecated_notice("unexpose_function() deprecated for the function elgg_ws_unexpose_function() in web_services plugin", 1.9);
  2068. if (function_exists("elgg_ws_unexpose_function")) {
  2069. return elgg_ws_unexpose_function($method);
  2070. }
  2071. }
  2072. /**
  2073. * Registers a web services handler
  2074. *
  2075. * @param string $handler Web services type
  2076. * @param string $function Your function name
  2077. * @return bool Depending on success
  2078. * @deprecated 1.9 Enable the web services plugin and use elgg_ws_register_service_handler().
  2079. */
  2080. function register_service_handler($handler, $function) {
  2081. elgg_deprecated_notice("register_service_handler() deprecated for the function elgg_ws_register_service_handler() in web_services plugin", 1.9);
  2082. if (function_exists("elgg_ws_register_service_handler")) {
  2083. return elgg_ws_register_service_handler($handler, $function);
  2084. }
  2085. }
  2086. /**
  2087. * Remove a web service
  2088. * To replace a web service handler, register the desired handler over the old on
  2089. * with register_service_handler().
  2090. *
  2091. * @param string $handler web services type
  2092. * @return void
  2093. * @deprecated 1.9 Enable the web services plugin and use elgg_ws_unregister_service_handler().
  2094. */
  2095. function unregister_service_handler($handler) {
  2096. elgg_deprecated_notice("unregister_service_handler() deprecated for the function elgg_ws_unregister_service_handler() in web_services plugin", 1.9);
  2097. if (function_exists("elgg_ws_unregister_service_handler")) {
  2098. return elgg_ws_unregister_service_handler($handler);
  2099. }
  2100. }
  2101. /**
  2102. * Create or update the entities table for a given site.
  2103. * Call create_entity first.
  2104. *
  2105. * @param int $guid Site GUID
  2106. * @param string $name Site name
  2107. * @param string $description Site Description
  2108. * @param string $url URL of the site
  2109. *
  2110. * @return bool
  2111. * @access private
  2112. * @deprecated 1.9 Use \ElggSite constructor
  2113. */
  2114. function create_site_entity($guid, $name, $description, $url) {
  2115. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggSite constructor', 1.9);
  2116. global $CONFIG;
  2117. $guid = (int)$guid;
  2118. $name = sanitise_string($name);
  2119. $description = sanitise_string($description);
  2120. $url = sanitise_string($url);
  2121. $row = get_entity_as_row($guid);
  2122. if ($row) {
  2123. // Exists and you have access to it
  2124. $query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}";
  2125. if ($exists = get_data_row($query)) {
  2126. $query = "UPDATE {$CONFIG->dbprefix}sites_entity
  2127. set name='$name', description='$description', url='$url' where guid=$guid";
  2128. $result = update_data($query);
  2129. if ($result != false) {
  2130. // Update succeeded, continue
  2131. $entity = get_entity($guid);
  2132. if (elgg_trigger_event('update', $entity->type, $entity)) {
  2133. return $guid;
  2134. } else {
  2135. $entity->delete();
  2136. //delete_entity($guid);
  2137. }
  2138. }
  2139. } else {
  2140. // Update failed, attempt an insert.
  2141. $query = "INSERT into {$CONFIG->dbprefix}sites_entity
  2142. (guid, name, description, url) values ($guid, '$name', '$description', '$url')";
  2143. $result = insert_data($query);
  2144. if ($result !== false) {
  2145. $entity = get_entity($guid);
  2146. if (elgg_trigger_event('create', $entity->type, $entity)) {
  2147. return $guid;
  2148. } else {
  2149. $entity->delete();
  2150. //delete_entity($guid);
  2151. }
  2152. }
  2153. }
  2154. }
  2155. return false;
  2156. }
  2157. /**
  2158. * Create or update the entities table for a given group.
  2159. * Call create_entity first.
  2160. *
  2161. * @param int $guid GUID
  2162. * @param string $name Name
  2163. * @param string $description Description
  2164. *
  2165. * @return bool
  2166. * @access private
  2167. * @deprecated 1.9 Use \ElggGroup constructor
  2168. */
  2169. function create_group_entity($guid, $name, $description) {
  2170. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggGroup constructor', 1.9);
  2171. global $CONFIG;
  2172. $guid = (int)$guid;
  2173. $name = sanitise_string($name);
  2174. $description = sanitise_string($description);
  2175. $row = get_entity_as_row($guid);
  2176. if ($row) {
  2177. // Exists and you have access to it
  2178. $exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}groups_entity WHERE guid = {$guid}");
  2179. if ($exists) {
  2180. $query = "UPDATE {$CONFIG->dbprefix}groups_entity set"
  2181. . " name='$name', description='$description' where guid=$guid";
  2182. $result = update_data($query);
  2183. if ($result != false) {
  2184. // Update succeeded, continue
  2185. $entity = get_entity($guid);
  2186. if (elgg_trigger_event('update', $entity->type, $entity)) {
  2187. return $guid;
  2188. } else {
  2189. $entity->delete();
  2190. }
  2191. }
  2192. } else {
  2193. // Update failed, attempt an insert.
  2194. $query = "INSERT into {$CONFIG->dbprefix}groups_entity"
  2195. . " (guid, name, description) values ($guid, '$name', '$description')";
  2196. $result = insert_data($query);
  2197. if ($result !== false) {
  2198. $entity = get_entity($guid);
  2199. if (elgg_trigger_event('create', $entity->type, $entity)) {
  2200. return $guid;
  2201. } else {
  2202. $entity->delete();
  2203. }
  2204. }
  2205. }
  2206. }
  2207. return false;
  2208. }
  2209. /**
  2210. * Create or update the entities table for a given user.
  2211. * Call create_entity first.
  2212. *
  2213. * @param int $guid The user's GUID
  2214. * @param string $name The user's display name
  2215. * @param string $username The username
  2216. * @param string $password The password
  2217. * @param string $salt A salt for the password
  2218. * @param string $email The user's email address
  2219. * @param string $language The user's default language
  2220. * @param string $code A code
  2221. *
  2222. * @return bool
  2223. * @access private
  2224. * @deprecated 1.9 Use \ElggUser constructor
  2225. */
  2226. function create_user_entity($guid, $name, $username, $password, $salt, $email, $language, $code) {
  2227. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggUser constructor', 1.9);
  2228. global $CONFIG;
  2229. $guid = (int)$guid;
  2230. $name = sanitise_string($name);
  2231. $username = sanitise_string($username);
  2232. $password = sanitise_string($password);
  2233. $salt = sanitise_string($salt);
  2234. $email = sanitise_string($email);
  2235. $language = sanitise_string($language);
  2236. $row = get_entity_as_row($guid);
  2237. if ($row) {
  2238. // Exists and you have access to it
  2239. $query = "SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}";
  2240. if ($exists = get_data_row($query)) {
  2241. $query = "UPDATE {$CONFIG->dbprefix}users_entity
  2242. SET name='$name', username='$username', password='$password', salt='$salt',
  2243. email='$email', language='$language'
  2244. WHERE guid = $guid";
  2245. $result = update_data($query);
  2246. if ($result != false) {
  2247. // Update succeeded, continue
  2248. $entity = get_entity($guid);
  2249. if (elgg_trigger_event('update', $entity->type, $entity)) {
  2250. return $guid;
  2251. } else {
  2252. $entity->delete();
  2253. }
  2254. }
  2255. } else {
  2256. // Exists query failed, attempt an insert.
  2257. $query = "INSERT into {$CONFIG->dbprefix}users_entity
  2258. (guid, name, username, password, salt, email, language)
  2259. values ($guid, '$name', '$username', '$password', '$salt', '$email', '$language')";
  2260. $result = insert_data($query);
  2261. if ($result !== false) {
  2262. $entity = get_entity($guid);
  2263. if (elgg_trigger_event('create', $entity->type, $entity)) {
  2264. return $guid;
  2265. } else {
  2266. $entity->delete();
  2267. }
  2268. }
  2269. }
  2270. }
  2271. return false;
  2272. }
  2273. /**
  2274. * Create or update the extras table for a given object.
  2275. * Call create_entity first.
  2276. *
  2277. * @param int $guid The guid of the entity you're creating (as obtained by create_entity)
  2278. * @param string $title The title of the object
  2279. * @param string $description The object's description
  2280. *
  2281. * @return bool
  2282. * @access private
  2283. * @deprecated 1.9 Use \ElggObject constructor
  2284. */
  2285. function create_object_entity($guid, $title, $description) {
  2286. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggObject constructor', 1.9);
  2287. global $CONFIG;
  2288. $guid = (int)$guid;
  2289. $title = sanitise_string($title);
  2290. $description = sanitise_string($description);
  2291. $row = get_entity_as_row($guid);
  2292. if ($row) {
  2293. // Core entities row exists and we have access to it
  2294. $query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}";
  2295. if ($exists = get_data_row($query)) {
  2296. $query = "UPDATE {$CONFIG->dbprefix}objects_entity
  2297. set title='$title', description='$description' where guid=$guid";
  2298. $result = update_data($query);
  2299. if ($result != false) {
  2300. // Update succeeded, continue
  2301. $entity = get_entity($guid);
  2302. elgg_trigger_event('update', $entity->type, $entity);
  2303. return $guid;
  2304. }
  2305. } else {
  2306. // Update failed, attempt an insert.
  2307. $query = "INSERT into {$CONFIG->dbprefix}objects_entity
  2308. (guid, title, description) values ($guid, '$title','$description')";
  2309. $result = insert_data($query);
  2310. if ($result !== false) {
  2311. $entity = get_entity($guid);
  2312. if (elgg_trigger_event('create', $entity->type, $entity)) {
  2313. return $guid;
  2314. } else {
  2315. $entity->delete();
  2316. }
  2317. }
  2318. }
  2319. }
  2320. return false;
  2321. }
  2322. /**
  2323. * Attempt to construct an ODD object out of a XmlElement or sub-elements.
  2324. *
  2325. * @param XmlElement $element The element(s)
  2326. *
  2327. * @return mixed An ODD object if the element can be handled, or false.
  2328. * @access private
  2329. * @deprecated 1.9
  2330. */
  2331. function ODD_factory (XmlElement $element) {
  2332. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2333. $name = $element->name;
  2334. $odd = false;
  2335. switch ($name) {
  2336. case 'entity' :
  2337. $odd = new ODDEntity("", "", "");
  2338. break;
  2339. case 'metadata' :
  2340. $odd = new ODDMetaData("", "", "", "");
  2341. break;
  2342. case 'relationship' :
  2343. $odd = new ODDRelationship("", "", "");
  2344. break;
  2345. }
  2346. // Now populate values
  2347. if ($odd) {
  2348. // Attributes
  2349. foreach ($element->attributes as $k => $v) {
  2350. $odd->setAttribute($k, $v);
  2351. }
  2352. // Body
  2353. $body = $element->content;
  2354. $a = stripos($body, "<![CDATA");
  2355. $b = strripos($body, "]]>");
  2356. if (($body) && ($a !== false) && ($b !== false)) {
  2357. $body = substr($body, $a + 8, $b - ($a + 8));
  2358. }
  2359. $odd->setBody($body);
  2360. }
  2361. return $odd;
  2362. }
  2363. /**
  2364. * Utility function used by import_entity_plugin_hook() to
  2365. * process an ODDEntity into an unsaved \ElggEntity.
  2366. *
  2367. * @param ODDEntity $element The OpenDD element
  2368. *
  2369. * @return \ElggEntity the unsaved entity which should be populated by items.
  2370. * @todo Remove this.
  2371. * @access private
  2372. *
  2373. * @throws ClassException|InstallationException|ImportException
  2374. * @deprecated 1.9
  2375. */
  2376. function oddentity_to_elggentity(ODDEntity $element) {
  2377. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2378. $class = $element->getAttribute('class');
  2379. $subclass = $element->getAttribute('subclass');
  2380. // See if we already have imported this uuid
  2381. $tmp = get_entity_from_uuid($element->getAttribute('uuid'));
  2382. if (!$tmp) {
  2383. // Construct new class with owner from session
  2384. $classname = get_subtype_class($class, $subclass);
  2385. if ($classname) {
  2386. if (class_exists($classname)) {
  2387. $tmp = new $classname();
  2388. if (!($tmp instanceof \ElggEntity)) {
  2389. $msg = $classname . " is not a " . get_class() . ".";
  2390. throw new \ClassException($msg);
  2391. }
  2392. } else {
  2393. error_log("Class '" . $classname . "' was not found, missing plugin?");
  2394. }
  2395. } else {
  2396. switch ($class) {
  2397. case 'object' :
  2398. $tmp = new \ElggObject();
  2399. break;
  2400. case 'user' :
  2401. $tmp = new \ElggUser();
  2402. break;
  2403. case 'group' :
  2404. $tmp = new \ElggGroup();
  2405. break;
  2406. case 'site' :
  2407. $tmp = new \ElggSite();
  2408. break;
  2409. default:
  2410. $msg = "Type " . $class . " is not supported. This indicates an error in your installation, most likely caused by an incomplete upgrade.";
  2411. throw new \InstallationException($msg);
  2412. }
  2413. }
  2414. }
  2415. if ($tmp) {
  2416. if (!$tmp->import($element)) {
  2417. $msg = "Could not import element " . $element->getAttribute('uuid');
  2418. throw new \ImportException($msg);
  2419. }
  2420. return $tmp;
  2421. }
  2422. return NULL;
  2423. }
  2424. /**
  2425. * Import an ODD document.
  2426. *
  2427. * @param string $xml The XML ODD.
  2428. *
  2429. * @return ODDDocument
  2430. * @access private
  2431. * @deprecated 1.9
  2432. */
  2433. function ODD_Import($xml) {
  2434. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2435. // Parse XML to an array
  2436. $elements = xml_to_object($xml);
  2437. // Sanity check 1, was this actually XML?
  2438. if ((!$elements) || (!$elements->children)) {
  2439. return false;
  2440. }
  2441. // Create ODDDocument
  2442. $document = new ODDDocument();
  2443. // Itterate through array of elements and construct ODD document
  2444. $cnt = 0;
  2445. foreach ($elements->children as $child) {
  2446. $odd = ODD_factory($child);
  2447. if ($odd) {
  2448. $document->addElement($odd);
  2449. $cnt++;
  2450. }
  2451. }
  2452. // Check that we actually found something
  2453. if ($cnt == 0) {
  2454. return false;
  2455. }
  2456. return $document;
  2457. }
  2458. /**
  2459. * Export an ODD Document.
  2460. *
  2461. * @param ODDDocument $document The Document.
  2462. *
  2463. * @return string
  2464. * @access private
  2465. * @deprecated 1.9
  2466. */
  2467. function ODD_Export(ODDDocument $document) {
  2468. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2469. return "$document";
  2470. }
  2471. /**
  2472. * Get a UUID from a given object.
  2473. *
  2474. * @param mixed $object The object either an \ElggEntity, \ElggRelationship or \ElggExtender
  2475. *
  2476. * @return string|false the UUID or false
  2477. * @deprecated 1.9
  2478. */
  2479. function get_uuid_from_object($object) {
  2480. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2481. if ($object instanceof \ElggEntity) {
  2482. return guid_to_uuid($object->guid);
  2483. } else if ($object instanceof \ElggExtender) {
  2484. $type = $object->type;
  2485. if ($type == 'volatile') {
  2486. $uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->name}/";
  2487. } else {
  2488. $uuid = guid_to_uuid($object->entity_guid) . $type . "/{$object->id}/";
  2489. }
  2490. return $uuid;
  2491. } else if ($object instanceof \ElggRelationship) {
  2492. return guid_to_uuid($object->guid_one) . "relationship/{$object->id}/";
  2493. }
  2494. return false;
  2495. }
  2496. /**
  2497. * Generate a UUID from a given GUID.
  2498. *
  2499. * @param int $guid The GUID of an object.
  2500. *
  2501. * @return string
  2502. * @deprecated 1.9
  2503. */
  2504. function guid_to_uuid($guid) {
  2505. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2506. return elgg_get_site_url() . "export/opendd/$guid/";
  2507. }
  2508. /**
  2509. * Test to see if a given uuid is for this domain, returning true if so.
  2510. *
  2511. * @param string $uuid A unique ID
  2512. *
  2513. * @return bool
  2514. * @deprecated 1.9
  2515. */
  2516. function is_uuid_this_domain($uuid) {
  2517. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2518. if (strpos($uuid, elgg_get_site_url()) === 0) {
  2519. return true;
  2520. }
  2521. return false;
  2522. }
  2523. /**
  2524. * This function attempts to retrieve a previously imported entity via its UUID.
  2525. *
  2526. * @param string $uuid A unique ID
  2527. *
  2528. * @return \ElggEntity|false
  2529. * @deprecated 1.9
  2530. */
  2531. function get_entity_from_uuid($uuid) {
  2532. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2533. $uuid = sanitise_string($uuid);
  2534. $options = array('metadata_name' => 'import_uuid', 'metadata_value' => $uuid);
  2535. $entities = elgg_get_entities_from_metadata($options);
  2536. if ($entities) {
  2537. return $entities[0];
  2538. }
  2539. return false;
  2540. }
  2541. /**
  2542. * Tag a previously created guid with the uuid it was imported on.
  2543. *
  2544. * @param int $guid A GUID
  2545. * @param string $uuid A Unique ID
  2546. *
  2547. * @return bool
  2548. * @deprecated 1.9
  2549. */
  2550. function add_uuid_to_guid($guid, $uuid) {
  2551. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2552. $guid = (int)$guid;
  2553. $uuid = sanitise_string($uuid);
  2554. $result = create_metadata($guid, "import_uuid", $uuid);
  2555. return (bool)$result;
  2556. }
  2557. $IMPORTED_DATA = array();
  2558. $IMPORTED_OBJECT_COUNTER = 0;
  2559. /**
  2560. * This function processes an element, passing elements to the plugin stack to see if someone will
  2561. * process it.
  2562. *
  2563. * If nobody processes the top level element, the sub level elements are processed.
  2564. *
  2565. * @param ODD $odd The odd element to process
  2566. *
  2567. * @return bool
  2568. * @access private
  2569. * @deprecated 1.9
  2570. */
  2571. function _process_element(ODD $odd) {
  2572. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2573. global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
  2574. // See if anyone handles this element, return true if it is.
  2575. $to_be_serialised = null;
  2576. if ($odd) {
  2577. $handled = elgg_trigger_plugin_hook("import", "all", array("element" => $odd), $to_be_serialised);
  2578. // If not, then see if any of its sub elements are handled
  2579. if ($handled) {
  2580. // Increment validation counter
  2581. $IMPORTED_OBJECT_COUNTER ++;
  2582. // Return the constructed object
  2583. $IMPORTED_DATA[] = $handled;
  2584. return true;
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. /**
  2590. * Exports an entity as an array
  2591. *
  2592. * @param int $guid Entity GUID
  2593. *
  2594. * @return array
  2595. * @throws ExportException
  2596. * @access private
  2597. * @deprecated 1.9
  2598. */
  2599. function exportAsArray($guid) {
  2600. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2601. $guid = (int)$guid;
  2602. // Trigger a hook to
  2603. $to_be_serialised = elgg_trigger_plugin_hook("export", "all", array("guid" => $guid), array());
  2604. // Sanity check
  2605. if ((!is_array($to_be_serialised)) || (count($to_be_serialised) == 0)) {
  2606. throw new \ExportException("No such entity GUID:" . $guid);
  2607. }
  2608. return $to_be_serialised;
  2609. }
  2610. /**
  2611. * Export a GUID.
  2612. *
  2613. * This function exports a GUID and all information related to it in an XML format.
  2614. *
  2615. * This function makes use of the "serialise" plugin hook, which is passed an array to which plugins
  2616. * should add data to be serialised to.
  2617. *
  2618. * @param int $guid The GUID.
  2619. *
  2620. * @return string XML
  2621. * @see \ElggEntity for an example of its usage.
  2622. * @access private
  2623. * @deprecated 1.9
  2624. */
  2625. function export($guid) {
  2626. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2627. $odd = new ODDDocument(exportAsArray($guid));
  2628. return ODD_Export($odd);
  2629. }
  2630. /**
  2631. * Import an XML serialisation of an object.
  2632. * This will make a best attempt at importing a given xml doc.
  2633. *
  2634. * @param string $xml XML string
  2635. *
  2636. * @return bool
  2637. * @throws ImportException if there was a problem importing the data.
  2638. * @access private
  2639. * @deprecated 1.9
  2640. */
  2641. function import($xml) {
  2642. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9);
  2643. global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
  2644. $IMPORTED_DATA = array();
  2645. $IMPORTED_OBJECT_COUNTER = 0;
  2646. $document = ODD_Import($xml);
  2647. if (!$document) {
  2648. throw new \ImportException("No OpenDD elements found in import data, import failed.");
  2649. }
  2650. foreach ($document as $element) {
  2651. _process_element($element);
  2652. }
  2653. if ($IMPORTED_OBJECT_COUNTER != count($IMPORTED_DATA)) {
  2654. throw new \ImportException("Not all elements were imported.");
  2655. }
  2656. return true;
  2657. }
  2658. /**
  2659. * Register the OpenDD import action
  2660. *
  2661. * @return void
  2662. * @access private
  2663. * @deprecated 1.9
  2664. */
  2665. function _export_init() {
  2666. global $CONFIG;
  2667. elgg_register_action("import/opendd");
  2668. }
  2669. /**
  2670. * Returns the name of views for in a directory.
  2671. *
  2672. * Use this to get all namespaced views under the first element.
  2673. *
  2674. * @param string $dir The main directory that holds the views. (mod/profile/views/)
  2675. * @param string $base The root name of the view to use, without the viewtype. (profile)
  2676. *
  2677. * @return array
  2678. * @since 1.7.0
  2679. * @todo Why isn't this used anywhere else but in elgg_view_tree()?
  2680. * Seems like a useful function for autodiscovery.
  2681. * @access private
  2682. * @deprecated 1.9
  2683. */
  2684. function elgg_get_views($dir, $base) {
  2685. $return = array();
  2686. if (file_exists($dir) && is_dir($dir)) {
  2687. if ($handle = opendir($dir)) {
  2688. while ($view = readdir($handle)) {
  2689. if (!in_array($view, array('.', '..', '.svn', 'CVS'))) {
  2690. if (is_dir($dir . '/' . $view)) {
  2691. if ($val = elgg_get_views($dir . '/' . $view, $base . '/' . $view)) {
  2692. $return = array_merge($return, $val);
  2693. }
  2694. } else {
  2695. $view = str_replace('.php', '', $view);
  2696. $return[] = $base . '/' . $view;
  2697. }
  2698. }
  2699. }
  2700. }
  2701. }
  2702. return $return;
  2703. }
  2704. /**
  2705. * Returns all views below a partial view.
  2706. *
  2707. * Settings $view_root = 'profile' will show all available views under
  2708. * the "profile" namespace.
  2709. *
  2710. * @param string $view_root The root view
  2711. * @param string $viewtype Optionally specify a view type
  2712. * other than the current one.
  2713. *
  2714. * @return array A list of view names underneath that root view
  2715. * @todo This is used once in the deprecated get_activity_stream_data() function.
  2716. * @access private
  2717. * @deprecated 1.9
  2718. */
  2719. function elgg_view_tree($view_root, $viewtype = "") {
  2720. global $CONFIG;
  2721. static $treecache = array();
  2722. // Get viewtype
  2723. if (!$viewtype) {
  2724. $viewtype = elgg_get_viewtype();
  2725. }
  2726. // A little light internal caching
  2727. if (!empty($treecache[$view_root])) {
  2728. return $treecache[$view_root];
  2729. }
  2730. // Examine $CONFIG->views->locations
  2731. if (isset($CONFIG->views->locations[$viewtype])) {
  2732. foreach ($CONFIG->views->locations[$viewtype] as $view => $path) {
  2733. $pos = strpos($view, $view_root);
  2734. if ($pos === 0) {
  2735. $treecache[$view_root][] = $view;
  2736. }
  2737. }
  2738. }
  2739. // Now examine core
  2740. $location = $CONFIG->viewpath;
  2741. $viewtype = elgg_get_viewtype();
  2742. $root = $location . $viewtype . '/' . $view_root;
  2743. if (file_exists($root) && is_dir($root)) {
  2744. $val = elgg_get_views($root, $view_root);
  2745. if (!is_array($treecache[$view_root])) {
  2746. $treecache[$view_root] = array();
  2747. }
  2748. $treecache[$view_root] = array_merge($treecache[$view_root], $val);
  2749. }
  2750. return $treecache[$view_root];
  2751. }
  2752. /**
  2753. * Adds an item to the river.
  2754. *
  2755. * @param string $view The view that will handle the river item (must exist)
  2756. * @param string $action_type An arbitrary string to define the action (eg 'comment', 'create')
  2757. * @param int $subject_guid The GUID of the entity doing the action
  2758. * @param int $object_guid The GUID of the entity being acted upon
  2759. * @param int $access_id The access ID of the river item (default: same as the object)
  2760. * @param int $posted The UNIX epoch timestamp of the river item (default: now)
  2761. * @param int $annotation_id The annotation ID associated with this river entry
  2762. * @param int $target_guid The GUID of the the object entity's container
  2763. *
  2764. * @return int/bool River ID or false on failure
  2765. * @deprecated 1.9 Use elgg_create_river_item()
  2766. */
  2767. function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "",
  2768. $posted = 0, $annotation_id = 0, $target_guid = 0) {
  2769. elgg_deprecated_notice('add_to_river was deprecated in favor of elgg_create_river_item', '1.9');
  2770. // Make sure old parameters are passed in correct format
  2771. $access_id = ($access_id == '') ? null : $access_id;
  2772. $posted = ($posted == 0) ? null : $posted;
  2773. return elgg_create_river_item(array(
  2774. 'view' => $view,
  2775. 'action_type' => $action_type,
  2776. 'subject_guid' => $subject_guid,
  2777. 'object_guid' => $object_guid,
  2778. 'target_guid' => $target_guid,
  2779. 'access_id' => $access_id,
  2780. 'posted' => $posted,
  2781. 'annotation_id' => $annotation_id,
  2782. ));
  2783. }
  2784. /**
  2785. * This function serialises an object recursively into an XML representation.
  2786. *
  2787. * The function attempts to call $data->export() which expects a \stdClass in return,
  2788. * otherwise it will attempt to get the object variables using get_object_vars (which
  2789. * will only return public variables!)
  2790. *
  2791. * @param mixed $data The object to serialise.
  2792. * @param string $name The name?
  2793. * @param int $n Level, only used for recursion.
  2794. *
  2795. * @return string The serialised XML output.
  2796. * @deprecated 1.9
  2797. */
  2798. function serialise_object_to_xml($data, $name = "", $n = 0) {
  2799. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9);
  2800. $classname = ($name == "" ? get_class($data) : $name);
  2801. $vars = method_exists($data, "export") ? get_object_vars($data->export()) : get_object_vars($data);
  2802. $output = "";
  2803. if (($n == 0) || ( is_object($data) && !($data instanceof \stdClass))) {
  2804. $output = "<$classname>";
  2805. }
  2806. foreach ($vars as $key => $value) {
  2807. $output .= "<$key type=\"" . gettype($value) . "\">";
  2808. if (is_object($value)) {
  2809. $output .= serialise_object_to_xml($value, $key, $n + 1);
  2810. } else if (is_array($value)) {
  2811. $output .= serialise_array_to_xml($value, $n + 1);
  2812. } else if (gettype($value) == "boolean") {
  2813. $output .= $value ? "true" : "false";
  2814. } else {
  2815. $output .= htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
  2816. }
  2817. $output .= "</$key>\n";
  2818. }
  2819. if (($n == 0) || (is_object($data) && !($data instanceof \stdClass))) {
  2820. $output .= "</$classname>\n";
  2821. }
  2822. return $output;
  2823. }
  2824. /**
  2825. * Serialise an array.
  2826. *
  2827. * @param array $data The data to serialize
  2828. * @param int $n Used for recursion
  2829. *
  2830. * @return string
  2831. * @deprecated 1.9
  2832. */
  2833. function serialise_array_to_xml(array $data, $n = 0) {
  2834. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated.', 1.9);
  2835. $output = "";
  2836. if ($n == 0) {
  2837. $output = "<array>\n";
  2838. }
  2839. foreach ($data as $key => $value) {
  2840. $item = "array_item";
  2841. if (is_numeric($key)) {
  2842. $output .= "<$item name=\"$key\" type=\"" . gettype($value) . "\">";
  2843. } else {
  2844. $item = $key;
  2845. $output .= "<$item type=\"" . gettype($value) . "\">";
  2846. }
  2847. if (is_object($value)) {
  2848. $output .= serialise_object_to_xml($value, "", $n + 1);
  2849. } else if (is_array($value)) {
  2850. $output .= serialise_array_to_xml($value, $n + 1);
  2851. } else if (gettype($value) == "boolean") {
  2852. $output .= $value ? "true" : "false";
  2853. } else {
  2854. $output .= htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
  2855. }
  2856. $output .= "</$item>\n";
  2857. }
  2858. if ($n == 0) {
  2859. $output .= "</array>\n";
  2860. }
  2861. return $output;
  2862. }
  2863. /**
  2864. * Parse an XML file into an object.
  2865. *
  2866. * @param string $xml The XML
  2867. *
  2868. * @return \ElggXMLElement
  2869. * @deprecated 1.9 Use \ElggXMLElement
  2870. */
  2871. function xml_to_object($xml) {
  2872. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by \ElggXMLElement', 1.9);
  2873. return new \ElggXMLElement($xml);
  2874. }
  2875. /**
  2876. * Retrieve a site and return the domain portion of its url.
  2877. *
  2878. * @param int $guid \ElggSite GUID
  2879. *
  2880. * @return string
  2881. * @deprecated 1.9 Use \ElggSite::getDomain()
  2882. */
  2883. function get_site_domain($guid) {
  2884. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggSite::getDomain()', 1.9);
  2885. $guid = (int)$guid;
  2886. $site = get_entity($guid);
  2887. if ($site instanceof \ElggSite) {
  2888. $breakdown = parse_url($site->url);
  2889. return $breakdown['host'];
  2890. }
  2891. return false;
  2892. }
  2893. /**
  2894. * Register an entity type and subtype to be eligible for notifications
  2895. *
  2896. * @param string $entity_type The type of entity
  2897. * @param string $object_subtype Its subtype
  2898. * @param string $language_name Its localized notification string (eg "New blog post")
  2899. *
  2900. * @return void
  2901. * @deprecated 1.9 Use elgg_register_notification_event(). The 3rd argument was used
  2902. * as the subject line in a notification. As of Elgg 1.9, it is now set by a callback
  2903. * for a plugin hook. See the documentation at the top of the notifications library
  2904. * titled "Adding a New Notification Event" for more details.
  2905. */
  2906. function register_notification_object($entity_type, $object_subtype, $language_name) {
  2907. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_register_notification_event()', 1.9);
  2908. elgg_register_notification_event($entity_type, $object_subtype);
  2909. _elgg_services()->notifications->setDeprecatedNotificationSubject($entity_type, $object_subtype, $language_name);
  2910. }
  2911. /**
  2912. * Establish a 'notify' relationship between the user and a content author
  2913. *
  2914. * @param int $user_guid The GUID of the user who wants to follow a user's content
  2915. * @param int $author_guid The GUID of the user whose content the user wants to follow
  2916. *
  2917. * @return bool Depending on success
  2918. * @deprecated 1.9 Use elgg_add_subscription()
  2919. */
  2920. function register_notification_interest($user_guid, $author_guid) {
  2921. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_add_subscription()', 1.9);
  2922. return add_entity_relationship($user_guid, 'notify', $author_guid);
  2923. }
  2924. /**
  2925. * Remove a 'notify' relationship between the user and a content author
  2926. *
  2927. * @param int $user_guid The GUID of the user who is following a user's content
  2928. * @param int $author_guid The GUID of the user whose content the user wants to unfollow
  2929. *
  2930. * @return bool Depending on success
  2931. * @deprecated 1.9 Use elgg_remove_subscription()
  2932. */
  2933. function remove_notification_interest($user_guid, $author_guid) {
  2934. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_remove_subscription()', 1.9);
  2935. return remove_entity_relationship($user_guid, 'notify', $author_guid);
  2936. }
  2937. /**
  2938. * Automatically triggered notification on 'create' events that looks at registered
  2939. * objects and attempts to send notifications to anybody who's interested
  2940. *
  2941. * @see register_notification_object
  2942. *
  2943. * @param string $event create
  2944. * @param string $object_type mixed
  2945. * @param mixed $object The object created
  2946. *
  2947. * @return bool
  2948. * @access private
  2949. * @deprecated 1.9
  2950. */
  2951. function object_notifications($event, $object_type, $object) {
  2952. throw new \BadFunctionCallException("object_notifications is a private function and should not be called directly");
  2953. }
  2954. /**
  2955. * This function registers a handler for a given notification type (eg "email")
  2956. *
  2957. * @param string $method The method
  2958. * @param string $handler The handler function, in the format
  2959. * "handler(\ElggEntity $from, \ElggUser $to, $subject,
  2960. * $message, array $params = NULL)". This function should
  2961. * return false on failure, and true/a tracking message ID on success.
  2962. * @param array $params An associated array of other parameters for this handler
  2963. * defining some properties eg. supported msg length or rich text support.
  2964. *
  2965. * @return bool
  2966. * @deprecated 1.9 Use elgg_register_notification_method()
  2967. */
  2968. function register_notification_handler($method, $handler, $params = NULL) {
  2969. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_register_notification_method()', 1.9);
  2970. elgg_register_notification_method($method);
  2971. _elgg_services()->notifications->registerDeprecatedHandler($method, $handler);
  2972. }
  2973. /**
  2974. * This function unregisters a handler for a given notification type (eg "email")
  2975. *
  2976. * @param string $method The method
  2977. *
  2978. * @return void
  2979. * @since 1.7.1
  2980. * @deprecated 1.9 Use elgg_unregister_notification_method()
  2981. */
  2982. function unregister_notification_handler($method) {
  2983. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by elgg_unregister_notification_method()', 1.9);
  2984. elgg_unregister_notification_method($method);
  2985. }
  2986. /**
  2987. * Import an entity.
  2988. *
  2989. * This function checks the passed XML doc (as array) to see if it is
  2990. * a user, if so it constructs a new elgg user and returns "true"
  2991. * to inform the importer that it's been handled.
  2992. *
  2993. * @param string $hook import
  2994. * @param string $entity_type all
  2995. * @param mixed $returnvalue Value from previous hook
  2996. * @param mixed $params Array of params
  2997. *
  2998. * @return mixed
  2999. * @elgg_plugin_hook_handler import all
  3000. * @todo document
  3001. * @access private
  3002. *
  3003. * @throws ImportException
  3004. * @deprecated 1.9
  3005. */
  3006. function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3007. $element = $params['element'];
  3008. $tmp = null;
  3009. if ($element instanceof ODDEntity) {
  3010. $tmp = oddentity_to_elggentity($element);
  3011. if ($tmp) {
  3012. // Make sure its saved
  3013. if (!$tmp->save()) {
  3014. $msg = "There was a problem saving " . $element->getAttribute('uuid');
  3015. throw new \ImportException($msg);
  3016. }
  3017. // Belts and braces
  3018. if (!$tmp->guid) {
  3019. throw new \ImportException("New entity created but has no GUID, this should not happen.");
  3020. }
  3021. // We have saved, so now tag
  3022. add_uuid_to_guid($tmp->guid, $element->getAttribute('uuid'));
  3023. return $tmp;
  3024. }
  3025. }
  3026. }
  3027. /**
  3028. * Exports all attributes of an entity.
  3029. *
  3030. * @warning Only exports fields in the entity and entity type tables.
  3031. *
  3032. * @param string $hook export
  3033. * @param string $entity_type all
  3034. * @param mixed $returnvalue Previous hook return value
  3035. * @param array $params Parameters
  3036. *
  3037. * @elgg_event_handler export all
  3038. * @return mixed
  3039. * @access private
  3040. *
  3041. * @throws InvalidParameterException|InvalidClassException
  3042. * @deprecated 1.9
  3043. */
  3044. function export_entity_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3045. // Sanity check values
  3046. if ((!is_array($params)) && (!isset($params['guid']))) {
  3047. throw new \InvalidParameterException("GUID has not been specified during export, this should never happen.");
  3048. }
  3049. if (!is_array($returnvalue)) {
  3050. throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter");
  3051. }
  3052. $guid = (int)$params['guid'];
  3053. // Get the entity
  3054. $entity = get_entity($guid);
  3055. if (!($entity instanceof \ElggEntity)) {
  3056. $msg = "GUID:" . $guid . " is not a valid " . get_class();
  3057. throw new \InvalidClassException($msg);
  3058. }
  3059. $export = $entity->export();
  3060. if (is_array($export)) {
  3061. foreach ($export as $e) {
  3062. $returnvalue[] = $e;
  3063. }
  3064. } else {
  3065. $returnvalue[] = $export;
  3066. }
  3067. return $returnvalue;
  3068. }
  3069. /**
  3070. * Exports attributes generated on the fly (volatile) about an entity.
  3071. *
  3072. * @param string $hook volatile
  3073. * @param string $entity_type metadata
  3074. * @param string $returnvalue Return value from previous hook
  3075. * @param array $params The parameters, passed 'guid' and 'varname'
  3076. *
  3077. * @return \ElggMetadata|null
  3078. * @elgg_plugin_hook_handler volatile metadata
  3079. * @todo investigate more.
  3080. * @access private
  3081. * @todo document
  3082. * @deprecated 1.9
  3083. */
  3084. function volatile_data_export_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3085. $guid = (int)$params['guid'];
  3086. $variable_name = sanitise_string($params['varname']);
  3087. if (($hook == 'volatile') && ($entity_type == 'metadata')) {
  3088. if (($guid) && ($variable_name)) {
  3089. switch ($variable_name) {
  3090. case 'renderedentity' :
  3091. elgg_set_viewtype('default');
  3092. $view = elgg_view_entity(get_entity($guid));
  3093. elgg_set_viewtype();
  3094. $tmp = new \ElggMetadata();
  3095. $tmp->type = 'volatile';
  3096. $tmp->name = 'renderedentity';
  3097. $tmp->value = $view;
  3098. $tmp->entity_guid = $guid;
  3099. return $tmp;
  3100. break;
  3101. }
  3102. }
  3103. }
  3104. }
  3105. /**
  3106. * Export the annotations for the specified entity
  3107. *
  3108. * @param string $hook 'export'
  3109. * @param string $type 'all'
  3110. * @param mixed $returnvalue Default return value
  3111. * @param mixed $params Parameters determining what annotations to export
  3112. *
  3113. * @elgg_plugin_hook export all
  3114. *
  3115. * @return array
  3116. * @throws InvalidParameterException
  3117. * @access private
  3118. * @deprecated 1.9
  3119. */
  3120. function export_annotation_plugin_hook($hook, $type, $returnvalue, $params) {
  3121. // Sanity check values
  3122. if ((!is_array($params)) && (!isset($params['guid']))) {
  3123. throw new \InvalidParameterException("GUID has not been specified during export, this should never happen.");
  3124. }
  3125. if (!is_array($returnvalue)) {
  3126. throw new \InvalidParameterException("Entity serialization function passed a non-array returnvalue parameter");
  3127. }
  3128. $guid = (int)$params['guid'];
  3129. $options = array('guid' => $guid, 'limit' => 0);
  3130. if (isset($params['name'])) {
  3131. $options['annotation_name'] = $params['name'];
  3132. }
  3133. $result = elgg_get_annotations($options);
  3134. if ($result) {
  3135. foreach ($result as $r) {
  3136. $returnvalue[] = $r->export();
  3137. }
  3138. }
  3139. return $returnvalue;
  3140. }
  3141. /**
  3142. * Handler called by trigger_plugin_hook on the "import" event.
  3143. *
  3144. * @param string $hook volatile
  3145. * @param string $entity_type metadata
  3146. * @param string $returnvalue Return value from previous hook
  3147. * @param array $params The parameters
  3148. *
  3149. * @return null
  3150. * @elgg_plugin_hook_handler volatile metadata
  3151. * @todo investigate more.
  3152. * @throws ImportException
  3153. * @access private
  3154. * @deprecated 1.9
  3155. */
  3156. function import_extender_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3157. $element = $params['element'];
  3158. $tmp = NULL;
  3159. if ($element instanceof ODDMetaData) {
  3160. /* @var ODDMetaData $element */
  3161. // Recall entity
  3162. $entity_uuid = $element->getAttribute('entity_uuid');
  3163. $entity = get_entity_from_uuid($entity_uuid);
  3164. if (!$entity) {
  3165. throw new \ImportException("Entity '" . $entity_uuid . "' could not be found.");
  3166. }
  3167. oddmetadata_to_elggextender($entity, $element);
  3168. // Save
  3169. if (!$entity->save()) {
  3170. $attr_name = $element->getAttribute('name');
  3171. $msg = "There was a problem updating '" . $attr_name . "' on entity '" . $entity_uuid . "'";
  3172. throw new \ImportException($msg);
  3173. }
  3174. return true;
  3175. }
  3176. }
  3177. /**
  3178. * Utility function used by import_extender_plugin_hook() to process
  3179. * an ODDMetaData and add it to an entity. This function does not
  3180. * hit ->save() on the entity (this lets you construct in memory)
  3181. *
  3182. * @param \ElggEntity $entity The entity to add the data to.
  3183. * @param ODDMetaData $element The OpenDD element
  3184. *
  3185. * @return bool
  3186. * @access private
  3187. * @deprecated 1.9
  3188. */
  3189. function oddmetadata_to_elggextender(\ElggEntity $entity, ODDMetaData $element) {
  3190. // Get the type of extender (metadata, type, attribute etc)
  3191. $type = $element->getAttribute('type');
  3192. $attr_name = $element->getAttribute('name');
  3193. $attr_val = $element->getBody();
  3194. switch ($type) {
  3195. // Ignore volatile items
  3196. case 'volatile' :
  3197. break;
  3198. case 'annotation' :
  3199. $entity->annotate($attr_name, $attr_val);
  3200. break;
  3201. case 'metadata' :
  3202. $entity->setMetadata($attr_name, $attr_val, "", true);
  3203. break;
  3204. default : // Anything else assume attribute
  3205. $entity->set($attr_name, $attr_val);
  3206. }
  3207. // Set time if appropriate
  3208. $attr_time = $element->getAttribute('published');
  3209. if ($attr_time) {
  3210. $entity->set('time_updated', $attr_time);
  3211. }
  3212. return true;
  3213. }
  3214. /**
  3215. * Handler called by trigger_plugin_hook on the "export" event.
  3216. *
  3217. * @param string $hook export
  3218. * @param string $entity_type all
  3219. * @param mixed $returnvalue Value returned from previous hook
  3220. * @param mixed $params Params
  3221. *
  3222. * @return array
  3223. * @access private
  3224. *
  3225. * @throws InvalidParameterException
  3226. * @deprecated 1.9
  3227. */
  3228. function export_metadata_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3229. // Sanity check values
  3230. if ((!is_array($params)) && (!isset($params['guid']))) {
  3231. throw new \InvalidParameterException("GUID has not been specified during export, this should never happen.");
  3232. }
  3233. if (!is_array($returnvalue)) {
  3234. throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter");
  3235. }
  3236. $result = elgg_get_metadata(array(
  3237. 'guid' => (int)$params['guid'],
  3238. 'limit' => 0,
  3239. ));
  3240. if ($result) {
  3241. /* @var \ElggMetadata[] $result */
  3242. foreach ($result as $r) {
  3243. $returnvalue[] = $r->export();
  3244. }
  3245. }
  3246. return $returnvalue;
  3247. }
  3248. /**
  3249. * Handler called by trigger_plugin_hook on the "export" event.
  3250. *
  3251. * @param string $hook export
  3252. * @param string $entity_type all
  3253. * @param mixed $returnvalue Previous hook return value
  3254. * @param array $params Parameters
  3255. *
  3256. * @elgg_event_handler export all
  3257. * @return mixed
  3258. * @throws InvalidParameterException
  3259. * @access private
  3260. * @deprecated 1.9
  3261. */
  3262. function export_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3263. // Sanity check values
  3264. if ((!is_array($params)) && (!isset($params['guid']))) {
  3265. throw new \InvalidParameterException("GUID has not been specified during export, this should never happen.");
  3266. }
  3267. if (!is_array($returnvalue)) {
  3268. throw new \InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter");
  3269. }
  3270. $guid = (int)$params['guid'];
  3271. $result = get_entity_relationships($guid);
  3272. if ($result) {
  3273. foreach ($result as $r) {
  3274. $returnvalue[] = $r->export();
  3275. }
  3276. }
  3277. return $returnvalue;
  3278. }
  3279. /**
  3280. * Handler called by trigger_plugin_hook on the "import" event.
  3281. *
  3282. * @param string $hook import
  3283. * @param string $entity_type all
  3284. * @param mixed $returnvalue Value from previous hook
  3285. * @param mixed $params Array of params
  3286. *
  3287. * @return mixed
  3288. * @access private
  3289. * @deprecated 1.9
  3290. */
  3291. function import_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) {
  3292. $element = $params['element'];
  3293. $tmp = NULL;
  3294. if ($element instanceof ODDRelationship) {
  3295. $tmp = new \ElggRelationship();
  3296. $tmp->import($element);
  3297. return $tmp;
  3298. }
  3299. return $tmp;
  3300. }
  3301. /**
  3302. * Returns the SQL where clause for a table with access_id and enabled columns.
  3303. *
  3304. * This handles returning where clauses for ACCESS_FRIENDS in addition to using
  3305. * get_access_list() for access collections and the standard access levels.
  3306. *
  3307. * Note that if this code is executed in privileged mode it will return (1=1).
  3308. *
  3309. * @param string $table_prefix Optional table prefix for the access code.
  3310. * @param int $owner Optional user guid to get access information for. Defaults
  3311. * to logged in user.
  3312. * @return string
  3313. * @access private
  3314. * @deprecated 1.9 Use _elgg_get_access_where_sql()
  3315. */
  3316. function get_access_sql_suffix($table_prefix = '', $owner = null) {
  3317. elgg_deprecated_notice(__FUNCTION__ . ' is deprecated by _elgg_get_access_where_sql()', 1.9);
  3318. return _elgg_get_access_where_sql(array(
  3319. 'table_alias' => $table_prefix,
  3320. 'user_guid' => (int)$owner,
  3321. ));
  3322. }
  3323. /**
  3324. * Get the name of the most recent plugin to be called in the
  3325. * call stack (or the plugin that owns the current page, if any).
  3326. *
  3327. * i.e., if the last plugin was in /mod/foobar/, this would return foo_bar.
  3328. *
  3329. * @param boolean $mainfilename If set to true, this will instead determine the
  3330. * context from the main script filename called by
  3331. * the browser. Default = false.
  3332. *
  3333. * @return string|false Plugin name, or false if no plugin name was called
  3334. * @since 1.8.0
  3335. * @access private
  3336. * @deprecated 1.9
  3337. */
  3338. function elgg_get_calling_plugin_id($mainfilename = false) {
  3339. elgg_deprecated_notice('elgg_get_calling_plugin_id() is deprecated', 1.9);
  3340. if (!$mainfilename) {
  3341. if ($backtrace = debug_backtrace()) {
  3342. foreach ($backtrace as $step) {
  3343. $file = $step['file'];
  3344. $file = str_replace("\\", "/", $file);
  3345. $file = str_replace("//", "/", $file);
  3346. if (preg_match("/mod\/([a-zA-Z0-9\-\_]*)\/start\.php$/", $file, $matches)) {
  3347. return $matches[1];
  3348. }
  3349. }
  3350. }
  3351. } else {
  3352. //@todo this is a hack -- plugins do not have to match their page handler names!
  3353. if ($handler = get_input('handler', false)) {
  3354. return $handler;
  3355. } else {
  3356. $file = $_SERVER["SCRIPT_NAME"];
  3357. $file = str_replace("\\", "/", $file);
  3358. $file = str_replace("//", "/", $file);
  3359. if (preg_match("/mod\/([a-zA-Z0-9\-\_]*)\//", $file, $matches)) {
  3360. return $matches[1];
  3361. }
  3362. }
  3363. }
  3364. return false;
  3365. }
  3366. /**
  3367. * Returns the \ElggPlugin entity of the last plugin called.
  3368. *
  3369. * @return ElggPlugin|false
  3370. * @since 1.8.0
  3371. * @access private
  3372. * @deprecated 1.9
  3373. */
  3374. function elgg_get_calling_plugin_entity() {
  3375. elgg_deprecated_notice("elgg_get_calling_plugin_entity() is deprecated.", 1.9);
  3376. $plugin_id = elgg_get_calling_plugin_id();
  3377. if ($plugin_id) {
  3378. return elgg_get_plugin_from_id($plugin_id);
  3379. }
  3380. return false;
  3381. }
  3382. return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
  3383. // Register a startup event
  3384. $events->registerHandler('init', 'system', '_export_init', 100);
  3385. /** Register the import hook */
  3386. $hooks->registerHandler("import", "all", "import_entity_plugin_hook", 0);
  3387. $hooks->registerHandler("import", "all", "import_extender_plugin_hook", 2);
  3388. $hooks->registerHandler("import", "all", "import_relationship_plugin_hook", 3);
  3389. /** Register the hook, ensuring entities are serialised first */
  3390. $hooks->registerHandler("export", "all", "export_entity_plugin_hook", 0);
  3391. $hooks->registerHandler("export", "all", "export_annotation_plugin_hook", 2);
  3392. $hooks->registerHandler("export", "all", "export_metadata_plugin_hook", 2);
  3393. $hooks->registerHandler("export", "all", "export_relationship_plugin_hook", 3);
  3394. /** Hook to get certain named bits of volatile data about an entity */
  3395. $hooks->registerHandler('volatile', 'metadata', 'volatile_data_export_plugin_hook');
  3396. };